Ubuntu在CMakeLists.txt中指定OpenCV版本的参考方法
文章目录
- 写在前面
- 一、问题描述
- 二、解决方法
- 参考链接
写在前面
自己的测试环境:
Ubuntu20.04, ROS-Noetic, OpenCV-4.2.0, OpenCV-4.5.4。
一、问题描述
编译运行OpenCV遇到如下报错:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.4) /home/wong/third_party/opencv-4.5.4/modules/core/src/matrix.cpp:250: error: (-215:Assertion failed) s >= 0 in function 'setSize'
二、解决方法
出现上述报错的原因是 OpenCV 库版本不兼容的问题,因此需要在CMakeLists.txt
中指定 OpenCV 4.2.0 的路径:
set(OpenCV_DIR /usr/lib/x86_64-linux-gnu/cmake/opencv4/)
find_package(OpenCV REQUIRED)
message("OpenCV_DIR: ${OpenCV_DIR}")
message("OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}")
message("OpenCV version: ${OpenCV_VERSION}")
# 打印结果
# OpenCV_DIR: /usr/lib/x86_64-linux-gnu/cmake/opencv4/
# OpenCV_INCLUDE_DIRS: /usr/include/opencv4
# OpenCV version: 4.2.0
然后重新编译,重新运行即可。
参考链接
[1] wonghome. OpenCV报错遇到 No rule to make target ‘/usr/lib/x86_64-linux-gnu/libopencv_dpm.s‘ 的参考解决方法 [EB/OL]. https://blog.csdn.net/qq_39779233/article/details/142202706, 2024-09-13/2024-09-13.