forked from xdhzhang/Specular-Highlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
92 lines (70 loc) · 2.12 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QTimer>
#include <QFileDialog>
#include "Basic/basic.h"
#define QCV_DEF_ITERATION_VALUE 0
#define QCV_DEF_QTIMER_VALUE 20
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow) {
m_ui->setupUi(this);
m_timer = new QTimer;
connect(m_timer, SIGNAL(timeout()), this, SLOT(cam()));
}
MainWindow::~MainWindow() {
delete m_ui;
}
void MainWindow::cam() {
static QMat frame;
m_webCam >> frame;
if(frame.empty()) {
qDebug() << "Frame empty";
return;
}
frame.cvtColor_(CV_BGR2RGB);
highLightRemove(frame, QCV_DEF_ITERATION_VALUE);
}
void MainWindow::on_pbCamOnOff_clicked() {
if(m_ui->pbCamOnOff->text() == "Start") {
m_webCam.open(m_ui->sbCamNumber->value());
if(!m_webCam.isOpened()) {
qDebug() << "Not found web cam";
qDebug() << "Automatic setting";
m_webCam.open(0);
if(!m_webCam.isOpened()) {
qDebug() << "Not found web cam";
return;
}
}
m_ui->pbCamOnOff->setText("Stop");
m_ui->pbFileOpen->setEnabled(false);
m_timer->start(QCV_DEF_QTIMER_VALUE);
} else {
m_ui->pbCamOnOff->setText("Start");
m_ui->pbFileOpen->setEnabled(true);
m_timer->stop();
}
}
void MainWindow::on_pbFileOpen_clicked() {
QString pathFile = QFileDialog::getOpenFileName();
if(pathFile.isEmpty()) {
qDebug() << "Path file empty";
return;
}
QMat file = imread(pathFile.toStdString());
if(file.empty()) {
qDebug() << "File empty";
return;
}
file.cvtColor_(CV_BGR2RGB);
highLightRemove(file, QCV_DEF_ITERATION_VALUE);
}
void MainWindow::highLightRemove(QMat mat, int iter) {
static QHighLight h;
h.init(mat, 20, m_ui->doubleSpinBox->value());
int iter_count = h.diffuse(iter);
// qDebug() << "Highlight removal of iterations before convergece: " << iter_count;
h.getDiffuseImage().draw(m_ui->lblImage);
}