头文件更改
默认的头文件引用是
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
但是在ubuntu20中/usr/include
中默认的是opencv4
,他文件夹里面才是opencv2
,需要我们手动拷贝出来才行。
cd /usr/include
sudo ln -s opencv4/opencv2 opencv2
cmakelist更改
需要加上opencv的库
set(OpenCV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/usr/lib/x86_64-linux-gnu/cmake/opencv4")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})target_link_libraries(test ${OpenCV_LIBS})
代码修改
CV_RGB2GRAY
将
cvtColor(src, grayImg, CV_RGB2GRAY);
修改为
cvtColor(src, grayImg, COLOR_RGB2GRAY);
并添加头文件
#include <opencv2/imgproc/types_c.h>
参考文章
如何解决 opencv2/core.hpp: No such file or directory“ for opencv4
ubuntu20.04下opencv版本不兼容问题