新手 关于opencv摄像头捕捉
版本是vs2008+opencv2.4.5配置都是好的下面的代码是捕捉摄像头视频的运行后大概能捕捉到两秒然后就出现“test.exe停止工作”新手求指教#include"...
版本是 vs2008+opencv2.4.5 配置都是好的 下面的代码是捕捉摄像头视频的 运行后大概能捕捉到两秒 然后就出现 “test.exe 停止工作” 新手求指教
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
CvCapture* capture = cvCaptureFromCAM(0);
CvVideoWriter* writer = 0;
int isColor = 1;
int fps = 25;
int frameW = 640;
int frameH = 480;
writer = cvCreateVideoWriter("out.avi", CV_FOURCC('P', 'I', 'M', '1'), fps, cvSize(frameW, frameH), isColor);
IplImage* img = 0;
int nFrames = 50;
for(int i = 0; i < nFrames; i ++)
{
cvGrabFrame(capture);
img = cvRetrieveFrame(capture);
cvWriteFrame(writer, img);
}
cvNamedWindow("myWin", CV_WINDOW_AUTOSIZE);
cvShowImage("myWin", img);
cvWaitKey(20);
cvReleaseVideoWriter(&writer);
cvReleaseCapture(&capture);
cvReleaseImage(&img);
cvDestroyWindow("myWin");
return 0;
} 展开
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
CvCapture* capture = cvCaptureFromCAM(0);
CvVideoWriter* writer = 0;
int isColor = 1;
int fps = 25;
int frameW = 640;
int frameH = 480;
writer = cvCreateVideoWriter("out.avi", CV_FOURCC('P', 'I', 'M', '1'), fps, cvSize(frameW, frameH), isColor);
IplImage* img = 0;
int nFrames = 50;
for(int i = 0; i < nFrames; i ++)
{
cvGrabFrame(capture);
img = cvRetrieveFrame(capture);
cvWriteFrame(writer, img);
}
cvNamedWindow("myWin", CV_WINDOW_AUTOSIZE);
cvShowImage("myWin", img);
cvWaitKey(20);
cvReleaseVideoWriter(&writer);
cvReleaseCapture(&capture);
cvReleaseImage(&img);
cvDestroyWindow("myWin");
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询