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 并安装我用的版本是2.1 安装后使用灶山CMake 进行了编译配置,具体的方法见OpenCV的官方网站。
第二步:下载QT
这里我下载了三个软件:QTCreator qt-win-opensource-4.7.3-vs2008.exe qt-vs-addin-1.1.9.exe 具体的方法我也不说了,Windows下的QT配置还是很Easy的。
第三步:在带辩袭QTCreator下使用OpenCV
其实也是很简单的,在你的Pro文件下添加一些语句就OK了。我的添加语句如下:
INCLUDEPATH += D:\OpenCV2.1\VS2008\include\opencv
CONFIG(release,debug|release){
LIBS += D:\OpenCV2.1\VS2008\lib\cv210.lib \
D:\OpenCV2.1\VS2008\蠢兄lib\cvaux210.lib \
D:\OpenCV2.1\VS2008\lib\cxcore210.lib \
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)