/
cameracalibrationevaluation.cpp
163 lines (152 loc) · 6.44 KB
/
cameracalibrationevaluation.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*******************************************************************************
*
* Copyright (C) 2016 by Tom Koeppchen
* gtkoeppchen (at) googlemail (dot) com
* This file is part of Stereocalibrator.
*
* Stereocalibrator is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Stereocalibrator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Stereocalibrator. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#include "cameracalibrationevaluation.h"
/**
* Constructor.
* @param cam
* @param parent
*/
CameraCalibrationEvaluation::CameraCalibrationEvaluation(scc::CameraCalibration *cam,
QWidget *parent) :
QWidget(parent) {
qDebug() << "CameraCalibrationEvaluation(QTabWidget *parent):";
cameraCalibration = cam;
setupLayout();
}
/**
* Destructor.
*/
CameraCalibrationEvaluation::~CameraCalibrationEvaluation() {
qDebug() << "~CameraCalibrationEvaluation()";
}
/**
* Sets up the layout.
*/
void CameraCalibrationEvaluation::setupLayout() {
qDebug() << "CameraCalibrationEvaluation::setupLayout()";
QHBoxLayout *mainLayout = new QHBoxLayout;
imagePreview = new QScrollArea;
setImagePreviewLayout(imagePreview);
mainLayout->addWidget(imagePreview);
dataPreview = new QWidget;
setDataPreviewLayout(dataPreview);
mainLayout->addWidget(dataPreview);
connect(picPreviewMapper, SIGNAL(mapped(const QString &)), this,
SLOT(openMaxPicWindow(const QString &)));
setLayout(mainLayout);
}
/**
* Sets up the layout for the image preview area.
* @param picPreview The widget to set up the layout for.
*/
void CameraCalibrationEvaluation::setImagePreviewLayout(
QScrollArea *pPreview) {
qDebug() << "CameraCalibrationEvaluation::setImagePreviewLayout("
<< "QScrollArea *picPreview)";
pPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
pPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
imagePreviewWidget = new QWidget;
pPreview->setWidget(imagePreviewWidget);
imagePreviewLayout = new QVBoxLayout(imagePreviewWidget);
imagePreviewLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
loadImagesIntoPreview(cameraCalibration->getTargetImages());
}
/**
* Sets up the layout for the data preview area.
* @param dPreview The widget to set up the layout for.
*/
void CameraCalibrationEvaluation::setDataPreviewLayout(QWidget *dPreview) {
qDebug() << "CameraCalibrationEvaluation::setDataPreviewLayout("
<< "QScrollArea *picPreview)";
QVBoxLayout *dataPreviewLayout = new QVBoxLayout(dPreview);
tempPixmap = new QPixmap(QString::fromStdString(cameraCalibration->getImagePointsDistributionImagePath()));
*tempPixmap = tempPixmap->scaledToWidth(this->width() * 0.4);
QPushButton *tempButton = new QPushButton;
tempButton->setFlat(true);
tempButton->setAutoFillBackground(true);
tempButton->setIcon(QIcon(*tempPixmap));
tempButton->setIconSize(QSize(tempPixmap->width(),
tempPixmap->height()));
dataPreviewLayout->addWidget(tempButton);
connect(tempButton, SIGNAL(clicked()), picPreviewMapper, SLOT(map()));
picPreviewMapper->setMapping(tempButton,
QString::fromStdString(cameraCalibration->getImagePointsDistributionImagePath()));
results = new QPlainTextEdit;
results->setReadOnly(true);
results->setMinimumHeight(1);
results->setMinimumWidth(1);
QPalette palette;
palette.setColor(QPalette::Base,Qt::black);
palette.setColor(QPalette::Text,Qt::white);
results->setPalette(palette);
dataPreviewLayout->addWidget(results);
loadDataIntoResultPreview();
}
/**
* Loads the given images from the system and places them as button into the
* image preview area.
* @param imageFiles Vector of string holding the path to the images to load.
*/
void CameraCalibrationEvaluation::loadImagesIntoPreview(
std::vector<std::string> imageFiles) {
qDebug() << "CameraCalibrationEvaluation::loadImagesIntoPreview("
<< "std::vector<std::string> imageFiles)";
picPreviewMapper = new QSignalMapper();
for (unsigned int i = 0; i < imageFiles.size(); i++) {
tempPixmap = new QPixmap(QString::fromStdString(imageFiles.at(i)));
*tempPixmap = tempPixmap->scaledToWidth(
this->width() * 0.45);
QPushButton *tempButton = new QPushButton;
tempButton->setFlat(true);
tempButton->setAutoFillBackground(true);
tempButton->setIcon(QIcon(*tempPixmap));
tempButton->setIconSize(QSize(tempPixmap->width(),
tempPixmap->height()));
imagePreviewLayout->addWidget(tempButton);
connect(tempButton, SIGNAL(clicked()), picPreviewMapper, SLOT(map()));
picPreviewMapper->setMapping(tempButton,
QString::fromStdString(imageFiles.at(i)));
}
}
/**
* Loads the data into the data preview area.
*/
void CameraCalibrationEvaluation::loadDataIntoResultPreview() {
results->appendPlainText("Camera matrix:\n");
results->appendPlainText(QString::fromStdString(cameraCalibration->getCameraMatrixString()));
results->appendPlainText("\nDistortion coefficients:\n");
results->appendPlainText(QString::fromStdString(cameraCalibration->getDistortionMatrixString()));
}
/**
* Opens a window containing the image found under the given path.
* @param imagePath The path to the image a window is opened for.
*/
void CameraCalibrationEvaluation::openMaxPicWindow(const QString &imagePath) {
qDebug() << "CameraCalibrationEvaluation::openMaxPicWindow(const QString "
"&imagePath) ...";
QScrollArea *sArea = new QScrollArea;
QLabel *label = new QLabel;
QPixmap *pixmap = new QPixmap(imagePath);
label->setPixmap(*pixmap);
sArea->setWidget(label);
sArea->setWindowTitle(imagePath);
sArea->showMaximized();
}