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
37515125
Commit
37515125
authored
Jan 28, 2020
by
cb
Browse files
Added MultiLine text support
parent
b1ff9e5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
trackmultiplefaces.py
View file @
37515125
...
...
@@ -31,6 +31,7 @@ BLUE = (255, 0, 0)
PURPLE
=
(
127
,
0
,
255
)
ORANGE
=
(
0
,
165
,
255
)
GREEN
=
(
0
,
255
,
0
)
GREY
=
(
128
,
128
,
128
)
suspiciousColors
=
{
0
:(
0
,
0
,
0
),
1
:
GREEN
,
2
:
ORANGE
,
3
:
RED
}
...
...
@@ -42,9 +43,13 @@ cursor = cv2.resize(cursor, cursorSize)
averageSuspicious
=
0
NAME_COLOR
=
WHITE
NAME_COLOR
=
WHITE
IDENTIFYING_COLOR
=
WHITE
# TEXT
FONT_SIZE
=
0.5
# The default color of the rectangle we draw around the face
rectangleColor
=
(
0
,
165
,
255
)
rectangleColorSuspicious
=
RED
...
...
@@ -89,7 +94,7 @@ def displayGradientOn(resultImage, value):
"Danger"
,
(
int
(
width
-
55
),
int
(
10
+
start_position
+
gradient_height
)),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
FONT_SIZE
,
NAME_COLOR
,
1
,
cv2
.
LINE_AA
)
...
...
@@ -98,7 +103,7 @@ def displayGradientOn(resultImage, value):
"moyen"
,
(
int
(
width
-
55
),
int
(
10
+
12
+
start_position
+
gradient_height
)),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
FONT_SIZE
,
NAME_COLOR
,
1
,
cv2
.
LINE_AA
)
...
...
@@ -348,21 +353,23 @@ def detectAndTrackMultipleFaces(start_thread,
# If Known -> print Name
if
fid
in
faceNames
.
keys
():
cv2
.
putText
(
resultImage
,
faceNames
[
fid
]
,
# Name's alignment
(
t_x
+
int
((
t_w
-
len
(
faceNames
[
fid
])
*
10
)
/
2
+
10
),
int
(
t_y
)
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
0
,
0
)
,
FONT_SIZE
,
NAME_COLOR
,
2
,
cv2
.
LINE_AA
)
cv2
.
putText
(
resultImage
,
faceNames
[
fid
]
,
# Name's alignment
(
t_x
+
int
((
t_w
-
len
(
faceNames
[
fid
])
*
10
)
/
2
+
10
),
int
(
t_y
)
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
FONT_SIZE
,
NAME_COLOR
,
1
,
cv2
.
LINE_AA
)
...
...
@@ -425,22 +432,45 @@ def put_warning_message(fid, faceTrackers, faceSuspicion, resultImage):
text
=
"Citoyen modele"
color
=
GREEN
if
suspicion_level
>
SUSPICIOUS_THRESHOLD
:
text
=
"ATTENTION!
PERSONNE
DANGEREU
SE
!"
text
=
"ATTENTION!
\n
CITOYEN
DANGEREU
X
!"
color
=
RED
elif
suspicion_level
>
1
:
text
=
"C
omportement a
surveiller"
text
=
"C
itoyen Suspect.
\n
A
surveiller
.
"
color
=
ORANGE
cv2
.
putText
(
resultImage
,
text
,
# Name's alignment
(
t_x
+
int
((
t_w
-
len
(
text
)
*
10
)
/
2
+
10
),
int
(
t_y
)
+
20
+
t_h
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
color
,
1
,
cv2
.
LINE_AA
)
# Print to screen
put_multi_lines
(
t_x
,
t_w
,
t_y
,
t_h
,
text
,
resultImage
,
color
)
def
put_multi_lines
(
t_x
,
t_w
,
t_y
,
t_h
,
text
,
image
,
color
=
WHITE
):
'''
Print a multi line text on the screen
Lines split based upon
\n
t_x -> left()
t_y -> top()
t_w -> width()
t_h -> height()
'''
lines
=
text
.
split
(
"
\n
"
)
adj
=
0
for
i
in
lines
:
cv2
.
putText
(
image
,
i
,
# Name's alignment
(
t_x
+
int
((
t_w
-
len
(
i
)
*
10
)
/
2
+
10
),
# x
int
(
t_y
)
+
20
+
t_h
+
int
(
adj
*
(
FONT_SIZE
+
15
))
# y -> Adjusted for lines
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
FONT_SIZE
,
color
,
1
,
cv2
.
LINE_AA
)
adj
+=
1
def
rectangle_around_face
(
fid
,
faceTrackers
,
faceSuspicion
,
draw_person_dangerosity
,
resultImage
):
'''
...
...
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