Created
January 24, 2023 14:05
-
-
Save keizerzilla/2d6369df47d23e44af4422efa419113c to your computer and use it in GitHub Desktop.
Lists all avaiable cameras attached to the computer using Python and OpenCV.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# camlist.py | |
# Lists all avaiable cameras attached to the computer | |
# Dependencies: pip install opencv-python | |
# Usage: python camlist.py | |
import cv2 | |
print(f"OpenCV version: {cv2.__version__}") | |
max_cameras = 10 | |
avaiable = [] | |
for i in range(max_cameras): | |
cap = cv2.VideoCapture(i, cv2.CAP_DSHOW) | |
if not cap.read()[0]: | |
print(f"Camera index {i:02d} not found...") | |
continue | |
avaiable.append(i) | |
cap.release() | |
print(f"Camera index {i:02d} OK!") | |
print(f"Cameras found: {avaiable}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment