#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
string name = "我的";
int main()
{
VideoCapture capture; //宣告視頻讀入類
capture.open(0); //從攝像頭讀入視頻 0表示從攝像頭讀入
if (!capture.isOpened()) //先判斷是否打開攝像頭
{
cout << "can not open";
cin.get();
return -1;
}
namedWindow(name);
while (1) {
Mat cap; //定義一個Mat變數,用于存盤每一幀的影像
capture >> cap; //讀取當前幀
if (!cap.empty()) //判斷當前幀是否捕捉成功 **這步很重要
imshow(name, cap); //若當前幀捕捉成功,顯示
else
cout << "can not ";
waitKey(30); //延時30毫秒
}
return 0;
}

uj5u.com熱心網友回復:
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv) {
cvNamedWindow("OpenCVideoWindows");
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while(1) {
frame = cvQueryFrame(capture);
if(!frame) break;
cvShowImage("win", frame);
char c = cvWaitKey(50);
if(c==27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("OpenCVideoWindows");
return 0;
}
uj5u.com熱心網友回復:
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv) {
cvNamedWindow("OpenCVideoWindows");
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while(1) {
frame = cvQueryFrame(capture);
if(!frame) break;
cvShowImage("OpenCVideoWindows", frame);
char c = cvWaitKey(30);
if(c==27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("OpenCVideoWindows");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/66025.html
上一篇:UE4安裝問題
