通过OPENCV从视频中获取图片并保存

//#include "stdafx.h"
#include "Afxdlgs.h"
#include "highgui.h"
#include "stdio.h"
#include "cv.h"
#include "cxcore.h" 
#include "math.h"
#include "stdlib.h"
#include "time.h" 
#include "cderr.h"
#include "cstringt.h"

//#include "opencv2/opencv.hpp"
//#include "time.h" 

//extern CString * selectfile();
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
int main( int argc, char** argv )
{
  /*
 CString *arr=NULL;

 arr = selectfile();
   printf("%s",arr[0]);
 delete [] arr;
 */ 

CString path = "E:\\导出图片\\";       //存放导出图片位置
  char filename[50];
  CString file;
     int bknum=10000; //起始帧的位置,可以更改
  CvCapture* capture = 0;
  int save;
  capture = cvCreateFileCapture( "E:\\原始视频\\10020911\\14360005.AVI" );  //原始视频

  if( !capture ){
   return -1;
  }
  int count=cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT );// 视频文件中帧的总数
  printf("%d",count);

  while (bknum   {
  
   cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, bknum);
  IplImage *bgr_frame = cvQueryFrame( capture );

  file.Format("%d", bknum) ;
  printf("%s",file);
  sprintf(filename,"%s%s%s",path,file,"f.bmp");
  printf("%s",filename);
  
  save = cvSaveImage( filename, bgr_frame );
  bknum = bknum + 15;  //设置为每隔15帧取一张图片
  }
  cvReleaseCapture( &capture );

 


 return 1;
}

你可能感兴趣的:(opencv使用)