Ask Your Question
0

Python & OpenCV 3.1: imshow fail when called in different thread

asked 2016-01-13 04:02:51 -0600

Gioia gravatar image

Hi guys,

I'm trying to build a multi-threading application. Each thread captures a video and display each frame of the video with imshow till the end. However, the script fails with:

xcb] Unknown request in queue while dequeuing [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. python: ../../src/xcb_io.c:179: dequeue_pending_request: assertion "!xcb_xlib_unknown_req_in_deq" failed.

Any idea on how to solve this with Python?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-13 10:59:19 -0600

Hi,

the imshow function is not thread safe. A thread must acquire a lock before showing the image and release it afer the specified time in the waitKey function has passed.

In python is really easy, define a lock in your code and add in the run method of your thread:

with image_lock: 
     cv2.imshow('image',self.image)
     cv2.waitKey(25)

Hope it'll help.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-13 04:02:51 -0600

Seen: 5,572 times

Last updated: Jan 13 '16