54 #include <visp/vpConfig.h>
55 #include <visp/vpColor.h>
56 #include <visp/vpImage.h>
58 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408))
60 #include <opencv2/video/tracking.hpp>
61 #include <opencv2/imgproc/imgproc.hpp>
62 #include <opencv2/highgui/highgui.hpp>
86 void addFeature(
const float &x,
const float &y);
87 void addFeature(
const long &
id,
const float &x,
const float &y);
88 void addFeature(
const cv::Point2f &f);
94 static void display(
const vpImage<vpRGBa> &I,
const std::vector<cv::Point2f> &features,
97 const std::vector<long> &featuresid,
99 static void display(
const vpImage<vpRGBa> &I,
const std::vector<cv::Point2f> &features,
100 const std::vector<long> &featuresid,
105 void getFeature(
const int &index,
int &
id,
float &x,
float &y)
const;
107 std::vector<cv::Point2f>
getFeatures()
const {
return m_points[1];}
137 void initTracking(
const cv::Mat &I,
const cv::Mat &mask=cv::Mat());
138 void initTracking(
const cv::Mat &I,
const std::vector<cv::Point2f> &pts);
139 void initTracking(
const cv::Mat &I,
const std::vector<cv::Point2f> &pts,
const std::vector<long> &ids);
142 void track(
const cv::Mat &I);
143 void setBlockSize(
const int blockSize);
144 void setHarrisFreeParameter(
double harris_k);
145 void setInitialGuess(
const std::vector<cv::Point2f> &guess_pts);
146 void setMaxFeatures(
const int maxCount);
147 void setMinDistance(
double minDistance);
148 void setMinEigThreshold(
double minEigThreshold);
149 void setPyramidLevels(
const int pyrMaxLevel);
150 void setQuality(
double qualityLevel);
153 void setUseHarris(
const int useHarrisDetector);
154 void setWindowSize(
const int winSize);
155 void suppressFeature(
const int &index);
159 std::vector<cv::Point2f> m_points[2];
176 #elif defined(VISP_HAVE_OPENCV)
178 #pragma package <opencv>
181 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
182 # include <opencv2/imgproc/imgproc.hpp>
183 # include <opencv2/video/tracking.hpp>
184 # include <opencv2/legacy/legacy.hpp>
185 # include <opencv2/highgui/highgui.hpp>
189 # include <highgui.h>
195 #include <visp/vpConfig.h>
196 #include <visp/vpImage.h>
197 #include <visp/vpImageIo.h>
198 #include <visp/vpDisplay.h>
199 #include <visp/vpDebug.h>
200 #include <visp/vpException.h>
201 #include <visp/vpTrackingException.h>
203 typedef int (*funccheck)(int,double,double);
204 typedef void (*funcinfo)(int,int,int,double,double);
205 typedef void (*funcevent)(int);
228 int globalcountFeatures;
235 double harris_free_parameter;
242 IplImage *prev_image;
244 IplImage *prev_pyramid;
248 int countPrevFeatures;
250 CvPoint2D32f *features;
251 CvPoint2D32f *prev_features;
254 long *prev_featuresid;
260 bool *lostDuringTrack;
266 funcevent OnInitialize;
267 funcinfo OnFeatureLost;
268 funcinfo OnNewFeature;
269 funcinfo OnMeasureFeature;
270 funccheck IsFeatureValid;
284 void addFeature(
const int &
id,
const float &x,
const float &y);
291 int getBlockSize()
const {
return block_size;}
292 void getFeature(
int index,
int &
id,
float &x,
float &y)
const;
294 CvPoint2D32f* getFeatures()
const {
return features;}
296 long* getFeaturesId()
const {
return featuresid;}
298 double getHarrisFreeParameter()
const {
return harris_free_parameter;}
300 bool *getListOfLostFeature()
const {
return lostDuringTrack; }
302 int getMaxFeatures()
const {
return maxFeatures;}
304 double getMinDistance()
const {
return min_distance;}
306 int getNbFeatures()
const {
return countFeatures; }
308 int getNbPrevFeatures()
const {
return countPrevFeatures; }
309 void getPrevFeature(
int index,
int &
id,
float &x,
float &y)
const;
311 CvPoint2D32f* getPrevFeatures()
const {
return prev_features;}
313 long* getPrevFeaturesId()
const {
return prev_featuresid;}
315 int getPyramidLevels()
const {
return pyramid_level;}
317 double getQuality()
const {
return quality;}
319 int getWindowSize()
const {
return win_size;}
322 void initTracking(
const IplImage *I,
const IplImage *mask = NULL);
323 void initTracking(
const IplImage *I, CvPoint2D32f *pts,
int size);
324 void initTracking(
const IplImage *I, CvPoint2D32f *pts,
long *fid,
int size);
327 void track(
const IplImage *I);
339 void setBlockSize(
const int input) {initialized = 0; block_size=input;}
347 void setHarrisFreeParameter(
double input) {initialized = 0; harris_free_parameter=input;}
348 void setInitialGuess(CvPoint2D32f **guess_pts);
352 void setIsFeatureValid(funccheck input) {IsFeatureValid = input;}
355 void setMaxFeatures(
const int input);
363 void setMinDistance(
double input) {initialized = 0; min_distance=input;}
368 void setOnInitialize(funcevent input) {OnInitialize = input;}
370 void setOnFeatureLost(funcinfo input) {OnFeatureLost = input;}
372 void setOnNewFeature(funcinfo input) {OnNewFeature = input;}
374 void setOnMeasureFeature(funcinfo input) {OnMeasureFeature = input;}
383 void setPyramidLevels(
const int input) {initialized = 0; pyramid_level=input;}
384 void setQuality(
double input) {initialized = 0; quality=input;}
385 void setTrackerId(
int tid) {_tid = tid;}
393 void setUseHarris(
const int input) {initialized = 0; use_harris=input;}
394 void setWindowSize(
const int input) {initialized = 0; win_size=input;}
396 void suppressFeature(
int index);
402 unsigned int thickness=1);
403 static void display(
const vpImage<vpRGBa>& I,
const CvPoint2D32f* features_list,
405 unsigned int thickness=1);
408 const long *featuresid_list,
const int &nbFeatures,
410 static void display(
const vpImage<vpRGBa>& I,
const CvPoint2D32f* features_list,
411 const long *featuresid_list,
const int &nbFeatures,
int getPyramidLevels() const
Get the list of features id.
int getMaxFeatures() const
Get the list of lost feature.
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.
double getHarrisFreeParameter() const
Get the free parameter of the Harris detector.
Class to define colors available for display functionnalities.
cv::TermCriteria m_termcrit
static const vpColor green
std::vector< long > m_points_id
Keypoint id.
double getQuality() const
Get the parameter characterizing the minimal accepted quality of image corners.
void setTrackerId(int tid)
Does nothing. Just here for compat with previous releases that use OpenCV C api to do the tracking...
int getBlockSize() const
Get the size of the averaging block used to track the features.
std::vector< cv::Point2f > getPrevFeatures() const
Get the list of previous features.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
int getNbFeatures() const
Get the number of current features.
double getMinDistance() const
Get the minimal Euclidean distance between detected corners during initialization.
int getNbPrevFeatures() const
Get the number of previous features.
int getWindowSize() const
Get the window size used to refine the corner locations.
std::vector< long > getFeaturesId() const
Get the unique id of each feature.