Ask Your Question

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

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


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

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:

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

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

If you'd rather write nodes in python: 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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


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

Seen: 2,317 times

Last updated: Oct 07 '11