26 #include <mrpt/examples_config.h>    28     MRPT_EXAMPLES_BASE_DIRECTORY +
    29     string(
"vision_keypoint_matching_example/imgs/"));
    41     string imgL = 
myDataDir + string(
"imL_p01.jpg");  
    42     string imgR = 
myDataDir + string(
"imR_p01.jpg");  
    47         cerr << 
"Cannot load " << imgL << endl;
    50     cout << 
"Loaded test image: " << imgL << endl;
    54         cerr << 
"Cannot load " << imgR << endl;
    57     cout << 
"Loaded test image: " << imgR << endl;
    59     cout << 
"***************************************************" << endl;
    60     cout << 
"***************************************************" << endl;
    64     cout << 
"Detecting HARRIS features in LEFT image" << endl;
    67     cout << 
"Detected " << featsHarris_L.
size() << endl;
    69     cout << 
"Detecting HARRIS features in RIGHT image" << endl;
    71     cout << 
"Detected " << featsHarris_R.
size() << endl;
    73     cout << 
"***************************************************" << endl;
    74     cout << 
"***************************************************" << endl;
    78     cout << 
"Matching HARRIS features by CORRELATION" << endl;
    80     cout << 
"Matches found: " << mHarris.size() << endl;
    82     cout << 
"***************************************************" << endl;
    87     cout << 
"Projecting matched features" << endl;
    96     scene3D->insert(gridXY);
    97     scene3D->insert(map3D);
    99     win3D.unlockAccess3DScene();
   112     CFeatureList featsHarris_L, featsHarris_R, featsSIFT_L, featsSIFT_R,
   113         featsSURF_L, featsSURF_R, featsFAST_L, featsFAST_R;
   117     string imgL = 
myDataDir + string(
"imL_p01.jpg");  
   118     string imgR = 
myDataDir + string(
"imR_p01.jpg");  
   123         cerr << 
"Cannot load " << imgL << endl;
   126     cout << 
"Loaded LEFT image: " << endl << imgL << endl;
   130         cerr << 
"Cannot load " << imgR << endl;
   133     cout << 
"Loaded RIGHT image: " << endl << imgR << endl;
   135     cout << 
"***************************************************" << endl;
   136     cout << 
"***************************************************" << endl;
   140     cout << 
"Detecting HARRIS features in LEFT image" << endl;
   143     cout << 
"Detected " << featsHarris_L.
size() << endl;
   145     cout << 
"Detecting HARRIS features in RIGHT image" << endl;
   147     cout << 
"Detected " << featsHarris_R.
size() << endl;
   148     cout << 
"***************************************************" << endl;
   151     cout << 
"Detecting SIFT features in LEFT image" << endl;
   156     cout << 
"Detected " << featsSIFT_L.
size() << endl;
   158     cout << 
"Detecting SIFT features in RIGHT image" << endl;
   163     cout << 
"Detected " << featsSIFT_R.
size() << endl;
   164     cout << 
"***************************************************" << endl;
   167     cout << 
"Detecting SURF features in LEFT image" << endl;
   170     cout << 
"Detected " << featsSURF_L.
size() << endl;
   172     cout << 
"Detecting SURF features in RIGHT image" << endl;
   174     cout << 
"Detected " << featsSURF_R.
size() << endl;
   175     cout << 
"***************************************************" << endl;
   178     cout << 
"Detecting FAST features in LEFT image" << endl;
   181     cout << 
"Detected " << featsFAST_L.
size() << endl;
   183     cout << 
"Detecting FAST features in RIGHT image" << endl;
   185     cout << 
"Detected " << featsFAST_R.
size() << endl;
   186     cout << 
"***************************************************" << endl;
   187     cout << 
"***************************************************" << endl;
   195     cout << 
"Matching HARRIS features" << endl;
   199     cout << 
"[NCC] Matches found: " << mHarris.size() << 
" in " << T * 1000.0f
   204     matchFeatures(featsHarris_L, featsHarris_R, mHarris_SAD, opt);
   206     cout << 
"[SAD] Matches found: " << mHarris_SAD.size() << 
" in "   207          << T * 1000.0f << 
" ms " << endl;
   208     cout << 
"***************************************************" << endl;
   211     cout << 
"Matching SIFT features by DESCRIPTOR" << endl;
   216     cout << 
"Matches found: " << mSIFT.size() << 
" in " << T * 1000.0f << 
" ms "   218     cout << 
"***************************************************" << endl;
   221     cout << 
"Matching SURF features by DESCRIPTOR" << endl;
   226     cout << 
"Matches found: " << mSURF.size() << 
" in " << T * 1000.0f << 
" ms "   228     cout << 
"***************************************************" << endl;
   231     cout << 
"Matching FAST features" << endl;
   235     cout << 
"[NCC] Matches found: " << mFAST_CC.size() << 
" in " << T * 1000.0f
   242     cout << 
"[SAD] Matches found: " << mFAST_SAD.size() << 
" in " << T * 1000.0f
   244     cout << 
"***************************************************" << endl;
   248         CDisplayWindow winHarrisSAD, winHarrisNCC, winFASTSAD, winFASTNCC,
   259             imL, imR, mHarris, 
TColor(0, 0, 255));
   261             imL, imR, mHarris_SAD, 
TColor(0, 0, 255));
   265             imL, imR, mFAST_SAD, 
TColor(0, 255, 0));
   267             imL, imR, mFAST_CC, 
TColor(0, 255, 0));
   280     string imgL = 
myDataDir + string(
"imL_p01.jpg");  
   281     string imgR = 
myDataDir + string(
"imR_p01.jpg");  
   312     win2.
setPos(0, imH * 1.5);
   313     CImage joinimage, copyjoinimage, copyInfoImage;
   320     infoimage.filledRectangle(0, 0, imW2, imH2, 
TColor(150, 150, 150));
   321     infoimage.textOut(20, imH2 - 53, 
"SAD", TColor::blue());
   322     infoimage.textOut(20, imH2 - 41, 
"NCC", TColor::blue());
   323     infoimage.textOut(20, imH2 - 29, 
"SIFT", TColor::blue());
   324     infoimage.textOut(20, imH2 - 17, 
"SURF", TColor::blue());
   325     for (
auto it1 = list1.
begin(); it1 != list1.
end(); ++it1)
   327         const auto& pt1 = it1->keypoint.pt;
   329         copyInfoImage = infoimage;
   330         copyjoinimage = joinimage;
   331         copyjoinimage.
line(pt1.x, 0, pt1.x, imH, TColor::green());  
   333             pt1.x + imW, 0, pt1.x + imW, imH,
   336             0, pt1.y, imW + imW, pt1.y, TColor::green());  
   338             pt1.x, pt1.y, 4, TColor::green(), 2);  
   341         bool firstMatch = 
true;
   344         double minsad = 1.0, maxncc = 0.0;
   345         float minsiftd = 1.0f, minsurfd = 1.0f;
   346         int idxsad = 0, idxncc = 0, idxsiftd = 0, idxsurfd = 0;
   348         for (
auto it2 = list2.
begin(); it2 != list2.
end(); ++it2)
   350             const auto& pt2 = it2->keypoint.pt;
   352             if (fabs(pt1.y - pt2.y) <= 1.0 && pt1.x > pt2.x)
   367                     *it1->patch, *it2->patch, u, v, ncc);
   375                 float siftd = it1->descriptorSIFTDistanceTo(*it2);
   376                 if (siftd < minsiftd)
   383                 float surfd = it1->descriptorSURFDistanceTo(*it2);
   384                 if (surfd < minsurfd)
   394                         pt1.x + imW, 0, pt1.x + imW, imH,
   400                     pt2.x + imW, pt2.y, 4, TColor::blue(),
   402                 double rx0, rx1, ry0, ry1, tx, ty;
   403                 rx0 = pt2.x + imW - 15;
   405                 tx = pt2.x + imW - 13;
   419                     rx0, ry0, rx1, ry1, 
TColor(150, 150, 150));
   421                     tx, ty, 
format(
"%d", cnt), TColor::blue());
   429                     px, imH2 - 70, 
format(
"%d", cnt), TColor::blue());
   431                     px, imH2 - 53, 
format(
"%.2f", sad), TColor::blue());
   433                     px, imH2 - 41, 
format(
"%.2f", ncc), TColor::blue());
   435                     px, imH2 - 29, 
format(
"%.2f", siftd), TColor::blue());
   437                     px, imH2 - 17, 
format(
"%.2f", surfd), TColor::blue());
   443             80 + idxsad * 50, imH2 - 53, 
format(
"%.2f", minsad),
   446             80 + idxncc * 50, imH2 - 41, 
format(
"%.2f", maxncc),
   449             80 + idxsiftd * 50, imH2 - 29, 
format(
"%.2f", minsiftd),
   452             80 + idxsurfd * 50, imH2 - 17, 
format(
"%.2f", minsurfd),
   455         win.showImage(copyjoinimage);
   471             cerr << 
"Usage: " << 
argv[0] << endl;
   472             cerr << 
"Options:" << endl;
   473             cerr << 
" -match [-s]: TestMatchFeatures (if -s is set, final "   474                     "matches in images will be shown)."   476             cerr << 
" -comp: TestMatchingComparative." << endl;
   477             cerr << 
" -proj: TestExtractMatchProjectAndPaint." << endl;
   481             if (!strcmp(
argv[1], 
"-match"))
   483                 if (
argc == 3 && !strcmp(
argv[2], 
"-s"))
   488             else if (!strcmp(
argv[1], 
"-proj"))
   490             else if (!strcmp(
argv[1], 
"-comp"))
   492                 cout << 
"Press ^C to finish program." << endl;
   497                 cerr << 
"Usage: " << 
argv[0] << endl;
   498                 cerr << 
"Options:" << endl;
   499                 cerr << 
" -match [-s]: TestMatchFeatures (if -s is set, final "   500                         "matches in images will be shown)."   502                 cerr << 
" -comp: TestMatchingComparative." << endl;
   503                 cerr << 
" -proj: TestExtractMatchProjectAndPaint." << endl;
   508     catch (
const std::exception& e)
   515         printf(
"Another exception!!");
 void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map. 
void update_patch(const CImage &patch, const unsigned int col, const unsigned int row)
Update a part of this image with the "patch" given as argument. 
double Tac() noexcept
Stops the stopwatch. 
void drawCircle(int x, int y, int radius, const mrpt::img::TColor &color=mrpt::img::TColor(255, 255, 255), unsigned int width=1) override
Draws a circle of a given radius. 
void line(int x0, int y0, int x1, int y1, const mrpt::img::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid) override
Draws a line. 
void TestMatchingComparative()
std::string std::string format(std::string_view fmt, ARGS &&... args)
void showImagesAndMatchedPoints(const mrpt::img::CImage &img1, const mrpt::img::CImage &img2, const MATCHEDLIST &mList, const mrpt::img::TColor &color=mrpt::img::TColor::red(), bool showNumbers=false)
Show a pair of given color or grayscale images (put together) on the window and print a set of matche...
A high-performance stopwatch, with typical resolution of nanoseconds. 
void TestExtractMatchProjectAndPaint()
size_t getHeight() const override
Returns the height of the image in pixels. 
Scale Invariant Feature Transform [LOWE'04]. 
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally. 
void setWindowTitle(const std::string &str) override
Changes the window title text. 
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV)...
size_t getWidth() const override
Returns the width of the image in pixels. 
A class for storing a map of 3D probabilistic landmarks. 
Parameters associated to a stereo system. 
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle. 
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
Classes for computer vision, detectors, features, etc. 
Speeded Up Robust Feature [BAY'06]. 
mrpt::gui::CDisplayWindow3D::Ptr win
FAST feature detector, OpenCV's implementation ("Faster and better: A    machine learning approach to...
A list of visual features, to be used as output by detectors, as input/output by trackers, etc. 
void setPos(int x, int y) override
Changes the position of the window on the screen. 
void pause(const std::string &msg=std::string("Press any key to continue...")) noexcept
Shows the message "Press any key to continue" (or other custom message) to the current standard outpu...
void drawFeatures(const FEATURELIST &list, const TColor &color=TColor::red(), const bool showIDs=false, const bool showResponse=false, const bool showScale=false, const char marker='+')
Draws a set of marks (or scaled circles for features with scale) onto the image, given a generic cont...
Harris border and corner detector [HARRIS]. 
size_t matchFeatures(const CFeatureList &list1, const CFeatureList &list2, CMatchedFeatureList &matches, const TMatchingOptions &options=TMatchingOptions(), const TStereoSystemParams ¶ms=TStereoSystemParams())
Find the matches between two lists of features which must be of the same type. 
A structure containing options for the matching. 
Kanade-Lucas-Tomasi feature [SHI'94]. 
The namespace for 3D scene representation and rendering. 
double computeSAD(const mrpt::img::CImage &patch1, const mrpt::img::CImage &patch2)
Calculates the Sum of Absolutes Differences (range [0,1]) between two patches. 
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
void showImage(const mrpt::img::CImage &img)
Show a given color or grayscale image on the window. 
virtual void textOut(int x0, int y0, const std::string &str, const mrpt::img::TColor color)
Renders 2D text using bitmap fonts. 
Classes for creating GUI windows for 2D and 3D visualization. 
void Tic() noexcept
Starts the stopwatch. 
void openCV_cross_correlation(const mrpt::img::CImage &img, const mrpt::img::CImage &patch_img, size_t &x_max, size_t &y_max, double &max_val, int x_search_ini=-1, int y_search_ini=-1, int x_search_size=-1, int y_search_size=-1)
Computes the correlation between this image and another one, encapsulating the openCV function cvMatc...
void projectMatchedFeatures(const CMatchedFeatureList &matches, const mrpt::img::TStereoCamera &stereo_camera, std::vector< mrpt::math::TPoint3D > &out_points)
TMatchingMethod matching_method
Matching method. 
A class for storing images as grayscale or RGB bitmaps. 
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.