Skip to main content

Enumerate / List / Find / Detect / Search index for opencv VideoCapture.

Project description

cv2_enumerate_cameras

PyPI - Version Python Version from PEP 621 TOML PyPI - Downloads

Retrieve camera's name, VID, PID, and the corresponding OpenCV index.

Installation

Install from PyPI

pip install cv2_enumerate_cameras

Install from Source

pip install git+https://github.com/chinaheyu/cv2_enumerate_cameras.git

Example

Run as Script

We have provided a simple script that prints out information for all cameras. Open a shell and simply run:

python -m cv2_enumerate_cameras

Supported Backends

Since OpenCV supports many different backends, not all of them provide support for camera enumeration. The following code demonstrates how to retrieve 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))

Currently supported backends on windows:

  • Microsoft Media Foundation (CAP_MSMF)
  • DirectShow (CAP_DSHOW)

Currently supported backends on linux:

  • GStreamer (CAP_GSTREAMER)
  • V4L/V4L2 (CAP_V4L2)

Enumerate Cameras

This is an example showing how to enumerate cameras.

from cv2_enumerate_cameras import enumerate_cameras

for camera_info in enumerate_cameras():
    print(f'{camera_info.index}: {camera_info.name}')

The enumerate_cameras(apiPreference: int = CAP_ANY) function comes with the default parameter CAP_ANY, and you will receive output similar to the following:

1400: HD Webcam
...
700: HD Webcam
701: OBS Virtual Camera
...

These indices may seem strange, since opencv defaults to using the high digits of index to represent the backend. For example, 701 indicates the second camera on the DSHOW backend (700).

You can also select a supported backend for enumerating camera devices.

Here's an example of enumerating camera devices via the CAP_MSMF backend on windows.

import cv2
from cv2_enumerate_cameras import enumerate_cameras

for camera_info in enumerate_cameras(cv2.CAP_MSMF):
    print(f'{camera_info.index}: {camera_info.name}')

Output:

0: HD Webcam
...

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 as an option for the enumerate_cameras function, the backend parameter can be omitted. However, it is highly recommended to pass it along when creating a VideoCapture.

Camera Info

The cv2_enumerate_cameras.enumerate_cameras() function will return a list of CameraInfo objects, each containing information about a specific camera.

def enumerate_cameras(apiPreference: int = CAP_ANY) -> list[CameraInfo]:
    ...
  • CameraInfo.index: Camera index for creating cv2.VideoCaptureach containing all the information about a camera;
  • CameraInfo.name: Camera name;
  • CameraInfo.path: Camera device path;
  • CameraInfo.vid: Vendor identifier;
  • CameraInfo.pid: Product identifier;
  • CameraInfo.backend: Camera backend.

Find Camera by Vendor and Product Identifier

This example demonstrates how to automatically select a camera based on its VID and PID and create a VideoCapture object.

import cv2
from cv2_enumerate_cameras import enumerate_cameras

# define a function to search for a camera
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)
    return None

# find the camera with VID 0x04F2 and PID 0xB711
cap = find_camera(0x04F2, 0xB711)

# read and display the camera frame
while True:
    result, frame = cap.read()
    if not result:
        break
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
        break

TODO

Currently, support for MacOS is in the planning stage, and pull requests are very welcome.

  • Windows Support
  • Linux Support
  • MacOS Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cv2_enumerate_cameras-1.1.17.tar.gz (45.0 kB view details)

Uploaded Source

Built Distributions

cv2_enumerate_cameras-1.1.17-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

cv2_enumerate_cameras-1.1.17-pp310-pypy310_pp73-win_amd64.whl (43.4 kB view details)

Uploaded PyPy Windows x86-64

cv2_enumerate_cameras-1.1.17-pp39-pypy39_pp73-win_amd64.whl (43.4 kB view details)

Uploaded PyPy Windows x86-64

cv2_enumerate_cameras-1.1.17-pp38-pypy38_pp73-win_amd64.whl (43.4 kB view details)

Uploaded PyPy Windows x86-64

cv2_enumerate_cameras-1.1.17-pp37-pypy37_pp73-win_amd64.whl (42.3 kB view details)

Uploaded PyPy Windows x86-64

cv2_enumerate_cameras-1.1.17-cp312-cp312-win_amd64.whl (43.4 kB view details)

Uploaded CPython 3.12 Windows x86-64

cv2_enumerate_cameras-1.1.17-cp312-cp312-win32.whl (42.6 kB view details)

Uploaded CPython 3.12 Windows x86

cv2_enumerate_cameras-1.1.17-cp311-cp311-win_amd64.whl (43.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

cv2_enumerate_cameras-1.1.17-cp311-cp311-win32.whl (42.6 kB view details)

Uploaded CPython 3.11 Windows x86

cv2_enumerate_cameras-1.1.17-cp310-cp310-win_amd64.whl (43.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

cv2_enumerate_cameras-1.1.17-cp310-cp310-win32.whl (42.6 kB view details)

Uploaded CPython 3.10 Windows x86

cv2_enumerate_cameras-1.1.17-cp39-cp39-win_amd64.whl (43.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

cv2_enumerate_cameras-1.1.17-cp39-cp39-win32.whl (42.6 kB view details)

Uploaded CPython 3.9 Windows x86

cv2_enumerate_cameras-1.1.17-cp38-cp38-win_amd64.whl (43.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

cv2_enumerate_cameras-1.1.17-cp38-cp38-win32.whl (42.6 kB view details)

Uploaded CPython 3.8 Windows x86

cv2_enumerate_cameras-1.1.17-cp37-cp37m-win_amd64.whl (42.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

cv2_enumerate_cameras-1.1.17-cp37-cp37m-win32.whl (41.4 kB view details)

Uploaded CPython 3.7m Windows x86

cv2_enumerate_cameras-1.1.17-cp36-cp36m-win_amd64.whl (27.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

cv2_enumerate_cameras-1.1.17-cp36-cp36m-win32.whl (26.8 kB view details)

Uploaded CPython 3.6m Windows x86

File details

Details for the file cv2_enumerate_cameras-1.1.17.tar.gz.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17.tar.gz
Algorithm Hash digest
SHA256 e1960e6fc6fdf85cb4019d066422dbfe7fb16c977e71d5b700d9588999ab6a19
MD5 5e5b48278da7904a241d2aca88ea5d3e
BLAKE2b-256 d0cac069f5a890f4745f719c5017c81ace70c6fb8f725f0ca52823cc906e4128

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-py3-none-any.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 6c032b5b3fd138a60ec486717566d916636e3d8bfe6377d2ab6f3f8a76fd9c38
MD5 eea9e0ac5c77bea9c5b81788aa94b6a1
BLAKE2b-256 493b333b38993381d22d92cdacca219bf34348a4993f6a43398fb0adf0dd5145

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-pp310-pypy310_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-pp310-pypy310_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 6d318e819809212d0428ec1507240fca74cbde456e133937f5bf151165631e1a
MD5 19667ce0690896e270485ddf0e28c8a9
BLAKE2b-256 d71a4e8cd6e797a77b3fbc7901a1f1ff40bddb836aa362620cef7259e0e1cebc

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-pp39-pypy39_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-pp39-pypy39_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 14f88b6f5abf451dc329e2eb8fdd23284c39fa6ed6f085bb054fca6d6f64d91d
MD5 5f0b466e9ee2384e5b759c03f53cb82d
BLAKE2b-256 916a9bcffe15b06ced9ae8248cbc0e589b5b871135c6000790bf171447711b82

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-pp38-pypy38_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-pp38-pypy38_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 a43575d38e125163942ec871ab8b4864880563462b4e9c7b4cceae8296c09e57
MD5 79048fc3895efa4002c95eb9fac821d2
BLAKE2b-256 21ed107571615cf2099a664c476048938b8d27a804c7b6d9520ffb3a4003ee9e

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-pp37-pypy37_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-pp37-pypy37_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 94580ec044147045250be84655dd084268f8ffb1f74bbe1e9f4073e653715589
MD5 8193b0c4fafd2f0bd7ac0c874fd9dd26
BLAKE2b-256 d800021a124821646d276a41414d7b034e0d4f50daea3106cc61811befefcddd

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f3daff70995b67f28f1b211a5dcc281f0687d74f3088db09fdefb3ec30c8cfe6
MD5 c2df1de8c2e92d0ddb0ca31cbf0d7579
BLAKE2b-256 6c0722aa874cebed970ee2e5038659583449bfb3ac7cfd251cfb25397c3c23ae

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 47421f06adf2c70c83e90da47b8ea2f2fc4807093f14c95e74671b7521489c0a
MD5 7500405cd9713dfdc446044086c9d6fc
BLAKE2b-256 b89ffa3ca4803acea917afd7e05a5b6af3082f48518e06c7d6561c3e71530be3

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 00cd2c3f96f51a13a52cfee3b2cbe30ef0b26854c6f3cafdc02c18345f8546de
MD5 cb58c7f82d5beba2f3047b8a28423996
BLAKE2b-256 503a0e104eec531c4428c180624ca1181d5addd5e60538f534cdce472a2d2acd

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 ff2b8cf3d0c338a2aadc868893acd71b975a39ab5871ea9cc5ac222beba16573
MD5 1ab656998f5f6bbf408b3b2331f0ca59
BLAKE2b-256 45d3c658e9cd419836f89e1038cd1598d72cb04209ef078f623714de54dfe94a

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 11ecefdf3a86f0b3cc9b5bc3d84b7075a30b19560692ec51c3576ed213cdcb1c
MD5 e476a2caca7c0f3772306103a5d4a9f2
BLAKE2b-256 b4a7e938dc3ef3542387038c3e54b433a9d304680f97636eb588750cc8b835f0

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp310-cp310-win32.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 87019ac946f6403df88a780b3ca788f41554b3e55b58b6d83f9dfcac0de78f11
MD5 f67b920d43828090f80104bf36c22191
BLAKE2b-256 448da38ad931865dd157a18efc8c5874e80fbc137a8130514b4cfc655a59fa5e

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c9846db2385263cfc826acf9b80ca23083add56609210db6a356223a1dbd95af
MD5 8405347ea9d915f0c165cec78acb18f2
BLAKE2b-256 27ca9570d1d734c715fc8d7fa1db79a3836501dc99541653bf7f40578b08f13e

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp39-cp39-win32.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 8d4b311edcc593f36f066432454592b1fad94188064d317d4226bda9dc6be330
MD5 ffa3a051abccca55e73a97a541960346
BLAKE2b-256 0c115922cf70d61639b5bc7ff8c3029268b4fe4e3ac8e2de128a4533b7320b76

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 593f838b44e5b85575f15010a6eb0a4994e50ebeea8415ca764da1e31a9a1867
MD5 f51dc91d12387db50c0537e882110354
BLAKE2b-256 512bb8f9606e8fcdcf2d61eeeb54970024624b4aa8d379ddd7c902fec31c4722

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp38-cp38-win32.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 c5dfd378ba20b710f24f6a5a11e9df68abe46cdb1320563530f1ed1b275801b0
MD5 daa90185b2f4c0657a35bbfc8cda7dba
BLAKE2b-256 eb5a4e18a20b269e7580ad4d7bc3fb4f59b20e69c53be5cede559ba8718d7be2

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 61d6441a0910e558803965880243eabbc41b4e97bb1c14aca94c97e03e7d2559
MD5 4d3327721dceb884433db764de63cbb5
BLAKE2b-256 682a61778ccb499eec02d7f120de37a91a530c582f568d6c72e22292ee374903

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp37-cp37m-win32.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 f26be44e3f48025c56768cfa82d5fb3d7163107f4be6e148a3738b9404ffeabe
MD5 f21d48435be8841ec6a145aa8076eca5
BLAKE2b-256 d2d0b17977c4b57fefd0fc1fcbe7b6c3c4902348b1d1636669d4810fd918e84e

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 da603b717e682248e74b80ea2e2e7fdd408fd1f15dd3f8e0f2c5639394009dfa
MD5 f184dcfc8e7692ee6f8d001d486d835c
BLAKE2b-256 c892dec6c414f8ba7cad5e902ee618956a107fe92af52cb80892d49ea1078a8d

See more details on using hashes here.

File details

Details for the file cv2_enumerate_cameras-1.1.17-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for cv2_enumerate_cameras-1.1.17-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 c3bc505458f1032c46a04b3cb62fdf3d638c89c0f0d4461f5052a06591811019
MD5 d7c03f3d4e63a56cb0267e962bd901b1
BLAKE2b-256 ae82a1b88085ac697271cdc8cf6f7db1f06eb38705fb2273aa82e87787f3db5a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page