Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Wagner José Kramer Vieira
VSSS
Commits
bb7fe1f7
Commit
bb7fe1f7
authored
Oct 14, 2019
by
Wagner José Kramer Vieira
Browse files
update 14-10
parent
edd7f67f
Changes
9
Hide whitespace changes
Inline
Side-by-side
.idea/.name
deleted
100644 → 0
View file @
edd7f67f
VSSS
\ No newline at end of file
VSSS.pro.user
View file @
bb7fe1f7
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.1, 2019-10-12T14:
18:45
. -->
<!-- Written by QtCreator 4.8.1, 2019-10-12T14:
24:16
. -->
<qtcreator>
<data>
<variable>
EnvironmentId
</variable>
...
...
@@ -293,19 +293,20 @@
</valuelist>
<value
type=
"int"
key=
"PE.EnvironmentAspect.Base"
>
2
</value>
<valuelist
type=
"QVariantList"
key=
"PE.EnvironmentAspect.Changes"
/>
<value
type=
"QString"
key=
"ProjectExplorer.CustomExecutableRunConfiguration.Executable"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
Custom Executable
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
VSSS
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
ProjectExplorer.CustomExecutableRunConfiguration
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
Qt4ProjectManager.Qt4RunConfiguration:/home/kramer/VSSS/VSSS.pro
</value>
<value
type=
"QString"
key=
"Qt4ProjectManager.Qt4RunConfiguration.ProFile"
>
VSSS.pro
</value>
<value
type=
"QString"
key=
"RunConfiguration.Arguments"
></value>
<value
type=
"uint"
key=
"RunConfiguration.QmlDebugServerPort"
>
3768
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseCppDebugger"
>
false
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseCppDebuggerAuto"
>
true
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseLibrarySearchPath"
>
true
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseMultiProcess"
>
false
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseQmlDebugger"
>
false
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseQmlDebuggerAuto"
>
true
</value>
<value
type=
"QString"
key=
"RunConfiguration.WorkingDirectory"
></value>
<value
type=
"QString"
key=
"RunConfiguration.WorkingDirectory.default"
></value>
<value
type=
"QString"
key=
"RunConfiguration.WorkingDirectory.default"
>
/home/kramer/build-VSSS-Desktop-Debug
</value>
</valuemap>
<value
type=
"int"
key=
"ProjectExplorer.Target.RunConfigurationCount"
>
1
</value>
</valuemap>
...
...
backend.cpp
View file @
bb7fe1f7
...
...
@@ -10,6 +10,7 @@
#include "ui_mainwindow.h"
#include <experimental/filesystem>
#include <math.h>
#define PI 3.14159265
using
namespace
std
;
using
namespace
cv
;
using
namespace
Global
;
...
...
@@ -17,14 +18,14 @@ using namespace Global;
namespace
fs
=
std
::
experimental
::
filesystem
;
std
::
chrono
::
high_resolution_clock
::
time_point
lastFrame
;
QTimer
timer
;
int
counter
=
0
;
double
counter
=
0
;
void
countFrames
(){
fps
=
frames
;
frames
=
0
;
QTimer
::
singleShot
(
1000
,
&
countFrames
);
};
double
angleBetweenTwoPoints
(
Point2
f
p1
,
Point2
f
p2
)
{
double
angleBetweenTwoPoints
(
Point2
d
p1
,
Point2
d
p2
)
{
if
(
p1
.
y
>
p2
.
y
){
double
x
=
p2
.
x
-
p1
.
x
;
double
y
=
p2
.
y
-
p1
.
y
;
...
...
@@ -58,7 +59,7 @@ void getFrame(){
timer
.
stop
();
return
;
}
if
(
counter
==
cap
.
get
(
CAP_PROP_FRAME_COUNT
))
if
(
fabs
(
counter
)
==
fabs
(
cap
.
get
(
CAP_PROP_FRAME_COUNT
))
)
{
cap
.
set
(
CAP_PROP_POS_FRAMES
,
0
);
counter
=
0
;
...
...
@@ -141,18 +142,18 @@ void findBall() {
std
::
sort
(
contours
.
begin
(),
contours
.
end
(),
[](
std
::
vector
<
cv
::
Point
>
contour1
,
std
::
vector
<
cv
::
Point
>
contour2
)
{
double
i
=
fabs
(
contourArea
(
cv
::
Mat
(
contour1
))
);
double
j
=
fabs
(
contourArea
(
cv
::
Mat
(
contour2
))
);
return
(
i
<
j
);
return
(
i
>
j
);
});
if
(
contours
.
size
()
>
0
){
Point2f
center
;
float
radius
;
minEnclosingCircle
(
contours
[
contours
.
size
()
-
1
],
center
,
radius
);
minEnclosingCircle
(
contours
[
0
],
center
,
radius
);
if
(
radius
>
10
){
ballPosition
=
center
;
return
;
}
}
ballPosition
=
Point2
f
(
-
NAN
,
-
NAN
);
ballPosition
=
Point2
d
(
static_cast
<
double
>
(
-
NAN
)
,
static_cast
<
double
>
(
-
NAN
)
)
;
}
void
detectAlly
()
{
...
...
@@ -179,20 +180,18 @@ void detectAlly() {
bool
rob5Found
=
false
;
for
(
const
auto
&
contour
:
contours
)
{
if
(
contourArea
(
contour
)
>
100
){
vector
<
Point2
f
>
points
;
vector
<
Point2
d
>
points
;
approxPolyDP
(
contour
,
points
,
0.05
*
arcLength
(
contour
,
true
),
true
);
if
(
points
.
size
()
==
3
)
{
if
(
!
rob3Found
){
posRobot1
=
Point2f
((
points
[
0
].
x
+
points
[
1
].
x
+
points
[
2
].
x
)
/
3
,
(
points
[
0
].
y
+
points
[
1
].
y
+
points
[
2
].
y
)
/
3
);
posRobots
[
0
]
=
(
points
[
0
]
+
points
[
1
]
+
points
[
2
])
/
3
;
lastAllyFormats
.
emplace_back
(
points
);
rob3Found
=
true
;
}
}
if
(
points
.
size
()
==
4
)
{
if
(
!
rob4Found
){
posRobot2
=
Point2f
((
points
[
0
].
x
+
points
[
1
].
x
+
points
[
2
].
x
+
points
[
3
].
x
)
/
4
,
(
points
[
0
].
y
+
points
[
1
].
y
+
points
[
2
].
y
+
points
[
3
].
y
)
/
4
);
posRobots
[
1
]
=
(
points
[
0
]
+
points
[
1
]
+
points
[
2
]
+
points
[
3
])
/
4
;
lastAllyFormats
.
emplace_back
(
points
);
rob4Found
=
true
;
}
...
...
@@ -200,8 +199,7 @@ void detectAlly() {
}
if
(
points
.
size
()
==
5
)
{
if
(
!
rob5Found
){
posRobot3
=
Point2f
((
points
[
0
].
x
+
points
[
1
].
x
+
points
[
2
].
x
+
points
[
3
].
x
+
points
[
4
].
x
)
/
5
,
(
points
[
0
].
y
+
points
[
1
].
y
+
points
[
2
].
y
+
points
[
3
].
y
+
points
[
4
].
y
)
/
5
);
posRobots
[
2
]
=
(
points
[
0
]
+
points
[
1
]
+
points
[
2
]
+
points
[
3
]
+
points
[
4
])
/
5
;
lastAllyFormats
.
emplace_back
(
points
);
}
...
...
@@ -216,11 +214,11 @@ void detectAlly() {
findContours
(
thresholdAllyF
,
contours
,
hierarchy
,
RETR_TREE
,
CHAIN_APPROX_SIMPLE
,
Point
(
0
,
0
));
qApp
->
processEvents
();
vector
<
vector
<
Point2
f
>>
triangles
;
vector
<
vector
<
Point2
d
>>
triangles
;
lastTriangles
.
clear
();
for
(
const
auto
&
contour
:
contours
)
{
if
(
contourArea
(
contour
)
>
100
){
vector
<
Point2
f
>
points
;
vector
<
Point2
d
>
points
;
approxPolyDP
(
contour
,
points
,
arcLength
(
contour
,
true
)
*
0.05
,
true
);
if
(
points
.
size
()
==
3
)
{
...
...
@@ -234,20 +232,20 @@ void detectAlly() {
}
if
(
triangles
.
size
()
==
6
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
vector
<
Point2
f
>
mediaT0
;
vector
<
Point2
d
>
mediaT0
;
mediaT0
.
emplace_back
(
Point2
f
((
triangles
[
0
][
0
].
x
+
triangles
[
0
][
1
].
x
)
/
2
,
(
triangles
[
0
][
0
].
y
+
triangles
[
0
][
1
].
y
)
/
2
));
Point2
d
((
triangles
[
0
][
0
].
x
+
triangles
[
0
][
1
].
x
)
/
2
,
(
triangles
[
0
][
0
].
y
+
triangles
[
0
][
1
].
y
)
/
2
));
mediaT0
.
emplace_back
(
Point2
f
((
triangles
[
0
][
1
].
x
+
triangles
[
0
][
2
].
x
)
/
2
,
(
triangles
[
0
][
1
].
y
+
triangles
[
0
][
2
].
y
)
/
2
));
Point2
d
((
triangles
[
0
][
1
].
x
+
triangles
[
0
][
2
].
x
)
/
2
,
(
triangles
[
0
][
1
].
y
+
triangles
[
0
][
2
].
y
)
/
2
));
mediaT0
.
emplace_back
(
Point2
f
((
triangles
[
0
][
2
].
x
+
triangles
[
0
][
0
].
x
)
/
2
,
(
triangles
[
0
][
2
].
y
+
triangles
[
0
][
0
].
y
)
/
2
));
Point2
d
((
triangles
[
0
][
2
].
x
+
triangles
[
0
][
0
].
x
)
/
2
,
(
triangles
[
0
][
2
].
y
+
triangles
[
0
][
0
].
y
)
/
2
));
for
(
std
::
size_t
k
=
1
;
k
<
triangles
.
size
();
k
++
)
{
vector
<
Point2
f
>
mediaTi
;
mediaTi
.
emplace_back
(
Point2
f
((
triangles
[
k
][
0
].
x
+
triangles
[
k
][
1
].
x
)
/
2
,
vector
<
Point2
d
>
mediaTi
;
mediaTi
.
emplace_back
(
Point2
d
((
triangles
[
k
][
0
].
x
+
triangles
[
k
][
1
].
x
)
/
2
,
(
triangles
[
k
][
0
].
y
+
triangles
[
k
][
1
].
y
)
/
2
));
mediaTi
.
emplace_back
(
Point2
f
((
triangles
[
k
][
1
].
x
+
triangles
[
k
][
2
].
x
)
/
2
,
mediaTi
.
emplace_back
(
Point2
d
((
triangles
[
k
][
1
].
x
+
triangles
[
k
][
2
].
x
)
/
2
,
(
triangles
[
k
][
1
].
y
+
triangles
[
k
][
2
].
y
)
/
2
));
mediaTi
.
emplace_back
(
Point2
f
((
triangles
[
k
][
2
].
x
+
triangles
[
k
][
0
].
x
)
/
2
,
mediaTi
.
emplace_back
(
Point2
d
((
triangles
[
k
][
2
].
x
+
triangles
[
k
][
0
].
x
)
/
2
,
(
triangles
[
k
][
2
].
y
+
triangles
[
k
][
0
].
y
)
/
2
));
vector
<
double
>
distance
;
for
(
size_t
x
=
0
;
x
<
3
;
x
++
)
{
...
...
@@ -255,99 +253,80 @@ void detectAlly() {
distance
.
emplace_back
(
norm
(
mediaT0
[
x
]
-
mediaTi
[
y
]));
}
}
int
pos
=
max_element
(
distance
.
begin
(),
distance
.
end
())
-
distance
.
begin
();
size_t
x
=
floor
(
pos
/
3
);
int
pos
=
static_cast
<
int
>
(
max_element
(
distance
.
begin
(),
distance
.
end
())
-
distance
.
begin
()
)
;
size_t
x
=
static_cast
<
size_t
>
(
floor
(
pos
/
3
)
)
;
size_t
y
=
pos
%
3
;
if
(
norm
(
triangles
[
0
][(
x
+
2
)
%
3
]
-
triangles
[
k
][(
y
+
2
)
%
3
])
<
DISTANCE
&&
std
::
abs
(
angleBetweenTwoPoints
(
triangles
[
0
][
x
],
triangles
[
0
][(
x
+
1
)
%
3
])
-
angleBetweenTwoPoints
(
triangles
[
k
][
y
],
triangles
[
k
][(
y
+
1
)
%
3
]))
<
10
)
{
Point2
f
media
=
(
triangles
[
0
][
0
]
+
triangles
[
0
][
1
]
+
triangles
[
0
][
2
]
Point2
d
media
=
(
triangles
[
0
][
0
]
+
triangles
[
0
][
1
]
+
triangles
[
0
][
2
]
+
triangles
[
k
][
0
]
+
triangles
[
k
][
1
]
+
triangles
[
k
][
2
])
/
6
;
double
dist1
=
norm
(
posRobot1
-
media
);
double
dist2
=
norm
(
posRobot2
-
media
);
double
dist3
=
norm
(
posRobot3
-
media
);
if
((
dist1
<
dist2
)
&&
(
dist1
<
dist3
))
{
frenteRobot1
=
(
triangles
[
0
][(
x
+
2
)
%
3
]
+
triangles
[
k
][(
y
+
2
)
%
3
])
/
2
;
if
(
norm
(
posRobot1
-
triangles
[
0
][
x
])
>
norm
(
posRobot1
-
triangles
[
0
][(
x
+
1
)
%
3
]))
{
contornosRobot1
.
clear
();
contornosRobot1
.
emplace_back
(
triangles
[
0
][
x
]);
if
(
norm
(
posRobot1
-
triangles
[
k
][
y
])
>
norm
(
posRobot1
-
triangles
[
k
][(
y
+
1
)
%
3
]))
{
contornosRobot1
.
emplace_back
(
triangles
[
k
][
y
]);
contornosRobot1
.
emplace_back
(((
triangles
[
0
][
x
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
contornosRobot1
.
emplace_back
(((
triangles
[
k
][
y
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
}
else
{
contornosRobot1
.
emplace_back
(
triangles
[
k
][(
y
+
1
)
%
3
]);
contornosRobot1
.
emplace_back
(((
triangles
[
0
][
x
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
contornosRobot1
.
emplace_back
(((
triangles
[
k
][(
y
+
1
)
%
3
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
}
}
else
{
contornosRobot1
.
clear
();
contornosRobot1
.
emplace_back
(
triangles
[
0
][(
x
+
1
)
%
3
]);
if
(
norm
(
posRobot1
-
triangles
[
k
][
y
])
>
norm
(
posRobot1
-
triangles
[
k
][(
y
+
1
)
%
3
]))
{
contornosRobot1
.
emplace_back
(
triangles
[
k
][
y
]);
contornosRobot1
.
emplace_back
(((
triangles
[
0
][(
x
+
1
)
%
3
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
contornosRobot1
.
emplace_back
(((
triangles
[
k
][
y
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
}
else
{
contornosRobot1
.
emplace_back
(
triangles
[
k
][(
y
+
1
)
%
3
]);
contornosRobot1
.
emplace_back
(((
triangles
[
0
][(
x
+
1
)
%
3
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
contornosRobot1
.
emplace_back
(((
triangles
[
k
][(
y
+
1
)
%
3
]
-
posRobot1
)
*
-
1
)
+
posRobot1
);
}
vector
<
tuple
<
double
,
size_t
>>
distRobots
;
distRobots
.
emplace_back
(
tuple
(
norm
(
posRobots
[
0
]
-
media
),
0
));
distRobots
.
emplace_back
(
tuple
(
norm
(
posRobots
[
1
]
-
media
),
1
));
distRobots
.
emplace_back
(
tuple
(
norm
(
posRobots
[
2
]
-
media
),
2
));
sort
(
distRobots
.
begin
(),
distRobots
.
end
(),
[
=
](
tuple
<
double
,
int
>
a
,
tuple
<
double
,
int
>
b
){
return
get
<
double
>
(
a
)
<
get
<
double
>
(
b
);
});
size_t
robotIndex
=
get
<
size_t
>
(
distRobots
[
0
]);
frenteRobots
[
robotIndex
]
=
(
triangles
[
0
][(
x
+
2
)
%
3
]
+
triangles
[
k
][(
y
+
2
)
%
3
])
/
2
;
sort
(
triangles
[
0
].
begin
(),
triangles
[
0
].
end
(),
[
=
](
Point2d
a
,
Point2d
b
){
return
norm
(
posRobots
[
robotIndex
]
-
a
)
>
norm
(
posRobots
[
robotIndex
]
-
b
);
});
sort
(
triangles
[
k
].
begin
(),
triangles
[
k
].
end
(),
[
=
](
Point2d
a
,
Point2d
b
){
return
norm
(
posRobots
[
robotIndex
]
-
a
)
>
norm
(
posRobots
[
robotIndex
]
-
b
);
});
contornosRobots
[
robotIndex
].
clear
();
Point2d
aux
=
frenteRobots
[
robotIndex
]
-
posRobots
[
robotIndex
];
Point2d
esq
,
dir
;
double
angulo
=
atan2
(
aux
.
y
,
aux
.
x
)
*
180
/
PI
;
if
(
angulo
<
-
5
&&
angulo
>
-
175
){
if
(
triangles
[
0
][
0
].
x
<
triangles
[
k
][
0
].
x
){
esq
=
triangles
[
0
][
0
];
dir
=
triangles
[
k
][
0
];
}
else
{
dir
=
triangles
[
0
][
0
];
esq
=
triangles
[
k
][
0
];
}
}
else
if
(
dist2
<
dist1
&&
dist2
<
dist3
)
{
frenteRobot2
=
(
triangles
[
0
][(
x
+
2
)
%
3
]
+
triangles
[
k
][(
y
+
2
)
%
3
])
/
2
;
if
(
norm
(
posRobot2
-
triangles
[
0
][
x
])
>
norm
(
posRobot2
-
triangles
[
0
][(
x
+
1
)
%
3
]))
{
contornosRobot2
.
clear
();
contornosRobot2
.
emplace_back
(
triangles
[
0
][
x
]);
if
(
norm
(
posRobot2
-
triangles
[
k
][
y
])
>
norm
(
posRobot2
-
triangles
[
k
][(
y
+
1
)
%
3
]))
{
contornosRobot2
.
emplace_back
(
triangles
[
k
][
y
]);
contornosRobot2
.
emplace_back
(((
triangles
[
0
][
x
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
contornosRobot2
.
emplace_back
(((
triangles
[
k
][
y
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
}
else
{
contornosRobot2
.
emplace_back
(
triangles
[
k
][(
y
+
1
)
%
3
]);
contornosRobot2
.
emplace_back
(((
triangles
[
0
][
x
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
contornosRobot2
.
emplace_back
(((
triangles
[
k
][(
y
+
1
)
%
3
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
}
}
else
{
contornosRobot2
.
clear
();
contornosRobot2
.
emplace_back
(
triangles
[
0
][(
x
+
1
)
%
3
]);
if
(
norm
(
posRobot2
-
triangles
[
k
][
y
])
>
norm
(
posRobot2
-
triangles
[
k
][(
y
+
1
)
%
3
]))
{
contornosRobot2
.
emplace_back
(
triangles
[
k
][
y
]);
contornosRobot2
.
emplace_back
(((
triangles
[
0
][(
x
+
1
)
%
3
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
contornosRobot2
.
emplace_back
(((
triangles
[
k
][
y
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
}
else
{
contornosRobot2
.
emplace_back
(
triangles
[
k
][(
y
+
1
)
%
3
]);
contornosRobot2
.
emplace_back
(((
triangles
[
0
][(
x
+
1
)
%
3
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
contornosRobot2
.
emplace_back
(((
triangles
[
k
][(
y
+
1
)
%
3
]
-
posRobot2
)
*
-
1
)
+
posRobot2
);
}
}
else
if
(
angulo
>
5
&&
angulo
<
175
){
if
(
triangles
[
0
][
0
].
x
<
triangles
[
k
][
0
].
x
){
dir
=
triangles
[
0
][
0
];
esq
=
triangles
[
k
][
0
];
}
else
{
esq
=
triangles
[
0
][
0
];
dir
=
triangles
[
k
][
0
];
}
}
else
{
frenteRobot3
=
(
triangles
[
0
][(
x
+
2
)
%
3
]
+
triangles
[
k
][(
y
+
2
)
%
3
])
/
2
;
if
(
norm
(
posRobot3
-
triangles
[
0
][
x
])
>
norm
(
posRobot3
-
triangles
[
0
][(
x
+
1
)
%
3
]))
{
contornosRobot3
.
clear
();
contornosRobot3
.
emplace_back
(
triangles
[
0
][
x
]);
if
(
norm
(
posRobot3
-
triangles
[
k
][
y
])
>
norm
(
posRobot3
-
triangles
[
k
][(
y
+
1
)
%
3
]))
{
contornosRobot3
.
emplace_back
(
triangles
[
k
][
y
]);
contornosRobot3
.
emplace_back
(((
triangles
[
0
][
x
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
contornosRobot3
.
emplace_back
(((
triangles
[
k
][
y
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
}
else
{
contornosRobot3
.
emplace_back
(
triangles
[
k
][(
y
+
1
)
%
3
]);
contornosRobot3
.
emplace_back
(((
triangles
[
0
][
x
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
contornosRobot3
.
emplace_back
(((
triangles
[
k
][(
y
+
1
)
%
3
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
}
else
{
if
(
aux
.
x
>
0
){
if
(
triangles
[
0
][
0
].
y
>
triangles
[
k
][
0
].
y
){
dir
=
triangles
[
0
][
0
];
esq
=
triangles
[
k
][
0
];
}
else
{
esq
=
triangles
[
0
][
0
];
dir
=
triangles
[
k
][
0
];
}
}
else
{
contornosRobot3
.
clear
();
contornosRobot3
.
emplace_back
(
triangles
[
0
][(
x
+
1
)
%
3
]);
if
(
norm
(
posRobot3
-
triangles
[
k
][
y
])
>
norm
(
posRobot3
-
triangles
[
k
][(
y
+
1
)
%
3
]))
{
contornosRobot3
.
emplace_back
(
triangles
[
k
][
y
]);
contornosRobot3
.
emplace_back
(((
triangles
[
0
][(
x
+
1
)
%
3
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
contornosRobot3
.
emplace_back
(((
triangles
[
k
][
y
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
}
else
{
contornosRobot3
.
emplace_back
(
triangles
[
k
][(
y
+
1
)
%
3
]);
contornosRobot3
.
emplace_back
(((
triangles
[
0
][(
x
+
1
)
%
3
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
contornosRobot3
.
emplace_back
(((
triangles
[
k
][(
y
+
1
)
%
3
]
-
posRobot3
)
*
-
1
)
+
posRobot3
);
}
else
{
if
(
triangles
[
0
][
0
].
y
<=
triangles
[
k
][
0
].
y
){
dir
=
triangles
[
0
][
0
];
esq
=
triangles
[
k
][
0
];
}
else
{
esq
=
triangles
[
0
][
0
];
dir
=
triangles
[
k
][
0
];
}
}
}
aux
=
esq
-
dir
;
Point2d
rb
(
aux
.
x
*
cos
(
-
90
*
PI
/
180
)
-
aux
.
y
*
sin
(
-
90
*
PI
/
180
),
aux
.
x
*
sin
(
-
90
*
PI
/
180
)
+
aux
.
y
*
cos
(
-
90
*
PI
/
180
));
rb
+=
dir
;
aux
=
dir
-
rb
;
Point2d
lb
(
aux
.
x
*
cos
(
-
90
*
PI
/
180
)
-
aux
.
y
*
sin
(
-
90
*
PI
/
180
),
aux
.
x
*
sin
(
-
90
*
PI
/
180
)
+
aux
.
y
*
cos
(
-
90
*
PI
/
180
));
lb
+=
rb
;
contornosRobots
[
robotIndex
].
emplace_back
(
esq
);
contornosRobots
[
robotIndex
].
emplace_back
(
dir
);
contornosRobots
[
robotIndex
].
emplace_back
(
rb
);
contornosRobots
[
robotIndex
].
emplace_back
(
lb
);
posRobots
[
robotIndex
]
=
(
esq
+
dir
+
rb
+
lb
)
/
4
;
triangles
.
erase
(
triangles
.
begin
()
+
0
);
triangles
.
erase
(
triangles
.
begin
()
+
k
-
1
);
triangles
.
erase
(
triangles
.
begin
()
+
static_cast
<
int
>
(
k
-
1
)
)
;
}
}
}
...
...
@@ -369,19 +348,19 @@ void findEnemies() {
mu
.
emplace_back
(
moments
(
contours
[
i
]));
}
vector
<
Point2
f
>
mc
;
vector
<
Point2
d
>
mc
;
for
(
size_t
i
=
0
;
i
<
mu
.
size
();
i
++
)
{
if
((
mu
[
i
].
m10
/
mu
[
i
].
m00
)
>
0
)
mc
.
push_back
(
Point2
f
(
mu
[
i
].
m10
/
mu
[
i
].
m00
,
mu
[
i
].
m01
/
mu
[
i
].
m00
));
mc
.
push_back
(
Point2
d
(
mu
[
i
].
m10
/
mu
[
i
].
m00
,
mu
[
i
].
m01
/
mu
[
i
].
m00
));
}
if
(
mc
.
size
()
>
3
)
{
vector
<
Point2
f
>
ret
;
vector
<
Point2
d
>
ret
;
for
(
size_t
i
=
0
;
i
<
3
;
i
++
)
{
vector
<
Point2
f
>
vectorBackup
;
Point2
f
ponto
(
mc
[
0
].
x
,
mc
[
0
].
y
);
vector
<
Point2
d
>
vectorBackup
;
Point2
d
ponto
(
mc
[
0
].
x
,
mc
[
0
].
y
);
for
(
size_t
j
=
1
;
j
<
mc
.
size
();
j
++
)
{
if
(
norm
(
ponto
-
mc
[
j
])
<=
distanceTolerance
)
{
ponto
=
Point2
f
((
int
)
((
ponto
.
x
+
mc
[
j
].
x
)
/
2
),
(
int
)
((
ponto
.
y
+
mc
[
j
].
y
)
/
2
));
ponto
=
Point2
d
(
((
ponto
.
x
+
mc
[
j
].
x
)
/
2
),
((
ponto
.
y
+
mc
[
j
].
y
)
/
2
));
}
else
{
vectorBackup
.
push_back
(
mc
[
j
]);
}
...
...
backend.h
View file @
bb7fe1f7
...
...
@@ -2,8 +2,12 @@
#define BACKEND_HPP
#include <chrono>
#include <opencv2/opencv.hpp>
#include <QTimer>
extern
std
::
chrono
::
high_resolution_clock
::
time_point
lastFrame
;
extern
QTimer
timer
;
extern
double
counter
;
double
angleBetweenTwoPoints
(
cv
::
Point2f
p1
,
cv
::
Point2f
p2
);
void
startCapture
();
void
calibration
();
...
...
cmake-build-debug/CMakeFiles/clion-log.txt
0 → 100644
View file @
bb7fe1f7
CMakeLists.txt not found in /home/kramer/gitlab/vsss Select CMakeLists.txt file...
global.cpp
View file @
bb7fe1f7
...
...
@@ -8,8 +8,8 @@ using namespace cv;
namespace
Global
{
int
defaultImageHeight
;
vector
<
vector
<
Point2
f
>>
lastTriangles
;
vector
<
vector
<
Point2
f
>>
lastAllyFormats
;
vector
<
vector
<
Point2
d
>>
lastTriangles
;
vector
<
vector
<
Point2
d
>>
lastAllyFormats
;
bool
showAllyThreshold
=
true
;
bool
showAllyFThreshold
=
true
;
Mutex
mtx
;
...
...
@@ -45,13 +45,13 @@ namespace Global {
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
::
Point2
f
marcas
[]
=
{
cv
::
Point2
f
(
25
,
37.5
),
cv
::
Point2
f
(
65
,
37.5
),
cv
::
Point2
f
(
105
,
37.5
),
cv
::
Point2
f
(
25
,
112.5
),
cv
::
Point2
f
(
65
,
112.5
),
cv
::
Point2
f
(
105
,
112.5
)
const
cv
::
Point2
d
marcas
[]
=
{
cv
::
Point2
d
(
25
,
37.5
),
cv
::
Point2
d
(
65
,
37.5
),
cv
::
Point2
d
(
105
,
37.5
),
cv
::
Point2
d
(
25
,
112.5
),
cv
::
Point2
d
(
65
,
112.5
),
cv
::
Point2
d
(
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
...
...
@@ -69,7 +69,7 @@ namespace Global {
int
ballLS
=
120
;
///< Saturation mínimo
int
ballUV
=
255
;
///< Value máximo
int
ballLV
=
120
;
///< Value mínimo
cv
::
Point2
f
ballPosition
(
0
,
0
);
cv
::
Point2
d
ballPosition
(
0
,
0
);
///@}
/**
...
...
@@ -85,7 +85,7 @@ namespace Global {
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
::
Point2
f
>
enemies
;
vector
<
cv
::
Point2
d
>
enemies
;
///@}
/**
...
...
@@ -94,18 +94,9 @@ namespace Global {
* @addtogroup Aliados
* @{
*/
cv
::
Point2f
posRobot1
(
0
,
0
);
cv
::
Point2f
posRobot2
(
0
,
0
);
cv
::
Point2f
posRobot3
(
0
,
0
);
cv
::
Point2f
frenteRobot1
(
0
,
0
);
cv
::
Point2f
frenteRobot2
(
0
,
0
);
cv
::
Point2f
frenteRobot3
(
0
,
0
);
std
::
vector
<
cv
::
Point2f
>
contornosRobot1
;
std
::
vector
<
cv
::
Point2f
>
contornosRobot2
;
std
::
vector
<
cv
::
Point2f
>
contornosRobot3
;
vector
<
Point2d
>
posRobots
(
3
);
vector
<
Point2d
>
frenteRobots
(
3
);
vector
<
vector
<
Point2d
>>
contornosRobots
(
3
);
int
allyUH
=
150
;
///< Hue máximo
int
allyLH
=
100
;
///< Hue mínimo
...
...
global.h
View file @
bb7fe1f7
...
...
@@ -7,8 +7,8 @@ using namespace cv;
namespace
Global
{
extern
int
defaultImageHeight
;
extern
vector
<
vector
<
Point2
f
>>
lastTriangles
;
extern
vector
<
vector
<
Point2
f
>>
lastAllyFormats
;
extern
vector
<
vector
<
Point2
d
>>
lastTriangles
;
extern
vector
<
vector
<
Point2
d
>>
lastAllyFormats
;
extern
bool
showAllyThreshold
;
extern
bool
showAllyFThreshold
;
extern
Mutex
mtx
;
...
...
@@ -44,7 +44,7 @@ namespace Global {
extern
const
double
proporcao
;
///< Proporção do tamanho do campo para píxels, equivale a 1 cm
extern
const
int
comprimento
;
///< Largura do campo em cm
extern
const
int
altura
;
///< Altura do campo em cm
extern
const
cv
::
Point2
f
marcas
[];
///< Posição das marcações do campo
extern
const
cv
::
Point2
d
marcas
[];
///< Posição das marcações do campo
extern
const
int
alturaGol
;
///< Altura do gol
extern
const
int
alturaAG
;
///< Altura da área do gol
extern
const
int
larguraAG
;
///< Largura da área do gol
...
...
@@ -61,7 +61,7 @@ namespace Global {
extern
int
ballLS
;
///< Saturation mínimo
extern
int
ballUV
;
///< Value máximo
extern
int
ballLV
;
///< Value mínimo
extern
cv
::
Point2
f
ballPosition
;
extern
cv
::
Point2
d
ballPosition
;
///@}
/**
...
...
@@ -77,7 +77,7 @@ namespace Global {
extern
int
enemyUV
;
///< Value máximo
extern
int
enemyLV
;
///< Value mínimo
extern
double
distanceTolerance
;
///< Tolerância de distancia entre pontos para considerar como um robô
extern
vector
<
cv
::
Point2
f
>
enemies
;
extern
vector
<
cv
::
Point2
d
>
enemies
;
///@}
/**
...
...
@@ -86,18 +86,9 @@ namespace Global {
* @addtogroup Aliados
* @{
*/
extern
cv
::
Point2f
posRobot1
;
extern
cv
::
Point2f
posRobot2
;
extern
cv
::
Point2f
posRobot3
;
extern
cv
::
Point2f
frenteRobot1
;
extern
cv
::
Point2f
frenteRobot2
;
extern
cv
::
Point2f
frenteRobot3
;
extern
std
::
vector
<
cv
::
Point2f
>
contornosRobot1
;
extern
std
::
vector
<
cv
::
Point2f
>
contornosRobot2
;
extern
std
::
vector
<
cv
::
Point2f
>
contornosRobot3
;
extern
vector
<
Point2d
>
posRobots
;
extern
vector
<
Point2d
>
frenteRobots
;
extern
vector
<
vector
<
Point2d
>>
contornosRobots
;
extern
int
allyUH
;
///< Hue máximo
extern
int
allyLH
;
///< Hue mínimo
...
...
mainwindow.cpp
View file @
bb7fe1f7
...
...
@@ -14,11 +14,11 @@ using namespace cv;
using
namespace
std
;
void
calcHomography
(){
vector
<
Point2
f
>
base
;
base
.
push_back
(
Point2
f
(
0
,
0
));
base
.
push_back
(
Point2
f
(
0
,
1300
));
base
.
push_back
(
Point2
f
(
1500
,
1300
));
base
.
push_back
(
Point2
f
(
1500
,
0
));
vector
<
Point2
d
>
base
;
base
.
push_back
(
Point2
d
(
0
,
0
));
base
.
push_back
(
Point2
d
(
0
,
1300
));
base
.
push_back
(
Point2
d
(
1500
,
1300
));
base
.
push_back
(
Point2
d
(
1500
,
0
));
Global
::
homography
=
findHomography
(
Global
::
corners
,
base
);
}
...
...
@@ -35,10 +35,6 @@ MainWindow::MainWindow(QWidget *parent) :
Global
::
corners
[
2
]
=
Point2f
(
100
,
100
);
Global
::
corners
[
3
]
=
Point2f
(
100
,
0
);
calcHomography
();
std
::
sort
(
Global
::
corners
.
begin
(),
Global
::
corners
.
end
(),
[](
const
cv
::
Point2f
&
a
,
const
cv
::
Point2f
&
b
)
{
return
a
.
x
<
b
.
x
;
});
// Conexão de sliders com variáveis
//Bola
connect
(
ui
->
sliderBallUH
,
&
QSlider
::
valueChanged
,[
=
](
const
int
&
value
)
->
void
{
Global
::
ballUH
=
value
;
ui
->
lblBallUH
->
setText
(
QString
::
fromUtf8
(
"UH = "
)
+
QString
::
number
(
value
));});
...
...
@@ -74,16 +70,16 @@ MainWindow::MainWindow(QWidget *parent) :
// Outras conexões com variáveis
connect
(
ui
->
tabWidget
,
&
QTabWidget
::
currentChanged
,
[
=
](
const
int
&
value
)
->
void
{
Global
::
actualTab
=
value
;});
connect
(
ui
->
LTX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
1
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
LTY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
1
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
BLX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
2
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
BLY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
2
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
BRX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
3
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
BRY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
3
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
RTX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
0
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
RTY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
0
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
btnAllyCenter
,
&
QPushButton
::
clicked
,
[
=
](
const
bool
&
check
){
Global
::
showAllyThreshold
=
!
Global
::
showAllyThreshold
;});
connect
(
ui
->
btnAllyFrente
,
&
QPushButton
::
clicked
,
[
=
](
const
bool
&
check
){
Global
::
showAllyFThreshold
=
!
Global
::
showAllyFThreshold
;});
connect
(
ui
->
LTX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
0
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
LTY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
0
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
BLX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
3
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
BLY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
3
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
BRX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
2
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
BRY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
2
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
RTX
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
1
].
x
=
value
;
calcHomography
();});
connect
(
ui
->
RTY
,
qOverload
<
int
>
(
&
QSpinBox
::
valueChanged
),
[
=
](
const
int
&
value
)
->
void
{
Global
::
corners
[
1
].
y
=
value
;
calcHomography
();});
connect
(
ui
->
btnAllyCenter
,
&
QPushButton
::
clicked
,
[
=
](){
Global
::
showAllyThreshold
=
!
Global
::
showAllyThreshold
;});
connect
(
ui
->
btnAllyFrente
,
&
QPushButton
::
clicked
,
[
=
](){
Global
::
showAllyFThreshold
=
!
Global
::
showAllyFThreshold
;});
}
...
...
@@ -116,116 +112,112 @@ void MainWindow::on_btnCamera_clicked()
}
void
MainWindow
::
setUiImage
(){
QImage
qimg
;
qApp
->
processEvents
();
double
h
=
Global
::
defaultImageHeight
;
double
w
=
(
Global
::
frame
.
cols
*
h
)
/
Global
::
frame
.
rows
;
Global
::
mtx
.
lock
();
try
{
switch
(
Global
::
actualTab
)
{
case
0
:
if
(
Global
::
cameraStatus
==
0
){
qimg
=
QImage
(
Global
::
frame
.
data
,
Global
::
frame
.
cols
,
Global
::
frame
.
rows
,
Global
::
frame
.
step
,
QImage
::
Format_RGB888
);
if
(
Global
::
frame
.
rows
>
0
){