ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

cv_bridge::Exception bayer_rggb8 vs 8UC3

asked 2017-10-04 11:32:22 -0500

ROSkinect gravatar image

I'm publishing /camera/image_raw of type sensor_msgs/Image from PointgreyDriver :

image_transport::SubscriberStatusCallback cb = boost::bind(&PointGreyCameraNodelet::connectCb, this);
it_pub_ = it_->advertiseCamera("image_raw", 5, cb, cb);

On the other hand I'm subscribing to that topic:

 this->sub = new image_transport::Subscriber(this->imageTransport->subscribe("/camera/image_raw",1000,&p_vision_apriltags::callback,this));
imgTmp = cv_bridge::toCvCopy(msg,sensor_msgs::image_encodings::TYPE_8UC3);

The error I'm getting is an exception:

terminate called after throwing an instance of 'cv_bridge::Exception'
  what():  [bayer_rggb8] is a color format but [8UC3] is not so they must have the same OpenCV type, CV_8UC3, CV16UC1 ....
[AprilTagsDetector-1] process has died [pid 29207, exit code -6, cmd /home/jaouadros/catkin_ws/devel/lib/p_vision_apriltags/p_vision_apriltags __name:=AprilTagsDetector __log:=/home/jaouadros/.ros/log/da606018-a91e-11e7-80aa-0024d7d045f0/AprilTagsDetector-1.log].
log file: /home/jaouadros/.ros/log/da606018-a91e-11e7-80aa-0024d7d045f0/AprilTagsDetector-1*.log
all processes on machine have died, roslaunch will exit

When I change TYPE_8UC3 to bgr8 it shows frames with random uniform colors.

What types should I be using? normally TYPE_8UC3 works with image_raw !

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-10-04 21:45:17 -0500

updated 2017-10-04 23:41:29 -0500

sensor_msgs::image_encodings::TYPE_8UC3 is not a color format, it is a data type with 3 channels of 8 bits each (but with no information of what each channel mean), so cv_bridge::toCvCopy doesn't know who to transform from bayer_rggb8 color format.

I assume that what you really want is to transform the original image received in bayer_rggb8 format to the more commonly used BGR8 format.

In that case try the following:

 imgTmp = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);

Now, BGR8 is a color format, it also has 3 channels of 8 bits each, but now you know that the first channel corresponds to Blue, the second corresponds to Green and the third corresponds to Red.

If by doing this you get random uniform colors, then make sure that the original image published by the driver is actually in bayer_rggb8 format.

edit flag offensive delete link more

Comments

BGR8 gives me a uniform color each frame. How can I make sure that it is of type bayer_rggb8? rostopic info /camera/image_raw doesn't give much information?

ROSkinect gravatar image ROSkinect  ( 2017-10-05 08:46:54 -0500 )edit

You should check the specifications of your camera, which camera are you using?

Martin Peris gravatar image Martin Peris  ( 2017-10-05 19:52:29 -0500 )edit

I'm using this camera Blackfly 0.9 MP Color GigE PoE

ROSkinect gravatar image ROSkinect  ( 2017-10-06 02:39:05 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-04 11:32:22 -0500

Seen: 1,893 times

Last updated: Oct 04 '17