使用C ++中的directshow从网络摄像头在Windows中进行简单的视频捕获

时间:2013-04-27 14:43:47

标签: c++ visual-studio-2010

我一直在尝试编写一个简单的程序,只需几秒钟就能从网络摄像头录制短视频并将其存储在文件中,但我无法这样做。如果有人经历过这件事,请帮助我。感谢

1 个答案:

答案 0 :(得分: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;
}