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