Commit eb0c6706 authored by Kurnianggoro's avatar Kurnianggoro

naive implementation of the multi tracker

parent 7aa3e6b0
......@@ -1245,14 +1245,81 @@ class CV_EXPORTS_W TrackerKCF : public Tracker
//! @}
/************************************ MultiTracker Class ************************************/
/** @brief This class is used to track multiple objects using the specified tracker algorithm.
* The MultiTracker is naive implementation of multiple object tracking.
* It process the tracked objects independently without any optimization accross the tracked objects.
*/
class CV_EXPORTS_W MultiTracker
{
public:
/**
* \brief Constructor.
* In the case of trackerType is given, it will be set as the default algorithm for all trackers.
* @param trackerType the name of the tracker algorithm to be used
*/
MultiTracker(const String& trackerType = "" );
/**
* \brief Destructor
*/
~MultiTracker();
/**
* \brief Add a new object to be tracked.
* The defaultAlgorithm will be used the newly added tracker.
* @param image input image
* @param boundingBox a rectangle represents ROI of the tracked object
*/
bool add( const Mat& image, const Rect2d& boundingBox );
/**
* \brief Add a new object to be tracked.
* @param trackerType the name of the tracker algorithm to be used
* @param image input image
* @param boundingBox a rectangle represents ROI of the tracked object
*/
bool add( const String& trackerType, const Mat& image, const Rect2d& boundingBox );
/**
* \brief Add a set of objects to be tracked.
* @param trackerType the name of the tracker algorithm to be used
* @param image input image
* @param boundingBox list of the tracked objects
*/
bool add(const String& trackerType, const Mat& image, std::vector<Rect2d> boundingBox);
/**
* \brief Add a set of objects to be tracked using the defaultAlgorithm tracker.
* @param image input image
* @param boundingBox list of the tracked objects
*/
bool add(const Mat& image, std::vector<Rect2d> boundingBox);
/**
* \brief Update the current tracking status.
* The result will be saved in the internal storage.
* @param image input image
*/
bool update( const Mat& image);
//!< storage for the tracked objects, each object corresponds to one tracker algorithm.
std::vector<Rect2d> objects;
/**
* \brief Update the current tracking status.
* @param image input image
* @param boundingBox the tracking result, represent a list of ROIs of the tracked objects.
*/
bool update( const Mat& image, std::vector<Rect2d> & boundingBox );
protected:
//!< storage for the tracker algorithms.
std::vector< Ptr<Tracker> > trackerList;
std::vector<Rect2d> objects;
//!< default algorithm for the tracking method.
String defaultAlgorithm;
};
} /* namespace cv */
......
......@@ -41,21 +41,80 @@
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<Tracker> 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);
};
bool MultiTracker::update( const Mat& image, std::vector<Rect2d> & boundingBox ){
// add a set of objects to be tracked
bool MultiTracker::add(const String& trackerType, const Mat& image, std::vector<Rect2d> boundingBox){
// status of the tracker addition
bool stat;
// add tracker for all input objects
for(unsigned i =0;i<boundingBox.size();i++){
stat=add(trackerType,image,boundingBox[i]);
if(!stat)break;
}
// return the status
return stat;
};
// add a set of object to be tracked, defaultAlgorithm is used.
bool MultiTracker::add(const Mat& image, std::vector<Rect2d> 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<Rect2d> & boundingBox ){
update(image);
boundingBox=objects;
return true;
};
} /* namespace cv */
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