Ubuntu16.04环境下通过Cmake管理Opencv项目
1、新建qt cmake工程
New Project -> Non-Qt Project -> Plain C++ Application

2、CMakeLists.txt文件内容修改为如下:
//gh
project(untitled2)
# 添加c++ 11标准支持
set( CMAKE_CXX_FLAGS "-std=c++11" )
# 寻找OpenCV库
find_package( OpenCV REQUIRED )
# 添加头文件
include_directories( ${OpenCV_INCLUDE_DIRS} )
# add sourcce files: *.cpp
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
# 链接OpenCV库
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )
3 、main.cpp内容为:
#include <iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("ubuntu.png",IMREAD_COLOR);
if(image.data == nullptr)
cout<<"files doesn't exist"<<endl;
else
cout<<"success!"<<endl;
cout << "Hello World!" << endl;
imshow("test",image);
waitKey ( 0 ); // 暂停程序,等待一个按键输入
return 0;
}
4、工程项目右键依次执行:
build -> run
5、如果有任何疑问欢迎咨询我
[email protected]