Merge pull request #2737 from alalek:tracking_api
commit
f1c3d0e5e7
89 changed files with 2760 additions and 2201 deletions
@ -1,3 +1,24 @@ |
||||
set(the_description "Tracking API") |
||||
ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_plot OPTIONAL opencv_dnn opencv_datasets WRAP java python objc) |
||||
|
||||
set(debug_modules "") |
||||
if(DEBUG_opencv_tracking) |
||||
list(APPEND debug_modules opencv_highgui) |
||||
endif() |
||||
|
||||
ocv_define_module(tracking |
||||
opencv_imgproc |
||||
opencv_core |
||||
opencv_video |
||||
opencv_plot # samples only |
||||
${debug_modules} |
||||
OPTIONAL |
||||
opencv_dnn |
||||
opencv_datasets |
||||
opencv_highgui |
||||
WRAP |
||||
java |
||||
python |
||||
objc |
||||
) |
||||
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-shadow /wd4458) |
||||
|
@ -1,284 +1,271 @@ |
||||
/*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*/
|
||||
|
||||
#ifndef __OPENCV_TRACKING_HPP__ |
||||
#define __OPENCV_TRACKING_HPP__ |
||||
|
||||
#include "opencv2/core/cvdef.h" |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_CONTRIB_TRACKING_HPP |
||||
#define OPENCV_CONTRIB_TRACKING_HPP |
||||
|
||||
#include "opencv2/core.hpp" |
||||
|
||||
namespace cv { |
||||
#ifndef CV_DOXYGEN |
||||
inline namespace tracking { |
||||
#endif |
||||
|
||||
/** @defgroup tracking Tracking API
|
||||
@{ |
||||
@defgroup tracking_detail Tracking API implementation details |
||||
@defgroup tracking_legacy Legacy Tracking API |
||||
@} |
||||
*/ |
||||
|
||||
Long-term optical tracking API |
||||
------------------------------ |
||||
|
||||
Long-term optical tracking is an important issue for many computer vision applications in |
||||
real world scenario. The development in this area is very fragmented and this API is an unique |
||||
interface useful for plug several algorithms and compare them. This work is partially based on |
||||
@cite AAM and @cite AMVOT . |
||||
|
||||
These algorithms start from a bounding box of the target and with their internal representation they |
||||
avoid the drift during the tracking. These long-term trackers are able to evaluate online the |
||||
quality of the location of the target in the new frame, without ground truth. |
||||
|
||||
There are three main components: the TrackerSampler, the TrackerFeatureSet and the TrackerModel. The |
||||
first component is the object that computes the patches over the frame based on the last target |
||||
location. The TrackerFeatureSet is the class that manages the Features, is possible plug many kind |
||||
of these (HAAR, HOG, LBP, Feature2D, etc). The last component is the internal representation of the |
||||
target, it is the appearance model. It stores all state candidates and compute the trajectory (the |
||||
most likely target states). The class TrackerTargetState represents a possible state of the target. |
||||
The TrackerSampler and the TrackerFeatureSet are the visual representation of the target, instead |
||||
the TrackerModel is the statistical model. |
||||
|
||||
A recent benchmark between these algorithms can be found in @cite OOT |
||||
|
||||
Creating Your Own %Tracker |
||||
-------------------- |
||||
|
||||
If you want to create a new tracker, here's what you have to do. First, decide on the name of the class
|
||||
for the tracker (to meet the existing style, we suggest something with prefix "tracker", e.g. |
||||
trackerMIL, trackerBoosting) -- we shall refer to this choice as to "classname" in subsequent. |
||||
|
||||
- Declare your tracker in modules/tracking/include/opencv2/tracking/tracker.hpp. Your tracker should inherit from |
||||
Tracker (please, see the example below). You should declare the specialized Param structure, |
||||
where you probably will want to put the data, needed to initialize your tracker. You should |
||||
get something similar to : |
||||
@code |
||||
class CV_EXPORTS_W TrackerMIL : public Tracker |
||||
{ |
||||
public: |
||||
struct CV_EXPORTS Params |
||||
{ |
||||
Params(); |
||||
//parameters for sampler
|
||||
float samplerInitInRadius; // radius for gathering positive instances during init
|
||||
int samplerInitMaxNegNum; // # negative samples to use during init
|
||||
float samplerSearchWinSize; // size of search window
|
||||
float samplerTrackInRadius; // radius for gathering positive instances during tracking
|
||||
int samplerTrackMaxPosNum; // # positive samples to use during tracking
|
||||
int samplerTrackMaxNegNum; // # negative samples to use during tracking
|
||||
int featureSetNumFeatures; // #features
|
||||
|
||||
void read( const FileNode& fn ); |
||||
void write( FileStorage& fs ) const; |
||||
}; |
||||
@endcode |
||||
of course, you can also add any additional methods of your choice. It should be pointed out, |
||||
however, that it is not expected to have a constructor declared, as creation should be done via |
||||
the corresponding create() method. |
||||
- Finally, you should implement the function with signature : |
||||
@code |
||||
Ptr<classname> classname::create(const classname::Params ¶meters){ |
||||
... |
||||
} |
||||
@endcode |
||||
That function can (and probably will) return a pointer to some derived class of "classname", |
||||
which will probably have a real constructor. |
||||
|
||||
Every tracker has three component TrackerSampler, TrackerFeatureSet and TrackerModel. The first two |
||||
are instantiated from Tracker base class, instead the last component is abstract, so you must |
||||
implement your TrackerModel. |
||||
|
||||
### TrackerSampler |
||||
|
||||
TrackerSampler is already instantiated, but you should define the sampling algorithm and add the |
||||
classes (or single class) to TrackerSampler. You can choose one of the ready implementation as |
||||
TrackerSamplerCSC or you can implement your sampling method, in this case the class must inherit |
||||
TrackerSamplerAlgorithm. Fill the samplingImpl method that writes the result in "sample" output |
||||
argument. |
||||
|
||||
Example of creating specialized TrackerSamplerAlgorithm TrackerSamplerCSC : : |
||||
@code |
||||
class CV_EXPORTS_W TrackerSamplerCSC : public TrackerSamplerAlgorithm |
||||
{ |
||||
public: |
||||
TrackerSamplerCSC( const TrackerSamplerCSC::Params ¶meters = TrackerSamplerCSC::Params() ); |
||||
~TrackerSamplerCSC(); |
||||
... |
||||
/** @addtogroup tracking
|
||||
@{ |
||||
Tracking is an important issue for many computer vision applications in real world scenario. |
||||
The development in this area is very fragmented and this API is an interface useful for plug several algorithms and compare them. |
||||
*/ |
||||
|
||||
protected: |
||||
bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ); |
||||
... |
||||
|
||||
}; |
||||
@endcode |
||||
|
||||
Example of adding TrackerSamplerAlgorithm to TrackerSampler : : |
||||
@code |
||||
//sampler is the TrackerSampler
|
||||
Ptr<TrackerSamplerAlgorithm> CSCSampler = new TrackerSamplerCSC( CSCparameters ); |
||||
if( !sampler->addTrackerSamplerAlgorithm( CSCSampler ) ) |
||||
return false; |
||||
|
||||
//or add CSC sampler with default parameters
|
||||
//sampler->addTrackerSamplerAlgorithm( "CSC" );
|
||||
@endcode |
||||
@sa |
||||
TrackerSamplerCSC, TrackerSamplerAlgorithm |
||||
|
||||
### TrackerFeatureSet |
||||
|
||||
TrackerFeatureSet is already instantiated (as first) , but you should define what kinds of features |
||||
you'll use in your tracker. You can use multiple feature types, so you can add a ready |
||||
implementation as TrackerFeatureHAAR in your TrackerFeatureSet or develop your own implementation. |
||||
In this case, in the computeImpl method put the code that extract the features and in the selection |
||||
method optionally put the code for the refinement and selection of the features. |
||||
|
||||
Example of creating specialized TrackerFeature TrackerFeatureHAAR : : |
||||
@code |
||||
class CV_EXPORTS_W TrackerFeatureHAAR : public TrackerFeature |
||||
{ |
||||
public: |
||||
TrackerFeatureHAAR( const TrackerFeatureHAAR::Params ¶meters = TrackerFeatureHAAR::Params() ); |
||||
~TrackerFeatureHAAR(); |
||||
void selection( Mat& response, int npoints ); |
||||
... |
||||
|
||||
protected: |
||||
bool computeImpl( const std::vector<Mat>& images, Mat& response ); |
||||
... |
||||
/** @brief Base abstract class for the long-term tracker
|
||||
*/ |
||||
class CV_EXPORTS_W Tracker |
||||
{ |
||||
protected: |
||||
Tracker(); |
||||
public: |
||||
virtual ~Tracker(); |
||||
|
||||
}; |
||||
@endcode |
||||
Example of adding TrackerFeature to TrackerFeatureSet : : |
||||
@code |
||||
//featureSet is the TrackerFeatureSet
|
||||
Ptr<TrackerFeature> trackerFeature = new TrackerFeatureHAAR( HAARparameters ); |
||||
featureSet->addTrackerFeature( trackerFeature ); |
||||
@endcode |
||||
@sa |
||||
TrackerFeatureHAAR, TrackerFeatureSet |
||||
|
||||
### TrackerModel |
||||
|
||||
TrackerModel is abstract, so in your implementation you must develop your TrackerModel that inherit |
||||
from TrackerModel. Fill the method for the estimation of the state "modelEstimationImpl", that |
||||
estimates the most likely target location, see @cite AAM table I (ME) for further information. Fill |
||||
"modelUpdateImpl" in order to update the model, see @cite AAM table I (MU). In this class you can use |
||||
the :cConfidenceMap and :cTrajectory to storing the model. The first represents the model on the all |
||||
possible candidate states and the second represents the list of all estimated states. |
||||
|
||||
Example of creating specialized TrackerModel TrackerMILModel : : |
||||
@code |
||||
class TrackerMILModel : public TrackerModel |
||||
{ |
||||
public: |
||||
TrackerMILModel( const Rect& boundingBox ); |
||||
~TrackerMILModel(); |
||||
... |
||||
/** @brief Initialize the tracker with a known bounding box that surrounded the target
|
||||
@param image The initial frame |
||||
@param boundingBox The initial bounding box |
||||
*/ |
||||
CV_WRAP virtual |
||||
void init(InputArray image, const Rect& boundingBox) = 0; |
||||
|
||||
protected: |
||||
void modelEstimationImpl( const std::vector<Mat>& responses ); |
||||
void modelUpdateImpl(); |
||||
... |
||||
/** @brief Update the tracker, find the new most likely bounding box for the target
|
||||
@param image The current frame |
||||
@param boundingBox The bounding box that represent the new target location, if true was returned, not |
||||
modified otherwise |
||||
|
||||
}; |
||||
@endcode |
||||
And add it in your Tracker : : |
||||
@code |
||||
bool TrackerMIL::initImpl( const Mat& image, const Rect2d& boundingBox ) |
||||
@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) |
||||
*/ |
||||
CV_WRAP virtual |
||||
bool update(InputArray image, CV_OUT Rect& boundingBox) = 0; |
||||
}; |
||||
|
||||
|
||||
/** @brief the CSRT tracker
|
||||
|
||||
The implementation is based on @cite Lukezic_IJCV2018 Discriminative Correlation Filter with Channel and Spatial Reliability |
||||
*/ |
||||
class CV_EXPORTS_W TrackerCSRT : public Tracker |
||||
{ |
||||
protected: |
||||
TrackerCSRT(); // use ::create()
|
||||
public: |
||||
virtual ~TrackerCSRT() CV_OVERRIDE; |
||||
|
||||
struct CV_EXPORTS_W_SIMPLE Params |
||||
{ |
||||
... |
||||
//model is the general TrackerModel field of the general Tracker
|
||||
model = new TrackerMILModel( boundingBox ); |
||||
... |
||||
} |
||||
@endcode |
||||
In the last step you should define the TrackerStateEstimator based on your implementation or you can |
||||
use one of ready class as TrackerStateEstimatorMILBoosting. It represent the statistical part of the |
||||
model that estimates the most likely target state. |
||||
|
||||
Example of creating specialized TrackerStateEstimator TrackerStateEstimatorMILBoosting : : |
||||
@code |
||||
class CV_EXPORTS_W TrackerStateEstimatorMILBoosting : public TrackerStateEstimator |
||||
CV_WRAP Params(); |
||||
|
||||
CV_PROP_RW bool use_hog; |
||||
CV_PROP_RW bool use_color_names; |
||||
CV_PROP_RW bool use_gray; |
||||
CV_PROP_RW bool use_rgb; |
||||
CV_PROP_RW bool use_channel_weights; |
||||
CV_PROP_RW bool use_segmentation; |
||||
|
||||
CV_PROP_RW std::string window_function; //!< Window function: "hann", "cheb", "kaiser"
|
||||
CV_PROP_RW float kaiser_alpha; |
||||
CV_PROP_RW float cheb_attenuation; |
||||
|
||||
CV_PROP_RW float template_size; |
||||
CV_PROP_RW float gsl_sigma; |
||||
CV_PROP_RW float hog_orientations; |
||||
CV_PROP_RW float hog_clip; |
||||
CV_PROP_RW float padding; |
||||
CV_PROP_RW float filter_lr; |
||||
CV_PROP_RW float weights_lr; |
||||
CV_PROP_RW int num_hog_channels_used; |
||||
CV_PROP_RW int admm_iterations; |
||||
CV_PROP_RW int histogram_bins; |
||||
CV_PROP_RW float histogram_lr; |
||||
CV_PROP_RW int background_ratio; |
||||
CV_PROP_RW int number_of_scales; |
||||
CV_PROP_RW float scale_sigma_factor; |
||||
CV_PROP_RW float scale_model_max_area; |
||||
CV_PROP_RW float scale_lr; |
||||
CV_PROP_RW float scale_step; |
||||
|
||||
CV_PROP_RW float psr_threshold; //!< we lost the target, if the psr is lower than this.
|
||||
}; |
||||
|
||||
/** @brief Create CSRT tracker instance
|
||||
@param parameters CSRT parameters TrackerCSRT::Params |
||||
*/ |
||||
static CV_WRAP |
||||
Ptr<TrackerCSRT> create(const TrackerCSRT::Params ¶meters = TrackerCSRT::Params()); |
||||
|
||||
//void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE;
|
||||
//bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE;
|
||||
|
||||
CV_WRAP virtual void setInitialMask(InputArray mask) = 0; |
||||
}; |
||||
|
||||
|
||||
|
||||
/** @brief the KCF (Kernelized Correlation Filter) tracker
|
||||
|
||||
* KCF is a novel tracking framework that utilizes properties of circulant matrix to enhance the processing speed. |
||||
* This tracking method is an implementation of @cite KCF_ECCV which is extended to KCF with color-names features (@cite KCF_CN). |
||||
* The original paper of KCF is available at <http://www.robots.ox.ac.uk/~joao/publications/henriques_tpami2015.pdf>
|
||||
* as well as the matlab implementation. For more information about KCF with color-names features, please refer to |
||||
* <http://www.cvl.isy.liu.se/research/objrec/visualtracking/colvistrack/index.html>.
|
||||
*/ |
||||
class CV_EXPORTS_W TrackerKCF : public Tracker |
||||
{ |
||||
protected: |
||||
TrackerKCF(); // use ::create()
|
||||
public: |
||||
virtual ~TrackerKCF() CV_OVERRIDE; |
||||
|
||||
/**
|
||||
* \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names |
||||
* The modes available now: |
||||
- "GRAY" -- Use grayscale values as the feature |
||||
- "CN" -- Color-names feature |
||||
*/ |
||||
enum MODE { |
||||
GRAY = (1 << 0), |
||||
CN = (1 << 1), |
||||
CUSTOM = (1 << 2) |
||||
}; |
||||
|
||||
struct CV_EXPORTS_W_SIMPLE Params |
||||
{ |
||||
class TrackerMILTargetState : public TrackerTargetState |
||||
{ |
||||
... |
||||
}; |
||||
CV_WRAP Params(); |
||||
|
||||
CV_PROP_RW float detect_thresh; //!< detection confidence threshold
|
||||
CV_PROP_RW float sigma; //!< gaussian kernel bandwidth
|
||||
CV_PROP_RW float lambda; //!< regularization
|
||||
CV_PROP_RW float interp_factor; //!< linear interpolation factor for adaptation
|
||||
CV_PROP_RW float output_sigma_factor; //!< spatial bandwidth (proportional to target)
|
||||
CV_PROP_RW float pca_learning_rate; //!< compression learning rate
|
||||
CV_PROP_RW bool resize; //!< activate the resize feature to improve the processing speed
|
||||
CV_PROP_RW bool split_coeff; //!< split the training coefficients into two matrices
|
||||
CV_PROP_RW bool wrap_kernel; //!< wrap around the kernel values
|
||||
CV_PROP_RW bool compress_feature; //!< activate the pca method to compress the features
|
||||
CV_PROP_RW int max_patch_size; //!< threshold for the ROI size
|
||||
CV_PROP_RW int compressed_size; //!< feature size after compression
|
||||
CV_PROP_RW int desc_pca; //!< compressed descriptors of TrackerKCF::MODE
|
||||
CV_PROP_RW int desc_npca; //!< non-compressed descriptors of TrackerKCF::MODE
|
||||
}; |
||||
|
||||
/** @brief Create KCF tracker instance
|
||||
@param parameters KCF parameters TrackerKCF::Params |
||||
*/ |
||||
static CV_WRAP |
||||
Ptr<TrackerKCF> create(const TrackerKCF::Params ¶meters = TrackerKCF::Params()); |
||||
|
||||
//void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE;
|
||||
//bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE;
|
||||
|
||||
// FIXIT use interface
|
||||
typedef void (*FeatureExtractorCallbackFN)(const Mat, const Rect, Mat&); |
||||
virtual void setFeatureExtractor(FeatureExtractorCallbackFN callback, bool pca_func = false) = 0; |
||||
}; |
||||
|
||||
|
||||
public: |
||||
TrackerStateEstimatorMILBoosting( int nFeatures = 250 ); |
||||
~TrackerStateEstimatorMILBoosting(); |
||||
... |
||||
|
||||
protected: |
||||
Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps ); |
||||
void updateImpl( std::vector<ConfidenceMap>& confidenceMaps ); |
||||
... |
||||
/** @brief The MIL algorithm trains a classifier in an online manner to separate the object from the
|
||||
background. |
||||
|
||||
Multiple Instance Learning avoids the drift problem for a robust tracking. The implementation is |
||||
based on @cite MIL . |
||||
|
||||
Original code can be found here <http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml>
|
||||
*/ |
||||
class CV_EXPORTS_W TrackerMIL : public Tracker |
||||
{ |
||||
protected: |
||||
TrackerMIL(); // use ::create()
|
||||
public: |
||||
virtual ~TrackerMIL() CV_OVERRIDE; |
||||
|
||||
struct CV_EXPORTS_W_SIMPLE Params |
||||
{ |
||||
CV_WRAP Params(); |
||||
//parameters for sampler
|
||||
CV_PROP_RW float samplerInitInRadius; //!< radius for gathering positive instances during init
|
||||
CV_PROP_RW int samplerInitMaxNegNum; //!< # negative samples to use during init
|
||||
CV_PROP_RW float samplerSearchWinSize; //!< size of search window
|
||||
CV_PROP_RW float samplerTrackInRadius; //!< radius for gathering positive instances during tracking
|
||||
CV_PROP_RW int samplerTrackMaxPosNum; //!< # positive samples to use during tracking
|
||||
CV_PROP_RW int samplerTrackMaxNegNum; //!< # negative samples to use during tracking
|
||||
CV_PROP_RW int featureSetNumFeatures; //!< # features
|
||||
}; |
||||
@endcode |
||||
And add it in your TrackerModel : : |
||||
@code |
||||
//model is the TrackerModel of your Tracker
|
||||
Ptr<TrackerStateEstimatorMILBoosting> stateEstimator = new TrackerStateEstimatorMILBoosting( params.featureSetNumFeatures ); |
||||
model->setTrackerStateEstimator( stateEstimator ); |
||||
@endcode |
||||
@sa |
||||
TrackerModel, TrackerStateEstimatorMILBoosting, TrackerTargetState |
||||
|
||||
During this step, you should define your TrackerTargetState based on your implementation. |
||||
TrackerTargetState base class has only the bounding box (upper-left position, width and height), you |
||||
can enrich it adding scale factor, target rotation, etc. |
||||
|
||||
Example of creating specialized TrackerTargetState TrackerMILTargetState : : |
||||
@code |
||||
class TrackerMILTargetState : public TrackerTargetState |
||||
|
||||
/** @brief Create MIL tracker instance
|
||||
* @param parameters MIL parameters TrackerMIL::Params |
||||
*/ |
||||
static CV_WRAP |
||||
Ptr<TrackerMIL> create(const TrackerMIL::Params ¶meters = TrackerMIL::Params()); |
||||
|
||||
|
||||
//void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE;
|
||||
//bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE;
|
||||
}; |
||||
|
||||
|
||||
|
||||
/** @brief the GOTURN (Generic Object Tracking Using Regression Networks) tracker
|
||||
* |
||||
* GOTURN (@cite GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). While taking all advantages of CNN trackers, |
||||
* GOTURN is much faster due to offline training without online fine-tuning nature. |
||||
* GOTURN tracker addresses the problem of single target tracking: given a bounding box label of an object in the first frame of the video, |
||||
* we track that object through the rest of the video. NOTE: Current method of GOTURN does not handle occlusions; however, it is fairly |
||||
* robust to viewpoint changes, lighting changes, and deformations. |
||||
* Inputs of GOTURN are two RGB patches representing Target and Search patches resized to 227x227. |
||||
* Outputs of GOTURN are predicted bounding box coordinates, relative to Search patch coordinate system, in format X1,Y1,X2,Y2. |
||||
* Original paper is here: <http://davheld.github.io/GOTURN/GOTURN.pdf>
|
||||
* As long as original authors implementation: <https://github.com/davheld/GOTURN#train-the-tracker>
|
||||
* Implementation of training algorithm is placed in separately here due to 3d-party dependencies: |
||||
* <https://github.com/Auron-X/GOTURN_Training_Toolkit>
|
||||
* GOTURN architecture goturn.prototxt and trained model goturn.caffemodel are accessible on opencv_extra GitHub repository. |
||||
*/ |
||||
class CV_EXPORTS_W TrackerGOTURN : public Tracker |
||||
{ |
||||
protected: |
||||
TrackerGOTURN(); // use ::create()
|
||||
public: |
||||
virtual ~TrackerGOTURN() CV_OVERRIDE; |
||||
|
||||
struct CV_EXPORTS_W_SIMPLE Params |
||||
{ |
||||
public: |
||||
TrackerMILTargetState( const Point2f& position, int targetWidth, int targetHeight, bool foreground, const Mat& features ); |
||||
~TrackerMILTargetState(); |
||||
... |
||||
CV_WRAP Params(); |
||||
CV_PROP_RW std::string modelTxt; |
||||
CV_PROP_RW std::string modelBin; |
||||
}; |
||||
|
||||
private: |
||||
bool isTarget; |
||||
Mat targetFeatures; |
||||
... |
||||
/** @brief Constructor
|
||||
@param parameters GOTURN parameters TrackerGOTURN::Params |
||||
*/ |
||||
static CV_WRAP |
||||
Ptr<TrackerGOTURN> create(const TrackerGOTURN::Params& parameters = TrackerGOTURN::Params()); |
||||
|
||||
}; |
||||
@endcode |
||||
//void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE;
|
||||
//bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE;
|
||||
}; |
||||
|
||||
*/ |
||||
//! @}
|
||||
|
||||
#include <opencv2/tracking/tracker.hpp> |
||||
#include <opencv2/tracking/tldDataset.hpp> |
||||
#ifndef CV_DOXYGEN |
||||
} |
||||
#endif |
||||
} // namespace
|
||||
|
||||
#endif //__OPENCV_TRACKING_HPP__
|
||||
#endif // OPENCV_CONTRIB_TRACKING_HPP
|
||||
|
@ -0,0 +1,538 @@ |
||||
/*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*/
|
||||
|
||||
#ifndef OPENCV_TRACKING_LEGACY_HPP |
||||
#define OPENCV_TRACKING_LEGACY_HPP |
||||
|
||||
/*
|
||||
* Partially based on: |
||||
* ==================================================================================================================== |
||||
* - [AAM] S. Salti, A. Cavallaro, L. Di Stefano, Adaptive Appearance Modeling for Video Tracking: Survey and Evaluation |
||||
* - [AMVOT] X. Li, W. Hu, C. Shen, Z. Zhang, A. Dick, A. van den Hengel, A Survey of Appearance Models in Visual Object Tracking |
||||
* |
||||
* This Tracking API has been designed with PlantUML. If you modify this API please change UML files under modules/tracking/doc/uml |
||||
* |
||||
*/ |
||||
|
||||
#include "tracking_internals.hpp" |
||||
|
||||
namespace cv { |
||||
namespace legacy { |
||||
#ifndef CV_DOXYGEN |
||||
inline namespace tracking { |
||||
#endif |
||||
using namespace cv::detail::tracking; |
||||
|
||||
/** @addtogroup tracking_legacy
|
||||
@{ |
||||
*/ |
||||
|
||||
/************************************ Tracker Base Class ************************************/ |
||||
|
||||
/** @brief Base abstract class for the long-term tracker:
|
||||
*/ |
||||
class CV_EXPORTS_W Tracker : public virtual Algorithm |
||||
{ |
||||
public: |
||||
Tracker(); |
||||
virtual ~Tracker() CV_OVERRIDE; |
||||
|
||||
/** @brief Initialize the tracker with a known bounding box that surrounded the target
|
||||
@param image The initial frame |
||||
@param boundingBox The initial bounding box |
||||
|
||||
@return True if initialization went succesfully, false otherwise |
||||
*/ |
||||
CV_WRAP bool init( InputArray image, const Rect2d& boundingBox ); |
||||
|
||||
/** @brief Update the tracker, find the new most likely bounding box for the target
|
||||
@param image The current frame |
||||
@param boundingBox The bounding 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) |
||||
*/ |
||||
CV_WRAP bool update( InputArray image, CV_OUT Rect2d& boundingBox ); |
||||
|
||||
virtual void read( const FileNode& fn ) CV_OVERRIDE = 0; |
||||
virtual void write( FileStorage& fs ) const CV_OVERRIDE = 0; |
||||
|
||||
protected: |
||||
|
||||
virtual bool initImpl( const Mat& image, const Rect2d& boundingBox ) = 0; |
||||
virtual bool updateImpl( const Mat& image, Rect2d& boundingBox ) = 0; |
||||
|
||||
bool isInit; |
||||
|
||||
Ptr<TrackerFeatureSet> featureSet; |
||||
Ptr<TrackerSampler> sampler; |
||||
Ptr<TrackerModel> model; |
||||
}; |
||||
|
||||
|
||||
/************************************ Specific Tracker Classes ************************************/ |
||||
|
||||
/** @brief The MIL algorithm trains a classifier in an online manner to separate the object from the
|
||||
background. |
||||
|
||||
Multiple Instance Learning avoids the drift problem for a robust tracking. The implementation is |
||||
based on @cite MIL . |
||||
|
||||
Original code can be found here <http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml>
|
||||
*/ |
||||
class CV_EXPORTS_W TrackerMIL : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
struct CV_EXPORTS Params : cv::tracking::TrackerMIL::Params |
||||
{ |
||||
void read( const FileNode& fn ); |
||||
void write( FileStorage& fs ) const; |
||||
}; |
||||
|
||||
/** @brief Constructor
|
||||
@param parameters MIL parameters TrackerMIL::Params |
||||
*/ |
||||
static Ptr<legacy::TrackerMIL> create(const TrackerMIL::Params ¶meters); |
||||
|
||||
CV_WRAP static Ptr<legacy::TrackerMIL> create(); |
||||
|
||||
virtual ~TrackerMIL() CV_OVERRIDE {} |
||||
}; |
||||
|
||||
/** @brief the Boosting tracker
|
||||
|
||||
This is a real-time object tracking based on a novel on-line version of the AdaBoost algorithm. |
||||
The classifier uses the surrounding background as negative examples in update step to avoid the |
||||
drifting problem. The implementation is based on @cite OLB . |
||||
*/ |
||||
class CV_EXPORTS_W TrackerBoosting : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
struct CV_EXPORTS Params |
||||
{ |
||||
Params(); |
||||
int numClassifiers; //!<the number of classifiers to use in a OnlineBoosting algorithm
|
||||
float samplerOverlap; //!<search region parameters to use in a OnlineBoosting algorithm
|
||||
float samplerSearchFactor; //!< search region parameters to use in a OnlineBoosting algorithm
|
||||
int iterationInit; //!<the initial iterations
|
||||
int featureSetNumFeatures; //!< # features
|
||||
/**
|
||||
* \brief Read parameters from a file |
||||
*/ |
||||
void read( const FileNode& fn ); |
||||
|
||||
/**
|
||||
* \brief Write parameters to a file |
||||
*/ |
||||
void write( FileStorage& fs ) const; |
||||
}; |
||||
|
||||
/** @brief Constructor
|
||||
@param parameters BOOSTING parameters TrackerBoosting::Params |
||||
*/ |
||||
static Ptr<legacy::TrackerBoosting> create(const TrackerBoosting::Params ¶meters); |
||||
|
||||
CV_WRAP static Ptr<legacy::TrackerBoosting> create(); |
||||
|
||||
virtual ~TrackerBoosting() CV_OVERRIDE {} |
||||
}; |
||||
|
||||
/** @brief the Median Flow tracker
|
||||
|
||||
Implementation of a paper @cite MedianFlow . |
||||
|
||||
The tracker is suitable for very smooth and predictable movements when object is visible throughout |
||||
the whole sequence. It's quite and accurate for this type of problems (in particular, it was shown |
||||
by authors to outperform MIL). During the implementation period the code at |
||||
<http://www.aonsquared.co.uk/node/5>, the courtesy of the author Arthur Amarra, was used for the
|
||||
reference purpose. |
||||
*/ |
||||
class CV_EXPORTS_W TrackerMedianFlow : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
struct CV_EXPORTS Params |
||||
{ |
||||
Params(); //!<default constructor
|
||||
//!<note that the default values of parameters are recommended for most of use cases
|
||||
int pointsInGrid; //!<square root of number of keypoints used; increase it to trade
|
||||
//!<accurateness for speed
|
||||
cv::Size winSize; //!<window size parameter for Lucas-Kanade optical flow
|
||||
int maxLevel; //!<maximal pyramid level number for Lucas-Kanade optical flow
|
||||
TermCriteria termCriteria; //!<termination criteria for Lucas-Kanade optical flow
|
||||
cv::Size winSizeNCC; //!<window size around a point for normalized cross-correlation check
|
||||
double maxMedianLengthOfDisplacementDifference; //!<criterion for loosing the tracked object
|
||||
|
||||
void read( const FileNode& /*fn*/ ); |
||||
void write( FileStorage& /*fs*/ ) const; |
||||
}; |
||||
|
||||
/** @brief Constructor
|
||||
@param parameters Median Flow parameters TrackerMedianFlow::Params |
||||
*/ |
||||
static Ptr<legacy::TrackerMedianFlow> create(const TrackerMedianFlow::Params ¶meters); |
||||
|
||||
CV_WRAP static Ptr<legacy::TrackerMedianFlow> create(); |
||||
|
||||
virtual ~TrackerMedianFlow() CV_OVERRIDE {} |
||||
}; |
||||
|
||||
/** @brief the TLD (Tracking, learning and detection) tracker
|
||||
|
||||
TLD is a novel tracking framework that explicitly decomposes the long-term tracking task into |
||||
tracking, learning and detection. |
||||
|
||||
The tracker follows the object from frame to frame. The detector localizes all appearances that |
||||
have been observed so far and corrects the tracker if necessary. The learning estimates detector's |
||||
errors and updates it to avoid these errors in the future. The implementation is based on @cite TLD . |
||||
|
||||
The Median Flow algorithm (see cv::TrackerMedianFlow) was chosen as a tracking component in this |
||||
implementation, following authors. The tracker is supposed to be able to handle rapid motions, partial |
||||
occlusions, object absence etc. |
||||
*/ |
||||
class CV_EXPORTS_W TrackerTLD : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
struct CV_EXPORTS Params |
||||
{ |
||||
Params(); |
||||
void read( const FileNode& /*fn*/ ); |
||||
void write( FileStorage& /*fs*/ ) const; |
||||
}; |
||||
|
||||
/** @brief Constructor
|
||||
@param parameters TLD parameters TrackerTLD::Params |
||||
*/ |
||||
static Ptr<legacy::TrackerTLD> create(const TrackerTLD::Params ¶meters); |
||||
|
||||
CV_WRAP static Ptr<legacy::TrackerTLD> create(); |
||||
|
||||
virtual ~TrackerTLD() CV_OVERRIDE {} |
||||
}; |
||||
|
||||
/** @brief the KCF (Kernelized Correlation Filter) tracker
|
||||
|
||||
* KCF is a novel tracking framework that utilizes properties of circulant matrix to enhance the processing speed. |
||||
* This tracking method is an implementation of @cite KCF_ECCV which is extended to KCF with color-names features (@cite KCF_CN). |
||||
* The original paper of KCF is available at <http://www.robots.ox.ac.uk/~joao/publications/henriques_tpami2015.pdf>
|
||||
* as well as the matlab implementation. For more information about KCF with color-names features, please refer to |
||||
* <http://www.cvl.isy.liu.se/research/objrec/visualtracking/colvistrack/index.html>.
|
||||
*/ |
||||
class CV_EXPORTS_W TrackerKCF : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
/**
|
||||
* \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names |
||||
* The modes available now: |
||||
- "GRAY" -- Use grayscale values as the feature |
||||
- "CN" -- Color-names feature |
||||
*/ |
||||
typedef enum cv::tracking::TrackerKCF::MODE MODE; |
||||
|
||||
struct CV_EXPORTS Params : cv::tracking::TrackerKCF::Params |
||||
{ |
||||
void read(const FileNode& /*fn*/); |
||||
void write(FileStorage& /*fs*/) const; |
||||
}; |
||||
|
||||
virtual void setFeatureExtractor(void(*)(const Mat, const Rect, Mat&), bool pca_func = false) = 0; |
||||
|
||||
/** @brief Constructor
|
||||
@param parameters KCF parameters TrackerKCF::Params |
||||
*/ |
||||
static Ptr<legacy::TrackerKCF> create(const TrackerKCF::Params ¶meters); |
||||
|
||||
CV_WRAP static Ptr<legacy::TrackerKCF> create(); |
||||
|
||||
virtual ~TrackerKCF() CV_OVERRIDE {} |
||||
}; |
||||
|
||||
#if 0 // legacy variant is not available
|
||||
/** @brief the GOTURN (Generic Object Tracking Using Regression Networks) tracker
|
||||
|
||||
* GOTURN (@cite GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). While taking all advantages of CNN trackers, |
||||
* GOTURN is much faster due to offline training without online fine-tuning nature. |
||||
* GOTURN tracker addresses the problem of single target tracking: given a bounding box label of an object in the first frame of the video, |
||||
* we track that object through the rest of the video. NOTE: Current method of GOTURN does not handle occlusions; however, it is fairly |
||||
* robust to viewpoint changes, lighting changes, and deformations. |
||||
* Inputs of GOTURN are two RGB patches representing Target and Search patches resized to 227x227. |
||||
* Outputs of GOTURN are predicted bounding box coordinates, relative to Search patch coordinate system, in format X1,Y1,X2,Y2. |
||||
* Original paper is here: <http://davheld.github.io/GOTURN/GOTURN.pdf>
|
||||
* As long as original authors implementation: <https://github.com/davheld/GOTURN#train-the-tracker>
|
||||
* Implementation of training algorithm is placed in separately here due to 3d-party dependencies: |
||||
* <https://github.com/Auron-X/GOTURN_Training_Toolkit>
|
||||
* GOTURN architecture goturn.prototxt and trained model goturn.caffemodel are accessible on opencv_extra GitHub repository. |
||||
*/ |
||||
class CV_EXPORTS_W TrackerGOTURN : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
struct CV_EXPORTS Params |
||||
{ |
||||
Params(); |
||||
void read(const FileNode& /*fn*/); |
||||
void write(FileStorage& /*fs*/) const; |
||||
String modelTxt; |
||||
String modelBin; |
||||
}; |
||||
|
||||
/** @brief Constructor
|
||||
@param parameters GOTURN parameters TrackerGOTURN::Params |
||||
*/ |
||||
static Ptr<legacy::TrackerGOTURN> create(const TrackerGOTURN::Params ¶meters); |
||||
|
||||
CV_WRAP static Ptr<legacy::TrackerGOTURN> create(); |
||||
|
||||
virtual ~TrackerGOTURN() CV_OVERRIDE {} |
||||
}; |
||||
#endif |
||||
|
||||
/** @brief the MOSSE (Minimum Output Sum of Squared %Error) tracker
|
||||
|
||||
The implementation is based on @cite MOSSE Visual Object Tracking using Adaptive Correlation Filters |
||||
@note this tracker works with grayscale images, if passed bgr ones, they will get converted internally. |
||||
*/ |
||||
|
||||
class CV_EXPORTS_W TrackerMOSSE : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
/** @brief Constructor
|
||||
*/ |
||||
CV_WRAP static Ptr<legacy::TrackerMOSSE> create(); |
||||
|
||||
virtual ~TrackerMOSSE() CV_OVERRIDE {} |
||||
}; |
||||
|
||||
|
||||
/************************************ MultiTracker Class ---By Laksono Kurnianggoro---) ************************************/ |
||||
/** @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 Algorithm |
||||
{ |
||||
public: |
||||
|
||||
/**
|
||||
* \brief Constructor. |
||||
*/ |
||||
CV_WRAP MultiTracker(); |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
~MultiTracker() CV_OVERRIDE; |
||||
|
||||
/**
|
||||
* \brief Add a new object to be tracked. |
||||
* |
||||
* @param newTracker tracking algorithm to be used |
||||
* @param image input image |
||||
* @param boundingBox a rectangle represents ROI of the tracked object |
||||
*/ |
||||
CV_WRAP bool add(Ptr<cv::legacy::Tracker> newTracker, InputArray image, const Rect2d& boundingBox); |
||||
|
||||
/**
|
||||
* \brief Add a set of objects to be tracked. |
||||
* @param newTrackers list of tracking algorithms to be used |
||||
* @param image input image |
||||
* @param boundingBox list of the tracked objects |
||||
*/ |
||||
bool add(std::vector<Ptr<legacy::Tracker> > newTrackers, InputArray 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(InputArray image); |
||||
|
||||
/**
|
||||
* \brief Update the current tracking status. |
||||
* @param image input image |
||||
* @param boundingBox the tracking result, represent a list of ROIs of the tracked objects. |
||||
*/ |
||||
CV_WRAP bool update(InputArray image, CV_OUT std::vector<Rect2d> & boundingBox); |
||||
|
||||
/**
|
||||
* \brief Returns a reference to a storage for the tracked objects, each object corresponds to one tracker algorithm |
||||
*/ |
||||
CV_WRAP const std::vector<Rect2d>& getObjects() const; |
||||
|
||||
/**
|
||||
* \brief Returns a pointer to a new instance of MultiTracker |
||||
*/ |
||||
CV_WRAP static Ptr<MultiTracker> create(); |
||||
|
||||
protected: |
||||
//!< storage for the tracker algorithms.
|
||||
std::vector< Ptr<Tracker> > trackerList; |
||||
|
||||
//!< storage for the tracked objects, each object corresponds to one tracker algorithm.
|
||||
std::vector<Rect2d> objects; |
||||
}; |
||||
|
||||
/************************************ Multi-Tracker Classes ---By Tyan Vladimir---************************************/ |
||||
|
||||
/** @brief Base abstract class for the long-term Multi Object Trackers:
|
||||
|
||||
@sa Tracker, MultiTrackerTLD |
||||
*/ |
||||
class CV_EXPORTS MultiTracker_Alt |
||||
{ |
||||
public: |
||||
/** @brief Constructor for Multitracker
|
||||
*/ |
||||
MultiTracker_Alt() |
||||
{ |
||||
targetNum = 0; |
||||
} |
||||
|
||||
/** @brief Add a new target to a tracking-list and initialize the tracker with a known bounding box that surrounded the target
|
||||
@param image The initial frame |
||||
@param boundingBox The initial bounding box of target |
||||
@param tracker_algorithm Multi-tracker algorithm |
||||
|
||||
@return True if new target initialization went succesfully, false otherwise |
||||
*/ |
||||
bool addTarget(InputArray image, const Rect2d& boundingBox, Ptr<legacy::Tracker> tracker_algorithm); |
||||
|
||||
/** @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets
|
||||
@param image The current frame |
||||
|
||||
@return True means that all targets were located and false means that tracker couldn't locate one of the targets 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) |
||||
*/ |
||||
bool update(InputArray image); |
||||
|
||||
/** @brief Current number of targets in tracking-list
|
||||
*/ |
||||
int targetNum; |
||||
|
||||
/** @brief Trackers list for Multi-Object-Tracker
|
||||
*/ |
||||
std::vector <Ptr<Tracker> > trackers; |
||||
|
||||
/** @brief Bounding Boxes list for Multi-Object-Tracker
|
||||
*/ |
||||
std::vector <Rect2d> boundingBoxes; |
||||
/** @brief List of randomly generated colors for bounding boxes display
|
||||
*/ |
||||
std::vector<Scalar> colors; |
||||
}; |
||||
|
||||
/** @brief Multi Object %Tracker for TLD.
|
||||
|
||||
TLD is a novel tracking framework that explicitly decomposes |
||||
the long-term tracking task into tracking, learning and detection. |
||||
|
||||
The tracker follows the object from frame to frame. The detector localizes all appearances that |
||||
have been observed so far and corrects the tracker if necessary. The learning estimates detector's |
||||
errors and updates it to avoid these errors in the future. The implementation is based on @cite TLD . |
||||
|
||||
The Median Flow algorithm (see cv::TrackerMedianFlow) was chosen as a tracking component in this |
||||
implementation, following authors. The tracker is supposed to be able to handle rapid motions, partial |
||||
occlusions, object absence etc. |
||||
|
||||
@sa Tracker, MultiTracker, TrackerTLD |
||||
*/ |
||||
class CV_EXPORTS MultiTrackerTLD : public MultiTracker_Alt |
||||
{ |
||||
public: |
||||
/** @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets by
|
||||
optimized update method using some techniques to speedup calculations specifically for MO TLD. The only limitation |
||||
is that all target bounding boxes should have approximately same aspect ratios. Speed boost is around 20% |
||||
|
||||
@param image The current frame. |
||||
|
||||
@return True means that all targets were located and false means that tracker couldn't locate one of the targets 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) |
||||
*/ |
||||
bool update_opt(InputArray image); |
||||
}; |
||||
|
||||
/*********************************** CSRT ************************************/ |
||||
/** @brief the CSRT tracker
|
||||
|
||||
The implementation is based on @cite Lukezic_IJCV2018 Discriminative Correlation Filter with Channel and Spatial Reliability |
||||
*/ |
||||
class CV_EXPORTS_W TrackerCSRT : public cv::legacy::Tracker |
||||
{ |
||||
public: |
||||
struct CV_EXPORTS Params : cv::tracking::TrackerCSRT::Params |
||||
{ |
||||
/**
|
||||
* \brief Read parameters from a file |
||||
*/ |
||||
void read(const FileNode& /*fn*/); |
||||
|
||||
/**
|
||||
* \brief Write parameters to a file |
||||
*/ |
||||
void write(cv::FileStorage& fs) const; |
||||
}; |
||||
|
||||
/** @brief Constructor
|
||||
@param parameters CSRT parameters TrackerCSRT::Params |
||||
*/ |
||||
static Ptr<legacy::TrackerCSRT> create(const TrackerCSRT::Params ¶meters); |
||||
|
||||
CV_WRAP static Ptr<legacy::TrackerCSRT> create(); |
||||
|
||||
CV_WRAP virtual void setInitialMask(InputArray mask) = 0; |
||||
|
||||
virtual ~TrackerCSRT() CV_OVERRIDE {} |
||||
}; |
||||
|
||||
|
||||
CV_EXPORTS_W Ptr<cv::tracking::Tracker> upgradeTrackingAPI(const Ptr<legacy::Tracker>& legacy_tracker); |
||||
|
||||
//! @}
|
||||
|
||||
#ifndef CV_DOXYGEN |
||||
} // namespace
|
||||
#endif |
||||
}} // namespace
|
||||
|
||||
#endif // OPENCV_TRACKING_LEGACY_HPP
|
@ -0,0 +1,5 @@ |
||||
{ |
||||
"namespaces_dict": { |
||||
"cv.legacy": "legacy" |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
package org.opencv.test.tracking; |
||||
|
||||
import org.opencv.core.Core; |
||||
import org.opencv.core.CvException; |
||||
import org.opencv.test.OpenCVTestCase; |
||||
|
||||
import org.opencv.tracking.Tracking; |
||||
import org.opencv.tracking.legacy_Tracker; |
||||
import org.opencv.tracking.legacy_TrackerTLD; |
||||
|
||||
public class TrackerCreateLegacyTest extends OpenCVTestCase { |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
} |
||||
|
||||
|
||||
public void testCreateLegacyTrackerTLD() { |
||||
legacy_Tracker tracker = legacy_TrackerTLD.create(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@ |
||||
package org.opencv.test.tracking; |
||||
|
||||
import org.opencv.core.Core; |
||||
import org.opencv.core.CvException; |
||||
import org.opencv.test.OpenCVTestCase; |
||||
|
||||
import org.opencv.tracking.Tracking; |
||||
import org.opencv.tracking.Tracker; |
||||
import org.opencv.tracking.TrackerGOTURN; |
||||
import org.opencv.tracking.TrackerKCF; |
||||
import org.opencv.tracking.TrackerMIL; |
||||
|
||||
public class TrackerCreateTest extends OpenCVTestCase { |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
} |
||||
|
||||
|
||||
public void testCreateTrackerGOTURN() { |
||||
try { |
||||
Tracker tracker = TrackerGOTURN.create(); |
||||
assert(tracker != null); |
||||
} catch (CvException e) { |
||||
// expected, model files may be missing
|
||||
} |
||||
} |
||||
|
||||
public void testCreateTrackerKCF() { |
||||
Tracker tracker = TrackerKCF.create(); |
||||
} |
||||
|
||||
public void testCreateTrackerMIL() { |
||||
Tracker tracker = TrackerMIL.create(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,6 @@ |
||||
#ifdef HAVE_OPENCV_TRACKING |
||||
typedef TrackerCSRT::Params TrackerCSRT_Params; |
||||
typedef TrackerKCF::Params TrackerKCF_Params; |
||||
typedef TrackerMIL::Params TrackerMIL_Params; |
||||
typedef TrackerGOTURN::Params TrackerGOTURN_Params; |
||||
#endif |
@ -0,0 +1,31 @@ |
||||
#!/usr/bin/env python |
||||
import os |
||||
import numpy as np |
||||
import cv2 as cv |
||||
|
||||
from tests_common import NewOpenCVTests, unittest |
||||
|
||||
class tracking_contrib_test(NewOpenCVTests): |
||||
|
||||
def test_createTracker(self): |
||||
|
||||
t = cv.TrackerMIL_create() |
||||
t = cv.TrackerKCF_create() |
||||
try: |
||||
t = cv.TrackerGOTURN_create() |
||||
except cv.error as e: |
||||
pass # may fail due to missing DL model files |
||||
|
||||
def test_createLegacyTracker(self): |
||||
|
||||
t = cv.legacy.TrackerBoosting_create() |
||||
t = cv.legacy.TrackerMIL_create() |
||||
t = cv.legacy.TrackerKCF_create() |
||||
t = cv.legacy.TrackerMedianFlow_create() |
||||
#t = cv.legacy.TrackerGOTURN_create() |
||||
t = cv.legacy.TrackerMOSSE_create() |
||||
t = cv.legacy.TrackerCSRT_create() |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
NewOpenCVTests.bootstrap() |
@ -1,412 +0,0 @@ |
||||
/*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 "perf_precomp.hpp" |
||||
|
||||
namespace opencv_test { namespace { |
||||
|
||||
//write sanity: ./bin/opencv_perf_tracking --perf_write_sanity=true --perf_min_samples=1
|
||||
//verify sanity: ./bin/opencv_perf_tracking --perf_min_samples=1
|
||||
|
||||
#define TESTSET_NAMES testing::Values("david","dudek","faceocc2") |
||||
//#define TESTSET_NAMES testing::internal::ValueArray1<string>("david")
|
||||
#define SEGMENTS testing::Values(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
||||
|
||||
const string TRACKING_DIR = "cv/tracking"; |
||||
const string FOLDER_IMG = "data"; |
||||
|
||||
typedef perf::TestBaseWithParam<tuple<string, int> > tracking; |
||||
|
||||
std::vector<std::string> splitString( std::string s, std::string delimiter ) |
||||
{ |
||||
std::vector<string> token; |
||||
size_t pos = 0; |
||||
while ( ( pos = s.find( delimiter ) ) != std::string::npos ) |
||||
{ |
||||
token.push_back( s.substr( 0, pos ) ); |
||||
s.erase( 0, pos + delimiter.length() ); |
||||
} |
||||
token.push_back( s ); |
||||
return token; |
||||
} |
||||
|
||||
void checkData( const string& datasetMeta, int& startFrame, string& prefix, string& suffix ) |
||||
{ |
||||
//get informations on the current test data
|
||||
FileStorage fs; |
||||
fs.open( datasetMeta, FileStorage::READ ); |
||||
fs["start"] >> startFrame; |
||||
fs["prefix"] >> prefix; |
||||
fs["suffix"] >> suffix; |
||||
fs.release(); |
||||
} |
||||
|
||||
bool getGroundTruth( const string& gtFile, vector<Rect>& gtBBs ) |
||||
{ |
||||
std::ifstream gt; |
||||
//open the ground truth
|
||||
gt.open( gtFile.c_str() ); |
||||
if( !gt.is_open() ) |
||||
{ |
||||
return false; |
||||
} |
||||
string line; |
||||
Rect currentBB; |
||||
while ( getline( gt, line ) ) |
||||
{ |
||||
vector<string> tokens = splitString( line, "," ); |
||||
|
||||
if( tokens.size() != 4 ) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
gtBBs.push_back( |
||||
Rect( atoi( tokens.at( 0 ).c_str() ), atoi( tokens.at( 1 ).c_str() ), atoi( tokens.at( 2 ).c_str() ), atoi( tokens.at( 3 ).c_str() ) ) ); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void getSegment( int segmentId, int numSegments, int bbCounter, int& startFrame, int& endFrame ) |
||||
{ |
||||
//compute the start and the and for each segment
|
||||
int gtStartFrame = startFrame; |
||||
int numFrame = bbCounter / numSegments; |
||||
startFrame += ( segmentId - 1 ) * numFrame; |
||||
endFrame = startFrame + numFrame; |
||||
|
||||
if( ( segmentId ) == numSegments ) |
||||
endFrame = bbCounter + gtStartFrame - 1; |
||||
} |
||||
|
||||
void getMatOfRects( const vector<Rect>& bbs, Mat& bbs_mat ) |
||||
{ |
||||
for ( int b = 0, size = (int)bbs.size(); b < size; b++ ) |
||||
{ |
||||
bbs_mat.at<float>( b, 0 ) = (float)bbs[b].x; |
||||
bbs_mat.at<float>( b, 1 ) = (float)bbs[b].y; |
||||
bbs_mat.at<float>( b, 2 ) = (float)bbs[b].width; |
||||
bbs_mat.at<float>( b, 3 ) = (float)bbs[b].height; |
||||
} |
||||
} |
||||
|
||||
PERF_TEST_P(tracking, mil, testing::Combine(TESTSET_NAMES, SEGMENTS)) |
||||
{ |
||||
string video = get<0>( GetParam() ); |
||||
int segmentId = get<1>( GetParam() ); |
||||
|
||||
int startFrame; |
||||
string prefix; |
||||
string suffix; |
||||
string datasetMeta = getDataPath( TRACKING_DIR + "/" + video + "/" + video + ".yml" ); |
||||
checkData( datasetMeta, startFrame, prefix, suffix ); |
||||
int gtStartFrame = startFrame; |
||||
|
||||
vector<Rect> gtBBs; |
||||
string gtFile = getDataPath( TRACKING_DIR + "/" + video + "/gt.txt" ); |
||||
if( !getGroundTruth( gtFile, gtBBs ) ) |
||||
FAIL()<< "Ground truth file " << gtFile << " can not be read" << endl; |
||||
int bbCounter = (int)gtBBs.size(); |
||||
|
||||
Mat frame; |
||||
bool initialized = false; |
||||
vector<Rect> bbs; |
||||
|
||||
Ptr<Tracker> tracker = TrackerMIL::create(); |
||||
string folder = TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; |
||||
int numSegments = ( sizeof ( SEGMENTS)/sizeof(int) ); |
||||
int endFrame = 0; |
||||
getSegment( segmentId, numSegments, bbCounter, startFrame, endFrame ); |
||||
|
||||
Rect currentBBi = gtBBs[startFrame - gtStartFrame]; |
||||
Rect2d currentBB(currentBBi); |
||||
|
||||
TEST_CYCLE_N(1) |
||||
{ |
||||
VideoCapture c; |
||||
c.open( getDataPath( TRACKING_DIR + "/" + video + "/" + FOLDER_IMG + "/" + video + ".webm" ) ); |
||||
c.set( CAP_PROP_POS_FRAMES, startFrame ); |
||||
|
||||
for ( int frameCounter = startFrame; frameCounter < endFrame; frameCounter++ ) |
||||
{ |
||||
c >> frame; |
||||
|
||||
if( frame.empty() ) |
||||
{ |
||||
break; |
||||
} |
||||
|
||||
if( !initialized ) |
||||
{ |
||||
if( !tracker->init( frame, currentBB ) ) |
||||
{ |
||||
FAIL()<< "Could not initialize tracker" << endl; |
||||
return; |
||||
} |
||||
initialized = true; |
||||
} |
||||
else if( initialized ) |
||||
{ |
||||
tracker->update( frame, currentBB ); |
||||
} |
||||
bbs.push_back( currentBB ); |
||||
|
||||
} |
||||
} |
||||
//save the bounding boxes in a Mat
|
||||
Mat bbs_mat( (int)bbs.size(), 4, CV_32F ); |
||||
getMatOfRects( bbs, bbs_mat ); |
||||
|
||||
SANITY_CHECK( bbs_mat, 15, ERROR_RELATIVE ); |
||||
|
||||
} |
||||
|
||||
PERF_TEST_P(tracking, boosting, testing::Combine(TESTSET_NAMES, SEGMENTS)) |
||||
{ |
||||
string video = get<0>( GetParam() ); |
||||
int segmentId = get<1>( GetParam() ); |
||||
|
||||
int startFrame; |
||||
string prefix; |
||||
string suffix; |
||||
string datasetMeta = getDataPath( TRACKING_DIR + "/" + video + "/" + video + ".yml" ); |
||||
checkData( datasetMeta, startFrame, prefix, suffix ); |
||||
int gtStartFrame = startFrame; |
||||
|
||||
vector<Rect> gtBBs; |
||||
string gtFile = getDataPath( TRACKING_DIR + "/" + video + "/gt.txt" ); |
||||
if( !getGroundTruth( gtFile, gtBBs ) ) |
||||
FAIL()<< "Ground truth file " << gtFile << " can not be read" << endl; |
||||
int bbCounter = (int)gtBBs.size(); |
||||
|
||||
Mat frame; |
||||
bool initialized = false; |
||||
vector<Rect> bbs; |
||||
|
||||
Ptr<Tracker> tracker = TrackerBoosting::create(); |
||||
string folder = TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; |
||||
int numSegments = ( sizeof ( SEGMENTS)/sizeof(int) ); |
||||
int endFrame = 0; |
||||
getSegment( segmentId, numSegments, bbCounter, startFrame, endFrame ); |
||||
|
||||
Rect currentBBi = gtBBs[startFrame - gtStartFrame]; |
||||
Rect2d currentBB(currentBBi); |
||||
|
||||
TEST_CYCLE_N(1) |
||||
{ |
||||
VideoCapture c; |
||||
c.open( getDataPath( TRACKING_DIR + "/" + video + "/" + FOLDER_IMG + "/" + video + ".webm" ) ); |
||||
c.set( CAP_PROP_POS_FRAMES, startFrame ); |
||||
for ( int frameCounter = startFrame; frameCounter < endFrame; frameCounter++ ) |
||||
{ |
||||
c >> frame; |
||||
|
||||
if( frame.empty() ) |
||||
{ |
||||
break; |
||||
} |
||||
|
||||
if( !initialized ) |
||||
{ |
||||
if( !tracker->init( frame, currentBB ) ) |
||||
{ |
||||
FAIL()<< "Could not initialize tracker" << endl; |
||||
return; |
||||
} |
||||
initialized = true; |
||||
} |
||||
else if( initialized ) |
||||
{ |
||||
tracker->update( frame, currentBB ); |
||||
} |
||||
bbs.push_back( currentBB ); |
||||
|
||||
} |
||||
} |
||||
//save the bounding boxes in a Mat
|
||||
Mat bbs_mat( (int)bbs.size(), 4, CV_32F ); |
||||
getMatOfRects( bbs, bbs_mat ); |
||||
|
||||
SANITY_CHECK( bbs_mat, 15, ERROR_RELATIVE ); |
||||
|
||||
} |
||||
|
||||
PERF_TEST_P(tracking, tld, testing::Combine(TESTSET_NAMES, SEGMENTS)) |
||||
{ |
||||
string video = get<0>( GetParam() ); |
||||
int segmentId = get<1>( GetParam() ); |
||||
|
||||
int startFrame; |
||||
string prefix; |
||||
string suffix; |
||||
string datasetMeta = getDataPath( TRACKING_DIR + "/" + video + "/" + video + ".yml" ); |
||||
checkData( datasetMeta, startFrame, prefix, suffix ); |
||||
int gtStartFrame = startFrame; |
||||
|
||||
vector<Rect> gtBBs; |
||||
string gtFile = getDataPath( TRACKING_DIR + "/" + video + "/gt.txt" ); |
||||
if( !getGroundTruth( gtFile, gtBBs ) ) |
||||
FAIL()<< "Ground truth file " << gtFile << " can not be read" << endl; |
||||
int bbCounter = (int)gtBBs.size(); |
||||
|
||||
Mat frame; |
||||
bool initialized = false; |
||||
vector<Rect> bbs; |
||||
|
||||
Ptr<Tracker> tracker = TrackerTLD::create(); |
||||
string folder = TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; |
||||
int numSegments = ( sizeof ( SEGMENTS)/sizeof(int) ); |
||||
int endFrame = 0; |
||||
getSegment( segmentId, numSegments, bbCounter, startFrame, endFrame ); |
||||
|
||||
Rect currentBBi = gtBBs[startFrame - gtStartFrame]; |
||||
Rect2d currentBB(currentBBi); |
||||
|
||||
TEST_CYCLE_N(1) |
||||
{ |
||||
VideoCapture c; |
||||
c.open( getDataPath( TRACKING_DIR + "/" + video + "/" + FOLDER_IMG + "/" + video + ".webm" ) ); |
||||
c.set( CAP_PROP_POS_FRAMES, startFrame ); |
||||
for ( int frameCounter = startFrame; frameCounter < endFrame; frameCounter++ ) |
||||
{ |
||||
c >> frame; |
||||
|
||||
if( frame.empty() ) |
||||
{ |
||||
break; |
||||
} |
||||
|
||||
if( !initialized ) |
||||
{ |
||||
if( !tracker->init( frame, currentBB ) ) |
||||
{ |
||||
FAIL()<< "Could not initialize tracker" << endl; |
||||
return; |
||||
} |
||||
initialized = true; |
||||
} |
||||
else if( initialized ) |
||||
{ |
||||
tracker->update( frame, currentBB ); |
||||
} |
||||
bbs.push_back( currentBB ); |
||||
|
||||
} |
||||
} |
||||
//save the bounding boxes in a Mat
|
||||
Mat bbs_mat( (int)bbs.size(), 4, CV_32F ); |
||||
getMatOfRects( bbs, bbs_mat ); |
||||
|
||||
SANITY_CHECK( bbs_mat, 15, ERROR_RELATIVE ); |
||||
|
||||
} |
||||
|
||||
PERF_TEST_P(tracking, GOTURN, testing::Combine(TESTSET_NAMES, SEGMENTS)) |
||||
{ |
||||
string video = get<0>(GetParam()); |
||||
int segmentId = get<1>(GetParam()); |
||||
|
||||
int startFrame; |
||||
string prefix; |
||||
string suffix; |
||||
string datasetMeta = getDataPath(TRACKING_DIR + "/" + video + "/" + video + ".yml"); |
||||
checkData(datasetMeta, startFrame, prefix, suffix); |
||||
int gtStartFrame = startFrame; |
||||
|
||||
vector<Rect> gtBBs; |
||||
string gtFile = getDataPath(TRACKING_DIR + "/" + video + "/gt.txt"); |
||||
if (!getGroundTruth(gtFile, gtBBs)) |
||||
FAIL() << "Ground truth file " << gtFile << " can not be read" << endl; |
||||
int bbCounter = (int)gtBBs.size(); |
||||
|
||||
Mat frame; |
||||
bool initialized = false; |
||||
vector<Rect> bbs; |
||||
|
||||
Ptr<Tracker> tracker = TrackerGOTURN::create(); |
||||
string folder = TRACKING_DIR + "/" + video + "/" + FOLDER_IMG; |
||||
int numSegments = (sizeof(SEGMENTS) / sizeof(int)); |
||||
int endFrame = 0; |
||||
getSegment(segmentId, numSegments, bbCounter, startFrame, endFrame); |
||||
|
||||
Rect currentBBi = gtBBs[startFrame - gtStartFrame]; |
||||
Rect2d currentBB(currentBBi); |
||||
|
||||
TEST_CYCLE_N(1) |
||||
{ |
||||
VideoCapture c; |
||||
c.open(getDataPath(TRACKING_DIR + "/" + video + "/" + FOLDER_IMG + "/" + video + ".webm")); |
||||
c.set(CAP_PROP_POS_FRAMES, startFrame); |
||||
for (int frameCounter = startFrame; frameCounter < endFrame; frameCounter++) |
||||
{ |
||||
c >> frame; |
||||
|
||||
if (frame.empty()) |
||||
{ |
||||
break; |
||||
} |
||||
|
||||
if (!initialized) |
||||
{ |
||||
if (!tracker->init(frame, currentBB)) |
||||
{ |
||||
FAIL() << "Could not initialize tracker" << endl; |
||||
return; |
||||
} |
||||
initialized = true; |
||||
} |
||||
else if (initialized) |
||||
{ |
||||
tracker->update(frame, currentBB); |
||||
} |
||||
bbs.push_back(currentBB); |
||||
|
||||
} |
||||
} |
||||
//save the bounding boxes in a Mat
|
||||
Mat bbs_mat((int)bbs.size(), 4, CV_32F); |
||||
getMatOfRects(bbs, bbs_mat); |
||||
|
||||
SANITY_CHECK(bbs_mat, 15, ERROR_RELATIVE); |
||||
|
||||
} |
||||
|
||||
}} // namespace
|
@ -0,0 +1,119 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
#include <opencv2/tracking/tracking_legacy.hpp> |
||||
|
||||
namespace opencv_test { namespace { |
||||
using namespace perf; |
||||
|
||||
//using namespace cv::tracking;
|
||||
|
||||
typedef tuple<string, int, Rect> TrackingParams_t; |
||||
|
||||
std::vector<TrackingParams_t> getTrackingParams() |
||||
{ |
||||
std::vector<TrackingParams_t> params { |
||||
TrackingParams_t("david/data/david.webm", 300, Rect(163,62,47,56)), |
||||
TrackingParams_t("dudek/data/dudek.webm", 1, Rect(123,87,132,176)), |
||||
TrackingParams_t("faceocc2/data/faceocc2.webm", 1, Rect(118,57,82,98)) |
||||
}; |
||||
return params; |
||||
} |
||||
|
||||
class Tracking : public perf::TestBaseWithParam<TrackingParams_t> |
||||
{ |
||||
public: |
||||
template<typename ROI_t = Rect2d, typename Tracker> |
||||
void runTrackingTest(const Ptr<Tracker>& tracker, const TrackingParams_t& params); |
||||
}; |
||||
|
||||
template<typename ROI_t, typename Tracker> |
||||
void Tracking::runTrackingTest(const Ptr<Tracker>& tracker, const TrackingParams_t& params) |
||||
{ |
||||
const int N = 10; |
||||
string video = get<0>(params); |
||||
int startFrame = get<1>(params); |
||||
//int endFrame = startFrame + N;
|
||||
Rect boundingBox = get<2>(params); |
||||
|
||||
string videoPath = findDataFile(std::string("cv/tracking/") + video); |
||||
|
||||
VideoCapture c; |
||||
c.open(videoPath); |
||||
ASSERT_TRUE(c.isOpened()) << videoPath; |
||||
#if 0 |
||||
// c.set(CAP_PROP_POS_FRAMES, startFrame);
|
||||
#else |
||||
if (startFrame) |
||||
std::cout << "startFrame = " << startFrame << std::endl; |
||||
for (int i = 0; i < startFrame; i++) |
||||
{ |
||||
Mat dummy_frame; |
||||
c >> dummy_frame; |
||||
ASSERT_FALSE(dummy_frame.empty()) << i << ": " << videoPath; |
||||
} |
||||
#endif |
||||
|
||||
// decode frames into memory (don't measure decoding performance)
|
||||
std::vector<Mat> frames; |
||||
for (int i = 0; i < N; ++i) |
||||
{ |
||||
Mat frame; |
||||
c >> frame; |
||||
ASSERT_FALSE(frame.empty()) << "i=" << i; |
||||
frames.push_back(frame); |
||||
} |
||||
|
||||
std::cout << "frame size = " << frames[0].size() << std::endl; |
||||
|
||||
PERF_SAMPLE_BEGIN(); |
||||
{ |
||||
tracker->init(frames[0], (ROI_t)boundingBox); |
||||
for (int i = 1; i < N; ++i) |
||||
{ |
||||
ROI_t rc; |
||||
tracker->update(frames[i], rc); |
||||
ASSERT_FALSE(rc.empty()); |
||||
} |
||||
} |
||||
PERF_SAMPLE_END(); |
||||
|
||||
SANITY_CHECK_NOTHING(); |
||||
} |
||||
|
||||
|
||||
//==================================================================================================
|
||||
|
||||
PERF_TEST_P(Tracking, MIL, testing::ValuesIn(getTrackingParams())) |
||||
{ |
||||
auto tracker = TrackerMIL::create(); |
||||
runTrackingTest<Rect>(tracker, GetParam()); |
||||
} |
||||
|
||||
PERF_TEST_P(Tracking, Boosting, testing::ValuesIn(getTrackingParams())) |
||||
{ |
||||
auto tracker = legacy::TrackerBoosting::create(); |
||||
runTrackingTest(tracker, GetParam()); |
||||
} |
||||
|
||||
PERF_TEST_P(Tracking, TLD, testing::ValuesIn(getTrackingParams())) |
||||
{ |
||||
auto tracker = legacy::TrackerTLD::create(); |
||||
runTrackingTest(tracker, GetParam()); |
||||
} |
||||
|
||||
PERF_TEST_P(Tracking, GOTURN, testing::ValuesIn(getTrackingParams())) |
||||
{ |
||||
std::string model = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.prototxt"); |
||||
std::string weights = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.caffemodel", false); |
||||
TrackerGOTURN::Params params; |
||||
params.modelTxt = model; |
||||
params.modelBin = weights; |
||||
auto tracker = TrackerGOTURN::create(params); |
||||
runTrackingTest<Rect>(tracker, GetParam()); |
||||
} |
||||
|
||||
}} // namespace
|
@ -1,80 +0,0 @@ |
||||
|
||||
/*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*/
|
||||
|
||||
#ifndef OPENCV_GOTURN_TRACKER |
||||
#define OPENCV_GOTURN_TRACKER |
||||
|
||||
#include "precomp.hpp" |
||||
#include "opencv2/video/tracking.hpp" |
||||
#include "gtrUtils.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
|
||||
#include <algorithm> |
||||
#include <limits.h> |
||||
|
||||
#include "opencv2/opencv_modules.hpp" |
||||
#ifdef HAVE_OPENCV_DNN |
||||
#include "opencv2/dnn.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace gtr |
||||
{ |
||||
|
||||
class TrackerGOTURNImpl : public TrackerGOTURN |
||||
{ |
||||
public: |
||||
TrackerGOTURNImpl(const TrackerGOTURN::Params ¶meters = TrackerGOTURN::Params()); |
||||
void read(const FileNode& fn) CV_OVERRIDE; |
||||
void write(FileStorage& fs) const CV_OVERRIDE; |
||||
bool initImpl(const Mat& image, const Rect2d& boundingBox) CV_OVERRIDE; |
||||
bool updateImpl(const Mat& image, Rect2d& boundingBox) CV_OVERRIDE; |
||||
|
||||
TrackerGOTURN::Params params; |
||||
|
||||
dnn::Net net; |
||||
}; |
||||
|
||||
} |
||||
} |
||||
#endif |
||||
#endif |
@ -0,0 +1,140 @@ |
||||
/*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 "opencv2/tracking/tracking_legacy.hpp" |
||||
|
||||
namespace cv { |
||||
namespace legacy { |
||||
inline namespace tracking { |
||||
|
||||
Tracker::Tracker() |
||||
{ |
||||
isInit = false; |
||||
} |
||||
|
||||
Tracker::~Tracker() |
||||
{ |
||||
} |
||||
|
||||
bool Tracker::init( InputArray image, const Rect2d& boundingBox ) |
||||
{ |
||||
|
||||
if( isInit ) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
if( image.empty() ) |
||||
return false; |
||||
|
||||
sampler = Ptr<TrackerSampler>( new TrackerSampler() ); |
||||
featureSet = Ptr<TrackerFeatureSet>( new TrackerFeatureSet() ); |
||||
model = Ptr<TrackerModel>(); |
||||
|
||||
bool initTracker = initImpl( image.getMat(), boundingBox ); |
||||
|
||||
//check if the model component is initialized
|
||||
if (!model) |
||||
{ |
||||
CV_Error( -1, "The model is not initialized" ); |
||||
} |
||||
|
||||
if( initTracker ) |
||||
{ |
||||
isInit = true; |
||||
} |
||||
|
||||
return initTracker; |
||||
} |
||||
|
||||
bool Tracker::update( InputArray image, Rect2d& boundingBox ) |
||||
{ |
||||
|
||||
if( !isInit ) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
if( image.empty() ) |
||||
return false; |
||||
|
||||
return updateImpl( image.getMat(), boundingBox ); |
||||
} |
||||
|
||||
|
||||
|
||||
class LegacyTrackerWrapper : public cv::tracking::Tracker |
||||
{ |
||||
const Ptr<legacy::Tracker> legacy_tracker_; |
||||
public: |
||||
LegacyTrackerWrapper(const Ptr<legacy::Tracker>& legacy_tracker) : legacy_tracker_(legacy_tracker) |
||||
{ |
||||
CV_Assert(legacy_tracker_); |
||||
} |
||||
virtual ~LegacyTrackerWrapper() CV_OVERRIDE {}; |
||||
|
||||
void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE |
||||
{ |
||||
CV_DbgAssert(legacy_tracker_); |
||||
legacy_tracker_->init(image, (Rect2d)boundingBox); |
||||
} |
||||
|
||||
bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE |
||||
{ |
||||
CV_DbgAssert(legacy_tracker_); |
||||
Rect2d boundingBox2d; |
||||
bool res = legacy_tracker_->update(image, boundingBox2d); |
||||
int x1 = cvRound(boundingBox2d.x); |
||||
int y1 = cvRound(boundingBox2d.y); |
||||
int x2 = cvRound(boundingBox2d.x + boundingBox2d.width); |
||||
int y2 = cvRound(boundingBox2d.y + boundingBox2d.height); |
||||
boundingBox = Rect(x1, y1, x2 - x1, y2 - y1) & Rect(Point(0, 0), image.size()); |
||||
return res; |
||||
} |
||||
}; |
||||
|
||||
|
||||
CV_EXPORTS_W Ptr<cv::tracking::Tracker> upgradeTrackingAPI(const Ptr<legacy::Tracker>& legacy_tracker) |
||||
{ |
||||
return makePtr<LegacyTrackerWrapper>(legacy_tracker); |
||||
} |
||||
|
||||
}}} // namespace
|
@ -0,0 +1,159 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "opencv2/tracking/tracking_legacy.hpp" |
||||
|
||||
namespace cv { |
||||
namespace legacy { |
||||
inline namespace tracking { |
||||
namespace impl { |
||||
|
||||
class TrackerCSRTImpl CV_FINAL : public legacy::TrackerCSRT |
||||
{ |
||||
public: |
||||
cv::tracking::impl::TrackerCSRTImpl impl; |
||||
|
||||
TrackerCSRTImpl(const legacy::TrackerCSRT::Params ¶meters) |
||||
: impl(parameters) |
||||
{ |
||||
isInit = false; |
||||
} |
||||
|
||||
void read(const FileNode& fn) CV_OVERRIDE |
||||
{ |
||||
static_cast<legacy::TrackerCSRT::Params&>(impl.params).read(fn); |
||||
} |
||||
void write(FileStorage& fs) const CV_OVERRIDE |
||||
{ |
||||
static_cast<const legacy::TrackerCSRT::Params&>(impl.params).write(fs); |
||||
} |
||||
|
||||
bool initImpl(const Mat& image, const Rect2d& boundingBox) CV_OVERRIDE |
||||
{ |
||||
impl.init(image, boundingBox); |
||||
model = impl.model; |
||||
sampler = makePtr<TrackerSampler>(); |
||||
featureSet = makePtr<TrackerFeatureSet>(); |
||||
isInit = true; |
||||
return true; |
||||
} |
||||
bool updateImpl(const Mat& image, Rect2d& boundingBox) CV_OVERRIDE |
||||
{ |
||||
Rect bb; |
||||
bool res = impl.update(image, bb); |
||||
boundingBox = bb; |
||||
return res; |
||||
} |
||||
|
||||
virtual void setInitialMask(InputArray mask) CV_OVERRIDE |
||||
{ |
||||
impl.setInitialMask(mask); |
||||
} |
||||
}; |
||||
|
||||
} // namespace
|
||||
|
||||
void legacy::TrackerCSRT::Params::read(const FileNode& fn) |
||||
{ |
||||
*this = TrackerCSRT::Params(); |
||||
if(!fn["padding"].empty()) |
||||
fn["padding"] >> padding; |
||||
if(!fn["template_size"].empty()) |
||||
fn["template_size"] >> template_size; |
||||
if(!fn["gsl_sigma"].empty()) |
||||
fn["gsl_sigma"] >> gsl_sigma; |
||||
if(!fn["hog_orientations"].empty()) |
||||
fn["hog_orientations"] >> hog_orientations; |
||||
if(!fn["num_hog_channels_used"].empty()) |
||||
fn["num_hog_channels_used"] >> num_hog_channels_used; |
||||
if(!fn["hog_clip"].empty()) |
||||
fn["hog_clip"] >> hog_clip; |
||||
if(!fn["use_hog"].empty()) |
||||
fn["use_hog"] >> use_hog; |
||||
if(!fn["use_color_names"].empty()) |
||||
fn["use_color_names"] >> use_color_names; |
||||
if(!fn["use_gray"].empty()) |
||||
fn["use_gray"] >> use_gray; |
||||
if(!fn["use_rgb"].empty()) |
||||
fn["use_rgb"] >> use_rgb; |
||||
if(!fn["window_function"].empty()) |
||||
fn["window_function"] >> window_function; |
||||
if(!fn["kaiser_alpha"].empty()) |
||||
fn["kaiser_alpha"] >> kaiser_alpha; |
||||
if(!fn["cheb_attenuation"].empty()) |
||||
fn["cheb_attenuation"] >> cheb_attenuation; |
||||
if(!fn["filter_lr"].empty()) |
||||
fn["filter_lr"] >> filter_lr; |
||||
if(!fn["admm_iterations"].empty()) |
||||
fn["admm_iterations"] >> admm_iterations; |
||||
if(!fn["number_of_scales"].empty()) |
||||
fn["number_of_scales"] >> number_of_scales; |
||||
if(!fn["scale_sigma_factor"].empty()) |
||||
fn["scale_sigma_factor"] >> scale_sigma_factor; |
||||
if(!fn["scale_model_max_area"].empty()) |
||||
fn["scale_model_max_area"] >> scale_model_max_area; |
||||
if(!fn["scale_lr"].empty()) |
||||
fn["scale_lr"] >> scale_lr; |
||||
if(!fn["scale_step"].empty()) |
||||
fn["scale_step"] >> scale_step; |
||||
if(!fn["use_channel_weights"].empty()) |
||||
fn["use_channel_weights"] >> use_channel_weights; |
||||
if(!fn["weights_lr"].empty()) |
||||
fn["weights_lr"] >> weights_lr; |
||||
if(!fn["use_segmentation"].empty()) |
||||
fn["use_segmentation"] >> use_segmentation; |
||||
if(!fn["histogram_bins"].empty()) |
||||
fn["histogram_bins"] >> histogram_bins; |
||||
if(!fn["background_ratio"].empty()) |
||||
fn["background_ratio"] >> background_ratio; |
||||
if(!fn["histogram_lr"].empty()) |
||||
fn["histogram_lr"] >> histogram_lr; |
||||
if(!fn["psr_threshold"].empty()) |
||||
fn["psr_threshold"] >> psr_threshold; |
||||
CV_Assert(number_of_scales % 2 == 1); |
||||
CV_Assert(use_gray || use_color_names || use_hog || use_rgb); |
||||
} |
||||
void legacy::TrackerCSRT::Params::write(FileStorage& fs) const |
||||
{ |
||||
fs << "padding" << padding; |
||||
fs << "template_size" << template_size; |
||||
fs << "gsl_sigma" << gsl_sigma; |
||||
fs << "hog_orientations" << hog_orientations; |
||||
fs << "num_hog_channels_used" << num_hog_channels_used; |
||||
fs << "hog_clip" << hog_clip; |
||||
fs << "use_hog" << use_hog; |
||||
fs << "use_color_names" << use_color_names; |
||||
fs << "use_gray" << use_gray; |
||||
fs << "use_rgb" << use_rgb; |
||||
fs << "window_function" << window_function; |
||||
fs << "kaiser_alpha" << kaiser_alpha; |
||||
fs << "cheb_attenuation" << cheb_attenuation; |
||||
fs << "filter_lr" << filter_lr; |
||||
fs << "admm_iterations" << admm_iterations; |
||||
fs << "number_of_scales" << number_of_scales; |
||||
fs << "scale_sigma_factor" << scale_sigma_factor; |
||||
fs << "scale_model_max_area" << scale_model_max_area; |
||||
fs << "scale_lr" << scale_lr; |
||||
fs << "scale_step" << scale_step; |
||||
fs << "use_channel_weights" << use_channel_weights; |
||||
fs << "weights_lr" << weights_lr; |
||||
fs << "use_segmentation" << use_segmentation; |
||||
fs << "histogram_bins" << histogram_bins; |
||||
fs << "background_ratio" << background_ratio; |
||||
fs << "histogram_lr" << histogram_lr; |
||||
fs << "psr_threshold" << psr_threshold; |
||||
} |
||||
|
||||
}} // namespace
|
||||
|
||||
Ptr<legacy::TrackerCSRT> legacy::TrackerCSRT::create(const legacy::TrackerCSRT::Params ¶meters) |
||||
{ |
||||
return makePtr<legacy::tracking::impl::TrackerCSRTImpl>(parameters); |
||||
} |
||||
Ptr<legacy::TrackerCSRT> legacy::TrackerCSRT::create() |
||||
{ |
||||
return create(legacy::TrackerCSRT::Params()); |
||||
} |
||||
|
||||
} // namespace
|
@ -0,0 +1,173 @@ |
||||
/*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 "opencv2/tracking/tracking_legacy.hpp" |
||||
|
||||
namespace cv { |
||||
namespace legacy { |
||||
inline namespace tracking { |
||||
namespace impl { |
||||
|
||||
/*---------------------------
|
||||
| TrackerKCF |
||||
|---------------------------*/ |
||||
class TrackerKCFImpl CV_FINAL : public legacy::TrackerKCF |
||||
{ |
||||
public: |
||||
cv::tracking::impl::TrackerKCFImpl impl; |
||||
|
||||
TrackerKCFImpl(const legacy::TrackerKCF::Params ¶meters) |
||||
: impl(parameters) |
||||
{ |
||||
isInit = false; |
||||
} |
||||
void read(const FileNode& fn) CV_OVERRIDE |
||||
{ |
||||
static_cast<legacy::TrackerKCF::Params&>(impl.params).read(fn); |
||||
} |
||||
void write(FileStorage& fs) const CV_OVERRIDE |
||||
{ |
||||
static_cast<const legacy::TrackerKCF::Params&>(impl.params).write(fs); |
||||
} |
||||
|
||||
bool initImpl(const Mat& image, const Rect2d& boundingBox) CV_OVERRIDE |
||||
{ |
||||
impl.init(image, boundingBox); |
||||
model = impl.model; |
||||
sampler = makePtr<TrackerSampler>(); |
||||
featureSet = makePtr<TrackerFeatureSet>(); |
||||
isInit = true; |
||||
return true; |
||||
} |
||||
bool updateImpl(const Mat& image, Rect2d& boundingBox) CV_OVERRIDE |
||||
{ |
||||
Rect bb; |
||||
bool res = impl.update(image, bb); |
||||
boundingBox = bb; |
||||
return res; |
||||
} |
||||
void setFeatureExtractor(void (*f)(const Mat, const Rect, Mat&), bool pca_func = false) CV_OVERRIDE |
||||
{ |
||||
impl.setFeatureExtractor(f, pca_func); |
||||
} |
||||
}; |
||||
|
||||
} // namespace
|
||||
|
||||
void legacy::TrackerKCF::Params::read(const cv::FileNode& fn) |
||||
{ |
||||
*this = TrackerKCF::Params(); |
||||
|
||||
if (!fn["detect_thresh"].empty()) |
||||
fn["detect_thresh"] >> detect_thresh; |
||||
|
||||
if (!fn["sigma"].empty()) |
||||
fn["sigma"] >> sigma; |
||||
|
||||
if (!fn["lambda"].empty()) |
||||
fn["lambda"] >> lambda; |
||||
|
||||
if (!fn["interp_factor"].empty()) |
||||
fn["interp_factor"] >> interp_factor; |
||||
|
||||
if (!fn["output_sigma_factor"].empty()) |
||||
fn["output_sigma_factor"] >> output_sigma_factor; |
||||
|
||||
if (!fn["resize"].empty()) |
||||
fn["resize"] >> resize; |
||||
|
||||
if (!fn["max_patch_size"].empty()) |
||||
fn["max_patch_size"] >> max_patch_size; |
||||
|
||||
if (!fn["split_coeff"].empty()) |
||||
fn["split_coeff"] >> split_coeff; |
||||
|
||||
if (!fn["wrap_kernel"].empty()) |
||||
fn["wrap_kernel"] >> wrap_kernel; |
||||
|
||||
|
||||
if (!fn["desc_npca"].empty()) |
||||
fn["desc_npca"] >> desc_npca; |
||||
|
||||
if (!fn["desc_pca"].empty()) |
||||
fn["desc_pca"] >> desc_pca; |
||||
|
||||
if (!fn["compress_feature"].empty()) |
||||
fn["compress_feature"] >> compress_feature; |
||||
|
||||
if (!fn["compressed_size"].empty()) |
||||
fn["compressed_size"] >> compressed_size; |
||||
|
||||
if (!fn["pca_learning_rate"].empty()) |
||||
fn["pca_learning_rate"] >> pca_learning_rate; |
||||
} |
||||
|
||||
void legacy::TrackerKCF::Params::write(cv::FileStorage& fs) const |
||||
{ |
||||
fs << "detect_thresh" << detect_thresh; |
||||
fs << "sigma" << sigma; |
||||
fs << "lambda" << lambda; |
||||
fs << "interp_factor" << interp_factor; |
||||
fs << "output_sigma_factor" << output_sigma_factor; |
||||
fs << "resize" << resize; |
||||
fs << "max_patch_size" << max_patch_size; |
||||
fs << "split_coeff" << split_coeff; |
||||
fs << "wrap_kernel" << wrap_kernel; |
||||
fs << "desc_npca" << desc_npca; |
||||
fs << "desc_pca" << desc_pca; |
||||
fs << "compress_feature" << compress_feature; |
||||
fs << "compressed_size" << compressed_size; |
||||
fs << "pca_learning_rate" << pca_learning_rate; |
||||
} |
||||
|
||||
|
||||
}} // namespace legacy::tracking
|
||||
|
||||
Ptr<legacy::TrackerKCF> legacy::TrackerKCF::create(const legacy::TrackerKCF::Params ¶meters) |
||||
{ |
||||
return makePtr<legacy::tracking::impl::TrackerKCFImpl>(parameters); |
||||
} |
||||
Ptr<legacy::TrackerKCF> legacy::TrackerKCF::create() |
||||
{ |
||||
return create(legacy::TrackerKCF::Params()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,122 @@ |
||||
/*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 "opencv2/tracking/tracking_legacy.hpp" |
||||
|
||||
namespace cv { |
||||
namespace legacy { |
||||
inline namespace tracking { |
||||
namespace impl { |
||||
|
||||
class TrackerMILImpl CV_FINAL : public legacy::TrackerMIL |
||||
{ |
||||
public: |
||||
cv::tracking::impl::TrackerMILImpl impl; |
||||
|
||||
TrackerMILImpl(const legacy::TrackerMIL::Params ¶meters) |
||||
: impl(parameters) |
||||
{ |
||||
isInit = false; |
||||
} |
||||
|
||||
void read(const FileNode& fn) CV_OVERRIDE |
||||
{ |
||||
static_cast<legacy::TrackerMIL::Params&>(impl.params).read(fn); |
||||
} |
||||
void write(FileStorage& fs) const CV_OVERRIDE |
||||
{ |
||||
static_cast<const legacy::TrackerMIL::Params&>(impl.params).write(fs); |
||||
} |
||||
|
||||
bool initImpl(const Mat& image, const Rect2d& boundingBox) CV_OVERRIDE |
||||
{ |
||||
impl.init(image, boundingBox); |
||||
model = impl.model; |
||||
featureSet = impl.featureSet; |
||||
sampler = impl.sampler; |
||||
isInit = true; |
||||
return true; |
||||
} |
||||
bool updateImpl(const Mat& image, Rect2d& boundingBox) CV_OVERRIDE |
||||
{ |
||||
Rect bb; |
||||
bool res = impl.update(image, bb); |
||||
boundingBox = bb; |
||||
return res; |
||||
} |
||||
}; |
||||
|
||||
} // namespace
|
||||
|
||||
void legacy::TrackerMIL::Params::read(const cv::FileNode& fn) |
||||
{ |
||||
samplerInitInRadius = fn["samplerInitInRadius"]; |
||||
samplerSearchWinSize = fn["samplerSearchWinSize"]; |
||||
samplerInitMaxNegNum = fn["samplerInitMaxNegNum"]; |
||||
samplerTrackInRadius = fn["samplerTrackInRadius"]; |
||||
samplerTrackMaxPosNum = fn["samplerTrackMaxPosNum"]; |
||||
samplerTrackMaxNegNum = fn["samplerTrackMaxNegNum"]; |
||||
featureSetNumFeatures = fn["featureSetNumFeatures"]; |
||||
} |
||||
|
||||
void legacy::TrackerMIL::Params::write(cv::FileStorage& fs) const |
||||
{ |
||||
fs << "samplerInitInRadius" << samplerInitInRadius; |
||||
fs << "samplerSearchWinSize" << samplerSearchWinSize; |
||||
fs << "samplerInitMaxNegNum" << samplerInitMaxNegNum; |
||||
fs << "samplerTrackInRadius" << samplerTrackInRadius; |
||||
fs << "samplerTrackMaxPosNum" << samplerTrackMaxPosNum; |
||||
fs << "samplerTrackMaxNegNum" << samplerTrackMaxNegNum; |
||||
fs << "featureSetNumFeatures" << featureSetNumFeatures; |
||||
} |
||||
|
||||
}} // namespace
|
||||
|
||||
Ptr<legacy::TrackerMIL> legacy::TrackerMIL::create(const legacy::TrackerMIL::Params ¶meters) |
||||
{ |
||||
return makePtr<legacy::tracking::impl::TrackerMILImpl>(parameters); |
||||
} |
||||
Ptr<legacy::TrackerMIL> legacy::TrackerMIL::create() |
||||
{ |
||||
return create(legacy::TrackerMIL::Params()); |
||||
} |
||||
|
||||
} // namespace
|
@ -1,100 +1,23 @@ |
||||
/*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*/
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
/*
|
||||
* Tracker |
||||
*/ |
||||
namespace cv { |
||||
inline namespace tracking { |
||||
|
||||
Tracker::~Tracker() |
||||
Tracker::Tracker() |
||||
{ |
||||
// nothing
|
||||
} |
||||
|
||||
bool Tracker::init( InputArray image, const Rect2d& boundingBox ) |
||||
Tracker::~Tracker() |
||||
{ |
||||
|
||||
if( isInit ) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
if( image.empty() ) |
||||
return false; |
||||
|
||||
sampler = Ptr<TrackerSampler>( new TrackerSampler() ); |
||||
featureSet = Ptr<TrackerFeatureSet>( new TrackerFeatureSet() ); |
||||
model = Ptr<TrackerModel>(); |
||||
|
||||
bool initTracker = initImpl( image.getMat(), boundingBox ); |
||||
|
||||
//check if the model component is initialized
|
||||
if (!model) |
||||
{ |
||||
CV_Error( -1, "The model is not initialized" ); |
||||
} |
||||
|
||||
if( initTracker ) |
||||
{ |
||||
isInit = true; |
||||
} |
||||
|
||||
return initTracker; |
||||
// nothing
|
||||
} |
||||
|
||||
bool Tracker::update( InputArray image, Rect2d& boundingBox ) |
||||
{ |
||||
}} // namespace
|
||||
|
||||
if( !isInit ) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
if( image.empty() ) |
||||
return false; |
||||
|
||||
return updateImpl( image.getMat(), boundingBox ); |
||||
} |
||||
|
||||
} /* namespace cv */ |
||||
#include "legacy/tracker.legacy.hpp" |
||||
|
Loading…
Reference in new issue