当前位置:网站首页>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
边栏推荐
- 轻松入门自然语言处理系列 12 隐马尔可夫模型
- word设置粘贴仅保留文本
- 苹果手机端同步不成功,退出登录,结果再也登录不了了
- 2271. Maximum number of white bricks covered by blanket ●●
- Summary of some problems about left value and right value [easy to understand]
- Typora无法打开提示安装新版本解决办法
- Brush questions - Luogu -p1059 clear random number
- 在线问题反馈模块实战(十三):实现多参数分页查询列表
- From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part I)
- 苹果手机端同步不成功,退出登录,结果再也登录不了
猜你喜欢

maya建模练习

2271. 毯子覆盖的最多白色砖块数 ●●

Practice of online problem feedback module (13): realize multi parameter paging query list

Alibaba mqtt IOT platform "cloud product circulation" practice - the two esp32 achieve remote interoperability through the IOT platform

CDA level Ⅰ 2021 new version simulation question 2 (with answers)
Famous handwritten note taking software recruit CTO · coordinate Shenzhen

2271. Maximum number of white bricks covered by blanket ●●

Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction

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

Deep understanding of pytorch distributed parallel processing tool DDP -- starting from bugs in engineering practice
随机推荐
Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
Sqli labs installation environment: ubuntu18 php7
Arduino code of key state machine for realizing single, double click, long press and other functions with esp32 timed interrupt
Mysql表的操作
Write an esp32 Watchdog with Arduino
金鱼哥RHCA回忆录:CL210管理存储--管理共享文件系统
应急科普|收好这份暑期安全指南,让孩子安全过暑假!
Sunfeng, general manager of Yixun: the company has completed the share reform and is preparing for IPO
It is predicted that 2021 will accelerate the achievement of super automation beyond RPA
Day1: 130 questions in three languages
~4.2 CCF 2021-12-1 sequence query
Okaleido生态核心权益OKA,尽在聚变Mining模式
~5 new solution of CCF 2021-12-2 sequence query
Engineering monitoring multi-channel vibrating wire sensor wireless acquisition instrument external digital sensor process
MySQL and Navicat installation and stepping on pits
CDA level1 double disk summary
【学习记录】plt.show()闪退解决方法
Esp32 connects to Alibaba cloud mqtt IOT platform
Pytorch uses tensorboard to realize visual summary
Detailed explanation of Telnet remote login AAA mode [Huawei ENSP]