linux系统cmakelist编译简单opencv读图测试

 

  近日,安装opencv环境,总会使用简单opencv的代码进一步测试是否安装成功,又不想总是写代码cpp与CMakeLists.txt文件。为此,本文将简单记录此demo代码,便于以后测试直接复制。

 

main.cpp 代码如下:

#include<iostream>
//#include "opencv2/core/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/opencv.hpp"

using namespace std;

int main ()
{

  cv::Mat img=cv::imread("./1.jpg");

  cout<<"wh:"<<img.cols<<","<<img.rows<<endl;

//  cv::imshow("window",img);
//  cv::waitKey(0);
  return 0;
}

 

CMakeLists.txt内容如下:

cmake_minimum_required(VERSION 2.6)
project(demo)
add_definitions(-std=c++11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
include_directories(${PROJECT_SOURCE_DIR}/include)

# opencv
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(demo ${PROJECT_SOURCE_DIR}/main.cpp)

target_link_libraries(demo ${OpenCV_LIBS})
add_definitions(-O2 -pthread)

 

编译执行代码:

mkdir build
cd build
cmake ..
make

执行demo
./demo

 

posted @ 2023-06-09 09:52  tangjunjun  阅读(74)  评论(0编辑  收藏  举报
https://rpc.cnblogs.com/metaweblog/tangjunjun