-
Notifications
You must be signed in to change notification settings - Fork 1
/
userscreen.cpp
156 lines (152 loc) · 3.94 KB
/
userscreen.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
/**
* @file userscreen.cpp
* @brief User window implementation
* @author mnxoid
*
* Copyright 2014 by mnxoid,
*
* This software is the confidential and proprietary information
* of mnxoid ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with mnxoid.
**/
#include "userscreen.h"
#include "ui_userscreen.h"
#include "windowmanager.h"
#include <opencv2/highgui/highgui.hpp>
#include "cameracapture.h"
#include "cvtoqt.h"
#include "packet.h"
#include <QTimer>
#include <QPainter>
extern int isCapturing; //!< Determines, whether capturing session is active
extern int session; //!< Session ID
/**
* @brief Window Manager instance
* @see main.cpp
**/
extern WindowManager WMgr;
/**
* @brief Camera capture instance
* @see CameraCapture
**/
extern CameraCapture* cc;
/**
* @brief UserScreen constructor
* @param [in] parent - Window parent
**/
UserScreen::UserScreen(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UserScreen)
{
ui->setupUi(this);
connect(this, SIGNAL(stopCap()), this, SLOT(captureStop()));
t = NULL;
}
/**
* @brief UserScreen destructor
**/
UserScreen::~UserScreen()
{
delete ui;
}
/**
* @brief Exit button click handler
**/
void UserScreen::on_pushButton_2_clicked()
{
emit stopCap();
WMgr.mw->show();
WMgr.us->hide();
}
/**
* @brief Start button click handler
**/
void UserScreen::on_pushButton_clicked()
{
if (isCapturing == 0)
{
isCapturing = 1;
ui->pushButton->setText("STOP");
cc = new CameraCapture(this);
//cc->setParent(this);
qRegisterMetaType<cv::Mat>("cv::Mat");
connect(cc, SIGNAL(updatePic(cv::Mat)), this, SLOT(imShow(cv::Mat)));
connect(cc, SIGNAL(response()), this, SLOT(respond()));
cc->Start();
cc->start();
t = new QTimer();
connect(t, SIGNAL(timeout()), this, SLOT(sendPic()));
t->start(ui->spinBox->value());
} else {
emit stopCap();
}
}
/**
* @brief Unexpected end of capturing handler
**/
void UserScreen::respond()
{
emit stopCap();
}
/**
* @brief Camera stream receiver
**/
void UserScreen::imShow(cv::Mat m)
{
QImage qm = MatToQImage(m);
QPixmap px;
px.convertFromImage(qm);
QPixmap scaledPixmap = px.scaled(ui->label_3->size(), Qt::KeepAspectRatio);
QPainter* paint = new QPainter(&scaledPixmap);
paint->drawRect(ui->horizontalSlider_2->value(),ui->horizontalSlider_3->value(),ui->horizontalSlider_4->value(),ui->horizontalSlider->value());
ui->label_3->setPixmap( scaledPixmap);
delete paint;
ui->horizontalSlider_3->setMaximum(scaledPixmap.height());
ui->horizontalSlider_2->setMaximum(scaledPixmap.width());
ui->horizontalSlider->setMaximum(scaledPixmap.height() - ui->horizontalSlider_3->value());
ui->horizontalSlider_4->setMaximum(scaledPixmap.width() - ui->horizontalSlider_2->value());
}
/**
* @brief Capture stopping handler
**/
void UserScreen::captureStop()
{
disconnect(this,SLOT(imShow(cv::Mat)));
disconnect(this,SLOT(sendPic()));
if(isCapturing)
{
isCapturing = 0;
ui->pushButton->setText("START");
cc->terminate();
cc->wait();
cc->End();
delete cc;
}
if(t->isActive())
{
t->stop();
delete t;
}
}
/**
* @brief Sender
**/
void UserScreen::sendPic()
{
if(ui->label_3->pixmap())
{
char *d;
QImage cut = ui->label_3->pixmap()->toImage().copy(ui->horizontalSlider_2->value(),ui->horizontalSlider_3->value(),ui->horizontalSlider_4->value(),ui->horizontalSlider->value());
int size = cut.byteCount();
d = (char*)cut.bits();
Packet p(PIC_SEND, session, size, d);
Packet* resp = p.send("127.0.0.1",1337);
if (resp->getRequestID() != RESP_OK)
{
qDebug() << "Error sending pic: byte count = " << size;
}
delete resp;
}
}