Commit 6e7d162e authored by Alex Leontiev's avatar Alex Leontiev

Change Rect to Rect2d in Tracker::update() and ::init()

I've changed Rect to Rect2d in Tracker::update(), Tracker::init() and
all related methods (including documentation). This allows to initialize
trackers with double-valued rectangles, thus adding versality. Besides,
trackers also can output double-valued rectangles, which may be
beneficial in some scenarios.

However, it remains to change UML diagrams in documentation to tracker
module, as they still display methods above with old signatures.
parent 9e5c28b8
...@@ -15,9 +15,9 @@ Base abstract class for the long-term tracker:: ...@@ -15,9 +15,9 @@ Base abstract class for the long-term tracker::
{ {
virtual ~Tracker(); virtual ~Tracker();
bool init( const Mat& image, const Rect& boundingBox ); bool init( const Mat& image, const Rect2d& boundingBox );
bool update( const Mat& image, Rect& boundingBox ); bool update( const Mat& image, Rect2d& boundingBox );
static Ptr<Tracker> create( const String& trackerType ); static Ptr<Tracker> create( const String& trackerType );
...@@ -28,23 +28,27 @@ Tracker::init ...@@ -28,23 +28,27 @@ Tracker::init
Initialize the tracker with a know bounding box that surrounding the target Initialize the tracker with a know bounding box that surrounding the target
.. ocv:function:: bool Tracker::init( const Mat& image, const Rect& boundingBox ) .. ocv:function:: bool Tracker::init( const Mat& image, const Rect2d& boundingBox )
:param image: The initial frame :param image: The initial frame
:param boundingBox: The initial boundig box :param boundingBox: The initial boundig box
:return: True if initialization went succesfully, false otherwise
Tracker::update Tracker::update
--------------- ---------------
Update the tracker, find the new most likely bounding box for the target Update the tracker, find the new most likely bounding box for the target
.. ocv:function:: bool Tracker::update( const Mat& image, Rect& boundingBox ) .. ocv:function:: bool Tracker::update( const Mat& image, Rect2d& boundingBox )
:param image: The current frame :param image: The current frame
:param boundingBox: The boundig box that represent the new target location :param boundingBox: The boundig box that represent the new target location, if true was returned, not modified otherwise
:return: True means that target was located and false means that tracker cannot locate target in current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed missing from the frame (say, out of sight)
Tracker::create Tracker::create
...@@ -83,8 +87,8 @@ Example of creating specialized Tracker ``TrackerMIL`` : :: ...@@ -83,8 +87,8 @@ Example of creating specialized Tracker ``TrackerMIL`` : ::
... ...
protected: protected:
bool initImpl( const Mat& image, const Rect& boundingBox ); bool initImpl( const Mat& image, const Rect2d& boundingBox );
bool updateImpl( const Mat& image, Rect& boundingBox ); bool updateImpl( const Mat& image, Rect2d& boundingBox );
... ...
}; };
...@@ -192,7 +196,7 @@ Example of creating specialized TrackerModel ``TrackerMILModel`` : :: ...@@ -192,7 +196,7 @@ Example of creating specialized TrackerModel ``TrackerMILModel`` : ::
And add it in your Tracker : :: And add it in your Tracker : ::
bool TrackerMIL::initImpl( const Mat& image, const Rect& boundingBox ) bool TrackerMIL::initImpl( const Mat& image, const Rect2d& boundingBox )
{ {
... ...
//model is the general TrackerModel field od the general Tracker //model is the general TrackerModel field od the general Tracker
......
...@@ -83,7 +83,7 @@ The modes available now: ...@@ -83,7 +83,7 @@ The modes available now:
* ``"HAAR"`` -- Haar Feature-based * ``"HAAR"`` -- Haar Feature-based
The modes available soon: The modes that will be available soon:
* ``"HOG"`` -- Histogram of Oriented Gradients features * ``"HOG"`` -- Histogram of Oriented Gradients features
...@@ -170,7 +170,7 @@ The modes available now: ...@@ -170,7 +170,7 @@ The modes available now:
* ``"HAAR"`` -- Haar Feature-based * ``"HAAR"`` -- Haar Feature-based
The modes available soon: The modes that will be available soon:
* ``"HOG"`` -- Histogram of Oriented Gradients features * ``"HOG"`` -- Histogram of Oriented Gradients features
......
...@@ -482,7 +482,7 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm ...@@ -482,7 +482,7 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm
* \param boundingBox The bounding box. * \param boundingBox The bounding box.
* \return true the tracker is initialized, false otherwise * \return true the tracker is initialized, false otherwise
*/ */
bool init( const Mat& image, const Rect& boundingBox ); bool init( const Mat& image, const Rect2d& boundingBox );
/** /**
* \brief Update the tracker at the next frames. * \brief Update the tracker at the next frames.
...@@ -490,7 +490,7 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm ...@@ -490,7 +490,7 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm
* \param boundingBox The bounding box. * \param boundingBox The bounding box.
* \return true the tracker is updated, false otherwise * \return true the tracker is updated, false otherwise
*/ */
bool update( const Mat& image, Rect& boundingBox ); bool update( const Mat& image, Rect2d& boundingBox );
/** /**
* \brief Create tracker by tracker type MIL - BOOSTING. * \brief Create tracker by tracker type MIL - BOOSTING.
...@@ -499,8 +499,8 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm ...@@ -499,8 +499,8 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm
protected: protected:
virtual bool initImpl( const Mat& image, const Rect& boundingBox ) = 0; virtual bool initImpl( const Mat& image, const Rect2d& boundingBox ) = 0;
virtual bool updateImpl( const Mat& image, Rect& boundingBox ) = 0; virtual bool updateImpl( const Mat& image, Rect2d& boundingBox ) = 0;
bool isInit; bool isInit;
...@@ -981,8 +981,8 @@ class CV_EXPORTS_W TrackerMIL : public Tracker ...@@ -981,8 +981,8 @@ class CV_EXPORTS_W TrackerMIL : public Tracker
protected: protected:
bool initImpl( const Mat& image, const Rect& boundingBox ); bool initImpl( const Mat& image, const Rect2d& boundingBox );
bool updateImpl( const Mat& image, Rect& boundingBox ); bool updateImpl( const Mat& image, Rect2d& boundingBox );
void compute_integral( const Mat & img, Mat & ii_img ); void compute_integral( const Mat & img, Mat & ii_img );
Params params; Params params;
...@@ -1029,8 +1029,8 @@ class CV_EXPORTS_W TrackerBoosting : public Tracker ...@@ -1029,8 +1029,8 @@ class CV_EXPORTS_W TrackerBoosting : public Tracker
protected: protected:
bool initImpl( const Mat& image, const Rect& boundingBox ); bool initImpl( const Mat& image, const Rect2d& boundingBox );
bool updateImpl( const Mat& image, Rect& boundingBox ); bool updateImpl( const Mat& image, Rect2d& boundingBox );
Params params; Params params;
AlgorithmInfo* info() const; AlgorithmInfo* info() const;
......
...@@ -161,7 +161,8 @@ PERF_TEST_P(tracking, mil, testing::Combine(TESTSET_NAMES, SEGMENTS)) ...@@ -161,7 +161,8 @@ PERF_TEST_P(tracking, mil, testing::Combine(TESTSET_NAMES, SEGMENTS))
int endFrame = 0; int endFrame = 0;
getSegment( segmentId, numSegments, bbCounter, startFrame, endFrame ); getSegment( segmentId, numSegments, bbCounter, startFrame, endFrame );
Rect currentBB = gtBBs[startFrame - gtStartFrame]; Rect currentBBi = gtBBs[startFrame - gtStartFrame];
Rect2d currentBB(currentBBi);
TEST_CYCLE_N(1) TEST_CYCLE_N(1)
{ {
...@@ -231,7 +232,8 @@ PERF_TEST_P(tracking, boosting, testing::Combine(TESTSET_NAMES, SEGMENTS)) ...@@ -231,7 +232,8 @@ PERF_TEST_P(tracking, boosting, testing::Combine(TESTSET_NAMES, SEGMENTS))
int endFrame = 0; int endFrame = 0;
getSegment( segmentId, numSegments, bbCounter, startFrame, endFrame ); getSegment( segmentId, numSegments, bbCounter, startFrame, endFrame );
Rect currentBB = gtBBs[startFrame - gtStartFrame]; Rect currentBBi = gtBBs[startFrame - gtStartFrame];
Rect2d currentBB(currentBBi);
TEST_CYCLE_N(1) TEST_CYCLE_N(1)
{ {
......
...@@ -7,7 +7,7 @@ using namespace std; ...@@ -7,7 +7,7 @@ using namespace std;
using namespace cv; using namespace cv;
static Mat image; static Mat image;
static Rect boundingBox; static Rect2d boundingBox;
static bool paused; static bool paused;
static bool selectObject = false; static bool selectObject = false;
static bool startSelection = false; static bool startSelection = false;
......
...@@ -52,7 +52,7 @@ Tracker::~Tracker() ...@@ -52,7 +52,7 @@ Tracker::~Tracker()
{ {
} }
bool Tracker::init( const Mat& image, const Rect& boundingBox ) bool Tracker::init( const Mat& image, const Rect2d& boundingBox )
{ {
if( isInit ) if( isInit )
...@@ -84,7 +84,7 @@ bool Tracker::init( const Mat& image, const Rect& boundingBox ) ...@@ -84,7 +84,7 @@ bool Tracker::init( const Mat& image, const Rect& boundingBox )
return initTracker; return initTracker;
} }
bool Tracker::update( const Mat& image, Rect& boundingBox ) bool Tracker::update( const Mat& image, Rect2d& boundingBox )
{ {
if( !isInit ) if( !isInit )
......
...@@ -106,7 +106,7 @@ void TrackerBoosting::write( cv::FileStorage& fs ) const ...@@ -106,7 +106,7 @@ void TrackerBoosting::write( cv::FileStorage& fs ) const
params.write( fs ); params.write( fs );
} }
bool TrackerBoosting::initImpl( const Mat& image, const Rect& boundingBox ) bool TrackerBoosting::initImpl( const Mat& image, const Rect2d& boundingBox )
{ {
srand (1); srand (1);
//sampling //sampling
...@@ -190,7 +190,7 @@ bool TrackerBoosting::initImpl( const Mat& image, const Rect& boundingBox ) ...@@ -190,7 +190,7 @@ bool TrackerBoosting::initImpl( const Mat& image, const Rect& boundingBox )
return true; return true;
} }
bool TrackerBoosting::updateImpl( const Mat& image, Rect& boundingBox ) bool TrackerBoosting::updateImpl( const Mat& image, Rect2d& boundingBox )
{ {
Mat_<int> intImage; Mat_<int> intImage;
Mat_<double> intSqImage; Mat_<double> intSqImage;
......
...@@ -122,7 +122,7 @@ void TrackerMIL::compute_integral( const Mat & img, Mat & ii_img ) ...@@ -122,7 +122,7 @@ void TrackerMIL::compute_integral( const Mat & img, Mat & ii_img )
ii_img = ii_imgs[0]; ii_img = ii_imgs[0];
} }
bool TrackerMIL::initImpl( const Mat& image, const Rect& boundingBox ) bool TrackerMIL::initImpl( const Mat& image, const Rect2d& boundingBox )
{ {
srand (1); srand (1);
Mat intImage; Mat intImage;
...@@ -184,7 +184,7 @@ bool TrackerMIL::initImpl( const Mat& image, const Rect& boundingBox ) ...@@ -184,7 +184,7 @@ bool TrackerMIL::initImpl( const Mat& image, const Rect& boundingBox )
return true; return true;
} }
bool TrackerMIL::updateImpl( const Mat& image, Rect& boundingBox ) bool TrackerMIL::updateImpl( const Mat& image, Rect2d& boundingBox )
{ {
Mat intImage; Mat intImage;
compute_integral( image, intImage ); compute_integral( image, intImage );
......
...@@ -176,7 +176,8 @@ void TrackerOPETest::distanceTest() ...@@ -176,7 +176,8 @@ void TrackerOPETest::distanceTest()
Mat frame; Mat frame;
bool initialized = false; bool initialized = false;
Rect currentBB = bbs.at( 0 ); Rect currentBBi = bbs.at( 0 );
Rect2d currentBB(currentBBi);
float sumDistance = 0; float sumDistance = 0;
int frameCounter = 0; int frameCounter = 0;
int frameCounterSucc = 0; int frameCounterSucc = 0;
...@@ -230,7 +231,8 @@ void TrackerOPETest::overlapTest() ...@@ -230,7 +231,8 @@ void TrackerOPETest::overlapTest()
{ {
Mat frame; Mat frame;
bool initialized = false; bool initialized = false;
Rect currentBB = bbs.at( 0 ); Rect currentBBi = bbs.at( 0 );
Rect2d currentBB(currentBBi);
float sumOverlap = 0; float sumOverlap = 0;
string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG;
......
...@@ -180,7 +180,8 @@ void TrackerSRETest::distanceTest() ...@@ -180,7 +180,8 @@ void TrackerSRETest::distanceTest()
Mat frame; Mat frame;
bool initialized = false; bool initialized = false;
Rect currentBB = bbs.at( 0 ); Rect currentBBi = bbs.at( 0 );
Rect2d currentBB(currentBBi);
float sumDistance = 0; float sumDistance = 0;
int frameCounter = 0; int frameCounter = 0;
int frameCounterSucc = 0; int frameCounterSucc = 0;
...@@ -235,7 +236,8 @@ void TrackerSRETest::overlapTest() ...@@ -235,7 +236,8 @@ void TrackerSRETest::overlapTest()
{ {
Mat frame; Mat frame;
bool initialized = false; bool initialized = false;
Rect currentBB = bbs.at( 0 ); Rect currentBBi = bbs.at( 0 );
Rect2d currentBB(currentBBi);
float sumOverlap = 0; float sumOverlap = 0;
string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG;
......
...@@ -190,7 +190,8 @@ void TrackerTRETest::distanceTest() ...@@ -190,7 +190,8 @@ void TrackerTRETest::distanceTest()
int fc = ( startFrame - gtStartFrame ); int fc = ( startFrame - gtStartFrame );
Rect currentBB = bbs.at( fc ); Rect currentBBi = bbs.at( fc );
Rect2d currentBB(currentBBi);
float sumDistance = 0; float sumDistance = 0;
string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG;
...@@ -250,7 +251,8 @@ void TrackerTRETest::overlapTest() ...@@ -250,7 +251,8 @@ void TrackerTRETest::overlapTest()
bool initialized = false; bool initialized = false;
int fc = ( startFrame - gtStartFrame ); int fc = ( startFrame - gtStartFrame );
Rect currentBB = bbs.at( fc ); Rect currentBBi = bbs.at( fc );
Rect2d currentBB(currentBBi);
float sumOverlap = 0; float sumOverlap = 0;
string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + video + "/" + FOLDER_IMG;
......
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