22 #include <mrpt/examples_config.h> 23 string myDataDir(MRPT_EXAMPLES_BASE_DIRECTORY +
string(
"img_convolution_fft/"));
30 "/Trabajo/Experimentos/[2009] vOdometry Characterization/right1.jpg");
32 "/Trabajo/Experimentos/[2009] vOdometry Characterization/right2.jpg");
40 "J:/Trabajo/Experimentos/[2009] vOdometry Characterization/before.txt");
51 "/Trabajo/Experimentos/[2009] vOdometry Characterization/after.txt");
65 string imgL = MRPT_EXAMPLES_BASE_DIRECTORY +
66 string(
"vision_feature_extraction/") +
67 string(
"imgs/imL_p01.jpg");
68 string imgR = MRPT_EXAMPLES_BASE_DIRECTORY +
69 string(
"vision_feature_extraction/") +
70 string(
"imgs/imR_p01.jpg");
75 cerr <<
"Cannot load " << imgL << endl;
78 cout <<
"Loaded test image: " << imgL << endl;
82 cerr <<
"Cannot load " << imgR << endl;
85 cout <<
"Loaded test image: " << imgR << endl;
87 cout <<
"***************************************************" << endl;
88 cout <<
"***************************************************" << endl;
92 cout <<
"Detecting HARRIS features in LEFT image" << endl;
95 cout <<
"Detected " << featsHarris_L.
size() << endl;
97 cout <<
"Detecting HARRIS features in RIGHT image" << endl;
99 cout <<
"Detected " << featsHarris_R.
size() << endl;
101 cout <<
"***************************************************" << endl;
102 cout <<
"***************************************************" << endl;
109 cout <<
"Matching HARRIS features by CORRELATION" << endl;
112 cout <<
"Matches found: " << mHarris.size() << endl;
114 cout <<
"***************************************************" << endl;
125 CFeatureList featsHarris_L, featsHarris_R, featsSIFT_L, featsSIFT_R,
126 featsSURF_L, featsSURF_R, featsFAST_L, featsFAST_R;
130 string imgL = MRPT_EXAMPLES_BASE_DIRECTORY +
131 string(
"vision_feature_extraction/") +
132 string(
"imgs/imL_p01.jpg");
133 string imgR = MRPT_EXAMPLES_BASE_DIRECTORY +
134 string(
"vision_feature_extraction/") +
135 string(
"imgs/imR_p01.jpg");
145 cerr <<
"Cannot load " << imgL << endl;
148 cout <<
"Loaded test image: " << imgL << endl;
152 cerr <<
"Cannot load " << imgR << endl;
155 cout <<
"Loaded test image: " << imgR << endl;
157 cout <<
"***************************************************" << endl;
158 cout <<
"***************************************************" << endl;
162 cout <<
"Detecting HARRIS features in LEFT image" << endl;
165 cout <<
"Detected " << featsHarris_L.
size() << endl;
167 cout <<
"Detecting HARRIS features in RIGHT image" << endl;
169 cout <<
"Detected " << featsHarris_R.
size() << endl;
170 cout <<
"***************************************************" << endl;
173 cout <<
"Detecting SIFT features in LEFT image" << endl;
178 cout <<
"Detected " << featsSIFT_L.
size() << endl;
180 cout <<
"Detecting SIFT features in RIGHT image" << endl;
185 cout <<
"Detected " << featsSIFT_R.
size() << endl;
186 cout <<
"***************************************************" << endl;
189 cout <<
"Detecting SURF features in LEFT image" << endl;
192 cout <<
"Detected " << featsSURF_L.
size() << endl;
194 cout <<
"Detecting SURF features in RIGHT image" << endl;
196 cout <<
"Detected " << featsSURF_R.
size() << endl;
197 cout <<
"***************************************************" << endl;
200 cout <<
"Detecting FAST features in LEFT image" << endl;
203 cout <<
"Detected " << featsFAST_L.
size() << endl;
205 fast1.showImageAndPoints(imL, featsFAST_L);
207 cout <<
"Detecting FAST features in RIGHT image" << endl;
209 cout <<
"Detected " << featsFAST_R.
size() << endl;
210 cout <<
"***************************************************" << endl;
211 cout <<
"***************************************************" << endl;
213 fast2.showImageAndPoints(imR, featsFAST_R);
221 cout <<
"Matching HARRIS features by CORRELATION" << endl;
225 double T = tictac.
Tac();
226 cout <<
"[CC] Matches found: " << mHarris.size() <<
" in " << T * 1000.0f
232 matchFeatures(featsHarris_L, featsHarris_R, mHarris_SAD, opt);
234 cout <<
"[SAD] Matches found: " << mHarris_SAD.size() <<
" in " 235 << T * 1000.0f <<
" ms " << endl;
236 cout <<
"***************************************************" << endl;
240 cout <<
"Matching SIFT features by DESCRIPTOR" << endl;
244 cout <<
"Matches found: " << mSIFT.size() << endl;
245 cout <<
"***************************************************" << endl;
248 cout <<
"Matching SURF features by DESCRIPTOR" << endl;
252 cout <<
"Matches found: " << mSURF.size() << endl;
253 cout <<
"***************************************************" << endl;
256 cout <<
"Matching FAST features by CC" << endl;
261 cout <<
"[CC] Matches found: " << mFAST_CC.size() <<
" in " << T * 1000.0f
269 cout <<
"[SAD] Matches found: " << mFAST_SAD.size() <<
" in " << T * 1000.0f
271 cout <<
"***************************************************" << endl;
282 string imgL = MRPT_EXAMPLES_BASE_DIRECTORY +
283 string(
"vision_feature_extraction/") +
284 string(
"imgs/imL_p01.jpg");
285 string imgR = MRPT_EXAMPLES_BASE_DIRECTORY +
286 string(
"vision_feature_extraction/") +
287 string(
"imgs/imR_p01.jpg");
314 for (it1 = list1.
begin(); it1 != list1.
end(); ++it1)
316 for (it2 = list2.
begin(); it2 != list2.
end(); ++it2)
321 win2.
setPos(0, imH * 1.5);
322 CImage joinimage, copyjoinimage, copyInfoImage;
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)
336 copyInfoImage = infoimage;
337 copyjoinimage = joinimage;
341 (*it1)->x + imW, 0, (*it1)->x + imW, imH,
349 bool firstMatch =
true;
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;
356 for (it2 = list2.
begin(); it2 != list2.
end(); ++it2)
358 if (fabs((*it1)->y - (*it2)->y) <= 1.0 && (*it1)->x > (*it2)->x)
374 (*it1)->patch, (*it2)->patch, u,
v, ncc);
382 float siftd = (*it1)->descriptorSIFTDistanceTo(*(*it2));
383 if (siftd < minsiftd)
390 float surfd = (*it1)->descriptorSURFDistanceTo(*(*it2));
391 if (surfd < minsurfd)
401 (*it1)->x + imW, 0, (*it1)->x + imW, imH,
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;
415 ry0 = (*it2)->y - 20;
416 ry1 = (*it2)->y - 10;
421 ry0 = (*it2)->y + 10;
422 ry1 = (*it2)->y + 20;
426 rx0, ry0, rx1, ry1,
TColor(150, 150, 150));
450 80 + idxsad * 50, imH2 - 53,
format(
"%.2f", minsad),
453 80 + idxncc * 50, imH2 - 41,
format(
"%.2f", maxncc),
456 80 + idxsiftd * 50, imH2 - 29,
format(
"%.2f", minsiftd),
459 80 + idxsurfd * 50, imH2 - 17,
format(
"%.2f", minsurfd),
462 win.showImage(copyjoinimage);
479 CFeatureList featsHarris, featsKLT, featsSIFT_Hess, featsSIFT_Lowe,
480 featsSIFT_Vedaldi, featsSURF, featsFAST;
489 cout <<
"------------------------------------------------------------------" 498 cout <<
"Detect Harris features... [f_harris.txt]" << endl;
502 cout <<
"Detected " << featsHarris.
size() <<
" features in ";
503 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl << endl;
508 cout <<
"Detect FAST features... [f_fast.txt]" << endl;
515 cout <<
"Detected " << featsFAST.
size() <<
" features in ";
516 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl << endl;
521 cout <<
"Computing SIFT descriptors only ... [f_harris+sift.txt]" << endl;
525 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl << endl;
528 cout <<
"Extracting KLT features... [f_klt.txt]" << endl;
534 cout <<
"Detected " << featsKLT.
size() <<
" features in ";
535 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl << endl;
540 cout <<
"Extracting SIFT features... [f_sift_hess.txt]" << endl;
545 cout <<
"Detected " << featsSIFT_Hess.
size() <<
" features in ";
546 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl << endl;
551 cout <<
"Extracting SURF features... [f_surf.txt]" << endl;
555 cout <<
"Detected " << featsSURF.
size() <<
" features in ";
556 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl << endl;
561 cout <<
"Computing spin images descriptors only ... [f_harris+spinimgs.txt]" 568 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl << endl;
585 if (!
img.loadFromFile(the_img))
587 cerr <<
"Cannot load " << the_img << endl;
590 cout <<
"Loaded test image: " << the_img << endl;
594 cout <<
"Extracting Harris features (tiled)... [f_harris_tiled.txt]";
601 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl;
603 cout <<
"Detected " << featsHarris.
size() <<
" features in " << endl;
608 cout <<
"Extracting Harris features... [f_harris.txt]";
614 cout <<
format(
" %.03fms", tictac.
Tac() * 1000) << endl;
625 int main(
int argc,
char** argv)
642 catch (std::exception& e)
644 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
649 printf(
"Another exception!!");
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 TestExtractFeatures()
void TestMatchingComparative()
void cross(int x0, int y0, const mrpt::img::TColor color, char type, unsigned int size=5, unsigned int width=1)
Draw a cross.
TInternalFeatList::iterator iterator
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...
void TestExtractFeaturesTile()
A high-performance stopwatch, with typical resolution of nanoseconds.
void TestExtractMatchProjectAndPaint()
size_t getHeight() const override
Returns the height of the image in pixels.
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
const string the_img_for_extract_feats
void setWindowTitle(const std::string &str) override
Changes the window title text.
FAST feature detector, OpenCV's implementation ("Faster and better: A machine learning approach to...
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.
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
Harris border and corner detector [HARRIS].
Scale Invariant Feature Transform [LOWE'04].
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
Classes for computer vision, detectors, features, etc.
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...
mrpt::gui::CDisplayWindow3D::Ptr win
GLsizei const GLchar ** string
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 saveToTextFile(const std::string &fileName, bool APPEND=false)
Save feature list to a text file.
Track a set of features from old_img -> new_img using sparse optimal flow (classic KL method)...
Speeded Up Robust Feature [BAY'06].
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
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.
double computeSAD(const mrpt::img::CImage &patch1, const mrpt::img::CImage &patch2)
Calculates the Sum of Absolutes Differences (range [0,1]) between two patches.
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.
Intensity-domain spin image descriptors.
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...
TMatchingMethod matching_method
Matching method.
Kanade-Lucas-Tomasi feature [SHI'94].
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...
A class for storing images as grayscale or RGB bitmaps.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.