0
$\begingroup$

Rosanswers logo

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


Originally posted by sameer on ROS Answers with karma: 118 on 2012-09-06

Post score: 1


Original comments

Comment by sameer on 2012-09-07:
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?

Comment by Dan Lazewatsky on 2012-09-07:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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?


Originally posted by Dan Lazewatsky with karma: 9115 on 2012-09-06

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.