4 #include <visp3/core/vpConfig.h>
6 #if 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
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();
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_) {
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)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void display(const vpImage< unsigned char > &I, const vpColor &color=vpColor::red, unsigned int thickness=1) const
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 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 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