Skip to main content

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 runtime/dotnet:
    • DirectShowLib.dll
    • DirectShowLibWrapper.dll
  • Python bridge layer:
    • camera/camera_inspector_bridge.py
    • camera/camera_device_bridge.py
  • Python facade/API:
    • camera/camera_manager.py
  • GUI:
    • GUI/main_GUI.py (PyQt5)

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:

  • pythonnet
  • opencv-python
  • Pillow
  • PyQt5

Optional for faster MJPG decode:

  • PyTurboJPEG==2.2.0
  • libjpeg-turbo native DLL (turbojpeg.dll or libturbojpeg.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 app.main

Alternative:

python app/main.py

If installed as a package entry point:

camera-manager

Quick API Example

from 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:

  1. PyTurboJPEG (if import + native DLL initialization succeeds)
  2. OpenCV imdecode
  3. 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:

  1. Bump [project].version in pyproject.toml.
  2. Keep requirements.txt and pyproject.toml dependencies aligned.
  3. Verify project.urls in pyproject.toml point to the correct repository.
  4. Confirm runtime DLLs are present under runtime/dotnet.
  5. Sanity test end-to-end:
    • camera enumeration
    • open/close
    • frame preview
    • property set/get
  6. 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


Download files

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

Source Distribution

python_camera_manager_directshow-0.2.0.tar.gz (158.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_camera_manager_directshow-0.2.0-py3-none-any.whl (157.4 kB view details)

Uploaded Python 3

File details

Details for the file python_camera_manager_directshow-0.2.0.tar.gz.

File metadata

File hashes

Hashes for python_camera_manager_directshow-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cfce4d505c87078d3bc04c3e0807413073359655fc2cc0211b462b65ead890a5
MD5 6d63c139a1a7edb10de19ce8532a89a3
BLAKE2b-256 3befd02a95f447be2a938a0104f0b06c249bbbb070ca43b017c21b17372b8ef8

See more details on using hashes here.

File details

Details for the file python_camera_manager_directshow-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_camera_manager_directshow-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51e7653d6349baecddd735bf007c4f26c730927e599749ddbe9b953427f35145
MD5 17164617c46ab0afa9e394fcfe12fb45
BLAKE2b-256 03da239bea75ca05d3c0fb3a95a87c2d85e149e3b7eafe8b43424cab2329e7e5

See more details on using hashes here.

Supported by

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