我使用opencv直接從網絡攝像頭捕捉視頻並將其保存到avi文件。我已經使用了以下代碼:視頻沒有寫入文件
#include "StdAfx.h"
using namespace std;
using namespace cv;
int _tmain()
{
VideoCapture src;
src.open(1);
if(!src.isOpened())
{
cout<<"could not open camera\n";
return -1;
}
else
{
cout<<"camera opened\n";
}
int ex=static_cast<int>(src.get(CV_CAP_PROP_FOURCC));
Size s(Size((int)src.get(CV_CAP_PROP_FRAME_WIDTH),(int)src.get((CV_CAP_PROP_FRAME_HEIGHT))));
VideoWriter out;
out.open("out.avi",ex,20,s);
while(1)
{
Mat im;
src>>im;
imshow("vid",im);
out<<im;
char c;
c=cvWaitKey(50);
if(c==27)
break;
}
system("pause");
}
所有標題都包含在stdafx.h中。 但實際上我得到一個大小爲0bite的avi文件。如何解決這個問題?我需要記錄攝像頭視頻而不顯示。
注:我在OpenCV中新,我使用Visual Studio 2010
喜,一看便知here..http://stackoverflow.com/questions/12054907/opencv-videowriter-wont-write-anything-although- cvwritetoavi-does/12059944#12059944 ..它可能會幫助你。 – G453