Commit 40dd8762 authored by cb's avatar cb

Finalizing put_multi_lines function

parent 37515125
......@@ -89,24 +89,32 @@ def displayGradientOn(resultImage, value):
y_offset = int((start_position - cursor_height/2) + gradient_height * (2-(value-1))/2)
resultImage[y_offset:y_offset+cursor_height, x_offset:x_offset+cursor_width] = cursor
cv2.putText(resultImage,
"Danger",
(int(width-55),int(10+start_position+gradient_height)),
cv2.FONT_HERSHEY_SIMPLEX,
FONT_SIZE,
NAME_COLOR,
1,
cv2.LINE_AA)
cv2.putText(resultImage,
"moyen",
(int(width-55),int(10+12+start_position+gradient_height)),
cv2.FONT_HERSHEY_SIMPLEX,
FONT_SIZE,
NAME_COLOR,
1,
cv2.LINE_AA)
text = "DANGEROSITE\nMOYENNE"
put_multi_lines(
int(width-55),
int(10+start_position+gradient_height),
text,
resultImage,
NAME_COLOR
)
#cv2.putText(resultImage,
# "Danger",
# (int(width-55),int(10+start_position+gradient_height)),
# cv2.FONT_HERSHEY_SIMPLEX,
# FONT_SIZE,
# NAME_COLOR,
# 1,
# cv2.LINE_AA)
#
#cv2.putText(resultImage,
# "moyen",
# (int(width-55),int(10+12+start_position+gradient_height)),
# cv2.FONT_HERSHEY_SIMPLEX,
# FONT_SIZE,
# NAME_COLOR,
# 1,
# cv2.LINE_AA)
def calculateAverageSuspicious(faceSuspicion):
global averageSuspicious
......@@ -440,29 +448,49 @@ def put_warning_message(fid, faceTrackers, faceSuspicion, resultImage):
# Print to screen
put_multi_lines(t_x, t_w, t_y, t_h, text, resultImage, color)
put_multi_lines(
t_x,
int(t_y) + 20 + t_h,
text,
resultImage,
color,
t_w, # Needed if want to center
True # Center
)
def put_multi_lines(t_x, t_w, t_y, t_h, text, image, color = WHITE):
def put_multi_lines(x, y, text, image, color = WHITE, w= 0, center = False):
'''
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()
w -> width of text, only used if center == TRUE
'''
# If center, adjust text to picture
if center == True:
if w == 0:
print("If you want to center multi line text, give me the width of the image")
exit()
# Split lites
lines = text.split("\n")
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)
else:
x_align = x
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
# Name's alignment
x_align,
# Adjust Y for lines
y + int(adj*(FONT_SIZE +15))
),
cv2.FONT_HERSHEY_SIMPLEX,
FONT_SIZE,
......
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