Ask Your Question
1

imshow() call never returns openCV 3.2.0-dev

asked 2017-06-16 13:10:55 -0600

burtbick gravatar image

Running Linux Mint 18.1 with ROS Kinetic Python 2.7.12 /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so OpenCV 3.2.0-dev

Using OpenCV with ROS Kinetic. If I run the camshift.py demo that works just fine, but in ROS code that worked fine with ROS Indigo and OpenCV 3.1.0 I have two problems.

First, with ROS the code subscribes to a topic message to get video camera raw data. This comes from another ROS node and is handled by a callback function in the code that I'm working on. This code worked with openCV 3.1.0 but imshow() never returns when called. No exceptions, no error output, just never returns. And, of course does not draw the frame image in the named window.

Note that the code never returns to call the waitKey function.

Second issue: A separate test with calling waitKey(5) before imshow() appears to behave the same, doesn't return but in this case I get the following error output on the terminal:

QObject::startTimer: Timers cannot be started from another thread

This error output doesn't happen with ROS Indigo and openCV 3.1.0

So I suspect this is a clue. I'm trying to determine if this is something that changed with openCV between 3.1.0 and 3.2.0-dev or something in ROS Kinetic that has broken things.

This failure of imshow and waitKey only appears to happen when the code is executed in the callback function that receives the video frame data. If I directly open the camera and read the frame data and then call imshow and waitKey everything works just fine in that case.

Any one seen this problem, and if so how did you work around it?

I've seem a couple of similar issues discussed here related to running on the Mac. That is imshow doesn't draw the frame data, etc.

Thanks, Burt

edit retag flag offensive close merge delete

Comments

believe it or not, but to my knowledge, not a single , ROS related question has been answered successfully here.

berak gravatar imageberak ( 2017-06-16 13:23:42 -0600 )edit

I know that:) I'm trying to determine if this is an OpenCV issue or specific to ROS. I guess I'll create a separate piece of Python code that will grab the frame data from the camera and send it to the camshift.py example so that it mimics what happens with ROS but is not using ROS to do it.

So if you ignore the ROS reference above and look at it as a general OpenCV question about imshow and waitKey issues, has anyone see something like this (other than the similar issue on Apple Mac)?

burtbick gravatar imageburtbick ( 2017-06-16 15:15:40 -0600 )edit
1

OK, here's what I've found. If I move the creation of the named window(s) so that it happens in the callback function instead of in the Python object __init__ method then imshow and waitKey work as expected and the frame data is displayed in the window.

This didn't need to be done previously, but it appears that this is at least a work around for now, so for anyone else who is having a similar problem you can try this to see if it helps. After I do some more testing with the full camshift code I'll fill in the details ans an answer.

burtbick gravatar imageburtbick ( 2017-06-16 16:06:13 -0600 )edit

oh, just in case you missed the current apple related hickup

berak gravatar imageberak ( 2017-06-16 19:11:02 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-17 11:57:26 -0600

GBY gravatar image

My workaround is to start a thread in python that only deals with opencv named window display. Communicate with this displaying thread via a thread-safe queue. The displaying thread is just a consumer who fetches constantly the (window_name, image) pairs from the queue and all other image topic callback functions are just supplier who feeds this queue.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-16 13:10:55 -0600

Seen: 2,408 times

Last updated: Jun 16 '17