编译全流程
-
解压
tar xvf opencv-4.5.4.tar.gz
cd opencv-4.5.4
- 交叉编译
//此处是配置交叉编译工具链路径
export COMPILE_PREFIX=/opt/rk3308h32
export CC=${COMPILE_PREFIX}/bin/arm-buildroot-linux-gnueabihf-gcc
export CXX=${COMPILE_PREFIX}/bin/arm-buildroot-linux-gnueabihf-g++
mkdir build
cd build
//此处我配置了静态编译
//另外关闭了一些不需要的模块。
//这里需要注意,有些模块你打开了,可是如果它依赖的模块被关闭了,也是会被设置为关闭的,详情看后面
cmake .. \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_opencv_gpu=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_opencv_apps=OFF \
-D BUILD_opencv_highgui=OFF \
-D BUILD_opencv_imgcodecs=OFF \
-D BUILD_opencv_calib3d=ON \
-D BUILD_opencv_contrib=OFF \
-D BUILD_opencv_dnn=OFF \
-D BUILD_opencv_gapi=OFF \
-D BUILD_opencv_features2d=ON \
-D BUILD_opencv_flann=ON \
-D BUILD_opencv_gpu=OFF \
-D BUILD_opencv_ml=OFF \
-D BUILD_opencv_nonfree=OFF \
-D BUILD_opencv_objdetect=OFF \
-D BUILD_opencv_photo=OFF \
-D BUILD_opencv_stitching=OFF \
-D BUILD_opencv_superres=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_opencv_video=OFF \
-D BUILD_opencv_videoio=OFF \
-D BUILD_opencv_videostab=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=`pwd`/output \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=arm \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX
//开始编译
make -j8
make install
关于模块编译开关
例如我关闭了其它模块,打开了BUILD_opencv_calib3d。执行上面命令后打印会显示如下,说明calib3d由于依赖关系还是被关闭了
-- OpenCV modules:
-- To be built: core imgproc
-- Disabled: dnn features2d flann gapi highgui imgcodecs ml objdetect photo stitching video videoio world
-- Disabled by dependency: calib3d
我们可以进入opencv-4.5.4/modules/calib3d/CMakeLists.txt看看
ocv_define_module(calib3d opencv_imgproc opencv_features2d opencv_flann ${debug_modules}
WRAP java objc python js
)
这里说明了calib3d依赖这些模块,所以我们需要打开opencv_imgproc opencv_features2d opencv_flann才能编译calib3d。