win10+qt+vs2013实现连续拍照功能并存储到文件夹中

来源:互联网 发布:dnf端口辅助怎么稳定 编辑:程序博客网 时间:2024/06/03 17:59

(1)vs下新建一个qt工程,打开ui文件

(2)布局ui文件,改变名称,对象名称,保存(只用一个PushButton)

(3)工程目录下新建一个文件夹取名Image

(4)Takephoto.h中代码为

#ifndef TAKEPHOTO_H#define TAKEPHOTO_H#include <QtWidgets/QMainWindow>#include "ui_takephoto.h"#include<opencv2/opencv.hpp>using namespace cv;class takephoto : public QMainWindow{Q_OBJECTpublic:takephoto(QWidget *parent = 0);~takephoto();private:Ui::takephotoClass ui;VideoCapture cap;Mat frame;private slots:void TakePhotoSlot();};#endif // TAKEPHOTO_H

(5)Takephoto.cpp中代码为

#include "takephoto.h"takephoto::takephoto(QWidget *parent): QMainWindow(parent){ui.setupUi(this);connect(ui.TakePhotoButton,SIGNAL(clicked()),this,SLOT(TakePhotoSlot()));//clicked与TakePhotoSlot后面的括号不能忘了}takephoto::~takephoto(){}void takephoto::TakePhotoSlot(){cap.open(0);//打开摄像头int i = 1;while (i != 11)//拍摄10张照片{cap >> frame;imshow("frame", frame);string filename = format("Image\\%d.jpg", i);char key = waitKey(10);//值越大视频越卡,为0出错switch (key){case 'p'://按键盘上的'p'拍摄i++;imwrite(filename, frame);imshow("takephoto", frame);waitKey(1000);destroyWindow("takephoto");break;default:break;}}}

(6)F5运行,按下拍照按钮,打开摄像头

(7)按下10次Image文件中拍摄完10张图片


阅读全文
0 0
原创粉丝点击