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