© 2019 Montgomery One
Building Complete Embedded
Vision Systems on Linux - Camera
to Display
Clay D. Montgomery
Montgomery One
May 2019
© 2019 Montgomery One
The Big Picture - Overview
• Start on a Ubuntu Linux PC to develop and prototype new CV algorithms and applications
- Install, build and explore the OpenCV sample programs on a Ubuntu system
• Select your Open-Hardware ARM SoC (System on Chip) board and cameras carefully
- A good BSP with camera drivers and Yocto support are critical!
• Build a custom OS with Yocto Open Embedded Linux for your target board
- Use the same open-source libraries on Ubuntu and target systems, if at all possible
• Build your application with the Yocto toolchain for your ARM target system
• Select Open-Source component libraries to use
- Which do you actually need and which are the best for your application?
- V4L2, FFmpeg, GStreamer, OpenCV, OpenGL ES, OpenCL and OpenVX?
• Explore the options for acceleration on your ARM SoC
- Acceleration is required for most CV applications, so plan for it
2
© 2019 Montgomery One
Popular ARM SoC Boards for Vision
3
RaspberryPi 3 TI BeagleBoard
NXP i.MX8
Nvidia Jetson TX2
i.MX6 WandBoard with MIPI Camera
© 2019 Montgomery One
Exploring Open Source Video
Components for Linux
© 2019 Montgomery One
An Example - Vision Components for Lightwing
5
© 2019 Montgomery One
V4L2 – Video for Linux (Version 2)
6
• Negotiates compatible video formats and manages buffers and events between apps and drivers
• The de-facto standard low-level video API for Linux
• The most widely used API for video input on Linux systems
• Most Linux distros and BSPs provide drivers for cameras and TV tuners for V4L2
• Version 1 is obsolete, but still used by the OpenCV VideoCapture class
• Well supported by most SoC vendors that have integrated MIPI camera support
• The UVC standard (USB Video Class for web cams) is newer and still uses V4L2 on Linux
© 2019 Montgomery One
GStreamer
• Negotiates compatible video formats and builds pipelines and filter-graphs to connect plug-in
components and apps to the V4L2 API
• The de-facto standard high-level audio/video API for Linux
• The most widely used API for video pipelines on Linux systems
• Used by OpenCV's VideoCapture class to work around video format issues, such as color space
and RGB/BGR mismatch issues
gst-launch-1.0 autovideosrc ! videoconvert ! autovideosink
./videocapture_basic "imxv4l2videosrc device=/dev/video0 ! videoconvert ! appsink"
• Well supported by some SoC vendors that have integrated VPUs and codecs
- VPUs can be very difficult to exploit without good drivers for GStreamer
- This is a major differentiator among SoC vendors and should be evaluated carefully
7
© 2019 Montgomery One
OpenCV
• 2D and 3D feature toolkits
• Egomotion estimation
• Facial recognition system
• Gesture recognition
• Human–computer interaction (HCI)
• Motion tracking and understanding
• Object segmentation and recognition
• Depth perception from 2 cameras
• Structure from motion (SFM)
• Statistical machine learning and DNN
• Support for OpenCL and CUDA accelerators
8
• Not a Khronos standard, but mostly open-source
• Began as Intel Research open initiative in 1999
• Intel donated OpenCV to non-profit OpenCV.org
• Most comprehensive and widely used CV library
• Available on most platforms and languages today
• Lots of sample programs in C/C++ and Python
• Great place to start to prototype a new design
• Latest 4.x available, but not much help on ARM
FeaturesOrigin and Status
Issues
• Typically too slow for camera video (on ARM)
• Samples require X11 on Linux
• Bugs in VideoCapture class on Linux
• Requires video in BGR format
© 2019 Montgomery One
FFmpeg
• A set of libraries for encoding, decoding and converting audio and video files and
streams, such as JPEG, MPEG and H.264, etc.
• Supported on a very wide range of platforms
• Very limited support for accelerators on ARM SoCs (NEON)
- Most ARM SoC vendors do not provide drivers to accelerate FFmpeg
- FFmpeg codecs are typically too slow for camera video on ARM SoCs
- But, still useful for de-muxing, removing containers, etc.
9
© 2019 Montgomery One
OpenGL ES
• The original Khronos consortium standard for 3D graphics on SoCs
• One of the most successful and widely adopted APIs for embedded multimedia ever
• Version 1.1 is obsolete
• Versions 2.0 - 3.0 are widely supported today by most SoC vendors with GPUs
• Shader code can be used to accelerate some CV algorithms
• Version 3.1 added more abilities to do general-purpose compute, including CV
• Driver support is more mature and stable than for OpenCL and OpenVX
• GLSL coding is familiar to more developers than OpenCL, NEON or CUDA
• Lightwing uses version 2.0 GLSL for faster motion tracking than is possible with OpenCV
10
© 2019 Montgomery One
OpenCL
11
• Khronos consortium standard for general-purpose compute acceleration on SoCs and FPGAs
• Framework for general-purpose compute acceleration across heterogeneous processors
including CPUs, GPUs, DSPs and FPGAs
• Based on C99 and C++11 languages
• Provides a standard interface for parallel computing using task- and data-based parallelism
• Some mid to high-end SoC and FPGA vendors support OpenCL for CV applications
• Open alternative to Nvidia's CUDA
• Not as mature on most platforms as OpenGL ES or CUDA
• Will accommodate a wider range of algorithms than OpenGL ES shader code
© 2019 Montgomery One
OpenVX
12
• Khronos standard for cross-platform acceleration of computer vision applications
• A higher level of abstraction for programming CV than OpenCL
• Based on a connected graph of vision nodes that execute a preferred chain of operations
• Complementary to OpenCV, but can offer more optimized graph management
• Many SoC vendors are quickly developing support for OpenVX
• Available now on NVIDIA
• Supports face, body and gesture tracking, smart video surveillance, advanced driver assistance
systems (ADAS), object and scene reconstruction, augmented reality, visual inspection, robotics, etc.
© 2019 Montgomery One
Basic Camera Video Pipelines
13
© 2019 Montgomery One
Your First Camera Video Pipeline (V4L2 and GStreamer)
• Attach a USB Camera to a Ubuntu PC (or your target system) and try:
dmesg | grep camera
- Displays kernel error messages about your camera driver's initialization
ls /dev/video0
cat /dev/video0
- Shows if your camera driver is installed and working (producing data)
lsmod
- Lists all installed kernel drivers
gst-launch-1.0 videotestsrc ! autovideosink
- Test to see if gstreamer is installed and working (should display a color bars test pattern)
gst-launch-1.0 autovideosrc ! autovideosink
- Initialize and run a complete video pipeline (camera to display) using V4L2 and gstreamer
14
© 2019 Montgomery One
OpenCV Sample Programs
© 2019 Montgomery One
Explore the OpenCV Sample Programs
• Install OpenCV 3.2 on Ubuntu (14 - 16) and build the sample apps:
sudo apt-get install opencv
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
cd ~/opencv-3.2.0/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
cp -r /usr/local/lib/libopencv* /usr/lib/.
• Run some sample apps on Ubuntu:
cd /usr/share/OpenCV/samples/bin
./cpp-example-videocapture_basic
• Combine sample source codes with 'videocapture_starter' to test an algorithm with camera video
- cpp-example-videocapture_starter.cpp + cpp-example-edge.cpp
16
© 2019 Montgomery One
Yocto Open Embedded Linux
© 2019 Montgomery One
Build a Yocto Linux System for Your Target Board
• Choose a board with a Yocto BSP and cameras with recipes for Yocto
• Test the camera drivers provided in your BSP well
- You will likely have to create recipes and/or a new V4L2 driver for your camera
- An example of a working driver from your camera vendor is a minimum requirement
• Install Yocto (Pyro, Rocko or Sumo) on Ubuntu and build a bootable OS:
repo init -u https://github.com/Freescale/fsl-community-bsp-platform -b pyro
repo sync
MACHINE=wandboard DISTRO=fslc-x11 source setup-environment build
bitbake fsl-image-machine-test-full (or, core-image-basic, fsl-image-x11-qt5, etc.)
• Build and install cross-development toolchain to build your app and any additional packages:
bitbake fsl-image-machine-test-full -c populate_sdk
./build/tmp/deploy/sdk/fslc-x11-glibc-x86_64-fsl-image-multimedia-armv7at2hf-neon-toolchain-2.3.4.sh
bitbake -s
18
© 2019 Montgomery One
Integrating OpenCV with
Yocto Linux
© 2019 Montgomery One
An Example - Vision Components for Lightwing
20
© 2019 Montgomery One
Build and Run OpenCV Samples for Your Target Board
• Add packages for OpenCV, X11, gstreamer, etc. to Yocto's config file:
buildconflocal.conf
CORE_IMAGE_EXTRA_INSTALL += "opencv x11 gstreamer"
• Build and test the OpenCV 3.2 samples using Yocto toolchain, sysroot and CMake in your Yocto tree
(mostly the same as on Ubuntu):
source /opt/fslc-x11/2.3.4/environment-setup-arm7at2hf-neon-fslc-linux-gnueabi
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
• Running the sample apps on your target requires initialization of an X window (X11):
export DISPLAY=:0.0
xhost +SI:localuser:root
cd /usr/share/OpenCV/samples/bin
./cpp-example-videocapture_basic
21
© 2019 Montgomery One
VideoCapture Class for Linux
• The camera interface for OpenCV
• About 40 implementations are provided for all major OS platforms
• Three implementations are provided for Linux:
cap_v4l.cpp - Original, for obsolete V4L version 1
cap_libv4l.cpp – Updated replacement for V4L2, with many patches
cap_gstreamer.cpp – Optional extension convert formats and accepts GStreamer pipeline syntax:
cpp-example-videocapture_basic 'videotestsrc ! videoconvert ! appsink'
• Required some debugging to work on newer (4.x) Linux kernels
- If V4L2 fails to initialize, it then tries V4L (version 1), which produces very confusing error messages.
- Removed the xioctl() call macro because it was failing when calling to inquire the video format
(VIDIOC_S_FMT)
• Some improvements are available in OpenCV 4.1.0 for the Android Media NDK
22
© 2019 Montgomery One
What Else Can (and Did) Go Wrong?
• OmniVision 5640 camera discontinued
–Was a popular camera supported by the FSL Community BSP
–Use new OV5645 driver from Rocko version instead
–Only older versions of Yocto (Pyro) actually work on most i.MX6/8 boards
• Yocto only supports OpenCV 3.2 because of CMake compatibility issues
–CMake installed by Yocto will not build OpenCV 3.4
• OpenCV samples require X Windows on Linux
–Either use X11 or eliminate the use of the High-GUI module in samples
• OpenCV VideoCapture class requires GStreamer on Linux
–Unnecessarily complex and broken on the i.MX6/8 platform
–Fixed the bugs in V4L2 implementation, so it works without GStreamer
23
© 2019 Montgomery One
Working Around Component Limitations
• OpenCV (VideoCapture class) requires the antiquated 24 bit BGR pixel format !
–Many cameras only provide 16 bit RGB 565, YUV or RAW formats
–RAW format is 10 bit RGB (Bayer), but requires software conversion (very slow)
• Official solution is to use gstreamer (with an appsink) element to convert YUV to BGR:
videocapture_starter 'imxv4l2videosrc ! videoconvert ! appsink'
- Can be accelerated by the IPU on i.MX6/8 by using NXP's plugins for gstreamer
- libgstapp.so must be installed manually for this to work due to a bug in some builds for i.MX6/8
• Other ways to adapt the V4L2 VideoCapture class and get better performance:
–Use the i.MX6/8 IPU without GStreamer. Red and Blue are swapped, but for many CV apps, that is fine
–Use luminance data directly (dropping color data), without conversion to RGB
• i.MX6 IPU will not scale video beyond 1024 x 1024 pixels (fixed on the i.MX8)
• Lightwing solution - Use the GPU (OpenGL ES) to convert and scale video, instead of the IPU or GStreamer
- Basic motion tracking algorithm is done in shader code, instead of OpenCV
24
© 2019 Montgomery One
Lightwing Motion Tracking
Demo
© 2019 Montgomery One
Lightwing Motion Tracking 3D GUI Demo
Motion tracking on the NXP i.MX6 GPU enables interactive control of 3D assets for
mixed-reality video walls, without VR headsets or hand controllers
26
© 2019 Montgomery One
Conclusions
© 2019 Montgomery One
Lessons Learned
• Start on a desktop PC with Ubuntu and the OpenCV samples
- Develop your vision algorithms there, first
• Use Yocto Open Embedded Linux to build your custom platform
• Use the same open source libraries on desktop and target systems
- Hacking OpenCV's VideoCapture class will likely be required
• Understand which vision components you actually need and why
• Select cameras carefully, considering software support
- You really need a good V4L2 driver with Yocto recipes
- Use a MIPI camera if possible, instead of USB
• Explore the acceleration options for your SoC (GPU, IPU, NEON, etc)
- Acceleration is required for most CV applications of camera video on ARM
28
© 2019 Montgomery One
Resources
29
OpenCV Installation Tutorial
https://www.docs.opencv.org/2.4.13/doc/tutorials/intr
oduction/linux_install/linux_install.html#linux-
installation
Yocto Open Embedded Linux
https://www.yoctoproject.org/
GStreamer Documentation
https://gstreamer.freedesktop.org/documentation/
V4L2 Documentation
https://www.kernel.org/doc/html/v4.9/media/uapi/v4l
/v4l2.html
Khronos OpenGL ES, OpenCL and OpenVX
Documentation
https://www.khronos.org/
Lightwing Open Mixed-Reality Platform
https://montgomery1.com/lightwing/
NXP i.MX6/8 Development Boards
https://www.wandboard.org/
OpenCV Status on Github
https://github.com/opencv/opencv/wiki/ChangeLog
© 2019 Montgomery One
Appendix
© 2019 Montgomery One
OpenCV C++ Example - Edge Detection on Camera Video
int iEdgeThreshSobel = 1;
Mat mImageFrame, mImageGray, mImageGrayBlur, mImageEdgeMask, mImageEdgeResult;
const char* WindowName = "Canny edge map with Sobel gradient";
static void onTrackbar(int, void*)
{
cvtColor(mImageFrame, mImageGray, COLOR_BGR2GRAY); // Create blurred gray scale image for edge detection.
blur(mImageGray, mImageGrayBlur, Size(3, 3));
Canny(mImageGrayBlur, mImageEdgeMask, iEdgeThreshSobel, iEdgeThreshSobel * 3, 3); // Canny detector with sobel filter.
mImageEdgeResult = Scalar::all(0); // Clear to black.
mImageFrame.copyTo(mImageEdgeResult, mImageEdgeMask);
imshow(WindowName, mImageEdgeResult); // Display image frame in window.
}
int main(int argc, char** argv)
{
VideoCapture capture;
capture.open(0); // Open camera device through V4L2.
namedWindow(WindowName, WINDOW_KEEPRATIO); // Create window and slider control.
createTrackbar("Canny threshold Sobel", WindowName, &iEdgeThreshSobel, 100, onTrackbar);
char key = 0;
while (key != ‘q’) // Capture frames from the camera and display them.
{
capture >> mImageFrame; // Capture another image frame from camera.
if (mImageFrame.empty())
break;
onTrackbar(0, 0); // Show the image.
key = (char)waitKey(30); // Wait 30 milliseconds for a key press.
}
return 0;
}
31
© 2019 Montgomery One 32
Lightwing – Open Mixed-Reality Video Wall Platform
• Build custom digital signs and video walls with interactive 3D content
• Camera motion tracking controls 3D assets without VR headsets or hand controllers
• Supports both touch screens and camera motion tracking input
• Multipanel video wall dimensions of any size for public spaces
• Built-in 3D animations, fonts, effects, audio, video, images and web RSS feeds
• GPU and IPU acceleration of camera video on the NXP i.MX6/8 series SoCs
• Scriptable, browserless architecture built on open tools for Windows and Linux
https://montgomery1.com/lightwing/
© 2019 Montgomery One
Lightwing on Linux verses Android and Windows
33
© 2019 Montgomery One
About Clay D. Montgomery
• 30+ Years of Embedded Multimedia Software Development
• C/C++, OpenGL 3D, Audio/Video, Linux, Windows and Android
• Previously worked at STB (3Dfx), VLSI (NXP), Nokia, TI and AMX (Harmon)
• Authored on Embedded OpenGL ES for Intel Developer Zone, TI, Montgomery One
• Freelance Embedded Linux Developer since 2010
• Now working on Open Embedded Linux (Yocto) on ARM almost Exclusively
• Active in Tech Start Up Community in Texas
• Created Lightwing Mixed-Reality Engine for Interactive Digital Signage, Video Walls and
Touch-Kiosks on NXP i.MX6/8 SoCs
• Currently adding CV Object Detection and Motion Tracking Features to Lightwing
34

More Related Content

PPTX
Yocto Project introduction
PDF
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
PDF
Video Drivers
PDF
Building your own embedded system with Yocto
PDF
My presentation raspberry pi
PDF
Linux KVM のコードを追いかけてみよう
PDF
Yocto - Embedded Linux Distribution Maker
Yocto Project introduction
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
Video Drivers
Building your own embedded system with Yocto
My presentation raspberry pi
Linux KVM のコードを追いかけてみよう
Yocto - Embedded Linux Distribution Maker

What's hot (20)

PDF
GPU仮想化最前線 - KVMGTとvirtio-gpu -
PDF
ARM Trusted FirmwareのBL31を単体で使う!
PDF
Build your own embedded linux distributions by yocto project
PDF
Embedded Linux from Scratch to Yocto
PDF
Cuda tutorial
PPTX
Enable DPDK and SR-IOV for containerized virtual network functions with zun
PPTX
An Introduction to RISC-V bootflow
PDF
Linux Kernel and Driver Development Training
PDF
Rootlinux17: Hypervisors on ARM - Overview and Design Choices by Julien Grall...
PDF
Introduction to yocto
PDF
今話題のいろいろなコンテナランタイムを比較してみた
PDF
Interrupt Affinityについて
PPTX
Beyond printk: Efficient Zynq UltraScale+ MPSoC Linux Debugging and Development
PDF
Let's trace Linux Lernel with KGDB @ COSCUP 2021
PDF
PPTX
Linux Memory Management with CMA (Contiguous Memory Allocator)
PDF
How to run P4 BMv2
PDF
Magnum IO GPUDirect Storage 最新情報
PPTX
Red Bend Software: Separation Using Type-1 Virtualization in Vehicles and Aut...
GPU仮想化最前線 - KVMGTとvirtio-gpu -
ARM Trusted FirmwareのBL31を単体で使う!
Build your own embedded linux distributions by yocto project
Embedded Linux from Scratch to Yocto
Cuda tutorial
Enable DPDK and SR-IOV for containerized virtual network functions with zun
An Introduction to RISC-V bootflow
Linux Kernel and Driver Development Training
Rootlinux17: Hypervisors on ARM - Overview and Design Choices by Julien Grall...
Introduction to yocto
今話題のいろいろなコンテナランタイムを比較してみた
Interrupt Affinityについて
Beyond printk: Efficient Zynq UltraScale+ MPSoC Linux Debugging and Development
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Linux Memory Management with CMA (Contiguous Memory Allocator)
How to run P4 BMv2
Magnum IO GPUDirect Storage 最新情報
Red Bend Software: Separation Using Type-1 Virtualization in Vehicles and Aut...
Ad

Similar to "Building Complete Embedded Vision Systems on Linux—From Camera to Display," a Presentation from Montgomery One (20)

PPTX
Add sale davinci
PPSX
Embedded project
PDF
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
PPTX
Implementing a parallel_open_cv_application_on_raspberry_pi3(1)
PDF
Embedded Recipes 2018 - Upstream multimedia on amlogic so cs from fiction t...
PDF
Starting with OpenCV on i.MX 6 Processors
ODP
Computer vision for your projects
PDF
Introduction to OpenCV 2.3.1
PDF
"The Vision API Maze: Options and Trade-offs," a Presentation from the Khrono...
PDF
OpenCV Workshop
PDF
Kernel Recipes 2016 - Why you need a test strategy for your kernel development
PDF
Installing OpenCV 2.4.x with Qt
PDF
PL-4043, Accelerating OpenVL for Heterogeneous Platforms, by Gregor Miller
PPTX
Cvpr2010 open source vision software, intro and training part v open cv and r...
PDF
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...
PDF
Opencv application on PandaBoard
PPTX
Cross platform computer vision optimization
PDF
kocialkowski-overview-linux-userspace-graphics-stack.pdf
PDF
Machine Vision On Embedded Platform
PDF
Machine vision Application
Add sale davinci
Embedded project
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
Implementing a parallel_open_cv_application_on_raspberry_pi3(1)
Embedded Recipes 2018 - Upstream multimedia on amlogic so cs from fiction t...
Starting with OpenCV on i.MX 6 Processors
Computer vision for your projects
Introduction to OpenCV 2.3.1
"The Vision API Maze: Options and Trade-offs," a Presentation from the Khrono...
OpenCV Workshop
Kernel Recipes 2016 - Why you need a test strategy for your kernel development
Installing OpenCV 2.4.x with Qt
PL-4043, Accelerating OpenVL for Heterogeneous Platforms, by Gregor Miller
Cvpr2010 open source vision software, intro and training part v open cv and r...
"The OpenCV Open Source Computer Vision Library: What’s New and What’s Coming...
Opencv application on PandaBoard
Cross platform computer vision optimization
kocialkowski-overview-linux-userspace-graphics-stack.pdf
Machine Vision On Embedded Platform
Machine vision Application
Ad

More from Edge AI and Vision Alliance (20)

PDF
“Strategies for Image Dataset Curation from High-volume Industrial IoT Data,”...
PDF
“Taking Computer Vision Products from Prototype to Robust Product,” an Interv...
PDF
“Improving Worksite Safety with AI-powered Perception,” a Presentation from A...
PDF
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
PDF
“Integrating Cameras with the Robot Operating System (ROS),” a Presentation f...
PDF
“Using Computer Vision for Early Detection of Cognitive Decline via Sleep-wak...
PDF
“AI-powered Scouting: Democratizing Talent Discovery in Sports,” a Presentati...
PDF
“Vision-based Aircraft Functions for Autonomous Flight Systems,” a Presentati...
PDF
“A View From the 2025 Embedded Vision Summit (Part 2),” a Presentation from t...
PDF
“A View From the 2025 Embedded Vision Summit (Part 1),” a Presentation from t...
PDF
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PDF
“The New OpenCV 5.0: Added Features, Performance Improvements and Future Dire...
PDF
“Introduction to Shrinking Models with Quantization-aware Training and Post-t...
PDF
“Customizing Vision-language Models for Real-world Applications,” a Presentat...
PDF
“An Introduction to the MIPI CSI-2 Image Sensor Standard and Its Latest Advan...
PDF
“Visual Search: Fine-grained Recognition with Embedding Models for the Edge,”...
PDF
“Optimizing Real-time SLAM Performance for Autonomous Robots with GPU Acceler...
PDF
“LLMs and VLMs for Regulatory Compliance, Quality Control and Safety Applicat...
PDF
“Simplifying Portable Computer Vision with OpenVX 2.0,” a Presentation from AMD
“Strategies for Image Dataset Curation from High-volume Industrial IoT Data,”...
“Taking Computer Vision Products from Prototype to Robust Product,” an Interv...
“Improving Worksite Safety with AI-powered Perception,” a Presentation from A...
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
“Integrating Cameras with the Robot Operating System (ROS),” a Presentation f...
“Using Computer Vision for Early Detection of Cognitive Decline via Sleep-wak...
“AI-powered Scouting: Democratizing Talent Discovery in Sports,” a Presentati...
“Vision-based Aircraft Functions for Autonomous Flight Systems,” a Presentati...
“A View From the 2025 Embedded Vision Summit (Part 2),” a Presentation from t...
“A View From the 2025 Embedded Vision Summit (Part 1),” a Presentation from t...
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
“The New OpenCV 5.0: Added Features, Performance Improvements and Future Dire...
“Introduction to Shrinking Models with Quantization-aware Training and Post-t...
“Customizing Vision-language Models for Real-world Applications,” a Presentat...
“An Introduction to the MIPI CSI-2 Image Sensor Standard and Its Latest Advan...
“Visual Search: Fine-grained Recognition with Embedding Models for the Edge,”...
“Optimizing Real-time SLAM Performance for Autonomous Robots with GPU Acceler...
“LLMs and VLMs for Regulatory Compliance, Quality Control and Safety Applicat...
“Simplifying Portable Computer Vision with OpenVX 2.0,” a Presentation from AMD

Recently uploaded (20)

PDF
Intravenous drug administration application for pediatric patients via augmen...
PDF
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
PDF
Revolutionizing recommendations a survey: a comprehensive exploration of mode...
PPTX
Blending method and technology for hydrogen.pptx
PDF
Altius execution marketplace concept.pdf
PPTX
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
PDF
State of AI in Business 2025 - MIT NANDA
PPTX
Introduction-to-Artificial-Intelligence (1).pptx
PDF
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
PDF
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
PDF
Applying Agentic AI in Enterprise Automation
PPT
Overviiew on Intellectual property right
PDF
Examining Bias in AI Generated News Content.pdf
PDF
Advancements in abstractive text summarization: a deep learning approach
PDF
Secure Java Applications against Quantum Threats
PDF
Peak of Data & AI Encore: Scalable Design & Infrastructure
PPTX
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
PDF
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
PDF
Rooftops detection with YOLOv8 from aerial imagery and a brief review on roof...
PDF
【AI論文解説】高速・高品質な生成を実現するFlow Map Models(Part 1~3)
Intravenous drug administration application for pediatric patients via augmen...
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
Revolutionizing recommendations a survey: a comprehensive exploration of mode...
Blending method and technology for hydrogen.pptx
Altius execution marketplace concept.pdf
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
State of AI in Business 2025 - MIT NANDA
Introduction-to-Artificial-Intelligence (1).pptx
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
Applying Agentic AI in Enterprise Automation
Overviiew on Intellectual property right
Examining Bias in AI Generated News Content.pdf
Advancements in abstractive text summarization: a deep learning approach
Secure Java Applications against Quantum Threats
Peak of Data & AI Encore: Scalable Design & Infrastructure
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
Rooftops detection with YOLOv8 from aerial imagery and a brief review on roof...
【AI論文解説】高速・高品質な生成を実現するFlow Map Models(Part 1~3)

"Building Complete Embedded Vision Systems on Linux—From Camera to Display," a Presentation from Montgomery One

  • 1. © 2019 Montgomery One Building Complete Embedded Vision Systems on Linux - Camera to Display Clay D. Montgomery Montgomery One May 2019
  • 2. © 2019 Montgomery One The Big Picture - Overview • Start on a Ubuntu Linux PC to develop and prototype new CV algorithms and applications - Install, build and explore the OpenCV sample programs on a Ubuntu system • Select your Open-Hardware ARM SoC (System on Chip) board and cameras carefully - A good BSP with camera drivers and Yocto support are critical! • Build a custom OS with Yocto Open Embedded Linux for your target board - Use the same open-source libraries on Ubuntu and target systems, if at all possible • Build your application with the Yocto toolchain for your ARM target system • Select Open-Source component libraries to use - Which do you actually need and which are the best for your application? - V4L2, FFmpeg, GStreamer, OpenCV, OpenGL ES, OpenCL and OpenVX? • Explore the options for acceleration on your ARM SoC - Acceleration is required for most CV applications, so plan for it 2
  • 3. © 2019 Montgomery One Popular ARM SoC Boards for Vision 3 RaspberryPi 3 TI BeagleBoard NXP i.MX8 Nvidia Jetson TX2 i.MX6 WandBoard with MIPI Camera
  • 4. © 2019 Montgomery One Exploring Open Source Video Components for Linux
  • 5. © 2019 Montgomery One An Example - Vision Components for Lightwing 5
  • 6. © 2019 Montgomery One V4L2 – Video for Linux (Version 2) 6 • Negotiates compatible video formats and manages buffers and events between apps and drivers • The de-facto standard low-level video API for Linux • The most widely used API for video input on Linux systems • Most Linux distros and BSPs provide drivers for cameras and TV tuners for V4L2 • Version 1 is obsolete, but still used by the OpenCV VideoCapture class • Well supported by most SoC vendors that have integrated MIPI camera support • The UVC standard (USB Video Class for web cams) is newer and still uses V4L2 on Linux
  • 7. © 2019 Montgomery One GStreamer • Negotiates compatible video formats and builds pipelines and filter-graphs to connect plug-in components and apps to the V4L2 API • The de-facto standard high-level audio/video API for Linux • The most widely used API for video pipelines on Linux systems • Used by OpenCV's VideoCapture class to work around video format issues, such as color space and RGB/BGR mismatch issues gst-launch-1.0 autovideosrc ! videoconvert ! autovideosink ./videocapture_basic "imxv4l2videosrc device=/dev/video0 ! videoconvert ! appsink" • Well supported by some SoC vendors that have integrated VPUs and codecs - VPUs can be very difficult to exploit without good drivers for GStreamer - This is a major differentiator among SoC vendors and should be evaluated carefully 7
  • 8. © 2019 Montgomery One OpenCV • 2D and 3D feature toolkits • Egomotion estimation • Facial recognition system • Gesture recognition • Human–computer interaction (HCI) • Motion tracking and understanding • Object segmentation and recognition • Depth perception from 2 cameras • Structure from motion (SFM) • Statistical machine learning and DNN • Support for OpenCL and CUDA accelerators 8 • Not a Khronos standard, but mostly open-source • Began as Intel Research open initiative in 1999 • Intel donated OpenCV to non-profit OpenCV.org • Most comprehensive and widely used CV library • Available on most platforms and languages today • Lots of sample programs in C/C++ and Python • Great place to start to prototype a new design • Latest 4.x available, but not much help on ARM FeaturesOrigin and Status Issues • Typically too slow for camera video (on ARM) • Samples require X11 on Linux • Bugs in VideoCapture class on Linux • Requires video in BGR format
  • 9. © 2019 Montgomery One FFmpeg • A set of libraries for encoding, decoding and converting audio and video files and streams, such as JPEG, MPEG and H.264, etc. • Supported on a very wide range of platforms • Very limited support for accelerators on ARM SoCs (NEON) - Most ARM SoC vendors do not provide drivers to accelerate FFmpeg - FFmpeg codecs are typically too slow for camera video on ARM SoCs - But, still useful for de-muxing, removing containers, etc. 9
  • 10. © 2019 Montgomery One OpenGL ES • The original Khronos consortium standard for 3D graphics on SoCs • One of the most successful and widely adopted APIs for embedded multimedia ever • Version 1.1 is obsolete • Versions 2.0 - 3.0 are widely supported today by most SoC vendors with GPUs • Shader code can be used to accelerate some CV algorithms • Version 3.1 added more abilities to do general-purpose compute, including CV • Driver support is more mature and stable than for OpenCL and OpenVX • GLSL coding is familiar to more developers than OpenCL, NEON or CUDA • Lightwing uses version 2.0 GLSL for faster motion tracking than is possible with OpenCV 10
  • 11. © 2019 Montgomery One OpenCL 11 • Khronos consortium standard for general-purpose compute acceleration on SoCs and FPGAs • Framework for general-purpose compute acceleration across heterogeneous processors including CPUs, GPUs, DSPs and FPGAs • Based on C99 and C++11 languages • Provides a standard interface for parallel computing using task- and data-based parallelism • Some mid to high-end SoC and FPGA vendors support OpenCL for CV applications • Open alternative to Nvidia's CUDA • Not as mature on most platforms as OpenGL ES or CUDA • Will accommodate a wider range of algorithms than OpenGL ES shader code
  • 12. © 2019 Montgomery One OpenVX 12 • Khronos standard for cross-platform acceleration of computer vision applications • A higher level of abstraction for programming CV than OpenCL • Based on a connected graph of vision nodes that execute a preferred chain of operations • Complementary to OpenCV, but can offer more optimized graph management • Many SoC vendors are quickly developing support for OpenVX • Available now on NVIDIA • Supports face, body and gesture tracking, smart video surveillance, advanced driver assistance systems (ADAS), object and scene reconstruction, augmented reality, visual inspection, robotics, etc.
  • 13. © 2019 Montgomery One Basic Camera Video Pipelines 13
  • 14. © 2019 Montgomery One Your First Camera Video Pipeline (V4L2 and GStreamer) • Attach a USB Camera to a Ubuntu PC (or your target system) and try: dmesg | grep camera - Displays kernel error messages about your camera driver's initialization ls /dev/video0 cat /dev/video0 - Shows if your camera driver is installed and working (producing data) lsmod - Lists all installed kernel drivers gst-launch-1.0 videotestsrc ! autovideosink - Test to see if gstreamer is installed and working (should display a color bars test pattern) gst-launch-1.0 autovideosrc ! autovideosink - Initialize and run a complete video pipeline (camera to display) using V4L2 and gstreamer 14
  • 15. © 2019 Montgomery One OpenCV Sample Programs
  • 16. © 2019 Montgomery One Explore the OpenCV Sample Programs • Install OpenCV 3.2 on Ubuntu (14 - 16) and build the sample apps: sudo apt-get install opencv sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev cd ~/opencv-3.2.0/opencv mkdir release cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. make sudo make install cp -r /usr/local/lib/libopencv* /usr/lib/. • Run some sample apps on Ubuntu: cd /usr/share/OpenCV/samples/bin ./cpp-example-videocapture_basic • Combine sample source codes with 'videocapture_starter' to test an algorithm with camera video - cpp-example-videocapture_starter.cpp + cpp-example-edge.cpp 16
  • 17. © 2019 Montgomery One Yocto Open Embedded Linux
  • 18. © 2019 Montgomery One Build a Yocto Linux System for Your Target Board • Choose a board with a Yocto BSP and cameras with recipes for Yocto • Test the camera drivers provided in your BSP well - You will likely have to create recipes and/or a new V4L2 driver for your camera - An example of a working driver from your camera vendor is a minimum requirement • Install Yocto (Pyro, Rocko or Sumo) on Ubuntu and build a bootable OS: repo init -u https://github.com/Freescale/fsl-community-bsp-platform -b pyro repo sync MACHINE=wandboard DISTRO=fslc-x11 source setup-environment build bitbake fsl-image-machine-test-full (or, core-image-basic, fsl-image-x11-qt5, etc.) • Build and install cross-development toolchain to build your app and any additional packages: bitbake fsl-image-machine-test-full -c populate_sdk ./build/tmp/deploy/sdk/fslc-x11-glibc-x86_64-fsl-image-multimedia-armv7at2hf-neon-toolchain-2.3.4.sh bitbake -s 18
  • 19. © 2019 Montgomery One Integrating OpenCV with Yocto Linux
  • 20. © 2019 Montgomery One An Example - Vision Components for Lightwing 20
  • 21. © 2019 Montgomery One Build and Run OpenCV Samples for Your Target Board • Add packages for OpenCV, X11, gstreamer, etc. to Yocto's config file: buildconflocal.conf CORE_IMAGE_EXTRA_INSTALL += "opencv x11 gstreamer" • Build and test the OpenCV 3.2 samples using Yocto toolchain, sysroot and CMake in your Yocto tree (mostly the same as on Ubuntu): source /opt/fslc-x11/2.3.4/environment-setup-arm7at2hf-neon-fslc-linux-gnueabi cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. make • Running the sample apps on your target requires initialization of an X window (X11): export DISPLAY=:0.0 xhost +SI:localuser:root cd /usr/share/OpenCV/samples/bin ./cpp-example-videocapture_basic 21
  • 22. © 2019 Montgomery One VideoCapture Class for Linux • The camera interface for OpenCV • About 40 implementations are provided for all major OS platforms • Three implementations are provided for Linux: cap_v4l.cpp - Original, for obsolete V4L version 1 cap_libv4l.cpp – Updated replacement for V4L2, with many patches cap_gstreamer.cpp – Optional extension convert formats and accepts GStreamer pipeline syntax: cpp-example-videocapture_basic 'videotestsrc ! videoconvert ! appsink' • Required some debugging to work on newer (4.x) Linux kernels - If V4L2 fails to initialize, it then tries V4L (version 1), which produces very confusing error messages. - Removed the xioctl() call macro because it was failing when calling to inquire the video format (VIDIOC_S_FMT) • Some improvements are available in OpenCV 4.1.0 for the Android Media NDK 22
  • 23. © 2019 Montgomery One What Else Can (and Did) Go Wrong? • OmniVision 5640 camera discontinued –Was a popular camera supported by the FSL Community BSP –Use new OV5645 driver from Rocko version instead –Only older versions of Yocto (Pyro) actually work on most i.MX6/8 boards • Yocto only supports OpenCV 3.2 because of CMake compatibility issues –CMake installed by Yocto will not build OpenCV 3.4 • OpenCV samples require X Windows on Linux –Either use X11 or eliminate the use of the High-GUI module in samples • OpenCV VideoCapture class requires GStreamer on Linux –Unnecessarily complex and broken on the i.MX6/8 platform –Fixed the bugs in V4L2 implementation, so it works without GStreamer 23
  • 24. © 2019 Montgomery One Working Around Component Limitations • OpenCV (VideoCapture class) requires the antiquated 24 bit BGR pixel format ! –Many cameras only provide 16 bit RGB 565, YUV or RAW formats –RAW format is 10 bit RGB (Bayer), but requires software conversion (very slow) • Official solution is to use gstreamer (with an appsink) element to convert YUV to BGR: videocapture_starter 'imxv4l2videosrc ! videoconvert ! appsink' - Can be accelerated by the IPU on i.MX6/8 by using NXP's plugins for gstreamer - libgstapp.so must be installed manually for this to work due to a bug in some builds for i.MX6/8 • Other ways to adapt the V4L2 VideoCapture class and get better performance: –Use the i.MX6/8 IPU without GStreamer. Red and Blue are swapped, but for many CV apps, that is fine –Use luminance data directly (dropping color data), without conversion to RGB • i.MX6 IPU will not scale video beyond 1024 x 1024 pixels (fixed on the i.MX8) • Lightwing solution - Use the GPU (OpenGL ES) to convert and scale video, instead of the IPU or GStreamer - Basic motion tracking algorithm is done in shader code, instead of OpenCV 24
  • 25. © 2019 Montgomery One Lightwing Motion Tracking Demo
  • 26. © 2019 Montgomery One Lightwing Motion Tracking 3D GUI Demo Motion tracking on the NXP i.MX6 GPU enables interactive control of 3D assets for mixed-reality video walls, without VR headsets or hand controllers 26
  • 27. © 2019 Montgomery One Conclusions
  • 28. © 2019 Montgomery One Lessons Learned • Start on a desktop PC with Ubuntu and the OpenCV samples - Develop your vision algorithms there, first • Use Yocto Open Embedded Linux to build your custom platform • Use the same open source libraries on desktop and target systems - Hacking OpenCV's VideoCapture class will likely be required • Understand which vision components you actually need and why • Select cameras carefully, considering software support - You really need a good V4L2 driver with Yocto recipes - Use a MIPI camera if possible, instead of USB • Explore the acceleration options for your SoC (GPU, IPU, NEON, etc) - Acceleration is required for most CV applications of camera video on ARM 28
  • 29. © 2019 Montgomery One Resources 29 OpenCV Installation Tutorial https://www.docs.opencv.org/2.4.13/doc/tutorials/intr oduction/linux_install/linux_install.html#linux- installation Yocto Open Embedded Linux https://www.yoctoproject.org/ GStreamer Documentation https://gstreamer.freedesktop.org/documentation/ V4L2 Documentation https://www.kernel.org/doc/html/v4.9/media/uapi/v4l /v4l2.html Khronos OpenGL ES, OpenCL and OpenVX Documentation https://www.khronos.org/ Lightwing Open Mixed-Reality Platform https://montgomery1.com/lightwing/ NXP i.MX6/8 Development Boards https://www.wandboard.org/ OpenCV Status on Github https://github.com/opencv/opencv/wiki/ChangeLog
  • 30. © 2019 Montgomery One Appendix
  • 31. © 2019 Montgomery One OpenCV C++ Example - Edge Detection on Camera Video int iEdgeThreshSobel = 1; Mat mImageFrame, mImageGray, mImageGrayBlur, mImageEdgeMask, mImageEdgeResult; const char* WindowName = "Canny edge map with Sobel gradient"; static void onTrackbar(int, void*) { cvtColor(mImageFrame, mImageGray, COLOR_BGR2GRAY); // Create blurred gray scale image for edge detection. blur(mImageGray, mImageGrayBlur, Size(3, 3)); Canny(mImageGrayBlur, mImageEdgeMask, iEdgeThreshSobel, iEdgeThreshSobel * 3, 3); // Canny detector with sobel filter. mImageEdgeResult = Scalar::all(0); // Clear to black. mImageFrame.copyTo(mImageEdgeResult, mImageEdgeMask); imshow(WindowName, mImageEdgeResult); // Display image frame in window. } int main(int argc, char** argv) { VideoCapture capture; capture.open(0); // Open camera device through V4L2. namedWindow(WindowName, WINDOW_KEEPRATIO); // Create window and slider control. createTrackbar("Canny threshold Sobel", WindowName, &iEdgeThreshSobel, 100, onTrackbar); char key = 0; while (key != ‘q’) // Capture frames from the camera and display them. { capture >> mImageFrame; // Capture another image frame from camera. if (mImageFrame.empty()) break; onTrackbar(0, 0); // Show the image. key = (char)waitKey(30); // Wait 30 milliseconds for a key press. } return 0; } 31
  • 32. © 2019 Montgomery One 32 Lightwing – Open Mixed-Reality Video Wall Platform • Build custom digital signs and video walls with interactive 3D content • Camera motion tracking controls 3D assets without VR headsets or hand controllers • Supports both touch screens and camera motion tracking input • Multipanel video wall dimensions of any size for public spaces • Built-in 3D animations, fonts, effects, audio, video, images and web RSS feeds • GPU and IPU acceleration of camera video on the NXP i.MX6/8 series SoCs • Scriptable, browserless architecture built on open tools for Windows and Linux https://montgomery1.com/lightwing/
  • 33. © 2019 Montgomery One Lightwing on Linux verses Android and Windows 33
  • 34. © 2019 Montgomery One About Clay D. Montgomery • 30+ Years of Embedded Multimedia Software Development • C/C++, OpenGL 3D, Audio/Video, Linux, Windows and Android • Previously worked at STB (3Dfx), VLSI (NXP), Nokia, TI and AMX (Harmon) • Authored on Embedded OpenGL ES for Intel Developer Zone, TI, Montgomery One • Freelance Embedded Linux Developer since 2010 • Now working on Open Embedded Linux (Yocto) on ARM almost Exclusively • Active in Tech Start Up Community in Texas • Created Lightwing Mixed-Reality Engine for Interactive Digital Signage, Video Walls and Touch-Kiosks on NXP i.MX6/8 SoCs • Currently adding CV Object Detection and Motion Tracking Features to Lightwing 34