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>
82 void addFeature(
const float &x,
const float &y);
83 void addFeature(
const long &
id,
const float &x,
const float &y);
84 void addFeature(
const cv::Point2f &f);
90 static void display(
const vpImage<vpRGBa> &I,
const std::vector<cv::Point2f> &features,
93 const std::vector<long> &featuresid,
95 static void display(
const vpImage<vpRGBa> &I,
const std::vector<cv::Point2f> &features,
96 const std::vector<long> &featuresid,
101 void getFeature(
const int &index,
int &
id,
float &x,
float &y)
const;
103 std::vector<cv::Point2f>
getFeatures()
const {
return m_points[1];}
133 void initTracking(
const cv::Mat &I,
const cv::Mat &mask=cv::Mat());
134 void initTracking(
const cv::Mat &I,
const std::vector<cv::Point2f> &pts);
135 void initTracking(
const cv::Mat &I,
const std::vector<cv::Point2f> &pts,
const std::vector<long> &ids);
138 void track(
const cv::Mat &I);
139 void setBlockSize(
const int blockSize);
140 void setHarrisFreeParameter(
double harris_k);
141 void setInitialGuess(
const std::vector<cv::Point2f> &guess_pts);
142 void setInitialGuess(
const std::vector<cv::Point2f> &init_pts,
const std::vector<cv::Point2f> &guess_pts,
const std::vector<long> &fid);
143 void setMaxFeatures(
const int maxCount);
144 void setMinDistance(
double minDistance);
145 void setMinEigThreshold(
double minEigThreshold);
146 void setPyramidLevels(
const int pyrMaxLevel);
147 void setQuality(
double qualityLevel);
150 void setUseHarris(
const int useHarrisDetector);
151 void setWindowSize(
const int winSize);
152 void suppressFeature(
const int &index);
156 std::vector<cv::Point2f> m_points[2];
173 #elif defined(VISP_HAVE_OPENCV)
175 #pragma package <opencv>
178 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
179 # include <opencv2/imgproc/imgproc.hpp>
180 # include <opencv2/video/tracking.hpp>
181 # include <opencv2/legacy/legacy.hpp>
182 # include <opencv2/highgui/highgui.hpp>
186 # include <highgui.h>
192 #include <visp3/core/vpConfig.h>
193 #include <visp3/core/vpImage.h>
194 #include <visp3/core/vpDisplay.h>
195 #include <visp3/core/vpDebug.h>
196 #include <visp3/core/vpException.h>
197 #include <visp3/core/vpTrackingException.h>
199 typedef int (*funccheck)(int,double,double);
200 typedef void (*funcinfo)(int,int,int,double,double);
201 typedef void (*funcevent)(int);
224 int globalcountFeatures;
229 double harris_free_parameter;
236 IplImage *prev_image;
238 IplImage *prev_pyramid;
242 int countPrevFeatures;
244 CvPoint2D32f *features;
245 CvPoint2D32f *prev_features;
248 long *prev_featuresid;
254 bool *lostDuringTrack;
260 funcevent OnInitialize;
261 funcinfo OnFeatureLost;
262 funcinfo OnNewFeature;
263 funcinfo OnMeasureFeature;
264 funccheck IsFeatureValid;
278 void addFeature(
const int &
id,
const float &x,
const float &y);
285 int getBlockSize()
const {
return block_size;}
286 void getFeature(
int index,
int &
id,
float &x,
float &y)
const;
288 CvPoint2D32f* getFeatures()
const {
return features;}
290 long* getFeaturesId()
const {
return featuresid;}
292 double getHarrisFreeParameter()
const {
return harris_free_parameter;}
294 bool *getListOfLostFeature()
const {
return lostDuringTrack; }
296 int getMaxFeatures()
const {
return maxFeatures;}
298 double getMinDistance()
const {
return min_distance;}
300 int getNbFeatures()
const {
return countFeatures; }
302 int getNbPrevFeatures()
const {
return countPrevFeatures; }
303 void getPrevFeature(
int index,
int &
id,
float &x,
float &y)
const;
305 CvPoint2D32f* getPrevFeatures()
const {
return prev_features;}
307 long* getPrevFeaturesId()
const {
return prev_featuresid;}
309 int getPyramidLevels()
const {
return pyramid_level;}
311 double getQuality()
const {
return quality;}
313 int getWindowSize()
const {
return win_size;}
316 void initTracking(
const IplImage *I,
const IplImage *mask = NULL);
317 void initTracking(
const IplImage *I, CvPoint2D32f *pts,
int size);
318 void initTracking(
const IplImage *I, CvPoint2D32f *pts,
long *fid,
int size);
321 void track(
const IplImage *I);
333 void setBlockSize(
const int input) {initialized = 0; block_size=input;}
341 void setHarrisFreeParameter(
double input) {initialized = 0; harris_free_parameter=input;}
342 void setInitialGuess(CvPoint2D32f **guess_pts);
343 void setInitialGuess(CvPoint2D32f **init_pts, CvPoint2D32f **guess_pts,
long *fid,
int size);
347 void setIsFeatureValid(funccheck input) {IsFeatureValid = input;}
350 void setMaxFeatures(
const int input);
358 void setMinDistance(
double input) {initialized = 0; min_distance=input;}
363 void setOnInitialize(funcevent input) {OnInitialize = input;}
365 void setOnFeatureLost(funcinfo input) {OnFeatureLost = input;}
367 void setOnNewFeature(funcinfo input) {OnNewFeature = input;}
369 void setOnMeasureFeature(funcinfo input) {OnMeasureFeature = input;}
378 void setPyramidLevels(
const int input) {initialized = 0; pyramid_level=input;}
379 void setQuality(
double input) {initialized = 0; quality=input;}
380 void setTrackerId(
int tid) {_tid = tid;}
388 void setUseHarris(
const int input) {initialized = 0; use_harris=input;}
389 void setWindowSize(
const int input) {initialized = 0; win_size=input;}
391 void suppressFeature(
int index);
397 unsigned int thickness=1);
398 static void display(
const vpImage<vpRGBa>& I,
const CvPoint2D32f* features_list,
400 unsigned int thickness=1);
403 const long *featuresid_list,
const int &nbFeatures,
405 static void display(
const vpImage<vpRGBa>& I,
const CvPoint2D32f* features_list,
406 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.