Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-matching-keypoint.cpp
1
2#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
10int main()
11{
13#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && \
14 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_FEATURES2D)) || \
15 ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_3D) && defined(HAVE_OPENCV_FEATURES)))
17#ifdef ENABLE_VISP_NAMESPACE
18 using namespace VISP_NAMESPACE_NAME;
19#endif
21
22 vpVideoReader reader;
23 reader.setFileName("video-postcard.mp4");
24 reader.acquire(I);
25
27 const std::string detectorName = "ORB";
28 const std::string extractorName = "ORB";
29 // Hamming distance must be used with ORB
30 const std::string matcherName = "BruteForce-Hamming";
32 vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
33 std::cout << "Reference keypoints=" << keypoint.buildReference(I) << std::endl;
35
38 Idisp.resize(I.getHeight(), 2 * I.getWidth());
39 Idisp.insert(I, vpImagePoint(0, 0));
40 Idisp.insert(I, vpImagePoint(0, I.getWidth()));
43 vpDisplayOpenCV d(Idisp, 0, 0, "Matching keypoints with ORB keypoints");
44 vpDisplay::display(Idisp);
45 vpDisplay::flush(Idisp);
47
48 while (!reader.end()) {
50 reader.acquire(I);
51 Idisp.insert(I, vpImagePoint(0, I.getWidth()));
53
55 vpDisplay::display(Idisp);
56 vpDisplay::displayLine(Idisp, vpImagePoint(0, I.getWidth()), vpImagePoint(I.getHeight(), I.getWidth()),
59
61 unsigned int nbMatch = keypoint.matchPoint(I);
63
64 std::cout << "Matches=" << nbMatch << std::endl;
65
67 vpImagePoint iPref, iPcur;
68 for (unsigned int i = 0; i < nbMatch; i++) {
69 keypoint.getMatchedPoints(i, iPref, iPcur);
72 vpDisplay::displayLine(Idisp, iPref, iPcur + vpImagePoint(0, I.getWidth()), vpColor::green);
74 }
76 vpDisplay::flush(Idisp);
78
79 if (vpDisplay::getClick(Idisp, false))
80 break;
81 }
82
84#endif
85
86 return EXIT_SUCCESS;
87}
static const vpColor white
Definition vpColor.h:193
static const vpColor green
Definition vpColor.h:201
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 of the vpImage class member functions.
Definition vpImage.h:131
Class that allows keypoints 2D features detection (and descriptors extraction) and matching thanks to...
Definition vpKeyPoint.h:274
@ ratioDistanceThreshold
Definition vpKeyPoint.h:283
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void setFileName(const std::string &filename)
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE