1. 下载 opencv 和对应版本的 opencv_contrib 库
- opencv:https://opencv.org/releases/
- opencv_contrib:https://github.com/opencv/opencv_contrib
2. 使用 cmake 编译 opencv 和指定 opencv_contrib 库
# 在 opencv 源码文件夹下创建并进入 build 文件夹
cd /home/usr/opencv-4.7.0 # 请切换为你的 opencv 源码路径
mkdir build && cd buildcmake -DOPENCV_EXTRA_MODULES_PATH=/home/usr/opencv_contrib-4.x/modules/aruco -DBUILD_opencv_legacy=OFF /home/usr/opencv-4.7.0make install
其中 -DOPENCV_EXTRA_MODULES_PATH
参数用于指定具体opencv_contrib库路径。如果需要安装多个指定 opencv_contrib 库,则用双引号和分号来提供多个 opencv_contrib 库路径,如:
cmake -DOPENCV_EXTRA_MODULES_PATH="/home/usr/opencv_contrib-4.x/modules/xfeatures2d;/home/usr/opencv_contrib-4.x/modules/aruco" -DBUILD_opencv_legacy=OFF /home/usr/opencv-4.7.0