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
210
211
212
213
214
215
216
217
218
219
220
221
222
|
/* Copyright (c) 2012 Patrick Ruoff
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*/
#include "ftnoir_tracker_pt_dialog.h"
#include <QMessageBox>
#include <QDebug>
//-----------------------------------------------------------------------------
TrackerDialog::TrackerDialog()
: settings_dirty(false), tracker(NULL), timer(this), trans_calib_running(false)
{
setAttribute(Qt::WA_DeleteOnClose, false);
ui.setupUi( this );
settings.load_ini();
// initialize ui values
ui.videowidget_check->setChecked(settings.video_widget);
ui.sleep_spin->setValue(settings.sleep_time);
ui.camindex_spin->setValue(settings.cam_index);
ui.f_dspin->setValue(settings.cam_f);
ui.threshold_slider->setValue(settings.threshold);
ui.mindiam_spin->setValue(settings.min_point_size);
ui.maxdiam_spin->setValue(settings.max_point_size);
ui.m1x_spin->setValue(settings.M01[0]);
ui.m1y_spin->setValue(settings.M01[1]);
ui.m1z_spin->setValue(settings.M01[2]);
ui.m2x_spin->setValue(settings.M02[0]);
ui.m2y_spin->setValue(settings.M02[1]);
ui.m2z_spin->setValue(settings.M02[2]);
ui.tx_spin->setValue(settings.t_MH[0]);
ui.ty_spin->setValue(settings.t_MH[1]);
ui.tz_spin->setValue(settings.t_MH[2]);
ui.tcalib_button->setEnabled(false);
// connect Qt signals and slots
connect( ui.videowidget_check,SIGNAL(toggled(bool)), this,SLOT(set_video_widget(bool)) );
connect( ui.sleep_spin,SIGNAL(valueChanged(int)), this,SLOT(set_sleep_time(int)) );
connect( ui.camindex_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_index(int)) );
connect( ui.f_dspin,SIGNAL(valueChanged(double)), this,SLOT(set_cam_f(double)) );
connect( ui.threshold_slider,SIGNAL(sliderMoved(int)), this,SLOT(set_threshold(int)) );
connect( ui.mindiam_spin,SIGNAL(valueChanged(int)), this,SLOT(set_min_point_size(int)) );
connect( ui.maxdiam_spin,SIGNAL(valueChanged(int)), this,SLOT(set_max_point_size(int)) );
connect( ui.m1x_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m1x(int)) );
connect( ui.m1y_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m1y(int)) );
connect( ui.m1z_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m1z(int)) );
connect( ui.m2x_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m2x(int)) );
connect( ui.m2y_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m2y(int)) );
connect( ui.m2z_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m2z(int)) );
connect( ui.tx_spin,SIGNAL(valueChanged(int)), this,SLOT(set_tx(int)) );
connect( ui.ty_spin,SIGNAL(valueChanged(int)), this,SLOT(set_ty(int)) );
connect( ui.tz_spin,SIGNAL(valueChanged(int)), this,SLOT(set_tz(int)) );
connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool)) );
connect(ui.ok_button, SIGNAL(clicked()), this, SLOT(doOK()));
connect(ui.cancel_button, SIGNAL(clicked()), this, SLOT(doCancel()));
connect(ui.center_button, SIGNAL(clicked()), this, SLOT(doCenter()));
connect(&timer,SIGNAL(timeout()), this,SLOT(poll_tracker_info()));
timer.start(100);
}
TrackerDialog::~TrackerDialog()
{
qDebug()<<"TrackerDialog::~TrackerDialog";
}
void TrackerDialog::startstop_trans_calib(bool start)
{
if (start)
{
qDebug()<<"TrackerDialog:: starting translation calibration";
trans_calib.reset();
trans_calib_running = true;
}
else
{
qDebug()<<"TrackerDialog:: stoppping translation calibration";
trans_calib_running = false;
settings.t_MH = trans_calib.get_estimate();
settings_changed();
}
}
void TrackerDialog::trans_calib_step()
{
if (tracker)
{
FrameTrafo X_CM;
tracker->get_pose(&X_CM);
trans_calib.update(X_CM.R, X_CM.t);
cv::Vec3f t_MH = trans_calib.get_estimate();
//qDebug()<<"TrackerDialog:: current translation estimate: "<<t_MH[0]<<t_MH[1]<<t_MH[2];
ui.tx_spin->setValue(t_MH[0]);
ui.ty_spin->setValue(t_MH[1]);
ui.tz_spin->setValue(t_MH[2]);
}
}
void TrackerDialog::set_cam_index(int val)
{
settings.cam_index = val;
settings_dirty = true;
if (tracker)
tracker->apply(settings);
}
void TrackerDialog::settings_changed()
{
settings_dirty = true;
if (tracker)
tracker->apply_without_camindex(settings);
}
void TrackerDialog::doCenter()
{
if (tracker)
tracker->CenterTracker();
}
void TrackerDialog::doOK()
{
settings.save_ini();
close();
}
void TrackerDialog::doCancel()
{
if (settings_dirty) {
int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?",
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard );
switch (ret) {
case QMessageBox::Save:
settings.save_ini();
close();
break;
case QMessageBox::Discard:
close();
break;
case QMessageBox::Cancel:
// Cancel was clicked
break;
default:
// should never be reached
break;
}
}
else {
close();
}
}
void TrackerDialog::poll_tracker_info()
{
if (tracker)
{
CamInfo info;
tracker->get_cam_info(&info);
ui.caminfo_label->setText(QString::number(info.res_x)+"x"+QString::number(info.res_y)+" @ "+QString::number(info.fps)+" FPS");
int n_points = tracker->get_n_points();
QString to_print = QString::number(n_points);
if (n_points == 3)
to_print += " OK!";
else
to_print += " BAD!";
ui.pointinfo_label->setText(to_print);
if (trans_calib_running) trans_calib_step();
}
else
{
ui.caminfo_label->setText("Tracker offline");
ui.pointinfo_label->setText("Tracker offline");
}
}
//-----------------------------------------------------------------------------
// ITrackerDialog interface
void TrackerDialog::Initialize(QWidget *parent)
{
QPoint offsetpos(200, 200);
if (parent) {
this->move(parent->pos() + offsetpos);
}
show();
}
void TrackerDialog::registerTracker(ITracker *t)
{
qDebug()<<"tracker registerd";
tracker = static_cast<Tracker*>(t);
if (isVisible() && settings_dirty)
tracker->apply(settings);
ui.tcalib_button->setEnabled(true);
}
void TrackerDialog::unRegisterTracker()
{
qDebug()<<"tracker un-registerd";
tracker = NULL;
ui.tcalib_button->setEnabled(false);
}
//-----------------------------------------------------------------------------
#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0")
FTNOIR_TRACKER_BASE_EXPORT ITrackerDialogPtr __stdcall GetTrackerDialog( )
{
return new TrackerDialog;
}
|