当前位置:网站首页>Opencv video tracking "suggestions collection"
Opencv video tracking "suggestions collection"
2022-07-25 14:11:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
What is object tracking ?
In short , Locating objects in consecutive frames of video is called track .
The definition sounds straightforward , But in computer vision and machine learning , Tracking is a very broad term , Cover conceptually similar but technically different ideas . for example , Usually in Object tracking Next, study all the following different but related ideas
- Dense optical flow : These algorithms are helpful to estimate the motion vector of each pixel in the video frame .
- Sparse optical flow : These algorithms , Such as Kanade-Lucas-Tomashi(KLT) Feature tracker , Track the position of several feature points in the image .
- Kalman filtering : A very popular signal processing algorithm , It is used to predict the position of a moving object based on previous motion information . One of the early applications of this algorithm is missile guidance ! Also mentioned here ,“ Is to guide Apollo 11 The on-board computer of the lunar module landing on the moon has a Kalman filter ”.
- Meanshift and Camshift: These are algorithms for locating the maximum value of the density function . They are also used to track .
- Single object tracker : In this kind of tracker , The first frame is marked with a rectangle , To indicate the location of the object we want to track . Then, the tracking algorithm is used to track the object in subsequent frames . In most practical applications , These trackers are used in combination with object detectors .
- Multiple object tracking algorithm : When we have a fast object detector , It is meaningful to detect multiple objects in each frame and then run the tracking search algorithm to identify which rectangle in one frame corresponds to the rectangle in the next frame .
Tracking and detection
If you've ever played OpenCV Face detection , You know it works in real time , You can easily detect the face in each frame . that , Why do you need to track first ? Let's explore the different reasons why you might want to track objects in video , Not just repeat detection .
- Tracking is faster than detection : Generally, the tracking algorithm is faster than the detection algorithm . The reason is simple . When you track objects detected in the previous frame , You know a lot about the appearance of this object . You can also know the position in the previous frame and the direction and speed of its movement . therefore , In the next frame , You can use all this information to predict the position of the object in the next frame , And make a small search around the expected position of the object , To accurately locate the object . A good tracking algorithm will use all its information about the object , The detection algorithm always starts from scratch . therefore , When designing effective systems , Usually every n One operation and one object detection in between n-1 The frame in which the tracking algorithm is used . Why don't we directly detect the object in the first frame and then track ? exactly , Tracking can benefit from the additional information it has , But when they fall behind obstacles for a long time , Or if they move too fast for the tracking algorithm to catch up , You may also lose tracking of objects . Cumulative errors in tracking algorithms are also common , The bounding box of the tracked object will slowly deviate from the object it is tracking . In order to solve these problems by tracking algorithm , Run the detection algorithm every once in a while . The detection algorithm is trained on a large number of examples of objects . therefore , They know more about the general classes of objects . On the other hand ,
- When the detection fails , Tracking can help : If you run a face detector on a video and your face is blocked by an object , Then the face detector is likely to fail . On the other hand , A good tracking algorithm will handle some degree of occlusion . In the video below , You can see MIL The author of the tracker Boris Babenko Doctor presentation MIL How the tracker works under cover .
- Track retention identification : The output of object detection is a rectangular array containing objects . however , The object has no attached identifier . for example , In the video below , The detector that detects red dots will output rectangles corresponding to all points it detects in the frame . In the next frame , It will output another rectangular array . In the first frame , A specific point can be determined by the position in the array 10 The rectangle at represents , And in the second frame , It can be in position 17 It's about . When using detection on a frame , We don't know which rectangle corresponds to which object . On the other hand , Tracing provides a way to literally join points !
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>
usingnamespacecv;
usingnamespacestd;
// Convert to string
#define SSTR( x ) static_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()
intmain(intargc, char**argv)
{
// List of tracker types in OpenCV 3.4.1
string trackerTypes[8] = {"BOOSTING", "MIL", "KCF", "TLD","MEDIANFLOW", "GOTURN", "MOSSE", "CSRT"};
// vector <string> trackerTypes(types, std::end(types));
// Create a tracker
string trackerType = trackerTypes[2];
Ptr<Tracker> tracker;
#if (CV_MINOR_VERSION < 3)
{
tracker = Tracker::create(trackerType);
}
#else
{
if(trackerType == "BOOSTING")
tracker = TrackerBoosting::create();
if(trackerType == "MIL")
tracker = TrackerMIL::create();
if(trackerType == "KCF")
tracker = TrackerKCF::create();
if(trackerType == "TLD")
tracker = TrackerTLD::create();
if(trackerType == "MEDIANFLOW")
tracker = TrackerMedianFlow::create();
if(trackerType == "GOTURN")
tracker = TrackerGOTURN::create();
if(trackerType == "MOSSE")
tracker = TrackerMOSSE::create();
if(trackerType == "CSRT")
tracker = TrackerCSRT::create();
}
#endif
// Read video
VideoCapture video("videos/chaplin.mp4");
// Exit if video is not opened
if(!video.isOpened())
{
cout << "Could not read video file"<< endl;
return1;
}
// Read first frame
Mat frame;
boolok = video.read(frame);
// Define initial bounding box
Rect2d bbox(287, 23, 86, 320);
// Uncomment the line below to select a different bounding box
// bbox = selectROI(frame, false);
// Display bounding box.
rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
imshow("Tracking", frame);
tracker->init(frame, bbox);
while(video.read(frame))
{
// Start timer
doubletimer = (double)getTickCount();
// Update the tracking result
boolok = tracker->update(frame, bbox);
// Calculate Frames per second (FPS)
floatfps = getTickFrequency() / ((double)getTickCount() - timer);
if(ok)
{
// Tracking success : Draw the tracked object
rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
}
else
{
// Tracking failure detected.
putText(frame, "Tracking failure detected", Point(100,80), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0,0,255),2);
}
// Display tracker type on frame
putText(frame, trackerType + " Tracker", Point(100,20), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50),2);
// Display FPS on frame
putText(frame, "FPS : "+ SSTR(int(fps)), Point(100,50), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50), 2);
// Display frame.
imshow("Tracking", frame);
// Exit if ESC pressed.
intk = waitKey(1);
if(k == 27)
{
break;
}
}
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/127650.html Link to the original text :https://javaforall.cn
边栏推荐
- Brush questions - Luogu -p1151 sub number integer
- Nuc980 set up SSH xshell connection
- Pytorch uses tensorboard to realize visual summary
- What are the ranking strategies for mobile websites, independent apps and websites?
- 飞沃科技IPO过会:年营收11.3亿 湖南文旅与沅澧投资是股东
- Problems and extensions of the monocular depth estimation model featdepth in practice
- 如何设计一个高并发系统?
- Xintang nuc980 set DHCP or static IP
- Gartner 2022 top technology trend: Super automation
- Tensorflow2 installation quick pit avoidance summary
猜你喜欢

Brush questions - Luogu -p1047 trees outside the school gate

maya建模练习

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part I) -- paper understanding and core source code analysis

Brush questions - Luogu -p1151 sub number integer

Doris学习笔记之与其他系统集成

The practice of depth estimation self-monitoring model monodepth2 in its own data set -- single card / multi card training, reasoning, onnx transformation and quantitative index evaluation

Engineering monitoring multi-channel vibrating wire sensor wireless acquisition instrument external digital sensor process

Brush questions - Luogu -p1085 unhappy Jinjin

Business analysis report and data visualization report of CDA level1 knowledge point summary

Maya modeling exercise
随机推荐
Four methods of importing CSV text files into Excel
Sunfeng, general manager of Yixun: the company has completed the share reform and is preparing for IPO
Doris学习笔记之与其他系统集成
NAT/NAPT地址转换(内外网通信)技术详解【华为eNSP】
~5 new solution of CCF 2021-12-2 sequence query
CDA level1 double disk summary
sqli-labs Basic Challenges Less11-22
Sqli labs installation environment: ubuntu18 php7
MySQL and Navicat installation and stepping on pits
Brush questions - Luogu -p1075 prime factor decomposition
[learning record] plt.show() solution to flash back
Okaleido ecological core equity Oka, all in fusion mining mode
Acquisition data transmission mode and online monitoring system of wireless acquisition instrument for vibrating wire sensor of engineering instrument
网络安全应急响应技术实战指南(奇安信)
Hyperautomation for the enhancement of automation in industries
It is predicted that 2021 will accelerate the achievement of super automation beyond RPA
手把手教你申请SSL证书
Doris learning notes integration with other systems
Leetcode202 --- Happy number
wangeditor 富文本编辑器