利用Cmake 生成一个opencv读取图像的程序

1、opencv_test.cpp文件

#include 
#include 

using namespace std;
using namespace cv;

int main()
{
    Mat image = imread("E:\\示例图像\\0.jpg");
    if (!image.data)
    {
        cout << "No image data" << endl;
        return -1;
    }

    Mat gray_img;
    cvtColor(image, gray_img, CV_BGR2GRAY);

	imshow("图像", gray_img);

	waitKey(0);
	return 0;
}

2、CMakeLists.txt中内容如下

# This is the root ITK CMakeLists file.
cmake_minimum_required(VERSION 2.8.12)

# This project is designed to be built outside the Insight source tree.
project(opencv_test)

# Find opencv.
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(opencv_test opencv_test.cpp ) #如果代码后缀名为.cxx,此处亦为
target_link_libraries(opencv_test ${OpenCV_LIBS})

3、CMake软件,编译生成。 

 

你可能感兴趣的:(opencv)