Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
klorydryk
FacialRecoTrackingScore
Commits
410ebe0b
Commit
410ebe0b
authored
Jan 30, 2020
by
klorydryk
Browse files
Right position of the cursor - Back to borders of letters - Increase cursor size
parent
961d5d72
Changes
1
Hide whitespace changes
Inline
Side-by-side
trackmultiplefaces.py
View file @
410ebe0b
...
...
@@ -37,13 +37,13 @@ suspiciousColors = {0:(0,0,0), 1:GREEN, 2:ORANGE, 3:RED}
avSusRectWidth
=
20
cursorSize
=
(
1
5
,
1
5
)
cursorSize
=
(
2
5
,
2
5
)
cursor
=
cv2
.
imread
(
'logo.png'
)
# Read the file
cursor
=
cv2
.
resize
(
cursor
,
cursorSize
)
averageSuspicious
=
0
NAME_COLOR
=
WHITE
NAME_COLOR
=
WHITE
IDENTIFYING_COLOR
=
WHITE
...
...
@@ -65,18 +65,18 @@ def doRecognizePerson(faceNames, fid):
def
displayGradientOn
(
resultImage
,
value
,
vertical
=
False
):
red
=
Color
(
"red"
)
orange
=
Color
(
"orange"
)
colors
=
list
(
red
.
range_to
(
orange
,
10
))
colors
+=
list
(
orange
.
range_to
(
Color
(
"green"
),
10
))
pixelColorSize
=
5
height
=
resultImage
.
shape
[
0
]
width
=
resultImage
.
shape
[
1
]
cursor_height
=
cursor
.
shape
[
0
]
cursor_width
=
cursor
.
shape
[
1
]
# Display vertivally
if
vertical
:
...
...
@@ -89,29 +89,29 @@ def displayGradientOn(resultImage, value, vertical=False):
h
=
color
.
hex
.
lstrip
(
'#'
)
if
(
len
(
h
)
==
6
):
cv2
.
rectangle
(
resultImage
,
resultImage
,
(
int
(
width
-
avSusRectWidth
),
int
(
width
-
avSusRectWidth
),
int
(
start_position
+
i
*
pixelColorSize
)
),
),
(
int
(
width
),
int
(
width
),
int
(
start_position
+
(
i
+
1
)
*
pixelColorSize
)
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
4
,
2
,
0
)),
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
4
,
2
,
0
)),
-
1
)
else
:
cv2
.
rectangle
(
resultImage
,
resultImage
,
(
int
(
width
-
avSusRectWidth
),
int
(
width
-
avSusRectWidth
),
int
(
start_position
+
i
*
pixelColorSize
)
),
),
(
int
(
width
),
int
(
width
),
int
(
start_position
+
(
i
+
1
)
*
pixelColorSize
)
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
2
,
1
,
0
)),
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
2
,
1
,
0
)),
-
1
)
i
+=
1
...
...
@@ -121,55 +121,55 @@ def displayGradientOn(resultImage, value, vertical=False):
resultImage
[
y_offset
:
y_offset
+
cursor_height
,
x_offset
:
x_offset
+
cursor_width
]
=
cursor
else
:
# Display Horizontally
gradient_height
=
len
(
colors
)
*
pixelColorSize
gradient_length
=
len
(
colors
)
*
pixelColorSize
start_position
=
height
/
2
-
gradient_height
/
2
# Put Colors
i
=
0
for
color
in
colors
:
h
=
color
.
hex
.
lstrip
(
'#'
)
if
(
len
(
h
)
==
6
):
cv2
.
rectangle
(
resultImage
,
resultImage
,
# Vertex
(
int
((
width
-
gradient_length
)
/
2
)
+
i
*
pixelColorSize
,
int
(
0
+
4
*
FONT_SIZE
*
10
)
),
),
# Opposite Vertex
(
int
((
width
-
gradient_length
)
/
2
)
+
(
i
+
1
)
*
pixelColorSize
,
int
(
pixelColorSize
+
5
+
4
*
FONT_SIZE
*
10
)
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
4
,
2
,
0
)),
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
4
,
2
,
0
)),
-
1
)
else
:
cv2
.
rectangle
(
resultImage
,
resultImage
,
# Vertex
(
int
((
width
-
gradient_length
)
/
2
)
+
i
*
pixelColorSize
,
int
(
0
+
4
*
FONT_SIZE
*
10
)
),
),
# Opposite Vertex
(
int
((
width
-
gradient_length
)
/
2
)
+
(
i
+
10
)
*
pixelColorSize
,
int
(
pixelColorSize
+
5
+
4
*
FONT_SIZE
*
10
)
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
2
,
1
,
0
)),
),
tuple
(
int
(
h
[
j
:
j
+
2
],
16
)
for
j
in
(
2
,
1
,
0
)),
-
1
)
i
+=
1
# Put Cursor
x_offset
=
int
((
width
-
gradient_length
)
/
2
+
(
gradient_length
-
10
)
*
(
3
-
value
)
/
2
)
y_offset
=
int
(
4
*
FONT_SIZE
*
10
+
pixelColorSize
+
cursor_height
/
2
-
1
)
try
:
x_offset
=
int
((
width
-
gradient_length
)
/
2
+
gradient_length
*
(
2
-
(
value
-
1
))
/
2
-
cursor_height
/
2
)
y_offset
=
int
(
4
*
FONT_SIZE
*
10
+
pixelColorSize
+
cursor_height
/
2
-
6
)
try
:
resultImage
[
y_offset
:
y_offset
+
cursor_height
,
x_offset
:
x_offset
+
cursor_width
]
=
cursor
except
Exception
as
e
:
print
(
"[+] Error putting cursor -> {}"
.
format
(
e
))
...
...
@@ -178,6 +178,15 @@ def displayGradientOn(resultImage, value, vertical=False):
# Put Text below Gradient
text
=
"Evaluation Risque Moyen
\n
"
put_multi_lines
(
int
((
width
-
gradient_length
)
/
2
),
15
,
text
,
resultImage
,
(
0
,
0
,
0
),
gradient_length
+
1
,
# Center text around gradient
True
# Center to true
)
put_multi_lines
(
int
((
width
-
gradient_length
)
/
2
),
15
,
...
...
@@ -187,8 +196,8 @@ def displayGradientOn(resultImage, value, vertical=False):
gradient_length
,
# Center text around gradient
True
# Center to true
)
def
calculateAverageSuspicious
(
faceSuspicion
):
global
averageSuspicious
currentFaces
=
len
(
faceSuspicion
)
-
faceSuspicion
.
count
(
0
)
...
...
@@ -421,7 +430,7 @@ def detectAndTrackMultipleFaces(start_thread,
(
t_x
+
int
((
t_w
-
len
(
faceNames
[
fid
])
*
10
)
/
2
+
10
),
int
(
t_y
)
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
FONT_SIZE
,
NAME_COLOR
,
(
0
,
0
,
0
)
,
2
,
cv2
.
LINE_AA
)
...
...
@@ -499,16 +508,16 @@ def put_warning_message(fid, faceTrackers, faceSuspicion, resultImage):
text
=
"Citoyen Suspect.
\n
A Surveiller."
color
=
ORANGE
# Print to screen
put_multi_lines
(
t_x
,
t_x
,
int
(
t_y
)
+
20
+
t_h
,
text
,
resultImage
,
text
,
resultImage
,
color
,
t_w
,
# Needed if want to center
True
# Center
True
# Center
)
def
put_multi_lines
(
x
,
y
,
text
,
image
,
color
=
WHITE
,
w
=
0
,
center
=
False
):
...
...
@@ -527,20 +536,20 @@ def put_multi_lines(x, y, text, image, color = WHITE, w= 0, center = False):
# Split lites
lines
=
text
.
split
(
"
\n
"
)
adj
=
0
adj
=
0
# Print lines one below the other, adjusting for x if centering
for
i
in
lines
:
if
center
==
True
:
x_align
=
x
+
int
((
w
-
len
(
i
)
*
10
)
/
2
+
10
)
x_align
=
x
+
int
((
w
-
len
(
i
)
*
10
)
/
2
+
10
)
else
:
x_align
=
x
x_align
=
x
cv2
.
putText
(
image
,
i
,
(
# Name's alignment
# Name's alignment
x_align
,
# Adjust Y for lines
y
+
int
(
adj
*
(
FONT_SIZE
+
15
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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