Skip to content

Identify and select your USB cameras in Python for use with OpenCV.

License

Notifications You must be signed in to change notification settings

JohnHardy/pyusbcameraindex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyusbcameraindex

Identify and select your USB cameras in Python for use with OpenCV.

🚀🤯 Stop guessing the camera index in OpenCV! 🤯🚀

PyPI PyPI - License PyPI - Python Version

PyPI - Downloads GitHub repo size

The pyusbcameraindex package enumerates USB video devices on Windows using DirectShow APIs.

Linux and Mac are not supported, but pull requests are welcome.

Usage:

import cv2
from pyusbcameraindex import enumerate_usb_video_devices_windows

# List the devices.
devices = enumerate_usb_video_devices_windows()
for device in devices:
    print(f"{device.index} == {device.name} (VID: {device.vid}, PID: {device.pid}, Path: {device.path}")

# Show a frame from each.
for device in devices:
    cap = cv2.VideoCapture(device.index, cv2.CAP_DSHOW)
    ret, frame = cap.read()
    cv2.imshow(f"Device={device.name}", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    cap.release()
cv2.destroyAllWindows()

About

Identify and select your USB cameras in Python for use with OpenCV.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages