File: %5BTutorial%5D%20Adding%20new%20Tracker%20Method%20for%20dummies

package info (click to toggle)
opencv 3.2.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 238,480 kB
  • sloc: xml: 901,650; cpp: 703,419; lisp: 20,142; java: 17,843; python: 17,641; ansic: 603; cs: 601; sh: 516; perl: 494; makefile: 117
file content (135 lines) | stat: -rw-r--r-- 3,277 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

/*---------------STEP 1---------------------*/
/* modify this file
*  opencv2/tracking/tracker.hpp
*  and put several lines of snippet similar to 
*  the following:
*/ 
/*------------------------------------------*/

class CV_EXPORTS_W TrackerKCF : public Tracker
{
 public:
  struct CV_EXPORTS Params
  {
    Params();
    void read( const FileNode& /*fn*/ );
    void write( FileStorage& /*fs*/ ) const;
  };

  /** @brief Constructor
    @param parameters KCF parameters TrackerKCF::Params
     */
  BOILERPLATE_CODE("KCF",TrackerKCF);
};


/*---------------STEP 2---------------------*/
/* modify this file
*  src/tracker.cpp
*  add one line in function  
*  Ptr<Tracker> Tracker::create( const String& trackerType )
*/ 
/*------------------------------------------*/

Ptr<Tracker> Tracker::create( const String& trackerType )
{
  BOILERPLATE_CODE("MIL",TrackerMIL);
  BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
  BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
  BOILERPLATE_CODE("TLD",TrackerTLD);
  BOILERPLATE_CODE("KCF",TrackerKCF); // add this line!
  return Ptr<Tracker>();
}


/*---------------STEP 3---------------------*/
/* make a new file and paste the snippet below
*  and modify it according to your needs.
*  also make sure to put the LICENSE part.
*  src/trackerKCF.cpp
*/
/*------------------------------------------*/

/*---------------------------
|  TrackerKCFModel
|---------------------------*/
namespace cv{
   /**
  * \brief Implementation of TrackerModel for MIL algorithm
  */
  class TrackerKCFModel : public TrackerModel{
  public:
    TrackerKCFModel(TrackerKCF::Params /*params*/){}
    ~TrackerKCFModel(){}
  protected:
    void modelEstimationImpl( const std::vector<Mat>& responses ){}
    void modelUpdateImpl(){}
  };
} /* namespace cv */


/*---------------------------
|  TrackerKCF
|---------------------------*/
namespace cv{
  
  /*
 * Prototype
 */
  class TrackerKCFImpl : public TrackerKCF{
  public:
    TrackerKCFImpl( const TrackerKCF::Params &parameters = TrackerKCF::Params() );
    void read( const FileNode& fn );
    void write( FileStorage& fs ) const;
  
  protected:
    bool initImpl( const Mat& image, const Rect2d& boundingBox );
    bool updateImpl( const Mat& image, Rect2d& boundingBox );
    
    TrackerKCF::Params params;
  };
    
  /*
 * Constructor
 */
  Ptr<TrackerKCF> TrackerKCF::createTracker(const TrackerKCF::Params &parameters){
      return Ptr<TrackerKCFImpl>(new TrackerKCFImpl(parameters));
  }
  TrackerKCFImpl::TrackerKCFImpl( const TrackerKCF::Params &parameters ) :
      params( parameters )
  {
    isInit = false;
  }
  
  void TrackerKCFImpl::read( const cv::FileNode& fn ){
    params.read( fn );
  }

  void TrackerKCFImpl::write( cv::FileStorage& fs ) const{
    params.write( fs );
  }
  
  
  bool TrackerKCFImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){
    model=Ptr<TrackerKCFModel>(new TrackerKCFModel(params));
    return true;
  }
  bool TrackerKCFImpl::updateImpl( const Mat& image, Rect2d& boundingBox ){return true;}
  
  /*
 * Parameters
 */
  TrackerKCF::Params::Params(){
      
  }

  void TrackerKCF::Params::read( const cv::FileNode& fn ){
    
  }

  void TrackerKCF::Params::write( cv::FileStorage& fs ) const{
    
  }
  
} /* namespace cv */