Scailable.
Search
⌃K

V4L2 loopback device setup

This tutorial provides a step-by-step guide on how to compile and install a V4L2 loopback device, as well as how to compile and install the Aravis GStreamer plugin on Ubuntu 20.04. It then explains how to utilize the Aravis plugin to make a wide range of standard GenICam USB3 and gigabit ethernet machine vision cameras available to the Scailable Edge AI Manager through the V4L2 loopback device.
To begin, you'll need to install specific packages that are necessary for compiling Aravis and the V4L2 loopback device.
sudo apt install libxml2-dev libglib2.0-dev cmake libusb-1.0-0-dev \
gobject-introspection libgtk-3-dev gtk-doc-tools xsltproc \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-good1.0-dev \
libgirepository1.0-dev gettext unzip python3-pip \
meson ninja-build
Next, install the V4L2 loopback device, which will allow you to create a "virtual video devices" that will allow any Linux application to access the industrial camera as a default Linux V4L2 video device:
git clone https://github.com/umlaeute/v4l2loopback.git
cd v4l2loopback
make && sudo make install
sudo depmod -a
Then, compile and install Aravis:
# retrieve aravis source code
wget https://github.com/AravisProject/aravis/archive/refs/heads/main.zip
apt install unzip autoremove
unzip main.zip
cd aravis-main/
# build aravis
meson setup build
cd build
ninja
ninja install
sudo ldconfig
If all went well, you can preview your machine vision camera(s) using the following command:
arv-viewer-0.8
To use Gstreamer with Scailable AI Manager, start by using Aravis to stream the camera input through Gstreamer (adjusting the format, width, height, and framerate parameters according to your camera's specifications):
gst-launch-1.0 --gst-plugin-path=/usr/local/lib/x86_64-linux-gnu/ aravissrc ! \
video/x-raw,format=GRAY8,width=2048,height=1536,framerate=20/1 ! \
videoconvert ! ximagesink
To make the image available to other applications as a V4L2 standard video device instead of displaying it in an X window, you need to generate a virtual V4L2 device:
sudo modprobe v4l2loopback card_label="vid0cam"
By creating this virtual loopback device, we enable the transmission of output from a machine vision camera to the Aravis Gstreamer plugin. Gstreamer then facilitates the availability of the camera output through this virtual loopback device:
gst-launch-1.0 --gst-plugin-path=/usr/local/lib/x86_64-linux-gnu/ \
aravissrc num-arv-buffers=1 ! \
video/x-raw,format=GRAY8,width=2048,height=1536,framerate=20/1 ! \
videoconvert ! video/x-raw,format=YUY2 ! v4l2sink device=/dev/video0
Your video pipeline should now start running:
At this stage, you can access the camera via /dev/video0 using any Linux application. Specifically, for our purposes, you can access it through the Scailable Edge AI Manager UI at http://localhost:8081:
To put the camera to good use, select, for instance, the people detection model and run it:
It is recommended to automate the creation of the loopback device and the execution of the Gstreamer pipeline during system boot. This can be achieved by implementing a startup script that executes the following two commands:
sudo modprobe v4l2loopback card_label="vid0cam"
gst-launch-1.0 --gst-plugin-path=/usr/local/lib/x86_64-linux-gnu/ \
aravissrc num-arv-buffers=1 ! \
video/x-raw,format=GRAY8,width=2048,height=1536,framerate=20/1 ! \
videoconvert ! video/x-raw,format=YUY2 ! v4l2sink device=/dev/video0