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