33,311
社区成员
发帖
与我相关
我的任务
分享
#include"highgui.h"
int main(int argc, char** argv)
{
cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(-1);
IplImage* frame;
while (1)
{
frame = cvQueryFrame(capture);
if(!frame)
{
break;
}
cvShowImage("Example2", frame);
char c = cvWaitKey(33);
if(c==27)
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example2");
system("pause");
}
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;
capture >> cap;
if (!cap.empty()) //判断当前帧是否捕捉成功 **这步很重要
imshow(name, cap);
else
{
cout << "can not open";
continue;
}
if(waitKey(3) == 'q')
break; //延时30毫秒
}
return 0;
}