-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
88 lines (75 loc) · 2.71 KB
/
Copy pathmainwindow.cpp
File metadata and controls
88 lines (75 loc) · 2.71 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qstring.h>
#include <qfiledialog.h>
#include "renderer.h"
#include <qelapsedtimer.h>
#include <qdebug.h>
#include <opencv2/opencv.hpp>
using namespace cv;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
}
MainWindow::~MainWindow() {
delete ui;
}
/*
* Setting up the button which open the file dialog
* and puts the path of the file selected in the
* respective line edit
*/
void MainWindow::on_scenePathButton_clicked() {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Images and Videos (*.png *.xpm *.jpg *.mp4)")); //Open file dialog
ui->scenePath->setText(fileName); //Put the path in the line edit
}
/*
* Setting up the button which open the file dialog
* and puts the path of the file selected in the
* respective line edit
*/
void MainWindow::on_texturesPathButton_clicked() {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Images (*.png *.xpm *.jpg)")); //Open file dialog
ui->texturesPath->setText(fileName); //Put the path in the line edit
}
/*
* Setting up the button which open the file dialog
* and puts the path of the file selected in the
* respective line edit
*/
void MainWindow::on_objectsPathButton_clicked() {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Images (*.png *.xpm *.jpg)")); //Open file dialog
ui->objectsPath->setText(fileName); //Put the path in the line edit
}
/*
* Setting up the apply button to start the algorithm
*/
void MainWindow::on_applyButton_clicked() {
Mat object = imread(ui->objectsPath->text().toStdString());
Mat texture = imread(ui->texturesPath->text().toStdString());
Mat scene = imread(ui->scenePath->text().toStdString());
cv::resize(object, object, Size(640, 480));
cv::resize(texture, texture, Size(640, 480));
Renderer render(texture, object);
namedWindow("Scene", WINDOW_NORMAL);
if (!ui->scenePath->text().endsWith(".mp4")) {
cv::resize(scene, scene, Size(640, 480));
render.performRender(scene, texture);
}
else {
VideoCapture capture(ui->scenePath->text().toStdString());
Mat frame;
if(!capture.isOpened())
throw "Error when reading " + ui->scenePath->text().toStdString();
for( ; ; ) {
QElapsedTimer timer;
timer.start();
capture >> frame;
if(frame.empty())
break;
render.performRender(frame, texture);
if (waitKey(5) >= 0)
break;
qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";
}
}
}