ViSP  2.10.0
tutorial-matching-keypoint-SIFT.cpp
1 #include <visp/vpDisplayOpenCV.h>
3 #include <visp/vpVideoReader.h>
4 #include <visp/vpImageIo.h>
6 #include <visp/vpKeyPoint.h>
8 
9 int main() {
11 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) && (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
14 
15  vpVideoReader reader;
16  reader.setFileName("video-postcard.mpeg");
17  reader.acquire(I);
18 
20  const std::string detectorName = "SIFT";
21  const std::string extractorName = "SIFT";
22  //Use L2 distance with a matching done using FLANN (Fast Library for Approximate Nearest Neighbors)
23  const std::string matcherName = "FlannBased";
25  vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
27 
29  std::cout << "Reference keypoints=" << keypoint.buildReference(I) << std::endl;
31 
34  Idisp.resize(I.getHeight(), 2*I.getWidth());
35  Idisp.insert(I, vpImagePoint(0, 0));
36  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
39  vpDisplayOpenCV d(Idisp, 0, 0, "Matching keypoints with SIFT keypoints") ;
40  vpDisplay::display(Idisp);
41  vpDisplay::flush(Idisp);
43 
44  while ( ! reader.end() )
45  {
47  reader.acquire(I);
48  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
50 
52  vpDisplay::display(Idisp);
55 
57  int nbMatch = keypoint.matchPoint(I);
59 
60  std::cout << "Matches=" << nbMatch << std::endl;
61 
63  vpImagePoint iPref, iPcur;
64  for (int i = 0; i < nbMatch; i++)
65  {
66  keypoint.getMatchedPoints(i, iPref, iPcur);
69  vpDisplay::displayLine(Idisp, iPref, iPcur + vpImagePoint(0, I.getWidth()), vpColor::green);
71  }
73  vpDisplay::flush(Idisp);
75 
76  if (vpDisplay::getClick(Idisp, false))
77  break;
78  }
79 
80  vpDisplay::getClick(Idisp);
81 #endif
82 
83  return 0;
84 }
unsigned int getWidth() const
Definition: vpImage.h:161
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
static const vpColor green
Definition: vpColor.h:170
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
The vpDisplayOpenCV allows to display image using the opencv library.
void acquire(vpImage< vpRGBa > &I)
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
Definition: vpImage.h:536
void setFileName(const char *filename)
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
Definition: vpKeyPoint.h:212
void insert(const vpImage< Type > &src, const vpImagePoint topLeft)
Definition: vpImage.h:855
vpFilterMatchingType
Definition: vpKeyPoint.h:217
unsigned int getHeight() const
Definition: vpImage.h:152
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
static const vpColor white
Definition: vpColor.h:162