#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
- 资源: 4
最新资源
- Autosar学习视频10-19节
- stm32小车.zip
- AshampooUnInstaller v15.00.22 Portable一款强大的卸载工具,彻底、智能著称阿香婆强制卸载软件.rar
- Ashampoo WinOptimizer v27.00.05 阿香婆一款专业的垃圾清理、碎片整理启动项管理系统优化工具.rar
- misc设备驱动 正点原子阿尔法
- youleng-wms JAVA开发的WMS源码可以借签学习 数据库MYSQL
- 385大神asp.net三层设计停车场管理系统毕业课程源码设计+参考论文
- 数据集,训练数据集,深度学习
- 384大神asp.net基于三层汽车进销存销售管理系统毕业课程源码设计
- AutoSAR基础学习资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈