1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
//! \example tutorial-matching-keypoint.cpp
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/io/vpVideoReader.h>
//! [Include]
#include <visp3/vision/vpKeyPoint.h>
//! [Include]
int main()
{
//! [Define]
#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_FEATURES2D)
//! [Define]
vpImage<unsigned char> I;
vpVideoReader reader;
reader.setFileName("video-postcard.mp4");
reader.acquire(I);
//! [Construction]
const std::string detectorName = "ORB";
const std::string extractorName = "ORB";
// Hamming distance must be used with ORB
const std::string matcherName = "BruteForce-Hamming";
vpKeyPoint::vpFilterMatchingType filterType = vpKeyPoint::ratioDistanceThreshold;
vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
std::cout << "Reference keypoints=" << keypoint.buildReference(I) << std::endl;
//! [Construction]
//! [Create image]
vpImage<unsigned char> Idisp;
Idisp.resize(I.getHeight(), 2 * I.getWidth());
Idisp.insert(I, vpImagePoint(0, 0));
Idisp.insert(I, vpImagePoint(0, I.getWidth()));
//! [Create image]
//! [Init display]
vpDisplayOpenCV d(Idisp, 0, 0, "Matching keypoints with ORB keypoints");
vpDisplay::display(Idisp);
vpDisplay::flush(Idisp);
//! [Init display]
while (!reader.end()) {
//! [Acquisition]
reader.acquire(I);
Idisp.insert(I, vpImagePoint(0, I.getWidth()));
//! [Acquisition]
//! [Display]
vpDisplay::display(Idisp);
vpDisplay::displayLine(Idisp, vpImagePoint(0, I.getWidth()), vpImagePoint(I.getHeight(), I.getWidth()),
vpColor::white, 2);
//! [Display]
//! [Matching]
unsigned int nbMatch = keypoint.matchPoint(I);
//! [Matching]
std::cout << "Matches=" << nbMatch << std::endl;
//! [Get matches]
vpImagePoint iPref, iPcur;
for (unsigned int i = 0; i < nbMatch; i++) {
keypoint.getMatchedPoints(i, iPref, iPcur);
//! [Get matches]
//! [Display matches]
vpDisplay::displayLine(Idisp, iPref, iPcur + vpImagePoint(0, I.getWidth()), vpColor::green);
//! [Display matches]
}
//! [Display flush]
vpDisplay::flush(Idisp);
//! [Display flush]
if (vpDisplay::getClick(Idisp, false))
break;
}
vpDisplay::getClick(Idisp);
#endif
return EXIT_SUCCESS;
}
|