42 #include <visp3/core/vpConfig.h> 44 #if defined(VISP_HAVE_CATCH2) 45 #define CATCH_CONFIG_RUNNER 47 #include <visp3/core/vpImageConvert.h> 50 static const double maxMeanPixelError = 1.0;
51 static const unsigned int width = 223, height = 151;
53 TEST_CASE(
"Gray to RGBa conversion",
"[image_conversion]") {
55 common_tools::fill(gray);
58 common_tools::grayToRGBaRef(gray.bitmap, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), gray.getSize());
62 CHECK((rgba == rgba_ref));
65 TEST_CASE(
"RGBa to Gray conversion",
"[image_conversion]") {
67 common_tools::fill(rgba);
70 common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.bitmap), gray_ref.bitmap, rgba.getSize());
75 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
76 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
79 TEST_CASE(
"RGB to Gray conversion",
"[image_conversion]") {
80 std::vector<unsigned char> rgb(height*width*3);
81 common_tools::fill(rgb);
84 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
89 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
90 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
94 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
95 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
98 TEST_CASE(
"RGB <==> RGBa conversion",
"[image_conversion]") {
100 common_tools::fill(rgba_ref);
102 std::vector<unsigned char> rgb(height*width*3);
108 CHECK((rgba == rgba_ref));
111 #if VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11 112 TEST_CASE(
"BGR to Gray conversion",
"[image_conversion]") {
114 common_tools::fill(rgba_ref);
119 std::vector<unsigned char> bgr;
120 common_tools::RGBaToBGR(rgba_ref, bgr);
126 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
127 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
131 TEST_CASE(
"BGRa to Gray conversion",
"[image_conversion]") {
133 common_tools::fill(rgba_ref);
138 std::vector<unsigned char> bgra;
139 common_tools::RGBaToBGRa(rgba_ref, bgra);
145 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
146 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
149 TEST_CASE(
"BGRa to RGBa conversion",
"[image_conversion]") {
151 common_tools::fill(rgba_ref);
153 std::vector<unsigned char> bgra_ref;
154 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
157 vpImageConvert::BGRaToRGBa(bgra_ref.data(),
reinterpret_cast<unsigned char*
>(rgba.bitmap), rgba.getWidth(), rgba.getHeight());
160 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
161 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
164 TEST_CASE(
"Split <==> Merge conversion",
"[image_conversion]") {
166 common_tools::fill(rgba_ref);
174 CHECK((rgba == rgba_ref));
177 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 178 TEST_CASE(
"OpenCV Mat <==> vpImage conversion",
"[image_conversion]") {
180 SECTION(
"CV_8UC3 to vpRGBa")
182 cv::Mat img(height, width, CV_8UC3);
183 common_tools::fill(img);
186 common_tools::BGRToRGBaRef(img.data, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), img.cols, img.rows,
false);
190 CHECK((rgba_ref == rgba));
193 SECTION(
"CV_8UC1 to vpRGBa")
195 cv::Mat img(height, width, CV_8UC1);
196 common_tools::fill(img);
199 common_tools::grayToRGBaRef(img.data, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), height*width);
203 CHECK((rgba_ref == rgba));
206 SECTION(
"CV_8UC3 to unsigned char")
208 cv::Mat img(height, width, CV_8UC3);
209 common_tools::fill(img);
212 common_tools::BGRToGrayRef(img.data, gray_ref.
bitmap, img.cols, img.rows,
false);
217 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
218 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
221 SECTION(
"CV_8UC1 to unsigned char")
223 cv::Mat img(height, width, CV_8UC1);
224 common_tools::fill(img);
232 for (
int i = 0; i < img.rows; i++) {
233 for (
int j = 0; j < img.cols; j++) {
234 REQUIRE(img.at<uchar>(i, j) == gray[i][j]);
241 int main(
int argc,
char *argv[])
243 Catch::Session session;
246 session.applyCommandLine(argc, argv);
248 int numFailed = session.run();
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
Type * bitmap
points toward the bitmap
static void BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
static void merge(const vpImage< unsigned char > *R, const vpImage< unsigned char > *G, const vpImage< unsigned char > *B, const vpImage< unsigned char > *a, vpImage< vpRGBa > &RGBa)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
unsigned int getHeight() const
static void RGBaToRGB(unsigned char *rgba, unsigned char *rgb, unsigned int size)