按键拍摄保存照片。
#include<opencv2/opencv.hpp>
#include"opencv2/highgui/highgui.hpp"
#include<iostream>
#include<string>
using namespace cv;
using namespace std;
int main()
{
int i = 0;
string name;
//调用摄像头
VideoCapture capture(0);
while (1)
{
//读入视频
Mat frame;//存放帧
capture >> frame;//读取帧
imshow("video photo", frame);
//按键实现功能 esc退出 g将图片灰度化后 保存到本地 其他彩色保存
while (waitKey(10) == 'g')
{
Mat dstimg;
cvtColor(frame, dstimg, COLOR_RGB2GRAY);
//sprintf_s(name,"PHOTOGRAY%d.jpg", i);
name = to_string(i) + ".jpg";
i++;
imwrite(name, dstimg);
}
while (waitKey(10) == 27)
{
return 0;
}
while (waitKey(10) >= 65 && waitKey(10) <= 90)
{
Mat dstImage;
name = to_string(i) + ".jpg";
i++;
imwrite(name, dstImage);
}
}
}