上午在调试程序:如何将摄像头采集到的视频隔一段时间自动扑获,并自动保存为图像,在网上看到一段程序,自己看了看,没能把那个捕获时间调出来(这个程序以后捕获摄像头的时间间隔太短,摄像机都没来得及完全启动,就又进行另一幅图片的捕获),特贴出来请高手指点!
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include<time.h>
using namespace std;
using namespace cv;
//#include<stdio.h>
//#include<stdlib.h>
//#include"cv.h"
//#include"highgui.h"
//#include<time.h>
int main()
{
while(1)
{
time_t now;
struct tm *timenow;
time(&now);
char outFileName[]="2011-01-01 24H00M00S.jpg";//修改
timenow = localtime(&now);
printf("saving...\n");
*(outFileName+5)=timenow->tm_mon/10+'0';
*(outFileName+6)=timenow->tm_mon%10+'0';
*(outFileName+8)=timenow->tm_mday/10+'0';
*(outFileName+9)=timenow->tm_mday%10+'0';
*(outFileName+11)=timenow->tm_hour/10+'0';
*(outFileName+12)=timenow->tm_hour%10+'0';
*(outFileName+14)=timenow->tm_min/10+'0';
*(outFileName+15)=timenow->tm_min%10+'0';
*(outFileName+17)=(timenow->tm_sec)/10+'0';
*(outFileName+18)=(timenow->tm_sec)%10+'0';
CvCapture *capture =cvCaptureFromCAM(1);
IplImage *img=0;
img = cvQueryFrame(capture);
if (!img)
{
printf("Could not grab a frame\n\7");
exit(0);
}
if(!cvSaveImage(outFileName,img))
printf("Could not save: %s\n",outFileName);
/*char c = cvWaitKey(1000000);
if(c == 10000)
{
break;
} */
cvReleaseCapture(&capture);
}
return 0;
}