1,222
社区成员




#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;
}
#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;
}
#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;
}