Automatic Raspberry Pi Camera driver for OpenCV — no setup headaches
Project description
rpicv2
Automatic Raspberry Pi Camera driver for OpenCV. No driver setup. No manual commands. Just import and go.
from rpicv2 import Camera
cam = Camera()
frame = cam.read()
How It Works
rpicv2 automatically:
- Loads
v4l2loopbackto create a virtual/dev/video0 - Pipes the
libcamera-vidfeed throughffmpeginto that virtual device - Opens the device with OpenCV so you can use it like any normal webcam
Requirements
Install system dependencies first:
sudo apt-get install v4l2loopback-dkms ffmpeg
libcamera comes pre-installed on Raspberry Pi OS.
Installation
pip install rpicv2
Or install from source:
git clone https://github.com/AsrayGopa/rpicv2.git
cd rpicv2
pip install .
Usage
Basic
from rpicv2 import Camera
cam = Camera()
while True:
frame = cam.show() # displays frame in a window
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cam.release()
Context Manager
from rpicv2 import Camera
import cv2
with Camera() as cam:
while True:
frame = cam.read()
cv2.imshow("Feed", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Custom Resolution / FPS
cam = Camera(width=1920, height=1080, fps=60)
API
Camera(width=1280, height=720, fps=30, device=0)
| Parameter | Default | Description |
|---|---|---|
width |
1280 |
Frame width in pixels |
height |
720 |
Frame height in pixels |
fps |
30 |
Frames per second |
device |
0 |
/dev/videoN device number |
Methods
| Method | Returns | Description |
|---|---|---|
read() |
np.ndarray |
Read one frame |
show(window="RPiCam") |
np.ndarray |
Read and display one frame |
release() |
None |
Stop pipeline and release resources |
License
MIT
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
rpicv2-0.1.0.tar.gz
(5.9 kB
view details)
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 rpicv2-0.1.0.tar.gz.
File metadata
- Download URL: rpicv2-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b6b006c22ce21ac0b38407a4d538ec5478cd8c229798097b57a741717f3b1c6
|
|
| MD5 |
01cb3ac24771972d9cfa46c704f482f1
|
|
| BLAKE2b-256 |
afb120a58e77e57d6a2a3e734f00f7217c354d1f100ad3d291a6dcdae6a6a472
|
File details
Details for the file rpicv2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rpicv2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da8767d285546b6bd756e3df1f01f6c9e4dc45982ecae9cb0243997f77bc18a7
|
|
| MD5 |
6332fa13a5b279a961f58e2156c4a5e6
|
|
| BLAKE2b-256 |
55fe43e834e99b454fed449b6398e2654c6709b32a17eed0dab45015ecc5c301
|