diff --git a/modules/tracking/include/opencv2/tracking/tldDataset.hpp b/modules/tracking/include/opencv2/tracking/tldDataset.hpp index 6d21a7d48..d31919ab5 100644 --- a/modules/tracking/include/opencv2/tracking/tldDataset.hpp +++ b/modules/tracking/include/opencv2/tracking/tldDataset.hpp @@ -48,7 +48,7 @@ namespace cv { namespace tld { - CV_EXPORTS cv::Rect2d tld_InitDataset(int datasetInd, const char* rootPath = "TLD_dataset"); + CV_EXPORTS cv::Rect2d tld_InitDataset(int videoInd, const char* rootPath = "TLD_dataset", int datasetInd = 0); CV_EXPORTS cv::Mat tld_getNextDatasetFrame(); } } diff --git a/modules/tracking/src/multiTracker_alt.cpp b/modules/tracking/src/multiTracker_alt.cpp new file mode 100644 index 000000000..99722a7c7 --- /dev/null +++ b/modules/tracking/src/multiTracker_alt.cpp @@ -0,0 +1,120 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#include "precomp.hpp" + +namespace cv { + + // constructor + MultiTracker::MultiTracker(const String& trackerType):defaultAlgorithm(trackerType){}; + + // destructor + MultiTracker::~MultiTracker(){}; + + // add an object to be tracked, defaultAlgorithm is used + bool MultiTracker::add(const Mat& image, const Rect2d& boundingBox){ + // quit if defaultAlgorithm has not been configured + if(defaultAlgorithm==""){ + printf("Default algorithm was not defined!\n"); + return false; + } + + // add a new tracked object + return add(defaultAlgorithm.c_str(), image, boundingBox); + }; + + // add a new tracked object + bool MultiTracker::add( const String& trackerType, const Mat& image, const Rect2d& boundingBox ){ + // declare a new tracker + Ptr newTracker = Tracker::create( trackerType ); + + // add the created tracker algorithm to the trackers list + trackerList.push_back(newTracker); + + // add the ROI to the bounding box list + objects.push_back(boundingBox); + + // initialize the created tracker + return trackerList.back()->init(image, boundingBox); + }; + + // add a set of objects to be tracked + bool MultiTracker::add(const String& trackerType, const Mat& image, std::vector boundingBox){ + // status of the tracker addition + bool stat=false; + + // add tracker for all input objects + for(unsigned i =0;i boundingBox){ + // quit if defaultAlgorithm has not been configured + if(defaultAlgorithm==""){ + printf("Default algorithm was not defined!\n"); + return false; + } + + return add(defaultAlgorithm.c_str(), image, boundingBox); + }; + + // update position of the tracked objects, the result is stored in internal storage + bool MultiTracker::update( const Mat& image){ + for(unsigned i=0;i< trackerList.size(); i++){ + trackerList[i]->update(image, objects[i]); + } + return true; + }; + + // update position of the tracked objects, the result is copied to external variable + bool MultiTracker::update( const Mat& image, std::vector & boundingBox ){ + update(image); + boundingBox=objects; + return true; + }; + +} /* namespace cv */ \ No newline at end of file diff --git a/modules/tracking/src/tldDataset.cpp b/modules/tracking/src/tldDataset.cpp index b93de2576..ddb241a83 100644 --- a/modules/tracking/src/tldDataset.cpp +++ b/modules/tracking/src/tldDataset.cpp @@ -48,70 +48,105 @@ namespace cv char tldRootPath[100]; int frameNum = 0; bool flagPNG = false; + bool flagVOT = false; - cv::Rect2d tld_InitDataset(int datasetInd,const char* rootPath) + //TLD Dataset Parameters + char* tldFolderName[10] = { + "01_david", + "02_jumping", + "03_pedestrian1", + "04_pedestrian2", + "05_pedestrian3", + "06_car", + "07_motocross", + "08_volkswagen", + "09_carchase", + "10_panda" + }; + char* votFolderName[60] = { + "bag", "ball1", "ball2", "basketball", "birds1", "birds2", "blanket", "bmx", "bolt1", "bolt2", + "book", "butterfly", "car1", "car2", "crossing", "dinosaur", "fernando", "fish1", "fish2", "fish3", + "fish4", "girl", "glove", "godfather", "graduate", "gymnastics1", "gymnastics2 ", "gymnastics3", "gymnastics4", "hand", + "handball1", "handball2", "helicopter", "iceskater1", "iceskater2", "leaves", "marching", "matrix", "motocross1", "motocross2", + "nature", "octopus", "pedestrian1", "pedestrian2", "rabbit", "racing", "road", "shaking", "sheep", "singer1", + "singer2", "singer3", "soccer1", "soccer2", "soldier", "sphere", "tiger", "traffic", "tunnel", "wiper" + }; + + Rect2d tldInitBB[10] = { + Rect2d(165, 183, 51, 54), Rect2d(147, 110, 33, 32), Rect2d(47, 51, 21, 36), Rect2d(130, 134, 21, 53), Rect2d(154, 102, 24, 52), + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(337, 219, 54, 37), Rect2d(58, 100, 27, 22) + }; + Rect2d votInitBB[60] = { + Rect2d(142, 125, 90, 39), Rect2d(490, 400, 40, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(225, 175, 50, 50), Rect2d(58, 100, 27, 22), + + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(560, 460, 50, 100), + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + Rect2d(142, 125, 90, 39), Rect2d(290, 43, 23, 40), Rect2d(273, 77, 27, 25), Rect2d(145, 84, 54, 37), Rect2d(58, 100, 27, 22), + }; + + int tldFrameOffset[10] = { 100, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int votFrameOffset[60] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }; + bool tldFlagPNG[10] = { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }; + bool votFlagPNG[60] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; + + cv::Rect2d tld_InitDataset(int videoInd, const char* rootPath, int datasetInd) { char* folderName = (char *)""; - int x = 0; - int y = 0; - int w = 0; - int h = 0; - flagPNG = false; - - frameNum = 1; - - if (datasetInd == 1) { - folderName = (char *)"01_david"; - x = 165, y = 83; - w = 51; h = 54; - frameNum = 100; - } - if (datasetInd == 2) { - folderName = (char *)"02_jumping"; - x = 147, y = 110; - w = 33; h = 32; - } - if (datasetInd == 3) { - folderName = (char *)"03_pedestrian1"; - x = 47, y = 51; - w = 21; h = 36; - } - if (datasetInd == 4) { - folderName = (char *)"04_pedestrian2"; - x = 130, y = 134; - w = 21; h = 53; - } - if (datasetInd == 5) { - folderName = (char *)"05_pedestrian3"; - x = 154, y = 102; - w = 24; h = 52; - } - if (datasetInd == 6) { - folderName = (char *)"06_car"; - x = 142, y = 125; - w = 90; h = 39; - } - if (datasetInd == 7) { - folderName = (char *)"07_motocross"; - x = 290, y = 43; - w = 23; h = 40; - flagPNG = true; - } - if (datasetInd == 8) { - folderName = (char *)"08_volkswagen"; - x = 273, y = 77; - w = 27; h = 25; - } - if (datasetInd == 9) { - folderName = (char *)"09_carchase"; - x = 145, y = 84; - w = 54; h = 37; - } - if (datasetInd == 10){ - folderName = (char *)"10_panda"; - x = 58, y = 100; - w = 27; h = 22; + int x, y, w, h; + + //Index range + // 1-10 TLD Dataset + // 1-60 VOT 2015 Dataset + int id = videoInd - 1; + + if (datasetInd == 0) + { + folderName = tldFolderName[id]; + x = tldInitBB[id].x; + y = tldInitBB[id].y; + w = tldInitBB[id].width; + h = tldInitBB[id].height; + frameNum = tldFrameOffset[id]; + flagPNG = tldFlagPNG[id]; + flagVOT = false; } + if (datasetInd == 1) + { + folderName = votFolderName[id]; + x = votInitBB[id].x; + y = votInitBB[id].y; + w = votInitBB[id].width; + h = votInitBB[id].height; + frameNum = votFrameOffset[id]; + flagPNG = votFlagPNG[id]; + flagVOT = true; + } strcpy(tldRootPath, rootPath); strcat(tldRootPath, "\\"); @@ -127,6 +162,8 @@ namespace cv char numStr[10]; strcpy(fullPath, tldRootPath); strcat(fullPath, "\\"); + if (flagVOT) + strcat(fullPath, "000"); if (frameNum < 10) strcat(fullPath, "0000"); else if (frameNum < 100) strcat(fullPath, "000"); else if (frameNum < 1000) strcat(fullPath, "00");