1
2
3
4
5
6
7
8
9
14#include <iostream>
15#include <cstring>
16#include <ctime>
17#include "samples_utility.hpp"
18
21
22int main(
int argc,
char** argv ){
23
24 if(argc<2){
25 cout<<
26 " Usage: example_tracking_multitracker <video_name> [algorithm]\n"
27 " examples:\n"
28 " example_tracking_multitracker Bolt/img/%04d.jpg\n"
29 " example_tracking_multitracker faceocc2.webm MEDIANFLOW\n"
30 << endl;
31 return 0;
32 }
33
34
35 std::string trackingAlg = "KCF";
36
37
38 if(argc>2)
39 trackingAlg = argv[2];
40
41
45
46
48 vector<Rect2d> objects;
50
51
52 std::string video = argv[1];
54
56
57
58 cap >> frame;
60 vector<Rect> ROIs;
63
64
65 if(ROIs.size()<1)
66 return 0;
67
68
70 std::vector<Ptr<legacy::Tracker> > algorithms;
71 for (size_t i = 0; i < ROIs.size(); i++)
72 {
73 algorithms.push_back(createTrackerByName_legacy(trackingAlg));
74 objects.push_back(ROIs[i]);
75 }
76
77 trackers.
add(algorithms,frame,objects);
79
80
81 printf("Start the tracking process, press ESC to quit.\n");
82 for ( ;; ){
83
84 cap >> frame;
85
86
87 if(frame.rows==0 || frame.cols==0)
88 break;
89
90
94
96
97 for(
unsigned i=0;i<trackers.
getObjects().size();i++)
100
101
103
104
106 }
107
108}
n-dimensional dense array class
Definition mat.hpp:812
Class for video capturing from video files, image sequences or cameras.
Definition videoio.hpp:731
This class is used to track multiple objects using the specified tracker algorithm.
Definition tracking_legacy.hpp:352
const std::vector< Rect2d > & getObjects() const
Returns a reference to a storage for the tracked objects, each object corresponds to one tracker algo...
bool add(Ptr< cv::legacy::Tracker > newTracker, InputArray image, const Rect2d &boundingBox)
Add a new object to be tracked.
bool update(InputArray image)
Update the current tracking status. The result will be saved in the internal storage.
Scalar_< double > Scalar
Definition types.hpp:702
void selectROIs(const String &windowName, InputArray img, std::vector< Rect > &boundingBoxes, bool showCrosshair=true, bool fromCenter=false, bool printNotice=true)
Allows users to select multiple ROIs on the given image.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple, thick, or filled up-right rectangle.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
"black box" representation of the file storage associated with a file on disk.
Definition core.hpp:102