using cv_bridge and keep header

asked 2020-10-12 03:33:23 -0500

Kreace gravatar image

Hello! I'm trying to get a video get a video stream in order to process the images and make object detection on it.

To do that I made a subscriber to the topic where the images are put in. (topic : '/camera/image_raw', type of message : 'sensor_msgs.msg.Image') this works fine. But I want to use OpenCV, so I need to convert the images to a type that OpenCV can process, I found 'cv_bridge' to do that the only problem I have is that the method :

cv_bridge.imgmsg_to_cv2(image,desired_encoding='passthrough')

only returns the image and the header disappear and I would like to keep it, I tried to create my own "Image type" which contains "header + image data" but it's not really clean moreover I need to republish theses images to other topics.

I also tried to create my own "ROS2 message type" but it can't support 'numpy.ndarray' (which is the type of object OpenCV can process) so I found "ros2_numpy" which allows me to 'msgify' a numpy type or 'numpify' a message but it does that on all the attribute of a message for example if in my header there is something like the 'height' of the image which is a simple 'uint32' it will process it like it's a numpy type and will throw an error.

To summarize I would like to keep the header and the image data of each image that's pretty much it. To precise my application use : Gazebo11, ROS2 foxy, OpenCV 4.4.0 (compiled from source)

Thanks you in advance for your help, let me know if you need more information

edit retag flag offensive close merge delete