Commit 37515125 authored by cb's avatar cb

Added MultiLine text support

parent b1ff9e5b
......@@ -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 DANGEREUSE!"
text = "ATTENTION!\n CITOYEN DANGEREUX!"
color = RED
elif suspicion_level > 1:
text = "Comportement a surveiller"
text = "Citoyen 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):
'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment