42 #include <visp3/core/vpConfig.h> 44 #if defined(VISP_HAVE_CATCH2) 45 #define CATCH_CONFIG_RUNNER 49 #include <visp3/core/vpImageTools.h> 50 #include <visp3/core/vpIoTools.h> 51 #include <visp3/io/vpImageIo.h> 55 static const double g_threshold_value = 0.5;
56 static const double g_threshold_percentage = 0.9;
57 static const double g_threshold_percentage_bilinear = 0.75;
58 static const double g_threshold_percentage_pers = 0.75;
59 static const double g_threshold_percentage_pers_bilinear = 0.65;
63 static const std::vector<std::string> interp_names = {
"Nearest Neighbor",
"Bilinear"};
64 static const std::vector<std::string> suffixes = {
"_NN.png",
"_bilinear.png" };
67 double threshold_percentage,
double& percentage)
75 for (
unsigned int i = 0; i < I1.
getHeight(); i++) {
76 for (
unsigned int j = 0; j < I1.
getWidth(); j++) {
77 nb_valid +=
vpMath::abs(I1[i][j] - I2[i][j]) < threshold_val ? 1 : 0;
81 percentage = nb_valid / I1.
getSize();
82 return percentage >= threshold_percentage;
86 double threshold_percentage,
double& percentage)
94 for (
unsigned int i = 0; i < I1.
getHeight(); i++) {
95 for (
unsigned int j = 0; j < I1.
getWidth(); j++) {
96 if (
vpMath::abs(I1[i][j].R - I2[i][j].R) < threshold_val) {
99 if (
vpMath::abs(I1[i][j].G - I2[i][j].G) < threshold_val) {
102 if (
vpMath::abs(I1[i][j].B - I2[i][j].B) < threshold_val) {
108 percentage = nb_valid / (3*I1.
getSize());
109 return percentage >= threshold_percentage;
113 TEST_CASE(
"Affine warp on grayscale",
"[warp_image]") {
126 for (
size_t i = 0; i < interp_methods.size(); i++) {
127 SECTION(interp_names[i])
129 SECTION(
"Empty destination")
133 CHECK((I == I_affine));
136 SECTION(
"Initialized destination")
140 CHECK((I == I_affine));
146 SECTION(
"Rotation 45 deg")
152 M[0][0] = cos(theta); M[0][1] = -sin(theta); M[0][2] = I.
getWidth() / 2.0;
153 M[1][0] = sin(theta); M[1][1] = cos(theta); M[1][2] = I.
getHeight() / 2.0;
155 for (
size_t i = 0; i < interp_methods.size(); i++) {
156 SECTION(interp_names[i])
158 SECTION(
"Against reference implementation")
166 double percentage = 0.0;
167 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
168 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" Ref): " << percentage << std::endl;
172 SECTION(
"Against OpenCV")
175 std::string(
"warp/cv_warp_affine_rot_45_gray" + suffixes[i]));
183 double percentage = 0.0;
184 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
185 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
189 SECTION(
"Against PIL")
192 std::string(
"warp/pil_warp_affine_rot_45_gray" + suffixes[i]));
200 double percentage = 0.0;
201 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
202 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
215 const double scale = 0.83;
216 M[0][0] = scale*cos(theta); M[0][1] = -scale*sin(theta); M[0][2] = I.
getWidth() / 2.0 + 17;
217 M[1][0] = scale*sin(theta); M[1][1] = scale*cos(theta); M[1][2] = I.
getHeight() / 2.0 - 23;
219 for (
size_t i = 0; i < interp_methods.size(); i++) {
220 SECTION(interp_names[i])
222 SECTION(
"Against reference implementation")
230 double percentage = 0.0;
231 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
232 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
236 SECTION(
"Against OpenCV")
239 std::string(
"warp/cv_warp_affine_SRT_gray" + suffixes[i]));
247 double percentage = 0.0;
248 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
249 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
253 SECTION(
"Against PIL")
256 std::string(
"warp/pil_warp_affine_SRT_gray" + suffixes[i]));
264 double percentage = 0.0;
265 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
266 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
274 TEST_CASE(
"Affine warp on color",
"[warp_image]") {
287 for (
size_t i = 0; i < interp_methods.size(); i++) {
288 SECTION(interp_names[i])
290 SECTION(
"Empty destination")
294 CHECK((I == I_affine));
297 SECTION(
"Initialized destination")
301 CHECK((I == I_affine));
307 SECTION(
"Rotation 45 deg")
313 M[0][0] = cos(theta); M[0][1] = -sin(theta); M[0][2] = I.
getWidth() / 2.0;
314 M[1][0] = sin(theta); M[1][1] = cos(theta); M[1][2] = I.
getHeight() / 2.0;
316 for (
size_t i = 0; i < interp_methods.size(); i++) {
317 SECTION(interp_names[i])
319 SECTION(
"Against reference implementation")
327 double percentage = 0.0;
328 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
329 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" Ref): " << percentage << std::endl;
333 SECTION(
"Against OpenCV")
336 std::string(
"warp/cv_warp_affine_rot_45_color" + suffixes[i]));
344 double percentage = 0.0;
345 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
346 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
350 SECTION(
"Against PIL")
353 std::string(
"warp/pil_warp_affine_rot_45_color" + suffixes[i]));
361 double percentage = 0.0;
362 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
363 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
376 const double scale = 0.83;
377 M[0][0] = scale * cos(theta); M[0][1] = -scale * sin(theta); M[0][2] = I.
getWidth() / 2.0 + 17;
378 M[1][0] = scale * sin(theta); M[1][1] = scale * cos(theta); M[1][2] = I.
getHeight() / 2.0 - 23;
380 for (
size_t i = 0; i < interp_methods.size(); i++) {
381 SECTION(interp_names[i])
383 SECTION(
"Against reference implementation")
391 double percentage = 0.0;
392 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
393 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
397 SECTION(
"Against OpenCV")
400 std::string(
"warp/cv_warp_affine_SRT_color" + suffixes[i]));
408 double percentage = 0.0;
409 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
410 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
414 SECTION(
"Against PIL")
417 std::string(
"warp/pil_warp_affine_SRT_color" + suffixes[i]));
425 double percentage = 0.0;
426 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value, (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
427 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
435 TEST_CASE(
"Perspective warp on grayscale",
"[warp_image]") {
448 for (
size_t i = 0; i < interp_methods.size(); i++) {
449 SECTION(interp_names[i])
451 SECTION(
"Empty destination")
455 CHECK((I == I_perspective));
458 SECTION(
"Initialized destination")
462 CHECK((I == I_perspective));
468 SECTION(
"Rotation 45 deg")
474 M[0][0] = cos(theta); M[0][1] = -sin(theta); M[0][2] = I.
getWidth() / 2.0;
475 M[1][0] = sin(theta); M[1][1] = cos(theta); M[1][2] = I.
getHeight() / 2.0;
477 SECTION(
"Nearest Neighbor")
485 double percentage = 0.0;
486 bool equal = almostEqual(I_ref, I_perspective, g_threshold_value, g_threshold_percentage, percentage);
487 std::cout <<
"Percentage valid pixels (persp 45 deg): " << percentage << std::endl;
492 SECTION(
"Homography")
497 M[0][0] = 1.8548; M[0][1] = -0.0402; M[0][2] = 114.9;
498 M[1][0] = 1.1209; M[1][1] = 4.0106; M[1][2] = 111;
499 M[2][0] = 0.0022; M[2][1] = 0.0064;
501 for (
size_t i = 0; i < interp_methods.size(); i++) {
502 SECTION(interp_names[i])
504 SECTION(
"Against reference implementation")
512 double percentage = 0.0;
513 bool equal = almostEqual(I_ref, I_perspective, g_threshold_value,
514 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
515 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage << std::endl;
519 SECTION(
"Against OpenCV")
522 std::string(
"warp/cv_warp_perspective_gray" + suffixes[i]));
530 double percentage = 0.0;
531 bool equal = almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
532 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
533 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
537 SECTION(
"Against PIL")
540 std::string(
"warp/pil_warp_perspective_gray" + suffixes[i]));
548 double percentage = 0.0;
549 bool equal = almostEqual(I_ref_pil, I_perspective, g_threshold_value,
550 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
551 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage << std::endl;
559 TEST_CASE(
"Perspective warp on color",
"[warp_image]") {
572 for (
size_t i = 0; i < interp_methods.size(); i++) {
573 SECTION(interp_names[i])
575 SECTION(
"Empty destination")
579 CHECK((I == I_perspective));
582 SECTION(
"Initialized destination")
586 CHECK((I == I_perspective));
592 SECTION(
"Homography")
597 M[0][0] = 1.8548; M[0][1] = -0.0402; M[0][2] = 114.9;
598 M[1][0] = 1.1209; M[1][1] = 4.0106; M[1][2] = 111;
599 M[2][0] = 0.0022; M[2][1] = 0.0064;
601 for (
size_t i = 0; i < interp_methods.size(); i++) {
602 SECTION(interp_names[i])
604 SECTION(
"Against reference implementation")
612 double percentage = 0.0;
613 bool equal = almostEqual(I_ref, I_perspective, g_threshold_value,
614 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
615 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage << std::endl;
619 SECTION(
"Against OpenCV")
622 std::string(
"warp/cv_warp_perspective_color" + suffixes[i]));
630 double percentage = 0.0;
631 bool equal = almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
632 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
633 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
637 SECTION(
"Against PIL")
640 std::string(
"warp/pil_warp_perspective_color" + suffixes[i]));
648 double percentage = 0.0;
649 bool equal = almostEqual(I_ref_pil, I_perspective, g_threshold_value,
650 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
651 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage << std::endl;
659 int main(
int argc,
char *argv[])
661 Catch::Session session;
664 session.applyCommandLine(argc, argv);
666 int numFailed = session.run();
Implementation of a matrix and operations on matrices.
unsigned int getWidth() const
static Type abs(const Type &x)
unsigned int getSize() const
static double rad(double deg)
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const