【OpenCV】使用gcc和CMake编译的OpenCV程序

2024-01-08 22:39:23

编写程序
DisplayImage.cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }
    Mat image;
    image = imread( argv[1], IMREAD_COLOR );
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);
    waitKey(0);
    return 0;
}

创建CMake文件
CMakeLists.txt file

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

生成可执行文件

cd <DisplayImage_directory>
cmake .
make

执行

./DisplayImage lena.jpg

https://docs.opencv.org/4.x/db/df5/tutorial_linux_gcc_cmake.html

文章来源:https://blog.csdn.net/weixin_44378835/article/details/135463556
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。