4#include <visp3/core/vpConfig.h>
6#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && defined(HAVE_OPENCV_VIDEOIO)
8#include <visp3/core/vpImageConvert.h>
9#include <visp3/gui/vpDisplayOpenCV.h>
10#include <visp3/io/vpVideoReader.h>
11#include <visp3/klt/vpKltOpencv.h>
15#ifdef ENABLE_VISP_NAMESPACE
41 tracker.setHarrisFreeParameter(0.04);
49 while (!reader.
end()) {
51 std::cout <<
"Process image " << reader.
getFrameIndex() << std::endl;
59 std::cout <<
"Re initialize the tracker" << std::endl;
62 std::vector<cv::Point2f> prev_features =
tracker.getFeatures();
66 std::vector<cv::Point2f> new_features =
tracker.getFeatures();
69 double distance, minDistance_ =
tracker.getMinDistance();
70 for (
size_t i = 0;
i < prev_features.size();
i++) {
73 bool is_redundant =
false;
74 for (
size_t j = 0;
j < new_features.size();
j++) {
75 distance = sqrt(
vpMath::sqr(new_features[j].x - prev_features[i].x) +
76 vpMath::sqr(new_features[j].y - prev_features[i].y));
77 if (distance < minDistance_) {
87 tracker.addFeature(prev_features[i]);
94 std::cout <<
"tracking of " <<
tracker.getNbFeatures() <<
" features" << std::endl;
104 std::cout <<
"Catch an exception: " <<
e << std::endl;
114#if !defined(HAVE_OPENCV_HIGHGUI)
115 std::cout <<
"This tutorial needs OpenCV highgui module that is missing." << std::endl;
117#if !defined(HAVE_OPENCV_IMGPROC)
118 std::cout <<
"This tutorial needs OpenCV imgproc module that is missing." << std::endl;
120#if !defined(HAVE_OPENCV_VIDEO)
121 std::cout <<
"This tutorial needs OpenCV video module that is missing." << std::endl;
123#if !defined(HAVE_OPENCV_VIDEOIO)
124 std::cout <<
"This tutorial needs OpenCV videoio module that is missing." << std::endl;
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