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>
55static const double g_threshold_value = 0.5;
56static const double g_threshold_percentage = 0.9;
57static const double g_threshold_percentage_bilinear = 0.75;
58static const double g_threshold_percentage_pers = 0.75;
59static const double g_threshold_percentage_pers_bilinear = 0.65;
63static const std::vector<std::string> interp_names = {
"Nearest Neighbor",
"Bilinear"};
64static 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;
113TEST_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")
188 double percentage = 0.0;
189 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
190 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
191 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
195 SECTION(
"Against PIL")
206 double percentage = 0.0;
207 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
208 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
209 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
222 const double scale = 0.83;
223 M[0][0] = scale * cos(theta);
224 M[0][1] = -scale * sin(theta);
226 M[1][0] = scale * sin(theta);
227 M[1][1] = scale * cos(theta);
230 for (
size_t i = 0; i < interp_methods.size(); i++) {
231 SECTION(interp_names[i])
233 SECTION(
"Against reference implementation")
241 double percentage = 0.0;
242 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
243 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
247 SECTION(
"Against OpenCV")
258 double percentage = 0.0;
259 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
260 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
261 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
265 SECTION(
"Against PIL")
276 double percentage = 0.0;
277 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
278 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
279 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
287TEST_CASE(
"Affine warp on color",
"[warp_image]")
301 for (
size_t i = 0; i < interp_methods.size(); i++) {
302 SECTION(interp_names[i])
304 SECTION(
"Empty destination")
308 CHECK((I == I_affine));
311 SECTION(
"Initialized destination")
315 CHECK((I == I_affine));
321 SECTION(
"Rotation 45 deg")
327 M[0][0] = cos(theta);
328 M[0][1] = -sin(theta);
330 M[1][0] = sin(theta);
331 M[1][1] = cos(theta);
334 for (
size_t i = 0; i < interp_methods.size(); i++) {
335 SECTION(interp_names[i])
337 SECTION(
"Against reference implementation")
345 double percentage = 0.0;
346 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
347 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" Ref): " << percentage << std::endl;
351 SECTION(
"Against OpenCV")
362 double percentage = 0.0;
363 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
364 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
365 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
369 SECTION(
"Against PIL")
380 double percentage = 0.0;
381 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
382 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
383 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[i] <<
" PIL): " << percentage << std::endl;
396 const double scale = 0.83;
397 M[0][0] = scale * cos(theta);
398 M[0][1] = -scale * sin(theta);
400 M[1][0] = scale * sin(theta);
401 M[1][1] = scale * cos(theta);
404 for (
size_t i = 0; i < interp_methods.size(); i++) {
405 SECTION(interp_names[i])
407 SECTION(
"Against reference implementation")
415 double percentage = 0.0;
416 bool equal = almostEqual(I_ref, I_affine, g_threshold_value,
417 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
418 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" Ref): " << percentage << std::endl;
422 SECTION(
"Against OpenCV")
433 double percentage = 0.0;
434 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
435 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
436 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" OpenCV): " << percentage << std::endl;
440 SECTION(
"Against PIL")
451 double percentage = 0.0;
452 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
453 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
454 std::cout <<
"Percentage valid pixels (SRT " << interp_names[i] <<
" PIL): " << percentage << std::endl;
462TEST_CASE(
"Perspective warp on grayscale",
"[warp_image]")
476 for (
size_t i = 0; i < interp_methods.size(); i++) {
477 SECTION(interp_names[i])
479 SECTION(
"Empty destination")
483 CHECK((I == I_perspective));
486 SECTION(
"Initialized destination")
490 CHECK((I == I_perspective));
496 SECTION(
"Rotation 45 deg")
502 M[0][0] = cos(theta);
503 M[0][1] = -sin(theta);
505 M[1][0] = sin(theta);
506 M[1][1] = cos(theta);
509 SECTION(
"Nearest Neighbor")
517 double percentage = 0.0;
518 bool equal = almostEqual(I_ref, I_perspective, g_threshold_value, g_threshold_percentage, percentage);
519 std::cout <<
"Percentage valid pixels (persp 45 deg): " << percentage << std::endl;
524 SECTION(
"Homography")
538 for (
size_t i = 0; i < interp_methods.size(); i++) {
539 SECTION(interp_names[i])
541 SECTION(
"Against reference implementation")
549 double percentage = 0.0;
551 almostEqual(I_ref, I_perspective, g_threshold_value,
552 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
553 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage
558 SECTION(
"Against OpenCV")
569 double percentage = 0.0;
571 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
572 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
573 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage
578 SECTION(
"Against PIL")
589 double percentage = 0.0;
591 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
592 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
593 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage
602TEST_CASE(
"Perspective warp on color",
"[warp_image]")
616 for (
size_t i = 0; i < interp_methods.size(); i++) {
617 SECTION(interp_names[i])
619 SECTION(
"Empty destination")
623 CHECK((I == I_perspective));
626 SECTION(
"Initialized destination")
630 CHECK((I == I_perspective));
636 SECTION(
"Homography")
650 for (
size_t i = 0; i < interp_methods.size(); i++) {
651 SECTION(interp_names[i])
653 SECTION(
"Against reference implementation")
661 double percentage = 0.0;
663 almostEqual(I_ref, I_perspective, g_threshold_value,
664 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
665 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" Ref): " << percentage
670 SECTION(
"Against OpenCV")
681 double percentage = 0.0;
683 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
684 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
685 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" OpenCV): " << percentage
690 SECTION(
"Against PIL")
701 double percentage = 0.0;
703 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
704 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
705 std::cout <<
"Percentage valid pixels (Homography " << interp_names[i] <<
" PIL): " << percentage
714int main(
int argc,
char *argv[])
716 Catch::Session session;
719 session.applyCommandLine(argc, argv);
721 int numFailed = session.run();
729int main() {
return EXIT_SUCCESS; }
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
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.