50 #include <visp3/core/vpConfig.h>
51 #include <visp3/core/vpColor.h>
52 #include <visp3/core/vpImage.h>
54 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408))
56 #include <opencv2/video/tracking.hpp>
57 #include <opencv2/imgproc/imgproc.hpp>
58 #include <opencv2/highgui/highgui.hpp>
83 void addFeature(
const float &x,
const float &y);
84 void addFeature(
const long &
id,
const float &x,
const float &y);
85 void addFeature(
const cv::Point2f &f);
91 static void display(
const vpImage<vpRGBa> &I,
const std::vector<cv::Point2f> &features,
94 const std::vector<long> &featuresid,
96 static void display(
const vpImage<vpRGBa> &I,
const std::vector<cv::Point2f> &features,
97 const std::vector<long> &featuresid,
102 void getFeature(
const int &index,
long &
id,
float &x,
float &y)
const;
104 std::vector<cv::Point2f>
getFeatures()
const {
return m_points[1];}
134 void initTracking(
const cv::Mat &I,
const cv::Mat &mask=cv::Mat());
135 void initTracking(
const cv::Mat &I,
const std::vector<cv::Point2f> &pts);
136 void initTracking(
const cv::Mat &I,
const std::vector<cv::Point2f> &pts,
const std::vector<long> &ids);
139 void track(
const cv::Mat &I);
140 void setBlockSize(
const int blockSize);
141 void setHarrisFreeParameter(
double harris_k);
142 void setInitialGuess(
const std::vector<cv::Point2f> &guess_pts);
143 void setInitialGuess(
const std::vector<cv::Point2f> &init_pts,
const std::vector<cv::Point2f> &guess_pts,
const std::vector<long> &fid);
144 void setMaxFeatures(
const int maxCount);
145 void setMinDistance(
double minDistance);
146 void setMinEigThreshold(
double minEigThreshold);
147 void setPyramidLevels(
const int pyrMaxLevel);
148 void setQuality(
double qualityLevel);
151 void setUseHarris(
const int useHarrisDetector);
152 void setWindowSize(
const int winSize);
153 void suppressFeature(
const int &index);
157 std::vector<cv::Point2f> m_points[2];
174 #elif defined(VISP_HAVE_OPENCV)
176 #pragma package <opencv>
179 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
180 # include <opencv2/imgproc/imgproc.hpp>
181 # include <opencv2/video/tracking.hpp>
182 # include <opencv2/legacy/legacy.hpp>
183 # include <opencv2/highgui/highgui.hpp>
187 # include <highgui.h>
193 #include <visp3/core/vpConfig.h>
194 #include <visp3/core/vpImage.h>
195 #include <visp3/core/vpDisplay.h>
196 #include <visp3/core/vpDebug.h>
197 #include <visp3/core/vpException.h>
198 #include <visp3/core/vpTrackingException.h>
200 typedef int (*funccheck)(int,double,double);
201 typedef void (*funcinfo)(int,int,int,double,double);
202 typedef void (*funcevent)(int);
225 int globalcountFeatures;
230 double harris_free_parameter;
237 IplImage *prev_image;
239 IplImage *prev_pyramid;
243 int countPrevFeatures;
245 CvPoint2D32f *features;
246 CvPoint2D32f *prev_features;
249 long *prev_featuresid;
255 bool *lostDuringTrack;
261 funcevent OnInitialize;
262 funcinfo OnFeatureLost;
263 funcinfo OnNewFeature;
264 funcinfo OnMeasureFeature;
265 funccheck IsFeatureValid;
279 void addFeature(
const int &
id,
const float &x,
const float &y);
286 int getBlockSize()
const {
return block_size;}
287 void getFeature(
int index,
long &
id,
float &x,
float &y)
const;
289 CvPoint2D32f* getFeatures()
const {
return features;}
291 long* getFeaturesId()
const {
return featuresid;}
293 double getHarrisFreeParameter()
const {
return harris_free_parameter;}
295 bool *getListOfLostFeature()
const {
return lostDuringTrack; }
297 int getMaxFeatures()
const {
return maxFeatures;}
299 double getMinDistance()
const {
return min_distance;}
301 int getNbFeatures()
const {
return countFeatures; }
303 int getNbPrevFeatures()
const {
return countPrevFeatures; }
304 void getPrevFeature(
int index,
int &
id,
float &x,
float &y)
const;
306 CvPoint2D32f* getPrevFeatures()
const {
return prev_features;}
308 long* getPrevFeaturesId()
const {
return prev_featuresid;}
310 int getPyramidLevels()
const {
return pyramid_level;}
312 double getQuality()
const {
return quality;}
314 int getWindowSize()
const {
return win_size;}
317 void initTracking(
const IplImage *I,
const IplImage *mask = NULL);
318 void initTracking(
const IplImage *I, CvPoint2D32f *pts,
int size);
319 void initTracking(
const IplImage *I, CvPoint2D32f *pts,
long *fid,
int size);
322 void track(
const IplImage *I);
334 void setBlockSize(
const int input) {initialized = 0; block_size=input;}
342 void setHarrisFreeParameter(
double input) {initialized = 0; harris_free_parameter=input;}
343 void setInitialGuess(CvPoint2D32f **guess_pts);
344 void setInitialGuess(CvPoint2D32f **init_pts, CvPoint2D32f **guess_pts,
long *fid,
int size);
348 void setIsFeatureValid(funccheck input) {IsFeatureValid = input;}
351 void setMaxFeatures(
const int input);
359 void setMinDistance(
double input) {initialized = 0; min_distance=input;}
364 void setOnInitialize(funcevent input) {OnInitialize = input;}
366 void setOnFeatureLost(funcinfo input) {OnFeatureLost = input;}
368 void setOnNewFeature(funcinfo input) {OnNewFeature = input;}
370 void setOnMeasureFeature(funcinfo input) {OnMeasureFeature = input;}
379 void setPyramidLevels(
const int input) {initialized = 0; pyramid_level=input;}
380 void setQuality(
double input) {initialized = 0; quality=input;}
381 void setTrackerId(
int tid) {_tid = tid;}
389 void setUseHarris(
const int input) {initialized = 0; use_harris=input;}
390 void setWindowSize(
const int input) {initialized = 0; win_size=input;}
392 void suppressFeature(
int index);
398 unsigned int thickness=1);
399 static void display(
const vpImage<vpRGBa>& I,
const CvPoint2D32f* features_list,
401 unsigned int thickness=1);
404 const long *featuresid_list,
const int &nbFeatures,
406 static void display(
const vpImage<vpRGBa>& I,
const CvPoint2D32f* features_list,
407 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. Thus to enable this ...
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.