-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimagesetprocessor.cpp
More file actions
206 lines (176 loc) · 5.52 KB
/
imagesetprocessor.cpp
File metadata and controls
206 lines (176 loc) · 5.52 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "imagesetprocessor.h"
#include "ui_imagesetprocessor.h"
#include <QCloseEvent>
#include <QDebug>
ImageSetProcessor::ImageSetProcessor(const QString &cnnPath, QWidget *parent) :
QDialog(parent),
cnnPath(cnnPath),
imagesCompleted(0),
ui(new Ui::ImageSetProcessor)
{
ui->setupUi(this);
isProcessing = false;
worker = NULL;
}
ImageSetProcessor::~ImageSetProcessor()
{
delete ui;
}
void ImageSetProcessor::on_browseImageSetFolder_clicked()
{
ui->imageSetFolder->setText(QFileDialog::getExistingDirectory(this, tr("Load Directory..."), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
}
void ImageSetProcessor::on_browseProcessedSaveFolder_clicked()
{
}
void ImageSetProcessor::listFiles(QDir directory, QString indent, QList<QString> &files)
{
indent += "\t";
QDir dir(directory);
QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QFileInfo finfo, list) {
files.append(finfo.filePath());
if(finfo.isDir()) {
listFiles(QDir(finfo.absoluteFilePath()), indent, files);
}
}
}
void ImageSetProcessor::on_buttonBox_accepted()
{
}
void ImageSetProcessor::on_browseProcessedFolder_clicked()
{
ui->processedFolderName->setText(QFileDialog::getExistingDirectory(this, tr("Load Directory..."), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
}
void ImageSetProcessor::on_pushButton_clicked()
{
ui->gpsLogPath->setText(QFileDialog::getOpenFileName(this,
tr("Open Image"), "", tr("Log Files (*.log)")));
}
void ProcessThread::run()
{
// Get application path
QString exePath = QDir::currentPath();
// Get potential files for classifier exe
QList<QString> files;
ImageSetProcessor::listFiles(exePath, "", files);
QString classifierPath;
// Find classifier exe
bool found = false;
for (int i = 0; i < files.size(); ++i)
{
if (files[i].contains("SoftmaxRegression.exe"))
{
classifierPath = files[i];
found = true;
break;
}
}
if (!found)
{
QMessageBox msgBox;
msgBox.setText("Classifier Script Not Found.");
msgBox.exec();
return;
}
// Get files
QList<QString> images;
ImageSetProcessor::listFiles(imageFolder, "", images);
numImages = images.size();
#pragma omp parallel for
for (int i = 0; i < images.size(); i++)
{
if (!process) continue;
// Check file name
if (images[i].toStdString().find(".jpg") == std::string::npos &&
images[i].toStdString().find(".png") == std::string::npos &&
images[i].toStdString().find(".JPG") == std::string::npos &&
images[i].toStdString().find(".PNG") == std::string::npos)
continue;
// Args:
// ImageName GPSLogName OutputFolderName
// Get args
QStringList args;
if (!aio)
{
args << "-identify" << images[i] << gpsLogFolder << outputFolder;
}
else
{
QString removeFalsePositivesStr = removeFalsePositives ? "true" : "false";
args << "-aio" << images[i] << gpsLogFolder << outputFolder << cnnPath << removeFalsePositivesStr;
}
// Make Process
QProcess scriptProcess;
// Start and wait
scriptProcess.start(classifierPath, args);
scriptProcess.waitForFinished(-1);
emit imageDone();
}
}
void ImageSetProcessor::on_processButton_clicked()
{
if (worker != NULL)
{
return;
}
// Get Info
QString imageFolder = ui->imageSetFolder->text();
QString gpsLogFolder = ui->gpsLogPath->text();
QString outputFolder = ui->processedFolderName->text();
if (imageFolder == "" || outputFolder == "")
{
return;
}
worker = new ProcessThread(imageFolder, gpsLogFolder,
outputFolder, cnnPath, ui->aioCheckbox->isChecked(),
ui->removeFalsePositivesCheckbox->isChecked());
this->setEnabled(false);
isProcessing = true;
connect(worker, &ProcessThread::finished, worker, &ProcessThread::deleteLater);
connect(worker, &ProcessThread::destroyed, this, [=]()
{
this->setEnabled(true);
this->isProcessing = false;
this->worker = NULL;
this->ui->progressBar->setValue(0);
imagesCompleted = 0;
});
connect(worker, &ProcessThread::imageDone, this, [=]()
{
++this->imagesCompleted;
this->ui->progressBar->setValue((double)this->imagesCompleted / worker->numImages * 100);
});
worker->start();
}
void ImageSetProcessor::closeEvent(QCloseEvent *event)
{
if (isProcessing)
{
QMessageBox::StandardButton reply = QMessageBox::question(this, "Terminate Processing",
tr("Things are processing. Are you sure you want to cancel?"),
QMessageBox::No | QMessageBox::Yes,
QMessageBox::Yes);
if (reply == QMessageBox::Yes)
{
if (worker)
{
worker->process = false;
worker->wait();
}
event->accept();
}
else
{
event->ignore();
}
}
else
{
event->accept();
}
}
void ImageSetProcessor::on_aioCheckbox_toggled(bool checked)
{
ui->removeFalsePositivesCheckbox->setEnabled(checked);
}