1 #include <visp/vpImageConvert.h>
3 #include <visp/vpKltOpencv.h>
4 #include <visp/vpDisplayOpenCV.h>
5 #include <visp/vpVideoReader.h>
9 #ifdef VISP_HAVE_OPENCV
17 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
18 IplImage * cvI = NULL;
43 while ( ! reader.
end() )
46 std::cout <<
"acquire image " << reader.
getFrameIndex() << std::endl;
54 std::cout <<
"Re initialize the tracker" << std::endl;
55 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
57 std::vector<cv::Point2f> prev_features = tracker.
getFeatures();
61 std::vector<cv::Point2f> new_features = tracker.
getFeatures();
66 for (
size_t i=0; i < prev_features.size(); i++) {
69 for (
size_t j=0; j < new_features.size(); j++){
70 distance = sqrt(
vpMath::sqr(new_features[j].x-prev_features[i].x) +
vpMath::sqr(new_features[j].y-prev_features[i].y));
71 if(distance < minDistance_){
88 CvPoint2D32f *prev_features = (CvPoint2D32f*)cvAlloc(prev_nfeatures*
sizeof(CvPoint2D32f));
90 for (
int i=0; i <prev_nfeatures ; i ++) {
99 std::cout <<
"Detection of " << tracker.
getNbFeatures() <<
" new features" << std::endl;
108 is_redundant =
false;
113 if(distance < minDistance_){
122 tracker.
addFeature(i, prev_features[j].x, prev_features[j].y);
125 cvFree(&prev_features);
132 std::cout <<
"tracking of " << tracker.
getNbFeatures() <<
" features" << std::endl;
140 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
141 cvReleaseImage(&cvI);
147 std::cout <<
"Catch an exception: " << e << std::endl;
void addFeature(const float &x, const float &y)
long getFrameIndex() const
void setHarrisFreeParameter(double harris_k)
int getMaxFeatures() const
Get the list of lost feature.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.
void setMaxFeatures(const int maxCount)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void setMinDistance(double minDistance)
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
void display(const vpImage< unsigned char > &I, const vpColor &color=vpColor::red, unsigned int thickness=1)
void setQuality(double qualityLevel)
static double sqr(double x)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
void getFeature(const int &index, int &id, float &x, float &y) const
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
void initTracking(const cv::Mat &I, const cv::Mat &mask=cv::Mat())
void setPyramidLevels(const int pyrMaxLevel)
void setWindowSize(const int winSize)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
void setBlockSize(const int blockSize)
int getNbFeatures() const
Get the number of current features.
virtual bool getClick(bool blocking=true)=0
void setUseHarris(const int useHarrisDetector)
double getMinDistance() const
Get the minimal Euclidean distance between detected corners during initialization.
void track(const cv::Mat &I)