Raspberry Camera API: Difference between revisions
(23 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Back to [[Robobot]] | Back to [[Robobot]] | ||
== | == Camera use == | ||
Raspberry pi operating system version "bullseye" uses a new camera library. | |||
The info is taken from https://www.raspberrypi.com/documentation/accessories/camera.html#libcamera-and-libcamera-apps?ref=https://githubhelp.com | |||
=== LibCamera === | |||
If not already installed, install with | |||
sudo apt install libcamera-apps | |||
It should not be needed to install libcamera-dev | |||
==== Camera streaming ==== | |||
The libcamera library can do streaming out of the box with the command: | |||
libcamera-vid -n -t 0 --inline --listen --rotation 0 --framerate 30 --width 1920 --height 1080 -o tcp://0.0.0.0:8888 | |||
It will listen to port 8888 for TCP connections on the localhost. | |||
From another PC the stream can be displayed by VLC, (or the same parameter in the VLC "media" -> "open network stream") | |||
vlc tcp/h264://192.168.2.14:8888 | |||
if 192.168.2.14 is the IP of the Raspberry pi. | |||
The streaming will terminate when the VLC stops the connection. | |||
A start-script is placed in the "local" home folder. | |||
./stream_cam.sh | |||
with examples of different solutions. | |||
== camera from OpenCV == | |||
The raspberry cameras seem to prefer 10 bit/pixel in Bayer RGGB format - other formats are not consistent for both new and old camera. | |||
=== Format check === | |||
Install package v4l-utils (also installed by default) | |||
sudo apt install v4l-utils | |||
The supported image formats from both cameras are: | |||
v4l2-ctl -d/dev/video0 --list-formats | |||
ioctl: VIDIOC_ENUM_FMT | |||
Type: Video Capture | |||
[0]: 'BA81' (8-bit Bayer BGBG/GRGR) | |||
[1]: 'pBAA' (10-bit Bayer BGBG/GRGR Packed) | |||
[2]: 'BG10' (10-bit Bayer BGBG/GRGR) | |||
For the used format 'BG10' the frame sizes supported is found | |||
v4l2-ctl -d /dev/video0 --list-framesizes BG10 | |||
ioctl: VIDIOC_ENUM_FRAMESIZES | |||
Size: Discrete 2592x1944 | |||
Size: Discrete 1920x1080 | |||
Size: Discrete 1296x972 | |||
Size: Discrete 640x480 | |||
But formats can be converted to other formats, visible as other video devices e.g /dev/video12. | |||
v4l2-ctl -d/dev/video12 --list-formats | |||
ioctl: VIDIOC_ENUM_FMT | |||
Type: Video Capture Multiplanar | |||
[0]: 'YUYV' (YUYV 4:2:2) | |||
[1]: 'YVYU' (YVYU 4:2:2) | |||
[2]: 'VYUY' (VYUY 4:2:2) | |||
[3]: 'UYVY' (UYVY 4:2:2) | |||
[4]: 'YU12' (Planar YUV 4:2:0) | |||
[5]: 'YV12' (Planar YVU 4:2:0) | |||
[6]: 'RGB3' (24-bit RGB 8-8-8) | |||
[7]: 'BGR3' (24-bit BGR 8-8-8) | |||
[8]: 'BGR4' (32-bit BGRA/X 8-8-8-8) | |||
[9]: 'RGBP' (16-bit RGB 5-6-5) | |||
[10]: 'NV12' (Y/CbCr 4:2:0) | |||
[11]: 'NV21' (Y/CrCb 4:2:0) | |||
Format BA81 did not give a proper result for both cameras. | |||
I didn't succeed in using the converted formats, maybe because they are based on the BA81 format. | |||
Format 'BG10' works for both cameras and is easily converted to RGB format using OpenCV (https://docs.opencv.org/3.4/db/d64/tutorial_js_colorspaces.html). |
Latest revision as of 14:49, 4 January 2022
Back to Robobot
Camera use
Raspberry pi operating system version "bullseye" uses a new camera library.
The info is taken from https://www.raspberrypi.com/documentation/accessories/camera.html#libcamera-and-libcamera-apps?ref=https://githubhelp.com
LibCamera
If not already installed, install with
sudo apt install libcamera-apps
It should not be needed to install libcamera-dev
Camera streaming
The libcamera library can do streaming out of the box with the command:
libcamera-vid -n -t 0 --inline --listen --rotation 0 --framerate 30 --width 1920 --height 1080 -o tcp://0.0.0.0:8888
It will listen to port 8888 for TCP connections on the localhost.
From another PC the stream can be displayed by VLC, (or the same parameter in the VLC "media" -> "open network stream")
vlc tcp/h264://192.168.2.14:8888
if 192.168.2.14 is the IP of the Raspberry pi. The streaming will terminate when the VLC stops the connection.
A start-script is placed in the "local" home folder.
./stream_cam.sh
with examples of different solutions.
camera from OpenCV
The raspberry cameras seem to prefer 10 bit/pixel in Bayer RGGB format - other formats are not consistent for both new and old camera.
Format check
Install package v4l-utils (also installed by default)
sudo apt install v4l-utils
The supported image formats from both cameras are:
v4l2-ctl -d/dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT Type: Video Capture [0]: 'BA81' (8-bit Bayer BGBG/GRGR) [1]: 'pBAA' (10-bit Bayer BGBG/GRGR Packed) [2]: 'BG10' (10-bit Bayer BGBG/GRGR)
For the used format 'BG10' the frame sizes supported is found
v4l2-ctl -d /dev/video0 --list-framesizes BG10
ioctl: VIDIOC_ENUM_FRAMESIZES Size: Discrete 2592x1944 Size: Discrete 1920x1080 Size: Discrete 1296x972 Size: Discrete 640x480
But formats can be converted to other formats, visible as other video devices e.g /dev/video12.
v4l2-ctl -d/dev/video12 --list-formats
ioctl: VIDIOC_ENUM_FMT Type: Video Capture Multiplanar [0]: 'YUYV' (YUYV 4:2:2) [1]: 'YVYU' (YVYU 4:2:2) [2]: 'VYUY' (VYUY 4:2:2) [3]: 'UYVY' (UYVY 4:2:2) [4]: 'YU12' (Planar YUV 4:2:0) [5]: 'YV12' (Planar YVU 4:2:0) [6]: 'RGB3' (24-bit RGB 8-8-8) [7]: 'BGR3' (24-bit BGR 8-8-8) [8]: 'BGR4' (32-bit BGRA/X 8-8-8-8) [9]: 'RGBP' (16-bit RGB 5-6-5) [10]: 'NV12' (Y/CbCr 4:2:0) [11]: 'NV21' (Y/CrCb 4:2:0)
Format BA81 did not give a proper result for both cameras. I didn't succeed in using the converted formats, maybe because they are based on the BA81 format. Format 'BG10' works for both cameras and is easily converted to RGB format using OpenCV (https://docs.opencv.org/3.4/db/d64/tutorial_js_colorspaces.html).