9
我想從我的網絡攝像頭輸出使用opencv創建一個AVI視頻。不會拋出任何異常,但是它創建的avi文件大小爲414字節,不會增長。opencv寫網絡攝像頭輸出到AVI文件
此外,它不會與任何媒體播放器一起玩。我懷疑寫入文件部分有問題。
下面是代碼:
CvCapture *capture = cvCaptureFromCAM(0);
int width = (int)cvGetCaptureProperty(capture,
CV_CAP_PROP_FRAME_WIDTH);
int height = (int)cvGetCaptureProperty(capture,
CV_CAP_PROP_FRAME_HEIGHT);
CvVideoWriter *writer = cvCreateVideoWriter("CamCapture.avi",
-1,30, cvSize( width, height));
cvNamedWindow("capWindow", CV_WINDOW_AUTOSIZE);
IplImage *frame = 0;
// this returns 0 not sure why ??
//double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
double fps = 30;
while(1)
{
frame = cvQueryFrame(capture);
cvShowImage("capWindow",frame);
cvWriteFrame(writer, frame);
char c = cvWaitKey(1000/fps);
if(c == 27) break;
}
cvReleaseCapture(&capture);
cvReleaseVideoWriter(&writer);
cvDestroyWindow("capWindow");
我已經沒有運氣參考,並嘗試了以下樣品:
- http://gipetrou.com/scc/2010/12/12/save-video-from-webcam-with-opencv-2-1/
- http://answers.oreilly.com/topic/1366-how-to-write-to-an-avi-file-with-opencv/
- https://www.cs.utexas.edu/~teammco/misc/udp_video/
上面的代碼是否會生成播放實時視頻?我看到你將視頻固定爲10 FPS,而許多攝像頭允許錄製30 FPS? –
您可以將其更改爲25或30 ... – Haris
現在正在進行測試,並且由於我的相機價格便宜,因此在不同的光線設置下它不會提供穩定的幀頻。例如。光環境使得三分之一fps與較暗的環境一樣。因此,如果場景正在改變,則視頻將比預期更快或更慢地播放。無論如何,感謝您的快速回復:) –