Ask Your Question
0

ROS iamge to opencv image and image processing [closed]

asked 2013-05-27 03:38:49 -0500

anthonyli gravatar image

Hello,

I follow the tutorials of cvbridge, and now I can get the opencv image from ROS image. Then I want to do some image processing, it seems that I should add the image processing function in the callback function? I try to do in this way and compile it, then rosrun the node, but it always show "Segmentation fault (core dumped)".

So I try another way, I want export the opencv image in the way like the tutorial and then write a new .cpp file to processing with the opencv iamge. But there are always problem, so how can I export the CvImage from ROS image and use it in another .cpp file?

Thank you!

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by Bill Smart
close date 2013-05-28 13:05:44

Comments

Can you run your code with the gnu debugger (gdb)?

SL Remy gravatar image SL Remy  ( 2013-05-27 16:00:06 -0500 )edit

Further, what you're describing sounds exactly like the tutorial code (see link), is there something specific that didn't work http://www.ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages (My guess is that there's a memory issue that is caused..)

SL Remy gravatar image SL Remy  ( 2013-05-27 16:03:07 -0500 )edit

Thank you for your reply! I try to put all the image processing function and mouse callback fuction in the callback function of subscribe message. It seems work, but there are still several problems......I mean, I have try to do image processing with my webcam, it works, but I try move to ROS now

anthonyli gravatar image anthonyli  ( 2013-05-28 05:45:54 -0500 )edit

It seems that dealing with ROS image is inconvenient because I am limited to the callback function?

anthonyli gravatar image anthonyli  ( 2013-05-28 05:50:12 -0500 )edit

The use of a callback function should not limit how you solve a problem. It is just a means of performing a fixed action whenever a new image is received.

SL Remy gravatar image SL Remy  ( 2013-05-28 13:00:56 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-05-28 13:25:47 -0500

SL Remy gravatar image

You could write a program that uses cvbridge to convert a ROS Image to an openCV image (in a callback) and then in another thread perform whatever processing (including "mouse callbacks")

This would be equivalent to the tutorial example (minus the republishing, and with the addition of a main loop that looks like the talker from the publish and subscribe tutorial.

But answering the question "how can I export the CvImage from ROS image and use it in another .cpp file?"

You could write a program that uses cvbridge to convert a ROS Image to an openCV image and save to file (e.g. jpg) and then open that file with your external program, although I wouldn't recommend such an approach.

edit flag offensive delete link more

Comments

Sorry.. question was closed before I clicked "answer"

SL Remy gravatar image SL Remy  ( 2013-05-28 13:27:15 -0500 )edit

Thank you! To be honest, in my program,I dont want to do image processing for each image. When I try with webcam, I grab a frame and deal with it, then grab again. So as you said, I will try to treat image message as common message and get the cv image in callback, then process them in other thread.

anthonyli gravatar image anthonyli  ( 2013-05-28 20:54:14 -0500 )edit

Moreover, you mean that, write a file contain the tutorial example (http://www.ros.org/wiki/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29) and another file like a talker? Well, I want to get the image from a robot, so I don't understand this way. What you mean by making a talker?

anthonyli gravatar image anthonyli  ( 2013-05-28 22:42:22 -0500 )edit

Finally, how about this way(not using the class)? Because follow the tutorial, in the main function, it will always stay in the " ImageConverter ic; "(the line 60 in the cvbridge tutorial), if I try add some code after that, them will never be used.

anthonyli gravatar image anthonyli  ( 2013-05-29 00:38:55 -0500 )edit
-1

answered 2013-05-27 04:42:21 -0500

anthonyli gravatar image

updated 2013-05-27 04:42:57 -0500

I really need help!

Please let me know which way is possible, adding the image processing function in the callback function or exporting the CvImage out and processing it in another .cpp file ?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-27 03:38:49 -0500

Seen: 797 times

Last updated: May 28 '13