ROS iamge to opencv image and image processing
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!
Asked by anthonyli on 2013-05-27 03:38:49 UTC
Answers
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 ?
Asked by anthonyli on 2013-05-27 04:42:21 UTC
Comments
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.
Asked by SL Remy on 2013-05-28 13:25:47 UTC
Comments
Sorry.. question was closed before I clicked "answer"
Asked by SL Remy on 2013-05-28 13:27:15 UTC
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.
Asked by anthonyli on 2013-05-28 20:54:14 UTC
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?
Asked by anthonyli on 2013-05-28 22:42:22 UTC
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.
Asked by anthonyli on 2013-05-29 00:38:55 UTC
Comments
Can you run your code with the gnu debugger (gdb)?
Asked by SL Remy on 2013-05-27 16:00:06 UTC
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..)
Asked by SL Remy on 2013-05-27 16:03:07 UTC
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
Asked by anthonyli on 2013-05-28 05:45:54 UTC
It seems that dealing with ROS image is inconvenient because I am limited to the callback function?
Asked by anthonyli on 2013-05-28 05:50:12 UTC
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.
Asked by SL Remy on 2013-05-28 13:00:56 UTC