Commit 961d5d72 authored by cb's avatar cb

First Try for printing gradient horizontally

parent 93e6986a
......@@ -37,7 +37,7 @@ suspiciousColors = {0:(0,0,0), 1:GREEN, 2:ORANGE, 3:RED}
avSusRectWidth = 20
cursorSize = (30, 30)
cursorSize = (15, 15)
cursor = cv2.imread('logo.png') # Read the file
cursor = cv2.resize(cursor, cursorSize)
......@@ -62,42 +62,132 @@ def doRecognizePerson(faceNames, fid):
time.sleep(2)
faceNames[ fid ] = randomnames.rand_name(charset) #"Person " + str(fid)
def displayGradientOn(resultImage, value):
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]
gradient_height = len(colors)*pixelColorSize
start_position = height/2-gradient_height/2
i = 0
for color in colors:
h = color.hex.lstrip('#')
if(len(h) == 6):
cv2.rectangle(resultImage, (int(width-avSusRectWidth), int(start_position + i*pixelColorSize)), (int(width), int(start_position + (i+1)*pixelColorSize)), tuple(int(h[j:j+2], 16) for j in (4, 2, 0)), -1)
else:
cv2.rectangle(resultImage, (int(width-avSusRectWidth), int(start_position + i*pixelColorSize)), (int(width), int(start_position + (i+1)*pixelColorSize)), tuple(int(h[j:j+2], 16) for j in (2, 1, 0)), -1)
i += 1
# Display vertivally
if vertical:
gradient_height = 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,
(
int(width-avSusRectWidth),
int(start_position + i*pixelColorSize)
),
(
int(width),
int(start_position + (i+1)*pixelColorSize)
),
tuple(int(h[j:j+2], 16) for j in (4, 2, 0)),
-1)
else:
cv2.rectangle(
resultImage,
(
int(width-avSusRectWidth),
int(start_position + i*pixelColorSize)
),
(
int(width),
int(start_position + (i+1)*pixelColorSize)
),
tuple(int(h[j:j+2], 16) for j in (2, 1, 0)),
-1)
i += 1
# Put cursor
x_offset = width-avSusRectWidth-30
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
x_offset = width-avSusRectWidth-30
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
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,
# 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)),
-1
)
else:
cv2.rectangle(
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)),
-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:
resultImage[y_offset:y_offset+cursor_height, x_offset: x_offset + cursor_width]=cursor
except Exception as e:
print("[+] Error putting cursor -> {}".format(e))
# Put Text below Gradient
text = "Evaluation Risque Moyen\n"
put_multi_lines(
int((width-gradient_length)/2),
15,
text,
resultImage,
NAME_COLOR,
gradient_length, # Center text around gradient
True # Center to true
)
# Put Text below Gradient
text = "Niveau\nRisque"
put_multi_lines(
int(width-55),
int(10+start_position+gradient_height),
text,
resultImage,
NAME_COLOR
)
def calculateAverageSuspicious(faceSuspicion):
global averageSuspicious
......@@ -320,28 +410,8 @@ def detectAndTrackMultipleFaces(start_thread,
t_w = int(tracked_position.width())
t_h = int(tracked_position.height())
# cv2.rectangle(resultImage,
# (t_x+t_w, t_y),
# (t_x+t_w+30, t_y+80),
# suspiciousColors[faceSuspicion[fid]],
# -1)
# if averageSuspicious>2.5:
# color = RED
# elif averageSuspicious>1.5:
# color = ORANGE
# else:
# color = GREEN
# width = resultImage.shape[1]
# cv2.rectangle(resultImage, (int(width-50), 0), (int(width), 120), color, -1)
displayGradientOn(resultImage, averageSuspicious) # TODO optimization ?
# x_offset = 50#width-avSusRectWidth
# y_offset = 100
# resultImage[y_offset:y_offset+cursor.shape[0], x_offset:x_offset+cursor.shape[1]] = cursor
# If Known -> print Name
if fid in faceNames.keys():
......@@ -426,7 +496,7 @@ def put_warning_message(fid, faceTrackers, faceSuspicion, resultImage):
text = "ATTENTION!\n CITOYEN DANGEREUX!"
color = RED
elif suspicion_level > 1:
text = "Citoyen Suspect. \n A surveiller."
text = "Citoyen Suspect. \n A Surveiller."
color = ORANGE
......
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