Skip to content

Instantly share code, notes, and snippets.

@taka-wang
Created October 16, 2019 02:33
Show Gist options
  • Save taka-wang/d66111d011c80a33631f5f6a7af6f832 to your computer and use it in GitHub Desktop.
Save taka-wang/d66111d011c80a33631f5f6a7af6f832 to your computer and use it in GitHub Desktop.
Build openCV 4.0 debian package on Jetson Nano
#!/bin/bash
#
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <Install Folder>"
exit
fi
folder="$1"
user="nvidia"
passwd="nvidia"
echo "** Remove OpenCV3.3 first"
sudo sudo apt-get purge *libopencv*
echo "** Install requirement"
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev python3.6-dev python-dev python-numpy python3-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl
sudo apt-get update
echo "** Download opencv-4.0.0"
cd $folder
curl -L https://github.com/opencv/opencv/archive/4.0.0.zip -o opencv-4.0.0.zip
curl -L https://github.com/opencv/opencv_contrib/archive/4.0.0.zip -o opencv_contrib-4.0.0.zip
unzip opencv-4.0.0.zip
unzip opencv_contrib-4.0.0.zip
cd opencv-4.0.0/
echo "** Building..."
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CPACK_BINARY_DEB=ON -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.0/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D WITH_CUBLAS=ON -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j3
# manual
#Edit the CPackConfig.cmake file in your build directory
# 1. to comment out the line set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "TRUE") -- borrowed from this Mozilla Services lua_sandbox resolved issue.
# 2. to replace all occurrences of unknown (version) to 4.1.0.
#. Edit the CPackSourceConfig.cmake to replace all occurrences of unknown (version) to 4.1.0.

#. make package -j3
# ref: https://github.com/jetsonhacks/buildOpenCVXavier
# ref: https://askubuntu.com/questions/1143060/opencv-compiles-correctly-but-fails-during-deb-packaging/1156304
# check content: dpkg -c Openxxxx-pyhon.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment