-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwidget.h
executable file
·156 lines (130 loc) · 3.93 KB
/
mainwidget.h
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
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include <QWidget>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <QPixmap>
#include <sstream>
#include <QPushButton>
#include <QRadioButton>
#include <QDir>
#include "kvconfig.h"
#include "classifier.h"
#define IMG_PATH "./image.d"
#define CFG_PATH "./cfg.d"
#define CATALOG_FNAME CFG_PATH "/catalogs.txt"
namespace Ui {
class MainWidget;
}
class MainWidget : public QWidget
{
Q_OBJECT
public:
explicit MainWidget(QWidget *parent = 0);
~MainWidget();
protected:
bool eventFilter(QObject *, QEvent *);
private slots:
void undo();
void but_skipped();
void but_confused();
void but_subject_selected();
void but_regions_selected();
void but_actions_selected();
void but_objects_selected();
void but_prev(); //
private:
Ui::MainWidget *ui;
/// 输入文件列表
std::deque<QString> img_fnames_;
/// 用于支持 undo
std::stack<QString> undo_list_;
//
QString subject_, region_, action_, object_; // 当前选择 ..
QString last_subject_, last_region_, last_action_, last_object_;
/// 加载模型,尝试在分类之前,先进行预测 ...
bool loaded_;
Classifier *cf_;
bool load_models();
/// 来自配置文件的分类 ...
std::vector<std::pair<QString, QString> > subjects_, regions_, actions_, objects_;
std::vector<QRadioButton*> but_regions_, but_actions_, but_subjects_, but_objects_;
std::vector<QRadioButton*> *buts_curr_; //
void load_image_fnames();
std::vector<std::pair<QString, QString> > load_catalogs(const char *fname);
virtual void paintEvent(QPaintEvent *pd);
// 下一张照片,当前照片位于 img_fnames_.front()
QPixmap *next_image();
QPixmap curr_image_; // 正在显示的图像 ...
std::string curr_fname_; // 正在显示的图像的文件名字 ..
QString pred_result_; // 预测结果,在 paintEvent 中显示 ..
void enable_buts(std::vector<QRadioButton*> buts, bool enable)
{
for (size_t i = 0; i < buts.size(); i++) {
buts[i]->setEnabled(enable);
buts[i]->setAutoExclusive(false);
buts[i]->setChecked(false);
buts[i]->setAutoExclusive(true);
}
}
void enable_buts();
void show_buttons(); // 根据当前状态,显示按钮 ...
// 显示
void show_image(const QPixmap *img);
void show_curr();
void show_info();
// 从原始名字转化为分类后的名字
QString cataloged_filename(const QString &fname, const QString &subdir)
{
if (region_.isEmpty() || action_.isEmpty() || subject_.isEmpty()) {
throw new std::exception();
}
int pos = fname.lastIndexOf('/');
if (pos > 0) {
QString fs = IMG_PATH;
fs += '/';
fs += subdir;
fs += '/';
fs += fname.right(fname.length() - pos - 1);
return fs;
}
else {
throw new std::exception();
}
}
QString cataloged_fname(const QString &catalog, const QString &fname)
{
int pos = fname.lastIndexOf('/');
if (pos > 0) {
QString fs = IMG_PATH;
fs += '/';
fs += catalog;
fs += '/';
fs += fname.right(fname.length() - pos - 1);
return fs;
}
else {
throw new std::exception();
return "";
}
}
QString origin_fname(const QString &cataloged_fname)
{
int pos = cataloged_fname.lastIndexOf("/");
if (pos > 0) {
QString fs = IMG_PATH;
fs += '/';
QString n = cataloged_fname.right(cataloged_fname.length() - pos - 1);
fs += n;
return fs;
}
else {
throw new std::exception();
return "";
}
}
void all_selected();
};
#endif // MAINWIDGET_H