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 DirectShow_Wrapper/runtime/dotnet:
    • DirectShowLib.dll
    • DirectShowLibWrapper.dll
  • Python bridge layer:
    • DirectShow_Wrapper/camera/camera_inspector_bridge.py
    • DirectShow_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:

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

  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 DirectShow_Wrapper/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.1.tar.gz (156.1 kB view details)

Uploaded Source

Built Distribution

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

File details

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

File metadata

File hashes

Hashes for python_camera_manager_directshow-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9a49b24dee6d8e09ebe02091a70253add9e8bc5fc4d69c8cdf31062a302379cd
MD5 4515e3c98aa18b60022140b1ac26f9a7
BLAKE2b-256 78fe9191c774b6382de75bd2b494fc83848b3a0f4f58b1f574d02644100f26b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_camera_manager_directshow-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b42a303bf8ee965b8f363a6c0dc864c6647a61bdddafa32b50ba66d86f34a3b6
MD5 88562943df37f7f70977a086d2937518
BLAKE2b-256 707a71d2726b8fcc7fd8511966cb7afa306155065c252346bbb047fb06085cb2

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