40 #include <visp3/core/vpConfig.h>
42 #if defined(VISP_HAVE_CATCH2) && (VISP_HAVE_DATASET_VERSION >= 0x030300)
44 #include <catch_amalgamated.hpp>
47 #include <visp3/core/vpImageTools.h>
48 #include <visp3/core/vpIoTools.h>
49 #include <visp3/io/vpImageIo.h>
51 #ifdef ENABLE_VISP_NAMESPACE
57 static const double g_threshold_value = 0.5;
58 static const double g_threshold_percentage = 0.9;
59 static const double g_threshold_percentage_bilinear = 0.75;
60 static const double g_threshold_percentage_pers = 0.75;
61 static const double g_threshold_percentage_pers_bilinear = 0.65;
65 static const std::vector<std::string> interp_names = {
"Nearest Neighbor",
"Bilinear" };
66 static const std::vector<std::string> suffixes = {
"_NN.png",
"_bilinear.png" };
69 double threshold_percentage,
double &percentage)
77 for (
unsigned int i = 0; i < I1.
getHeight(); i++) {
78 for (
unsigned int j = 0; j < I1.
getWidth(); j++) {
79 nb_valid +=
vpMath::abs(I1[i][j] - I2[i][j]) < threshold_val ? 1 : 0;
83 percentage = nb_valid / I1.
getSize();
84 return percentage >= threshold_percentage;
88 double threshold_percentage,
double &percentage)
96 for (
unsigned int i = 0; i < I1.
getHeight(); i++) {
97 for (
unsigned int j = 0; j < I1.
getWidth(); j++) {
98 if (
vpMath::abs(I1[i][j].R - I2[i][j].R) < threshold_val) {
101 if (
vpMath::abs(I1[i][j].G - I2[i][j].G) < threshold_val) {
104 if (
vpMath::abs(I1[i][j].B - I2[i][j].B) < threshold_val) {
110 percentage = nb_valid / (3 * I1.
getSize());
111 return percentage >= threshold_percentage;
115 TEST_CASE(
"Affine warp on grayscale",
"[warp_image]")
129 for (
size_t i = 0; i < interp_methods.size(); i++) {
130 SECTION(interp_names[i])
132 SECTION(
"Empty destination")
136 CHECK((I == I_affine));
139 SECTION(
"Initialized destination")
143 CHECK((I == I_affine));
149 SECTION(
"Rotation 45 deg")
155 M[0][0] = cos(theta);
156 M[0][1] = -sin(theta);
158 M[1][0] = sin(theta);
159 M[1][1] = cos(theta);
162 for (
size_t i = 0; i < interp_methods.size(); i++) {
163 SECTION(interp_names[i])
165 SECTION(
"Against reference implementation")
173 double percentage = 0.0;
174 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
175 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" Ref): " << percentage << std::endl;
179 SECTION(
"Against OpenCV")
191 double percentage = 0.0;
192 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
193 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
194 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
198 SECTION(
"Against PIL")
209 double percentage = 0.0;
210 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
211 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
212 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
225 const double scale = 0.83;
226 M[0][0] = scale * cos(theta);
227 M[0][1] = -scale * sin(theta);
229 M[1][0] = scale * sin(theta);
230 M[1][1] = scale * cos(theta);
233 for (
size_t i = 0; i < interp_methods.size(); i++) {
234 SECTION(interp_names[i])
236 SECTION(
"Against reference implementation")
244 double percentage = 0.0;
245 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
246 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
250 SECTION(
"Against OpenCV")
261 double percentage = 0.0;
262 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
263 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
264 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
268 SECTION(
"Against PIL")
279 double percentage = 0.0;
280 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
281 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
282 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
290 TEST_CASE(
"Affine warp on color",
"[warp_image]")
304 for (
size_t i = 0; i < interp_methods.size(); i++) {
305 SECTION(interp_names[i])
307 SECTION(
"Empty destination")
311 CHECK((I == I_affine));
314 SECTION(
"Initialized destination")
318 CHECK((I == I_affine));
324 SECTION(
"Rotation 45 deg")
330 M[0][0] = cos(theta);
331 M[0][1] = -sin(theta);
333 M[1][0] = sin(theta);
334 M[1][1] = cos(theta);
337 for (
size_t i = 0; i < interp_methods.size(); i++) {
338 SECTION(interp_names[i])
340 SECTION(
"Against reference implementation")
348 double percentage = 0.0;
349 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
350 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" Ref): " << percentage << std::endl;
354 SECTION(
"Against OpenCV")
365 double percentage = 0.0;
366 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
367 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
368 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
372 SECTION(
"Against PIL")
383 double percentage = 0.0;
384 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
385 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
386 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
399 const double scale = 0.83;
400 M[0][0] = scale * cos(theta);
401 M[0][1] = -scale * sin(theta);
403 M[1][0] = scale * sin(theta);
404 M[1][1] = scale * cos(theta);
407 for (
size_t i = 0; i < interp_methods.size(); i++) {
408 SECTION(interp_names[i])
410 SECTION(
"Against reference implementation")
418 double percentage = 0.0;
419 bool equal = almostEqual(I_ref, I_affine, g_threshold_value,
420 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
421 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
425 SECTION(
"Against OpenCV")
436 double percentage = 0.0;
437 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
438 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
439 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
443 SECTION(
"Against PIL")
454 double percentage = 0.0;
455 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
456 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
457 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
465 TEST_CASE(
"Perspective warp on grayscale",
"[warp_image]")
479 for (
size_t i = 0; i < interp_methods.size(); i++) {
480 SECTION(interp_names[i])
482 SECTION(
"Empty destination")
486 CHECK((I == I_perspective));
489 SECTION(
"Initialized destination")
493 CHECK((I == I_perspective));
499 SECTION(
"Rotation 45 deg")
505 M[0][0] = cos(theta);
506 M[0][1] = -sin(theta);
508 M[1][0] = sin(theta);
509 M[1][1] = cos(theta);
512 SECTION(
"Nearest Neighbor")
520 double percentage = 0.0;
521 bool equal = almostEqual(I_ref, I_perspective, g_threshold_value, g_threshold_percentage, percentage);
522 std::cout <<
"Percentage valid pixels (persp 45 deg): " << percentage << std::endl;
527 SECTION(
"Homography")
541 for (
size_t i = 0; i < interp_methods.size(); i++) {
542 SECTION(interp_names[i])
544 SECTION(
"Against reference implementation")
552 double percentage = 0.0;
554 almostEqual(I_ref, I_perspective, g_threshold_value,
555 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
556 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage
561 SECTION(
"Against OpenCV")
572 double percentage = 0.0;
574 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
575 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
576 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage
581 SECTION(
"Against PIL")
592 double percentage = 0.0;
594 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
595 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
596 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage
605 TEST_CASE(
"Perspective warp on color",
"[warp_image]")
619 for (
size_t i = 0; i < interp_methods.size(); i++) {
620 SECTION(interp_names[i])
622 SECTION(
"Empty destination")
626 CHECK((I == I_perspective));
629 SECTION(
"Initialized destination")
633 CHECK((I == I_perspective));
639 SECTION(
"Homography")
653 for (
size_t i = 0; i < interp_methods.size(); i++) {
654 SECTION(interp_names[i])
656 SECTION(
"Against reference implementation")
664 double percentage = 0.0;
666 almostEqual(I_ref, I_perspective, g_threshold_value,
667 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
668 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage
673 SECTION(
"Against OpenCV")
684 double percentage = 0.0;
686 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
687 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
688 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage
693 SECTION(
"Against PIL")
704 double percentage = 0.0;
706 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
707 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
708 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage
717 int main(
int argc,
char *argv[])
719 Catch::Session session;
720 session.applyCommandLine(argc, argv);
721 int numFailed = session.run();
725 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.