Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-matching-keypoint.cpp
1 #include <visp3/core/vpConfig.h>
3 #include <visp3/gui/vpDisplayOpenCV.h>
4 #include <visp3/io/vpImageIo.h>
5 #include <visp3/io/vpVideoReader.h>
7 #include <visp3/vision/vpKeyPoint.h>
9 
10 int main()
11 {
13 #if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D)
15 #ifdef ENABLE_VISP_NAMESPACE
16  using namespace VISP_NAMESPACE_NAME;
17 #endif
19 
20  vpVideoReader reader;
21  reader.setFileName("video-postcard.mp4");
22  reader.acquire(I);
23 
25  const std::string detectorName = "ORB";
26  const std::string extractorName = "ORB";
27  // Hamming distance must be used with ORB
28  const std::string matcherName = "BruteForce-Hamming";
30  vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
31  std::cout << "Reference keypoints=" << keypoint.buildReference(I) << std::endl;
33 
36  Idisp.resize(I.getHeight(), 2 * I.getWidth());
37  Idisp.insert(I, vpImagePoint(0, 0));
38  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
41  vpDisplayOpenCV d(Idisp, 0, 0, "Matching keypoints with ORB keypoints");
42  vpDisplay::display(Idisp);
43  vpDisplay::flush(Idisp);
45 
46  while (!reader.end()) {
48  reader.acquire(I);
49  Idisp.insert(I, vpImagePoint(0, I.getWidth()));
51 
53  vpDisplay::display(Idisp);
55  vpColor::white, 2);
57 
59  unsigned int nbMatch = keypoint.matchPoint(I);
61 
62  std::cout << "Matches=" << nbMatch << std::endl;
63 
65  vpImagePoint iPref, iPcur;
66  for (unsigned int i = 0; i < nbMatch; i++) {
67  keypoint.getMatchedPoints(i, iPref, iPcur);
70  vpDisplay::displayLine(Idisp, iPref, iPcur + vpImagePoint(0, I.getWidth()), vpColor::green);
72  }
74  vpDisplay::flush(Idisp);
76 
77  if (vpDisplay::getClick(Idisp, false))
78  break;
79  }
80 
81  vpDisplay::getClick(Idisp);
82 #endif
83 
84  return EXIT_SUCCESS;
85 }
static const vpColor white
Definition: vpColor.h:212
static const vpColor green
Definition: vpColor.h:220
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:242
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:542
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
Definition: vpImage.h:637
unsigned int getHeight() const
Definition: vpImage.h:181
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
Definition: vpKeyPoint.h:221
vpFilterMatchingType
Definition: vpKeyPoint.h:225
@ ratioDistanceThreshold
Definition: vpKeyPoint.h:230
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)