Commit 580f1578 authored by klorydryk's avatar klorydryk
Browse files

Ajout self aux fonctions de classe

parent c4b53661
......@@ -69,17 +69,16 @@ def count_cameras():
class facetracker:
camera_number = 0
def __init__(self, camera_nb):
camera_number = camera_nb
self.camera_number = camera_nb
#We are not doing really face recognition
def doRecognizePerson(faceNames, fid):
def doRecognizePerson(self, faceNames, fid):
time.sleep(2)
faceNames[ fid ] = randomnames.rand_name(charset) #"Person " + str(fid)
def displayGradientOn(resultImage, value, vertical=False):
def displayGradientOn(self, resultImage, value, vertical=False):
red = Color("red")
orange = Color("orange")
......@@ -195,7 +194,7 @@ class facetracker:
# Put Text below Gradient
text = "Evaluation Risque\n"
put_multi_lines(
self.put_multi_lines(
int((width-gradient_length)/2),
15,
text,
......@@ -204,7 +203,7 @@ class facetracker:
gradient_length+1, # Center text around gradient
True # Center to true
)
put_multi_lines(
self.put_multi_lines(
int((width-gradient_length)/2),
15,
text,
......@@ -214,14 +213,14 @@ class facetracker:
True # Center to true
)
def calculateAverageSuspicious(faceSuspicion):
def calculateAverageSuspicious(self, faceSuspicion):
global averageSuspicious
currentFaces = len(faceSuspicion) - faceSuspicion.count(0)
if(currentFaces>0):
averageSuspicious = sum(faceSuspicion)/currentFaces
print(f"Average suspicion: {averageSuspicious}")
def detectAndTrackMultipleFaces(camera_number,
def detectAndTrackMultipleFaces(self,
start_thread,
charset,
draw_person_dangerosity,
......@@ -315,7 +314,7 @@ class facetracker:
faceTrackers.pop( fid , None )
faceSuspicion[fid] = 0
calculateAverageSuspicious(faceSuspicion)
self.calculateAverageSuspicious(faceSuspicion)
#Every 10 frames, we will have to determine which faces
#are present in the frame
......@@ -399,16 +398,16 @@ class facetracker:
if start_thread :
#Start a new thread that is used to simulate face recognition.
t = threading.Thread( target = doRecognizePerson ,
t = threading.Thread( target = self.doRecognizePerson ,
args=(faceNames, currentFaceID))
t.start()
else:
# Directly add name + pass a charset to which name must belong
# "Person " + str(fid)
faceNames[ currentFaceID ] = randomnames.rand_name(charset)
self.faceNames[ currentFaceID ] = self.randomnames.rand_name(charset)
calculateAverageSuspicious(faceSuspicion)
self.calculateAverageSuspicious(faceSuspicion)
#Increase the currentFaceID counter
currentFaceID += 1
......@@ -421,7 +420,7 @@ class facetracker:
for fid in faceTrackers.keys():
# Draw a rectangle around people's face
rectangle_around_face(fid,
self.rectangle_around_face(fid,
faceTrackers,
faceSuspicion,
# If False, colors will not change with suspicion level
......@@ -429,20 +428,20 @@ class facetracker:
resultImage)
# Deal with the two others rectangles
tracked_position = faceTrackers[fid].get_position()
tracked_position = self.faceTrackers[fid].get_position()
t_x = int(tracked_position.left())
t_y = int(tracked_position.top())
t_w = int(tracked_position.width())
t_h = int(tracked_position.height())
displayGradientOn(resultImage, averageSuspicious) # TODO optimization ?
self.displayGradientOn(resultImage, averageSuspicious) # TODO optimization ?
# If Known -> print Name
if fid in faceNames.keys():
cv2.putText(resultImage,
faceNames[fid] ,
self.faceNames[fid] ,
# Name's alignment
(t_x+ int((t_w - len(faceNames[fid])*10)/2 + 10), int(t_y) - 10),
cv2.FONT_HERSHEY_SIMPLEX,
......@@ -452,7 +451,7 @@ class facetracker:
cv2.LINE_AA)
cv2.putText(resultImage,
faceNames[fid] ,
self.faceNames[fid] ,
# Name's alignment
(t_x+ int((t_w - len(faceNames[fid])*10)/2 + 10), int(t_y) - 10),
cv2.FONT_HERSHEY_SIMPLEX,
......@@ -463,7 +462,7 @@ class facetracker:
# Add a warning message depending on suspicious level
if add_warning_message:
put_warning_message(fid,
self.put_warning_message(fid,
faceTrackers,
faceSuspicion,
resultImage)
......@@ -503,7 +502,7 @@ class facetracker:
cv2.destroyAllWindows()
exit(0)
def put_warning_message(fid, faceTrackers, faceSuspicion, resultImage):
def put_warning_message(self, fid, faceTrackers, faceSuspicion, resultImage):
'''
Print a Warning message depending on suspicion level
'''
......@@ -514,7 +513,7 @@ class facetracker:
t_w = int(tracked_position.width())
t_h = int(tracked_position.height())
suspicion_level = faceSuspicion[fid]
suspicion_level = self.faceSuspicion[fid]
text = "Citoyen modele"
color = GREEN
......@@ -526,7 +525,7 @@ class facetracker:
color = ORANGE
# Print to screen
put_multi_lines(
self.put_multi_lines(
t_x,
int(t_y) + 20 + t_h,
text,
......@@ -536,7 +535,7 @@ class facetracker:
True # Center
)
def put_multi_lines(x, y, text, image, color = WHITE, w= 0, center = False):
def put_multi_lines(self, x, y, text, image, color = WHITE, w= 0, center = False):
'''
Print a multi line text on the screen
Lines split based upon \n
......@@ -578,12 +577,12 @@ class facetracker:
adj += 1
def rectangle_around_face(fid, faceTrackers, faceSuspicion, draw_person_dangerosity, resultImage):
def rectangle_around_face(self, 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()
tracked_position = self.faceTrackers[fid].get_position()
t_x = int(tracked_position.left())
t_y = int(tracked_position.top())
......@@ -606,7 +605,7 @@ class facetracker:
person_color,
2)
def pick_person_dangerosity_color(suspicionLevel):
def pick_person_dangerosity_color(self, suspicionLevel):
'''
Compute person level suspicion -> simplified to 2 levels
Can reintroduce the faceSuspicious dictionnary lated, was more clean
......
Supports Markdown
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