Opencv install any version on nvidia jetson xavier, tx2

Why write this

There are too many online tutorials, is nothing less than to compile manually or by a script to automatically compile written. Many tutorial, install the dependencies that part of the operation either too complicated, too messy, or is incomplete installation, resulting in compilation error. So I wanted to write a simple and effective method of installation, and let everyone know what each part is used.

Preconditions

Jetpack4.2 or later installed, usually already comes with opencv, but because of the opencv function is not comprehensive, we need to remove and install line version of the
delete command:

 sudo apt-get purge libopencv*

By installing script

Two options
① a key script operations:

 git clone https://github.com/jetsonhacks/buildOpenCVXavier.git
 cd buildOpenCVXavier
 git checkout v1.0
./buildOpenCV.sh

② modify the script to install any version opencv

 git clone https://github.com/jetsonhacks/buildOpenCVXavier.git
 cd buildOpenCVXavier

After entering buildOpenCVXavier folder, open buildOpenCV.sh script with any text editor:
Select version

OPENCV_VERSION=3.4.3

:( select the corresponding device by removing / reservations the # comment, of course, with each device ARCH_BIN one correspondence)

# Jetson AGX Xavier
ARCH_BIN=7.2
# Jetson TX2
#ARCH_BIN=6.2
# Jetson TX1
# ARCH_BIN=5.3
INSTALL_DIR=/usr/local

ARCH_BIN actually "GPU Compute Capability" of the company's number of NVIDIA graphics cards, other cards numbers can be checked from the following website

https://developer.nvidia.com/cuda-gpus

Save the script and run

 git checkout v1.0
./buildOpenCV.sh

After installation delete the installation package

./removeOpenCVSources.sh

Self-installation (to opencv3 latest version 3.4.9, for example)

This approach is very cumbersome, and less likely to accidentally install something, lead to re-install.

In fact, we have to do is download opencv source code, and then use CMAKE compiled, eventually produce opencv library

First install the dependencies, indispensable!

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

2, download opencv sourse code, enter the folder

cd ~/opencv
mkdir build
cd build

3, in order to facilitate the management and viewing, we compiled opencv by the new script:
sudo gedit my_cmake.sh
open my_cmake.sh, paste

cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_PNG=OFF \
    -DBUILD_TIFF=OFF \
    -DBUILD_TBB=OFF \
    -DBUILD_JPEG=OFF \
    -DBUILD_JASPER=OFF \
    -DBUILD_ZLIB=OFF \
    -DBUILD_EXAMPLES=ON \
    -DBUILD_opencv_java=OFF \
    -DBUILD_opencv_python2=ON \
    -DBUILD_opencv_python3=ON \
    -DENABLE_PRECOMPILED_HEADERS=OFF \
    -DWITH_OPENCL=OFF \
    -DWITH_OPENMP=OFF \
    -DWITH_FFMPEG=ON \
    -DWITH_GSTREAMER=ON \
    -DWITH_GSTREAMER_0_10=OFF \
    -DWITH_CUDA=ON \
    -DWITH_GTK=ON \
    -DWITH_VTK=OFF \
    -DWITH_TBB=ON \
    -DWITH_1394=OFF \
    -DWITH_OPENEXR=OFF \
    -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
    -DCUDA_ARCH_BIN=7.2 \    #tx2是6.2
    -DCUDA_ARCH_PTX="" \
    -DINSTALL_C_EXAMPLES=ON \
    -DINSTALL_TESTS=ON \
    -DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \  #CONTRIB文件的位置

Such as on off switch, opens the corresponding function

Run the script: sudo ./my_cmake.sh
4, compiled

make -j8
sudo make install

5 Add the environment variable (the purpose of the future, no matter what path, can use opencv library)

cd ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/
Released five original articles · won praise 1 · views 236

Guess you like

Origin blog.csdn.net/CCCCXXXXGGGG/article/details/104232719