Raspberry Camera API: Difference between revisions

From Rsewiki
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
Back to [Robobot]]
Back to [[Robobot]]


===Raspicam===
== Camera use ==


A rather short raspberry pi camera API is available from https://www.uco.es/investiga/grupos/ava/node/40.
Raspberry pi operating system version "bullseye" uses a new camera library.
And can be downloaded from https://sourceforge.net/projects/raspicam/files/,


or get the file from sourceforge with no GUI, with:
The info is taken from https://www.raspberrypi.com/documentation/accessories/camera.html#libcamera-and-libcamera-apps?ref=https://githubhelp.com


cd ~/Downloads
=== LibCamera ===
wget --no-check-certificate -O raspicam-0.1.9.zip https://downloads.sourceforge.net/project/raspicam/raspicam-0.1.9.zip?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fraspicam%2F%3Fsource%3Dtyp_redirect&ts=1486483484&use_mirror=netix


Once fetched and available on the raspberry, then
If not already installed, install with
Unpack and install:
unzip raspicam-0.1.9.zip
cd raspicam-0.1.9
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig


The library is installed in /usr/local, and therefore to make cmake find it the path needs to be added to startup configuration, in file ~/.bashrc
sudo apt install libcamera-apps


  nano ~/.bashrc
It should not be needed to install libcamera-dev
  add at the end:
 
  export CMAKE_PREFIX_PATH=/usr/local/lib
==== Camera streaming ====
  source ~/.bashrc  # to implement export
 
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).