Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
V
VSSS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wagner José Kramer Vieira
VSSS
Commits
3e40da03
Commit
3e40da03
authored
Oct 27, 2019
by
Wagner José Kramer Vieira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update with starting server
parent
bb7fe1f7
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
401 additions
and
228 deletions
+401
-228
VSSS.pro
VSSS.pro
+5
-3
VSSS.pro.user
VSSS.pro.user
+1
-1
backend.cpp
backend.cpp
+98
-63
backend.h
backend.h
+16
-5
global.cpp
global.cpp
+108
-123
global.h
global.h
+19
-0
localserver.cpp
localserver.cpp
+87
-0
localserver.h
localserver.h
+16
-0
mainwindow.cpp
mainwindow.cpp
+49
-32
mainwindow.h
mainwindow.h
+2
-1
No files found.
VSSS.pro
View file @
3e40da03
...
...
@@ -5,7 +5,7 @@
#-------------------------------------------------
QT
+=
core
gui
QT
+=
network
greaterThan
(
QT_MAJOR_VERSION
,
4
)
:
QT
+=
widgets
TARGET
=
VSSS
...
...
@@ -29,14 +29,16 @@ SOURCES += \
main
.
cpp
\
mainwindow
.
cpp
\
backend
.
cpp
\
global
.
cpp
global
.
cpp
\
localserver
.
cpp
LIBS
+=
-
lstdc
++
fs
HEADERS
+=
\
mainwindow
.
h
\
global
.
h
\
backend
.
h
backend
.
h
\
localserver
.
h
FORMS
+=
\
mainwindow
.
ui
...
...
VSSS.pro.user
View file @
3e40da03
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.1, 2019-10-
12T14:24:16
. -->
<!-- Written by QtCreator 4.8.1, 2019-10-
27T01:09:54
. -->
<qtcreator>
<data>
<variable>
EnvironmentId
</variable>
...
...
backend.cpp
View file @
3e40da03
This diff is collapsed.
Click to expand it.
backend.h
View file @
3e40da03
...
...
@@ -3,7 +3,8 @@
#include <chrono>
#include <opencv2/opencv.hpp>
#include <QTimer>
#include <QThread>
#include "global.h"
extern
std
::
chrono
::
high_resolution_clock
::
time_point
lastFrame
;
extern
QTimer
timer
;
extern
double
counter
;
...
...
@@ -13,9 +14,19 @@ void startCapture();
void
calibration
();
void
gerenciador
();
void
getFrame
();
void
frameMod
();
void
findBall
();
void
detectAlly
();
void
findEnemies
();
void
frameMod
(
Global
::
ThreadVariables
*
var
);
void
findBall
(
Global
::
ThreadVariables
*
var
);
void
detectAlly
(
Global
::
ThreadVariables
*
var
);
void
findEnemies
(
Global
::
ThreadVariables
*
var
);
void
estrategia
();
class
Threader
:
public
QThread
{
public:
Threader
();
void
run
();
};
extern
std
::
vector
<
Threader
*>
threads
;
#endif // BACKEND_HPP
global.cpp
View file @
3e40da03
#include <opencv2/opencv.hpp>
#include "global.h"
#include <mutex>
#include <QDebug>
using
namespace
std
;
using
namespace
cv
;
namespace
Global
{
int
defaultImageHeight
;
vector
<
vector
<
Point2d
>>
lastTriangles
;
vector
<
vector
<
Point2d
>>
lastAllyFormats
;
bool
showAllyThreshold
=
true
;
bool
showAllyFThreshold
=
true
;
Mutex
mtx
;
int
cameraStatus
=
0
;
VideoCapture
cap
;
bool
capActive
=
false
;
Mat
frame
;
Mat
correctedFrame
;
Mat
frameHSV
;
Mat
thresholdAllyF
;
Mat
thresholdAllyC
;
Mat
thresholdBall
;
Mat
thresholdEnemy
;
int
frames
=
0
;
int
fps
=
0
;
bool
frameModReady
=
true
;
bool
enemyDetectionReady
=
true
;
bool
ballDetectionReady
=
true
;
bool
allyDetectionReady
=
true
;
bool
strategyCompilerReady
=
true
;
ThreadVariables
::~
ThreadVariables
(){
Global
::
frame
=
frame
;
Global
::
frameHSV
=
frameHSV
;
Global
::
correctedFrame
=
correctedFrame
;
Global
::
thresholdBall
=
thresholdBall
;
Global
::
thresholdAllyF
=
thresholdAllyF
;
Global
::
thresholdAllyC
=
thresholdAllyC
;
Global
::
thresholdEnemy
=
thresholdEnemy
;
Global
::
posRobots
=
posRobots
;
Global
::
frenteRobots
=
frenteRobots
;
Global
::
contornosRobots
=
contornosRobots
;
Global
::
enemies
=
enemies
;
Global
::
ballPosition
=
ballPosition
;
}
ThreadVariables
::
ThreadVariables
(){
posRobots
=
vector
<
Point2d
>
(
3
);
frenteRobots
=
vector
<
Point2d
>
(
3
);
contornosRobots
=
vector
<
vector
<
Point2d
>>
(
3
);
};
int
defaultImageHeight
;
vector
<
vector
<
Point2d
>>
lastTriangles
;
vector
<
vector
<
Point2d
>>
lastAllyFormats
;
bool
showAllyThreshold
=
true
;
bool
showAllyFThreshold
=
true
;
Mutex
mtx
;
int
cameraStatus
=
0
;
VideoCapture
cap
;
bool
capActive
=
false
;
Mat
frame
;
Mat
correctedFrame
;
Mat
frameHSV
;
Mat
thresholdAllyF
;
Mat
thresholdAllyC
;
Mat
thresholdBall
;
Mat
thresholdEnemy
;
int
frames
=
0
;
int
fps
=
0
;
bool
frameModReady
=
true
;
bool
enemyDetectionReady
=
true
;
bool
ballDetectionReady
=
true
;
bool
allyDetectionReady
=
true
;
bool
strategyCompilerReady
=
true
;
int
actualTab
;
const
double
proporcao
=
7.5
;
const
int
comprimento
=
150
;
const
int
altura
=
130
;
const
cv
::
Point2d
marcas
[]
=
{
cv
::
Point2d
(
25
,
37.5
),
cv
::
Point2d
(
65
,
37.5
),
cv
::
Point2d
(
105
,
37.5
),
cv
::
Point2d
(
25
,
112.5
),
cv
::
Point2d
(
65
,
112.5
),
cv
::
Point2d
(
105
,
112.5
)
};
const
int
alturaGol
=
40
;
const
int
alturaAG
=
70
;
const
int
larguraAG
=
15
;
int
ballUH
=
20
;
int
ballLH
=
9
;
int
ballUS
=
255
;
int
ballLS
=
120
;
int
ballUV
=
255
;
int
ballLV
=
120
;
cv
::
Point2d
ballPosition
(
0
,
0
);
int
actualTab
;
///< Index atual do tab widget
/**
* @defgroup Global
* @brief Constantes e variáveis globais do software
* @addtogroup Global
* @{
* @defgroup Constantes
* @brief Constantes do software
* @addtogroup Constantes
* @{
*/
const
double
proporcao
=
7.5
;
///< Proporção do tamanho do campo para píxels, equivale a 1 cm
const
int
comprimento
=
150
;
///< Largura do campo em cm
const
int
altura
=
130
;
///< Altura do campo em cm
const
cv
::
Point2d
marcas
[]
=
{
cv
::
Point2d
(
25
,
37.5
),
cv
::
Point2d
(
65
,
37.5
),
cv
::
Point2d
(
105
,
37.5
),
cv
::
Point2d
(
25
,
112.5
),
cv
::
Point2d
(
65
,
112.5
),
cv
::
Point2d
(
105
,
112.5
)
};
///< Posição das marcações do campo
const
int
alturaGol
=
40
;
///< Altura do gol
const
int
alturaAG
=
70
;
///< Altura da área do gol
const
int
larguraAG
=
15
;
///< Largura da área do gol
/**
*@}
* @defgroup Bola
* @brief Variáveis utilizadas no reconhecimento da bola
* @addtogroup Bola
* @{
*/
int
ballUH
=
20
;
///< Hue máximo
int
ballLH
=
9
;
///< Hue mínimo
int
ballUS
=
255
;
///< Saturation máximo
int
ballLS
=
120
;
///< Saturation mínimo
int
ballUV
=
255
;
///< Value máximo
int
ballLV
=
120
;
///< Value mínimo
cv
::
Point2d
ballPosition
(
0
,
0
);
///@}
int
enemyUH
=
60
;
int
enemyLH
=
25
;
int
enemyUS
=
255
;
int
enemyLS
=
120
;
int
enemyUV
=
255
;
int
enemyLV
=
120
;
double
distanceTolerance
=
15
;
vector
<
cv
::
Point2d
>
enemies
;
/**
* @defgroup Oponentes
* @brief Variáveis usadas no reconhecimento dos oponentes
* @addtogroup Oponentes
* @{
*/
int
enemyUH
=
60
;
///< Hue máximo
int
enemyLH
=
25
;
///< Hue mínimo
int
enemyUS
=
255
;
///< Saturation máximo
int
enemyLS
=
120
;
///< Saturation mínimo
int
enemyUV
=
255
;
///< Value máximo
int
enemyLV
=
120
;
///< Value mínimo
double
distanceTolerance
=
15
;
///< Tolerância de distancia entre pontos para considerar como um robô
vector
<
cv
::
Point2d
>
enemies
;
///@}
vector
<
Point2d
>
posRobots
(
3
);
vector
<
Point2d
>
frenteRobots
(
3
);
vector
<
vector
<
Point2d
>>
contornosRobots
(
3
);
/**
* @defgroup Aliados
* @brief Vaiáveis de localização dos nossos robôs
* @addtogroup Aliados
* @{
*/
vector
<
Point2d
>
posRobots
(
3
);
vector
<
Point2d
>
frenteRobots
(
3
);
vector
<
vector
<
Point2d
>>
contornosRobots
(
3
);
int
allyUH
=
150
;
int
allyLH
=
100
;
int
allyUS
=
255
;
int
allyLS
=
120
;
int
allyUV
=
255
;
int
allyLV
=
120
;
int
allyUH
=
150
;
///< Hue máximo
int
allyLH
=
100
;
///< Hue mínimo
int
allyUS
=
255
;
///< Saturation máximo
int
allyLS
=
120
;
///< Saturation mínimo
int
allyUV
=
255
;
///< Value máximo
int
allyLV
=
120
;
///< Value mínimo
int
allyFUH
=
180
;
int
allyFLH
=
146
;
int
allyFUS
=
255
;
int
allyFLS
=
120
;
int
allyFUV
=
255
;
int
allyFLV
=
120
;
int
DISTANCE
=
15
;
int
allyFUH
=
180
;
///< Hue máximo
int
allyFLH
=
146
;
///< Hue mínimo
int
allyFUS
=
255
;
///< Saturation máximo
int
allyFLS
=
120
;
///< Saturation mínimo
int
allyFUV
=
255
;
///< Value máximo
int
allyFLV
=
120
;
///< Value mínimo
int
DISTANCE
=
15
;
/**
* @}
* @defgroup Calibração
* @brief Variáveis usadas na calibração da câmera
* @addtogroup Calibração
* @{
*/
std
::
vector
<
cv
::
Point2d
>
corners
(
4
);
///< Cantos do campo
cv
::
Point2d
midLeft
;
///< Centro esquerdo do campo
cv
::
Point2d
midRight
;
///< Centro direito do campo
double
rotation
=
0
;
///< Angulo de rotação do campo
int
confStatus
=
0
;
///< Estado atual da configuração
bool
confConcluded
=
false
;
///< Diz se a configuração foi terminada ou não
cv
::
Mat
homography
;
///< Homografia para correção de perspectiva
std
::
string
calibrationFramesPath
=
"/home/kramer/frames"
;
///< Caminho para os frames de calibração
std
::
vector
<
std
::
vector
<
cv
::
Point3f
>>
object_points
;
///<Variável utilizada pela função de calibração
std
::
vector
<
std
::
vector
<
cv
::
Point2f
>>
image_points
;
///<Variável utilizada pela função de calibração
std
::
vector
<
cv
::
Point2d
>
corners
(
4
);
cv
::
Point2d
midLeft
;
cv
::
Point2d
midRight
;
double
rotation
=
0
;
int
confStatus
=
0
;
bool
confConcluded
=
false
;
cv
::
Mat
homography
;
std
::
string
calibrationFramesPath
=
"/home/kramer/frames"
;
std
::
vector
<
std
::
vector
<
cv
::
Point3f
>>
object_points
;
std
::
vector
<
std
::
vector
<
cv
::
Point2f
>>
image_points
;
cv
::
Mat
intrinsic
=
cv
::
Mat
(
3
,
3
,
CV_32FC1
);
///<Variável utilizada pela função de calibração
cv
::
Mat
distCoeffs
;
///<Variável utilizada pela função de calibração
std
::
vector
<
cv
::
Mat
>
rvecs
;
///<Variável utilizada pela função de calibração
std
::
vector
<
cv
::
Mat
>
tvecs
;
///<Variável utilizada pela função de calibração
///@}
///@}
cv
::
Mat
intrinsic
=
cv
::
Mat
(
3
,
3
,
CV_32FC1
);
cv
::
Mat
distCoeffs
;
std
::
vector
<
cv
::
Mat
>
rvecs
;
std
::
vector
<
cv
::
Mat
>
tvecs
;
}
global.h
View file @
3e40da03
...
...
@@ -2,10 +2,29 @@
#define GLOBAL_H
#include <opencv2/opencv.hpp>
#include <mutex>
#include <chrono>
using
namespace
std
;
using
namespace
cv
;
using
namespace
std
::
chrono
;
namespace
Global
{
class
ThreadVariables
{
public:
ThreadVariables
();
~
ThreadVariables
();
Mat
frame
;
Mat
correctedFrame
;
Mat
frameHSV
;
Mat
thresholdBall
;
Mat
thresholdAllyF
;
Mat
thresholdAllyC
;
Mat
thresholdEnemy
;
vector
<
Point2d
>
posRobots
;
vector
<
Point2d
>
frenteRobots
;
vector
<
vector
<
Point2d
>>
contornosRobots
;
vector
<
Point2d
>
enemies
;
Point2d
ballPosition
;
};
extern
int
defaultImageHeight
;
extern
vector
<
vector
<
Point2d
>>
lastTriangles
;
extern
vector
<
vector
<
Point2d
>>
lastAllyFormats
;
...
...
localserver.cpp
0 → 100644
View file @
3e40da03
#include "localserver.h"
#include <QTcpSocket>
#include <QDataStream>
#include <QJsonObject>
#include <chrono>
#include <QJsonDocument>
#include <QJsonArray>
#include <opencv2/opencv.hpp>
#include "global.h"
using
namespace
std
::
chrono
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
Global
;
LocalServer
::
LocalServer
(
QObject
*
parent
)
:
QTcpServer
(
parent
)
{
mSocket
=
nullptr
;
connect
(
this
,
&
LocalServer
::
newConnection
,
[
&
](){
mSocket
=
nextPendingConnection
();
});
}
void
LocalServer
::
send
()
{
if
(
mSocket
)
{
high_resolution_clock
::
time_point
p
=
high_resolution_clock
::
now
();
milliseconds
ms
=
duration_cast
<
milliseconds
>
(
p
.
time_since_epoch
());
seconds
s
=
duration_cast
<
seconds
>
(
ms
);
std
::
time_t
t
=
s
.
count
();
std
::
size_t
fractional_seconds
=
ms
.
count
()
%
1000
;
QJsonObject
j
;
j
[
"time"
]
=
static_cast
<
int
>
(
fractional_seconds
);
QJsonArray
arr
;
for
(
size_t
i
=
0
;
i
<
3
;
i
++
){
QJsonObject
posRobot
;
posRobot
.
insert
(
"x"
,
posRobots
[
i
].
x
);
posRobot
.
insert
(
"y"
,
posRobots
[
i
].
y
);
arr
.
insert
(
static_cast
<
int
>
(
i
),
posRobot
);
}
j
.
insert
(
"posRobots"
,
arr
);
arr
=
QJsonArray
();
for
(
size_t
i
=
0
;
i
<
3
;
i
++
){
QJsonObject
frenteRobot
;
frenteRobot
.
insert
(
"x"
,
frenteRobots
[
i
].
x
);
frenteRobot
.
insert
(
"y"
,
frenteRobots
[
i
].
y
);
arr
.
insert
(
static_cast
<
int
>
(
i
),
frenteRobot
);
}
j
.
insert
(
"frenteRobots"
,
arr
);
arr
=
QJsonArray
();
for
(
size_t
i
=
0
;
i
<
3
;
i
++
){
QJsonArray
contornosRobot
;
for
(
size_t
j
=
0
;
j
<
contornosRobots
[
i
].
size
();
j
++
){
QJsonObject
contorno
;
contorno
.
insert
(
"x"
,
contornosRobots
[
i
][
j
].
x
);
contorno
.
insert
(
"y"
,
contornosRobots
[
i
][
j
].
y
);
contornosRobot
.
insert
(
static_cast
<
int
>
(
j
),
contorno
);
}
arr
.
insert
(
static_cast
<
int
>
(
i
),
contornosRobot
);
}
j
.
insert
(
"contornosRobots"
,
arr
);
arr
=
QJsonArray
();
for
(
size_t
i
=
0
;
i
<
3
;
i
++
){
QJsonObject
enemy
;
enemy
.
insert
(
"x"
,
enemies
[
i
].
x
);
enemy
.
insert
(
"y"
,
enemies
[
i
].
y
);
arr
.
insert
(
static_cast
<
int
>
(
i
),
enemy
);
}
j
.
insert
(
"enemies"
,
arr
);
QJsonObject
ball
;
ball
.
insert
(
"x"
,
ballPosition
.
x
);
ball
.
insert
(
"y"
,
ballPosition
.
y
);
j
.
insert
(
"ballPosition"
,
ball
);
QTextStream
D
(
mSocket
);
QJsonDocument
doc
(
j
);
D
<<
doc
.
toJson
();
mSocket
->
flush
();
}
}
localserver.h
0 → 100644
View file @
3e40da03
#ifndef LOCALSERVER_H
#define LOCALSERVER_H
#include <QTcpServer>
class
QTcpSocket
;
class
LocalServer
:
public
QTcpServer
{
Q_OBJECT
public:
explicit
LocalServer
(
QObject
*
parent
=
nullptr
);
void
send
();
QTcpSocket
*
mSocket
;
};
#endif // LOCALSERVER_H
mainwindow.cpp
View file @
3e40da03
This diff is collapsed.
Click to expand it.
mainwindow.h
View file @
3e40da03
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "localserver.h"
#include <QMainWindow>
namespace
Ui
{
class
MainWindow
;
}
...
...
@@ -27,6 +27,7 @@ private slots:
private:
Ui
::
MainWindow
*
ui
;
LocalServer
*
mLocalServer
;
protected:
void
closeEvent
(
QCloseEvent
*
event
)
override
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment