-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchingmodule.cpp
209 lines (152 loc) · 5.04 KB
/
matchingmodule.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
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
207
208
209
#include "matchingmodule.hpp"
#include "property.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <QVBoxLayout>
#include <QRadioButton>
#include <QLabel>
#include <QCheckBox>
#include <QSpinBox>
#include <QComboBox>
#include <QPushButton>
using namespace std;
using namespace cv;
MatchingModule::MatchingModule(QObject *parent)
: QObject(parent){
chosenAlgorithm = -1;
}
MatchingModule::~MatchingModule(){
for(int i = 0; i < algorithms.size(); ++i){
delete algorithms[i];
}
delete buttonGroup;
}
void MatchingModule::init(Settings * sets, QDialog * dialog){
settings = sets;
chooseDialog = new QDialog(dialog);
chooseDialog->setWindowTitle("Stereo dopasowanie");
initAlgorithms();
initChooseWindow();
initWindows();
}
void MatchingModule::initAlgorithms(){
StereoMatching * bm = new StereoMatchingBM();
bm->id = 0;
StereoMatching * sgbm = new StereoMatchingSGBM();
sgbm->id = 1;
StereoMatching * gc = new StereoMatchingGC();
gc->id = 2;
algorithms.push_back(bm);
algorithms.push_back(sgbm);
algorithms.push_back(gc);
chosenAlgorithm = 0;
}
void MatchingModule::initChooseWindow(){
QVBoxLayout *layout = new QVBoxLayout;
buttonGroup = new QButtonGroup;
for(int i = 0; i < algorithms.size(); ++i){
QRadioButton * button = new QRadioButton(QString(algorithms[i]->getName()), chooseDialog);
layout->addWidget(button);
buttonGroup->addButton(button);
if(chosenAlgorithm == i){
button->setChecked(true);
}
buttonGroup->setId(button, i);
}
connect ( buttonGroup, SIGNAL(buttonClicked (int)),
this, SLOT(algorithmChanged (int)));
chooseDialog->setLayout(layout);
chooseDialog->setMinimumWidth(200);
chooseDialog->adjustSize();
chooseDialog->move(10,20);
}
void MatchingModule::initWindows(){
for(int i = 0; i < algorithms.size(); ++i){
QDialog * setsDialog = new QDialog(chooseDialog);
QVBoxLayout *layout = new QVBoxLayout;
QPushButton * buttonApply = new QPushButton("Zastosuj", chooseDialog);
connect(buttonApply, SIGNAL(clicked()),
this, SLOT(applyValues()));
int propsCounter = algorithms[i]->properties.size();
for(int j = 0; j < propsCounter; ++j){
Property * prop = algorithms[i]->properties[j];
addGuiForProperty(setsDialog, layout, prop, buttonApply);
}
buttonApply->setEnabled(false);
layout->addWidget(buttonApply);
applyButtons.push_back(buttonApply);
setsDialog->setWindowTitle(algorithms[i]->getName());
setsDialog->setLayout(layout);
setsDialog->setMinimumWidth(200);
setsDialog->adjustSize();
setsDialog->move(10,150);
setsDialogs.push_back(setsDialog);
}
}
void MatchingModule::addGuiForProperty(QDialog * parent, QLayout * layout, Property * prop, QPushButton * button){
Property::TYPE theType = prop->getType();
switch(theType){
case Property::INT:{
QLabel * label = new QLabel(prop->getName(), parent);
layout->addWidget(label);
QSpinBox * spin = new QSpinBox(parent);
spin->setRange(prop->minValue, prop->maxValue);
spin->setValue(prop->getValue());
spin->setSingleStep(prop->step);
layout->addWidget(spin);
connect(spin, SIGNAL(valueChanged(int)),
prop, SLOT(setValueToChange(int)));
connect(spin, SIGNAL(valueChanged(int)),
this, SLOT(enableButton(int)));
break;
}
case Property::BOOL:{
QCheckBox * checkBox = new QCheckBox(prop->getName(), parent);
checkBox->setChecked((bool)prop->getValue());
layout->addWidget(checkBox);
connect(checkBox, SIGNAL(stateChanged(int)),
prop, SLOT(setValueToChange(int)));
connect(checkBox, SIGNAL(stateChanged(int)),
this, SLOT(enableButton(int)));
break;
}
case Property::DISCRETE:{
QLabel * label = new QLabel(prop->getName(), parent);
layout->addWidget(label);
QComboBox * combo = new QComboBox(parent);
int * values = prop->tableValues;
for(int i = 0; i < prop->maxValue; ++i){
combo->addItem(QString().setNum(values[i]));
}
combo->setCurrentIndex(prop->getValue());
connect(combo, SIGNAL(currentIndexChanged(int)),
prop, SLOT(setValueToChange(int)));
connect(combo, SIGNAL(currentIndexChanged(int)),
this, SLOT(enableButton(int)));
layout->addWidget(combo);
break;
}
}
}
IplImage * MatchingModule::match(IplImage * frame1, IplImage * frame2){
Mat retImage;
algorithms[chosenAlgorithm]->exec(Mat(frame1), Mat(frame2), retImage);
return NULL;
}
/*********** obsluga zdarzen *************/
void MatchingModule::algorithmChanged(int id){
if(id == chosenAlgorithm){
return;
}
setsDialogs[chosenAlgorithm]->hide();
chosenAlgorithm = id;
setsDialogs[chosenAlgorithm]->show();
}
void MatchingModule::applyValues(){
algorithms[chosenAlgorithm]->setPropertiesWereChanged();
Mat a, b, c;
algorithms[chosenAlgorithm]->exec(a,b,c);
applyButtons[chosenAlgorithm]->setEnabled(false);
}
void MatchingModule::enableButton(int){
applyButtons[chosenAlgorithm]->setEnabled(true);
}