42 #include <visp3/core/vpConfig.h>
44 #if defined(VISP_HAVE_CATCH2) && (VISP_HAVE_DATASET_VERSION >= 0x030300)
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]")
127 for (
size_t i = 0; i < interp_methods.size(); i++) {
128 SECTION(interp_names[i])
130 SECTION(
"Empty destination")
134 CHECK((I == I_affine));
137 SECTION(
"Initialized destination")
141 CHECK((I == I_affine));
147 SECTION(
"Rotation 45 deg")
153 M[0][0] = cos(theta);
154 M[0][1] = -sin(theta);
156 M[1][0] = sin(theta);
157 M[1][1] = cos(theta);
160 for (
size_t i = 0; i < interp_methods.size(); i++) {
161 SECTION(interp_names[i])
163 SECTION(
"Against reference implementation")
171 double percentage = 0.0;
172 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
173 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" Ref): " << percentage << std::endl;
177 SECTION(
"Against OpenCV")
189 double percentage = 0.0;
190 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
191 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
192 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
196 SECTION(
"Against PIL")
207 double percentage = 0.0;
208 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
209 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
210 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
223 const double scale = 0.83;
224 M[0][0] = scale * cos(theta);
225 M[0][1] = -scale * sin(theta);
227 M[1][0] = scale * sin(theta);
228 M[1][1] = scale * cos(theta);
231 for (
size_t i = 0; i < interp_methods.size(); i++) {
232 SECTION(interp_names[i])
234 SECTION(
"Against reference implementation")
242 double percentage = 0.0;
243 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
244 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
248 SECTION(
"Against OpenCV")
259 double percentage = 0.0;
260 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
261 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
262 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
266 SECTION(
"Against PIL")
277 double percentage = 0.0;
278 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
279 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
280 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
288 TEST_CASE(
"Affine warp on color",
"[warp_image]")
302 for (
size_t i = 0; i < interp_methods.size(); i++) {
303 SECTION(interp_names[i])
305 SECTION(
"Empty destination")
309 CHECK((I == I_affine));
312 SECTION(
"Initialized destination")
316 CHECK((I == I_affine));
322 SECTION(
"Rotation 45 deg")
328 M[0][0] = cos(theta);
329 M[0][1] = -sin(theta);
331 M[1][0] = sin(theta);
332 M[1][1] = cos(theta);
335 for (
size_t i = 0; i < interp_methods.size(); i++) {
336 SECTION(interp_names[i])
338 SECTION(
"Against reference implementation")
346 double percentage = 0.0;
347 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
348 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" Ref): " << percentage << std::endl;
352 SECTION(
"Against OpenCV")
363 double percentage = 0.0;
364 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
365 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
366 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
370 SECTION(
"Against PIL")
381 double percentage = 0.0;
382 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
383 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
384 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
397 const double scale = 0.83;
398 M[0][0] = scale * cos(theta);
399 M[0][1] = -scale * sin(theta);
401 M[1][0] = scale * sin(theta);
402 M[1][1] = scale * cos(theta);
405 for (
size_t i = 0; i < interp_methods.size(); i++) {
406 SECTION(interp_names[i])
408 SECTION(
"Against reference implementation")
416 double percentage = 0.0;
417 bool equal = almostEqual(I_ref, I_affine, g_threshold_value,
418 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
419 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
423 SECTION(
"Against OpenCV")
434 double percentage = 0.0;
435 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
436 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
437 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
441 SECTION(
"Against PIL")
452 double percentage = 0.0;
453 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
454 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
455 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
463 TEST_CASE(
"Perspective warp on grayscale",
"[warp_image]")
477 for (
size_t i = 0; i < interp_methods.size(); i++) {
478 SECTION(interp_names[i])
480 SECTION(
"Empty destination")
484 CHECK((I == I_perspective));
487 SECTION(
"Initialized destination")
491 CHECK((I == I_perspective));
497 SECTION(
"Rotation 45 deg")
503 M[0][0] = cos(theta);
504 M[0][1] = -sin(theta);
506 M[1][0] = sin(theta);
507 M[1][1] = cos(theta);
510 SECTION(
"Nearest Neighbor")
518 double percentage = 0.0;
519 bool equal = almostEqual(I_ref, I_perspective, g_threshold_value, g_threshold_percentage, percentage);
520 std::cout <<
"Percentage valid pixels (persp 45 deg): " << percentage << std::endl;
525 SECTION(
"Homography")
539 for (
size_t i = 0; i < interp_methods.size(); i++) {
540 SECTION(interp_names[i])
542 SECTION(
"Against reference implementation")
550 double percentage = 0.0;
552 almostEqual(I_ref, I_perspective, g_threshold_value,
553 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
554 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage
559 SECTION(
"Against OpenCV")
570 double percentage = 0.0;
572 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
573 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
574 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage
579 SECTION(
"Against PIL")
590 double percentage = 0.0;
592 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
593 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
594 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage
603 TEST_CASE(
"Perspective warp on color",
"[warp_image]")
617 for (
size_t i = 0; i < interp_methods.size(); i++) {
618 SECTION(interp_names[i])
620 SECTION(
"Empty destination")
624 CHECK((I == I_perspective));
627 SECTION(
"Initialized destination")
631 CHECK((I == I_perspective));
637 SECTION(
"Homography")
651 for (
size_t i = 0; i < interp_methods.size(); i++) {
652 SECTION(interp_names[i])
654 SECTION(
"Against reference implementation")
662 double percentage = 0.0;
664 almostEqual(I_ref, I_perspective, g_threshold_value,
665 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
666 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage
671 SECTION(
"Against OpenCV")
682 double percentage = 0.0;
684 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
685 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
686 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage
691 SECTION(
"Against PIL")
702 double percentage = 0.0;
704 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
705 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
706 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage
715 int main(
int argc,
char *argv[])
717 Catch::Session session;
720 session.applyCommandLine(argc, argv);
722 int numFailed = session.run();
730 int main() {
return EXIT_SUCCESS; }
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
unsigned int getWidth() const
unsigned int getSize() const
unsigned int getHeight() const
static double rad(double deg)
static Type abs(const Type &x)
Implementation of a matrix and operations on matrices.