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
57static const double g_threshold_value = 0.5;
58static const double g_threshold_percentage = 0.9;
59static const double g_threshold_percentage_bilinear = 0.75;
60static const double g_threshold_percentage_pers = 0.75;
61static const double g_threshold_percentage_pers_bilinear = 0.65;
63VP_ATTRIBUTE_NO_DESTROY
static const std::vector<vpImageTools::vpImageInterpolationType> interp_methods = {
66VP_ATTRIBUTE_NO_DESTROY
static const std::vector<std::string> interp_names = {
"Nearest Neighbor",
"Bilinear" };
67VP_ATTRIBUTE_NO_DESTROY
static const std::vector<std::string> suffixes = {
"_NN.png",
"_bilinear.png" };
70 double threshold_percentage,
double &percentage)
79 for (
unsigned int j = 0;
j < I1.
getWidth();
j++) {
80 nb_valid +=
vpMath::abs(I1[i][j] - I2[i][j]) < threshold_val ? 1 : 0;
84 percentage = nb_valid / I1.
getSize();
85 return percentage >= threshold_percentage;
89 double threshold_percentage,
double &percentage)
98 for (
unsigned int j = 0;
j < I1.
getWidth();
j++) {
99 if (
vpMath::abs(I1[i][j].R - I2[i][j].R) < threshold_val) {
102 if (
vpMath::abs(I1[i][j].G - I2[i][j].G) < threshold_val) {
105 if (
vpMath::abs(I1[i][j].B - I2[i][j].B) < threshold_val) {
111 percentage = nb_valid / (3 * I1.
getSize());
112 return percentage >= threshold_percentage;
116TEST_CASE(
"Affine warp on grayscale",
"[warp_image]")
123 REQUIRE(I.getSize() > 0);
130 for (
size_t i = 0;
i < interp_methods.size();
i++) {
131 SECTION(interp_names[i])
133 SECTION(
"Empty destination")
137 CHECK((I == I_affine));
140 SECTION(
"Initialized destination")
144 CHECK((I == I_affine));
150 SECTION(
"Rotation 45 deg")
156 M[0][0] = cos(theta);
157 M[0][1] = -sin(theta);
158 M[0][2] = I.getWidth() / 2.0;
159 M[1][0] = sin(theta);
160 M[1][1] = cos(theta);
161 M[1][2] = I.getHeight() / 2.0;
163 for (
size_t i = 0;
i < interp_methods.size();
i++) {
164 SECTION(interp_names[i])
166 SECTION(
"Against reference implementation")
174 double percentage = 0.0;
175 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
176 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[
i] <<
" Ref): " << percentage << std::endl;
180 SECTION(
"Against OpenCV")
192 double percentage = 0.0;
193 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
194 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
195 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[
i] <<
" OpenCV): " << percentage << std::endl;
199 SECTION(
"Against PIL")
210 double percentage = 0.0;
211 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
212 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
213 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[
i] <<
" PIL): " << percentage << std::endl;
226 const double scale = 0.83;
227 M[0][0] = scale * cos(theta);
228 M[0][1] = -scale * sin(theta);
229 M[0][2] = I.getWidth() / 2.0 + 17;
230 M[1][0] = scale * sin(theta);
231 M[1][1] = scale * cos(theta);
232 M[1][2] = I.getHeight() / 2.0 - 23;
234 for (
size_t i = 0;
i < interp_methods.size();
i++) {
235 SECTION(interp_names[i])
237 SECTION(
"Against reference implementation")
245 double percentage = 0.0;
246 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
247 std::cout <<
"Percentage valid pixels (SRT " << interp_names[
i] <<
" Ref): " << percentage << std::endl;
251 SECTION(
"Against OpenCV")
262 double percentage = 0.0;
263 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
264 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
265 std::cout <<
"Percentage valid pixels (SRT " << interp_names[
i] <<
" OpenCV): " << percentage << std::endl;
269 SECTION(
"Against PIL")
280 double percentage = 0.0;
281 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
282 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
283 std::cout <<
"Percentage valid pixels (SRT " << interp_names[
i] <<
" PIL): " << percentage << std::endl;
291TEST_CASE(
"Affine warp on color",
"[warp_image]")
298 REQUIRE(I.getSize() > 0);
305 for (
size_t i = 0;
i < interp_methods.size();
i++) {
306 SECTION(interp_names[i])
308 SECTION(
"Empty destination")
312 CHECK((I == I_affine));
315 SECTION(
"Initialized destination")
319 CHECK((I == I_affine));
325 SECTION(
"Rotation 45 deg")
331 M[0][0] = cos(theta);
332 M[0][1] = -sin(theta);
333 M[0][2] = I.getWidth() / 2.0;
334 M[1][0] = sin(theta);
335 M[1][1] = cos(theta);
336 M[1][2] = I.getHeight() / 2.0;
338 for (
size_t i = 0;
i < interp_methods.size();
i++) {
339 SECTION(interp_names[i])
341 SECTION(
"Against reference implementation")
349 double percentage = 0.0;
350 bool equal = almostEqual(I_ref, I_affine, g_threshold_value, g_threshold_percentage, percentage);
351 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[
i] <<
" Ref): " << percentage << std::endl;
355 SECTION(
"Against OpenCV")
366 double percentage = 0.0;
367 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
368 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
369 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[
i] <<
" OpenCV): " << percentage << std::endl;
373 SECTION(
"Against PIL")
384 double percentage = 0.0;
385 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
386 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
387 std::cout <<
"Percentage valid pixels (45 deg " << interp_names[
i] <<
" PIL): " << percentage << std::endl;
400 const double scale = 0.83;
401 M[0][0] = scale * cos(theta);
402 M[0][1] = -scale * sin(theta);
403 M[0][2] = I.getWidth() / 2.0 + 17;
404 M[1][0] = scale * sin(theta);
405 M[1][1] = scale * cos(theta);
406 M[1][2] = I.getHeight() / 2.0 - 23;
408 for (
size_t i = 0;
i < interp_methods.size();
i++) {
409 SECTION(interp_names[i])
411 SECTION(
"Against reference implementation")
419 double percentage = 0.0;
420 bool equal = almostEqual(I_ref, I_affine, g_threshold_value,
421 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
422 std::cout <<
"Percentage valid pixels (SRT " << interp_names[
i] <<
" Ref): " << percentage << std::endl;
426 SECTION(
"Against OpenCV")
437 double percentage = 0.0;
438 bool equal = almostEqual(I_ref_opencv, I_affine, g_threshold_value,
439 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
440 std::cout <<
"Percentage valid pixels (SRT " << interp_names[
i] <<
" OpenCV): " << percentage << std::endl;
444 SECTION(
"Against PIL")
455 double percentage = 0.0;
456 bool equal = almostEqual(I_ref_pil, I_affine, g_threshold_value,
457 (i == 0) ? g_threshold_percentage : g_threshold_percentage_bilinear, percentage);
458 std::cout <<
"Percentage valid pixels (SRT " << interp_names[
i] <<
" PIL): " << percentage << std::endl;
466TEST_CASE(
"Perspective warp on grayscale",
"[warp_image]")
473 REQUIRE(I.getSize() > 0);
480 for (
size_t i = 0;
i < interp_methods.size();
i++) {
481 SECTION(interp_names[i])
483 SECTION(
"Empty destination")
487 CHECK((I == I_perspective));
490 SECTION(
"Initialized destination")
494 CHECK((I == I_perspective));
500 SECTION(
"Rotation 45 deg")
506 M[0][0] = cos(theta);
507 M[0][1] = -sin(theta);
508 M[0][2] = I.getWidth() / 2.0;
509 M[1][0] = sin(theta);
510 M[1][1] = cos(theta);
511 M[1][2] = I.getHeight() / 2.0;
513 SECTION(
"Nearest Neighbor")
521 double percentage = 0.0;
522 bool equal = almostEqual(I_ref, I_perspective, g_threshold_value, g_threshold_percentage, percentage);
523 std::cout <<
"Percentage valid pixels (persp 45 deg): " << percentage << std::endl;
528 SECTION(
"Homography")
542 for (
size_t i = 0;
i < interp_methods.size();
i++) {
543 SECTION(interp_names[i])
545 SECTION(
"Against reference implementation")
553 double percentage = 0.0;
555 almostEqual(I_ref, I_perspective, g_threshold_value,
556 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
557 std::cout <<
"Percentage valid pixels (Homography " << interp_names[
i] <<
" Ref): " << percentage
562 SECTION(
"Against OpenCV")
573 double percentage = 0.0;
575 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
576 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
577 std::cout <<
"Percentage valid pixels (Homography " << interp_names[
i] <<
" OpenCV): " << percentage
582 SECTION(
"Against PIL")
593 double percentage = 0.0;
595 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
596 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
597 std::cout <<
"Percentage valid pixels (Homography " << interp_names[
i] <<
" PIL): " << percentage
606TEST_CASE(
"Perspective warp on color",
"[warp_image]")
613 REQUIRE(I.getSize() > 0);
620 for (
size_t i = 0;
i < interp_methods.size();
i++) {
621 SECTION(interp_names[i])
623 SECTION(
"Empty destination")
627 CHECK((I == I_perspective));
630 SECTION(
"Initialized destination")
634 CHECK((I == I_perspective));
640 SECTION(
"Homography")
654 for (
size_t i = 0;
i < interp_methods.size();
i++) {
655 SECTION(interp_names[i])
657 SECTION(
"Against reference implementation")
665 double percentage = 0.0;
667 almostEqual(I_ref, I_perspective, g_threshold_value,
668 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
669 std::cout <<
"Percentage valid pixels (Homography " << interp_names[
i] <<
" Ref): " << percentage
674 SECTION(
"Against OpenCV")
685 double percentage = 0.0;
687 almostEqual(I_ref_opencv, I_perspective, g_threshold_value,
688 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
689 std::cout <<
"Percentage valid pixels (Homography " << interp_names[
i] <<
" OpenCV): " << percentage
694 SECTION(
"Against PIL")
705 double percentage = 0.0;
707 almostEqual(I_ref_pil, I_perspective, g_threshold_value,
708 (i == 0) ? g_threshold_percentage_pers : g_threshold_percentage_pers_bilinear, percentage);
709 std::cout <<
"Percentage valid pixels (Homography " << interp_names[
i] <<
" PIL): " << percentage
718int main(
int argc,
char *argv[])
720 Catch::Session session;
721 session.applyCommandLine(argc, argv);
722 int numFailed = session.run();
726int 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.