Python camera manager with DirectShow capability discovery and .NET bridge integration
Project description
Python Camera Manager (DirectShow Bridge)
Python-first camera discovery, control, and live preview built on top of a .NET DirectShow wrapper.
This project was created to solve a common limitation in OpenCV camera workflows: while OpenCV can open cameras quickly, it does not provide a reliable, discoverable, device-specific model of control capabilities (valid ranges, step sizes, defaults, and auto/manual support) across many webcams.
Highlights
- Discover connected cameras.
- Query supported formats per device.
- Query control ranges and flags (min/max/step/default/current, supported, auto supported, auto enabled).
- Open camera streams through DirectShow from Python.
- Change auto/manual modes and set property values.
- Preview frames in a PyQt5 GUI.
- Decode MJPG using PyTurboJPEG first (when available), with OpenCV fallback.
Architecture
- .NET layer in
DirectShow_Wrapper/runtime/dotnet:DirectShowLib.dllDirectShowLibWrapper.dll
- Python bridge layer:
DirectShow_Wrapper/camera/camera_inspector_bridge.pyDirectShow_Wrapper/camera/camera_device_bridge.py
- Python facade/API:
DirectShow_Wrapper/camera/camera_manager.py
- GUI:
DirectShow_Wrapper/GUI/main_GUI.py(PyQt5)
DirectShow_Wrapper/camera/camera_manager.py exposes Python-native objects (NamedTuple, dict, list) so consumers do not need to deal with .NET object APIs directly.
Requirements
- Windows (DirectShow)
- Python 3.10+
- .NET runtime compatible with the shipped wrapper DLLs
- DirectShow-capable camera
Python dependencies:
pythonnetopencv-pythonPillowPyQt5
Optional for faster MJPG decode:
PyTurboJPEG==2.2.0libjpeg-turbonative DLL (turbojpeg.dllorlibturbojpeg.dll)
PyTurboJPEG is not required for base functionality and is intentionally not included in default package dependencies.
Setup
py -m venv .venv
.venv\Scripts\activate
python -m pip install -U pip
python -m pip install -e .
If you want accelerated MJPG decode:
python -m pip install PyTurboJPEG==2.2.0
Without PyTurboJPEG, MJPG decoding falls back to OpenCV automatically.
Notes:
- Do not install the unrelated package named
turbojpeg(different project, different API). - If needed, point to your native turbojpeg DLL with
TURBOJPEG_LIB_PATH.
Run
python -m DirectShow_Wrapper.app.main
Alternative:
python -m DirectShow_Wrapper.app.main
If installed as a package entry point:
camera-manager
Quick API Example
from DirectShow_Wrapper.camera.camera_manager import Camera
devices = Camera.get_connected_cameras(get_formats=True, get_ranges=True)
if not devices:
raise RuntimeError("No camera detected")
selected = devices[0]
fmt = selected.formats[0]
cam = Camera(debug_logging=False)
ok = cam.open(selected.path, fmt, request_rgb24_conversion=False)
if not ok:
raise RuntimeError("Failed to open camera")
try:
exposure = cam.property_ranges.get("Exposure")
if exposure and exposure.property_supported:
cam.set_property_auto_mode("Exposure", False)
cam.set_property_value("Exposure", int(exposure.default))
success, frame = cam.get_frame()
finally:
cam.close()
Decoder Behavior (MJPG)
For MJPG/MJPEG formats, decode priority is:
- PyTurboJPEG (if import + native DLL initialization succeeds)
- OpenCV
imdecode - Unavailable (frame skipped with error log)
For uncompressed formats (RGB24, BGR24, GRAY8, etc.), decoding does not require MJPG decoders.
Troubleshooting
PyQt5 import error
If you see ModuleNotFoundError: No module named 'PyQt5', verify you are using the project venv and install dependencies:
.venv\Scripts\python.exe -m pip install -e .
Pylance false positives with Qt/pythonnet
Some warnings are static-analysis false positives due to dynamic runtime APIs in PyQt/pythonnet. Use workspace-level Pylance settings in .vscode/settings.json to tune diagnostic severity as needed.
TurboJPEG confusion
If the wrong package was installed before, clean and reinstall:
.venv\Scripts\python.exe -m pip uninstall -y turbojpeg
.venv\Scripts\python.exe -m pip install PyTurboJPEG==2.2.0
Maintainer Release Checklist
Before publishing an update:
- Bump
[project].versioninpyproject.toml. - Keep
requirements.txtandpyproject.tomldependencies aligned. - Verify
project.urlsinpyproject.tomlpoint to the correct repository. - Confirm runtime DLLs are present under
DirectShow_Wrapper/runtime/dotnet. - Sanity test end-to-end:
- camera enumeration
- open/close
- frame preview
- property set/get
- Update README and changelog notes for behavior/API changes.
Companion .NET Repository
The current Python project repository is:
The .NET wrapper source code is maintained separately; this repository focuses on Python API ergonomics and application usage.
License
MIT. See LICENSE.
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 Distribution
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 python_camera_manager_directshow-0.2.1.tar.gz.
File metadata
- Download URL: python_camera_manager_directshow-0.2.1.tar.gz
- Upload date:
- Size: 156.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a49b24dee6d8e09ebe02091a70253add9e8bc5fc4d69c8cdf31062a302379cd
|
|
| MD5 |
4515e3c98aa18b60022140b1ac26f9a7
|
|
| BLAKE2b-256 |
78fe9191c774b6382de75bd2b494fc83848b3a0f4f58b1f574d02644100f26b6
|
File details
Details for the file python_camera_manager_directshow-0.2.1-py3-none-any.whl.
File metadata
- Download URL: python_camera_manager_directshow-0.2.1-py3-none-any.whl
- Upload date:
- Size: 158.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b42a303bf8ee965b8f363a6c0dc864c6647a61bdddafa32b50ba66d86f34a3b6
|
|
| MD5 |
88562943df37f7f70977a086d2937518
|
|
| BLAKE2b-256 |
707a71d2726b8fcc7fd8511966cb7afa306155065c252346bbb047fb06085cb2
|