-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
executable file
·97 lines (76 loc) · 2.65 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
92
93
94
95
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->message->setText("Iniciando buscador");
QSettings settings(SETTINGS_FNAME,QSettings::IniFormat);
QString folder = settings.value("rootFolder",QVariant(".")).toString();
classifier.init(folder);
configurationWindow = new ConfigurationWindow(0,&classifier);
ui->message->setText("Buscador preparado");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_configure_clicked()
{
configurationWindow->exec();
}
void MainWindow::on_selectPicture_clicked()
{
//get image fname
QFileDialog dialog;
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter("Image files (*.png *.xpm *.jpg *.bmp *.jpeg)");
if(dialog.exec()==0 || dialog.selectedFiles().size()==0 ) return;
imageToSearch = dialog.selectedFiles()[0];
//display
QGraphicsScene *scn = new QGraphicsScene(ui->imageView);
scn->setSceneRect(QRect(1,1,ui->imageView->rect().width()-2,ui->imageView->rect().height()-2));
ui->imageView->setScene(scn);
QPixmap pix(imageToSearch);
scn->addPixmap(pix);
}
void MainWindow::on_search_clicked()
{
//validate
if(imageToSearch.isEmpty()){
ui->message->setText("Debe cargar una imagen para la búsqueda");
return;
}
QSettings settings(SETTINGS_FNAME,QSettings::IniFormat);
QString folder = settings.value("rootFolder",QVariant(".")).toString();
ui->message->setText("detectando coincidencias");
classifier.detect(imread(imageToSearch.toStdString().c_str()));
QVector<QString> matches = classifier.getBestMatches();
//mostrar resultados
//limpiar
QLayoutItem *wItem;
while ((wItem = ui->resultsLayout->takeAt(0)) != 0){
ui->resultsLayout->removeItem(wItem);
delete wItem;
}
//mostrar
foreach(QString match, matches){
//show results
QLabel* label = new QLabel;
label->setText(match.toUpper());
ui->resultsLayout->addWidget(label);
QGraphicsView* graphics = new QGraphicsView;
QGraphicsScene *scn = new QGraphicsScene( graphics );
scn->setSceneRect(QRect(1,1,198,98));
graphics->setScene( scn );
graphics->setFixedSize(200, 100 );
QPixmap pix( folder+QDir::separator()+match);
scn->addPixmap( pix );
ui->resultsLayout->addWidget(graphics);
QSpacerItem* space = new QSpacerItem(100,20);
ui->resultsLayout->addSpacerItem(space);
}
ui->message->setText("Búsqueda finalizada");
ui->message->setText("Buscador preparado");
}