26 #include <mrpt/examples_config.h>
28 MRPT_EXAMPLES_BASE_DIRECTORY +
29 string(
"vision_keypoint_matching_example/imgs/"));
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;
79 cout <<
"Matching HARRIS features by CORRELATION" << endl;
82 cout <<
"Matches found: " << mHarris.size() << endl;
84 cout <<
"***************************************************" << endl;
89 cout <<
"Projecting matched features" << endl;
97 mrpt::make_aligned_shared<CGridPlaneXY>(-10, 10, -10, 10, 0, 1);
99 scene3D->insert(gridXY);
100 scene3D->insert(map3D);
102 win3D.unlockAccess3DScene();
115 CFeatureList featsHarris_L, featsHarris_R, featsSIFT_L, featsSIFT_R,
116 featsSURF_L, featsSURF_R, featsFAST_L, featsFAST_R;
126 cerr <<
"Cannot load " << imgL << endl;
129 cout <<
"Loaded LEFT image: " << endl << imgL << endl;
133 cerr <<
"Cannot load " << imgR << endl;
136 cout <<
"Loaded RIGHT image: " << endl << imgR << endl;
138 cout <<
"***************************************************" << endl;
139 cout <<
"***************************************************" << endl;
143 cout <<
"Detecting HARRIS features in LEFT image" << endl;
146 cout <<
"Detected " << featsHarris_L.
size() << endl;
148 cout <<
"Detecting HARRIS features in RIGHT image" << endl;
150 cout <<
"Detected " << featsHarris_R.
size() << endl;
151 cout <<
"***************************************************" << endl;
154 cout <<
"Detecting SIFT features in LEFT image" << endl;
159 cout <<
"Detected " << featsSIFT_L.
size() << endl;
161 cout <<
"Detecting SIFT features in RIGHT image" << endl;
166 cout <<
"Detected " << featsSIFT_R.
size() << endl;
167 cout <<
"***************************************************" << endl;
170 cout <<
"Detecting SURF features in LEFT image" << endl;
173 cout <<
"Detected " << featsSURF_L.
size() << endl;
175 cout <<
"Detecting SURF features in RIGHT image" << endl;
177 cout <<
"Detected " << featsSURF_R.
size() << endl;
178 cout <<
"***************************************************" << endl;
181 cout <<
"Detecting FAST features in LEFT image" << endl;
184 cout <<
"Detected " << featsFAST_L.
size() << endl;
186 cout <<
"Detecting FAST features in RIGHT image" << endl;
188 cout <<
"Detected " << featsFAST_R.
size() << endl;
189 cout <<
"***************************************************" << endl;
190 cout <<
"***************************************************" << endl;
199 cout <<
"Matching HARRIS features" << endl;
201 nMatches =
matchFeatures(featsHarris_L, featsHarris_R, mHarris);
203 cout <<
"[NCC] Matches found: " << mHarris.size() <<
" in " << T * 1000.0f
208 nMatches =
matchFeatures(featsHarris_L, featsHarris_R, mHarris_SAD, opt);
210 cout <<
"[SAD] Matches found: " << mHarris_SAD.size() <<
" in "
211 << T * 1000.0f <<
" ms " << endl;
212 cout <<
"***************************************************" << endl;
215 cout <<
"Matching SIFT features by DESCRIPTOR" << endl;
218 nMatches =
matchFeatures(featsSIFT_L, featsSIFT_R, mSIFT, opt);
220 cout <<
"Matches found: " << mSIFT.size() <<
" in " << T * 1000.0f <<
" ms "
222 cout <<
"***************************************************" << endl;
225 cout <<
"Matching SURF features by DESCRIPTOR" << endl;
228 nMatches =
matchFeatures(featsSURF_L, featsSURF_R, mSURF, opt);
230 cout <<
"Matches found: " << mSURF.size() <<
" in " << T * 1000.0f <<
" ms "
232 cout <<
"***************************************************" << endl;
235 cout <<
"Matching FAST features" << endl;
237 nMatches =
matchFeatures(featsFAST_L, featsFAST_R, mFAST_CC);
239 cout <<
"[NCC] Matches found: " << mFAST_CC.size() <<
" in " << T * 1000.0f
244 nMatches =
matchFeatures(featsFAST_L, featsFAST_R, mFAST_SAD, opt);
246 cout <<
"[SAD] Matches found: " << mFAST_SAD.size() <<
" in " << T * 1000.0f
248 cout <<
"***************************************************" << endl;
252 CDisplayWindow winHarrisSAD, winHarrisNCC, winFASTSAD, winFASTNCC,
263 imL, imR, mHarris,
TColor(0, 0, 255));
265 imL, imR, mHarris_SAD,
TColor(0, 0, 255));
269 imL, imR, mFAST_SAD,
TColor(0, 255, 0));
271 imL, imR, mFAST_CC,
TColor(0, 255, 0));
312 for (it1 = list1.
begin(); it1 != list1.
end(); ++it1)
314 for (it2 = list2.
begin(); it2 != list2.
end(); ++it2)
319 win2.
setPos(0, imH * 1.5);
320 CImage joinimage, copyjoinimage, copyInfoImage;
327 infoimage.filledRectangle(0, 0, imW2, imH2,
TColor(150, 150, 150));
328 infoimage.textOut(20, imH2 - 53,
"SAD",
TColor::blue());
329 infoimage.textOut(20, imH2 - 41,
"NCC",
TColor::blue());
330 infoimage.textOut(20, imH2 - 29,
"SIFT",
TColor::blue());
331 infoimage.textOut(20, imH2 - 17,
"SURF",
TColor::blue());
332 for (it1 = list1.
begin(); it1 != list1.
end(); ++it1)
334 copyInfoImage = infoimage;
335 copyjoinimage = joinimage;
339 (*it1)->x + imW, 0, (*it1)->x + imW, imH,
347 bool firstMatch =
true;
350 double minsad = 1.0, maxncc = 0.0;
351 float minsiftd = 1.0f, minsurfd = 1.0f;
352 int idxsad = 0, idxncc = 0, idxsiftd = 0, idxsurfd = 0;
354 for (it2 = list2.
begin(); it2 != list2.
end(); ++it2)
356 if (fabs((*it1)->y - (*it2)->y) <= 1.0 && (*it1)->x > (*it2)->x)
372 (*it1)->patch, (*it2)->patch, u,
v, ncc);
380 float siftd = (*it1)->descriptorSIFTDistanceTo(*(*it2));
381 if (siftd < minsiftd)
388 float surfd = (*it1)->descriptorSURFDistanceTo(*(*it2));
389 if (surfd < minsurfd)
399 (*it1)->x + imW, 0, (*it1)->x + imW, imH,
407 double rx0, rx1, ry0, ry1, tx,
ty;
408 rx0 = (*it2)->x + imW - 15;
409 rx1 = (*it2)->x + imW;
410 tx = (*it2)->x + imW - 13;
413 ry0 = (*it2)->y - 20;
414 ry1 = (*it2)->y - 10;
419 ry0 = (*it2)->y + 10;
420 ry1 = (*it2)->y + 20;
424 rx0, ry0, rx1, ry1,
TColor(150, 150, 150));
448 80 + idxsad * 50, imH2 - 53,
format(
"%.2f", minsad),
451 80 + idxncc * 50, imH2 - 41,
format(
"%.2f", maxncc),
454 80 + idxsiftd * 50, imH2 - 29,
format(
"%.2f", minsiftd),
457 80 + idxsurfd * 50, imH2 - 17,
format(
"%.2f", minsurfd),
460 win.showImage(copyjoinimage);
470 int main(
int argc,
char** argv)
476 cerr <<
"Usage: " << argv[0] << endl;
477 cerr <<
"Options:" << endl;
478 cerr <<
" -match [-s]: TestMatchFeatures (if -s is set, final "
479 "matches in images will be shown)."
481 cerr <<
" -comp: TestMatchingComparative." << endl;
482 cerr <<
" -proj: TestExtractMatchProjectAndPaint." << endl;
486 if (!strcmp(argv[1],
"-match"))
488 if (argc == 3 && !strcmp(argv[2],
"-s"))
493 else if (!strcmp(argv[1],
"-proj"))
495 else if (!strcmp(argv[1],
"-comp"))
497 cout <<
"Press ^C to finish program." << endl;
502 cerr <<
"Usage: " << argv[0] << endl;
503 cerr <<
"Options:" << endl;
504 cerr <<
" -match [-s]: TestMatchFeatures (if -s is set, final "
505 "matches in images will be shown)."
507 cerr <<
" -comp: TestMatchingComparative." << endl;
508 cerr <<
" -proj: TestExtractMatchProjectAndPaint." << endl;
513 catch (std::exception& e)
515 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
520 printf(
"Another exception!!");