Skip to content

Instantly share code, notes, and snippets.

@keizerzilla
Created January 24, 2023 14:05
Show Gist options
  • Save keizerzilla/2d6369df47d23e44af4422efa419113c to your computer and use it in GitHub Desktop.
Save keizerzilla/2d6369df47d23e44af4422efa419113c to your computer and use it in GitHub Desktop.
Lists all avaiable cameras attached to the computer using Python and OpenCV.
# 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