OpenCV3 读取摄像头并保存图像

#include <io.h>
#include
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

/* 函数说明 将int类型的参数追加到字符类型
输入:
@param Location 为文件所在的位置
@param num 为文件的命名(以字符命名)
@param EndLocationType 为文件的后缀
结果:
@param FilesName 目录文件夹下所有该类型的文件存入【目录 + 文件名 + 文件类型】
*/
string FileLocation(string Location, int num, string EndLocationType)
{
string imageFileName;
std::stringstream StrStm1;
StrStm1 << num + 1;
StrStm1 >> imageFileName;
imageFileName += EndLocationType;
return Location + imageFileName;
}

//程序说明:1.按下ESC程序退出,2.按下空格键截取图像
int main()
{
Mat srcImage;
char c;
int temp=0;//计数器
VideoCapture cam(0);
if (!cam.isOpened()) exit(0);
namedWindow("【摄像头】");
while (true) {
cam >> srcImage;
imshow("【摄像头】", srcImage);
c = waitKey(30);
if (c == ’ ')
{
imwrite(FileLocation(“e:\hello\”,temp,".jpg"),srcImage);
temp++;
}
if (c == 27)
break;
}
return 0;
}

最终的效果图

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值