-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcameralistwidget.cpp
118 lines (99 loc) · 3.8 KB
/
cameralistwidget.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
#include "cameralistwidget.h"
#include "extrinsicdialog.h"
#include "aspectsinglelayout.h"
#include "ui_cameralistwidget.h"
#include <functional>
#include <QDebug>
#include <QImage>
#include <QScrollBar>
#include <QLayout>
#include <QLineEdit>
CameraListWidget::CameraListWidget(Attribute attr, QVector<CameraParameter> &pv, QWidget *parent) :
QDialog(parent),
ui(new Ui::CameraListWidget),
pvec(pv)
{
ui->setupUi(this);
for(QVector<CameraParameter>::iterator it = pvec.begin();
it != pvec.end(); it++) {
QLabel *imgLabel = new QLabel;
imgLabel->setFrameShape(QLabel::Box);
imgLabel->setFrameShadow(QLabel::Raised);
imgLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
imgLabel->setMinimumSize(270, 180);
imgLabel->setScaledContents(true);
AspectSingleLayout *aspLayout =
new AspectSingleLayout(NULL, it->imageWidthToHeight);
aspLayout->setContentsMargins(0, 0, 0, 0);
aspLayout->addWidget(imgLabel);
aspLayout->setAlignment(imgLabel, Qt::AlignCenter);
QPushButton *calibButton = new QPushButton("calibrate");
calibButton->setMinimumSize(90, 60);
calibButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
//grabe an image to display
cv::VideoCapture cap(it->devId);
cap.set(CAP_PROP_FRAME_WIDTH, it->imgSize.width);
cap.set(CAP_PROP_FRAME_HEIGHT, it->imgSize.height);
cv::Mat cvImage;
if(cap.isOpened()) {
QImage img;
cap >> cvImage;
cv::cvtColor(cvImage, cvImage, CV_BGR2RGB);
CalibrateWidget::matToQimage(cvImage, img);
imgLabel->setPixmap(QPixmap::fromImage(img));
} else {
calibButton->setEnabled(false);
}
QLabel *calibStatusLabel = new QLabel;
std::function<void(void)> lfp;
bool ready(0);
if(attr == Attribute::intrinsic) {
ready = it->intrinsicDistReady;
lfp = [=](){CalibrateWidget *calibw = new CalibrateWidget(*it, this);
calibw->setAttribute(Qt::WA_DeleteOnClose);
calibw->setWindowTitle(it->name);
calibw->exec();
setCalibrateStatus(calibStatusLabel,
it, it->intrinsicDistReady);};
} else if (attr == Attribute::extrinsic) {
ready = it->extrinsicReady;
lfp = [=](){cv::Mat img;
cvImage.copyTo(img);
ExtrinsicDialog *exDialog = new ExtrinsicDialog(img, *it, this);
exDialog->setAttribute(Qt::WA_DeleteOnClose);
exDialog->setWindowTitle(it->name);
exDialog->exec();
setCalibrateStatus(calibStatusLabel,
it, it->extrinsicReady);};
if(!it->intrinsicDistReady) {
calibButton->setEnabled(false);
}
}
setCalibrateStatus(calibStatusLabel, it, ready);
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addLayout(aspLayout, 5);
hlayout->addWidget(calibStatusLabel, 1);
hlayout->addWidget(calibButton, 1);
ui->verticalLayout->addLayout(hlayout);
connect(calibButton, &QPushButton::clicked, lfp);
}
}
CameraListWidget::~CameraListWidget()
{
delete ui;
}
void CameraListWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
Q_UNUSED(event);
if(isMaximized()) {
showNormal();
} else {
showMaximized();
}
}
void CameraListWidget::setCalibrateStatus(QLabel *label, CameraParameter *p, bool ready)
{
QString s = p->name + ":\n";
s += (ready ? "calibrated" : "to be calibrated");
label->setText(s);
}