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
-
Install required dependencies:
pip install ovos-phal-plugin-camera
-
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
-
Install Required System Packages
Before proceeding, ensure thatlibcameraand its dependencies are installed on your Raspberry Pi. Run the following commands:sudo apt install -y python3-libcamera python3-kms++ libcap-dev
-
Modify the Virtual Environment Configuration
If you already have a virtual environment set up, enable access to system-wide packages by modifying thepyvenv.cfgfile in the virtual environment directory:nano ~/.venvs/ovos/pyvenv.cfgAdd or update the following line:
include-system-site-packages = true
Save the file and exit.
-
Verify Access to
libcamera
Activate your virtual environment:source ~/.venvs/ovos/bin/activate
Check if the
libcamerapackage 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
libcamerais 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
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 ovos_phal_plugin_camera-0.2.2a6.tar.gz.
File metadata
- Download URL: ovos_phal_plugin_camera-0.2.2a6.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f0c4e3bd4fdb029539cc849885cc91386369ed06f0bc0a3e0c0044e9eff3139
|
|
| MD5 |
31e44356053abcebb054723ea90fd06c
|
|
| BLAKE2b-256 |
790458132831d135387d6bb26c21dc46f2ac1fc10771c49b793032ebeed7f171
|
File details
Details for the file ovos_phal_plugin_camera-0.2.2a6-py3-none-any.whl.
File metadata
- Download URL: ovos_phal_plugin_camera-0.2.2a6-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f1e7a25cb1b744a4572d5745a749811ed848508fd3fe9fa789cdb55d29f2955
|
|
| MD5 |
a70fd0cd94320a8a85bc164bdd9c4f99
|
|
| BLAKE2b-256 |
fc50e05bfa7098033ec161fcc25a21c35d96b6c91269049870603372d2c3683b
|