1 |
jakw |
1 |
#include "SMScanner.h"
|
|
|
2 |
#include "ui_SMScanner.h"
|
|
|
3 |
|
4 |
jakw |
4 |
#include <QMetaObject>
|
36 |
jakw |
5 |
#include <QFileDialog>
|
67 |
jakw |
6 |
#include <QMessageBox>
|
141 |
jakw |
7 |
#include <QProgressDialog>
|
4 |
jakw |
8 |
|
44 |
jakw |
9 |
#include <pcl/io/pcd_io.h>
|
|
|
10 |
#include <pcl/io/ascii_io.h>
|
|
|
11 |
#include <pcl/io/ply_io.h>
|
|
|
12 |
#include <pcl/io/png_io.h>
|
|
|
13 |
#include <pcl/io/vtk_io.h>
|
|
|
14 |
#include <vtkPolyDataWriter.h>
|
|
|
15 |
#include <pcl/conversions.h>
|
|
|
16 |
|
139 |
jakw |
17 |
#include "cvtools.h"
|
|
|
18 |
|
27 |
jakw |
19 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner),
|
67 |
jakw |
20 |
calibrationReviewMode(false), captureReviewMode(false), lastCaptureId(-1){
|
4 |
jakw |
21 |
|
27 |
jakw |
22 |
// Register metatypes
|
|
|
23 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
|
|
24 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
30 |
jakw |
25 |
qRegisterMetaType< std::vector<float> >("std::vector<float>");
|
27 |
jakw |
26 |
qRegisterMetaType<SMCalibrationSet>("SMCalibrationSet");
|
|
|
27 |
qRegisterMetaType< std::vector<SMCalibrationSet> >("std::vector<SMCalibrationSet>");
|
|
|
28 |
qRegisterMetaType<SMFrameSequence>("SMFrameSequence");
|
42 |
jakw |
29 |
qRegisterMetaType< std::vector<SMFrameSequence> >("std::vector<SMFrameSequence>");
|
45 |
jakw |
30 |
qRegisterMetaType<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>("pcl::PointCloud<pcl::PointXYZRGB>::Ptr");
|
42 |
jakw |
31 |
qRegisterMetaType<SMPointCloud>("SMPointCloud");
|
208 |
flgw |
32 |
qRegisterMetaType< std::vector<SMPointCloud> >("std::vector<SMPointCloud>");
|
27 |
jakw |
33 |
|
42 |
jakw |
34 |
// Setup ui (requires stream operators registered)
|
|
|
35 |
ui->setupUi(this);
|
|
|
36 |
|
4 |
jakw |
37 |
// Restore geometry
|
|
|
38 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
|
|
39 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
|
|
40 |
|
|
|
41 |
// Set up threads
|
|
|
42 |
captureWorker = new SMCaptureWorker;
|
|
|
43 |
captureWorkerThread = new QThread(this);
|
|
|
44 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
|
|
45 |
captureWorker->moveToThread(captureWorkerThread);
|
|
|
46 |
captureWorkerThread->start();
|
|
|
47 |
|
|
|
48 |
// Connections
|
23 |
jakw |
49 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
27 |
jakw |
50 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
|
|
51 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
30 |
jakw |
52 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
4 |
jakw |
53 |
|
|
|
54 |
// Start capturing
|
|
|
55 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
|
|
56 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
|
|
57 |
|
148 |
jakw |
58 |
|
|
|
59 |
//ui->captureCamera0ScrollArea->setWidget(ui->captureCamera0Widget);
|
|
|
60 |
|
1 |
jakw |
61 |
}
|
|
|
62 |
|
23 |
jakw |
63 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
4 |
jakw |
64 |
|
23 |
jakw |
65 |
if(camId == 0){
|
25 |
jakw |
66 |
if(!calibrationReviewMode)
|
|
|
67 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
27 |
jakw |
68 |
if(!captureReviewMode)
|
|
|
69 |
ui->captureCamera0Widget->showImageCV(frame);
|
23 |
jakw |
70 |
} else if(camId == 1){
|
25 |
jakw |
71 |
if(!calibrationReviewMode)
|
|
|
72 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
27 |
jakw |
73 |
if(!captureReviewMode)
|
|
|
74 |
ui->captureCamera1Widget->showImageCV(frame);
|
23 |
jakw |
75 |
}
|
|
|
76 |
}
|
4 |
jakw |
77 |
|
23 |
jakw |
78 |
void SMScanner::on_actionPreferences_triggered(){
|
4 |
jakw |
79 |
|
74 |
jakw |
80 |
connect(&preferenceDialog, SIGNAL(accepted()), this, SLOT(onPreferencesChanged()));
|
73 |
jakw |
81 |
|
4 |
jakw |
82 |
preferenceDialog.show();
|
|
|
83 |
}
|
|
|
84 |
|
73 |
jakw |
85 |
void SMScanner::onPreferencesChanged(){
|
|
|
86 |
|
137 |
jakw |
87 |
// Stop capturing thread
|
|
|
88 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
|
|
89 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
|
|
90 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
|
|
91 |
captureWorkerThread->quit();
|
|
|
92 |
captureWorkerThread->wait();
|
73 |
jakw |
93 |
|
137 |
jakw |
94 |
// Restart capture worker
|
|
|
95 |
captureWorker = new SMCaptureWorker;
|
|
|
96 |
captureWorkerThread = new QThread(this);
|
|
|
97 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
|
|
98 |
captureWorker->moveToThread(captureWorkerThread);
|
|
|
99 |
captureWorkerThread->start();
|
73 |
jakw |
100 |
|
137 |
jakw |
101 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
|
|
102 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
|
|
103 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
|
|
104 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
74 |
jakw |
105 |
|
137 |
jakw |
106 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
|
|
107 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
74 |
jakw |
108 |
|
137 |
jakw |
109 |
// QMessageBox::warning(this, "Information", "You must quit and restart the program for new settings to take effect!", QMessageBox::Ok);
|
74 |
jakw |
110 |
|
73 |
jakw |
111 |
}
|
|
|
112 |
|
4 |
jakw |
113 |
void SMScanner::closeEvent(QCloseEvent *event){
|
|
|
114 |
|
23 |
jakw |
115 |
// Stop capturing thread
|
|
|
116 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
|
|
117 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
|
|
118 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
|
|
119 |
captureWorkerThread->quit();
|
|
|
120 |
captureWorkerThread->wait();
|
|
|
121 |
|
4 |
jakw |
122 |
// Save window geometry
|
|
|
123 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
|
|
124 |
settings.setValue("state/mainwindow", this->saveState());
|
|
|
125 |
|
|
|
126 |
event->accept();
|
|
|
127 |
|
|
|
128 |
}
|
|
|
129 |
|
2 |
jakw |
130 |
SMScanner::~SMScanner(){
|
1 |
jakw |
131 |
delete ui;
|
|
|
132 |
}
|
4 |
jakw |
133 |
|
23 |
jakw |
134 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
|
|
135 |
|
25 |
jakw |
136 |
// If in review mode, go back to aquisition mode
|
|
|
137 |
if(calibrationReviewMode){
|
26 |
jakw |
138 |
ui->calibrationListWidget->clearSelection();
|
25 |
jakw |
139 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
|
|
140 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
|
|
141 |
calibrationReviewMode = false;
|
|
|
142 |
return;
|
|
|
143 |
}
|
|
|
144 |
|
27 |
jakw |
145 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, -1.0));
|
23 |
jakw |
146 |
|
|
|
147 |
}
|
|
|
148 |
|
30 |
jakw |
149 |
|
|
|
150 |
void SMScanner::on_batchCalibrationButton_clicked(){
|
|
|
151 |
|
|
|
152 |
// If in review mode, go back to aquisition mode
|
|
|
153 |
if(calibrationReviewMode){
|
|
|
154 |
ui->calibrationListWidget->clearSelection();
|
|
|
155 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
|
|
156 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
|
|
157 |
calibrationReviewMode = false;
|
|
|
158 |
return;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
// Construct vector of angles
|
|
|
162 |
int angleStart = ui->calibrationBatchStartSpinBox->value();
|
|
|
163 |
int angleEnd = ui->calibrationBatchEndSpinBox->value();
|
|
|
164 |
int angleStep = ui->calibrationBatchStepSpinBox->value();
|
|
|
165 |
|
|
|
166 |
if(angleStart > angleEnd)
|
|
|
167 |
angleEnd += 360;
|
|
|
168 |
|
|
|
169 |
std::vector<float> angles;
|
|
|
170 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
|
|
171 |
angles.push_back(i % 360);
|
|
|
172 |
|
|
|
173 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSets", Q_ARG(std::vector<float>, angles));
|
|
|
174 |
|
|
|
175 |
std::cout << "Aquiring sets at ";
|
75 |
jakw |
176 |
for(unsigned int i=0; i<angles.size(); i++)
|
30 |
jakw |
177 |
std::cout << angles[i] << " ";
|
|
|
178 |
std::cout << " degrees" <<std::endl;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
23 |
jakw |
182 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
27 |
jakw |
183 |
|
23 |
jakw |
184 |
float angle = ui->calibrationRotationDial->value();
|
|
|
185 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
186 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
27 |
jakw |
187 |
|
159 |
jakw |
188 |
ui->calibrationRotationSpinBox->setValue(angle);
|
|
|
189 |
|
|
|
190 |
ui->captureRotationDial->setValue(angle);
|
|
|
191 |
ui->captureRotationSpinBox->setValue(angle);
|
23 |
jakw |
192 |
}
|
24 |
jakw |
193 |
|
159 |
jakw |
194 |
|
|
|
195 |
void SMScanner::on_calibrationRotationSpinBox_editingFinished(){
|
|
|
196 |
|
|
|
197 |
float angle = ui->calibrationRotationSpinBox->value();
|
|
|
198 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
199 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
200 |
|
|
|
201 |
ui->calibrationRotationDial->setValue(angle);
|
|
|
202 |
|
|
|
203 |
ui->captureRotationSpinBox->setValue(angle);
|
|
|
204 |
ui->captureRotationDial->setValue(angle);
|
|
|
205 |
}
|
|
|
206 |
|
27 |
jakw |
207 |
void SMScanner::onReceiveCalibrationSet(SMCalibrationSet calibrationSet){
|
123 |
jakw |
208 |
|
|
|
209 |
int id = ui->calibrationListWidget->count();
|
|
|
210 |
calibrationSet.id = id;
|
|
|
211 |
|
23 |
jakw |
212 |
calibrationData.push_back(calibrationSet);
|
25 |
jakw |
213 |
|
|
|
214 |
// Add identifier to list
|
123 |
jakw |
215 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
25 |
jakw |
216 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
|
217 |
item->setCheckState(Qt::Checked);
|
|
|
218 |
ui->calibrationListWidget->addItem(item);
|
|
|
219 |
|
|
|
220 |
// Set enabled checkmark
|
|
|
221 |
if(calibrationData.size() >= 2)
|
|
|
222 |
ui->calibrateButton->setEnabled(true);
|
23 |
jakw |
223 |
}
|
25 |
jakw |
224 |
|
27 |
jakw |
225 |
void SMScanner::on_calibrateButton_clicked(){
|
25 |
jakw |
226 |
|
29 |
jakw |
227 |
// disable ui elements
|
|
|
228 |
ui->calibrateButton->setEnabled(false);
|
|
|
229 |
ui->calibrationFrame->setEnabled(false);
|
27 |
jakw |
230 |
|
|
|
231 |
// set checked flags
|
75 |
jakw |
232 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
27 |
jakw |
233 |
calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
// SMCalibrationWorker calibrationWorker;
|
|
|
237 |
// calibrationWorker.performCalibration(calibrationData);
|
|
|
238 |
|
|
|
239 |
// Set up calibration thread
|
78 |
jakw |
240 |
calibrationWorker = new SMCalibrationWorker;
|
27 |
jakw |
241 |
calibrationWorkerThread = new QThread(this);
|
|
|
242 |
calibrationWorkerThread->setObjectName("calibrationWorkerThread");
|
123 |
jakw |
243 |
calibrationWorker->moveToThread(calibrationWorkerThread);
|
27 |
jakw |
244 |
calibrationWorkerThread->start();
|
|
|
245 |
|
|
|
246 |
// Connections
|
28 |
jakw |
247 |
connect(calibrationWorker, SIGNAL(newSetProcessed(int)), this, SLOT(onCalibrationSetProcessed(int)));
|
29 |
jakw |
248 |
connect(calibrationWorker, SIGNAL(newFrameResult(int,int,bool,cv::Mat)), this, SLOT(onCalibrationFrameResult(int,int,bool,cv::Mat)));
|
27 |
jakw |
249 |
connect(calibrationWorker, SIGNAL(done()), this, SLOT(onCalibrationDone()));
|
32 |
jakw |
250 |
connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
|
27 |
jakw |
251 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
|
|
|
252 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
|
|
|
253 |
|
32 |
jakw |
254 |
// Start calibration
|
207 |
flgw |
255 |
QMetaObject::invokeMethod(calibrationWorker, "performCameraCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
27 |
jakw |
256 |
|
|
|
257 |
}
|
|
|
258 |
|
30 |
jakw |
259 |
|
|
|
260 |
|
27 |
jakw |
261 |
void SMScanner::onCalibrationSetProcessed(int idx){
|
|
|
262 |
|
137 |
jakw |
263 |
if(calibrationData[idx].frame0Result.empty() && calibrationData[idx].frame1Result.empty())
|
|
|
264 |
ui->calibrationListWidget->item(idx)->setCheckState(Qt::Unchecked);
|
|
|
265 |
|
27 |
jakw |
266 |
ui->calibrationListWidget->setCurrentRow(idx);
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
void SMScanner::onCalibrationDone(){
|
|
|
270 |
|
|
|
271 |
std::cout << "Calibration done!" << std::endl;
|
29 |
jakw |
272 |
ui->calibrateButton->setEnabled(true);
|
|
|
273 |
ui->calibrationFrame->setEnabled(true);
|
27 |
jakw |
274 |
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
|
|
|
278 |
|
|
|
279 |
// if selection is just cleared
|
|
|
280 |
if(ui->calibrationListWidget->selectedItems().empty())
|
|
|
281 |
return;
|
|
|
282 |
|
207 |
flgw |
283 |
// clamp to available range
|
|
|
284 |
assert(ui->calibrationListWidget->currentRow() >= 0
|
|
|
285 |
&& ui->calibrationListWidget->currentRow() < calibrationData.size());
|
|
|
286 |
int currentRow = std::min(int(calibrationData.size())-1,
|
|
|
287 |
std::max(0, ui->calibrationListWidget->currentRow()));
|
27 |
jakw |
288 |
|
25 |
jakw |
289 |
calibrationReviewMode = true;
|
|
|
290 |
ui->singleCalibrationButton->setText("Live View");
|
|
|
291 |
ui->batchCalibrationButton->setText("Live View");
|
|
|
292 |
|
|
|
293 |
if(!calibrationData[currentRow].frame0Result.empty())
|
|
|
294 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
|
|
295 |
else
|
|
|
296 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
|
|
297 |
|
|
|
298 |
if(!calibrationData[currentRow].frame1Result.empty())
|
|
|
299 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
|
|
300 |
else
|
|
|
301 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
27 |
jakw |
302 |
|
|
|
303 |
// std::cout << "on_calibrationListWidget_itemSelectionChanged" << std::endl;
|
25 |
jakw |
304 |
}
|
|
|
305 |
|
29 |
jakw |
306 |
void SMScanner::onCalibrationFrameResult(int idx, int camID, bool success, cv::Mat result){
|
25 |
jakw |
307 |
|
137 |
jakw |
308 |
if(success){
|
29 |
jakw |
309 |
if(camID == 0)
|
|
|
310 |
calibrationData[idx].frame0Result = result;
|
|
|
311 |
else if(camID == 1)
|
|
|
312 |
calibrationData[idx].frame1Result = result;
|
|
|
313 |
}
|
27 |
jakw |
314 |
|
|
|
315 |
}
|
|
|
316 |
|
159 |
jakw |
317 |
void SMScanner::on_captureRotationDial_sliderReleased(){
|
|
|
318 |
|
|
|
319 |
float angle = ui->captureRotationDial->value();
|
|
|
320 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
321 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
322 |
|
|
|
323 |
ui->captureRotationSpinBox->setValue(ui->captureRotationDial->value());
|
|
|
324 |
|
|
|
325 |
ui->calibrationRotationDial->setValue(ui->captureRotationDial->value());
|
|
|
326 |
ui->calibrationRotationSpinBox->setValue(ui->captureRotationDial->value());
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
void SMScanner::on_captureRotationSpinBox_editingFinished(){
|
|
|
330 |
|
|
|
331 |
float angle = ui->captureRotationSpinBox->value();
|
|
|
332 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
333 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
334 |
|
|
|
335 |
ui->captureRotationDial->setValue(angle);
|
|
|
336 |
|
|
|
337 |
ui->calibrationRotationSpinBox->setValue(angle);
|
|
|
338 |
ui->calibrationRotationDial->setValue(angle);
|
|
|
339 |
}
|
|
|
340 |
|
27 |
jakw |
341 |
void SMScanner::on_singleCaptureButton_clicked(){
|
|
|
342 |
|
|
|
343 |
// If in review mode, go back to aquisition mode
|
|
|
344 |
if(captureReviewMode){
|
|
|
345 |
ui->captureTreeWidget->clearSelection();
|
|
|
346 |
ui->singleCaptureButton->setText("Single Aquisition");
|
|
|
347 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
|
|
348 |
captureReviewMode = false;
|
|
|
349 |
return;
|
25 |
jakw |
350 |
}
|
|
|
351 |
|
27 |
jakw |
352 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequence", Q_ARG(float, -1.0));
|
25 |
jakw |
353 |
|
|
|
354 |
}
|
26 |
jakw |
355 |
|
27 |
jakw |
356 |
|
30 |
jakw |
357 |
void SMScanner::on_batchCaptureButton_clicked(){
|
|
|
358 |
|
|
|
359 |
// If in review mode, go back to aquisition mode
|
|
|
360 |
if(captureReviewMode){
|
|
|
361 |
ui->captureTreeWidget->clearSelection();
|
|
|
362 |
ui->singleCaptureButton->setText("Single Aquisition");
|
|
|
363 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
|
|
364 |
captureReviewMode = false;
|
|
|
365 |
return;
|
|
|
366 |
}
|
|
|
367 |
|
|
|
368 |
// Construct vector of angles
|
|
|
369 |
int angleStart = ui->captureBatchStartSpinBox->value();
|
|
|
370 |
int angleEnd = ui->captureBatchEndSpinBox->value();
|
|
|
371 |
int angleStep = ui->captureBatchStepSpinBox->value();
|
|
|
372 |
|
|
|
373 |
if(angleStart > angleEnd)
|
|
|
374 |
angleEnd += 360;
|
|
|
375 |
|
|
|
376 |
std::vector<float> angles;
|
|
|
377 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
|
|
378 |
angles.push_back(i % 360);
|
|
|
379 |
|
|
|
380 |
std::cout << "Aquiring sequences at ";
|
75 |
jakw |
381 |
for(unsigned int i=0; i<angles.size(); i++)
|
30 |
jakw |
382 |
std::cout << angles[i] << " ";
|
|
|
383 |
std::cout << " degrees" <<std::endl;
|
|
|
384 |
|
|
|
385 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
|
|
|
386 |
}
|
|
|
387 |
|
27 |
jakw |
388 |
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
|
207 |
flgw |
389 |
frameSequence.id = ++lastCaptureId;
|
27 |
jakw |
390 |
captureData.push_back(frameSequence);
|
|
|
391 |
|
|
|
392 |
// Add identifier to list
|
|
|
393 |
QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
|
207 |
flgw |
394 |
item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(frameSequence.id).arg(frameSequence.rotationAngle));
|
139 |
jakw |
395 |
//item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
67 |
jakw |
396 |
item->setData(0, Qt::UserRole, QPoint(captureData.size()-1, -1));
|
139 |
jakw |
397 |
//item->setCheckState(0, Qt::Checked);
|
27 |
jakw |
398 |
//ui->captureTreeWidget->addItem(item);
|
|
|
399 |
|
103 |
jakw |
400 |
for(unsigned int i=0; i<frameSequence.frames0.size(); i++){
|
27 |
jakw |
401 |
QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
|
|
|
402 |
subItem->setText(0, QString("frames %1").arg(i));
|
207 |
flgw |
403 |
subItem->setData(0, Qt::UserRole, QPoint(frameSequence.id, i));
|
27 |
jakw |
404 |
}
|
41 |
jakw |
405 |
|
|
|
406 |
ui->reconstructButton->setEnabled(true);
|
27 |
jakw |
407 |
}
|
|
|
408 |
|
|
|
409 |
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
|
|
|
410 |
|
|
|
411 |
// if selection is just cleared
|
|
|
412 |
if(ui->captureTreeWidget->selectedItems().empty())
|
|
|
413 |
return;
|
|
|
414 |
|
|
|
415 |
QTreeWidgetItem *item = ui->captureTreeWidget->currentItem();
|
|
|
416 |
|
|
|
417 |
captureReviewMode = true;
|
|
|
418 |
|
|
|
419 |
ui->singleCaptureButton->setText("Live View");
|
|
|
420 |
ui->batchCaptureButton->setText("Live View");
|
|
|
421 |
|
|
|
422 |
QPoint idx = item->data(0, Qt::UserRole).toPoint();
|
|
|
423 |
|
207 |
flgw |
424 |
if( idx.y() != -1 && idx.x()>=0 && idx.x()<captureData.size()
|
|
|
425 |
&& idx.y()<captureData[idx.x()].frames0.size()
|
|
|
426 |
&& idx.y()<captureData[idx.x()].frames1.size() ){
|
|
|
427 |
// TODO idx.x() can & WILL be out of bounds
|
103 |
jakw |
428 |
ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
|
|
|
429 |
ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
|
27 |
jakw |
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 |
|
207 |
flgw |
580 |
// TODO is a reference working here??
|
|
|
581 |
QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointClouds", Q_ARG(std::vector<SMFrameSequence>, captureData));
|
75 |
jakw |
582 |
for(unsigned int i=0; i<captureData.size(); i++){
|
139 |
jakw |
583 |
if(!captureData[i].reconstructed){ // & (ui->captureTreeWidget->topLevelItem(i)->checkState(0) == Qt::Checked))
|
|
|
584 |
captureData[i].reconstructed = true;
|
207 |
flgw |
585 |
// now done before QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointCloud", Q_ARG(SMFrameSequence, captureData[i]));
|
139 |
jakw |
586 |
}
|
45 |
jakw |
587 |
}
|
41 |
jakw |
588 |
}
|
|
|
589 |
|
208 |
flgw |
590 |
void SMScanner::on_meshButton_clicked(){
|
|
|
591 |
|
|
|
592 |
// Set up reconstruction thread
|
|
|
593 |
meshWorker = new SMMeshingWorker;
|
|
|
594 |
meshWorkerThread = new QThread(this);
|
|
|
595 |
meshWorkerThread->setObjectName("meshWorkerThread");
|
|
|
596 |
meshWorker->moveToThread(meshWorkerThread);
|
|
|
597 |
meshWorkerThread->start();
|
|
|
598 |
|
|
|
599 |
// Connections
|
|
|
600 |
//connect(meshWorker, SIGNAL(newMesh(pcl::PolygonMesh)), this, SLOT(onReceiveMesh(pcl::PolygonMesh)));
|
|
|
601 |
//connect(meshWorker, SIGNAL(done()), meshWorkerThread, SLOT(quit()));
|
|
|
602 |
//connect(meshWorker, SIGNAL(done()), meshWorker, SLOT(deleteLater()));
|
|
|
603 |
|
|
|
604 |
// Start reconstructing
|
|
|
605 |
//QMetaObject::invokeMethod(meshWorker, "setup");
|
|
|
606 |
|
|
|
607 |
// TODO is a reference working here??
|
|
|
608 |
QMetaObject::invokeMethod(meshWorker, "reconstructMesh",
|
|
|
609 |
Q_ARG(std::vector<SMPointCloud>, pointCloudData));
|
|
|
610 |
}
|
|
|
611 |
|
148 |
jakw |
612 |
void SMScanner::onReceivePointCloud(SMPointCloud smCloud){
|
139 |
jakw |
613 |
// for(int i=0; i<captureData.size(); i++){
|
|
|
614 |
// if(captureData[i].id == id)
|
|
|
615 |
// captureData[i].reconstructed = true;
|
|
|
616 |
// }
|
82 |
jakw |
617 |
|
207 |
flgw |
618 |
//pointCloudData.push_back(smCloud);
|
208 |
flgw |
619 |
// TODO on demand resizing here is evil
|
207 |
flgw |
620 |
if(pointCloudData.size()<=smCloud.id) pointCloudData.resize(smCloud.id+1);
|
|
|
621 |
pointCloudData[smCloud.id] = smCloud;
|
41 |
jakw |
622 |
|
42 |
jakw |
623 |
// Add identifier to list
|
207 |
flgw |
624 |
QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(smCloud.id).arg(smCloud.rotationAngle));
|
42 |
jakw |
625 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
207 |
flgw |
626 |
item->setData(Qt::UserRole, QVariant(smCloud.id));
|
42 |
jakw |
627 |
item->setCheckState(Qt::Checked);
|
44 |
jakw |
628 |
|
42 |
jakw |
629 |
ui->pointCloudsListWidget->addItem(item);
|
207 |
flgw |
630 |
ui->pointCloudWidget->addPointCloud(smCloud, smCloud.id);
|
208 |
flgw |
631 |
|
|
|
632 |
// TODO just to test
|
|
|
633 |
on_meshButton_clicked();
|
41 |
jakw |
634 |
}
|
42 |
jakw |
635 |
|
44 |
jakw |
636 |
void SMScanner::on_actionExport_Point_Clouds_triggered(){
|
|
|
637 |
|
|
|
638 |
QString directory = QFileDialog::getExistingDirectory(this, "Export Point Clouds", QString());
|
|
|
639 |
|
|
|
640 |
// // Non native file dialog
|
|
|
641 |
// QFileDialog saveDirectoryDialog(this, "Export Point Clouds", QString(), "*.pcd;;*.ply;;*.vtk;;*.png;;*.txt");
|
|
|
642 |
// saveDirectoryDialog.setDefaultSuffix("ply");
|
|
|
643 |
// saveDirectoryDialog.setFileMode(QFileDialog::Directory);
|
|
|
644 |
// saveDirectoryDialog.exec();
|
|
|
645 |
// QString directory = saveDirectoryDialog.directory().path();
|
|
|
646 |
// QString type = saveDirectoryDialog.selectedNameFilter();
|
|
|
647 |
|
144 |
jakw |
648 |
QProgressDialog progressDialog("Exporting Point Clouds...", "Cancel", 0, 100, this);
|
143 |
jakw |
649 |
progressDialog.setWindowModality(Qt::WindowModal);
|
|
|
650 |
progressDialog.setMinimumDuration(1000);
|
|
|
651 |
|
44 |
jakw |
652 |
// save point clouds in ply format
|
75 |
jakw |
653 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
143 |
jakw |
654 |
|
|
|
655 |
progressDialog.setValue(100.0*i/pointCloudData.size());
|
207 |
flgw |
656 |
if(pointCloudData[i].id != -1){
|
44 |
jakw |
657 |
QString fileName = QString("%1/pointcloud_%2.ply").arg(directory).arg(i);
|
128 |
jakw |
658 |
pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr pointCloudPCL(pointCloudData[i].pointCloud);
|
44 |
jakw |
659 |
//pcl::io::savePLYFileBinary(fileName.toStdString(), *pointCloudPCL);
|
|
|
660 |
pcl::PLYWriter w;
|
|
|
661 |
// Write to ply in binary without camera
|
128 |
jakw |
662 |
w.write<pcl::PointXYZRGBNormal> (fileName.toStdString(), *pointCloudPCL, true, false);
|
207 |
flgw |
663 |
}
|
143 |
jakw |
664 |
QCoreApplication::processEvents();
|
|
|
665 |
if(progressDialog.wasCanceled())
|
|
|
666 |
return;
|
44 |
jakw |
667 |
}
|
|
|
668 |
|
|
|
669 |
// save meshlab aln project file
|
|
|
670 |
std::ofstream s(QString("%1/alignment.aln").arg(directory).toLocal8Bit());
|
|
|
671 |
s << pointCloudData.size() << std::endl;
|
75 |
jakw |
672 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
207 |
flgw |
673 |
if(pointCloudData[i].id != -1){
|
|
|
674 |
QString fileName = QString("pointcloud_%1.ply").arg(pointCloudData[i].id);
|
44 |
jakw |
675 |
s << fileName.toStdString() << std::endl << "#" << std::endl;
|
|
|
676 |
cv::Mat Tr = cv::Mat::eye(4, 4, CV_32F);
|
|
|
677 |
cv::Mat(pointCloudData[i].R.t()).copyTo(Tr.colRange(0, 3).rowRange(0, 3));
|
|
|
678 |
cv::Mat(-pointCloudData[i].R.t()*pointCloudData[i].T).copyTo(Tr.col(3).rowRange(0, 3));
|
|
|
679 |
for(int j=0; j<Tr.rows; j++){
|
|
|
680 |
for(int k=0; k<Tr.cols; k++){
|
|
|
681 |
s << Tr.at<float>(j,k) << " ";
|
|
|
682 |
}
|
|
|
683 |
s << std::endl;
|
|
|
684 |
}
|
207 |
flgw |
685 |
}
|
44 |
jakw |
686 |
}
|
|
|
687 |
s << "0" << std::flush;
|
|
|
688 |
s.close();
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
void SMScanner::on_pointCloudsListWidget_itemChanged(QListWidgetItem *item){
|
|
|
692 |
|
|
|
693 |
int id = item->data(Qt::UserRole).toInt();
|
207 |
flgw |
694 |
assert(pointCloudData.size()>id);
|
|
|
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 |
|
|
|
784 |
|
135 |
jakw |
785 |
int id = ui->calibrationListWidget->count();
|
|
|
786 |
calibrationSet.id = id;
|
|
|
787 |
|
|
|
788 |
calibrationData.push_back(calibrationSet);
|
|
|
789 |
|
|
|
790 |
// Add identifier to list
|
|
|
791 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
|
|
792 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
196 |
jakw |
793 |
item->setCheckState(Qt::Checked);
|
135 |
jakw |
794 |
ui->calibrationListWidget->addItem(item);
|
|
|
795 |
|
|
|
796 |
QCoreApplication::processEvents();
|
143 |
jakw |
797 |
if(progressDialog.wasCanceled())
|
|
|
798 |
return;
|
135 |
jakw |
799 |
}
|
|
|
800 |
|
|
|
801 |
// Set enabled checkmark
|
|
|
802 |
if(calibrationData.size() >= 2)
|
|
|
803 |
ui->calibrateButton->setEnabled(true);
|
|
|
804 |
}
|
139 |
jakw |
805 |
|
|
|
806 |
void SMScanner::on_actionImport_Sequences_triggered(){
|
|
|
807 |
|
|
|
808 |
// NOTE: we do not know which algorithm was used!!!
|
143 |
jakw |
809 |
|
139 |
jakw |
810 |
QString dirName = QFileDialog::getExistingDirectory(this, "Import captured sequences", QString());
|
|
|
811 |
|
|
|
812 |
QDir dir(dirName);
|
|
|
813 |
QStringList sequenceDirNames = dir.entryList(QStringList("sequence_*"));
|
|
|
814 |
|
|
|
815 |
if(sequenceDirNames.empty()){
|
|
|
816 |
std::cerr << "Error: could not find sequences." << std::endl;
|
|
|
817 |
return;
|
|
|
818 |
}
|
|
|
819 |
|
|
|
820 |
captureData.clear();
|
|
|
821 |
ui->captureTreeWidget->clear();
|
207 |
flgw |
822 |
lastCaptureId=-1;
|
139 |
jakw |
823 |
|
143 |
jakw |
824 |
QProgressDialog progressDialog("Importing Sequences...", "Cancel", 0, 100, this);
|
|
|
825 |
progressDialog.setWindowModality(Qt::WindowModal);
|
|
|
826 |
progressDialog.setMinimumDuration(1000);
|
|
|
827 |
|
139 |
jakw |
828 |
for(int s=0; s<sequenceDirNames.count(); s++){
|
|
|
829 |
|
|
|
830 |
QDir sequenceDir(QString("%1/%2").arg(dirName).arg(sequenceDirNames.at(s)));
|
|
|
831 |
|
|
|
832 |
QStringList fileNames0 = sequenceDir.entryList(QStringList("frames0_*.png"));
|
|
|
833 |
QStringList fileNames1 = sequenceDir.entryList(QStringList("frames1_*.png"));
|
|
|
834 |
|
|
|
835 |
if(fileNames0.empty() || fileNames1.empty() || fileNames0.count() != fileNames1.count()){
|
|
|
836 |
std::cerr << "Error: could not load sequence. Directory must contain .png files for both cameras." << std::endl;
|
|
|
837 |
return;
|
|
|
838 |
}
|
|
|
839 |
|
|
|
840 |
int nFrames = fileNames0.size();
|
|
|
841 |
|
|
|
842 |
SMFrameSequence sequence;
|
|
|
843 |
|
|
|
844 |
for(int f=0; f<nFrames; f++){
|
|
|
845 |
|
143 |
jakw |
846 |
progressDialog.setValue(100.0*s/sequenceDirNames.count() + 100.0/sequenceDirNames.count()*f/nFrames);
|
|
|
847 |
|
139 |
jakw |
848 |
cv::Mat frame0BGR, frame0BayerBG, frame1BGR, frame1BayerBG;
|
|
|
849 |
|
|
|
850 |
QString fileName0 = QString("%1/%2/frames0_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
|
|
851 |
frame0BGR = cv::imread(fileName0.toStdString());
|
|
|
852 |
cvtools::cvtColorBGRToBayerBG(frame0BGR, frame0BayerBG);
|
|
|
853 |
|
|
|
854 |
QString fileName1 = QString("%1/%2/frames1_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
|
|
855 |
frame1BGR = cv::imread(fileName1.toStdString());
|
|
|
856 |
cvtools::cvtColorBGRToBayerBG(frame1BGR, frame1BayerBG);
|
|
|
857 |
|
|
|
858 |
sequence.frames0.push_back(frame0BayerBG);
|
|
|
859 |
sequence.frames1.push_back(frame1BayerBG);
|
|
|
860 |
|
|
|
861 |
QCoreApplication::processEvents();
|
143 |
jakw |
862 |
if(progressDialog.wasCanceled())
|
|
|
863 |
return;
|
139 |
jakw |
864 |
}
|
143 |
jakw |
865 |
|
|
|
866 |
// Assign whatever algorithm is configured
|
139 |
jakw |
867 |
sequence.codec = settings.value("algorithm").toString();
|
|
|
868 |
sequence.rotationAngle = 0;
|
|
|
869 |
sequence.reconstructed = false;
|
|
|
870 |
|
|
|
871 |
onReceiveFrameSequence(sequence);
|
|
|
872 |
}
|
|
|
873 |
|
|
|
874 |
}
|
|
|
875 |
|
|
|
876 |
void SMScanner::on_actionClear_Point_Clouds_triggered(){
|
|
|
877 |
|
|
|
878 |
int res = QMessageBox::question(this, "Clear Reconstructed Point Clouds", "Clear all reconstructed point clouds?", QMessageBox::Ok, QMessageBox::Cancel);
|
|
|
879 |
|
|
|
880 |
if(res == QMessageBox::Ok){
|
|
|
881 |
|
|
|
882 |
pointCloudData.clear();
|
|
|
883 |
ui->pointCloudsListWidget->clear();
|
|
|
884 |
ui->pointCloudWidget->removeAllPointClouds();
|
|
|
885 |
|
167 |
jakw |
886 |
for(unsigned int i=0; i<captureData.size(); i++)
|
139 |
jakw |
887 |
captureData[i].reconstructed = false;
|
|
|
888 |
}
|
|
|
889 |
}
|
159 |
jakw |
890 |
|
199 |
jakw |
891 |
|
|
|
892 |
void SMScanner::on_actionProject_Focusing_Pattern_triggered()
|
|
|
893 |
{
|
|
|
894 |
bool projectFocusingPattern = ui->actionProject_Focusing_Pattern->isChecked();
|
|
|
895 |
QMetaObject::invokeMethod(captureWorker, "setProjectFocusingPattern", Q_ARG(bool, projectFocusingPattern));
|
|
|
896 |
|
|
|
897 |
}
|