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