Ask Your Question
2

Zero copy passing of OpenCV datatypes with nodelets

asked 2013-01-28 12:10:26 -0500

Tones gravatar image

Hi,

I am thinking about setting up an image processing pipeline using nodelets for a high flexibility. Is there a easy way to pass OpenCV datatypes between nodelets without having to convert them to ros-messages? For example, I would like to pass pointers to image data associated with cv::Mat objects stored in a shared memory. I want to avoid copying or converting this data.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2013-01-28 17:00:10 -0500

Chad Rockey gravatar image

You don't want to start with the OpenCV datatypes. The best method in ROS is to use nodelets with sensor_msgs::ImageConstPtrs. Then you cast them to a cv share using cv_bridge: http://www.ros.org/wiki/cv_bridge

http://www.ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages#cv_bridge.2BAC8-Tutorials.2BAC8-UsingCvBridgeCppDiamondback.Examples_of_sharing_the_image_data

This shares the large amount of image data that you do not want to copy, but sets up the correct metadata for each image type.

If you want to see this "in the wild" take a look at image_pipline, it all uses nodelets and follows best practices for image processing in ROS: https://github.com/ros-perception/image_pipeline/blob/groovy-devel/image_proc/src/nodelets/rectify.cpp

edit flag offensive delete link more

Comments

Thanks for your answer!

Tones gravatar image Tones  ( 2013-01-29 05:59:23 -0500 )edit
2

answered 2013-01-29 06:01:45 -0500

Tones gravatar image

Thanks for your answers! Another interesting possiblity to setup such an pipeline with shared image memory seems to be ECTO (http://ecto.willowgarage.com/). This is "a hybrid C++/Python framework for organizing computations as directed acyclic graphs". Among others, there is a module which wraps the openCV library.

edit flag offensive delete link more
1

answered 2013-01-28 16:20:47 -0500

As you mentioned, you could try using shared memory. A good library for that is Boost Interprocess. You can find an example of cv::Mat object passing using Boost Interprocess here.

Please note that your system will hardly be as flexible for connections as nodelets would be. I actually think the ROS message conversion isn't that big an overhead, but please check for yourself if you feel it will be benefitial for your application.

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

Stats

Asked: 2013-01-28 12:10:26 -0500

Seen: 1,325 times

Last updated: Jan 29 '13