我一直在尝试编写一个简单的程序,该程序仅从网络摄像头录制几秒钟的短视频并将其存储在文件中,但我无法这样做。如果有人以前经历过这件事,请帮助我。谢谢
问问题
1608 次
1 回答
0
我建议改用opencv。有许多书籍和开源项目。示例取自(http://opencv.willowgarage.com/wiki/CameraCapture)
这是一个连接到相机并在窗口中显示图像的简单框架。
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main() {
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while ( 1 ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "mywindow", frame );
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
于 2013-04-27T17:38:00.153 回答