-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCameraConnectDialog.cpp
175 lines (164 loc) · 7.68 KB
/
CameraConnectDialog.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
163
164
165
166
167
168
169
170
171
172
173
174
175
/************************************************************************/
/* qt-opencv-multithreaded: */
/* A multithreaded OpenCV application using the Qt framework. */
/* */
/* CameraConnectDialog.cpp */
/* */
/* Nick D'Ademo <[email protected]> */
/* */
/* Copyright (c) 2012 Nick D'Ademo */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without restriction, */
/* including without limitation the rights to use, copy, modify, merge, */
/* publish, distribute, sublicense, and/or sell copies of the Software, */
/* and to permit persons to whom the Software is furnished to do so, */
/* subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS */
/* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN */
/* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN */
/* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/* */
/************************************************************************/
#include "CameraConnectDialog.h"
// Qt header files
#include <QtGui>
// Configuration header file
#include "Config.h"
CameraConnectDialog::CameraConnectDialog(QWidget *parent) : QDialog(parent)
{
// Setup dialog
setupUi(this);
// deviceNumberEdit (device number) input string validation
QRegExp rx1("[0-9]\\d{0,2}"); // Integers 0 to 999
QRegExpValidator *validator1 = new QRegExpValidator(rx1, 0);
deviceNumberEdit->setValidator(validator1);
// imageBufferSizeEdit (image buffer size) input string validation
QRegExp rx2("[0-9]\\d{0,2}"); // Integers 0 to 999
QRegExpValidator *validator2 = new QRegExpValidator(rx2, 0);
imageBufferSizeEdit->setValidator(validator2);
// Setup combo boxes
setupComboBoxes();
// Set to defaults
resetToDefaults();
// Connect button to slot
connect(resetToDefaultsPushButton,SIGNAL(released()),SLOT(resetToDefaults()));
} // CameraConnectDialog constructor
int CameraConnectDialog::getDeviceNumber()
{
if(cameraButtonGroup->checkedButton()==(QAbstractButton*)anyCameraButton)
return -1;
else
{
// Set device number to default (any available camera) if field is blank
if(deviceNumberEdit->text().isEmpty())
{
QMessageBox::warning(this->parentWidget(), "WARNING:","Device Number field blank.\nAutomatically set to 'any available camera'.");
return -1;
}
return deviceNumberEdit->text().toInt();
}
} // getDeviceNumber()
int CameraConnectDialog::getImageBufferSize()
{
// Set image buffer size to default if field is blank
if(imageBufferSizeEdit->text().isEmpty())
{
QMessageBox::warning(this->parentWidget(), "WARNING:","Image Buffer Size field blank.\nAutomatically set to default value.");
return DEFAULT_IMAGE_BUFFER_SIZE;
}
// Set image buffer size to default if field is zero
else if(imageBufferSizeEdit->text().toInt()==0)
{
QMessageBox::warning(this->parentWidget(), "WARNING:","Image Buffer Size cannot be zero.\nAutomatically set to default value.");
return DEFAULT_IMAGE_BUFFER_SIZE;;
}
// Use image buffer size specified by user
else
return imageBufferSizeEdit->text().toInt();
} // getImageBufferSize()
bool CameraConnectDialog::getDropFrameCheckBoxState()
{
return dropFrameCheckBox->isChecked();
} // getDropFrameCheckBoxState()
void CameraConnectDialog::setupComboBoxes()
{
// Local variables
QStringList threadPriorities;
// Fill combo boxes
threadPriorities<<"Idle"<<"Lowest"<<"Low"<<"Normal"<<"High"<<"Highest"<<"Time Critical"<<"Inherit";
capturePrioComboBox->addItems(threadPriorities);
processingPrioComboBox->addItems(threadPriorities);
// Set to defaults
} // setupComboBoxes()
int CameraConnectDialog::getCaptureThreadPrio()
{
return capturePrioComboBox->currentIndex();
} // getCaptureThreadPrio()
int CameraConnectDialog::getProcessingThreadPrio()
{
return processingPrioComboBox->currentIndex();
} // getProcessingThreadPrio()
void CameraConnectDialog::resetToDefaults()
{
// Default camera
if(DEFAULT_CAMERA_DEV_NO!=-1)
{
deviceNumberButton->setChecked(true);
deviceNumberEdit->setEnabled(true);
deviceNumberEdit->setText(QString::number(DEFAULT_CAMERA_DEV_NO));
}
else
{
anyCameraButton->setChecked(true);
deviceNumberEdit->setEnabled(false);
deviceNumberEdit->clear();
}
// Image buffer size
imageBufferSizeEdit->setText(QString::number(DEFAULT_IMAGE_BUFFER_SIZE));
// Drop frames
dropFrameCheckBox->setChecked(DEFAULT_DROP_FRAMES);
// Capture thread
if(DEFAULT_CAP_THREAD_PRIO==QThread::IdlePriority)
capturePrioComboBox->setCurrentIndex(0);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::LowestPriority)
capturePrioComboBox->setCurrentIndex(1);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::LowPriority)
capturePrioComboBox->setCurrentIndex(2);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::NormalPriority)
capturePrioComboBox->setCurrentIndex(3);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::HighPriority)
capturePrioComboBox->setCurrentIndex(4);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::HighestPriority)
capturePrioComboBox->setCurrentIndex(5);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::TimeCriticalPriority)
capturePrioComboBox->setCurrentIndex(6);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::InheritPriority)
capturePrioComboBox->setCurrentIndex(7);
// Processing thread
if(DEFAULT_PROC_THREAD_PRIO==QThread::IdlePriority)
processingPrioComboBox->setCurrentIndex(0);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::LowestPriority)
processingPrioComboBox->setCurrentIndex(1);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::LowPriority)
processingPrioComboBox->setCurrentIndex(2);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::NormalPriority)
processingPrioComboBox->setCurrentIndex(3);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::HighPriority)
processingPrioComboBox->setCurrentIndex(4);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::HighestPriority)
processingPrioComboBox->setCurrentIndex(5);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::TimeCriticalPriority)
processingPrioComboBox->setCurrentIndex(6);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::InheritPriority)
processingPrioComboBox->setCurrentIndex(7);
} // resetToDefaults()