00001 #ifndef CAMSHIFTTRACKER_H 00002 #define CAMSHIFTTRACKER_H 00003 00004 #include "cv.h" 00005 00006 #include "SimpleManeuveringFilter.h" 00007 00008 #ifdef WIN32 00009 #ifdef BUILD_DLL 00010 #define DLLIMPORTEXPORT __declspec(dllexport) 00011 #else 00012 #define DLLIMPORTEXPORT __declspec(dllimport) 00013 #endif 00014 #else 00015 #define DLLIMPORTEXPORT 00016 #endif 00017 00036 class DLLIMPORTEXPORT CAMShiftTracker { 00037 public: 00038 CAMShiftTracker(); 00039 virtual ~CAMShiftTracker(); 00040 00047 void setVmin(int vmin = 10) { this->vmin = vmin; } 00054 void setVmax(int vmax = 256) { this->vmax = vmax; } 00061 void setSmin(int smin = 30) { this->smin = smin; } 00068 int getVmin() const { return vmin; } 00075 int getVmax() const { return vmax; } 00082 int getSmin() const { return smin; } 00083 00084 00090 SimpleManeuveringFilter &getPositionFilter() { return positionFilter; } 00096 SimpleManeuveringFilter &getSizeFilter() { return sizeFilter; } 00102 SimpleManeuveringFilter &getAngleFilter() { return angleFilter; } 00106 void resetFilters(); 00107 00108 00119 void setMinArea(int a = 300) { minArea = a; } 00125 int getMinArea() { return minArea; } 00126 00127 00133 void run(IplImage* frame); 00134 00135 00141 IplImage* getImage() const { return image; } 00149 IplImage* getBackProject() const { 00150 cvCvtColor(backproject, colorBackproject, CV_GRAY2RGB); 00151 return colorBackproject; 00152 } 00160 IplImage* getHistogramImage() const { return histimg; } 00168 CvHistogram* getHistogram() const { return hist; } 00174 void drawEllipse(IplImage *image) const; 00181 CvBox2D getTrackBox() const { return track_box; } 00189 CvScalar getTrackColor() const { return tracking_color; } 00190 00199 void learn(CvRect selection) { this->selection = selection; track_object = -1; } 00204 void forget() { track_object = 0; cvZero(histimg); } 00211 void enableTracking(CvRect selection); 00212 00213 private: 00214 IplImage *image, *hsv, *hue, *mask, *backproject, *histimg, *colorBackproject; 00215 CvHistogram *hist; 00216 00217 int track_object; 00218 CvRect selection; 00219 CvRect track_window; 00220 CvBox2D track_box; 00221 CvConnectedComp track_comp; 00222 int hdims; 00223 int vmin, vmax, smin; 00224 00225 CvScalar tracking_color; 00226 00227 CvScalar hsv2rgb(float hue); 00228 void buildHistogram(CvRect selection); 00229 00230 SimpleManeuveringFilter positionFilter, sizeFilter, angleFilter; 00231 00232 int minArea; 00233 }; 00234 00235 #endif // CAMSHIFTTRACKER_H