1 |
jakw |
1 |
#include "SMScanner.h"
|
|
|
2 |
#include "ui_SMScanner.h"
|
|
|
3 |
|
4 |
jakw |
4 |
#include <QMetaObject>
|
36 |
jakw |
5 |
#include <QFileDialog>
|
67 |
jakw |
6 |
#include <QMessageBox>
|
141 |
jakw |
7 |
#include <QProgressDialog>
|
4 |
jakw |
8 |
|
44 |
jakw |
9 |
#include <pcl/io/pcd_io.h>
|
|
|
10 |
#include <pcl/io/ascii_io.h>
|
|
|
11 |
#include <pcl/io/ply_io.h>
|
|
|
12 |
#include <pcl/io/png_io.h>
|
|
|
13 |
#include <pcl/io/vtk_io.h>
|
|
|
14 |
#include <vtkPolyDataWriter.h>
|
|
|
15 |
#include <pcl/conversions.h>
|
|
|
16 |
|
139 |
jakw |
17 |
#include "cvtools.h"
|
|
|
18 |
|
27 |
jakw |
19 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner),
|
67 |
jakw |
20 |
calibrationReviewMode(false), captureReviewMode(false), lastCaptureId(-1){
|
4 |
jakw |
21 |
|
27 |
jakw |
22 |
// Register metatypes
|
|
|
23 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
|
|
24 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
30 |
jakw |
25 |
qRegisterMetaType< std::vector<float> >("std::vector<float>");
|
27 |
jakw |
26 |
qRegisterMetaType<SMCalibrationSet>("SMCalibrationSet");
|
|
|
27 |
qRegisterMetaType< std::vector<SMCalibrationSet> >("std::vector<SMCalibrationSet>");
|
|
|
28 |
qRegisterMetaType<SMFrameSequence>("SMFrameSequence");
|
42 |
jakw |
29 |
qRegisterMetaType< std::vector<SMFrameSequence> >("std::vector<SMFrameSequence>");
|
45 |
jakw |
30 |
qRegisterMetaType<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>("pcl::PointCloud<pcl::PointXYZRGB>::Ptr");
|
42 |
jakw |
31 |
qRegisterMetaType<SMPointCloud>("SMPointCloud");
|
208 |
flgw |
32 |
qRegisterMetaType< std::vector<SMPointCloud> >("std::vector<SMPointCloud>");
|
27 |
jakw |
33 |
|
42 |
jakw |
34 |
// Setup ui (requires stream operators registered)
|
|
|
35 |
ui->setupUi(this);
|
|
|
36 |
|
4 |
jakw |
37 |
// Restore geometry
|
|
|
38 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
|
|
39 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
|
|
40 |
|
|
|
41 |
// Set up threads
|
|
|
42 |
captureWorker = new SMCaptureWorker;
|
|
|
43 |
captureWorkerThread = new QThread(this);
|
|
|
44 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
|
|
45 |
captureWorker->moveToThread(captureWorkerThread);
|
|
|
46 |
captureWorkerThread->start();
|
|
|
47 |
|
|
|
48 |
// Connections
|
23 |
jakw |
49 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
27 |
jakw |
50 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
|
|
51 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
30 |
jakw |
52 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
4 |
jakw |
53 |
|
|
|
54 |
// Start capturing
|
|
|
55 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
|
|
56 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
|
|
57 |
|
148 |
jakw |
58 |
|
|
|
59 |
//ui->captureCamera0ScrollArea->setWidget(ui->captureCamera0Widget);
|
|
|
60 |
|
1 |
jakw |
61 |
}
|
|
|
62 |
|
23 |
jakw |
63 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
4 |
jakw |
64 |
|
23 |
jakw |
65 |
if(camId == 0){
|
25 |
jakw |
66 |
if(!calibrationReviewMode)
|
|
|
67 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
27 |
jakw |
68 |
if(!captureReviewMode)
|
|
|
69 |
ui->captureCamera0Widget->showImageCV(frame);
|
23 |
jakw |
70 |
} else if(camId == 1){
|
25 |
jakw |
71 |
if(!calibrationReviewMode)
|
|
|
72 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
27 |
jakw |
73 |
if(!captureReviewMode)
|
|
|
74 |
ui->captureCamera1Widget->showImageCV(frame);
|
23 |
jakw |
75 |
}
|
|
|
76 |
}
|
4 |
jakw |
77 |
|
23 |
jakw |
78 |
void SMScanner::on_actionPreferences_triggered(){
|
4 |
jakw |
79 |
|
74 |
jakw |
80 |
connect(&preferenceDialog, SIGNAL(accepted()), this, SLOT(onPreferencesChanged()));
|
73 |
jakw |
81 |
|
4 |
jakw |
82 |
preferenceDialog.show();
|
|
|
83 |
}
|
|
|
84 |
|
73 |
jakw |
85 |
void SMScanner::onPreferencesChanged(){
|
|
|
86 |
|
137 |
jakw |
87 |
// Stop capturing thread
|
|
|
88 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
|
|
89 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
|
|
90 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
|
|
91 |
captureWorkerThread->quit();
|
|
|
92 |
captureWorkerThread->wait();
|
73 |
jakw |
93 |
|
137 |
jakw |
94 |
// Restart capture worker
|
|
|
95 |
captureWorker = new SMCaptureWorker;
|
|
|
96 |
captureWorkerThread = new QThread(this);
|
|
|
97 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
|
|
98 |
captureWorker->moveToThread(captureWorkerThread);
|
|
|
99 |
captureWorkerThread->start();
|
73 |
jakw |
100 |
|
137 |
jakw |
101 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
|
|
102 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
|
|
103 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
|
|
104 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
74 |
jakw |
105 |
|
137 |
jakw |
106 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
|
|
107 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
74 |
jakw |
108 |
|
137 |
jakw |
109 |
// QMessageBox::warning(this, "Information", "You must quit and restart the program for new settings to take effect!", QMessageBox::Ok);
|
74 |
jakw |
110 |
|
73 |
jakw |
111 |
}
|
|
|
112 |
|
4 |
jakw |
113 |
void SMScanner::closeEvent(QCloseEvent *event){
|
|
|
114 |
|
23 |
jakw |
115 |
// Stop capturing thread
|
|
|
116 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
|
|
117 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
|
|
118 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
|
|
119 |
captureWorkerThread->quit();
|
|
|
120 |
captureWorkerThread->wait();
|
|
|
121 |
|
4 |
jakw |
122 |
// Save window geometry
|
|
|
123 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
|
|
124 |
settings.setValue("state/mainwindow", this->saveState());
|
|
|
125 |
|
|
|
126 |
event->accept();
|
|
|
127 |
|
|
|
128 |
}
|
|
|
129 |
|
2 |
jakw |
130 |
SMScanner::~SMScanner(){
|
1 |
jakw |
131 |
delete ui;
|
|
|
132 |
}
|
4 |
jakw |
133 |
|
23 |
jakw |
134 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
|
|
135 |
|
25 |
jakw |
136 |
// If in review mode, go back to aquisition mode
|
|
|
137 |
if(calibrationReviewMode){
|
26 |
jakw |
138 |
ui->calibrationListWidget->clearSelection();
|
25 |
jakw |
139 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
|
|
140 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
|
|
141 |
calibrationReviewMode = false;
|
|
|
142 |
return;
|
|
|
143 |
}
|
|
|
144 |
|
27 |
jakw |
145 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, -1.0));
|
23 |
jakw |
146 |
|
|
|
147 |
}
|
|
|
148 |
|
30 |
jakw |
149 |
|
|
|
150 |
void SMScanner::on_batchCalibrationButton_clicked(){
|
|
|
151 |
|
|
|
152 |
// If in review mode, go back to aquisition mode
|
|
|
153 |
if(calibrationReviewMode){
|
|
|
154 |
ui->calibrationListWidget->clearSelection();
|
|
|
155 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
|
|
156 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
|
|
157 |
calibrationReviewMode = false;
|
|
|
158 |
return;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
// Construct vector of angles
|
|
|
162 |
int angleStart = ui->calibrationBatchStartSpinBox->value();
|
|
|
163 |
int angleEnd = ui->calibrationBatchEndSpinBox->value();
|
|
|
164 |
int angleStep = ui->calibrationBatchStepSpinBox->value();
|
|
|
165 |
|
|
|
166 |
if(angleStart > angleEnd)
|
|
|
167 |
angleEnd += 360;
|
|
|
168 |
|
|
|
169 |
std::vector<float> angles;
|
|
|
170 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
|
|
171 |
angles.push_back(i % 360);
|
|
|
172 |
|
|
|
173 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSets", Q_ARG(std::vector<float>, angles));
|
|
|
174 |
|
|
|
175 |
std::cout << "Aquiring sets at ";
|
75 |
jakw |
176 |
for(unsigned int i=0; i<angles.size(); i++)
|
30 |
jakw |
177 |
std::cout << angles[i] << " ";
|
|
|
178 |
std::cout << " degrees" <<std::endl;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
23 |
jakw |
182 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
27 |
jakw |
183 |
|
23 |
jakw |
184 |
float angle = ui->calibrationRotationDial->value();
|
|
|
185 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
186 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
27 |
jakw |
187 |
|
159 |
jakw |
188 |
ui->calibrationRotationSpinBox->setValue(angle);
|
|
|
189 |
|
|
|
190 |
ui->captureRotationDial->setValue(angle);
|
|
|
191 |
ui->captureRotationSpinBox->setValue(angle);
|
23 |
jakw |
192 |
}
|
24 |
jakw |
193 |
|
159 |
jakw |
194 |
|
|
|
195 |
void SMScanner::on_calibrationRotationSpinBox_editingFinished(){
|
|
|
196 |
|
|
|
197 |
float angle = ui->calibrationRotationSpinBox->value();
|
|
|
198 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
199 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
200 |
|
|
|
201 |
ui->calibrationRotationDial->setValue(angle);
|
|
|
202 |
|
|
|
203 |
ui->captureRotationSpinBox->setValue(angle);
|
|
|
204 |
ui->captureRotationDial->setValue(angle);
|
|
|
205 |
}
|
|
|
206 |
|
27 |
jakw |
207 |
void SMScanner::onReceiveCalibrationSet(SMCalibrationSet calibrationSet){
|
123 |
jakw |
208 |
|
|
|
209 |
int id = ui->calibrationListWidget->count();
|
|
|
210 |
calibrationSet.id = id;
|
|
|
211 |
|
23 |
jakw |
212 |
calibrationData.push_back(calibrationSet);
|
25 |
jakw |
213 |
|
|
|
214 |
// Add identifier to list
|
123 |
jakw |
215 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
25 |
jakw |
216 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
|
217 |
item->setCheckState(Qt::Checked);
|
|
|
218 |
ui->calibrationListWidget->addItem(item);
|
|
|
219 |
|
|
|
220 |
// Set enabled checkmark
|
|
|
221 |
if(calibrationData.size() >= 2)
|
|
|
222 |
ui->calibrateButton->setEnabled(true);
|
23 |
jakw |
223 |
}
|
25 |
jakw |
224 |
|
27 |
jakw |
225 |
void SMScanner::on_calibrateButton_clicked(){
|
25 |
jakw |
226 |
|
29 |
jakw |
227 |
// disable ui elements
|
|
|
228 |
ui->calibrateButton->setEnabled(false);
|
|
|
229 |
ui->calibrationFrame->setEnabled(false);
|
27 |
jakw |
230 |
|
|
|
231 |
// set checked flags
|
75 |
jakw |
232 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
27 |
jakw |
233 |
calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
// SMCalibrationWorker calibrationWorker;
|
|
|
237 |
// calibrationWorker.performCalibration(calibrationData);
|
|
|
238 |
|
|
|
239 |
// Set up calibration thread
|
78 |
jakw |
240 |
calibrationWorker = new SMCalibrationWorker;
|
27 |
jakw |
241 |
calibrationWorkerThread = new QThread(this);
|
|
|
242 |
calibrationWorkerThread->setObjectName("calibrationWorkerThread");
|
123 |
jakw |
243 |
calibrationWorker->moveToThread(calibrationWorkerThread);
|
27 |
jakw |
244 |
calibrationWorkerThread->start();
|
|
|
245 |
|
|
|
246 |
// Connections
|
28 |
jakw |
247 |
connect(calibrationWorker, SIGNAL(newSetProcessed(int)), this, SLOT(onCalibrationSetProcessed(int)));
|
29 |
jakw |
248 |
connect(calibrationWorker, SIGNAL(newFrameResult(int,int,bool,cv::Mat)), this, SLOT(onCalibrationFrameResult(int,int,bool,cv::Mat)));
|
27 |
jakw |
249 |
connect(calibrationWorker, SIGNAL(done()), this, SLOT(onCalibrationDone()));
|
32 |
jakw |
250 |
connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
|
27 |
jakw |
251 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
|
|
|
252 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
|
|
|
253 |
|
32 |
jakw |
254 |
// Start calibration
|
207 |
flgw |
255 |
QMetaObject::invokeMethod(calibrationWorker, "performCameraCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
27 |
jakw |
256 |
|
|
|
257 |
}
|
|
|
258 |
|
30 |
jakw |
259 |
|
|
|
260 |
|
27 |
jakw |
261 |
void SMScanner::onCalibrationSetProcessed(int idx){
|
|
|
262 |
|
137 |
jakw |
263 |
if(calibrationData[idx].frame0Result.empty() && calibrationData[idx].frame1Result.empty())
|
|
|
264 |
ui->calibrationListWidget->item(idx)->setCheckState(Qt::Unchecked);
|
|
|
265 |
|
27 |
jakw |
266 |
ui->calibrationListWidget->setCurrentRow(idx);
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
void SMScanner::onCalibrationDone(){
|
|
|
270 |
|
|
|
271 |
std::cout << "Calibration done!" << std::endl;
|
29 |
jakw |
272 |
ui->calibrateButton->setEnabled(true);
|
|
|
273 |
ui->calibrationFrame->setEnabled(true);
|
27 |
jakw |
274 |
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
|
|
|
278 |
|
|
|
279 |
// if selection is just cleared
|
|
|
280 |
if(ui->calibrationListWidget->selectedItems().empty())
|
|
|
281 |
return;
|
|
|
282 |
|
207 |
flgw |
283 |
// clamp to available range
|
222 |
flgw |
284 |
if(ui->calibrationListWidget->currentRow() < 0)
|
|
|
285 |
return;
|
|
|
286 |
assert(ui->calibrationListWidget->currentRow() < calibrationData.size());
|
207 |
flgw |
287 |
int currentRow = std::min(int(calibrationData.size())-1,
|
|
|
288 |
std::max(0, ui->calibrationListWidget->currentRow()));
|
27 |
jakw |
289 |
|
25 |
jakw |
290 |
calibrationReviewMode = true;
|
|
|
291 |
ui->singleCalibrationButton->setText("Live View");
|
|
|
292 |
ui->batchCalibrationButton->setText("Live View");
|
|
|
293 |
|
222 |
flgw |
294 |
if(calibrationData[currentRow].frame0Result.empty())
|
|
|
295 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
|
|
296 |
else
|
25 |
jakw |
297 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
222 |
flgw |
298 |
|
|
|
299 |
if(calibrationData[currentRow].frame1Result.empty())
|
|
|
300 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
25 |
jakw |
301 |
else
|
|
|
302 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
27 |
jakw |
303 |
|
|
|
304 |
// std::cout << "on_calibrationListWidget_itemSelectionChanged" << std::endl;
|
25 |
jakw |
305 |
}
|
|
|
306 |
|
29 |
jakw |
307 |
void SMScanner::onCalibrationFrameResult(int idx, int camID, bool success, cv::Mat result){
|
25 |
jakw |
308 |
|
137 |
jakw |
309 |
if(success){
|
29 |
jakw |
310 |
if(camID == 0)
|
|
|
311 |
calibrationData[idx].frame0Result = result;
|
|
|
312 |
else if(camID == 1)
|
|
|
313 |
calibrationData[idx].frame1Result = result;
|
|
|
314 |
}
|
27 |
jakw |
315 |
|
|
|
316 |
}
|
|
|
317 |
|
159 |
jakw |
318 |
void SMScanner::on_captureRotationDial_sliderReleased(){
|
|
|
319 |
|
|
|
320 |
float angle = ui->captureRotationDial->value();
|
|
|
321 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
322 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
323 |
|
|
|
324 |
ui->captureRotationSpinBox->setValue(ui->captureRotationDial->value());
|
|
|
325 |
|
|
|
326 |
ui->calibrationRotationDial->setValue(ui->captureRotationDial->value());
|
|
|
327 |
ui->calibrationRotationSpinBox->setValue(ui->captureRotationDial->value());
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
void SMScanner::on_captureRotationSpinBox_editingFinished(){
|
|
|
331 |
|
|
|
332 |
float angle = ui->captureRotationSpinBox->value();
|
|
|
333 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
334 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
335 |
|
|
|
336 |
ui->captureRotationDial->setValue(angle);
|
|
|
337 |
|
|
|
338 |
ui->calibrationRotationSpinBox->setValue(angle);
|
|
|
339 |
ui->calibrationRotationDial->setValue(angle);
|
|
|
340 |
}
|
|
|
341 |
|
27 |
jakw |
342 |
void SMScanner::on_singleCaptureButton_clicked(){
|
|
|
343 |
|
|
|
344 |
// If in review mode, go back to aquisition mode
|
|
|
345 |
if(captureReviewMode){
|
|
|
346 |
ui->captureTreeWidget->clearSelection();
|
|
|
347 |
ui->singleCaptureButton->setText("Single Aquisition");
|
|
|
348 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
|
|
349 |
captureReviewMode = false;
|
|
|
350 |
return;
|
25 |
jakw |
351 |
}
|
|
|
352 |
|
27 |
jakw |
353 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequence", Q_ARG(float, -1.0));
|
25 |
jakw |
354 |
|
|
|
355 |
}
|
26 |
jakw |
356 |
|
27 |
jakw |
357 |
|
30 |
jakw |
358 |
void SMScanner::on_batchCaptureButton_clicked(){
|
|
|
359 |
|
|
|
360 |
// If in review mode, go back to aquisition mode
|
|
|
361 |
if(captureReviewMode){
|
|
|
362 |
ui->captureTreeWidget->clearSelection();
|
|
|
363 |
ui->singleCaptureButton->setText("Single Aquisition");
|
|
|
364 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
|
|
365 |
captureReviewMode = false;
|
|
|
366 |
return;
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
// Construct vector of angles
|
|
|
370 |
int angleStart = ui->captureBatchStartSpinBox->value();
|
|
|
371 |
int angleEnd = ui->captureBatchEndSpinBox->value();
|
|
|
372 |
int angleStep = ui->captureBatchStepSpinBox->value();
|
|
|
373 |
|
|
|
374 |
if(angleStart > angleEnd)
|
|
|
375 |
angleEnd += 360;
|
|
|
376 |
|
|
|
377 |
std::vector<float> angles;
|
|
|
378 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
|
|
379 |
angles.push_back(i % 360);
|
|
|
380 |
|
|
|
381 |
std::cout << "Aquiring sequences at ";
|
75 |
jakw |
382 |
for(unsigned int i=0; i<angles.size(); i++)
|
30 |
jakw |
383 |
std::cout << angles[i] << " ";
|
|
|
384 |
std::cout << " degrees" <<std::endl;
|
|
|
385 |
|
|
|
386 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
|
|
|
387 |
}
|
|
|
388 |
|
27 |
jakw |
389 |
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
|
207 |
flgw |
390 |
frameSequence.id = ++lastCaptureId;
|
27 |
jakw |
391 |
captureData.push_back(frameSequence);
|
|
|
392 |
|
|
|
393 |
// Add identifier to list
|
|
|
394 |
QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
|
207 |
flgw |
395 |
item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(frameSequence.id).arg(frameSequence.rotationAngle));
|
139 |
jakw |
396 |
//item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
67 |
jakw |
397 |
item->setData(0, Qt::UserRole, QPoint(captureData.size()-1, -1));
|
139 |
jakw |
398 |
//item->setCheckState(0, Qt::Checked);
|
27 |
jakw |
399 |
//ui->captureTreeWidget->addItem(item);
|
|
|
400 |
|
103 |
jakw |
401 |
for(unsigned int i=0; i<frameSequence.frames0.size(); i++){
|
27 |
jakw |
402 |
QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
|
|
|
403 |
subItem->setText(0, QString("frames %1").arg(i));
|
207 |
flgw |
404 |
subItem->setData(0, Qt::UserRole, QPoint(frameSequence.id, i));
|
27 |
jakw |
405 |
}
|
41 |
jakw |
406 |
|
|
|
407 |
ui->reconstructButton->setEnabled(true);
|
27 |
jakw |
408 |
}
|
|
|
409 |
|
|
|
410 |
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
|
|
|
411 |
|
|
|
412 |
// if selection is just cleared
|
|
|
413 |
if(ui->captureTreeWidget->selectedItems().empty())
|
|
|
414 |
return;
|
|
|
415 |
|
|
|
416 |
QTreeWidgetItem *item = ui->captureTreeWidget->currentItem();
|
|
|
417 |
|
|
|
418 |
captureReviewMode = true;
|
|
|
419 |
|
|
|
420 |
ui->singleCaptureButton->setText("Live View");
|
|
|
421 |
ui->batchCaptureButton->setText("Live View");
|
|
|
422 |
|
|
|
423 |
QPoint idx = item->data(0, Qt::UserRole).toPoint();
|
|
|
424 |
|
207 |
flgw |
425 |
if( idx.y() != -1 && idx.x()>=0 && idx.x()<captureData.size()
|
|
|
426 |
&& idx.y()<captureData[idx.x()].frames0.size()
|
|
|
427 |
&& idx.y()<captureData[idx.x()].frames1.size() ){
|
|
|
428 |
// TODO idx.x() can & WILL be out of bounds
|
103 |
jakw |
429 |
ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
|
|
|
430 |
ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
|
27 |
jakw |
431 |
}
|
|
|
432 |
// std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
|
|
|
433 |
}
|
30 |
jakw |
434 |
|
|
|
435 |
|
|
|
436 |
void SMScanner::onReceiveRotatedTo(float angle){
|
|
|
437 |
|
|
|
438 |
// update ui with new position
|
|
|
439 |
ui->calibrationRotationDial->setValue(angle);
|
|
|
440 |
ui->captureRotationDial->setValue(angle);
|
|
|
441 |
|
159 |
jakw |
442 |
ui->calibrationRotationSpinBox->setValue(angle);
|
|
|
443 |
ui->captureRotationSpinBox->setValue(angle);
|
30 |
jakw |
444 |
}
|
36 |
jakw |
445 |
|
|
|
446 |
void SMScanner::on_actionExport_Sets_triggered(){
|
|
|
447 |
|
143 |
jakw |
448 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export calibration sets", QString());
|
|
|
449 |
|
|
|
450 |
QProgressDialog progressDialog("Exporting Sets...", "Cancel", 0, 100, this);
|
|
|
451 |
progressDialog.setWindowModality(Qt::WindowModal);
|
|
|
452 |
progressDialog.setMinimumDuration(1000);
|
|
|
453 |
|
|
|
454 |
progressDialog.show();
|
112 |
jakw |
455 |
cv::Mat frameBGR;
|
75 |
jakw |
456 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
36 |
jakw |
457 |
QString fileName = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
136 |
jakw |
458 |
|
143 |
jakw |
459 |
progressDialog.setValue(100.0*i/calibrationData.size());
|
|
|
460 |
|
136 |
jakw |
461 |
// Convert to BGR
|
|
|
462 |
if(calibrationData[i].frame0.channels() == 1)
|
|
|
463 |
cv::cvtColor(calibrationData[i].frame0, frameBGR, CV_BayerBG2BGR);
|
|
|
464 |
else
|
|
|
465 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
|
|
466 |
|
36 |
jakw |
467 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
|
|
468 |
fileName = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
136 |
jakw |
469 |
|
|
|
470 |
// Convert to BGR
|
|
|
471 |
if(calibrationData[i].frame1.channels() == 1)
|
|
|
472 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_BayerBG2BGR);
|
|
|
473 |
else
|
|
|
474 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
|
|
475 |
|
36 |
jakw |
476 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
137 |
jakw |
477 |
|
|
|
478 |
// Necessary to prevent pileup of video frame signals
|
112 |
jakw |
479 |
QCoreApplication::processEvents();
|
143 |
jakw |
480 |
|
|
|
481 |
if(progressDialog.wasCanceled())
|
|
|
482 |
return;
|
36 |
jakw |
483 |
}
|
|
|
484 |
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
void SMScanner::on_actionExport_Sequences_triggered(){
|
|
|
488 |
|
143 |
jakw |
489 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
|
|
490 |
|
|
|
491 |
QProgressDialog progressDialog("Exporting Sequences...", "Cancel", 0, 100, this);
|
142 |
jakw |
492 |
progressDialog.setWindowModality(Qt::WindowModal);
|
141 |
jakw |
493 |
progressDialog.setMinimumDuration(1000);
|
|
|
494 |
|
142 |
jakw |
495 |
progressDialog.show();
|
141 |
jakw |
496 |
|
112 |
jakw |
497 |
cv::Mat frameBGR;
|
103 |
jakw |
498 |
for(unsigned int i=0; i<captureData.size(); i++){
|
141 |
jakw |
499 |
|
103 |
jakw |
500 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
|
|
501 |
if(!QDir().mkdir(seqDirName))
|
|
|
502 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
|
|
503 |
for(unsigned int j=0; j<captureData[i].frames0.size(); j++){
|
142 |
jakw |
504 |
|
143 |
jakw |
505 |
progressDialog.setValue(100.0*i/captureData.size() + 100.0/captureData.size()*j/captureData[i].frames0.size());
|
142 |
jakw |
506 |
|
|
|
507 |
QString fileName0 = QString("%1/frames0_%2.png").arg(seqDirName).arg(j);
|
113 |
jakw |
508 |
// Convert Bayer to rgb (png needs BGR order)
|
|
|
509 |
cv::cvtColor(captureData[i].frames0[j], frameBGR, CV_BayerBG2BGR);
|
142 |
jakw |
510 |
cv::imwrite(fileName0.toStdString(), frameBGR);
|
137 |
jakw |
511 |
|
|
|
512 |
// Necessary to prevent pileup of video frame signals
|
112 |
jakw |
513 |
QCoreApplication::processEvents();
|
142 |
jakw |
514 |
|
|
|
515 |
QString fileName1 = QString("%1/frames1_%2.png").arg(seqDirName).arg(j);
|
113 |
jakw |
516 |
// Convert Bayer to rgb (png needs BGR order)
|
|
|
517 |
cv::cvtColor(captureData[i].frames1[j], frameBGR, CV_BayerBG2BGR);
|
142 |
jakw |
518 |
cv::imwrite(fileName1.toStdString(), frameBGR);
|
137 |
jakw |
519 |
|
|
|
520 |
// Necessary to prevent pileup of video frame signals
|
112 |
jakw |
521 |
QCoreApplication::processEvents();
|
142 |
jakw |
522 |
if(progressDialog.wasCanceled())
|
|
|
523 |
return;
|
103 |
jakw |
524 |
}
|
|
|
525 |
}
|
36 |
jakw |
526 |
}
|
41 |
jakw |
527 |
|
115 |
jakw |
528 |
void SMScanner::on_actionExport_White_Frames_triggered(){
|
|
|
529 |
|
143 |
jakw |
530 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
|
|
531 |
|
|
|
532 |
QProgressDialog progressDialog("Exporting White Frames...", "Cancel", 0, 100, this);
|
|
|
533 |
progressDialog.setWindowModality(Qt::WindowModal);
|
|
|
534 |
progressDialog.setMinimumDuration(1000);
|
|
|
535 |
|
115 |
jakw |
536 |
cv::Mat frameBGR;
|
|
|
537 |
for(unsigned int i=0; i<captureData.size(); i++){
|
143 |
jakw |
538 |
|
|
|
539 |
progressDialog.setValue(100.0*i/captureData.size());
|
|
|
540 |
|
115 |
jakw |
541 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
|
|
542 |
if(!QDir().mkdir(seqDirName))
|
|
|
543 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
|
|
544 |
|
|
|
545 |
QString fileName = QString("%1/frames0_0.png").arg(seqDirName);
|
|
|
546 |
// Convert Bayer to rgb (png needs BGR order)
|
|
|
547 |
cv::cvtColor(captureData[i].frames0[0], frameBGR, CV_BayerBG2BGR);
|
|
|
548 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
128 |
jakw |
549 |
// Necessary to prevent memory pileup
|
115 |
jakw |
550 |
QCoreApplication::processEvents();
|
|
|
551 |
|
|
|
552 |
fileName = QString("%1/frames1_0.png").arg(seqDirName);
|
|
|
553 |
// Convert Bayer to rgb (png needs BGR order)
|
|
|
554 |
cv::cvtColor(captureData[i].frames1[0], frameBGR, CV_BayerBG2BGR);
|
|
|
555 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
128 |
jakw |
556 |
// Necessary to prevent memory pileup
|
115 |
jakw |
557 |
QCoreApplication::processEvents();
|
143 |
jakw |
558 |
if(progressDialog.wasCanceled())
|
|
|
559 |
return;
|
115 |
jakw |
560 |
}
|
|
|
561 |
|
|
|
562 |
}
|
|
|
563 |
|
41 |
jakw |
564 |
void SMScanner::on_reconstructButton_clicked(){
|
|
|
565 |
|
|
|
566 |
// Set up reconstruction thread
|
|
|
567 |
reconstructionWorker = new SMReconstructionWorker;
|
|
|
568 |
reconstructionWorkerThread = new QThread(this);
|
|
|
569 |
reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
|
|
|
570 |
reconstructionWorker->moveToThread(reconstructionWorkerThread);
|
|
|
571 |
reconstructionWorkerThread->start();
|
|
|
572 |
|
|
|
573 |
// Connections
|
148 |
jakw |
574 |
connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onReceivePointCloud(SMPointCloud)));
|
41 |
jakw |
575 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
|
|
|
576 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
|
|
|
577 |
|
|
|
578 |
// Start reconstructing
|
42 |
jakw |
579 |
QMetaObject::invokeMethod(reconstructionWorker, "setup");
|
41 |
jakw |
580 |
|
207 |
flgw |
581 |
// TODO is a reference working here??
|
|
|
582 |
QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointClouds", Q_ARG(std::vector<SMFrameSequence>, captureData));
|
75 |
jakw |
583 |
for(unsigned int i=0; i<captureData.size(); i++){
|
139 |
jakw |
584 |
if(!captureData[i].reconstructed){ // & (ui->captureTreeWidget->topLevelItem(i)->checkState(0) == Qt::Checked))
|
|
|
585 |
captureData[i].reconstructed = true;
|
207 |
flgw |
586 |
// now done before QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointCloud", Q_ARG(SMFrameSequence, captureData[i]));
|
139 |
jakw |
587 |
}
|
45 |
jakw |
588 |
}
|
41 |
jakw |
589 |
}
|
|
|
590 |
|
208 |
flgw |
591 |
void SMScanner::on_meshButton_clicked(){
|
|
|
592 |
|
217 |
jakw |
593 |
// // Set up reconstruction thread
|
|
|
594 |
// meshWorker = new SMMeshingWorker;
|
|
|
595 |
// meshWorkerThread = new QThread(this);
|
|
|
596 |
// meshWorkerThread->setObjectName("meshWorkerThread");
|
|
|
597 |
// meshWorker->moveToThread(meshWorkerThread);
|
|
|
598 |
// meshWorkerThread->start();
|
208 |
flgw |
599 |
|
217 |
jakw |
600 |
// // Connections
|
|
|
601 |
// //connect(meshWorker, SIGNAL(newMesh(pcl::PolygonMesh)), this, SLOT(onReceiveMesh(pcl::PolygonMesh)));
|
|
|
602 |
// //connect(meshWorker, SIGNAL(done()), meshWorkerThread, SLOT(quit()));
|
|
|
603 |
// //connect(meshWorker, SIGNAL(done()), meshWorker, SLOT(deleteLater()));
|
208 |
flgw |
604 |
|
217 |
jakw |
605 |
// // Start reconstructing
|
|
|
606 |
// //QMetaObject::invokeMethod(meshWorker, "setup");
|
208 |
flgw |
607 |
|
217 |
jakw |
608 |
// // TODO is a reference working here??
|
|
|
609 |
// QMetaObject::invokeMethod(meshWorker, "reconstructMesh",
|
|
|
610 |
// Q_ARG(std::vector<SMPointCloud>, pointCloudData));
|
208 |
flgw |
611 |
}
|
|
|
612 |
|
148 |
jakw |
613 |
void SMScanner::onReceivePointCloud(SMPointCloud smCloud){
|
139 |
jakw |
614 |
// for(int i=0; i<captureData.size(); i++){
|
|
|
615 |
// if(captureData[i].id == id)
|
|
|
616 |
// captureData[i].reconstructed = true;
|
|
|
617 |
// }
|
82 |
jakw |
618 |
|
207 |
flgw |
619 |
//pointCloudData.push_back(smCloud);
|
208 |
flgw |
620 |
// TODO on demand resizing here is evil
|
207 |
flgw |
621 |
if(pointCloudData.size()<=smCloud.id) pointCloudData.resize(smCloud.id+1);
|
|
|
622 |
pointCloudData[smCloud.id] = smCloud;
|
41 |
jakw |
623 |
|
42 |
jakw |
624 |
// Add identifier to list
|
207 |
flgw |
625 |
QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(smCloud.id).arg(smCloud.rotationAngle));
|
42 |
jakw |
626 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
207 |
flgw |
627 |
item->setData(Qt::UserRole, QVariant(smCloud.id));
|
42 |
jakw |
628 |
item->setCheckState(Qt::Checked);
|
44 |
jakw |
629 |
|
42 |
jakw |
630 |
ui->pointCloudsListWidget->addItem(item);
|
207 |
flgw |
631 |
ui->pointCloudWidget->addPointCloud(smCloud, smCloud.id);
|
208 |
flgw |
632 |
|
|
|
633 |
// TODO just to test
|
|
|
634 |
on_meshButton_clicked();
|
41 |
jakw |
635 |
}
|
42 |
jakw |
636 |
|
44 |
jakw |
637 |
void SMScanner::on_actionExport_Point_Clouds_triggered(){
|
|
|
638 |
|
|
|
639 |
QString directory = QFileDialog::getExistingDirectory(this, "Export Point Clouds", QString());
|
|
|
640 |
|
|
|
641 |
// // Non native file dialog
|
|
|
642 |
// QFileDialog saveDirectoryDialog(this, "Export Point Clouds", QString(), "*.pcd;;*.ply;;*.vtk;;*.png;;*.txt");
|
|
|
643 |
// saveDirectoryDialog.setDefaultSuffix("ply");
|
|
|
644 |
// saveDirectoryDialog.setFileMode(QFileDialog::Directory);
|
|
|
645 |
// saveDirectoryDialog.exec();
|
|
|
646 |
// QString directory = saveDirectoryDialog.directory().path();
|
|
|
647 |
// QString type = saveDirectoryDialog.selectedNameFilter();
|
|
|
648 |
|
144 |
jakw |
649 |
QProgressDialog progressDialog("Exporting Point Clouds...", "Cancel", 0, 100, this);
|
143 |
jakw |
650 |
progressDialog.setWindowModality(Qt::WindowModal);
|
|
|
651 |
progressDialog.setMinimumDuration(1000);
|
|
|
652 |
|
44 |
jakw |
653 |
// save point clouds in ply format
|
75 |
jakw |
654 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
143 |
jakw |
655 |
|
|
|
656 |
progressDialog.setValue(100.0*i/pointCloudData.size());
|
207 |
flgw |
657 |
if(pointCloudData[i].id != -1){
|
44 |
jakw |
658 |
QString fileName = QString("%1/pointcloud_%2.ply").arg(directory).arg(i);
|
128 |
jakw |
659 |
pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr pointCloudPCL(pointCloudData[i].pointCloud);
|
44 |
jakw |
660 |
//pcl::io::savePLYFileBinary(fileName.toStdString(), *pointCloudPCL);
|
|
|
661 |
pcl::PLYWriter w;
|
|
|
662 |
// Write to ply in binary without camera
|
128 |
jakw |
663 |
w.write<pcl::PointXYZRGBNormal> (fileName.toStdString(), *pointCloudPCL, true, false);
|
207 |
flgw |
664 |
}
|
143 |
jakw |
665 |
QCoreApplication::processEvents();
|
|
|
666 |
if(progressDialog.wasCanceled())
|
|
|
667 |
return;
|
44 |
jakw |
668 |
}
|
|
|
669 |
|
|
|
670 |
// save meshlab aln project file
|
|
|
671 |
std::ofstream s(QString("%1/alignment.aln").arg(directory).toLocal8Bit());
|
|
|
672 |
s << pointCloudData.size() << std::endl;
|
75 |
jakw |
673 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
207 |
flgw |
674 |
if(pointCloudData[i].id != -1){
|
|
|
675 |
QString fileName = QString("pointcloud_%1.ply").arg(pointCloudData[i].id);
|
44 |
jakw |
676 |
s << fileName.toStdString() << std::endl << "#" << std::endl;
|
|
|
677 |
cv::Mat Tr = cv::Mat::eye(4, 4, CV_32F);
|
|
|
678 |
cv::Mat(pointCloudData[i].R.t()).copyTo(Tr.colRange(0, 3).rowRange(0, 3));
|
|
|
679 |
cv::Mat(-pointCloudData[i].R.t()*pointCloudData[i].T).copyTo(Tr.col(3).rowRange(0, 3));
|
|
|
680 |
for(int j=0; j<Tr.rows; j++){
|
|
|
681 |
for(int k=0; k<Tr.cols; k++){
|
|
|
682 |
s << Tr.at<float>(j,k) << " ";
|
|
|
683 |
}
|
|
|
684 |
s << std::endl;
|
|
|
685 |
}
|
207 |
flgw |
686 |
}
|
44 |
jakw |
687 |
}
|
|
|
688 |
s << "0" << std::flush;
|
|
|
689 |
s.close();
|
|
|
690 |
}
|
|
|
691 |
|
|
|
692 |
void SMScanner::on_pointCloudsListWidget_itemChanged(QListWidgetItem *item){
|
|
|
693 |
|
|
|
694 |
int id = item->data(Qt::UserRole).toInt();
|
207 |
flgw |
695 |
assert(pointCloudData.size()>id);
|
|
|
696 |
if(item->checkState() == Qt::Checked){
|
|
|
697 |
id = std::min(int(pointCloudData.size())-1,std::max(0,id));// clamp range
|
44 |
jakw |
698 |
ui->pointCloudWidget->addPointCloud(pointCloudData[id], id);
|
207 |
flgw |
699 |
}
|
44 |
jakw |
700 |
else
|
|
|
701 |
ui->pointCloudWidget->removePointCloud(id);
|
|
|
702 |
|
|
|
703 |
}
|
|
|
704 |
|
|
|
705 |
void SMScanner::on_actionExport_Parameters_triggered(){
|
|
|
706 |
|
42 |
jakw |
707 |
QString fileName = QFileDialog::getSaveFileName(this, "Export calibration parameters", QString(), "*.xml");
|
|
|
708 |
QFileInfo info(fileName);
|
|
|
709 |
QString type = info.suffix();
|
|
|
710 |
if(type == ""){
|
|
|
711 |
fileName.append(".xml");
|
|
|
712 |
}
|
|
|
713 |
|
|
|
714 |
SMCalibrationParameters calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
|
|
|
715 |
calibration.exportToXML(fileName);
|
|
|
716 |
}
|
67 |
jakw |
717 |
|
|
|
718 |
void SMScanner::on_actionClear_Sequences_triggered(){
|
|
|
719 |
|
|
|
720 |
int res = QMessageBox::question(this, "Clear Captured Sequences", "Clear all captured data?", QMessageBox::Ok, QMessageBox::Cancel);
|
|
|
721 |
|
|
|
722 |
if(res == QMessageBox::Ok){
|
|
|
723 |
captureData.clear();
|
|
|
724 |
ui->captureTreeWidget->clear();
|
207 |
flgw |
725 |
lastCaptureId=-1;
|
67 |
jakw |
726 |
}
|
|
|
727 |
}
|
115 |
jakw |
728 |
|
|
|
729 |
|
135 |
jakw |
730 |
|
|
|
731 |
void SMScanner::on_actionImport_Parameters_triggered(){
|
|
|
732 |
|
|
|
733 |
QString fileName = QFileDialog::getOpenFileName(this, "Import calibration parameters", QString(), "*.xml");
|
|
|
734 |
QFileInfo info(fileName);
|
|
|
735 |
QString type = info.suffix();
|
136 |
jakw |
736 |
if(type != "xml"){
|
135 |
jakw |
737 |
std::cerr << "Error: calibration parameters must be in .xml file." << std::endl;
|
|
|
738 |
return;
|
|
|
739 |
}
|
|
|
740 |
|
|
|
741 |
SMCalibrationParameters cal;
|
|
|
742 |
cal.importFromXML(fileName);
|
|
|
743 |
|
|
|
744 |
settings.setValue("calibration/parameters", QVariant::fromValue(cal));
|
|
|
745 |
ui->pointCloudWidget->updateCalibrationParameters();
|
139 |
jakw |
746 |
|
|
|
747 |
std::cout << "Imported calibration parameters " << fileName.toStdString() << std::endl;
|
135 |
jakw |
748 |
}
|
|
|
749 |
|
|
|
750 |
void SMScanner::on_actionImport_Sets_triggered(){
|
|
|
751 |
|
|
|
752 |
QString dirName = QFileDialog::getExistingDirectory(this, "Import calibration sets", QString());
|
|
|
753 |
|
|
|
754 |
QDir dir(dirName);
|
|
|
755 |
QStringList fileNames0 = dir.entryList(QStringList("frame0_*.png"));
|
|
|
756 |
QStringList fileNames1 = dir.entryList(QStringList("frame1_*.png"));
|
|
|
757 |
|
|
|
758 |
if(fileNames0.empty() || fileNames1.empty() || fileNames0.count() != fileNames1.count()){
|
|
|
759 |
std::cerr << "Error: could not load calibration sets. Directory must contain .png files for both cameras." << std::endl;
|
|
|
760 |
return;
|
|
|
761 |
}
|
|
|
762 |
|
|
|
763 |
calibrationData.clear();
|
|
|
764 |
ui->calibrationListWidget->clear();
|
|
|
765 |
|
143 |
jakw |
766 |
QProgressDialog progressDialog("Importing Sets...", "Cancel", 0, 100, this);
|
|
|
767 |
progressDialog.setWindowModality(Qt::WindowModal);
|
|
|
768 |
progressDialog.setMinimumDuration(1000);
|
|
|
769 |
|
167 |
jakw |
770 |
size_t nSets = fileNames0.size();
|
135 |
jakw |
771 |
for(unsigned int i=0; i<nSets; i++){
|
|
|
772 |
|
143 |
jakw |
773 |
progressDialog.setValue(100.0*i/nSets);
|
|
|
774 |
|
135 |
jakw |
775 |
SMCalibrationSet calibrationSet;
|
|
|
776 |
|
140 |
jakw |
777 |
QString fileName0 = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
139 |
jakw |
778 |
cv::Mat frame0BGR = cv::imread(fileName0.toStdString());
|
|
|
779 |
cvtools::cvtColorBGRToBayerBG(frame0BGR, calibrationSet.frame0);
|
135 |
jakw |
780 |
|
140 |
jakw |
781 |
QString fileName1 = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
139 |
jakw |
782 |
cv::Mat frame1BGR = cv::imread(fileName1.toStdString());
|
|
|
783 |
cvtools::cvtColorBGRToBayerBG(frame1BGR, calibrationSet.frame1);
|
|
|
784 |
|
|
|
785 |
|
135 |
jakw |
786 |
int id = ui->calibrationListWidget->count();
|
|
|
787 |
calibrationSet.id = id;
|
|
|
788 |
|
|
|
789 |
calibrationData.push_back(calibrationSet);
|
|
|
790 |
|
|
|
791 |
// Add identifier to list
|
|
|
792 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
|
|
793 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
196 |
jakw |
794 |
item->setCheckState(Qt::Checked);
|
135 |
jakw |
795 |
ui->calibrationListWidget->addItem(item);
|
|
|
796 |
|
|
|
797 |
QCoreApplication::processEvents();
|
143 |
jakw |
798 |
if(progressDialog.wasCanceled())
|
|
|
799 |
return;
|
135 |
jakw |
800 |
}
|
|
|
801 |
|
|
|
802 |
// Set enabled checkmark
|
|
|
803 |
if(calibrationData.size() >= 2)
|
|
|
804 |
ui->calibrateButton->setEnabled(true);
|
|
|
805 |
}
|
139 |
jakw |
806 |
|
|
|
807 |
void SMScanner::on_actionImport_Sequences_triggered(){
|
|
|
808 |
|
|
|
809 |
// NOTE: we do not know which algorithm was used!!!
|
143 |
jakw |
810 |
|
139 |
jakw |
811 |
QString dirName = QFileDialog::getExistingDirectory(this, "Import captured sequences", QString());
|
|
|
812 |
|
|
|
813 |
QDir dir(dirName);
|
|
|
814 |
QStringList sequenceDirNames = dir.entryList(QStringList("sequence_*"));
|
|
|
815 |
|
|
|
816 |
if(sequenceDirNames.empty()){
|
|
|
817 |
std::cerr << "Error: could not find sequences." << std::endl;
|
|
|
818 |
return;
|
|
|
819 |
}
|
|
|
820 |
|
|
|
821 |
captureData.clear();
|
|
|
822 |
ui->captureTreeWidget->clear();
|
207 |
flgw |
823 |
lastCaptureId=-1;
|
139 |
jakw |
824 |
|
143 |
jakw |
825 |
QProgressDialog progressDialog("Importing Sequences...", "Cancel", 0, 100, this);
|
|
|
826 |
progressDialog.setWindowModality(Qt::WindowModal);
|
|
|
827 |
progressDialog.setMinimumDuration(1000);
|
|
|
828 |
|
139 |
jakw |
829 |
for(int s=0; s<sequenceDirNames.count(); s++){
|
|
|
830 |
|
|
|
831 |
QDir sequenceDir(QString("%1/%2").arg(dirName).arg(sequenceDirNames.at(s)));
|
|
|
832 |
|
|
|
833 |
QStringList fileNames0 = sequenceDir.entryList(QStringList("frames0_*.png"));
|
|
|
834 |
QStringList fileNames1 = sequenceDir.entryList(QStringList("frames1_*.png"));
|
|
|
835 |
|
|
|
836 |
if(fileNames0.empty() || fileNames1.empty() || fileNames0.count() != fileNames1.count()){
|
|
|
837 |
std::cerr << "Error: could not load sequence. Directory must contain .png files for both cameras." << std::endl;
|
|
|
838 |
return;
|
|
|
839 |
}
|
|
|
840 |
|
|
|
841 |
int nFrames = fileNames0.size();
|
|
|
842 |
|
|
|
843 |
SMFrameSequence sequence;
|
|
|
844 |
|
|
|
845 |
for(int f=0; f<nFrames; f++){
|
|
|
846 |
|
143 |
jakw |
847 |
progressDialog.setValue(100.0*s/sequenceDirNames.count() + 100.0/sequenceDirNames.count()*f/nFrames);
|
|
|
848 |
|
139 |
jakw |
849 |
cv::Mat frame0BGR, frame0BayerBG, frame1BGR, frame1BayerBG;
|
|
|
850 |
|
|
|
851 |
QString fileName0 = QString("%1/%2/frames0_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
|
|
852 |
frame0BGR = cv::imread(fileName0.toStdString());
|
|
|
853 |
cvtools::cvtColorBGRToBayerBG(frame0BGR, frame0BayerBG);
|
|
|
854 |
|
|
|
855 |
QString fileName1 = QString("%1/%2/frames1_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
|
|
856 |
frame1BGR = cv::imread(fileName1.toStdString());
|
|
|
857 |
cvtools::cvtColorBGRToBayerBG(frame1BGR, frame1BayerBG);
|
|
|
858 |
|
|
|
859 |
sequence.frames0.push_back(frame0BayerBG);
|
|
|
860 |
sequence.frames1.push_back(frame1BayerBG);
|
|
|
861 |
|
|
|
862 |
QCoreApplication::processEvents();
|
143 |
jakw |
863 |
if(progressDialog.wasCanceled())
|
|
|
864 |
return;
|
139 |
jakw |
865 |
}
|
143 |
jakw |
866 |
|
|
|
867 |
// Assign whatever algorithm is configured
|
139 |
jakw |
868 |
sequence.codec = settings.value("algorithm").toString();
|
|
|
869 |
sequence.rotationAngle = 0;
|
|
|
870 |
sequence.reconstructed = false;
|
|
|
871 |
|
|
|
872 |
onReceiveFrameSequence(sequence);
|
|
|
873 |
}
|
|
|
874 |
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
void SMScanner::on_actionClear_Point_Clouds_triggered(){
|
|
|
878 |
|
|
|
879 |
int res = QMessageBox::question(this, "Clear Reconstructed Point Clouds", "Clear all reconstructed point clouds?", QMessageBox::Ok, QMessageBox::Cancel);
|
|
|
880 |
|
|
|
881 |
if(res == QMessageBox::Ok){
|
|
|
882 |
|
|
|
883 |
pointCloudData.clear();
|
|
|
884 |
ui->pointCloudsListWidget->clear();
|
|
|
885 |
ui->pointCloudWidget->removeAllPointClouds();
|
|
|
886 |
|
167 |
jakw |
887 |
for(unsigned int i=0; i<captureData.size(); i++)
|
139 |
jakw |
888 |
captureData[i].reconstructed = false;
|
|
|
889 |
}
|
|
|
890 |
}
|
159 |
jakw |
891 |
|
199 |
jakw |
892 |
|
|
|
893 |
void SMScanner::on_actionProject_Focusing_Pattern_triggered()
|
|
|
894 |
{
|
|
|
895 |
bool projectFocusingPattern = ui->actionProject_Focusing_Pattern->isChecked();
|
|
|
896 |
QMetaObject::invokeMethod(captureWorker, "setProjectFocusingPattern", Q_ARG(bool, projectFocusingPattern));
|
|
|
897 |
|
|
|
898 |
}
|