In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how opencv3/C++ uses Tracker to achieve target tracking, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Brief introduction
MIL: TrackerMIL trains the classifier online to separate the object from the background, and multi-instance learning avoids the drift problem of robust tracking.
OLB: TrackerBoosting online real-time object tracking based on AdaBoost algorithm. The classifier uses the surrounding background as a counterexample in the update step to avoid drift.
MedianFlow: the TrackerMedianFlow tracker is suitable for very smooth and predictable motion, and objects are visible in the entire sequence.
TLD: TrackerTLD breaks down long-term tracking tasks into tracking, learning, and testing. The tracker tracks objects between frames. The detector localizes all appearances observed and corrects the tracker if necessary. Learn to estimate the errors of the detector and update them to avoid repeating them. The tracker can handle fast movement, partial occlusion, missing objects, and so on.
KCF: TrackerKCF uses the circulant matrix of the area around the target to collect positive and negative samples, uses ridge regression to train the target detector, and successfully uses the diagonalizability of the circulant matrix in the Fourier space to transform the operation of the matrix into the Hadamad product of the vector, that is, the point multiplication of elements, which greatly reduces the amount of computation, improves the operation speed, and makes the algorithm meet the real-time requirements.
Partial related API:
TrackerMIL
Static Ptr create (const TrackerMIL::Params & parameters); CV_WRAP static Ptr create ()
Struct CV_EXPORTS Params {PARAMS (); / / parameters of the sampler float samplerInitInRadius; / / initial collection of positive instance radius int samplerInitMaxNegNum; / / initial use negative sample float samplerSearchWinSize; / / search window size float samplerTrackInRadius; / / collect positive instance radius int samplerTrackMaxPosNum; / / use positive sample int samplerTrackMaxNegNum; / / negative sample int featureSetNumFeatures used during tracking / / feature void read (const FileNode&fn); void write (FileStorage&fs) const;}
TrackerBoosting
Static Ptr create (const TrackerBoosting::Params & parameters); CV_WRAP static Ptr create ()
Struct CV_EXPORTS Params {PARAMS (); int numClassifiers; / / number of classifiers used in the OnlineBoosting algorithm float samplerOverlap; / / search area parameter float samplerSearchFactor; / / search area parameter int iterationInit; / / initial iteration int featureSetNumFeatures; / / feature / / read parameter void read (const FileNode&fn) from file; / / write parameter void write (FileStorage&fs) const;} from file
Example
First, get the first frame of the video, select the target to be tracked by clicking the left-click box, right-click to confirm and start tracking using MIL. From the actual situation, the algorithm has poor tracking ability when there is occlusion in the process.
(environment: Ubuntu16.04+QT5.8+opencv3.3.1)
# include # include using namespace cv;void draw_rectangle (int event, int x, int y, int flags, void*); Mat firstFrame;Point previousPoint, currentPoint;Rect2d bbox;int main (int argc, char * argv []) {VideoCapture capture; Mat frame; frame = capture.open ("/ home/w/mycode/QT/img/runners.avi"); if (! capture.isOpened ()) {printf ("can not open...\ n"); return-1 } / / get the first frame of the video, and select the target capture.read (firstFrame); if (! firstFrame.empty ()) {namedWindow ("output", WINDOW_AUTOSIZE); imshow ("output", firstFrame); setMouseCallback ("output", draw_rectangle, 0); waitKey ();} / / use TrackerMIL to track Ptr tracker= TrackerMIL::create (); / / Ptr tracker= TrackerTLD::create (); / / Ptr tracker= TrackerKCF::create (); / / Ptr tracker= TrackerMedianFlow::create () / / Ptr tracker= TrackerBoosting::create (); capture.read (frame); tracker- > init (frame,bbox); namedWindow ("output", WINDOW_AUTOSIZE); while (capture.read (frame)) {tracker- > update (frame,bbox); rectangle (frame,bbox, Scalar (255,0,0), 2,1); imshow ("output", frame); if (waitKey (20) = ='q') return 0;} capture.release (); destroyWindow ("output"); return 0 } / / Select the target void draw_rectangle (int event, int x, int y, int flags, void*) {if (event = = EVENT_LBUTTONDOWN) {previousPoint = Point (x, y);} else if (event = = EVENT_MOUSEMOVE & & (flags&EVENT_FLAG_LBUTTON)) {Mat tmp; firstFrame.copyTo (tmp); currentPoint = Point (x, y); rectangle (tmp, previousPoint, currentPoint, Scalar (0,255,0,0), 1,8,0); imshow ("output", tmp) } else if (event = = EVENT_LBUTTONUP) {bbox.x = previousPoint.x; bbox.y = previousPoint.y; bbox.width = abs (previousPoint.x-currentPoint.x); bbox.height = abs (previousPoint.y-currentPoint.y);} else if (event = = EVENT_RBUTTONUP) {destroyWindow ("output");}}
The experimental results show that the speed of KCF is the fastest, the speed of MedianFlow is also faster, and the tracking effect is better for the case of no occlusion, while the effect of TLD on partial occlusion is the best and the processing time is relatively slow.
Partial occlusion effect
MIL's effect on partial occlusion:
Opencv::Tracker Algorithms
Thank you for reading this article carefully. I hope the article "how opencv3/C++ uses Tracker to achieve goal tracking" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.