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

Sending the image using cvbridge

asked 2011-10-05 11:22:55 -0500

navderm_2 gravatar image

updated 2014-04-20 14:09:42 -0500

ngrennan gravatar image

I am getting in image from a webcam using cvbridge. What I want to be able to do is change a few things to that image, and finally publish it. When I try to create another cvImagePtr and change the image associated with it to finally publish it using

image_final.copyTo(cv_ptr_image_final->image); and then using "->toImageMsg()" to send the image,

It gives me an error saying /usr/include/boost/smart_ptr/shared_ptr.hpp:418: T* boost::shared_ptr< <template-parameter-1-1&gt; &gt;::operator-="">() const [with T = cv_bridge::CvImage]: Assertion `px != 0' failed. Aborted

What should I do to update the image in one of the cvBridge vairables so that I can publish it ?

Thx a lot

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
5

answered 2011-10-07 02:06:42 -0500

Achim gravatar image

The issue with your approach is, that just creating a variable of type "CvImagePtr" will not give you anything useful... ;) The "Ptr" means "pointer", in this case boost::shared_ptr. So you have a pointer poing to null. That's what the assertion is trying to tell you.

Maybe it will help, to create a CvImage with new in the follwing way:

CvImagePtr cv_ptr_image_final(new CvImage());

This will give you a shared pointer pointing to some empty CvImage. But I think, before you can really send the image, you need to fill the header and encoding members of your new CvImage, too. In most cases it should be possible to just copy them from the old CvImage.

edit flag offensive delete link more

Comments

I never liked typedeffing pointers. It never makes things easier and it becomes confusing when one has to know which data type he's dealing with.
Lorenzo Riano gravatar image Lorenzo Riano  ( 2011-10-08 01:32:05 -0500 )edit
2

answered 2011-10-07 10:55:03 -0500

Daniel Canelhas gravatar image

updated 2011-10-07 10:56:33 -0500

Did you happen to see this: http://www.ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages

This tutorial seems to be an exact match to your question. Another one, that I found helpful (with LOTS of comments in the code) is http://siddhantahuja.wordpress.com/2011/07/20/working-with-ros-and-opencv-draft/

It's written for diamondback but works just as well in electric.

If you'd rather write nodes in python: http://www.pirobot.org/blog/0016/ this is a nice little Head-tracking tutorial (using openCV). You can skip the part related to the actual robot.

They're all at quite modest levels of difficulty and show some slightly different ways of doing things in ROS. You can also manipulate the image from the ros message directly if you're just doing something simple (like inverting the colors) that doesn't really require openCV.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-10-05 11:22:55 -0500

Seen: 2,482 times

Last updated: Oct 07 '11