Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 #include <mrpt/vision/tracking.h>
12 #include <mrpt/gui.h>
13 #include <iostream>
14 
15 using namespace mrpt::gui;
16 using namespace mrpt::vision;
17 using namespace mrpt::img;
18 using namespace mrpt::system;
19 using namespace std;
20 using mrpt::format;
21 
22 #include <mrpt/examples_config.h>
23 string myDataDir(MRPT_EXAMPLES_BASE_DIRECTORY + string("img_convolution_fft/"));
24 const string the_img_for_extract_feats = myDataDir + string("test_image.jpg");
25 
26 void TestTrackFeatures()
27 {
28  CImage im1, im2;
29  im1.loadFromFile(
30  "/Trabajo/Experimentos/[2009] vOdometry Characterization/right1.jpg");
31  im2.loadFromFile(
32  "/Trabajo/Experimentos/[2009] vOdometry Characterization/right2.jpg");
33 
34  CFeatureExtraction fExt;
35  CFeatureList feats;
36 
37  fExt.options.featsType = featKLT;
38  fExt.detectFeatures(im1, feats);
39  feats.saveToTextFile(
40  "J:/Trabajo/Experimentos/[2009] vOdometry Characterization/before.txt");
41 
42  CFeatureTracker_KL tracker;
43  // tracker.extra_params["add_new_features"] = 1; // track, AND ALSO, add
44  // new features
45  // ...
46 
47  // Do tracking:
48  tracker.trackFeatures(im1, im2, feats);
49 
50  feats.saveToTextFile(
51  "/Trabajo/Experimentos/[2009] vOdometry Characterization/after.txt");
52 }
53 
54 // ------------------------------------------------------
55 // TestCapture
56 // ------------------------------------------------------
58 {
59  CDisplayWindow3D wind;
60  CFeatureExtraction fExt;
61  CFeatureList featsHarris_L, featsHarris_R;
62  CMatchedFeatureList mHarris, mSIFT, mSURF;
63  CImage imL, imR;
64 
65  string imgL = MRPT_EXAMPLES_BASE_DIRECTORY +
66  string("vision_feature_extraction/") +
67  string("imgs/imL_p01.jpg"); // Left image
68  string imgR = MRPT_EXAMPLES_BASE_DIRECTORY +
69  string("vision_feature_extraction/") +
70  string("imgs/imR_p01.jpg"); // Right image
71 
72  // Load and check images
73  if (!imL.loadFromFile(imgL))
74  {
75  cerr << "Cannot load " << imgL << endl;
76  return;
77  }
78  cout << "Loaded test image: " << imgL << endl;
79 
80  if (!imR.loadFromFile(imgR))
81  {
82  cerr << "Cannot load " << imgR << endl;
83  return;
84  }
85  cout << "Loaded test image: " << imgR << endl;
86 
87  cout << "***************************************************" << endl;
88  cout << "***************************************************" << endl;
89 
90  // Extract features:
91  // HARRIS
92  cout << "Detecting HARRIS features in LEFT image" << endl;
93  fExt.options.featsType = featKLT;
94  fExt.detectFeatures(imL, featsHarris_L);
95  cout << "Detected " << featsHarris_L.size() << endl;
96 
97  cout << "Detecting HARRIS features in RIGHT image" << endl;
98  fExt.detectFeatures(imR, featsHarris_R);
99  cout << "Detected " << featsHarris_R.size() << endl;
100 
101  cout << "***************************************************" << endl;
102  cout << "***************************************************" << endl;
103 
104  // Match features:
105  // size_t nMatches;
106  TMatchingOptions opt;
107 
108  // HARRIS
109  cout << "Matching HARRIS features by CORRELATION" << endl;
110  // nMatches =
111  matchFeatures(featsHarris_L, featsHarris_R, mHarris);
112  cout << "Matches found: " << mHarris.size() << endl;
113 
114  cout << "***************************************************" << endl;
115 
116 } // end TestExtractMatchProjectAndPaint
117 
118 // ------------------------------------------------------
119 // TestCapture
120 // ------------------------------------------------------
121 void TestMatchFeatures()
122 {
123  CDisplayWindow wind, wind2;
124  CFeatureExtraction fExt;
125  CFeatureList featsHarris_L, featsHarris_R, featsSIFT_L, featsSIFT_R,
126  featsSURF_L, featsSURF_R, featsFAST_L, featsFAST_R;
127  CMatchedFeatureList mHarris, mSIFT, mSURF, mHarris_SAD, mFAST_CC, mFAST_SAD;
128  CImage imL, imR;
129 
130  string imgL = MRPT_EXAMPLES_BASE_DIRECTORY +
131  string("vision_feature_extraction/") +
132  string("imgs/imL_p01.jpg"); // Left image
133  string imgR = MRPT_EXAMPLES_BASE_DIRECTORY +
134  string("vision_feature_extraction/") +
135  string("imgs/imR_p01.jpg"); // Right image
136 
137  // string imgL = "../../bin/imgs/640x480_left_rect.jpg"; // Left
138  // image
139  // string imgR = "../../bin/imgs/640x480_right_rect.jpg"; // Right
140  // image
141 
142  // Load and check images
143  if (!imL.loadFromFile(imgL))
144  {
145  cerr << "Cannot load " << imgL << endl;
146  return;
147  }
148  cout << "Loaded test image: " << imgL << endl;
149 
150  if (!imR.loadFromFile(imgR))
151  {
152  cerr << "Cannot load " << imgR << endl;
153  return;
154  }
155  cout << "Loaded test image: " << imgR << endl;
156 
157  cout << "***************************************************" << endl;
158  cout << "***************************************************" << endl;
159 
160  // Extract features:
161  // HARRIS
162  cout << "Detecting HARRIS features in LEFT image" << endl;
164  fExt.detectFeatures(imL, featsHarris_L);
165  cout << "Detected " << featsHarris_L.size() << endl;
166 
167  cout << "Detecting HARRIS features in RIGHT image" << endl;
168  fExt.detectFeatures(imR, featsHarris_R);
169  cout << "Detected " << featsHarris_R.size() << endl;
170  cout << "***************************************************" << endl;
171 
172  // SIFT
173  cout << "Detecting SIFT features in LEFT image" << endl;
174  fExt.options.featsType = featSIFT;
175  // fExt.options.SIFTOptions.implementation = CFeatureExtraction::Hess;
176  fExt.options.SIFTOptions.implementation = CFeatureExtraction::OpenCV;
177  fExt.detectFeatures(imL, featsSIFT_L);
178  cout << "Detected " << featsSIFT_L.size() << endl;
179 
180  cout << "Detecting SIFT features in RIGHT image" << endl;
181  fExt.options.featsType = featSIFT;
182  // fExt.options.SIFTOptions.implementation = CFeatureExtraction::Hess;
183  fExt.options.SIFTOptions.implementation = CFeatureExtraction::OpenCV;
184  fExt.detectFeatures(imR, featsSIFT_R);
185  cout << "Detected " << featsSIFT_R.size() << endl;
186  cout << "***************************************************" << endl;
187 
188  // SURF
189  cout << "Detecting SURF features in LEFT image" << endl;
190  fExt.options.featsType = featSURF;
191  fExt.detectFeatures(imL, featsSURF_L);
192  cout << "Detected " << featsSURF_L.size() << endl;
193 
194  cout << "Detecting SURF features in RIGHT image" << endl;
195  fExt.detectFeatures(imR, featsSURF_R);
196  cout << "Detected " << featsSURF_R.size() << endl;
197  cout << "***************************************************" << endl;
198 
199  // FAST
200  cout << "Detecting FAST features in LEFT image" << endl;
201  fExt.options.featsType = featFAST;
202  fExt.detectFeatures(imL, featsFAST_L, 0, 400);
203  cout << "Detected " << featsFAST_L.size() << endl;
204  CDisplayWindow fast1("LEFT");
205  fast1.showImageAndPoints(imL, featsFAST_L);
206 
207  cout << "Detecting FAST features in RIGHT image" << endl;
208  fExt.detectFeatures(imR, featsFAST_R, 0, 400);
209  cout << "Detected " << featsFAST_R.size() << endl;
210  cout << "***************************************************" << endl;
211  cout << "***************************************************" << endl;
212  CDisplayWindow fast2("RIGHT");
213  fast2.showImageAndPoints(imR, featsFAST_R);
214 
215  // Match features:
216  // size_t nMatches;
217  TMatchingOptions opt;
218 
219  // HARRIS
220  CTicTac tictac;
221  cout << "Matching HARRIS features by CORRELATION" << endl;
222  tictac.Tic();
223  // nMatches =
224  matchFeatures(featsHarris_L, featsHarris_R, mHarris);
225  double T = tictac.Tac();
226  cout << "[CC] Matches found: " << mHarris.size() << " in " << T * 1000.0f
227  << " ms " << endl;
228 
229  opt.matching_method = TMatchingOptions::mmSAD;
230  tictac.Tic();
231  // nMatches =
232  matchFeatures(featsHarris_L, featsHarris_R, mHarris_SAD, opt);
233  T = tictac.Tac();
234  cout << "[SAD] Matches found: " << mHarris_SAD.size() << " in "
235  << T * 1000.0f << " ms " << endl;
236  cout << "***************************************************" << endl;
237  wind.showImagesAndMatchedPoints(imL, imR, mHarris_SAD, TColor(0, 0, 255));
238 
239  // SIFT
240  cout << "Matching SIFT features by DESCRIPTOR" << endl;
241  opt.matching_method = TMatchingOptions::mmDescriptorSIFT;
242  // nMatches =
243  matchFeatures(featsSIFT_L, featsSIFT_R, mSIFT, opt);
244  cout << "Matches found: " << mSIFT.size() << endl;
245  cout << "***************************************************" << endl;
246 
247  // SURF
248  cout << "Matching SURF features by DESCRIPTOR" << endl;
249  opt.matching_method = TMatchingOptions::mmDescriptorSURF;
250  // nMatches =
251  matchFeatures(featsSURF_L, featsSURF_R, mSURF, opt);
252  cout << "Matches found: " << mSURF.size() << endl;
253  cout << "***************************************************" << endl;
254 
255  // FAST
256  cout << "Matching FAST features by CC" << endl;
257  tictac.Tic();
258  // nMatches =
259  matchFeatures(featsFAST_L, featsFAST_R, mFAST_CC);
260  T = tictac.Tac();
261  cout << "[CC] Matches found: " << mFAST_CC.size() << " in " << T * 1000.0f
262  << " ms " << endl;
263 
264  opt.matching_method = TMatchingOptions::mmSAD;
265  tictac.Tic();
266  // nMatches =
267  matchFeatures(featsFAST_L, featsFAST_R, mFAST_SAD, opt);
268  T = tictac.Tac();
269  cout << "[SAD] Matches found: " << mFAST_SAD.size() << " in " << T * 1000.0f
270  << " ms " << endl;
271  cout << "***************************************************" << endl;
272 
273  wind2.showImagesAndMatchedPoints(imL, imR, mFAST_SAD, TColor(0, 255, 0));
274 
276 
277 } // end TestMatchFeatures
278 
280 {
281  // Take two images
282  string imgL = MRPT_EXAMPLES_BASE_DIRECTORY +
283  string("vision_feature_extraction/") +
284  string("imgs/imL_p01.jpg"); // Left image
285  string imgR = MRPT_EXAMPLES_BASE_DIRECTORY +
286  string("vision_feature_extraction/") +
287  string("imgs/imR_p01.jpg"); // Right image
288 
289  CImage im1, im2;
290  im1.loadFromFile(imgL);
291  im2.loadFromFile(imgR);
292 
293  size_t imW = im1.getWidth();
294  size_t imH = im1.getHeight();
295 
296  CFeatureExtraction fExt;
297  fExt.options.featsType = featFAST;
298  fExt.options.patchSize = 21;
299  fExt.options.SIFTOptions.implementation = CFeatureExtraction::Hess;
300 
301  // Find FAST features
302  CFeatureList list1, list2;
303  fExt.detectFeatures(im1, list1, 150);
304  // Compute SIFT & SURF descriptors
305  fExt.computeDescriptors(im1, list1, descSIFT);
306  fExt.computeDescriptors(im1, list1, descSURF);
307 
308  fExt.detectFeatures(im2, list2, 150);
309  // Compute SIFT & SURF descriptors
310  fExt.computeDescriptors(im2, list2, descSIFT);
311  fExt.computeDescriptors(im2, list2, descSURF);
312 
313  CFeatureList::iterator it1, it2;
314  for (it1 = list1.begin(); it1 != list1.end(); ++it1)
315  im1.cross((*it1)->x, (*it1)->y, TColor::red(), '+');
316  for (it2 = list2.begin(); it2 != list2.end(); ++it2)
317  im2.cross((*it2)->x, (*it2)->y, TColor::red(), '+');
318 
319  CDisplayWindow win, win2;
320  win.setPos(0, 0);
321  win2.setPos(0, imH * 1.5);
322  CImage joinimage, copyjoinimage, copyInfoImage;
323  size_t imW2 = 1280;
324  size_t imH2 = 150;
325 
326  CImage infoimage(imW2, imH2, CH_RGB);
327 
328  joinimage.joinImagesHorz(im1, im2);
329  infoimage.filledRectangle(0, 0, imW2, imH2, TColor(150, 150, 150));
330  infoimage.textOut(20, imH2 - 53, "SAD", TColor::blue());
331  infoimage.textOut(20, imH2 - 41, "NCC", TColor::blue());
332  infoimage.textOut(20, imH2 - 29, "SIFT", TColor::blue());
333  infoimage.textOut(20, imH2 - 17, "SURF", TColor::blue());
334  for (it1 = list1.begin(); it1 != list1.end(); ++it1)
335  {
336  copyInfoImage = infoimage;
337  copyjoinimage = joinimage;
338  copyjoinimage.line(
339  (*it1)->x, 0, (*it1)->x, imH, TColor::green()); // Horiz
340  copyjoinimage.line(
341  (*it1)->x + imW, 0, (*it1)->x + imW, imH,
342  TColor::green()); // Horiz
343  copyjoinimage.line(
344  0, (*it1)->y, imW + imW, (*it1)->y, TColor::green()); // Epipolar
345  copyjoinimage.drawCircle(
346  (*it1)->x, (*it1)->y, 4, TColor::green(), 2); // Keypoint
347 
348  copyInfoImage.update_patch((*it1)->patch, 0, 0);
349  bool firstMatch = true;
350  int cnt = 0;
351  int px = 80;
352  double minsad = 1.0, maxncc = 0.0;
353  float minsiftd = 1.0f, minsurfd = 1.0f;
354  int idxsad = 0, idxncc = 0, idxsiftd = 0, idxsurfd = 0;
355 
356  for (it2 = list2.begin(); it2 != list2.end(); ++it2)
357  {
358  if (fabs((*it1)->y - (*it2)->y) <= 1.0 && (*it1)->x > (*it2)->x)
359  {
360  // Compute matching with SAD and Correlation and SIFT/SURF?
361  // Use epipolar constraints
362  // Compute SAD
363  double sad =
364  mrpt::vision::computeSAD((*it1)->patch, (*it2)->patch);
365  if (sad < minsad)
366  {
367  minsad = sad;
368  idxsad = cnt;
369  }
370  // Compute Correlation
371  double ncc;
372  size_t u, v;
374  (*it1)->patch, (*it2)->patch, u, v, ncc);
375  if (ncc > maxncc)
376  {
377  maxncc = ncc;
378  idxncc = cnt;
379  }
380 
381  // Compute distance between descriptors SIFT
382  float siftd = (*it1)->descriptorSIFTDistanceTo(*(*it2));
383  if (siftd < minsiftd)
384  {
385  minsiftd = siftd;
386  idxsiftd = cnt;
387  }
388 
389  // Compute distance between descriptors SIFT
390  float surfd = (*it1)->descriptorSURFDistanceTo(*(*it2));
391  if (surfd < minsurfd)
392  {
393  minsurfd = surfd;
394  idxsurfd = cnt;
395  }
396 
397  // Plot images + features + each candidate + difference score
398  if (firstMatch)
399  {
400  copyjoinimage.line(
401  (*it1)->x + imW, 0, (*it1)->x + imW, imH,
402  TColor::green()); // Limit line (only the first time)
403  firstMatch = false;
404  } // end-if
405 
406  copyjoinimage.drawCircle(
407  (*it2)->x + imW, (*it2)->y, 4, TColor::blue(),
408  2); // Keypoint
409  double rx0, rx1, ry0, ry1, tx, ty;
410  rx0 = (*it2)->x + imW - 15;
411  rx1 = (*it2)->x + imW;
412  tx = (*it2)->x + imW - 13;
413  if (cnt % 2)
414  {
415  ry0 = (*it2)->y - 20;
416  ry1 = (*it2)->y - 10;
417  ty = (*it2)->y - 22;
418  }
419  else
420  {
421  ry0 = (*it2)->y + 10;
422  ry1 = (*it2)->y + 20;
423  ty = (*it2)->y + 8;
424  }
425  copyjoinimage.filledRectangle(
426  rx0, ry0, rx1, ry1, TColor(150, 150, 150));
427  copyjoinimage.textOut(
428  tx, ty, format("%d", cnt), TColor::blue());
429 
430  px = 80 + cnt * 50;
431  if (px + fExt.options.patchSize > imW2) continue;
432 
433  copyInfoImage.update_patch((*it2)->patch, px, 30);
434 
435  copyInfoImage.textOut(
436  px, imH2 - 70, format("%d", cnt), TColor::blue());
437  copyInfoImage.textOut(
438  px, imH2 - 53, format("%.2f", sad), TColor::blue());
439  copyInfoImage.textOut(
440  px, imH2 - 41, format("%.2f", ncc), TColor::blue());
441  copyInfoImage.textOut(
442  px, imH2 - 29, format("%.2f", siftd), TColor::blue());
443  copyInfoImage.textOut(
444  px, imH2 - 17, format("%.2f", surfd), TColor::blue());
445 
446  cnt++;
447  } // end if
448  } // end for it2
449  copyInfoImage.textOut(
450  80 + idxsad * 50, imH2 - 53, format("%.2f", minsad),
451  TColor::green());
452  copyInfoImage.textOut(
453  80 + idxncc * 50, imH2 - 41, format("%.2f", maxncc),
454  TColor::green());
455  copyInfoImage.textOut(
456  80 + idxsiftd * 50, imH2 - 29, format("%.2f", minsiftd),
457  TColor::green());
458  copyInfoImage.textOut(
459  80 + idxsurfd * 50, imH2 - 17, format("%.2f", minsurfd),
460  TColor::green());
461 
462  win.showImage(copyjoinimage);
463  win2.showImage(copyInfoImage);
465  } // end for it1
466 
467  // Save to file
468  // Check number of good features
469 
470 } // end TestMatchingComparative
471 
472 // ------------------------------------------------------
473 // TestExtractFeatures
474 // ------------------------------------------------------
475 void TestExtractFeatures()
476 {
477  CDisplayWindow wind1, wind2, wind3, wind4, wind5;
478  CFeatureExtraction fExt;
479  CFeatureList featsHarris, featsKLT, featsSIFT_Hess, featsSIFT_Lowe,
480  featsSIFT_Vedaldi, featsSURF, featsFAST;
481  CImage img;
482 
483  if (!img.loadFromFile(the_img_for_extract_feats))
484  {
485  cerr << "Cannot load " << the_img_for_extract_feats << endl;
486  return;
487  }
488  cout << "Loaded test image: " << endl << the_img_for_extract_feats << endl;
489  cout << "------------------------------------------------------------------"
490  "--------"
491  << endl
492  << endl;
493 
494  CTicTac tictac;
495 
496  fExt.options.patchSize = 0;
497 
498  cout << "Detect Harris features... [f_harris.txt]" << endl;
499  tictac.Tic();
501  fExt.detectFeatures(img, featsHarris);
502  cout << "Detected " << featsHarris.size() << " features in ";
503  cout << format(" %.03fms", tictac.Tac() * 1000) << endl << endl;
504  featsHarris.saveToTextFile("f_harris.txt");
505  wind1.setWindowTitle("Harris detected features");
506  wind1.showImageAndPoints(img, featsHarris);
507 
508  cout << "Detect FAST features... [f_fast.txt]" << endl;
509  tictac.Tic();
510  fExt.options.featsType = featFAST;
511  fExt.options.FASTOptions.threshold = 15; // 150;
514  fExt.detectFeatures(img, featsFAST, 0, 500 /* max num feats */);
515  cout << "Detected " << featsFAST.size() << " features in ";
516  cout << format(" %.03fms", tictac.Tac() * 1000) << endl << endl;
517  featsFAST.saveToTextFile("f_fast.txt");
518  wind5.setWindowTitle("FAST detected features");
519  wind5.showImageAndPoints(img, featsFAST);
520 
521  cout << "Computing SIFT descriptors only ... [f_harris+sift.txt]" << endl;
522  tictac.Tic();
523  fExt.options.SIFTOptions.implementation = CFeatureExtraction::Hess;
524  fExt.computeDescriptors(img, featsHarris, descSIFT);
525  cout << format(" %.03fms", tictac.Tac() * 1000) << endl << endl;
526  featsHarris.saveToTextFile("f_harris+sift.txt");
527 
528  cout << "Extracting KLT features... [f_klt.txt]" << endl;
529  tictac.Tic();
530  fExt.options.featsType = featKLT;
531  fExt.options.KLTOptions.threshold = 0.05f;
532  fExt.options.KLTOptions.radius = 5;
533  fExt.detectFeatures(img, featsKLT, 0, 10);
534  cout << "Detected " << featsKLT.size() << " features in ";
535  cout << format(" %.03fms", tictac.Tac() * 1000) << endl << endl;
536  featsKLT.saveToTextFile("f_klt.txt");
537  wind2.setWindowTitle("KLT detected features");
538  wind2.showImageAndPoints(img, featsKLT);
539 
540  cout << "Extracting SIFT features... [f_sift_hess.txt]" << endl;
541  tictac.Tic();
542  fExt.options.featsType = featSIFT;
543  fExt.options.SIFTOptions.implementation = CFeatureExtraction::Hess;
544  fExt.detectFeatures(img, featsSIFT_Hess);
545  cout << "Detected " << featsSIFT_Hess.size() << " features in ";
546  cout << format(" %.03fms", tictac.Tac() * 1000) << endl << endl;
547  featsSIFT_Hess.saveToTextFile("f_sift_hess.txt");
548  wind3.setWindowTitle("SIFT Hess detected features");
549  wind3.showImageAndPoints(img, featsSIFT_Hess);
550 
551  cout << "Extracting SURF features... [f_surf.txt]" << endl;
552  tictac.Tic();
553  fExt.options.featsType = featSURF;
554  fExt.detectFeatures(img, featsSURF);
555  cout << "Detected " << featsSURF.size() << " features in ";
556  cout << format(" %.03fms", tictac.Tac() * 1000) << endl << endl;
557  featsSURF.saveToTextFile("f_surf.txt");
558  wind4.setWindowTitle("SURF detected features");
559  wind4.showImageAndPoints(img, featsSURF);
560 
561  cout << "Computing spin images descriptors only ... [f_harris+spinimgs.txt]"
562  << endl;
563  tictac.Tic();
564  fExt.options.SpinImagesOptions.radius = 13;
567  fExt.computeDescriptors(img, featsHarris, descSpinImages);
568  cout << format(" %.03fms", tictac.Tac() * 1000) << endl << endl;
569  featsHarris.saveToTextFile("f_harris+spinimgs.txt");
570 
572 
573  return;
574 }
575 
577 {
578  CDisplayWindow wind1, wind2;
579  CFeatureExtraction fExt;
580  CFeatureList featsHarris;
581  CImage img;
582 
583  string the_img = myDataDir + string("test_image.jpg");
584 
585  if (!img.loadFromFile(the_img))
586  {
587  cerr << "Cannot load " << the_img << endl;
588  return;
589  }
590  cout << "Loaded test image: " << the_img << endl;
591 
592  CTicTac tictac;
593 
594  cout << "Extracting Harris features (tiled)... [f_harris_tiled.txt]";
595 
597  fExt.options.harrisOptions.tile_image = true;
598 
599  tictac.Tic();
600  fExt.detectFeatures(img, featsHarris);
601  cout << format(" %.03fms", tictac.Tac() * 1000) << endl;
602 
603  cout << "Detected " << featsHarris.size() << " features in " << endl;
604  featsHarris.saveToTextFile("f_harris_tiled.txt");
605  wind1.setWindowTitle("Harris detected features (Tiled image)");
606  wind1.showTiledImageAndPoints(img, featsHarris);
607 
608  cout << "Extracting Harris features... [f_harris.txt]";
609 
610  fExt.options.harrisOptions.tile_image = false;
611 
612  tictac.Tic();
613  fExt.detectFeatures(img, featsHarris);
614  cout << format(" %.03fms", tictac.Tac() * 1000) << endl;
615 
616  featsHarris.saveToTextFile("f_harris.txt");
617  wind2.setWindowTitle("Harris detected features");
618  wind2.showTiledImageAndPoints(img, featsHarris);
619 
621 
622  return;
623 }
624 
625 int main(int argc, char** argv)
626 {
627  try
628  {
630  // TestExtractFeatures();
631  // TestExtractFeaturesTile();
632  // TestTrackFeatures();
633  // TestMatchingComparative();
634  // TestORBTiled();
635 
636  // CFeatureList fs;
637  // fs.loadFromTextFile("f_harris+sift.txt");
638  // fs.saveToTextFile("f_harris+sift2.txt");
639 
640  return 0;
641  }
642  catch (std::exception& e)
643  {
644  std::cout << "MRPT exception caught: " << e.what() << std::endl;
645  return -1;
646  }
647  catch (...)
648  {
649  printf("Another exception!!");
650  return -1;
651  }
652 }
mrpt::vision::CFeatureList::size
size_t size() const
Definition: CFeature.h:388
TestMatchingComparative
void TestMatchingComparative()
Definition: vision_stereo_rectify/test.cpp:279
mrpt::vision::CFeatureExtraction::TOptions::KLTOptions
struct mrpt::vision::CFeatureExtraction::TOptions::TKLTOptions KLTOptions
mrpt::vision::CFeatureExtraction::TOptions::TSpinImagesOptions::hist_size_distance
unsigned int hist_size_distance
"intensity" axis of the 2D histogram (default=10).
Definition: CFeatureExtraction.h:232
mrpt::vision::CFeatureExtraction::TOptions::TFASTOptions::min_distance
float min_distance
(default=5) minimum distance between
Definition: CFeatureExtraction.h:166
mrpt::vision::CFeatureExtraction
The central class from which images can be analyzed in search of different kinds of interest points a...
Definition: CFeatureExtraction.h:82
mrpt::img::CImage::getWidth
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:864
mrpt::gui::CDisplayWindow::showTiledImageAndPoints
void showTiledImageAndPoints(const mrpt::img::CImage &img, const FEATURELIST &list, const mrpt::img::TColor &color=mrpt::img::TColor::red())
Show a given color or grayscale image on the window and print a set of points on it and a set of line...
Definition: CDisplayWindow.h:108
mrpt::vision::featFAST
@ featFAST
FAST feature detector, OpenCV's implementation ("Faster and better: A machine learning approac...
Definition: vision/include/mrpt/vision/types.h:70
mrpt::vision::CFeatureExtraction::computeDescriptors
void computeDescriptors(const mrpt::img::CImage &in_img, CFeatureList &inout_features, TDescriptorType in_descriptor_list) const
Compute one (or more) descriptors for the given set of interest points onto the image,...
Definition: CFeatureExtraction_common.cpp:234
red
unsigned char red[10]
Definition: PbMapMaker.cpp:1298
green
GLclampf green
Definition: glext.h:3525
TestExtractFeatures
void TestExtractFeatures()
Definition: vision_stereo_rectify/test.cpp:475
mrpt::vision::matchFeatures
size_t matchFeatures(const CFeatureList &list1, const CFeatureList &list2, CMatchedFeatureList &matches, const TMatchingOptions &options=TMatchingOptions(), const TStereoSystemParams &params=TStereoSystemParams())
Find the matches between two lists of features which must be of the same type.
Definition: vision_utils.cpp:456
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
TestExtractFeaturesTile
void TestExtractFeaturesTile()
Definition: vision_stereo_rectify/test.cpp:576
mrpt::vision
Classes for computer vision, detectors, features, etc.
Definition: CCamModel.h:20
mrpt::img::CCanvas::cross
void cross(int x0, int y0, const mrpt::img::TColor color, char type, unsigned int size=5, unsigned int width=1)
Draw a cross.
Definition: CCanvas.cpp:305
mrpt::vision::CFeatureExtraction::TOptions::TFASTOptions::threshold
int threshold
default= 20
Definition: CFeatureExtraction.h:165
the_img_for_extract_feats
const string the_img_for_extract_feats
Definition: vision_stereo_rectify/test.cpp:24
CH_RGB
#define CH_RGB
Definition: img/CImage.h:45
mrpt::vision::CFeatureExtraction::TOptions::TSIFTOptions::implementation
TSIFTImplementation implementation
Default: Hess (OpenCV.
Definition: CFeatureExtraction.h:196
mrpt::vision::CFeatureList::iterator
TInternalFeatList::iterator iterator
Definition: CFeature.h:367
myDataDir
std::string myDataDir
Definition: vision_stereo_rectify/test.cpp:23
mrpt::gui::CDisplayWindow::setPos
void setPos(int x, int y) override
Changes the position of the window on the screen.
Definition: CDisplayWindow.cpp:621
TestExtractMatchProjectAndPaint
void TestExtractMatchProjectAndPaint()
Definition: vision_stereo_rectify/test.cpp:57
mrpt::vision::CFeatureExtraction::TOptions::THarrisOptions::tile_image
bool tile_image
Definition: CFeatureExtraction.h:152
mrpt::vision::featKLT
@ featKLT
Kanade-Lucas-Tomasi feature [SHI'94].
Definition: vision/include/mrpt/vision/types.h:55
mrpt::vision::CFeatureTracker_KL
Track a set of features from old_img -> new_img using sparse optimal flow (classic KL method).
Definition: tracking.h:320
mrpt::vision::CFeatureExtraction::TOptions::featsType
TFeatureType featsType
Type of the extracted features.
Definition: CFeatureExtraction.h:108
mrpt::vision::CFeatureList::begin
iterator begin()
Definition: CFeature.h:373
mrpt::vision::CFeatureExtraction::TOptions::TKLTOptions::radius
int radius
Definition: CFeatureExtraction.h:133
mrpt::vision::CFeatureExtraction::TOptions::patchSize
unsigned int patchSize
Size of the patch to extract, or 0 if no patch is desired (default=21).
Definition: CFeatureExtraction.h:113
mrpt::vision::openCV_cross_correlation
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...
Definition: vision_utils.cpp:56
mrpt::gui::CDisplayWindow::showImage
void showImage(const mrpt::img::CImage &img)
Show a given color or grayscale image on the window.
Definition: CDisplayWindow.cpp:417
tracking.h
ty
GLbyte ty
Definition: glext.h:6092
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
mrpt::vision::CFeatureExtraction::TOptions::TSpinImagesOptions::radius
unsigned int radius
for the "soft histogram" (default=20 units [0,255])
Definition: CFeatureExtraction.h:240
mrpt::vision::CFeatureList
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition: CFeature.h:304
v
const GLdouble * v
Definition: glext.h:3678
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::gui::CDisplayWindow::showImagesAndMatchedPoints
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...
Definition: CDisplayWindow.h:138
TestMatchFeatures
void TestMatchFeatures()
Definition: vision_stereo_rectify/test.cpp:121
mrpt::vision::descSIFT
@ descSIFT
SIFT descriptors.
Definition: vision/include/mrpt/vision/types.h:100
mrpt::img
Definition: CCanvas.h:17
mrpt::vision::CGenericFeatureTracker::trackFeatures
void trackFeatures(const mrpt::img::CImage &old_img, const mrpt::img::CImage &new_img, TSimpleFeatureList &inout_featureList)
Perform feature tracking from "old_img" to "new_img", with a (possibly empty) list of previously trac...
Definition: tracking.cpp:787
mrpt::vision::CMatchedFeatureList
A list of features.
Definition: CFeature.h:503
mrpt::vision::descSpinImages
@ descSpinImages
Intensity-domain spin image descriptors.
Definition: vision/include/mrpt/vision/types.h:104
mrpt::vision::CFeatureList::saveToTextFile
void saveToTextFile(const std::string &fileName, bool APPEND=false)
Save feature list to a text file.
Definition: CFeature.cpp:1039
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
mrpt::vision::CFeatureExtraction::TOptions::TKLTOptions::threshold
float threshold
Definition: CFeatureExtraction.h:134
mrpt::vision::featSIFT
@ featSIFT
Scale Invariant Feature Transform [LOWE'04].
Definition: vision/include/mrpt/vision/types.h:61
mrpt::vision::descSURF
@ descSURF
SURF descriptors.
Definition: vision/include/mrpt/vision/types.h:102
mrpt::img::CImage::line
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.
Definition: CImage.cpp:1296
CFeatureExtraction.h
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
mrpt::vision::featHarris
@ featHarris
Harris border and corner detector [HARRIS].
Definition: vision/include/mrpt/vision/types.h:57
mrpt::img::CImage::drawCircle
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.
Definition: CImage.cpp:1315
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
mrpt::img::CImage::joinImagesHorz
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
Definition: CImage.cpp:2437
mrpt::gui::CDisplayWindow
This class creates a window as a graphical user interface (GUI) for displaying images to the user.
Definition: CDisplayWindow.h:30
mrpt::vision::CFeatureExtraction::options
TOptions options
Set all the parameters of the desired method here.
Definition: CFeatureExtraction.h:317
mrpt::vision::CFeatureExtraction::TOptions::FASTOptions
struct mrpt::vision::CFeatureExtraction::TOptions::TFASTOptions FASTOptions
mrpt::gui::CDisplayWindow::showImageAndPoints
void showImageAndPoints(const mrpt::img::CImage &img, const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const mrpt::img::TColor &color=mrpt::img::TColor::red(), const bool &showNumbers=false)
Show a given color or grayscale image on the window and print a set of points on it.
Definition: CDisplayWindow.cpp:443
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::vision::CFeatureExtraction::TOptions::harrisOptions
struct mrpt::vision::CFeatureExtraction::TOptions::THarrisOptions harrisOptions
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
mrpt::vision::CFeatureList::end
iterator end()
Definition: CFeature.h:374
mrpt::vision::CFeatureExtraction::detectFeatures
void detectFeatures(const mrpt::img::CImage &img, CFeatureList &feats, const unsigned int init_ID=0, const unsigned int nDesiredFeatures=0, const TImageROI &ROI=TImageROI()) const
Extract features from the image based on the method defined in TOptions.
Definition: CFeatureExtraction_common.cpp:38
mrpt::vision::CFeatureExtraction::TOptions::TFASTOptions::use_KLT_response
bool use_KLT_response
(default=false) If true, use
Definition: CFeatureExtraction.h:169
mrpt::img::CImage::getHeight
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:892
img
GLint GLvoid * img
Definition: glext.h:3763
mrpt::vision::featSURF
@ featSURF
Speeded Up Robust Feature [BAY'06].
Definition: vision/include/mrpt/vision/types.h:63
mrpt::gui::CDisplayWindow::setWindowTitle
void setWindowTitle(const std::string &str) override
Changes the window title text.
Definition: CDisplayWindow.cpp:648
mrpt::vision::CFeatureExtraction::TOptions::SpinImagesOptions
struct mrpt::vision::CFeatureExtraction::TOptions::TSpinImagesOptions SpinImagesOptions
mrpt::img::CImage::update_patch
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.
Definition: CImage.cpp:1332
blue
GLclampf GLclampf blue
Definition: glext.h:3525
gui.h
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::img::CCanvas::textOut
virtual void textOut(int x0, int y0, const std::string &str, const mrpt::img::TColor color)
Renders 2D text using bitmap fonts.
Definition: CCanvas.cpp:369
mrpt::vision::CFeatureExtraction::TOptions::TSpinImagesOptions::hist_size_intensity
unsigned int hist_size_intensity
SpinImages Options.
Definition: CFeatureExtraction.h:229
mrpt::vision::TMatchingOptions::matching_method
TMatchingMethod matching_method
Matching method.
Definition: vision/include/mrpt/vision/types.h:412
TestTrackFeatures
void TestTrackFeatures()
Definition: vision_stereo_rectify/test.cpp:26
mrpt::img::CImage::loadFromFile
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
Definition: CImage.cpp:271
mrpt::vision::CFeatureExtraction::TOptions::SIFTOptions
struct mrpt::vision::CFeatureExtraction::TOptions::TSIFTOptions SIFTOptions
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117
mrpt::vision::computeSAD
double computeSAD(const mrpt::img::CImage &patch1, const mrpt::img::CImage &patch2)
Calculates the Sum of Absolutes Differences (range [0,1]) between two patches.
Definition: vision_utils.cpp:949
mrpt::system::pause
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...
Definition: os.cpp:428
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
mrpt::img::CCanvas::filledRectangle
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
Definition: CCanvas.cpp:214
mrpt::vision::TMatchingOptions
A structure containing options for the matching.
Definition: vision/include/mrpt/vision/types.h:359



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST