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!!");