clion的安装可以分别阅读我的另一篇文章。
clion:https://blog.csdn.net/ZT0518/article/details/82747181
在clion中新建一个c++项目后,打开CMakeLists.txt文件,这个文件就在clion界面左侧的project下面。将两句话粘贴进去。
find_package(OpenCV REQUIRED)
target_link_libraries(<project name> -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
)
其中target_link_libraries()中的内容每个人都不太一样。通过在Ubuntu的shell中输入
pkg-config --cflags --libs opencv
可以获得这部分内容,粘贴进去即可。搞定!