37 #include <gtest/gtest.h>
39 #include "opencv2/core/core.hpp"
42 #include <sensor_msgs/Image.h>
54 std::vector<std::string>
57 std::string encodings[] = {
RGB8,
RGBA8,
RGB16,
RGBA16,
BGR8,
BGRA8,
BGR16,
BGRA16,
MONO8,
MONO16,
68 return std::vector<std::string>(encodings, encodings+47-8-7);
71 TEST(OpencvTests, testCase_encode_decode)
74 for(
size_t i=0; i<encodings.size(); ++i) {
75 std::string src_encoding = encodings[i];
79 r.fill(image_original, cv::RNG::UNIFORM, 0, 127);
81 sensor_msgs::Image image_message;
85 sensor_msgs::ImagePtr image_msg = image_bridge.
toImageMsg();
87 for(
size_t j=0; j<encodings.size(); ++j) {
88 std::string dst_encoding = encodings[j];
95 if (!is_src_color_format) {
97 if (is_dst_color_format) {
102 if (!is_num_channels_the_same) {
109 if (!is_dst_color_format) {
110 if (!is_num_channels_the_same) {
120 if ((dst_encoding ==
YUV422) && (src_encoding !=
YUV422)) {
128 if ((src_encoding ==
YUV422) && (dst_encoding !=
YUV422)) {
134 image_back =
cvtColor(cv_image, src_encoding)->image;
137 if (!is_num_channels_the_same)
141 EXPECT_LT(cv::norm(image_original, image_back, cv::NORM_INF), 1) <<
"problem converting from " << src_encoding <<
" to " << dst_encoding <<
" and back.";
142 }
else if ((
bitDepth(src_encoding) == 16) && (
bitDepth(dst_encoding) == 8)) {
144 EXPECT_LT(cv::norm(image_original, image_back, cv::NORM_INF), 128) <<
"problem converting from " << src_encoding <<
" to " << dst_encoding <<
" and back.";
146 EXPECT_EQ(cv::norm(image_original, image_back, cv::NORM_INF), 0) <<
"problem converting from " << src_encoding <<
" to " << dst_encoding <<
" and back.";