Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
tutorial-matching-keypoint-SIFT.cpp
#include <visp3/core/vpConfig.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/io/vpVideoReader.h>
#include <visp3/vision/vpKeyPoint.h>
int main()
{
#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D) && \
(defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400))
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
vpVideoReader reader;
reader.setFileName("video-postcard.mp4");
reader.acquire(I);
const std::string detectorName = "SIFT";
const std::string extractorName = "SIFT";
// Use L2 distance with a matching done using FLANN (Fast Library for
// Approximate Nearest Neighbors)
const std::string matcherName = "FlannBased";
vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
std::cout << "Reference keypoints=" << keypoint.buildReference(I) << std::endl;
Idisp.resize(I.getHeight(), 2 * I.getWidth());
Idisp.insert(I, vpImagePoint(0, 0));
Idisp.insert(I, vpImagePoint(0, I.getWidth()));
vpDisplayOpenCV d(Idisp, 0, 0, "Matching keypoints with SIFT keypoints");
while (!reader.end()) {
reader.acquire(I);
Idisp.insert(I, vpImagePoint(0, I.getWidth()));
vpChrono chrono;
chrono.start();
unsigned int nbMatch = keypoint.matchPoint(I);
chrono.stop();
std::ostringstream oss;
oss << "Computation time: " << chrono.getDurationMs() << " ms";
vpDisplay::displayText(Idisp, vpImagePoint(20, 20), oss.str(), vpColor::red);
std::cout << "Matches=" << nbMatch << std::endl;
vpImagePoint iPref, iPcur;
for (unsigned int i = 0; i < nbMatch; i++) {
keypoint.getMatchedPoints(i, iPref, iPcur);
}
if (vpDisplay::getClick(Idisp, false))
break;
}
#endif
return EXIT_SUCCESS;
}
void getMatchedPoints(unsigned int index, vpImagePoint &referencePoint, vpImagePoint &currentPoint)
void start(bool reset=true)
Definition: vpTime.cpp:401
void stop()
Definition: vpTime.cpp:416
double getDurationMs()
Definition: vpTime.cpp:390
static const vpColor white
Definition: vpColor.h:212
static const vpColor red
Definition: vpColor.h:217
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)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
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:544
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
Definition: vpImage.h:639
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
unsigned int matchPoint(const vpImage< unsigned char > &I)
vpFilterMatchingType
Definition: vpKeyPoint.h:225
@ ratioDistanceThreshold
Definition: vpKeyPoint.h:230
unsigned int buildReference(const vpImage< unsigned char > &I)
Definition: vpKeyPoint.cpp:194
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)