ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

using cv_bridge and converting the cvmat to numpy efficiently

asked 2012-09-06 13:09:11 -0500

Hello everyone. I wrote a bunch of image tracking in python using the "cv2" API.

I am now trying to plug that into ROS and I noticed that cv_bridge gives me a cvmat object, not a numpy object that I need to use with the cv2 API. I used numpy.asarray() to convert the cvmat to numpy, but this introduces a serious amount of lag into my system.

I wrote a very simple test which takes the output of the cv_bridge and calls cv.ShowImage on it. It works fine. Then I modified it to take the cv_bridge output, convert it to a numpy with asarray() and run cv2.imshow() on it.

The second case had about a second of lag! Is that expected? Is there any way to convert the cvmat to a numpy "in-place" ?

Thanks -s

edit retag flag offensive close merge delete

Comments

Thanks for the idea Dan. Yeah I converted my numpy back to a cvmat and called cv.ImageShow and it works fine.. Is there a reason why imshow should be so much slower than ShowImage() though?

sameer gravatar image sameer  ( 2012-09-07 04:54:14 -0500 )edit
1

My guess would be that what's taking a long time is creating the window initially. Can you get timing for successive calls to imshow? You could also see how long calling cv2.namedWindow takes. At this point it might be better to ask the opencv mailing list.

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2012-09-07 05:38:45 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-09-06 13:50:47 -0500

Since cvMat is array-like, numpy.asarray is a no-copy function on it, and should be quite efficient. Are you sure that it's asarray being slow and not imshow?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-09-06 13:09:11 -0500

Seen: 622 times

Last updated: Sep 06 '12