配置cpp环境

编译opencv

先要提前安装依赖库

1
2
3
4
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get install build-essential   
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

在源码文件夹中,新建build目录,进到build目录运行cmake

1
2
3
4
mkdir build
cd build    
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_OPENGL=ON ..
make    

参考:https://docs.opencv.org/3.4.1/d7/d9f/tutorial_linux_install.html

Clion中添加依赖

  1. 在当前工程下新建一个cmake文件夹,将FindOpenCV.cmake文件拷贝进去
  2. 修改cmake文件指向自己的opencv所在的库路径

cmake配置文件

1
2
3
4
5
6
7
8
9
cmake_minimum_required(VERSION 3.14)
project(study_opencv_cpp)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(OpenCV REQUIRED)

add_executable(study_opencv_cpp02 02-图片剪切.cpp)
target_link_libraries(study_opencv_cpp02 ${OpenCV_LIBS})