Enumerate / List / Find / Detect / Search index for opencv VideoCapture.
Project description
cv2_enumerate_cameras
Retrieve the connected 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
python -m cv2_enumerate_cameras
Supported Backends
from cv2.videoio_registry import getBackendName
from cv2_enumerate_cameras import supported_backends
for backend in supported_backends:
print(getBackendName(backend))
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}')
Output:
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.
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)
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)
Camera Info
The cv2_enumerate_cameras.enumerate_cameras()
function will return a list of CameraInfo
objects.
CameraInfo.index
: Camera index for creatingcv2.VideoCapture
CameraInfo.name
: Camera nameCameraInfo.path
: Camera device pathCameraInfo.vid
: Vendor identifierCameraInfo.pid
: Product identifierCameraInfo.backend
: Camera backend
Find Camera by Vendor and Product Identifier
import cv2
from cv2_enumerate_cameras import enumerate_cameras
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
cap = find_camera(0x04F2, 0xB711)
while True:
result, frame = cap.read()
if not result:
break
cv2.imshow('frame', frame)
if cv2.waitKey(1) == ord('q'):
break
TODO
- Windows Support
- Linux Support
- MacOS Support
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
Hashes for cv2_enumerate_cameras-1.1.14.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d62c3366fe08b9095d1e8640121958b4256df7cd28646dc13edcdc1ceceec8cf |
|
MD5 | fcc31a5aa0405c3c0eb97cc101c38601 |
|
BLAKE2b-256 | 618dc01676deef5e9c5f0e4f233bddbfd8ebf0c040fe3593168cca31598e0313 |
Hashes for cv2_enumerate_cameras-1.1.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 867b94e787013d28f0d1c6d9bd8d7deb849a94033aa6e4923af1e0775a04677c |
|
MD5 | 80cba8876847c2b92c25c1baf4768763 |
|
BLAKE2b-256 | 43465f9b4c58ac3406fff87fc5dd12a0556d48838cfa832fa4dfcc7faccdba45 |
Hashes for cv2_enumerate_cameras-1.1.14-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eac36fc70fb8979acac18775a8b4ee25b648978f2dc3f0b84de496eb9ebc21a2 |
|
MD5 | d4e536eaaa081f1326087c70f8eef086 |
|
BLAKE2b-256 | cfdf3f7991ed7ed70c73924947c2918f4024bcb08191d1f7221116504f36c629 |
Hashes for cv2_enumerate_cameras-1.1.14-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2ffdbe9dd466e829861ac719b7a2ec71a17aa1c3e058afa6841daf493b712e9 |
|
MD5 | a9fb4d0e9cbad1af9d877a5be1579129 |
|
BLAKE2b-256 | 1a8b66f86f515ad8d1d50e46fddd3bc03f13fcb3aa84c21b42be1c65e9e77e74 |
Hashes for cv2_enumerate_cameras-1.1.14-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85c5ad057a9dd07a040bb299432bfe6eed67fda57d3218b43ac3dcaa28753ab6 |
|
MD5 | db2befd5ddd60c28461f07999fe67e4f |
|
BLAKE2b-256 | bda566378a809c23c40893bf61dc08e08a8951c2dfdff9ed7bd808b9dea4b5a6 |
Hashes for cv2_enumerate_cameras-1.1.14-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 739eeccbd430f787513e92997c23db64b90ade30d3d1217f6b22941c113029ce |
|
MD5 | 14d5d9e47fd31d56b4ab1f6fea5b93c6 |
|
BLAKE2b-256 | 5e4eab3a0f2aef6b56a237a7940a2b5da377216eeee57191d581e961b8019ac9 |
Hashes for cv2_enumerate_cameras-1.1.14-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3007b942d90448ab9416391bb7cc10ea502b53a61199bdaa760800fcc977c4e |
|
MD5 | 6f6c925dd510b9642465dd2cd061526c |
|
BLAKE2b-256 | e4006e4677f5ea118ec35b297e18d55c4bf9efb60e466bc30201e2b53fab4ea0 |
Hashes for cv2_enumerate_cameras-1.1.14-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 823efeb59a68e47e4669aca56580adc39afe7e9c1e3df06db8ddff5cec62ca82 |
|
MD5 | ea14c3bebfe3018664bf4591bb4a3e2c |
|
BLAKE2b-256 | f17bda55085121f9732efe843b89032fa17da2db8e46bdb7013143cf74486a2d |
Hashes for cv2_enumerate_cameras-1.1.14-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0296ea8dffea15223d42c610c48edd802383ed382dc7eeb08e415e83122b54b1 |
|
MD5 | ef8b4f50605c8ab7256b40a3d6e7c6bf |
|
BLAKE2b-256 | 23889471b99ea9c5c64b73d57952f1795d06b4f816796b0be70792f383a32647 |
Hashes for cv2_enumerate_cameras-1.1.14-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd58c13430c39605f92c5ba09e81f68586ae9917cc3bd4ee79ce6954e2be8f59 |
|
MD5 | ba8cd7766dfcd3235bd9162d5c72df96 |
|
BLAKE2b-256 | 4125c584eb31e2c0ead5f529749ec38d97ca0585724d5626d62e321408996ad8 |
Hashes for cv2_enumerate_cameras-1.1.14-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8077c85920a7159336c59ed40485a4f02da53e12b5972ff5807e51a36714083a |
|
MD5 | 93f80ad469c89f65ffb5db1c622a19a5 |
|
BLAKE2b-256 | 0136051ed91e5c4c353818044fa63d1901d79caaaca8ccbb26848804160a7ac6 |
Hashes for cv2_enumerate_cameras-1.1.14-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79aff5b01b0b4613eb8226aacc3493e1c4ec78a0030103c2a1dcc89af47d9bd4 |
|
MD5 | 46a3875bab472b1fd5813bd0c98c967d |
|
BLAKE2b-256 | 2d1ba7f6df97bf69406bc2ded426087d4edfdd1395b55c3200e911483f657bef |
Hashes for cv2_enumerate_cameras-1.1.14-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a84a1d454487f4ef3398bbb1a34c961ce7f0c109b3d4712f3107f28baf60425e |
|
MD5 | 53117723489eae99053e74f5a9851257 |
|
BLAKE2b-256 | 0ae72c3a1aa2c5e711792fdb46b71661f6df77c6e7cd68dbfc9d46d942b612fb |
Hashes for cv2_enumerate_cameras-1.1.14-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24c575248ab73804c558a3b0cd3597359a3dae6413546cbc704f434f1c37443e |
|
MD5 | c824f52f2043c6cd64f22444d5b67a58 |
|
BLAKE2b-256 | 0e5ed6c2fdfb32f9db7fc8159526c4164656ab7752d1e526a63fff280995482f |
Hashes for cv2_enumerate_cameras-1.1.14-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 555cbfe00efa10fc1a15e17f44fd6638d46bc4c6619471eabff9c37a93dc9df3 |
|
MD5 | e66694ab3ae6dfd87e85a2eb3bdfd72c |
|
BLAKE2b-256 | 72a10e70a90038fdec40ea1326f3fc4a684db773c5ebe93c9a646bb458db7f0b |
Hashes for cv2_enumerate_cameras-1.1.14-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33133262b6ba269324f8a167359ea9a0f771178c7f00bc90bef9ea754901d427 |
|
MD5 | 93a05f5fcecd23c88cb0cc5214b558bd |
|
BLAKE2b-256 | 287a243738bf44917c768d2e6c14e76779d14753df6b436768ca0fa4f8734f63 |
Hashes for cv2_enumerate_cameras-1.1.14-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d9e310442a44e897432de4ea077fbbab4cb2e2147b92ae325fe7dd307761036 |
|
MD5 | 083e7997e3bf856d897b4b96ed6cb86b |
|
BLAKE2b-256 | a65dfac303fbadbd81d785d5066fed1193f051340539ea3885c244595af1e3a9 |
Hashes for cv2_enumerate_cameras-1.1.14-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43fcefaf42c7999116cc0761355072894f13e27b0479d2a121ba7ff4edce447d |
|
MD5 | 88e093c422abc53e304597c88196cccc |
|
BLAKE2b-256 | 6e3a412da37253aaacfbf33b6a07c682ae9450176f5b3124168e3b39c0762196 |
Hashes for cv2_enumerate_cameras-1.1.14-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d2a0c02dfb24a7407298271f9388821b1ac48401642747ccd5c0003b55665a7 |
|
MD5 | a432b3c1f0ec0e4271fd528d54c12499 |
|
BLAKE2b-256 | 0c8226d4a4e0ecdfaa0ad3ae799145481e327e303837717b075ce361fb89d946 |
Hashes for cv2_enumerate_cameras-1.1.14-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a6b639393313cdaf0d82e6bd5a4c66d2be53e43580d9636c0a601ad6fbae220 |
|
MD5 | 4fea110316877c76e43b266e70b86f2e |
|
BLAKE2b-256 | d6de9dd244159547418f82a80946a049424dcd7d2b25b2552bbc92a85fcf0992 |