Commit f3699846 authored by cb's avatar cb

Modified detectAndTrackMultipleFaces so that the color of the rectangle around...

Modified detectAndTrackMultipleFaces so that the color of the rectangle around people's face depends upon their suspicionlevel
parent beb36f0e
......@@ -45,7 +45,7 @@ def calculateAverageSuspicious(faceSuspicion):
averageSuspicious = sum(faceSuspicion)/currentFaces
print(f"Average suspicion: {averageSuspicious}")
def detectAndTrackMultipleFaces(start_thread, charset):
def detectAndTrackMultipleFaces(start_thread, charset, draw_person_dangerosity):
#Open the first webcame device
capture = cv2.VideoCapture(0)
......@@ -250,6 +250,15 @@ def detectAndTrackMultipleFaces(start_thread, charset):
#of the person, otherwise the message indicating we are detecting
#the name of the person
for fid in faceTrackers.keys():
# Draw a rectangle around people's face
# Deal with the two others rectangles
tracked_position = faceTrackers[fid].get_position()
t_x = int(tracked_position.left())
......@@ -257,11 +266,6 @@ def detectAndTrackMultipleFaces(start_thread, charset):
t_w = int(tracked_position.width())
t_h = int(tracked_position.height())
cv2.rectangle(resultImage, (t_x, t_y),
(t_x + t_w , t_y + t_h),
rectangleColor ,2)
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:
......@@ -315,11 +319,50 @@ def detectAndTrackMultipleFaces(start_thread, charset):
def rectangle_around_face(fid, faceTrackers, faceSuspicion, draw_person_dangerosity, resultImage):
Draw a rectangle around's people face
If draw_person_dangerosity = True -> Add a color based on suspicionLevel
tracked_position = faceTrackers[fid].get_position()
t_x = int(tracked_position.left())
t_y = int(
t_w = int(tracked_position.width())
t_h = int(tracked_position.height())
# If we want to have a dangerosity color per personn
if draw_person_dangerosity :
suspicionLevel = faceSuspicion[fid]
person_color = draw_person_dangerosity_color(suspicionLevel)
# Else default to rectangleColor
person_color = rectangleColor
cv2.rectangle(resultImage, (t_x, t_y),
(t_x + t_w , t_y + t_h),
def draw_person_dangerosity_color(suspicionLevel):
Compute person level suspicion -> simplified to 2 levels
Can reintroduce the faceSuspicious dictionnary lated, was more clean
if suspicionLevel>2:
color = RED
color = GREEN
return color
if __name__ == '__main__':
# False: Names are directly printed on screen, no new thread
# Select only names with letters and whitespace. Any other value will select printable.
charset = "letters"
charset = "letters",
# If True, then rectangle color around people' face will turn red if dangerous
# + a message will pop
draw_person_dangerosity = True
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