#include <visp3/core/vpImageConvert.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/io/vpVideoReader.h>
#include <visp3/klt/vpKltOpencv.h>
int main()
{
#ifdef VISP_HAVE_OPENCV
try {
#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
IplImage *cvI = NULL;
#else
cv::Mat cvI;
#endif
std::cout <<
"Process image " << reader.
getFrameIndex() << std::endl;
std::cout << "Re initialize the tracker" << std::endl;
#if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
std::vector<cv::Point2f> prev_features = tracker.
getFeatures();
std::vector<cv::Point2f> new_features = tracker.
getFeatures();
for (size_t i = 0; i < prev_features.size(); i++) {
bool is_redundant = false;
for (size_t j = 0; j < new_features.size(); j++) {
distance = sqrt(
vpMath::sqr(new_features[j].x - prev_features[i].x) +
if (distance < minDistance_) {
is_redundant = true;
break;
}
}
if (is_redundant) {
continue;
}
}
#else
float x, y;
long id;
int j = 0;
CvPoint2D32f *prev_features = (CvPoint2D32f *)cvAlloc(prev_nfeatures * sizeof(CvPoint2D32f));
for (int i = 0; i < prev_nfeatures; i++) {
prev_features[i].x = x;
prev_features[i].y = y;
}
std::cout <<
"Detection of " << tracker.
getNbFeatures() <<
" new features" << std::endl;
bool is_redundant = false;
if (distance < minDistance_) {
is_redundant = true;
break;
}
}
if (is_redundant) {
continue;
}
tracker.
addFeature(i, prev_features[j].x, prev_features[j].y);
i++;
}
cvFree(&prev_features);
#endif
}
std::cout <<
"tracking of " << tracker.
getNbFeatures() <<
" features" << std::endl;
}
#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
cvReleaseImage(&cvI);
#endif
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
#endif
return EXIT_SUCCESS;
}
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emited by ViSP classes.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
int getMaxFeatures() const
Get the list of lost feature.
void setBlockSize(int blockSize)
void setQuality(double qualityLevel)
void track(const cv::Mat &I)
int getNbFeatures() const
Get the number of current features.
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.
void setHarrisFreeParameter(double harris_k)
void getFeature(const int &index, long &id, float &x, float &y) const
void setMaxFeatures(int maxCount)
void addFeature(const float &x, const float &y)
void initTracking(const cv::Mat &I, const cv::Mat &mask=cv::Mat())
double getMinDistance() const
void setMinDistance(double minDistance)
void display(const vpImage< unsigned char > &I, const vpColor &color=vpColor::red, unsigned int thickness=1)
void setUseHarris(int useHarrisDetector)
void setWindowSize(int winSize)
void setPyramidLevels(int pyrMaxLevel)
static double sqr(double x)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
long getFrameIndex() const