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