From b40b38d996c00505e54c6c4c38c67cf6e403909c Mon Sep 17 00:00:00 2001 From: AirballTest Date: Fri, 11 May 2012 18:08:24 +0200 Subject: [PATCH] Adds user interaction for cropping. TODO : Add corresponding option in command line. Change pixels to number of face size --- facemovie/Facemovie.py | 54 ++++++++++++++++++++++++-------------- facemovie/Facemoviefier.py | 3 +++ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/facemovie/Facemovie.py b/facemovie/Facemovie.py index c510004..b935931 100644 --- a/facemovie/Facemovie.py +++ b/facemovie/Facemovie.py @@ -43,9 +43,16 @@ class FaceMovie(object): # thumbmails self.crop = False + self.cropdims = [0, 0] # user defined desired dimensions for cropping self.width = [0, 0] self.height = [0, 0] + def set_crop_dims(self, crop_x, crop_y): + """ + Sets the cropping dimension in case they have been provided by the end user + """ + self.cropdims = [crop_x, crop_y] + def list_guys(self): """ Aims at populating the guys list, using the source folder as an input. @@ -103,26 +110,33 @@ class FaceMovie(object): wl = 1000000 # space left left of eyes wr = 1000000 # space left right of eyes - for a_guy in self.guys: - if a_guy.has_face(): - xc = a_guy.x_center - yc = a_guy.y_center - inx = a_guy.in_x - iny = a_guy.in_y - - # finding width - if xc < wl: - wl = xc - if (inx - xc) < wr: - wr = inx - xc - # finding height - if yc < ht: - ht = yc - if (iny - yc) < hb: - hb = iny - yc - - self.width = [wl, wr] - self.height = [ht, hb] + if self.cropdims != [0, 0]: + w = int(self.cropdims[0] / 2) + self.width = [w, w] + h = int(self.cropdims[1] / 2) + self.height = [h, h] + else: + for a_guy in self.guys: + if a_guy.has_face(): + xc = a_guy.x_center + yc = a_guy.y_center + inx = a_guy.in_x + iny = a_guy.in_y + + # finding width + if xc < wl: + wl = xc + if (inx - xc) < wr: + wr = inx - xc + # finding height + if yc < ht: + ht = yc + if (iny - yc) < hb: + hb = iny - yc + + self.width = [wl, wr] + self.height = [ht, hb] + self.crop = True def find_out_dims(self): diff --git a/facemovie/Facemoviefier.py b/facemovie/Facemoviefier.py index 5b91b83..df618de 100644 --- a/facemovie/Facemoviefier.py +++ b/facemovie/Facemoviefier.py @@ -89,6 +89,9 @@ class Facemoviefier(): # I want to know the size of the output frame, knowing initial conditions self.facemovie.find_out_dims() # finds output minimal size to get all eyes in the same place if self.args['crop']: + # TODO: additional parameters (2) may be added here. Add support for this + self.facemovie.set_crop_dims(100, 100) # TODO : do we need something else than pixel here ? It stinks due to face normalization. + # TODO : Change to number of face size self.facemovie.find_crop_dims() # finds output minimal size to get all eyes in the same place #choose your final step