36#include <visp3/core/vpConfig.h>
38#if defined(VISP_HAVE_CATCH2) && (VISP_HAVE_DATASET_VERSION >= 0x030500)
39#define CATCH_CONFIG_ENABLE_BENCHMARKING
40#define CATCH_CONFIG_RUNNER
44#include <visp3/core/vpIoTools.h>
45#include <visp3/io/vpImageIo.h>
48static const std::string path = ipath +
"/Solvay/Solvay_conference_1927_Version2_640x440";
50static const double ccThreshPNG = 1.0;
51static const double ccThreshJPG = 0.99;
53static const std::vector<vpImageIo::vpImageIoBackendType> backends
55#if defined(VISP_HAVE_JPEG) && defined(VISP_HAVE_PNG)
58#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
63static const std::vector<std::string> backendNamesJpeg
65#if defined(VISP_HAVE_JPEG)
68#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
73static std::vector<std::string> backendNamesPng
75#if defined(VISP_HAVE_PNG)
78#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
84static const unsigned int imgWidth = 640;
85static const unsigned int imgHeight = 440;
94 double num = 0, den1 = 0, den2 = 0;
95 for (
unsigned int i = 0; i < I1.
getSize(); i++) {
98 double x1_m = x1 - m1;
99 double x2_m = x2 - m2;
105 return num / (std::sqrt(den1) * std::sqrt(den2));
113 double num = 0, den1 = 0, den2 = 0;
114 for (
unsigned int i = 0; i < I1.
getSize(); i++) {
117 double x1_m = x1 - m1;
118 double x2_m = x2 - m2;
124 return num / (std::sqrt(den1) * std::sqrt(den2));
128TEST_CASE(
"Test grayscale JPEG image loading",
"[image_I/O]")
133 for (
size_t j = 0; j < backends.size(); j++) {
136 SECTION(backendNamesJpeg[j] +
" backend")
139 double cc = computePearsonCC(I_ref, I);
140 std::cout << backendNamesJpeg[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
141 CHECK(cc >= Approx(ccThreshJPG));
148TEST_CASE(
"Test RGBA JPEG image loading",
"[image_I/O]")
153 for (
size_t j = 0; j < backends.size(); j++) {
156 SECTION(backendNamesJpeg[j] +
" backend")
159 double cc = computePearsonCC(I_ref, I);
160 std::cout << backendNamesJpeg[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
161 CHECK(cc >= Approx(ccThreshJPG));
168TEST_CASE(
"Test grayscale PNG image loading",
"[image_I/O]")
173 for (
size_t j = 0; j < backends.size(); j++) {
176 SECTION(backendNamesPng[j] +
" backend")
179 double cc = computePearsonCC(I_ref, I);
180 std::cout << backendNamesPng[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
181 CHECK(cc == Approx(ccThreshPNG));
188TEST_CASE(
"Test RGBA PNG image loading",
"[image_I/O]")
193 for (
size_t j = 0; j < backends.size(); j++) {
196 SECTION(backendNamesPng[j] +
" backend")
199 double cc = computePearsonCC(I_ref, I);
200 std::cout << backendNamesPng[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
201 CHECK(cc == Approx(ccThreshPNG));
208TEST_CASE(
"Test grayscale JPEG image saving",
"[image_I/O]")
211 std::string directory_filename_tmp =
219 for (
size_t j = 0; j < backends.size(); j++) {
220 SECTION(backendNamesJpeg[j] +
" backend")
222 CHECK_NOTHROW(
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.jpg", backends[j]));
224 vpImageIo::read(I_read, directory_filename_tmp +
"/ViSP_tmp_perf_write.jpg");
225 double cc = computePearsonCC(I_read, I);
226 std::cout << backendNamesPng[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
227 CHECK(cc >= Approx(ccThreshJPG));
234TEST_CASE(
"Test RGBA JPEG image saving",
"[image_I/O]")
237 std::string directory_filename_tmp =
245 for (
size_t j = 0; j < backends.size(); j++) {
246 SECTION(backendNamesJpeg[j] +
" backend")
248 CHECK_NOTHROW(
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.jpg", backends[j]));
250 vpImageIo::read(I_read, directory_filename_tmp +
"/ViSP_tmp_perf_write.jpg");
251 double cc = computePearsonCC(I_read, I);
252 std::cout << backendNamesPng[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
253 CHECK(cc >= Approx(ccThreshJPG));
260TEST_CASE(
"Test grayscale PNG image saving",
"[image_I/O]")
263 std::string directory_filename_tmp =
271 for (
size_t j = 0; j < backends.size(); j++) {
272 SECTION(backendNamesPng[j] +
" backend")
274 CHECK_NOTHROW(
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.png", backends[j]));
276 vpImageIo::read(I_read, directory_filename_tmp +
"/ViSP_tmp_perf_write.png");
277 double cc = computePearsonCC(I_read, I);
278 std::cout << backendNamesPng[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
279 CHECK(cc == Approx(ccThreshPNG));
286TEST_CASE(
"Test RGBA PNG image saving",
"[image_I/O]")
289 std::string directory_filename_tmp =
297 for (
size_t j = 0; j < backends.size(); j++) {
298 SECTION(backendNamesPng[j] +
" backend")
300 CHECK_NOTHROW(
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.png", backends[j]));
302 vpImageIo::read(I_read, directory_filename_tmp +
"/ViSP_tmp_perf_write.png");
303 double cc = computePearsonCC(I_read, I);
304 std::cout << backendNamesPng[j] <<
" backend Pearson correlation coefficient: " << cc << std::endl;
305 CHECK(cc == Approx(ccThreshPNG));
312int main(
int argc,
char *argv[])
314 Catch::Session session;
317 session.applyCommandLine(argc, argv);
319 int numFailed = session.run();
329int main() {
return EXIT_SUCCESS; }
@ IO_STB_IMAGE_BACKEND
Use embedded stb_image library.
@ IO_SIMDLIB_BACKEND
Use embedded simd library.
@ IO_SYSTEM_LIB_BACKEND
Use system libraries like libpng or libjpeg.
@ IO_OPENCV_BACKEND
Use OpenCV.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const 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
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
VISP_EXPORT std::string getDateTime(const std::string &format="%Y/%m/%d %H:%M:%S")