1. 程式人生 > >Ubuntu16.04環境下通過Cmake管理Opencv專案

Ubuntu16.04環境下通過Cmake管理Opencv專案

Ubuntu16.04環境下通過Cmake管理Opencv專案

1、新建qt cmake工程

New Project -> Non-Qt Project -> Plain C++ Application

qt
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