Test image resize.
#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_CATCH2)
#include "common.hpp"
#include <catch_amalgamated.hpp>
#include <visp3/core/vpImageTools.h>
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;
#ifdef ENABLE_VISP_NAMESPACE
#endif
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()
| Catch::Clara::Opt(g_input_width, "g_input_width")["--iw"]("Input image width.")
| Catch::Clara::Opt(g_input_height, "g_input_height")["--ih"]("Input image height.")
| Catch::Clara::Opt(g_output_width, "g_output_width")["--ow"]("Output image width.")
| Catch::Clara::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 EXIT_SUCCESS; }
#endif