SDKManager自动安装的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 包)
git clone --branch "4.4.0" https://github.com/opencv/opencv.git
git clone --branch "4.4.0" https://github.com/opencv/opencv_contrib.git
https://github.com/opencv/opencv/releases
https://github.com/opencv/opencv_contrib/releases
- 编译安装问题
问题1、buildOpenCV.sh 脚本默认支持CUDA且指定了OpenCV版本,如需其他版本则要修改buildOpenCV.sh的一些参数:
a. 修改版本:OPENCV_VERSION=4.1.1 -> 3.4.11
b. 修改CUDA不支持: -D WITH_CUDA=ON -> OFF
c. 修改ARCH BIN版本:-D CUDA_ARCH_BIN=${ARCH_BIN} -> 不同平台不同,需根据平台进行设置
问题2、 编译opencv和openc_contrib 提示缺少boostdesc_bgm.i文件出错
错误提示:
opencv_contrib/modules/xfeatures2d/src/boostdesc.cpp:673:20: fatal error: boostdesc_bgm.i: No such file or directory
解决方法:
由于采用的是源码编译,所以可以查看 build 文件夹下的日志文件 CMakeDownloadLog.txt,在日志文件CMakeDownloadLog.txt 中搜索 boostdesc_bgm.i 关键词 (不是在文件夹中搜索),发现这个文件下载失败了。日志文件里就有这个文件的下载地址,直接复制其下载地址到网页可以看该到文件的源码,直接拷贝源码并生存同名文件,放在 opencv_contrib/modules/xfeatures2d/src/ 路径下即可。
参考连接:
https://github.com/opencv/opencv_contrib/issues/1301
https://blog.csdn.net/u011736771/article/details/85960300
问题3、编译时提示cuda.hpp ,
错误提示:
/home/nvidia/opencv/modules/stitching/include/opencv2/stitching/detail/matchers.hpp:52:12: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory
解决方法一、
编辑matchers.hpp 添加cuda.hpp的绝对路径
$vi /home/nvidia/opencv/modules/stitching/include/opencv2/stitching/detail/matchers.hpp
如下内容:
#ifdef HAVE_OPENCV_XFEATURES2D
//#include "opencv2/xfeatures2d/cuda.hpp"
#include "/home/nvidia/opencv_contrib/modules/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp"
#endif
解决方法二、
/home/nvidia/opencv/modules/stitching/CMakeLists.txt
添加:
set(STITCHING_CONTRIB_DEPS "opencv_xfeatures2d")
INCLUDE_DIRECTORIES(/home/nvidia/opencv_contrib/modules/xfeatures2d/include)
修改后重新执行Cmake再编译但未解决(不建议采纳)