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