#include <visp3/core/vpImageConvert.h>
#include <visp3/klt/vpKltOpencv.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/io/vpVideoReader.h>
int main()
{
#ifdef VISP_HAVE_OPENCV
try {
#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
IplImage * cvI = NULL;
#else
cv::Mat cvI;
#endif
{
std::cout <<
"acquire 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();
bool is_redundant;
for (size_t i=0; i < prev_features.size(); i++) {
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) +
vpMath::sqr(new_features[j].y-prev_features[i].y));
if(distance < minDistance_){
is_redundant = true;
break;
}
}
if(is_redundant){
continue;
}
}
#else
float x,y;
int id, 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;
j++){
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
return 0;
}
std::cout << "Catch an exception: " << e << std::endl;
}
#endif
}