24 #include <mrpt/examples_config.h>
26 MRPT_EXAMPLES_BASE_DIRECTORY +
27 string(
"img_correlation_example/"));
37 printf(
"Loading matrix from file...");
38 A.loadFromTextFile(
"dft2_test.txt");
42 "Computing 2D FFT of %ux%u...", (
unsigned int)A.rows(),
43 (
unsigned int)A.cols());
46 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
48 RES_R.saveToTextFile(
"_out_dft2_real.txt");
49 RES_I.saveToTextFile(
"_out_dft2_imag.txt");
52 "Computing 2D IFFT of %ux%u...", (
unsigned int)A.rows(),
53 (
unsigned int)A.cols());
56 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
64 D.find_index_max_value(u,
v, maxError);
66 printf(
"Maximum error between 'A' and 'IFFT(FFT(A))'=%e\n", maxError);
74 CMatrix DATA_R, DATA_I, RES_R, RES_I, B_R, B_I, D_R, D_I;
77 printf(
"Loading matrix from file...");
78 DATA_R.loadFromTextFile(
"complex_dft2_test_real.txt");
79 DATA_I.loadFromTextFile(
"complex_dft2_test_imag.txt");
83 "Computing 2D complex FFT of %ux%u...", (
unsigned int)DATA_R.rows(),
84 (
unsigned int)DATA_R.cols());
87 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
89 RES_R.saveToTextFile(
"_out_complex_dft2_real.txt");
90 RES_I.saveToTextFile(
"_out_complex_dft2_imag.txt");
93 "Computing 2D complex IFFT of %ux%u...", (
unsigned int)DATA_R.rows(),
94 (
unsigned int)DATA_R.cols());
97 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
104 float maxError_R, maxError_I;
106 D_R.find_index_max_value(u,
v, maxError_R);
107 D_I.find_index_max_value(u,
v, maxError_I);
109 printf(
"Maximum error between 'A' and 'IFFT(FFT(A))'=%e\n", maxError_R);
110 printf(
"Maximum error between 'A' and 'IFFT(FFT(A))'=%e\n", maxError_I);
123 myDataDir +
string(
"fft2_test_image_patch.jpg"), 0);
125 myDataDir +
string(
"fft2_test_image.jpg"), 0);
127 printf(
"Computing images correlation...");
130 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
132 imgCorr.saveToTextFile(
"_out_dft2_image_test.txt");
171 if (!
img.loadFromFile(
"../img_basic_example/frame_color.bmp"))
173 cerr <<
"Error loading ../img_basic_example/frame_color.bmp"
177 printf(
"bmp file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
184 img.loadFromFile(
"frame_gray.bmp");
185 printf(
"bmp file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
194 img.loadFromFile(
"frame.jpg");
195 printf(
"jpeg file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
200 CImage imgSmall2(imgSmall.scaleHalf());
201 CImage imgGray(imgSmall2.grayscale());
205 imgSmall.rectangle(85, 35, 170, 170,
TColor(255, 0, 0), 10);
207 imgSmall.line(550, 75, 650, 25,
TColor(0, 0, 255));
208 imgSmall.line(-10, -20, 20, 30,
TColor(0, 0, 255));
213 COV(0, 1) = COV(1, 0) = -30;
214 imgSmall.ellipseGaussian(&COV, 600.0f, 50.0f, 2,
TColor(255, 255, 0), 4);
215 imgGray.ellipseGaussian(&COV, 100.0f, 100.0f, 2,
TColor(0, 0, 255), 4);
217 imgSmall.drawImage(400, 500, imgGray);
221 win1.showImage(imgSmall);
223 win2.showImage(imgSmall2);
225 win3.showImage(imgGray);
226 win3.setPos(810, 400);
232 printf(
"jpeg file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
288 catch (std::exception& e)
290 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
295 printf(
"Untyped exception!!");