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.";
const std::string TYPE_16UC4
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
Convert an immutable sensor_msgs::Image message to an OpenCV-compatible CvImage, sharing the image da...
const std::string TYPE_8SC4
const std::string TYPE_64FC3
const std::string TYPE_8UC4
bool isUnsigned(const std::string &encoding)
const std::string TYPE_32FC4
const std::string TYPE_8UC1
TEST(OpencvTests, testCase_encode_decode)
static bool isMono(const std::string &encoding)
const std::string TYPE_8SC3
static bool isColor(const std::string &encoding)
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
Convert a CvImage to another encoding using the same rules as toCvCopy.
Image message class that is interoperable with sensor_msgs/Image but uses a more convenient cv::Mat r...
const std::string TYPE_32FC1
const std::string TYPE_16SC3
const std::string TYPE_8UC2
const std::string TYPE_16UC1
const std::string TYPE_8SC1
const std::string TYPE_64FC4
const std::string TYPE_16UC3
const std::string TYPE_16UC2
int getCvType(const std::string &encoding)
Get the OpenCV type enum corresponding to the encoding.
const std::string TYPE_64FC1
static int numChannels(const std::string &encoding)
const std::string TYPE_32SC3
const std::string TYPE_8UC3
const std::string TYPE_32SC4
const std::string TYPE_32FC3
std::vector< std::string > getEncodings()
static int bitDepth(const std::string &encoding)
const std::string TYPE_32SC1
const std::string TYPE_16SC4
sensor_msgs::ImagePtr toImageMsg() const
Convert this message to a ROS sensor_msgs::Image message.
const std::string TYPE_16SC1