最近开始接触opencv,调用摄像头的代码已经都公开过,但一直在想怎么用摄像头进行连续的拍照呢,所以纠结了一个下午打算自己写一个吧,虽然这里是简单的实现,但在后面想用多线程的思想来调用,最近在赶中期论文报告,之后补上,现在现将简单的实现放上来吧
编译环境:VS+opencv3.1 摄像头帧率:30ftp/s
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture(0);
int delay = 1000 / 30;
string a[] = {"cam01.jpg","cam02.jpg","cam03.jpg","cam04.jpg","cam05.jpg","cam06.jpg",
"cam07.jpg","cam08.jpg","cam09.jpg","cam10.jpg","cam11.jpg","cam12.jpg"};
int i = 0;
while (1)
{
Mat frame;
capture >> frame;
imshow("show",frame);
//imwrite("camera1.jpg", frame);
int key;
key = waitKey(delay);
if ( 27 == (char)key)
{
imwrite(a[i],frame);
i++;
}
}
}
欢迎大家一起讨论学习,可以加个人qq 联系:3559903110