Test image resize.
#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_CATCH2)
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <visp3/core/vpImageTools.h>
#include "common.hpp"
static unsigned int g_input_width = 7;
static unsigned int g_input_height = 5;
static unsigned int g_output_width = 4;
static unsigned int g_output_height = 3;
TEST_CASE("Nearest neighbor interpolation", "[image_resize]") {
SECTION("unsigned char")
{
common_tools::fill(I);
common_tools::resizeRef(I, Iresize_ref, common_tools::g_nearest_neighbor);
std::cout << "I:\n" << I << std::endl;
std::cout << "Iresize_ref:\n" << Iresize_ref << std::endl;
std::cout << "Iresize:\n" << Iresize << std::endl;
CHECK((Iresize == Iresize_ref));
}
SECTION("vpRGBa")
{
common_tools::fill(I);
common_tools::resizeRef(I, Iresize_ref, common_tools::g_nearest_neighbor);
std::cout << "I:\n" << I << std::endl;
std::cout << "Iresize_ref:\n" << Iresize_ref << std::endl;
std::cout << "Iresize:\n" << Iresize << std::endl;
CHECK((Iresize == Iresize_ref));
}
}
TEST_CASE("Bilinear interpolation", "[image_resize]") {
SECTION("unsigned char")
{
common_tools::fill(I);
common_tools::resizeRef(I, Iresize_ref, common_tools::g_bilinear);
std::cout << "I:\n" << I << std::endl;
std::cout << "Iresize_ref:\n" << Iresize_ref << std::endl;
std::cout << "Iresize:\n" << Iresize << std::endl;
CHECK((Iresize == Iresize_ref));
}
SECTION("vpRGBa")
{
common_tools::fill(I);
common_tools::resizeRef(I, Iresize_ref, common_tools::g_bilinear);
std::cout << "I:\n" << I << std::endl;
std::cout << "Iresize_ref:\n" << Iresize_ref << std::endl;
std::cout << "Iresize:\n" << Iresize << std::endl;
const double max_pixel_error = 0.5;
double error = 0.0;
CHECK(common_tools::almostEqual(Iresize, Iresize_ref, max_pixel_error, error));
std::cout << "Error: " << error << std::endl;
}
}
int main(int argc, char *argv[])
{
Catch::Session session;
using namespace Catch::clara;
auto cli = session.cli()
| Opt(g_input_width, "g_input_width")
["--iw"]
("Input image width.")
| Opt(g_input_height, "g_input_height")
["--ih"]
("Input image height.")
| Opt(g_output_width, "g_output_width")
["--ow"]
("Output image width.")
| Opt(g_output_height, "g_output_height")
["--oh"]
("Output image height.");
session.cli(cli);
session.applyCommandLine(argc, argv);
std::cout << "Input image (wxh): " << g_input_width << "x" << g_input_height << std::endl;
std::cout << "Output image (wxh): " << g_output_width << "x" << g_output_height << std::endl;
int numFailed = session.run();
return numFailed;
}
#else
int main()
{
return 0;
}
#endif