forked from AntonioRedondo/ImageFeatureDetector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindowFastRealTime.cpp
More file actions
118 lines (86 loc) · 3.79 KB
/
windowFastRealTime.cpp
File metadata and controls
118 lines (86 loc) · 3.79 KB
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
/*
* 2010-2015 (C) Antonio Redondo
* http://antonioredondo.com
* https://github.com/AntonioRedondo/ImageFeatureDetector
*
* Code under the terms of the GNU General Public License v3.
*
*/
#include "windowFastRealTime.h"
WindowFastRealTime::WindowFastRealTime(WindowMain* windowMain) : QDialog(windowMain, Qt::Dialog), mDetecting(false), mCamera(VideoCapture(0)), mTimer(0) {
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
mSettings = new QSettings("imageFeatureDetectorSettings.ini", QSettings::IniFormat);
mLocale = new QLocale(QLocale::English);
uiSpinBoxThresholdFAST->setValue(mSettings->value("fastRT/threshold", 25).toInt());
uiPushButtonNonMaxFAST->setChecked(mSettings->value("fastRT/nonMaxSuppression", true).toBool());
connect(uiPushButtonNonMaxFAST, &QPushButton::toggled, this, &WindowFastRealTime::saveFastParams);
connect(uiSpinBoxThresholdFAST, &QSpinBox::editingFinished, this, &WindowFastRealTime::saveFastParams);
connect(uiPushButtonResetFAST, &QAbstractButton::clicked, this, &WindowFastRealTime::resetFastParams);
connect(uiPushButtonDetect, &QAbstractButton::clicked, this, &WindowFastRealTime::detect);
connect(uiPushButtonCancel, &QAbstractButton::clicked, this, &WindowFastRealTime::close);
if (mCamera.isOpened()) {
mPainter = new QPainter();
mTimer = new QTimer();
mTimer->start(40); //25fps
connect(mTimer, &QTimer::timeout, this, &WindowFastRealTime::compute);
uiPushButtonDetect->setEnabled(true);
} else {
uiLabelRealTime->setText("There is some problem with the cam.\nCannot get images.");
}
show();
}
void WindowFastRealTime::detect() {
if (!mDetecting) {
uiPushButtonDetect->setIcon(QIcon("icons/media-playback-stop.svg"));
uiPushButtonDetect->setText("Stop Detecting");
} else {
uiPushButtonDetect->setIcon(QIcon("icons/media-playback-start.svg"));
uiPushButtonDetect->setText("Detect");
}
mDetecting = !mDetecting;
}
void WindowFastRealTime::close() {
if (mTimer)
mTimer->stop();
mCamera.release();
QWidget::close();
}
void WindowFastRealTime::closeEvent(QCloseEvent* closeEvent) {
close();
QWidget::closeEvent(closeEvent);
}
void WindowFastRealTime::saveFastParams() {
mSettings->setValue("fastRT/threshold", uiSpinBoxThresholdFAST->value());
mSettings->setValue("fastRT/nonMaxSuppression", uiPushButtonNonMaxFAST->isChecked());
}
void WindowFastRealTime::resetFastParams() {
uiSpinBoxThresholdFAST->setValue(25);
uiPushButtonNonMaxFAST->setChecked(true);
saveFastParams();
}
void WindowFastRealTime::compute() {
mCamera >> mImageRT;
if (mDetecting) {
Mat mImageGrey(mImageRT.rows, mImageRT.cols, CV_8UC1);
cvtColor(mImageRT, mImageGrey, CV_RGB2GRAY);
mTime = (float) getTickCount();
FAST(mImageGrey, mKeypoints, mSettings->value("fastRT/threshold", true).toInt(), mSettings->value("fastRT/nonMaxSuppression", true).toBool());
uiLabelTime->setText(QString("Detecting Time: ").append(mLocale->toString((float)((getTickCount()-mTime)/(getTickFrequency()*1000)),'f', 2).append(" ms")));
uiLabelKeypoints->setText(QString("Keypoints: ").append(mLocale->toString((float)mKeypoints.size(),'f', 0)));
mPixmap = QPixmap::fromImage(QImage(mImageRT.data, mImageRT.cols, mImageRT.rows, mImageRT.step, QImage::Format_RGB888).rgbSwapped());
mPainter->begin(&mPixmap);
QPen pen(QColor::fromRgb(255, 0, 0));
pen.setWidth(2);
mPainter->setPen(pen);
mPainter->setRenderHint(QPainter::Antialiasing);
for(int n=0; n<mKeypoints.size(); ++n)
mPainter->drawEllipse((int)mKeypoints.at(n).pt.x, (int)mKeypoints.at(n).pt.y, 4, 4);
mPainter->end();
uiLabelRealTime->setPixmap(mPixmap);
} else {
uiLabelRealTime->setPixmap(QPixmap::fromImage(QImage(mImageRT.data, mImageRT.cols, mImageRT.rows, mImageRT.step, QImage::Format_RGB888).rgbSwapped()));
uiLabelTime->setText("Detecting Time: -");
uiLabelKeypoints->setText("Keypoints: -");
}
}