#include "dialog.h"
#include "ui_dialog.h"
#include <QString>
#include <string>
#include <QMessageBox>
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
m_timer = new QTimer(this);
ui->Exposure->setText("-5");
connect(m_timer, SIGNAL(timeout()), this, SLOT(readFrame()));
}
Dialog::~Dialog()
{
if(m_timer != nullptr)
{
m_timer->stop();
}
delete ui;
}
void Dialog::on_btn_Rec_clicked()
{
cap.open(0);
double frame_width = cap.get(CAP_PROP_FRAME_WIDTH);
double frame_height = cap.get(CAP_PROP_FRAME_HEIGHT);
double frame_rate = cap.get(CAP_PROP_FPS);
printf("frame_width: %f, frame_height: %f, frame_rate: %f.\n", frame_width, frame_height, frame_rate);
cap.set(CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));
cap.set(CAP_PROP_FPS,25);
cap.set(CAP_PROP_FRAME_WIDTH, 640);
cap.set(CAP_PROP_FRAME_HEIGHT, 480);
double frame_set_width = cap.get(cv::CAP_PROP_FRAME_WIDTH);
double frame_set_height = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
double frame_set_rate = cap.get(cv::CAP_PROP_FPS);
printf("frame_set_width: %f, frame_set_height: %f, frame_set_rate: %f.\n", frame_set_width, frame_set_height, frame_set_rate);
if (!cap.isOpened())
{
printf("open camera err.\n");
return;
}
if(ui->AutoExposure->isChecked())
{
QMessageBox::about(this, "info", "checked");
double getAuto = cap.get(cv::CAP_PROP_AUTO_EXPOSURE);
qDebug() << "GET_AUTO_EXPOSURE" << getAuto;
cap.set(cv::CAP_PROP_AUTO_EXPOSURE, -1);
}
else
{
QMessageBox::about(this, "info", "No checked");
//手动曝光设置代码片段
int getEx = cap.get(cv::CAP_PROP_EXPOSURE);
qDebug() << "GET_EXPOSURE_START" << getEx;
//先设置自动为0.25
cap.set(cv::CAP_PROP_AUTO_EXPOSURE, 0.25);
//取值范围是:-13 ~ -1
int exp = ui->Exposure->text().toInt();
cap.set(cv::CAP_PROP_EXPOSURE, exp);
qDebug() << "SET_EXPOSURE" << exp;
double getEx2 = cap.get(cv::CAP_PROP_EXPOSURE);
qDebug() << "GET_EXPOSURE" << getEx2;
}
Size videoSize(640, 480);
//int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
int fourcc = cv::VideoWriter::fourcc('X', 'V', 'I', 'D');
writer.open("R640.avi", fourcc, 25, videoSize);
if (!writer.isOpened())
{
//printf("open file err.\n");
qDebug()<< "open file err";
return;
}
m_timer->start(40);
}
void Dialog::on_btn_Stop_clicked()
{
cap.release();
writer.release();
m_timer->stop();
}
void Dialog::readFrame()
{
Mat frame;
QElapsedTimer timer;
timer.start();
cap.read(frame);
frame.type();
//writer.write(frame);
int milsec = timer.elapsed();
qDebug() << "rec need" << milsec << "ms";
Mat zoomImg(cv::Size(800, 450), CV_8UC3, cv::Scalar(255,255,255));
cvtColor(frame, zoomImg, COLOR_BGR2RGB);
QImage::Format format;
switch (zoomImg.type())
{
case CV_8UC1:
format = QImage::Format_Indexed8;
break;
case CV_8UC3:
format = QImage::Format_RGB888;
break;
case CV_8UC4:
format = QImage::Format_ARGB32;
break;
}
QImage img = QImage((const uchar*)zoomImg.data, zoomImg.cols, zoomImg.rows, format);
ui->videoDisplay->clear();
QPixmap pixmap = QPixmap::fromImage(img);
pixmap = pixmap.scaled(ui->videoDisplay->size());
ui->videoDisplay->setAutoFillBackground(true);
QPalette palette;
palette.setBrush(ui->videoDisplay->backgroundRole(), QBrush(pixmap));
ui->videoDisplay->setPalette(palette);
ui->videoDisplay->repaint();
}
david_2006
- 粉丝: 0
- 资源: 7
最新资源
- 微信小程序源码-警务辅助人员管理系统-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-警务辅助人员管理系统-服务端-毕业设计源码-期末大作业.zip
- Java项目总结怎么写
- 微信小程序源码-乐室预约小程序-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-考研论坛设计-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-乐室预约小程序-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-马拉松报名系统微信小程序-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-培训咨询微信小程序-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-马拉松报名系统微信小程序-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-汽车预约维修系统-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-培训咨询微信小程序-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-汽车预约维修系统-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-四六级词汇-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-四六级词汇-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-私家车位共享系统演示录像-毕业设计源码-期末大作业.zip
- 微信小程序源码-停车场微信小程序的设计与实现-微信端-毕业设计源码-期末大作业.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈