Visual Servoing Platform  version 3.6.1 under development (2024-03-29)
tutorial-matching-keypoint.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 defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D)
15 
16  vpVideoReader reader;
17  reader.setFileName("video-postcard.mp4");
18  reader.acquire(I);
19 
21  const std::string detectorName = "ORB";
22  const std::string extractorName = "ORB";
23  // Hamming distance must be used with ORB
24  const std::string matcherName = "BruteForce-Hamming";
26  vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
27  std::cout << "Reference keypoints=" << keypoint.buildReference(I) << std::endl;
29 
32  Idisp.resize(I.getHeight(), 2 * I.getWidth());
33  Idisp.insert(I, vpImagePoint(0, 0));
34  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
37  vpDisplayOpenCV d(Idisp, 0, 0, "Matching keypoints with ORB keypoints");
38  vpDisplay::display(Idisp);
39  vpDisplay::flush(Idisp);
41 
42  while (!reader.end()) {
44  reader.acquire(I);
45  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
47 
49  vpDisplay::display(Idisp);
51  vpColor::white, 2);
53 
55  unsigned int nbMatch = keypoint.matchPoint(I);
57 
58  std::cout << "Matches=" << nbMatch << std::endl;
59 
61  vpImagePoint iPref, iPcur;
62  for (unsigned int i = 0; i < nbMatch; i++) {
63  keypoint.getMatchedPoints(i, iPref, iPcur);
66  vpDisplay::displayLine(Idisp, iPref, iPcur + vpImagePoint(0, I.getWidth()), vpColor::green);
68  }
70  vpDisplay::flush(Idisp);
72 
73  if (vpDisplay::getClick(Idisp, false))
74  break;
75  }
76 
77  vpDisplay::getClick(Idisp);
78 #endif
79 
80  return EXIT_SUCCESS;
81 }
static const vpColor white
Definition: vpColor.h:206
static const vpColor green
Definition: vpColor.h:214
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 displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void flush(const vpImage< unsigned char > &I)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
unsigned int getWidth() const
Definition: vpImage.h:245
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:783
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
Definition: vpImage.h:1533
unsigned int getHeight() const
Definition: vpImage.h:184
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
Definition: vpKeyPoint.h:212
vpFilterMatchingType
Definition: vpKeyPoint.h:216
@ ratioDistanceThreshold
Definition: vpKeyPoint.h:221
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)