1 #include <visp3/core/vpImageConvert.h> 3 #include <visp3/gui/vpDisplayOpenCV.h> 4 #include <visp3/io/vpVideoReader.h> 5 #include <visp3/klt/vpKltOpencv.h> 9 #ifdef VISP_HAVE_OPENCV 17 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 43 while (!reader.
end()) {
45 std::cout <<
"Process image " << reader.
getFrameIndex() << std::endl;
53 std::cout <<
"Re initialize the tracker" << std::endl;
54 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408) 56 std::vector<cv::Point2f> prev_features = tracker.
getFeatures();
60 std::vector<cv::Point2f> new_features = tracker.
getFeatures();
64 for (
size_t i = 0; i < prev_features.size(); i++) {
67 bool is_redundant =
false;
68 for (
size_t j = 0; j < new_features.size(); j++) {
69 distance = sqrt(
vpMath::sqr(new_features[j].x - prev_features[i].x) +
70 vpMath::sqr(new_features[j].y - prev_features[i].y));
71 if (distance < minDistance_) {
90 CvPoint2D32f *prev_features = (CvPoint2D32f *)cvAlloc(prev_nfeatures *
sizeof(CvPoint2D32f));
92 for (
int i = 0; i < prev_nfeatures; i++) {
94 prev_features[i].x = x;
95 prev_features[i].y = y;
101 std::cout <<
"Detection of " << tracker.
getNbFeatures() <<
" new features" << std::endl;
108 bool is_redundant =
false;
113 if (distance < minDistance_) {
123 tracker.
addFeature(i, prev_features[j].x, prev_features[j].y);
126 cvFree(&prev_features);
133 std::cout <<
"tracking of " << tracker.
getNbFeatures() <<
" features" << std::endl;
141 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 142 cvReleaseImage(&cvI);
147 std::cout <<
"Catch an exception: " << e << std::endl;
void addFeature(const float &x, const float &y)
void setMaxFeatures(int maxCount)
long getFrameIndex() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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.
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)
void setPyramidLevels(int pyrMaxLevel)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void acquire(vpImage< vpRGBa > &I)
void setWindowSize(int winSize)
void initTracking(const cv::Mat &I, const cv::Mat &mask=cv::Mat())
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void getFeature(const int &index, long &id, float &x, float &y) const
int getNbFeatures() const
Get the number of current features.
void setUseHarris(int useHarrisDetector)
void setFileName(const std::string &filename)
double getMinDistance() const
void setBlockSize(int blockSize)
void track(const cv::Mat &I)