24,854
社区成员
发帖
与我相关
我的任务
分享
#include "highgui.h"
#include "cv.h"
#include <iostream>
using namespace std;
int main ()
{
CvCapture *capture=NULL;
capture=cvCreateCameraCapture(0);/*改为0,-1都不能获取摄像头图像。
如果我将这行改为capture=cvCreateFileCapture("filename.avi");可以读取视频文件,
按理说视频和摄像头的读取应该大同小异的,但为什么提取不了?*/
assert (capture!=NULL);
IplImage *img=cvQueryFrame(capture);
CvSize size=cvSize(img->width,img->height);
double fps=0;
fps=cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);
cout<<fps<<':'<<size.width<<':'<<size.height<<endl;//显示fps,宽和高
system("pause");
cvNamedWindow("img");
int i=0;
while (cvQueryFrame(capture)!=NULL){
cvMoveWindow("img",i++,i++);/*为了判断我的循环是否在运行*/
cvShowImage("img",img);
char c=cvWaitKey(1000/fps);
if (c==27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("img");
return (0);
}