From bfc960e103262898b3afc874bd9cad3953d1e113 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Thu, 16 Aug 2012 09:09:44 +0200 Subject: [PATCH] FaceMovieThread successfully gets messages from face listing in lib. TODO: Change length of system messages to simplyfy updating Think way to choose where to update messages --- ivolution/FacemovieThread.py | 2 ++ ivolution/Facemovie_lib.py | 27 ++++++++++++++++++++++++++- ivolution/gui/IvolutionWindow.py | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ivolution/FacemovieThread.py b/ivolution/FacemovieThread.py index 98d6e3d..83098c3 100644 --- a/ivolution/FacemovieThread.py +++ b/ivolution/FacemovieThread.py @@ -38,6 +38,7 @@ class FacemovieThread(threading.Thread, Observable, Observer): self.face_params = face_params self.facemovie = Facemovie_lib.FaceMovie(self.face_params) + self.facemovie.subscribe(self) # Subscribing to facemovie reports self.my_logger = logging.getLogger('FileLog') self.console_logger = logging.getLogger('ConsoleLog') @@ -60,6 +61,7 @@ class FacemovieThread(threading.Thread, Observable, Observer): else: self.console_logger.debug(message[0]) self.my_logger.debug(message[0]) + def run(self): # FIXME : Quite ugly way of doing. Find better! diff --git a/ivolution/Facemovie_lib.py b/ivolution/Facemovie_lib.py index a5a9b8c..b1ed3d3 100644 --- a/ivolution/Facemovie_lib.py +++ b/ivolution/Facemovie_lib.py @@ -17,7 +17,9 @@ import cv from util import exif import Guy -class FaceMovie(object): +from util.Notifier import Observable + +class FaceMovie(object, Observable): ''' Main class of the whole application. Contains the core image processing functions. @@ -36,6 +38,7 @@ class FaceMovie(object): :param face_param: the location of the profile file used to train the classifier :type face_param: string """ + Observable.__init__(self) # used to send notifications to process self.console_logger = logging.getLogger('ConsoleLog') # Used to send messages to the console self.my_logger = logging.getLogger('FileLog') # Used to save events into a file @@ -150,9 +153,20 @@ class FaceMovie(object): The Face of each guy is searched. In case no face is found, a warning is returned and Guy is set to None """ + ptr = 0 for a_guy in self.guys: + ptr += 1 if self.run: a_guy.search_face(self.face_params) + + # notifying the Observers + print ptr, len(self.guys) + try: + self.notify(["Face", self.percent(ptr, len(self.guys))]) + except (ArithmeticError, ZeroDivisionError): + #pass + self.notify(["Error", 0]) + if a_guy.has_face(): # face(s) have been found self.console_logger.info("Face found for %s" % (a_guy.name)) self.my_logger.info("Face found for %s" % (a_guy.name)) @@ -160,6 +174,17 @@ class FaceMovie(object): self.console_logger.warning("No face found for %s. Skipped . . ." %(a_guy.name)) self.my_logger.warning("No face found for %s. Skipped . . ." %(a_guy.name)) + def percent(self, num, den): + """ + Returns a float between 0 and 1, being the percentage given by num / den + """ + if num > den : + raise ArithmeticError + if den <= 0 : + raise ZeroDivisionError + + return (num / float(den)) + def clean_guys(self): """ Removes all guys for who no face has been found. diff --git a/ivolution/gui/IvolutionWindow.py b/ivolution/gui/IvolutionWindow.py index d69c23b..1bd1e2f 100755 --- a/ivolution/gui/IvolutionWindow.py +++ b/ivolution/gui/IvolutionWindow.py @@ -116,7 +116,7 @@ class IvolutionWindow(Observer, Observable): # Instantiating the facemovie self.facemovie = FacemovieThread.FacemovieThread(self.face_params) self.facemovie.subscribe(self) # I want new information ! Subscribes to facemovie reports - self.subscribe(self.facemovie) # Trying to subscribe facemovie to our messages + self.subscribe(self.facemovie) # Subscribing facemovie to our messages self.facemovie.start()