#include <iostream>
#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && defined(HAVE_OPENCV_VIDEOIO)
#include <visp3/core/vpImageConvert.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/io/vpVideoReader.h>
#include <visp3/klt/vpKltOpencv.h>
int main()
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
try {
cv::Mat cvI;
tracker.setMaxFeatures(200);
tracker.setWindowSize(10);
tracker.setQuality(0.01);
tracker.setMinDistance(15);
tracker.setHarrisFreeParameter(0.04);
tracker.setBlockSize(9);
tracker.setUseHarris(1);
tracker.setPyramidLevels(3);
tracker.initTracking(cvI);
std::cout <<
"Process image " << reader.
getFrameIndex() << std::endl;
std::cout << "Re initialize the tracker" << std::endl;
std::vector<cv::Point2f> prev_features = tracker.getFeatures();
tracker.initTracking(cvI);
std::vector<cv::Point2f> new_features = tracker.getFeatures();
double distance, minDistance_ = tracker.getMinDistance();
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;
}
tracker.addFeature(prev_features[i]);
}
}
tracker.track(cvI);
std::cout << "tracking of " << tracker.getNbFeatures() << " features" << std::endl;
}
}
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
#else
int main()
{
#if !defined(HAVE_OPENCV_HIGHGUI)
std::cout << "This tutorial needs OpenCV highgui module that is missing." << std::endl;
#endif
#if !defined(HAVE_OPENCV_IMGPROC)
std::cout << "This tutorial needs OpenCV imgproc module that is missing." << std::endl;
#endif
#if !defined(HAVE_OPENCV_VIDEO)
std::cout << "This tutorial needs OpenCV video module that is missing." << std::endl;
#endif
#if !defined(HAVE_OPENCV_VIDEOIO)
std::cout << "This tutorial needs OpenCV videoio module that is missing." << std::endl;
#endif
}
#endif
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 emitted by ViSP classes.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
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 setFileName(const std::string &filename)
long getFrameIndex() const
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE