forked from utat-uav/Software
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtargetwindow.cpp
More file actions
124 lines (109 loc) · 3.97 KB
/
targetwindow.cpp
File metadata and controls
124 lines (109 loc) · 3.97 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
#include "targetwindow.h"
#include "ui_targetwindow.h"
#include "targetlistwindow.h"
#include "imagewidget.h"
#include <QCloseEvent>
#include <QDebug>
TargetWindow::TargetWindow(LifeSupport *dataPackage, TargetListItem *targetListItem, QWidget *parent) :
QDialog(parent),
processing(false),
ui(new Ui::TargetWindow)
{
this->targetListItem = targetListItem;
ui->setupUi(this);
this->parent = (TargetListWindow *)parent;
// Set image
QPixmap *pix = new QPixmap();
QPixmap pic;
pix->load(targetListItem->imageFilePath);
pic = pix->scaled(280, 280, Qt::KeepAspectRatioByExpanding, Qt::FastTransformation) ;
ui->targetPic->setPixmap(pic);
delete pix;
this->dataPackage = dataPackage;
// Set all other information
ui->nameLabel->setText(targetListItem->name->text());
ui->coordinatesLabel->setText(targetListItem->coord->text());
ui->description->moveCursor(QTextCursor::End);
ui->description->insertPlainText(targetListItem->desc->text());
}
TargetWindow::~TargetWindow()
{
delete ui;
}
void TargetWindow::closeEvent(QCloseEvent *event)
{
if (processing)
{
event->ignore();
}
else
{
event->accept();
}
}
void TargetWindow::on_zbar_pressed()
{
this->setEnabled(false);
processing = true;
QString str = targetListItem->imageFilePath ;
dataPackage->classifier->write("zbar "+str.toLatin1()+"\n");
connect(dataPackage->consoleOutput,&QTextBrowser::textChanged, this, &TargetWindow::zbar) ;
}
void TargetWindow::on_classifyButton_pressed()
{
this->setEnabled(false);
processing = true;
dataPackage->classifier->write("classify "+targetListItem->imageFilePath.toLatin1()+"\n");
connect(dataPackage->consoleOutput, &QTextBrowser::textChanged, this, &TargetWindow::classify);
}
void TargetWindow::classify(){
QString str = dataPackage->consoleOutput->toHtml() ;
str.remove(0,str.lastIndexOf("Classified as")) ;
if ( !str.contains("valid"))
{
str.truncate(str.indexOf("confidence")+10) ;
QSettings resultFile(dataPackage->filePath, QSettings::IniFormat);
for ( int i = 1 ; i <= resultFile.value("Crop Info/Number of Crops").toInt() ; i ++ )
{
QString imageName = resultFile.value("Crop "+QString::number(i)+"/Image Name").toString() ;
if ( imageName == dataPackage->imagePath )
{
resultFile.setValue("Crop "+QString::number(i)+"/Description",str);
}
}
targetListItem->desc->setText(str);
// Update the internal target data
TargetData &target = dynamic_cast<ImageWidget *>(this->parent->parent)->getTarget(dataPackage->imagePath);
target.desc = str;
}
disconnect(dataPackage->consoleOutput, &QTextBrowser::textChanged, this, &TargetWindow::classify);
this->setEnabled(true);
processing = false;
this->accept();
}
void TargetWindow::zbar(){
QString str = dataPackage->consoleOutput->toHtml() ;
str.remove(0,str.lastIndexOf("QR-Code result"));
if ( !str.contains("valid"))
{
str.replace(""", "\"");
str.truncate(str.indexOf("<")) ;
QSettings resultFile(dataPackage->filePath, QSettings::IniFormat);
for ( int i = 1 ; i <= resultFile.value("Crop Info/Number of Crops").toInt() ; i ++ )
{
QString imageName = resultFile.value("Crop "+QString::number(i)+"/Image Name").toString();
if ( dataPackage->imagePath == imageName )
{
resultFile.setValue("Crop "+QString::number(i)+"/Description",str);
}
}
targetListItem->desc->setText(str);
// Update the internal target data
TargetData &target = dynamic_cast<ImageWidget *>(this->parent->parent)->getTarget(dataPackage->imagePath);
target.desc = str;
}
disconnect(dataPackage->consoleOutput, &QTextBrowser::textChanged, this, &TargetWindow::zbar);
this->setEnabled(true);
processing = false;
this->accept();
}