Visual Servoing Platform  version 3.1.0
tutorial-matching-keypoint-SIFT.cpp
1 #include <visp3/gui/vpDisplayOpenCV.h>
3 #include <visp3/io/vpImageIo.h>
4 #include <visp3/io/vpVideoReader.h>
6 #include <visp3/vision/vpKeyPoint.h>
8 
9 int main()
10 {
12 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) && \
13  (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
16 
17  vpVideoReader reader;
18  reader.setFileName("video-postcard.mpeg");
19  reader.acquire(I);
20 
22  const std::string detectorName = "SIFT";
23  const std::string extractorName = "SIFT";
24  // Use L2 distance with a matching done using FLANN (Fast Library for
25  // Approximate Nearest Neighbors)
26  const std::string matcherName = "FlannBased";
28  vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
30 
32  std::cout << "Reference keypoints=" << keypoint.buildReference(I) << std::endl;
34 
37  Idisp.resize(I.getHeight(), 2 * I.getWidth());
38  Idisp.insert(I, vpImagePoint(0, 0));
39  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
42  vpDisplayOpenCV d(Idisp, 0, 0, "Matching keypoints with SIFT keypoints");
43  vpDisplay::display(Idisp);
44  vpDisplay::flush(Idisp);
46 
47  while (!reader.end()) {
49  reader.acquire(I);
50  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
52 
54  vpDisplay::display(Idisp);
56  vpColor::white, 2);
58 
60  unsigned int nbMatch = keypoint.matchPoint(I);
62 
63  std::cout << "Matches=" << nbMatch << std::endl;
64 
66  vpImagePoint iPref, iPcur;
67  for (unsigned int i = 0; i < nbMatch; i++) {
68  keypoint.getMatchedPoints(i, iPref, iPcur);
71  vpDisplay::displayLine(Idisp, iPref, iPcur + vpImagePoint(0, I.getWidth()), vpColor::green);
73  }
75  vpDisplay::flush(Idisp);
77 
78  if (vpDisplay::getClick(Idisp, false))
79  break;
80  }
81 
82  vpDisplay::getClick(Idisp);
83 #endif
84 
85  return 0;
86 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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:183
static void flush(const vpImage< unsigned char > &I)
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 resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:856
void setFileName(const char *filename)
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
Definition: vpImage.h:1102
unsigned int getHeight() const
Definition: vpImage.h:178
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
Definition: vpKeyPoint.h:223
vpFilterMatchingType
Definition: vpKeyPoint.h:228
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static const vpColor white
Definition: vpColor.h:175
unsigned int getWidth() const
Definition: vpImage.h:229