Go to the documentation of this file.00001 #include <cv_bridge/cv_bridge.h>
00002 #include <stdio.h>
00003 #include <gtest/gtest.h>
00004
00005 TEST(CvBridgeTest, compression)
00006 {
00007 cv::RNG rng(0);
00008 std_msgs::Header header;
00009
00010
00011 for (int i = 0; i < 2; ++i)
00012 {
00013 const std::string format = (i == 0) ? "bgr8" : "rgb8";
00014 cv::Mat_<cv::Vec3b> in(10, 10);
00015 rng.fill(in, cv::RNG::UNIFORM, 0, 256);
00016
00017 sensor_msgs::CompressedImagePtr msg = cv_bridge::CvImage(header, format, in).toCompressedImageMsg(cv_bridge::PNG);
00018 const cv_bridge::CvImageConstPtr out = cv_bridge::toCvCopy(msg, format);
00019
00020 EXPECT_EQ(out->image.channels(), 3);
00021 EXPECT_EQ(cv::norm(out->image, in), 0);
00022 }
00023
00024
00025 for (int i = 0; i < 2; ++i)
00026 {
00027 const std::string format = (i == 0) ? "bgra8" : "rgba8";
00028 cv::Mat_<cv::Vec4b> in(10, 10);
00029 rng.fill(in, cv::RNG::UNIFORM, 0, 256);
00030
00031 sensor_msgs::CompressedImagePtr msg = cv_bridge::CvImage(header, format, in).toCompressedImageMsg(cv_bridge::PNG);
00032 const cv_bridge::CvImageConstPtr out = cv_bridge::toCvCopy(msg, format);
00033 EXPECT_EQ(out->image.channels(), 4);
00034 EXPECT_EQ(cv::norm(out->image, in), 0);
00035 }
00036 }