Enumerate / List / Find / Detect / Search index for opencv VideoCapture.
Project description
cv2_enumerate_cameras
Retrieve camera names, VID/PID information, device paths, and the corresponding OpenCV indices.
Installation
Install from PyPI
pip install cv2-enumerate-cameras
Quick Start
Run as a Script
A simple command-line script is provided to enumerate all cameras:
lscam
Or run the module directly:
python -m cv2_enumerate_cameras
Integrate into Your Project
To enumerate cameras inside your code:
from cv2_enumerate_cameras import enumerate_cameras
for camera_info in enumerate_cameras():
print(camera_info)
By default, enumerate_cameras() is called with the parameter CAP_ANY, which instructs cv2_enumerate_cameras to probe all supported backends when enumerating cameras. Example output:
1400: 2K USB Camera (2BDF:02A5)
700: 2K USB Camera (2BDF:02A5)
701: OBS Virtual Camera
These seemingly unusual indices are intentional: OpenCV encodes the backend ID into the high digits of the index. For example, 701 indicates the second camera (1) on the DSHOW backend (700).
To explicitly use a specific backend:
import cv2
from cv2_enumerate_cameras import enumerate_cameras
for camera_info in enumerate_cameras(cv2.CAP_MSMF):
print(camera_info)
Output:
0: 2K USB Camera (2BDF:02A5)
1: ...
2: ...
Once you have found the target camera, you can create a cv2.VideoCapture by its index and backend properties.
cap = cv2.VideoCapture(camera_info.index, camera_info.backend)
When using CAP_ANY, the backend argument can be omitted. But for robust behavior, explicitly passing it is strongly recommended.
Supported Backends
Not all OpenCV backends support camera enumeration. Use the following snippet to print the names of the supported backends:
from cv2.videoio_registry import getBackendName
from cv2_enumerate_cameras import supported_backends
for backend in supported_backends:
print(getBackendName(backend))
Windows:
- Microsoft Media Foundation (
CAP_MSMF) - DirectShow (
CAP_DSHOW)
Linux:
- GStreamer (
CAP_GSTREAMER) - V4L/V4L2 (
CAP_V4L2)
macOS:
- AVFoundation (
CAP_AVFOUNDATION)
CameraInfo Object
enumerate_cameras() returns a list of CameraInfo objects:
def enumerate_cameras(apiPreference: int = CAP_ANY) -> list[CameraInfo]:
...
CameraInfo.index: Camera index for the selected backendCameraInfo.name: Human-readable device nameCameraInfo.path: Device path (macOS:uniqueID);CameraInfo.vid: USB Vendor ID (if available);CameraInfo.pid: USB Product ID (if available);CameraInfo.backend: OpenCV backend used for enumeration.
Examples
Automatically Select a Camera by VID/PID
This example finds a camera using VID/PID and creates a VideoCapture:
import cv2
from cv2_enumerate_cameras import enumerate_cameras
# Search for a specific camera by VID and PID
def find_camera(vid, pid, apiPreference=cv2.CAP_ANY):
for i in enumerate_cameras(apiPreference):
if i.vid == vid and i.pid == pid:
return cv2.VideoCapture(i.index, i.backend)
raise RuntimeError('Camera not found!')
# Example: Find the camera with VID 0x04F2 and PID 0xB711
cap = find_camera(0x04F2, 0xB711)
# Capture and display frames
while True:
ok, frame = cap.read()
if not ok:
break
cv2.imshow('frame', frame)
if cv2.waitKey(1) == ord('q'):
break
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cv2_enumerate_cameras-1.3.3.tar.gz.
File metadata
- Download URL: cv2_enumerate_cameras-1.3.3.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc09429e3fd4a2ea3449bbc0ee12420666aee6705d80a36f2235503d90fff3a2
|
|
| MD5 |
acba0f05d7f5b3ec70b4db21006eb14d
|
|
| BLAKE2b-256 |
88406208e5ef9a0e46e9acc233c00a1b30728ca3b03b429e751c59e4d9cf5c8b
|
Provenance
The following attestation bundles were made for cv2_enumerate_cameras-1.3.3.tar.gz:
Publisher:
publish-to-pypi.yml on lukehugh/cv2_enumerate_cameras
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cv2_enumerate_cameras-1.3.3.tar.gz -
Subject digest:
cc09429e3fd4a2ea3449bbc0ee12420666aee6705d80a36f2235503d90fff3a2 - Sigstore transparency entry: 829718387
- Sigstore integration time:
-
Permalink:
lukehugh/cv2_enumerate_cameras@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Branch / Tag:
refs/tags/v1.3.3 - Owner: https://github.com/lukehugh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Trigger Event:
push
-
Statement type:
File details
Details for the file cv2_enumerate_cameras-1.3.3-py3-none-any.whl.
File metadata
- Download URL: cv2_enumerate_cameras-1.3.3-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f83c7329d85462bc27d805aa25a3cde73aa66d7e28e2f5b6cb425ccc84c965d0
|
|
| MD5 |
cb855ff2d7bd27699621fd2da0409da3
|
|
| BLAKE2b-256 |
98b1183463b131f6fb459186fd060ab1761aa8230f52417efc827d335c72df54
|
Provenance
The following attestation bundles were made for cv2_enumerate_cameras-1.3.3-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on lukehugh/cv2_enumerate_cameras
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cv2_enumerate_cameras-1.3.3-py3-none-any.whl -
Subject digest:
f83c7329d85462bc27d805aa25a3cde73aa66d7e28e2f5b6cb425ccc84c965d0 - Sigstore transparency entry: 829718395
- Sigstore integration time:
-
Permalink:
lukehugh/cv2_enumerate_cameras@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Branch / Tag:
refs/tags/v1.3.3 - Owner: https://github.com/lukehugh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Trigger Event:
push
-
Statement type:
File details
Details for the file cv2_enumerate_cameras-1.3.3-cp32-abi3-win_amd64.whl.
File metadata
- Download URL: cv2_enumerate_cameras-1.3.3-cp32-abi3-win_amd64.whl
- Upload date:
- Size: 21.8 kB
- Tags: CPython 3.2+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb4c9cf9d3f9d1bc0e648943f6683d5dd0228c93d6ed11aae471500701009dee
|
|
| MD5 |
2cdc651adb56cf2fbb6803c48cd3a51e
|
|
| BLAKE2b-256 |
1ae8197478c59e66ace7b41cbe6a5ce9cbbea42dfe6a0afba3d4dcc5d4b59df4
|
Provenance
The following attestation bundles were made for cv2_enumerate_cameras-1.3.3-cp32-abi3-win_amd64.whl:
Publisher:
publish-to-pypi.yml on lukehugh/cv2_enumerate_cameras
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cv2_enumerate_cameras-1.3.3-cp32-abi3-win_amd64.whl -
Subject digest:
fb4c9cf9d3f9d1bc0e648943f6683d5dd0228c93d6ed11aae471500701009dee - Sigstore transparency entry: 829718411
- Sigstore integration time:
-
Permalink:
lukehugh/cv2_enumerate_cameras@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Branch / Tag:
refs/tags/v1.3.3 - Owner: https://github.com/lukehugh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Trigger Event:
push
-
Statement type:
File details
Details for the file cv2_enumerate_cameras-1.3.3-cp32-abi3-win32.whl.
File metadata
- Download URL: cv2_enumerate_cameras-1.3.3-cp32-abi3-win32.whl
- Upload date:
- Size: 20.9 kB
- Tags: CPython 3.2+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
700d5d4283eb630e74d0a9e4829b9f5a3e373c3ce9a2e5bbed7959eb5bb31246
|
|
| MD5 |
c68c6b68cb2d1bb46eed0d65e293ca66
|
|
| BLAKE2b-256 |
38a97395194e0a7ad25e14669fd499a5bf062cb9ae3dcba4d4fca8dd398b4061
|
Provenance
The following attestation bundles were made for cv2_enumerate_cameras-1.3.3-cp32-abi3-win32.whl:
Publisher:
publish-to-pypi.yml on lukehugh/cv2_enumerate_cameras
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cv2_enumerate_cameras-1.3.3-cp32-abi3-win32.whl -
Subject digest:
700d5d4283eb630e74d0a9e4829b9f5a3e373c3ce9a2e5bbed7959eb5bb31246 - Sigstore transparency entry: 829718403
- Sigstore integration time:
-
Permalink:
lukehugh/cv2_enumerate_cameras@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Branch / Tag:
refs/tags/v1.3.3 - Owner: https://github.com/lukehugh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@98876ae19e6a5cf828bb17eb6e2007e0768413fb -
Trigger Event:
push
-
Statement type: