Commit 7dc95a3a authored by Vladimir's avatar Vladimir

Added Multi-tracker functionality and example

1. Multi-tracker classes (multiTracker.cpp)
2. Multi-tracker example (multiTracker_test.cpp)
3. Fixed a rare bug (OpenCL runtime error)
parent f67fb500
...@@ -1366,7 +1366,6 @@ void CV_EXPORTS_W selectROI(const std::string& windowName, Mat img, std::vector< ...@@ -1366,7 +1366,6 @@ void CV_EXPORTS_W selectROI(const std::string& windowName, Mat img, std::vector<
/************************************ Multi-Tracker Classes ************************************/ /************************************ Multi-Tracker Classes ************************************/
class CV_EXPORTS_W MultiTracker_Alt class CV_EXPORTS_W MultiTracker_Alt
{ {
public: public:
...@@ -1376,15 +1375,15 @@ public: ...@@ -1376,15 +1375,15 @@ public:
bool update(const Mat& image); bool update(const Mat& image);
int targetNum = 0; int targetNum = 0;
std::vector <Ptr<Tracker> > trackers; std::vector <Ptr<Tracker>> trackers;
std::vector <Rect2d> boundingBoxes; std::vector <Rect2d> boundingBoxes;
std::vector<Scalar> colors; std::vector<Scalar> colors;
}; };
class CV_EXPORTS_W MultiTrackerTLD : public MultiTracker_Alt class CV_EXPORTS_W MultiTrackerTLD : public MultiTracker
{ {
public: public:
bool update_opt(const Mat& image); bool update(const Mat& image);
}; };
//! @} //! @}
......
...@@ -49,7 +49,11 @@ using namespace std; ...@@ -49,7 +49,11 @@ using namespace std;
using namespace cv; using namespace cv;
#define NUM_TEST_FRAMES 100 #define NUM_TEST_FRAMES 100
<<<<<<< HEAD
#define TEST_VIDEO_INDEX 15 //TLD Dataset Video Index from 1-10 for TLD and 1-60 for VOT #define TEST_VIDEO_INDEX 15 //TLD Dataset Video Index from 1-10 for TLD and 1-60 for VOT
=======
#define TEST_VIDEO_INDEX 7 //TLD Dataset Video Index from 1-10
>>>>>>> Added Multi-tracker functionality and example
//#define RECORD_VIDEO_FLG //#define RECORD_VIDEO_FLG
static Mat image; static Mat image;
...@@ -119,8 +123,17 @@ int main() ...@@ -119,8 +123,17 @@ int main()
//From TLD dataset //From TLD dataset
selectObject = true; selectObject = true;
<<<<<<< HEAD
Rect2d boundingBox1 = tld::tld_InitDataset(TEST_VIDEO_INDEX, "D:/opencv/VOT 2015", 1); Rect2d boundingBox1 = tld::tld_InitDataset(TEST_VIDEO_INDEX, "D:/opencv/VOT 2015", 1);
Rect2d boundingBox2(470, 490, 50, 120); Rect2d boundingBox2(470, 490, 50, 120);
=======
Rect2d boundingBox1 = tld::tld_InitDataset(TEST_VIDEO_INDEX, "D:/opencv/TLD_dataset");
Rect2d boundingBox2;
boundingBox2.x = 280;
boundingBox2.y = 60;
boundingBox2.width = 40;
boundingBox2.height = 60;
>>>>>>> Added Multi-tracker functionality and example
frame = tld::tld_getNextDatasetFrame(); frame = tld::tld_getNextDatasetFrame();
frame.copyTo(image); frame.copyTo(image);
...@@ -129,14 +142,22 @@ int main() ...@@ -129,14 +142,22 @@ int main()
#ifdef RECORD_VIDEO_FLG #ifdef RECORD_VIDEO_FLG
String outputFilename = "test.avi"; String outputFilename = "test.avi";
VideoWriter outputVideo; VideoWriter outputVideo;
<<<<<<< HEAD
outputVideo.open(outputFilename, -1, 15, Size(image.cols, image.rows)); outputVideo.open(outputFilename, -1, 15, Size(image.cols, image.rows));
=======
outputVideo.open(outputFilename, -1, 30, Size(image.cols, image.rows));
>>>>>>> Added Multi-tracker functionality and example
if (!outputVideo.isOpened()) if (!outputVideo.isOpened())
{ {
std::cout << "!!! Output video could not be opened" << std::endl; std::cout << "!!! Output video could not be opened" << std::endl;
getchar(); getchar();
<<<<<<< HEAD
return 0; return 0;
=======
return;
>>>>>>> Added Multi-tracker functionality and example
} }
#endif #endif
...@@ -180,17 +201,26 @@ int main() ...@@ -180,17 +201,26 @@ int main()
{ {
//initializes the tracker //initializes the tracker
mt.addTarget(frame, boundingBox1, tracker_algorithm_name); mt.addTarget(frame, boundingBox1, tracker_algorithm_name);
<<<<<<< HEAD
rectangle(frame, boundingBox1, mt.colors[0], 2, 1); rectangle(frame, boundingBox1, mt.colors[0], 2, 1);
mt.addTarget(frame, boundingBox2, tracker_algorithm_name); mt.addTarget(frame, boundingBox2, tracker_algorithm_name);
rectangle(frame, boundingBox2, mt.colors[1], 2, 1); rectangle(frame, boundingBox2, mt.colors[1], 2, 1);
=======
rectangle(image, boundingBox1, mt.colors[0], 2, 1);
mt.addTarget(frame, boundingBox2, tracker_algorithm_name);
rectangle(image, boundingBox2, mt.colors[1], 2, 1);
>>>>>>> Added Multi-tracker functionality and example
initialized = true; initialized = true;
} }
else else
{ {
//updates the tracker //updates the tracker
if (mt.update(frame)) if (mt.update(frame))
<<<<<<< HEAD
{ {
for (int i = 0; i < mt.targetNum; i++) for (int i = 0; i < mt.targetNum; i++)
rectangle(frame, mt.boundingBoxes[i], mt.colors[i], 2, 1); rectangle(frame, mt.boundingBoxes[i], mt.colors[i], 2, 1);
...@@ -201,6 +231,16 @@ int main() ...@@ -201,6 +231,16 @@ int main()
#ifdef RECORD_VIDEO_FLG #ifdef RECORD_VIDEO_FLG
outputVideo << frame; outputVideo << frame;
=======
for (int i=0; i < mt.targetNum; i++)
rectangle(image, mt.boundingBoxes[i], mt.colors[i], 2, 1);
}
}
imshow("Tracking API", image);
#ifdef RECORD_VIDEO_FLG
outputVideo << image;
>>>>>>> Added Multi-tracker functionality and example
#endif #endif
...@@ -209,7 +249,11 @@ int main() ...@@ -209,7 +249,11 @@ int main()
double t1 = (e2 - e1) / getTickFrequency(); double t1 = (e2 - e1) / getTickFrequency();
cout << frameCounter << "\tframe : " << t1 * 1000.0 << "ms" << endl; cout << frameCounter << "\tframe : " << t1 * 1000.0 << "ms" << endl;
<<<<<<< HEAD
//waitKey(0); //waitKey(0);
=======
waitKey(0);
>>>>>>> Added Multi-tracker functionality and example
} }
} }
......
...@@ -65,8 +65,6 @@ namespace cv ...@@ -65,8 +65,6 @@ namespace cv
else else
colors.push_back(Scalar(rand() % 256, rand() % 256, rand() % 256)); colors.push_back(Scalar(rand() % 256, rand() % 256, rand() % 256));
//Target counter //Target counter
targetNum++; targetNum++;
...@@ -750,5 +748,4 @@ namespace cv ...@@ -750,5 +748,4 @@ namespace cv
//t = (e2 - e1) / getTickFrequency()*1000.0; //t = (e2 - e1) / getTickFrequency()*1000.0;
//printf("NN: %d\t%f\n", patches.size(), t); //printf("NN: %d\t%f\n", patches.size(), t);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment