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

cv_bridge.core.CvBridgeError: [8UC1] is not a color format. but [bgr8] is.

asked 2018-12-18 05:16:46 -0500

alessiadele gravatar image

Hi all!

I have a bag file recorded with the IR sensor of a realsense SR300 camera. I am trying to convert it in a video with bag2video.py file, but it turns out this result:

cv_bridge.core.CvBridgeError: [8UC1] is not a color format. but [bgr8] is. The conversion does not make sense

I've found the problem and I've understood it, but actually I don't know how to solve it!! Please can you help me??

edit retag flag offensive close merge delete

Comments

Are you trying to encode a color video format? I suspect you'll need to specify the video as greyscale to get this to work.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-18 06:02:34 -0500 )edit

I used all the three different parameters for "--encode" (rgb8, bgr8, mono8), but the program always gives me the same error. I don't know how to specify the video as greyscale!

alessiadele gravatar image alessiadele  ( 2018-12-18 06:06:02 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-12-18 06:13:26 -0500

updated 2018-12-18 07:32:42 -0500

I've just had a quick look at the source code for this and it seems the encoding option is not implemented. It's actually hard coded to use bgr8 and ignores whatever you specify as the encoding!

Since It's a python file you could dig in and change the hard coded encoding format yourself or get it to use the encoding value correctly.

Hope this helps.

Update:

You'll need to change line 53 which is currently:

img = np.asarray(bridge.imgmsg_to_cv2(msg, 'bgr8'))

so that the encoding you want to use is in the inverted commas instead such as

img = np.asarray(bridge.imgmsg_to_cv2(msg, 'mono8'))
edit flag offensive delete link more

Comments

Yes, unfortunately I am not a programmer, so I don't know how to change the code, or wich line I should add in the python file!

alessiadele gravatar image alessiadele  ( 2018-12-18 07:22:58 -0500 )edit

I've added some instructions for you.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-18 07:32:57 -0500 )edit

Thank you very much! I've followed your instructions, but now the error is:

cv_bridge.core.CvBridgeError: [8UC1] is not a color format. but [mono8] is.

I am trying to read and understand something more about 8UC1, ROS images and OpenCV images, but it's a little bit complicated, you're right!

alessiadele gravatar image alessiadele  ( 2018-12-18 07:39:21 -0500 )edit

according to the documentation for imgmsg_to_cv2 you can give it an encoding of passthrough and it will not try and change it. This might be worth a go.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-18 07:50:44 -0500 )edit

Thank you Pete!! I've solved (in part) the problem modifying the line that you said to me in this way:

img = np.asarray(bridge.imgmsg_to_cv2(msg, '8UC1'))

Now the program does convert the bag file in a video, but it doesn't save any file, it just shows me it! Thank you very much!! :D

alessiadele gravatar image alessiadele  ( 2018-12-18 08:50:59 -0500 )edit
1

Great. Can you accept my answer by clicking the tick next to it. This way other users can see that a solution was found.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-18 08:57:26 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-12-18 05:16:46 -0500

Seen: 7,622 times

Last updated: Dec 18 '18