Todd Stellanova Todd Stellanova - 1 year ago 161
Python Question

Unable to start camera capture in Python-OpenCV (cv2) using a non-main thread

I have some python-opencv (cv2) code that opens the video capture device (camera):

self.capture = cv2.VideoCapture(device)

If I call this code from the python main thread, the VideoCapture starts OK; however, if I call this setup code from a non-main thread, the camera never opens. The VideoCapture() call never returns. I'm creating a background thread by simply doing:

run_thread = threading.Thread(

Is this simply a bug in OpenCV/cv2 or am I overlooking a limitation of python threads?

Answer Source

This SO post mentions quite summarily that it's an openCV limitation. Also, this constraint exists for the show and waitKey methods.

This official code sample can give some ideas on python-openCV multithreading.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download