Solves cropping problem. Cropping does not need big image any more

This commit is contained in:
2012-06-05 22:33:59 +02:00
parent 92a45fe285
commit 4db69c4cfa
2 changed files with 41 additions and 2 deletions

View File

@@ -59,6 +59,7 @@ class FaceMovie(object):
self.dim_x = 0
self.dim_y = 0
self.normalize = False
# thumbmails
self.crop = False
self.cropdims = [0, 0] # user defined desired dimensions for cropping
@@ -144,6 +145,7 @@ class FaceMovie(object):
:param reference: the reference size of the face that we want to have (0)
:type reference: int
"""
self.normalize = True
# FIXME: May be enhanced by choosing a more educated reference
if reference == 0:
reference = self.guys[0].faces[0][0][3] # catch face size (width)
@@ -255,6 +257,37 @@ class FaceMovie(object):
# finishes by calculating average face size
self.calc_mean_face()
def crop_im_new(self, a_guy):
if a_guy.normalize:
image = a_guy.load_normalized_image()
else :
image = a_guy.load_image()
width = self.width#[0, 0]
height = self.height#[0, 0]
out_im = cv.CreateImage((width[0] + width[1], height[0] + height[1]),cv.IPL_DEPTH_8U, image.nChannels)
cv.Zero(out_im)
((x, y, w, h), n) = a_guy.faces[0]
# all should have the same w and h now ! What is different is the x and y !
w = int(w * a_guy.ratio)
h = int(h * a_guy.ratio)
xtl = a_guy.x_center - width[0]
ytl = a_guy.y_center - height[0]
w = width[0] + width[1]
h = height[0] + height[1]
rect = (xtl, ytl, w, h)
cv.SetImageROI(image, rect)
print "###"
print cv.GetSize(image), cv.GetSize(out_im)
cv.Copy(image, out_im)
cv.ResetImageROI(image)
return out_im
def crop_im(self, image):
"""
If needed, crops the image to avoid having black borders.
@@ -354,7 +387,8 @@ class FaceMovie(object):
self.x_center,
self.y_center)
if self.crop:
out_im = self.crop_im(out_im)
#out_im = self.crop_im(out_im)
out_im = self.crop_im_new(a_guy)
cv.WriteFrame(my_video, out_im)
def number_guys(self):

View File

@@ -50,6 +50,9 @@ class Guy(object):
self.x_center = self.in_x / 2
self.y_center = self.in_y / 2
self.normalize = False
self.ratio = 1.0
def load_image(self):
"""
This function is used to load the image when needed. To reduce memory load, only its location is saved in real time
@@ -186,7 +189,7 @@ class Guy(object):
:param reference: The refence size of the face (in pixels). Defined as the first face size for now
:type reference: int
"""
self.normalize = 1
self.normalize = True
ratio = reference / float(self.faces[0][0][3])
#defines the size of the image to have an equalized face
@@ -198,6 +201,8 @@ class Guy(object):
self.in_y = norm_y
self.x_center = int(ratio * self.x_center)
self.y_center = int(ratio * self.y_center)
self.ratio = ratio
def create_video_output(self, x_size, y_size, x_point, y_point):
"""