[CMakeList][转载]利用CmakeList构建opencv程序

[CMakeList][转载]利用CmakeList构建opencv程序,第1张

打开VS2019创建CMake项目

CmakeList.txt

# requirement of cmake version

cmake_minimum_required(VERSION 3.10)

set(Project_Name OpencvTest)

set(SRC_LIST OpencvTest.cpp)

set(OpenCV_LIB "D:\\lufiles\\opencv310\\build\\x64\\vc14\\lib")

set(Opencv_Include "D:\\lufiles\\opencv310\\build\\include")

# set(OpenCV_LIB "D:\\lufiles\\opencv310\\build\\")  # 这两个目录中都包含 OpenCVConfig.cmake 文件,两种设置都可以构建项目

PROJECT(${Project_Name})

include_directories(${Opencv_Include})

link_directories(${OpenCV_LIB})

add_executable(${Project_Name} ${SRC_LIST})

target_link_libraries(${Project_Name} opencv_world310d.lib)

OpencvTest.cpp

#include <opencv2/core.hpp>

#include <opencv2/简尺videoio.hpp>

#include <opencv2/highgui.hpp>

#include <iostream>

#include <stdio.h>

using namespace cv

using namespace std

int main(int, char**)

{

    Mat frame

    //--- INITIALIZE VIDEOCAPTURE

    VideoCapture cap

    // open the default camera using default API

    // cap.open(0)

    // OR advance usage: select any API backend

    int deviceID = 0             // 0 = open default camera

    int apiID = cv::CAP_ANY      // 0 = autodetect default API

    // open selected camera using selected API

    cap.open(deviceID + apiID)

    /拦埋高/ check if we succeeded

    if (!cap.isOpened()) {

        cerr <<"ERROR! Unable to open camera\n"

        return -1

    }

    //--- GRAB AND WRITE LOOP

    cout <<"Start grabbing" <<endl

        <<"Press any key to terminate" <<endl

    for ()

    {

        // wait for a new frame from camera and store it into 'frame'

        cap.read(frame)

        // check if we succeeded

        if (frame.empty()) {

            cerr <<"ERROR! blank frame grabbed\n"

           液漏 break

        }

        // show live and wait for a key with timeout long enough to show images

        imshow("Live", frame)

        if (waitKey(5) >= 0)

            break

    }

    // the camera will be deinitialized automatically in VideoCapture destructor

    return 0

}

opencv源誉祥码就在你的opencv安李埋装庆扰搏目录下啊,默认programfile

里opencv版本号文件夹。好好找一下

我记得有纯C代码的,不过注意下调用方式等和VS上有很大区别。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12234857.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存