Ask Your Question
1

cv_bridge and IplImage -> Mat when going from OpenCV 2.1 to OpenCV 2.3?

asked 2012-02-13 05:10:02 -0500

Pi Robot gravatar image

updated 2012-02-13 05:31:29 -0500

Hello,

I am trying to use some of the newer Python sample code included with OpenCV 2.3 while also using cv_bridge in ROS Electric. It appears that most of the sample code (such as the lk_track.py demo) assumes images are in Mat format rather than IplImage format. However, cv_bridge converts ROS Image format to IplImage format so that I am constantly running into format incompatibilities. Is there some way I can have cv_bridge convert ROS Image messages to Mat format instead of IplImage? Alternatively, can I convert the IplImage returned by cv_bridge to Mat? I am programming in Python so I am hoping for a solution in that language.

Thanks!
patrick

edit retag flag offensive close delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-02-13 05:35:25 -0500

updated 2012-02-13 14:07:02 -0500

Pi Robot gravatar image
cv.GetMat(myIplImage)

Since OpenCV seems to be moving away from IplImages, it would make sense for cv_bridge to do the same. Perhaps that should be ticketed.

edit flag offensive delete publish link more

Comments

Many thanks @diaz! Do you happen to know what type of Mat is returned by GetMat? For example, if I use 'frame = cv.GetMat(self.bridge.imgmsg_to_cv(ros_image, "bgr8"))', what Mat type is frame? e.g. 8UC3, 32FC3? etc. I ask because I'm still having size and/or type compatibility problems when trying to copy or perform other operations with the 'frame' matrix and other image matrices in my code.

Pi Robot ( 2012-02-13 06:21:30 -0500 )edit

I'm not sure what the correspondence is between IplImage encodings and the regular Mat encodings, but it should be semantically equivalent. bgr8 would likely give you 8UC3 or something similar. When creating new Mats of the same type, you can be encoding-agnostic by using mat.type and mat.channels.

Dan Lazewatsky ( 2012-02-13 06:44:49 -0500 )edit

Thanks again @diaz. Yes, it looks like its type 8UC3 or 16 in integer format.

Pi Robot ( 2012-02-13 07:29:43 -0500 )edit

Could you post code that requires converting to a numpy array? Most OpenCV functions work on array-like objects, and Mats certainly are. I just tried cv.CvtColor using a Mat as the source and destination, and it works fine.

Dan Lazewatsky ( 2012-02-13 10:09:11 -0500 )edit

OK, I jumped the gun. It looks like it is only the functions in cv2 that require a numpy array. In the lk_track.py demo the convert function used is cv2.cvtColor and this requires a numpy array whereas the old cv.CvtColor does not. Similarly, the new cv2.goodFeaturesToTrack requires numpy arrays.

Pi Robot ( 2012-02-13 14:09:49 -0500 )edit

Your Answer

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

Add Answer

[hide preview]

Question Tools

Follow
1 follower

Stats

Asked: 2012-02-13 05:10:02 -0500

Seen: 1,381 times

Last updated: Feb 13 '12