mirror of
https://github.com/jlengrand/Ivolution.git
synced 2026-03-10 08:21:18 +00:00
Adds feature to resize all images to have the same head size.
Some problems with video creation. Cannot be read on vlc and wmp. TODO : Create executables Allow saving sessions (will save lots of my time) Ant script, test class (will also save some time!)
This commit is contained in:
43
Guy.py
43
Guy.py
@@ -116,30 +116,18 @@ class Guy(object):
|
||||
"""
|
||||
Creates intermediate image, whose face fits reference size
|
||||
"""
|
||||
#TODO: implement
|
||||
self.normalize = 1
|
||||
|
||||
ratio = reference / float(self.faces[0][0][3])
|
||||
new_x = int(ratio * self.in_x)
|
||||
new_y = int(ratio * self.in_y)
|
||||
|
||||
print "reference : %d" %(reference)
|
||||
print ratio
|
||||
print "bef_f_size : %d" %(self.faces[0][0][3])
|
||||
print "aft_f_size : %d" %(self.faces[0][0][3] * ratio)
|
||||
print "bef_size : %d, %d " %(self.in_x, self.in_y)
|
||||
print "af_size : %d, %d" %(new_x, new_y)
|
||||
print "###"
|
||||
|
||||
self.norm_im = cv.CreateImage((new_x, new_y),cv.IPL_DEPTH_8U, self.in_channels)
|
||||
cv.Resize(self.in_image, self.norm_im)
|
||||
|
||||
#defines the size of the image to have an equalized face
|
||||
self.norm_x = int(ratio * self.in_x)
|
||||
self.norm_y = int(ratio * self.in_y)
|
||||
self.x_norm_center = int(ratio * self.x_center)
|
||||
self.y_norm_center = int(ratio * self.y_center)
|
||||
|
||||
self.norm_im = cv.CreateImage((self.norm_x, self.norm_y),cv.IPL_DEPTH_8U, self.in_channels)
|
||||
cv.Resize(self.in_image, self.norm_im)
|
||||
|
||||
self.norm_x = new_x
|
||||
self.norm_y = new_y
|
||||
|
||||
def create_video_output(self, x_size, y_size, x_point, y_point):
|
||||
"""
|
||||
Creates image output, centering the face center with the required position
|
||||
@@ -153,22 +141,25 @@ class Guy(object):
|
||||
# x_center and y_center
|
||||
if self.normalize :
|
||||
xtl = x_point - self.x_norm_center
|
||||
ytl = y_point - self.y_norm_center
|
||||
ytl = y_point - self.y_norm_center
|
||||
w = self.norm_x
|
||||
h = self.norm_y
|
||||
else:
|
||||
xtl = x_point - self.x_center
|
||||
ytl = y_point - self.y_center
|
||||
|
||||
rect = (xtl, ytl, self.in_x, self.in_y)
|
||||
|
||||
w = self.in_x
|
||||
h = self.in_y
|
||||
|
||||
rect = (xtl, ytl, w, h)
|
||||
cv.SetImageROI(self.out_im, rect)
|
||||
|
||||
if self.normalize :
|
||||
if self.normalize :
|
||||
cv.Copy(self.norm_im, self.out_im)
|
||||
else:
|
||||
cv.Copy(self.in_image, self.out_im)
|
||||
|
||||
cv.ResetImageROI(self.out_im)
|
||||
|
||||
|
||||
def create_debug_output(self):
|
||||
"""
|
||||
Creates output image
|
||||
@@ -199,10 +190,6 @@ class Guy(object):
|
||||
pt3,
|
||||
cv.RGB(0, 255, 0),
|
||||
3, 8, 0)
|
||||
|
||||
# updates out size
|
||||
cv.GetSize
|
||||
|
||||
|
||||
def in_display(self, time=1000, im_x=640, im_y=480):
|
||||
"""
|
||||
|
||||
52
facemovie.py
52
facemovie.py
@@ -95,7 +95,6 @@ class FaceMovie(object):
|
||||
for a_guy in self.guys:
|
||||
if a_guy.has_face():
|
||||
if a_guy.normalize:
|
||||
print "======================"
|
||||
xc = a_guy.x_norm_center
|
||||
yc = a_guy.y_norm_center
|
||||
inx = a_guy.norm_x
|
||||
@@ -119,35 +118,20 @@ class FaceMovie(object):
|
||||
|
||||
self.dim_x = self.x_af + self.x_center
|
||||
self.dim_y = self.y_af + self.y_center
|
||||
|
||||
|
||||
def show_faces(self, time=1000, equalize=True):
|
||||
"""
|
||||
Show all faces that have been found for the guys.
|
||||
The time for which each image will be displayed can be chosen.
|
||||
Several modes can be chosen to adapt the result.
|
||||
"""
|
||||
prev_size = 0
|
||||
for a_guy in self.guys:
|
||||
if a_guy.has_face():
|
||||
a_guy.create_video_output(self.dim_x,
|
||||
self.dim_y,
|
||||
self.x_center,
|
||||
self.y_center,
|
||||
prev_size)
|
||||
if equalize:
|
||||
prev_size = a_guy.faces[0][0][3]
|
||||
a_guy.out_display(time)
|
||||
|
||||
def show_debug(self, time=1000):
|
||||
"""
|
||||
Show all faces that have been found for the guys, with a debug output.
|
||||
The time for which each image will be displayed can be chosen.
|
||||
Several modes can be chosen to adapt the result.
|
||||
"""
|
||||
for a_guy in self.guys:
|
||||
if a_guy.has_face():
|
||||
a_guy.create_debug_output()
|
||||
a_guy.out_display(time)
|
||||
self.y_center)
|
||||
a_guy.out_display(time)
|
||||
|
||||
def save_faces(self, out_folder, im_format="png"):
|
||||
"""
|
||||
@@ -156,7 +140,6 @@ class FaceMovie(object):
|
||||
"""
|
||||
for a_guy in self.guys:
|
||||
if a_guy.has_face():
|
||||
print self.dim_x, self.dim_y,self.x_center, self.y_center
|
||||
a_guy.create_video_output(self.dim_x,
|
||||
self.dim_y,
|
||||
self.x_center,
|
||||
@@ -181,16 +164,12 @@ class FaceMovie(object):
|
||||
fps,
|
||||
frameSize,
|
||||
1)
|
||||
prev_size = 0
|
||||
for a_guy in self.guys:
|
||||
if a_guy.has_face():
|
||||
a_guy.create_video_output(self.dim_x,
|
||||
self.dim_y,
|
||||
self.x_center,
|
||||
self.y_center,
|
||||
prev_size)
|
||||
if equalize:
|
||||
prev_size = a_guy.faces[0][0][3]
|
||||
self.y_center)
|
||||
cv.WriteFrame(my_video, a_guy.out_im)
|
||||
|
||||
def number_guys(self):
|
||||
@@ -201,27 +180,22 @@ class FaceMovie(object):
|
||||
|
||||
if __name__ == "__main__":
|
||||
# quick and dirty tests
|
||||
root_fo = "C:\Users\jll\perso\FaceMovie"
|
||||
root_fo = "C:\Users\jll\perso\workspace\FaceMovie"
|
||||
#in_fo = os.path.join(root_fo, "input\Axel_tsts")
|
||||
in_fo = os.path.join(root_fo, "input\plouf")
|
||||
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()
|
||||
my_movie.search_faces()
|
||||
my_movie.list_guys() # find images in input folder
|
||||
my_movie.search_faces() # search for images with faces
|
||||
# I want to change images so that all faces have the same size
|
||||
my_movie.normalize_faces() # sets all faces to the same size
|
||||
# I want to know the size of the output frame, knowing initial conditions
|
||||
my_movie.find_out_dims()
|
||||
my_movie.find_out_dims() # finds output minimal size to get all eyes in the same place
|
||||
|
||||
#for a_guy in my_movie.guys:
|
||||
# if a_guy.has_face:
|
||||
# try:
|
||||
# print a_guy.faces[0]
|
||||
# except IndexError:
|
||||
# print "Error"
|
||||
#my_movie.show_faces(1000)
|
||||
my_movie.save_faces("output")
|
||||
#my_movie.save_faces("output")
|
||||
#my_movie.save_movie("output")
|
||||
|
||||
print "Facemovie finished !"
|
||||
|
||||
print "Facemovie finished !"
|
||||
@@ -9,9 +9,9 @@ from facemovie import *
|
||||
from Guy import *
|
||||
|
||||
# quick and dirty tests
|
||||
root_fo = "C:\Users\jll\perso\FaceMovie"
|
||||
root_fo = "C:\Users\jll\perso\workspace\FaceMovie"
|
||||
#in_fo = os.path.join(root_fo, "input\Axel_tsts")
|
||||
in_fo = os.path.join(root_fo, "input\plouf")
|
||||
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")
|
||||
|
||||
@@ -22,41 +22,11 @@ my_movie.search_faces()
|
||||
# I want to change images so that all faces have the same size
|
||||
my_movie.normalize_faces()
|
||||
|
||||
print "ypolpa"
|
||||
# I want to know the size of the output frame, knowing initial conditions
|
||||
my_movie.find_out_dims()
|
||||
|
||||
# Here I want to modify in_im first
|
||||
for a_guy in my_movie.guys:
|
||||
if a_guy.has_face():
|
||||
# some nice drawings
|
||||
((x, y, w, h), n) = a_guy.faces[0]
|
||||
# the input to cv.HaarDetectObjects was resized, so scale the
|
||||
# bounding box of each face and convert it to two CvPoints
|
||||
pt1 = (x, y)
|
||||
pt2 = ((x + w), (y + h))
|
||||
cv.Rectangle(a_guy.norm_im,
|
||||
pt1,
|
||||
pt2,
|
||||
cv.RGB(255, 0, 0),
|
||||
3, 8, 0)# surrounds face
|
||||
|
||||
# Adds point in the center
|
||||
pt3 = (a_guy.x_center, a_guy.y_center)
|
||||
cv.Line(a_guy.norm_im,
|
||||
pt3,
|
||||
pt3,
|
||||
cv.RGB(0, 255, 0),
|
||||
3, 8, 0)
|
||||
|
||||
#for a_guy in my_movie.guys:
|
||||
# if a_guy.has_face:
|
||||
# try:
|
||||
# print a_guy.faces[0]
|
||||
# except IndexError:
|
||||
# print "Error"
|
||||
#my_movie.show_faces(1000)
|
||||
my_movie.save_faces("output")
|
||||
#my_movie.save_movie("output")
|
||||
#my_movie.save_faces("output")
|
||||
my_movie.save_movie("output")
|
||||
|
||||
print "Facemovie finished !"
|
||||
Reference in New Issue
Block a user