test_compression.cpp
Go to the documentation of this file.
1 #include <cv_bridge/cv_bridge.h>
2 #include <stdio.h>
3 #include <gtest/gtest.h>
4 
5 TEST(CvBridgeTest, compression)
6 {
7  cv::RNG rng(0);
8  std_msgs::Header header;
9 
10  // Test 3 channel images.
11  for (int i = 0; i < 2; ++i)
12  {
13  const std::string format = (i == 0) ? "bgr8" : "rgb8";
14  cv::Mat_<cv::Vec3b> in(10, 10);
15  rng.fill(in, cv::RNG::UNIFORM, 0, 256);
16 
17  sensor_msgs::CompressedImagePtr msg = cv_bridge::CvImage(header, format, in).toCompressedImageMsg(cv_bridge::PNG);
18  const cv_bridge::CvImageConstPtr out = cv_bridge::toCvCopy(msg, format);
19 
20  EXPECT_EQ(out->image.channels(), 3);
21  EXPECT_EQ(cv::norm(out->image, in), 0);
22  }
23 
24  // Test 4 channel images.
25  for (int i = 0; i < 2; ++i)
26  {
27  const std::string format = (i == 0) ? "bgra8" : "rgba8";
28  cv::Mat_<cv::Vec4b> in(10, 10);
29  rng.fill(in, cv::RNG::UNIFORM, 0, 256);
30 
31  sensor_msgs::CompressedImagePtr msg = cv_bridge::CvImage(header, format, in).toCompressedImageMsg(cv_bridge::PNG);
32  const cv_bridge::CvImageConstPtr out = cv_bridge::toCvCopy(msg, format);
33  EXPECT_EQ(out->image.channels(), 4);
34  EXPECT_EQ(cv::norm(out->image, in), 0);
35  }
36 }
std_msgs::Header * header(M &m)
TEST(CvBridgeTest, compression)
Image message class that is interoperable with sensor_msgs/Image but uses a more convenient cv::Mat r...
Definition: cv_bridge.h:76
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
Convert a sensor_msgs::Image message to an OpenCV-compatible CvImage, copying the image data...
Definition: cv_bridge.cpp:392
sensor_msgs::CompressedImagePtr toCompressedImageMsg(const Format dst_format=JPG) const
Definition: cv_bridge.cpp:437


cv_bridge
Author(s): Patrick Mihelich, James Bowman
autogenerated on Thu Dec 12 2019 03:52:01