在c++中使用directshow从网络摄像头捕获简单的视频

simple video capturing in windows from webcam using directshow in C++

本文关键字:摄像头 简单 的视频 网络 c++ directshow      更新时间:2023-10-16

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

我建议使用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;
}