-
Notifications
You must be signed in to change notification settings - Fork 1
/
qembeddedeye.cpp
319 lines (270 loc) · 11.5 KB
/
qembeddedeye.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include "qembeddedeye.h"
#include "ui_qembeddedeye.h"
#include <QDebug>
#include <QMessageBox>
QEmbeddedEye::QEmbeddedEye(QWidget *parent) :
QMainWindow(parent),
mPanDisplay(NULL),
mFovDisplay(NULL),
mPanCamNumber(1), mFovCamNumber(0),
mPanFrameTime(0),mFovFrameTime(0),
mPanDisplayTime(0), mFovDisplayTime(0),
ui(new Ui::QEmbeddedEye)
{
// create the camera capturing threads
mPanCameraCapture = new QFrameCaptureThread(mPanCamNumber, mPanFrameTime, this);
connect( mPanCameraCapture, SIGNAL(finished()), mPanCameraCapture, SLOT(deleteLater()));
mFovCameraCapture = new QFrameCaptureThread(mFovCamNumber, mFovFrameTime, this);
connect( mFovCameraCapture, SIGNAL(finished()), mFovCameraCapture, SLOT(deleteLater()));
motor_lookup = new MotorMatrix();
motor_lookup->loadMotorTargetsLUT();
stream = new QStreamer();
motor = new DynamixelSimpleAPI(SERVO_MX12W);
motor->setTorqueEnabled(PAN_MOTOR_ID,10);
motor->setTorqueEnabled(TILT_MOTOR_ID,10);
std::string deviceName = "/dev/ttyUSB0";
if (motor->connect(deviceName, 1) == 0)
{
std::cerr << "> Failed to open a serial link for our SimpleAPI! Exiting..." << std::endl;
exit(EXIT_FAILURE);
}
if(!stream->createElements())
{
QMessageBox::warning(this, "GStreamer failed", "GStreamer failed to create pipeline elements!");
return;
}
ui->setupUi(this);
}
////////////////////////////////////////////////////////////////////////////////////////////////
QEmbeddedEye::~QEmbeddedEye()
{
delete ui;
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::closeEvent(QCloseEvent*){
terminateAllThreads();
QApplication::quit();
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::terminateAllThreads(){
mPanCameraCapture->quit();
mFovCameraCapture->quit();
if(stream)
{
stream->stopStreaming();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_actionCamera_Settings_triggered()
{
QCameraSettingsDialog mCamSettings;
mCamSettings.setCameraNumbers(mPanCamNumber,mFovCamNumber);
mCamSettings.setFrameTimes(mPanFrameTime,mFovFrameTime);
mCamSettings.setModal(true);
mCamSettings.exec();
if(mCamSettings.result() == QDialog::Accepted) // if accepted, set the new camera settings
{
if(mCamSettings.getPanCameraNumber() == mCamSettings.getFovCameraNumber())
{
QMessageBox::warning(this, "Same Camera Number", "Please select different camera numbers for each camera.");
return;
}
// set the camera numbers
mPanCamNumber = mCamSettings.getPanCameraNumber();
mFovCamNumber = mCamSettings.getFovCameraNumber();
// set the inter frame time if necessary
mPanFrameTime = mCamSettings.getPanFrameTime();
mFovFrameTime = mCamSettings.getFovFrameTime();
mPanCameraCapture->setTimeToSleep(mPanFrameTime);
mFovCameraCapture->setTimeToSleep(mFovFrameTime);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_actionTracking_Settings_triggered()
{
QTrackingSettingsDialog mTrackSettings;
mTrackSettings.setModal(true);
mTrackSettings.exec();
if(mTrackSettings.result() == QDialog::Accepted) // if accepted, set the new camera settings
{
qDebug() << "Accepted tracking settings";
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_actionPanoramic_triggered()
{
if(mPanDisplay){
mPanDisplay->show();
}
else{
mPanDisplay = new QFrameDisplay(PAN_DISPLAY);
// connect the mouse movement events and mouse click events
connect(mPanDisplay, SIGNAL(sendMousePosition(QPoint)), this, SLOT(receiveAndSetMousePos(QPoint)));
connect(mPanDisplay, SIGNAL(sendClickedMousePosition(QPoint)), this, SLOT(receiveClickedMousePos(QPoint)));
// connect frame displayed image
connect(mPanDisplay, SIGNAL(sendFrameDisplayed()), this, SLOT(receivePanFrameDisplayed()));
// connect the camera
connect(mPanCameraCapture, SIGNAL(sendFrame(cv::Mat*)),mPanDisplay, SLOT(receiveFrameCaptured(cv::Mat*)));
mPanDisplay->show();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_actionFoveal_triggered()
{
if(mFovDisplay){
mFovDisplay->show();
}
else{
mFovDisplay = new QFrameDisplay(FOVEAL_DISPLAY);
// connect frame displayed image
connect(mFovDisplay, SIGNAL(sendFrameDisplayed()), this, SLOT(receiveFovFrameDisplayed()));
// connect the camera
connect(mFovCameraCapture, SIGNAL(sendFrame(cv::Mat*)), mFovDisplay, SLOT(receiveFrameCaptured(cv::Mat*)));
mFovDisplay->show();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::receiveAndSetMousePos(QPoint pos){
//ui->label_XYPos->setText(QString::number(pos.x()) + " , " + QString::number(pos.y()));
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::receiveClickedMousePos(QPoint pos){
float p,t;
motor_lookup->getPanTiltFromCoordinates(pos.x(),pos.y(),&p,&t);
ui->label_XYPos->setText(QString::number(p) + " , " + QString::number(t));
motor->setGoalPosition(PAN_MOTOR_ID,(int)p,30);
motor->setGoalPosition(TILT_MOTOR_ID,(int)t,30);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_actionExit_triggered()
{
terminateAllThreads();
QApplication::quit();
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_pushButton_startPanoramicCam_clicked()
{
if(!mPanPlaying)
{
mPanCameraCapture->openCamera(mPanCamNumber);
if(mPanCameraCapture->isCameraOpen())
{
mPanCameraCapture->start();
mPanPlaying = true;
ui->pushButton_startPanoramicCam->setEnabled(false);
}
else
{
QMessageBox::warning(this, "Panoramic Camera Failed to Open", "Unable to Open Panoramic Camera: " + QString::number(mPanCamNumber) + ". Restart application and select another camera number!");
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_pushButton_startFovealCam_clicked()
{
if(!mFovPlaying)
{
mFovCameraCapture->openCamera(mFovCamNumber);
if(mFovCameraCapture->isCameraOpen())
{
QMessageBox::StandardButton rpns;
rpns = QMessageBox::question(this, "Display Foveal Feed", "Displaying this foveal feed will not allow for feed to be streamed. "
"If you want to stream then select 'No'. If you want to display "
"the feed, click 'Yes'.",
QMessageBox::Yes | QMessageBox::No
);
if(rpns == QMessageBox::Yes)
{
mFovCameraCapture->start();
mFovPlaying = true;
ui->pushButton_startFovealCam->setEnabled(false);
}
}
else
{
QMessageBox::warning(this, "Foveal Camera Failed to Open", "Unable to Open Foveal Camera: " + QString::number(mFovCamNumber) + ". Restart application and select another camera number!");
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_pushButton_doTracking_clicked()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_pushButton_captureImages_clicked()
{
// we might not need the image saving functionality
//qDebug() << "on_pushButton_captureImages_clicked";
//if(!thread)
//{
// thread = new QThread( );
// task = new QImageSaver(100);
// task->moveToThread(thread);
//
// connect( thread, SIGNAL(started()), task, SLOT(startSaving()));
// connect( task, SIGNAL(finishedSaving()), thread, SLOT(quit()) );
//
// connect(task, SIGNAL(sendStatus(QString)), this, SLOT(receiveImageSaverStatus(QString)));
//
// connect(task, SIGNAL(finishedSaving()), this, SLOT(receiveFinishedSavingFrames()));
//
// //automatically delete thread and task object when work is done:
// //connect( thread, SIGNAL(finished()), task, SLOT(deleteLater()) );
// //connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );
// thread->start();
//}
//else
//{
//
//}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::receiveImageSaverStatus(QString str)
{
ui->label_imageSaverStatus->setText(str);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::receivePanFrame(cv::Mat*frm){
// qDebug() << "receive Pan Frame!";
if(task){
task->setFrameCaptured(frm);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::receiveFinishedSavingFrames(){
// not yet implemented
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::receivePanFrameDisplayed(void){
double ellapsedTime = CLOCKS_PER_SEC/(clock() - mPanDisplayTime);
ui->label_panFPSDisplay->setText(QString::number(ellapsedTime));
mPanDisplayTime = clock();
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::receiveFovFrameDisplayed(void){
double ellapsedTime = CLOCKS_PER_SEC/(clock() - mFovDisplayTime);
ui->label_fovFPSDisplay->setText(QString::number(ellapsedTime));
mFovDisplayTime = clock();
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_actionStreaming_Settings_triggered()
{
QStreamingSettings mStreamSettings;
mStreamSettings.setModal(true);
mStreamSettings.exec();
if(mStreamSettings.result() == QDialog::Accepted)
{
ui->label_StreamingStatus->setText(mStreamSettings.getAddress() /* + " | " + mStreamSettings.getPortNumber() */);
stream->setCameraID(mFovCamNumber);
stream->addClient(mStreamSettings.getAddress().toUtf8().constData()/*, mStreamSettings.getPortNumber().toUtf8().constData()*/);
} // 10.24.191.215
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QEmbeddedEye::on_pushButton_StartStopStreaming_clicked()
{
if(stream)
{
stream->initialize();
stream->startStreaming();
}
}