From 8a1366c3e9c94d87dcbde615be5f25fe67787ed8 Mon Sep 17 00:00:00 2001 From: julien Lengrand-Lambert Date: Fri, 30 Mar 2012 10:09:04 +0200 Subject: [PATCH] Starts implementing architecture. Adds .gitignore --- .gitignore | 1 + Eye.py | 19 +++++++++++++++ Face.py | 19 +++++++++++++++ Guy.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ facemovie.py | 60 +++++++++++++++++++++++++++++++++++++++++++--- main_file.py | 7 +++++- 6 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 Eye.py create mode 100644 Face.py create mode 100644 Guy.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/Eye.py b/Eye.py new file mode 100644 index 0000000..f1299c2 --- /dev/null +++ b/Eye.py @@ -0,0 +1,19 @@ +''' +Created on 29 mars 2012 + +@author: jll +''' + +class Eye(object): + ''' + Created is an Eye-like blob is found using the Face Detection algorithm. + ''' + def __init__(self): + ''' + Constructor + ''' + x_pos = None # x position of the eye in the image + y_pos = None # y position of the eye in the image + x_size = None # x size of the blob in pixel + y_size = None # y size of the blob in pixel + conf = None # confidence indice, indicating the probability of the target to actually be an eye \ No newline at end of file diff --git a/Face.py b/Face.py new file mode 100644 index 0000000..e29672a --- /dev/null +++ b/Face.py @@ -0,0 +1,19 @@ +''' +Created on 29 mars 2012 + +@author: jll +''' + +class Face(object): + ''' + Created is an Face-like blob is found using the Face Detection algorithm. + ''' + def __init__(self): + ''' + Constructor + ''' + x_center = None # x position of the face in the image + y_center = None # y position of the face in the image + x_size = None # x size of the blob in pixel + y_size = None # y size of the blob in pixel + conf = None # confidence indice, indicating the probability of the target to actually be an eye \ No newline at end of file diff --git a/Guy.py b/Guy.py new file mode 100644 index 0000000..f325cb3 --- /dev/null +++ b/Guy.py @@ -0,0 +1,67 @@ +''' +Created on 29 mars 2012 + +@author: jll +''' +import cv + +import os # needed only for main. Shall be removed + +class Guy(object): + ''' + Represents the user on the people at a fixed time. + All datas found for this time may be found here. + ''' + def __init__(self, image, image_id): + ''' + Constructor + ''' + self.in_image = image # input image + self.in_x = None + self.in_y = None + self.in_channels = self.in_image.nChannels + self.name = image_id # Name of the picture used as input + self.out_im = None + + self.faces = [] # List of faces detected for this input + # TODO: should eyes be tied to a precise face ? + self.eyes = [] # List of eyes detected for this input + + # Some operations on variables + + (self.in_x, self.in_y) = cv.GetSize(self.in_image) # image size in x, y + + # Creation of the output image + self.out_im = cv.CreateImage((self.in_x, self.in_y),cv.IPL_DEPTH_8U, self.in_channels) + cv.Zero(self.out_im) # put everything to 0 + + + def in_display(self, time): + """ + Displays the input image, for time ms. + Setting time to 0 causes the image to remains open. + """ + cv.NamedWindow(self.name) + cv.ShowImage(self.name, self.in_image) + cv.WaitKey(time) + + def out_display(self, time): + """ + Displays the output image, for time ms. + Setting time to 0 causes the image to remains open. + Window name slightly changed to match output + """ + win_name = self.name + " - out" + cv.NamedWindow(win_name) + cv.ShowImage(win_name, self.in_image) + cv.WaitKey(time) + +if __name__ == "__main__": + # quick and dirty tests + name = "input/search.jpg" + im = cv.LoadImage(name) + + my_guy = Guy(im, os.path.basename(name)) + my_guy.in_display(100) + my_guy.out_display(1000) + \ No newline at end of file diff --git a/facemovie.py b/facemovie.py index 3e46091..1983425 100644 --- a/facemovie.py +++ b/facemovie.py @@ -3,15 +3,69 @@ Created on 27 mars 2012 @author: jll ''' +import cv +import os +import Guy class FaceMovie(object): ''' - Main class of the project + Main class of the whole application. + Contains the core image processing functions. + Supports the communication layer with the end user interface. ''' - def __init__(self): + def __init__(self, in_folder, out_folder, param_folder): ''' Constructor ''' - pass \ No newline at end of file + self.source= in_folder # Source folder for pictures + self.out = out_folder # Folder to save outputs + self.params_source = param_folder # Folder in which xml files can be found + + self.guys = [] # List of pictures in source folder + + # Setting up some default parameters for Face Detection + self.face_cascade = cv.Load(os.path.join(param_folder, "haarcascade_frontalface_alt.xml")) + self.eye_cascade = cv.Load(os.path.join(param_folder, "haarcascade_eye.xml")) + + # To be defined more precisely + self.min_size = (20,20) + self.image_scale = 2 + self.haar_scale = 1.2 + self.min_neighbors = 2 + self.haar_flags = 0 + + def list_guys(self): + """ + Aims at populating the guys list, using the source folder as an input. + Guys list shall be sorted by file name alphabetical order + """ + try: + os.path.exists(self.source) + os.path.isdir(self.source) # checking if folder exists + except : # find precise exception + print "ERROR : Source folder not found ! Exiting. . ." + sys.exit(0) + + # just listing directory. Lets be more secure later + files = os.listdir(self.source) + + # loading images, create Guys and store it into guys + for token in files : + image = cv.LoadImage(os.path.join(self.source, token)) + a_guy = Guy.Guy(image, token) + + # populating guys + self.guys.append(a_guy) + +if __name__ == "__main__": + # quick and dirty tests + root_fo = "C:\Users\jll\perso\FaceMovie" + in_fo = os.path.join(root_fo, "input\Axel") + out_fo = os.path.join(root_fo, "output") + par_fo = os.path.join(root_fo, "haarcascades") + + my_movie = FaceMovie(in_fo, out_fo, par_fo) + my_movie.list_guys() + print "Done !" \ No newline at end of file diff --git a/main_file.py b/main_file.py index ced8d7e..8bfd519 100644 --- a/main_file.py +++ b/main_file.py @@ -3,7 +3,12 @@ Created on 29 mars 2012 @author: jll ''' +import cv +import os if __name__ == '__main__': # Main test file to test current application - print "test" \ No newline at end of file + print "test" + a = "C:\PerfLogs" + b = "plouf" + print os.path.join(a, b) \ No newline at end of file