Birds Eye View Building and Installation Guide

From RidgeRun Developer Connection
< Birds Eye View‎ | Getting the Code
Revision as of 09:17, 25 May 2020 by Spalli (talk | contribs) (Building OpenCV with GStreamer support)
Jump to: navigation, search




Previous: Getting the Code/How to get the code Index Next: Getting_Started





Birds eye view library and examples installation

System Dependencies

Birds eye view has the following system dependencies:

  • meson >= 0.50
  • ninja
  • boost
  • opencv 3.1.0 (or higher version)

Meson, Ninja and Boost can be installed using the next command line (tested on Ubuntu 18.04.3):

sudo apt install meson ninja-build libboost-dev

Building OpenCV with GStreamer support



1. Install previous GStreamer dependencies

sudo apt-get install gstreamer1.0*
sudo apt install ubuntu-restricted-extras
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

2. Install compiler and building dependencies

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
pip3 install numpy
pip3 install imutils

3. Obtain source code from Github

git clone https://github.com/opencv/opencv.git
cd opencv/
git checkout 4.1.0
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib/
git checkout 4.1.0

*Disclaimer: On newer relases of OpenCV, some algorithms are proprietary and not for commercial use. This is a research project, therefore be informed that you can't use the line -D OPENCV_ENABLE_NONFREE=ON for commercial purposes.

4. Configure with required flags

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=$(which python3) \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D WITH_GSTREAMER=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules/ \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_GENERATE_PKGCONFIG=YES \
-D BUILD_EXAMPLES=ON ..

5. Check configuration log

✔ Verify if it has Python 3: section and all interpreter and path are right. (If they aren’t there, check the numpy package)

✔ Check the GStreamer section. (If it does not indicate YES, go check GStreamer lib package)

Opencv configure.png

6. Building

It will last some time. Please be patient.

sudo make -j4

7. Install the package

sudo make install
sudo ldconfig

Building OpenCV with GStreamer and CUDA support

If you are using a NVIDIA Jetson device, you can follow the instructions on the next wiki:

in order to properly configure, compile and install OpenCV, in a native way; it is worth to mention that this is not a cross compilation.

Build library and examples

git clone https://gitlab.com/RidgeRun/rnd/bird-eye-view.git
cd bird-eye-view
mkdir build
cd build
meson ..
ninja


The library also supports several meson options to:

1. Build the library with OpenCV CUDA support. This boost library performance by using CUDA to compute heavy transformation methods on GPU.

meson -Dopencv-cuda=enabled ..

2. Build the library with profiling support. Please refer to Birds_Eye_View/Performance/Profiling to install dependencies

meson -Dprofiling=enabled ..

3. Build the library with documentation

meson -Ddoc=enabled ..

4. Build only the documentation

meson -Ddocs-only=enabled ..

Now you will find the example files:

Troubleshooting

Meson version

On Ubuntu 18.04.1 LTS, the Meson install usually has a 0.45.1 version, however the project requires at least 0.50. A newer version of Meson can be installed using Pip in the following way:

sudo -H pip3 install meson

This usually installs the latest version of Meson available for your system. However, this is just accessible from the Python environment. In order to make it system wide do:

sudo touch /usr/local/bin/meson
sudo chmod +x /usr/local/bin/meson


and add the following on it:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from mesonbuild.mesonmain import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

With this, you can follow the steps to build without further issues.

Patch to support 4 USB cameras

When using more than 2 USB cameras it may be necessary to jump over the bandwidth restriction imposed by the generic usb driver, which is not capable of requesting the correct image size therefore requests the max size. It is necessary to recompile the driver after applying the required patch.

*Disclaimer: This patch is a 'hack' to trick the verification process when asking for resources to initialize the cameras. Needed to allow the use of 4 simultaneous usb cameras, however it was just used for testing purposes and may not be stable.

1. Download the kernel source

sudo apt-get source linux-image-unsigned-$(uname -r)
cd $(uname -r)/drivers/media/usb/uvc/
mkdir patches
cd patches

If you get this error:

E: You must put some 'source' URIs in your sources.list

Run the following commands:

sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt-get update


2. Create the patch file

vim 001-uvc-add-compressed-video-bandwidth-parameter.patch
Index: ./uvc_video.c
===================================================================
--- ./uvc_video.c
+++ ./uvc_video.c
@@ -161,6 +161,11 @@ static void uvc_fixup_video_ctrl(struct
 
                ctrl->dwMaxPayloadTransferSize = bandwidth;
        }
+
+       if (format->flags & UVC_FMT_FLAG_COMPRESSED) {
+         ctrl->dwMaxPayloadTransferSize = 0x300;
+       }
+
 }
 
 static int uvc_get_video_ctrl(struct uvc_streaming *stream,

3. Setup the series file:

echo 001-uvc-add-compressed-video-bandwidth-parameter.patch > series
cd ..

4. Apply the patch:

quilt push

5. Compile and reload the kernel module:

sudo make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
sudo rmmod uvcvideo
sudo insmod uvcvideo.ko



Previous: Getting the Code/How to get the code Index Next: Getting_Started