mirror of
https://github.com/jlengrand/Ivolution.git
synced 2026-03-10 08:21:18 +00:00
Enhances current logger. Now subclasses and modules are also indicated
This commit is contained in:
@@ -85,7 +85,7 @@ class FaceParams(object):
|
||||
"""
|
||||
Log configuration
|
||||
"""
|
||||
my_logger = logging.getLogger('FileLog')
|
||||
my_logger = logging.getLogger('IvolutionFile.Params')
|
||||
params_str = "---------"
|
||||
params_str += "Selected parameters for your Facemovie:"
|
||||
params_str += "Input Folder: %s" % (self.input_folder)
|
||||
|
||||
@@ -40,7 +40,7 @@ class FacemovieThread(threading.Thread, Observable, Observer):
|
||||
self.facemovie.subscribe(self) # Subscribing to facemovie reports
|
||||
self.subscribe(self.facemovie) # Used to send request to stop
|
||||
|
||||
self.my_logger = logging.getLogger('FileLog')
|
||||
self.my_logger = logging.getLogger('IvolutionFile.Thread')
|
||||
self.console_logger = logging.getLogger('ConsoleLog')
|
||||
|
||||
def update(self, message):
|
||||
|
||||
@@ -43,7 +43,7 @@ class FaceMovie(object, Observable, Observer):
|
||||
Observer.__init__(self, "Lib") # used to receive notification to stop
|
||||
|
||||
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
|
||||
self.my_logger = logging.getLogger('IvolutionFile.Lib') # Used to save events into a file
|
||||
|
||||
self.source = face_params.input_folder # Source folder for pictures
|
||||
# Retrieving parameters for Face Detection
|
||||
|
||||
@@ -13,7 +13,7 @@ import cv
|
||||
|
||||
class Guy(object):
|
||||
"""
|
||||
A new Guy is declared for each input image.
|
||||
A new Guy is declared for each input image.
|
||||
A Guy should have a face, and owns the input image.
|
||||
"""
|
||||
def __init__(self, image_id, date, source):
|
||||
@@ -30,13 +30,13 @@ class Guy(object):
|
||||
"""
|
||||
self.in_x = None
|
||||
self.in_y = None
|
||||
|
||||
|
||||
self.name = image_id # Name of the picture used as input
|
||||
self.date = self.find_date(date) # date where image was taken
|
||||
self.source = source
|
||||
|
||||
self.faces = [] # List of faces detected for this input
|
||||
|
||||
|
||||
self.faces = [] # List of faces detected for this input
|
||||
|
||||
# Some operations on variables
|
||||
#image = self.load_image() # used to get size
|
||||
image = self.load_image()
|
||||
@@ -45,7 +45,7 @@ class Guy(object):
|
||||
# FIXME : Time for me to find a better solution
|
||||
self.in_channels = image.nChannels
|
||||
self.depth = image.depth
|
||||
|
||||
|
||||
# Two variables used to define the new center of interest of the image
|
||||
# they are defined as the middle of input image at first
|
||||
self.x_center = 0
|
||||
@@ -75,13 +75,13 @@ class Guy(object):
|
||||
"""
|
||||
This function is used to load the image when needed. To reduce memory load, only its location is saved in real time
|
||||
Returns an iplImage.
|
||||
|
||||
|
||||
:returns IplImage - the input image, not modified; loaded using self.source
|
||||
"""
|
||||
image = cv.LoadImage(self.source)
|
||||
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def find_date(self, date):
|
||||
"""This function takes a date as a string, and returns a date object.
|
||||
Used afterwards to sort images chronologically
|
||||
@@ -92,18 +92,18 @@ class Guy(object):
|
||||
:returns: datetime -- Returns a date object according to time library.
|
||||
:raises: In case of error, set the date to be the current time.
|
||||
"""
|
||||
try:
|
||||
try:
|
||||
my_date = time.strptime(date, "%Y:%m:%d %H:%M:%S")
|
||||
except Exception:
|
||||
my_logger = logging.getLogger('FileLog')
|
||||
my_logger = logging.getLogger('IvolutionFile.Guy')
|
||||
my_logger.error("Impossible to parse date for %s" %(self.name))
|
||||
my_date = time.time()
|
||||
return my_date
|
||||
|
||||
def search_face(self, face_params):
|
||||
"""
|
||||
Search on the picture for a face.
|
||||
Populates faces list.
|
||||
Search on the picture for a face.
|
||||
Populates faces list.
|
||||
This function is the only one containing scaling information
|
||||
|
||||
Set several Guy information, such as the face size, or the virtual center of the image
|
||||
@@ -113,54 +113,54 @@ class Guy(object):
|
||||
|
||||
Once Faces have been found, they are listed and ordered
|
||||
"""
|
||||
|
||||
|
||||
# Load the input image
|
||||
in_image = self.load_image()
|
||||
|
||||
|
||||
# Allocate the temporary images
|
||||
gray = cv.CreateImage((self.in_x, self.in_y),
|
||||
cv.IPL_DEPTH_8U,
|
||||
gray = cv.CreateImage((self.in_x, self.in_y),
|
||||
cv.IPL_DEPTH_8U,
|
||||
1)
|
||||
smallImage = cv.CreateImage((cv.Round(self.in_x / face_params.image_scale),
|
||||
cv.Round (self.in_y / face_params.image_scale)),
|
||||
cv.Round (self.in_y / face_params.image_scale)),
|
||||
cv.IPL_DEPTH_8U ,
|
||||
1)
|
||||
|
||||
1)
|
||||
|
||||
# Converts color input image to grayscale
|
||||
cv.CvtColor(in_image, gray, cv.CV_BGR2GRAY)
|
||||
# Scales input image for faster processing
|
||||
cv.Resize(gray, smallImage, cv.CV_INTER_LINEAR)
|
||||
# Equalizes the histogram
|
||||
cv.EqualizeHist(smallImage, smallImage)
|
||||
|
||||
|
||||
# Detect the faces
|
||||
small_faces = cv.HaarDetectObjects(smallImage,
|
||||
face_params.face_cascade,
|
||||
small_faces = cv.HaarDetectObjects(smallImage,
|
||||
face_params.face_cascade,
|
||||
cv.CreateMemStorage(0),
|
||||
face_params.haar_scale,
|
||||
face_params.min_neighbors,
|
||||
face_params.haar_flags,
|
||||
face_params.haar_scale,
|
||||
face_params.min_neighbors,
|
||||
face_params.haar_flags,
|
||||
face_params.min_size)
|
||||
|
||||
|
||||
# Resizing faces to full_scale
|
||||
for face in small_faces:
|
||||
if len(face): # if faces have been found
|
||||
((x, y, w, h), n) = face
|
||||
big_face = ((int(x * face_params.image_scale),
|
||||
int(y * face_params.image_scale),
|
||||
int(w * face_params.image_scale),
|
||||
big_face = ((int(x * face_params.image_scale),
|
||||
int(y * face_params.image_scale),
|
||||
int(w * face_params.image_scale),
|
||||
int(h * face_params.image_scale)), n)
|
||||
self.faces.append(big_face)
|
||||
|
||||
|
||||
# sorting faces to keep only the most probable one
|
||||
self.sort_faces()
|
||||
self.update_center() # finds center of face in image
|
||||
|
||||
|
||||
def update_center(self):
|
||||
"""
|
||||
Using sorted faces, defines the new center of interest of the output image
|
||||
|
||||
Updates the center of the image, using the most probable face as reference.
|
||||
Updates the center of the image, using the most probable face as reference.
|
||||
If no face was found, the center is not updated.
|
||||
"""
|
||||
if self.has_face():
|
||||
@@ -179,9 +179,9 @@ class Guy(object):
|
||||
"""
|
||||
if self.has_face() : # needed ?
|
||||
self.faces.sort(key= lambda prob : prob[1], reverse=True)
|
||||
else :
|
||||
else :
|
||||
self.faces = []
|
||||
|
||||
|
||||
def set_ratio(self, reference):
|
||||
"""
|
||||
"""
|
||||
@@ -203,19 +203,19 @@ class Guy(object):
|
||||
"""
|
||||
|
||||
out_im = cv.CreateImage((size[0], size[1]),cv.IPL_DEPTH_8U, self.in_channels)
|
||||
cv.Zero(out_im)
|
||||
cv.Zero(out_im)
|
||||
|
||||
# We want to place the input image so that the center of the face matches
|
||||
# x_center and y_center
|
||||
# x_center and y_center
|
||||
(w, h) = self.resized_dims()
|
||||
(x_center, y_center) = self.resized_center()
|
||||
|
||||
xtl = point[0] - x_center # position of top left corner in output image
|
||||
ytl = point[1] - y_center # position of top left corner in output image
|
||||
|
||||
|
||||
rect = (xtl, ytl, w, h) # creating the bounding rectangle on output image
|
||||
cv.SetImageROI(out_im, rect)
|
||||
|
||||
|
||||
# Load input image and resizes it to fit with what we want
|
||||
in_image = self.load_image()
|
||||
norm_im = cv.CreateImage((w, h),cv.IPL_DEPTH_8U, self.in_channels)
|
||||
@@ -223,14 +223,14 @@ class Guy(object):
|
||||
|
||||
# creating the final out image
|
||||
cv.Copy(norm_im, out_im)
|
||||
cv.ResetImageROI(out_im)
|
||||
cv.ResetImageROI(out_im)
|
||||
|
||||
return out_im
|
||||
|
||||
def create_crop_output(self, size, point):
|
||||
"""
|
||||
Creates image output, centering the face center with the required position
|
||||
In this case, the image from which we have to select a ROI is the normalized image.
|
||||
In this case, the image from which we have to select a ROI is the normalized image.
|
||||
The output image shall be smaller than all other images.
|
||||
|
||||
:param size: The size of the ouput image in [x, y] (in pixels)
|
||||
@@ -242,36 +242,36 @@ class Guy(object):
|
||||
|
||||
"""
|
||||
out_im = cv.CreateImage((size[0], size[1]),cv.IPL_DEPTH_8U, self.in_channels)
|
||||
cv.Zero(out_im)
|
||||
|
||||
cv.Zero(out_im)
|
||||
|
||||
(w, h) = self.resized_dims()
|
||||
(x_center, y_center) = self.resized_center()
|
||||
|
||||
xtl = x_center - point[0] # position of top left corner in output image
|
||||
ytl = y_center - point[1] # position of top left corner in output image
|
||||
|
||||
|
||||
rect = (xtl, ytl, size[0], size[1]) # creating the bounding rectangle on output image
|
||||
|
||||
# Load input image and resizes it to fit with what we want
|
||||
in_image = self.load_image()
|
||||
norm_im = cv.CreateImage((w, h),cv.IPL_DEPTH_8U, self.in_channels)
|
||||
cv.Resize(in_image, norm_im)
|
||||
|
||||
|
||||
cv.SetImageROI(norm_im, rect)
|
||||
|
||||
# creating the final out image
|
||||
cv.Copy(norm_im, out_im)
|
||||
cv.ResetImageROI(out_im)
|
||||
cv.ResetImageROI(out_im)
|
||||
|
||||
return out_im
|
||||
|
||||
def num_faces(self):
|
||||
"""
|
||||
Returns the number of faces found for this guy
|
||||
|
||||
|
||||
:returns: int -- The number of faces found for the input image
|
||||
"""
|
||||
return len(self.faces)
|
||||
"""
|
||||
return len(self.faces)
|
||||
|
||||
def has_face(self):
|
||||
"""
|
||||
@@ -280,4 +280,3 @@ class Guy(object):
|
||||
:returns: boolean -- True if at least one face has been found
|
||||
"""
|
||||
return (len(self.faces) > 0)
|
||||
|
||||
@@ -260,7 +260,7 @@ either expressed or implied, of the FreeBSD Project."""
|
||||
log_file = os.path.join(os.path.expanduser(personal_dir), log_root)
|
||||
|
||||
# create logger for 'facemovie'
|
||||
self.my_logger = logging.getLogger('FileLog')
|
||||
self.my_logger = logging.getLogger('IvolutionFile')
|
||||
|
||||
self.my_logger.setLevel(logging.DEBUG)
|
||||
# create file handler which logs even debug messages
|
||||
|
||||
Reference in New Issue
Block a user