Skip to main content

Expose camera to OVOS

Project description

Camera Plugin for OVOS PHAL

This plugin allows users to interact with cameras using OpenCV or libcamera, take snapshots, and serve video streams over HTTP. It also provides methods for handling camera operations via message bus events.

Features

  • Detect and use compatible camera systems (libcamera on Raspberry Pi or OpenCV on other systems).
  • Open and close the camera dynamically.
  • Capture frames and save them to a file or return them as base64-encoded strings.
  • Serve video streams as an MJPEG feed over HTTP.

HiveMind Support

This plugin can be used both in OVOS and with HiveMind satellites.

Be sure to allow "ovos.phal.camera.pong" in your hivemind for your satellite to be able to report camera support

hivemind-core allow-msg "ovos.phal.camera.pong"

Installation

  1. Install required dependencies:

    pip install ovos-phal-plugin-camera
    
  2. Add the plugin to your OVOS PHAL configuration:

    {
        "PHAL": {
            "ovos-phal-plugin-camera": {
                "video_source": 0,
                "start_open": false,
                "serve_mjpeg": false,
                "mjpeg_host": "0.0.0.0",
                "mjpeg_port": 5000
            }
        }
    }
    

Additional Steps for Raspberry Pi Users

If you plan to use this skill on a Raspberry Pi, it requires access to the libcamera package for the Picamera2 library to function correctly. Due to how libcamera is installed on the Raspberry Pi (system-wide), additional steps are necessary to ensure compatibility when using a Python virtual environment (venv).

In these examples we use the default .venv location from ovos-installer, ~/.venvs/ovos, adjust as needed

Steps to Enable libcamera in Your Virtual Environment

  1. Install Required System Packages
    Before proceeding, ensure that libcamera and its dependencies are installed on your Raspberry Pi. Run the following commands:

    sudo apt install -y python3-libcamera python3-kms++ libcap-dev
    
  2. Modify the Virtual Environment Configuration
    If you already have a virtual environment set up, enable access to system-wide packages by modifying the pyvenv.cfg file in the virtual environment directory:

    nano ~/.venvs/ovos/pyvenv.cfg
    

    Add or update the following line:

    include-system-site-packages = true
    

    Save the file and exit.

  3. Verify Access to libcamera
    Activate your virtual environment:

    source ~/.venvs/ovos/bin/activate
    

    Check if the libcamera package is accessible:

    python3 -c "import libcamera; print('libcamera is accessible')"
    

Why Are These Steps Necessary?

The libcamera package is not available on PyPI and is installed system-wide on the Raspberry Pi. Virtual environments typically isolate themselves from system-wide Python packages, so these adjustments allow the skill to access libcamera while still benefiting from the isolation provided by a venv.

Notes

  • These steps are specific to Raspberry Pi users who want to utilize the Picamera2 library for camera functionality. On other platforms, the skill defaults to using OpenCV, which does not require additional configuration.
  • Ensure that libcamera is installed on your Raspberry Pi before attempting these steps. You can test this by running:
    libcamera-still --version
    

Configuration Options

Option Type Default Description
video_source int 0 Index of the video source to use for the camera.
start_open bool false Whether to open the camera at plugin startup.
serve_mjpeg bool false Whether to start an MJPEG server for video streaming.
mjpeg_port int 5000 Port for the MJPEG server.

Bus Events

Handled Events

Event Name Description Payload
ovos.phal.camera.open Opens the camera. None
ovos.phal.camera.close Closes the camera. None
ovos.phal.camera.get Captures a frame from the camera. { "path": "<file_path>" }

Emitted Events

Event Name Description Payload
ovos.phal.camera.get.response Response for the captured frame. { "path": "<file_path>" } or { "b64_frame": "<base64_data>" }

Usage

Open the Camera

Send the following message to open the camera:

bus.emit(Message("ovos.phal.camera.open"))

Close the Camera

Send the following message to close the camera:

bus.emit(Message("ovos.phal.camera.close"))

Capture a Frame

Send the following message to capture a frame:

bus.emit(Message("ovos.phal.camera.get", {"path": "/path/to/save/image.jpg"}))

If the path is not provided, the frame will be returned as a base64-encoded string.

MJPEG Server

If the serve_mjpeg option is enabled in the configuration, the MJPEG feed will be accessible at:

http://<mjpeg_host>:<mjpeg_port>/video_feed

You can use the MJPEG feed to integrate this camera into Home Assistant


License

This project is licensed under the Apache 2.0 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

ovos_phal_plugin_camera-0.2.3a1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

ovos_phal_plugin_camera-0.2.3a1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file ovos_phal_plugin_camera-0.2.3a1.tar.gz.

File metadata

File hashes

Hashes for ovos_phal_plugin_camera-0.2.3a1.tar.gz
Algorithm Hash digest
SHA256 b626f0dfde3b46038cf407b55900294a514fe5ec90ded955ac807cec274f4f73
MD5 812d7816d6d5d60c15e4a27afff374ea
BLAKE2b-256 19f90c96de4fbdcf8cde16291661955567614fd757eeb21e7d2e37b53f1fae56

See more details on using hashes here.

File details

Details for the file ovos_phal_plugin_camera-0.2.3a1-py3-none-any.whl.

File metadata

File hashes

Hashes for ovos_phal_plugin_camera-0.2.3a1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfb7d49593e6027e9dda39788856fc6d534bcc10a64283cd1ccd5b345d52049d
MD5 2ca111ce91c6d993cfa111f881e2e2c3
BLAKE2b-256 1535bdb683995274940776889134bbb63fd14369596763a186e71a82a283c02f

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