Skip to content

[Issue] : Handle Busy Camera #71

@CourageTrain

Description

@CourageTrain

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:

  1. 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
  2. VideoCapture.close() : prevents deadlock if read blocks
  3. VideoCapture.init() : Make thread daemon = True i.e. if the
    master thread dies, the daemon thread dies along with it now
  4. reader() : if not ret: print log + declare self.run = False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions