Clion中配置OpenCV环境(Ubuntu)

一. 在Ubuntu环境下安装破解Clion

  • 请看我之前的教程Clion安装与破解教程(Linux)

二. 在Ubuntu环境下安装OpenCV(c++版本)

  • 请看我之前的教程ubuntu 安装 opencv 的 c++版本

三. Clion的OpenCV环境配置

1. 打开Clion,新建一个工程,工程名为XXX

2. 打开工程的CMakeList,在末尾添加以下代码

find_package(OpenCV REQUIRED)
target_link_libraries(<project name> ${OpenCV_LIBS})
  • 把project name 修改成你工程的名字
  • 在终端输入$ pkg-config --cflags --libs opencv, 用返回的内容替代${OpenCV_LIBS}即可,下面是我修改的示例:
target_link_libraries(hello_world -I/usr/include/opencv -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_video -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_viz -lopencv_surface_matching -lopencv_text -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core)

3. Clion的测试代码

#include
using namespace cv;
int main() {
    Mat image = imread("../test.jpg"); 
    imshow("mytest",image);
    waitKey(0);
    return 0;
}
  • 命名为test.jpg,放在与main.cpp同一路径下
  • Clion下的图片相对路径需要写作 ../相对路径

每天进步一点,欢迎技术交流!!!
Clion中配置OpenCV环境(Ubuntu)_第1张图片

你可能感兴趣的:(基础技术,Clion,OpenCV,Ubuntu)