-
Notifications
You must be signed in to change notification settings - Fork 0
Home
OpenCV built with CUDA and OpenGL support is required by default. Script below can be used on NVIDIA Jetson platform to build and install a correct OpenCV version. Alternative is to switch to CPU rendering code-path (much slower), which doesn’t depend on CUDA and OpenGL support in OpenCV:
-
change the following values in
imagebroker.json
(see inline comments there for guidance):-
chains/main/elements/gpuproc/elements/export/type
to"export_to_hostmem"
-
chains/main/elements/exporter/device_id
to"cpu_dev"
-
Tested on L4T R32.7.2.
#!/bin/bash
set -eEo pipefail
shopt -s failglob
trap 'echo "${BASH_SOURCE[0]}{${FUNCNAME[0]}}:${LINENO}: Error: command \`${BASH_COMMAND}\` failed with exit code $?"' ERR
echo "Installing dependencies..."
sudo apt update
sudo apt install -y build-essential cmake pkg-config libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev python-dev python-numpy python3-dev python3-numpy python3-matplotlib libv4l-dev libtbb-dev libjpeg-dev libpng-dev libtiff-dev curl cuda-toolkit-10-2 libgtkglext1-dev nvidia-cudnn8
sudo mkdir -p /usr/lib/aarch64-linux-gnu/gtkglext-1.0/include
echo "Done."
mkdir opencv
cd opencv
echo "Downloading OpenCV and Contribs Modules..."
curl -L https://github.com/opencv/opencv/archive/4.6.0.zip -o opencv.zip
echo "Downloaded opencv-4.6.0.zip."
curl -L https://github.com/opencv/opencv_contrib/archive/4.6.0.zip -o opencv_contrib.zip
echo "Downloaded opencv_contrib-4.6.0.zip."
echo "Unpacking..."
unzip opencv.zip
unzip opencv_contrib.zip
echo "Done."
echo "Configuring modules..."
mkdir build_release
cd build_release
cmake -DWITH_CUDA=ON \
-DWITH_CUDNN=ON \
-DWITH_CUBLAS=ON \
-DCUDA_ARCH_BIN="5.3,6.2,7.2" \
-DCUDA_ARCH_PTX="7.2" \
-DCUDA_FAST_MATH=ON \
-DENABLE_NEON=ON \
-DWITH_OPENGL=ON \
-DWITH_LIBV4L=ON \
-DWITH_GSTREAMER=ON \
-DBUILD_opencv_python2=ON \
-DBUILD_opencv_python3=ON \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_DOCS=OFF \
-DBUILD_EXAMPLES=OFF \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.6.0/modules \
../opencv-4.6.0
echo "Configuration done."
echo "Building..."
make -j8
echo "Installing to /usr/local ..."
sudo cmake -P cmake_install.cmake
echo "OpenCV 4.6.0 has been successfully installed."
Simplest way to use OpenCV on Windows is to download the official release: https://opencv.org/releases/ (tested with version 4.6.0).
The downside of this solution is a lack of CUDA and OpenGL support.
To have OpenCV detected, after unpacking the package, add environment variable named OpenCV_DIR
with value equal to path to build
sub-directory of the unpacked OpenCV package.
Also another path has to be added to PATH environment variable (pay attention to cmake output) or .dll files copied from that directory near the resulting imagebroker.exe
executable (so to build
/bin directory) to be able to run the sample application.