Summary:
Camera already in use
Steps to Reproduce:
1. start laptop camera app
2. Run examples/simple_example_v2.py
3. pygame window hangs with a blank screen
Expected Behavior:
graceful exit - as camera is not accessible
root cause:
cap = VideoCapture(0, cv2.CAP_DSHOW) -> CAP_DSHOW enables camera access
to OpenCV from Windows - even if camera feed is unavailable.
i.e. ret == True, even if camera is unavailable
Fix:
- If camera is already in use -report a runtime error i.e. cv2.CAP_DSHOW returns True for cap.read(), even if camera is busy - the frames are unusable i.e. almost entirely black
black_pixel_ratio = number of black pixels / total frame size
If black_pixel_ratio > 9 -> raise a runtime error
- VideoCapture.close() : prevents deadlock if read blocks
- VideoCapture.init() : Make thread daemon = True i.e. if the
master thread dies, the daemon thread dies along with it now
- reader() : if not ret: print log + declare self.run = False
Summary:
Camera already in use
Steps to Reproduce:
1. start laptop camera app
2. Run examples/simple_example_v2.py
3. pygame window hangs with a blank screen
Expected Behavior:
graceful exit - as camera is not accessible
root cause:
cap = VideoCapture(0, cv2.CAP_DSHOW) -> CAP_DSHOW enables camera access
to OpenCV from Windows - even if camera feed is unavailable.
i.e. ret == True, even if camera is unavailable
Fix:
black_pixel_ratio = number of black pixels / total frame size
If black_pixel_ratio > 9 -> raise a runtime error
master thread dies, the daemon thread dies along with it now