python.exe crash if opencv tries to access busy webcam

I

ifelsetrue

Hello,


I have a while loop taking images every 5 minutes from webcam. Unfortunately, if the camera is busy, python.exe crashes and there is no exception to catch. Is there a way to check if camera is busy to avoid the crash?


Thanks!

from cv2 import *

while True:
time.sleep(4)
cam = VideoCapture(0)
s, img = cam.read()
if s: # frame captured without any errors
namedWindow("cam-test",CV_WINDOW_AUTOSIZE)
imshow("cam-test",img)
waitKey(0)
destroyWindow("cam-test")
imwrite("filename.jpg",img) #save image
 
T

Tim Golden

Hello,


I have a while loop taking images every 5 minutes from webcam.
Unfortunately, if the camera is busy, python.exe crashes and there is
no exception to catch. Is there a way to check if camera is busy to
avoid the crash?

If python.exe crashes -- ie exits completely without a traceback, then
it's most likely a flaw in the extension module which is capturing the
image. If that's the case, there's nothing you can do in Python code to
prevent it; you need to work with the project maintainers to fix that.

If you're getting a traceback but the console window is then closing too
fast for you to see it, then try running the code from an open console
window rather than double-clicking on it. (You don't say how you're
kicking the code off so I'm offering this just in case)

TJG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top