-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimagesetprocessor.cpp
131 lines (109 loc) · 3.98 KB
/
imagesetprocessor.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
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
#include "imagesetprocessor.h"
#include "ui_imagesetprocessor.h"
ImageSetProcessor::ImageSetProcessor(QWidget *parent) :
QDialog(parent),
ui(new Ui::ImageSetProcessor)
{
ui->setupUi(this);
}
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_browsePythonPath_clicked()
{
ui->pythonPath->setText(QFileDialog::getExistingDirectory(this, tr("Load Directory..."), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
}
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 ImageSetProcessor::on_buttonBox_clicked(QAbstractButton *button)
{
if (button->text() == "OK") {
// Get application path
QString exePath = QDir::currentPath();
// Get potential files for classifier exe
QList<QString> files;
listFiles(exePath, "", files);
QString scriptPath;
// Find classifier exe
bool found = false;
for (int i = 0; i < files.size(); ++i)
{
if (files[i].contains("fextract.py"))
{
scriptPath = files[i];
found = true;
}
}
if (!found)
{
QMessageBox msgBox;
msgBox.setText("Python Script Not Found.");
msgBox.exec();
return;
}
// Get Info
QString imageFolder = ui->imageSetFolder->text();
QString gpsLogFolder = ui->gpsLogPath->text();
QString outputFolder = ui->processedFolderName->text();
// Get files
QList<QString> images;
listFiles(imageFolder, "", images);
#pragma omp parallel for
for (int i = 0; i < images.size(); i++)
{
// 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;
args << scriptPath << images[i] << gpsLogFolder << outputFolder;
// Make Process
QProcess scriptProcess;
// Set process working directory
int pos = scriptPath.toStdString().find_last_of('/');
QString workingDirectory = QString::fromStdString(scriptPath.toStdString().substr(0, pos));
scriptProcess.setWorkingDirectory(workingDirectory);
// Start and wait
scriptProcess.start(ui->pythonPath->text() + "\\python.exe", args);
scriptProcess.waitForFinished(-1);
//QMessageBox msgBox;
//msgBox.setText(scriptProcess.readAllStandardError());
//msgBox.exec();
}
}
}