-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmainwindow.cpp
142 lines (121 loc) · 3.9 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDir>
#include <QFileInfo>
#include <opencv2/opencv.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
intrinsicAllReady(0),
extrinsicAllReady(0),
curFile(QApplication::applicationDirPath() + "/data/cameras.xml")
{
ui->setupUi(this);
QFileInfo checkFile(curFile);
QVector<QString> camName;
camName << "front" << "left" << "back" << "right";
foreach (const QString &name, camName) {
CameraParameter p;
p.name = name;
camParameters.append(p);
}
if(checkFile.exists() && checkFile.isFile()) {
load();
} else {
qInfo() << QDir(curFile).absolutePath() << ": not found";
save();
}
}
MainWindow::~MainWindow()
{
if(CameraParameter::changed) {
save();
}
delete ui;
}
void MainWindow::on_intrinButton_clicked()
{
cameraList = new CameraListWidget(CameraListWidget::intrinsic,
camParameters, this);
cameraList->setAttribute(Qt::WA_DeleteOnClose);
cameraList->setWindowTitle("Intrinsic List");
cameraList->exec();
svButtonEnable();
}
void MainWindow::on_extrinButton_clicked()
{
cameraList = new CameraListWidget(CameraListWidget::extrinsic,
camParameters, this);
cameraList->setAttribute(Qt::WA_DeleteOnClose);
cameraList->setWindowTitle("Extrinsic List");
cameraList->exec();
svButtonEnable();
}
void MainWindow::on_svButton_clicked()
{
svDialog = new SurroundViewDialog(camParameters, this);
svDialog->setAttribute(Qt::WA_DeleteOnClose);
svDialog->setWindowTitle("Surround View");
svDialog->exec();
}
void MainWindow::svButtonEnable()
{
bool enable(1);
for(auto &item : camParameters) {
enable = enable & item.intrinsicDistReady & item.extrinsicReady;
}
ui->svButton->setEnabled(enable);
}
void MainWindow::save()
{
cv::FileStorage fs(curFile.toStdString(),
cv::FileStorage::WRITE);
fs << "chessboardSetting" << "{"
<< "width" << CameraParameter::boardSize.width
<< "height" << CameraParameter::boardSize.height
<< "squareSize" << CameraParameter::squareSize
<< "}";
fs << "imageResolution" << "{"
<< "width" << CameraParameter::imgSize.width
<< "height" << CameraParameter::imgSize.height
<< "}";
fs << "parameters" << "{";
foreach (const CameraParameter &p, camParameters) {
fs << p.name.toStdString() << "{"
<< "devId" << p.devId
<< "intrinsicReady" << p.intrinsicDistReady
<< "extrinsicReady" << p.extrinsicReady
<< "intrinsic" << p.cvIntrinsic
<< "dist" << p.cvDistCoeffs
<< "extrinsic" << p.cvExtrinsic
<< "}";
}
fs << "}";
}
void MainWindow::load()
{
cv::FileStorage fs(curFile.toStdString(),
cv::FileStorage::READ);
cv::FileNode n;
n = fs["chessboardSetting"];
n["width"] >> CameraParameter::boardSize.width;
n["height"] >> CameraParameter::boardSize.height;
n["squareSize"] >> CameraParameter::squareSize;
n = fs["imageResolution"];
n["width"] >> CameraParameter::imgSize.width;
n["height"] >> CameraParameter::imgSize.height;
float w = CameraParameter::imgSize.width;
float h = CameraParameter::imgSize.height;
CameraParameter::imageWidthToHeight = w / h;
n = fs["parameters"];
for(QVector<CameraParameter>::iterator it = camParameters.begin();
it != camParameters.end(); ++it) {
cv::FileNode sn = n[it->name.toStdString()];
sn["devId"] >> it->devId;
sn["intrinsicReady"] >> it->intrinsicDistReady;
sn["extrinsicReady"] >> it->extrinsicReady;
sn["intrinsic"] >> it->cvIntrinsic;
sn["dist"] >> it->cvDistCoeffs;
sn["extrinsic"] >> it->cvExtrinsic;
}
}