常见问题

如何在jetson设备上编译安装opencv

2022-12-16 admin 862

Jetson设备上安装JetPack安装了对应的OpenCV不支持CUDA且版本是固定搭配的,如下方法提供了在Nvidia Jetson 上手动编译OpenCV(支持/不支持CUDA)

1.根据自身需求下载安装OpenCV源码编译按照脚本(Github Jetsonhacks)
https://github.com/JetsonHacksNano/buildOpenCV (Nano 安装)
https://github.com/jetsonhacks/buildOpenCVXavier (Xavier/NX 安装)

OpenCV 代码包下载:(Git clone如果很慢,可以在releases中下载tar.gz 包)

https://github.com/opencv/opencv/releases
https://github.com/opencv/opencv_contrib/releases


卸载原有opencv相关内容

sudo apt-get purge *libopencv*


新建脚本

vim buildOpenCV.sh

#! /bin/bash

echo "** Remove OpenCV4.1 first"

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.1.1"

cd $folder

curl -L https://github.com/opencv/opencv/archive/4.1.1.zip -o opencv-4.1.1.zip

curl -L https://github.com/opencv/opencv_contrib/archive/4.1.1.zip -o opencv_contrib-4.1.1.zip

unzip opencv-4.1.1.zip 

unzip opencv_contrib-4.1.1.zip 

cd opencv-4.1.1/


echo "** Building..."

mkdir release

cd release/

cmake -D WITH_CUDA=ON -D ENABLE_PRECOMPILED_HEADERS=OFF  -D CUDA_ARCH_BIN="7.2" -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.1/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

make -j6

sudo make install


echo "** Install opencv-4.1.1 successfully"

echo "** Bye :)"

编译安装

./buildOpenCV.sh

等待安装完成即可

首页
产品
案例
联系