test for nice switch between frames ok

This commit is contained in:
2012-06-14 19:00:56 +02:00
parent d26e4ce9ca
commit 957f96d393
2 changed files with 140 additions and 2 deletions

View File

@@ -66,6 +66,8 @@ class FaceMovie(object):
self.face_mean = [0, 0] self.face_mean = [0, 0]
self.sort_method = "n" # sorting by name or using metadata (n or e) self.sort_method = "n" # sorting by name or using metadata (n or e)
self.weight_steps = 5 # number of images to be inserted between each frame to reduce violent switch
def set_crop_dims(self, crop_x, crop_y): def set_crop_dims(self, crop_x, crop_y):
""" """
@@ -373,7 +375,7 @@ class FaceMovie(object):
if self.crop: if self.crop:
out_im = self.crop_im(out_im) out_im = self.crop_im(out_im)
self.save_result(out_im, a_guy.name, out_folder, im_format) self.save_result(out_im, a_guy.name, out_folder, im_format)
def save_movie(self, out_folder, fps=3): def save_movie(self, out_folder, fps=3):
""" """
Creates a movie with all faces found in the inputs. Creates a movie with all faces found in the inputs.
@@ -388,7 +390,6 @@ class FaceMovie(object):
MAX_OUT_DIM_X = 1900 MAX_OUT_DIM_X = 1900
filename = os.path.join(out_folder, "output.avi") filename = os.path.join(out_folder, "output.avi")
# Codec is OS dependant.
# FIXME : Find an unified version # FIXME : Find an unified version
if "win" in sys.platform: if "win" in sys.platform:
fourcc = cv.CV_FOURCC('C', 'V', 'I', 'D') fourcc = cv.CV_FOURCC('C', 'V', 'I', 'D')
@@ -412,6 +413,74 @@ class FaceMovie(object):
frameSize = (out_x, out_y) frameSize = (out_x, out_y)
### ###
print "Speed is set to %d fps" %(fps)
my_video = cv.CreateVideoWriter(filename,
fourcc,
fps,
frameSize,
1)
ii = 0
for a_guy in self.guys:
ii += 1
if a_guy.has_face():
print "Saving frame %d / %d" %(ii, self.number_guys())
out_im = a_guy.create_video_output(self.dim_x,
self.dim_y,
self.x_center,
self.y_center)
if self.crop:
#out_im = self.crop_im(out_im)
out_im = self.crop_im_new(a_guy)
###
# Quick fix while thinking
# Some dimensions seem to cause output problems in the end.
# We resize to a well known size
imm = cv.CreateImage(frameSize, out_im.depth, out_im.nChannels)
cv.Resize(out_im, imm)
cv.WriteFrame(my_video, imm)
###
#cv.WriteFrame(my_video, out_im)
def save_movie_old(self, out_folder, fps=3):
"""
Creates a movie with all faces found in the inputs.
Guy is skipped if no face is found.
:param out_folder: the location where to save the output image.
:type out_folder: string
:param fps: the number of frames per second to be displayed in final video (3)
:type fps: int
"""
MAX_OUT_DIM_X = 1900
filename = os.path.join(out_folder, "output.avi")
# FIXME : Find an unified version
if "win" in sys.platform:
fourcc = cv.CV_FOURCC('C', 'V', 'I', 'D')
else: # some kind of Linux/Unix platform
fourcc = cv.CV_FOURCC('F', 'M', 'P', '4')
if self.crop:
width = self.width
height = self.height
frameSize = (width[0] + width[1], height[0] + height[1])
else:
frameSize = (self.dim_x, self.dim_y)
###
# FIXME : Find a proper solution for that
# Quick fix while thinking
# Some dimensions seem to cause output problems in the end.
# We resize to a well known size
out_x = 1900
out_y = int((out_x * frameSize[1]) / float(frameSize[0]))
frameSize = (out_x, out_y)
###
print "Speed is set to %d fps" %(fps) print "Speed is set to %d fps" %(fps)
my_video = cv.CreateVideoWriter(filename, my_video = cv.CreateVideoWriter(filename,
fourcc, fourcc,

69
test/weighted_images.py Normal file
View File

@@ -0,0 +1,69 @@
"""
.. module:: weighted_images
:platform: Unix, Windows
:synopsis: Basic test script aiming at testing the possibility to use inter frames between images to enhance video output
.. moduleauthor:: Julien Lengrand-Lambert <jlengrand@gmail.com>
"""
import sys
import cv
image1 = "../data/inputs/moi/DSC04858.jpg"
image2 = "../data/inputs/moi/DSC04882.jpg"
delay = 00
# input images
im1 = cv.LoadImage(image1)
im2 = cv.LoadImage(image2)
# cv.NamedWindow("im1", cv.CV_WINDOW_NORMAL)
# cv.NamedWindow("im2", cv.CV_WINDOW_NORMAL)
# cv.ResizeWindow("im1", 640, 480)
# cv.ResizeWindow("im2", 640, 480)
# cv.MoveWindow("im1", 0, 0)
# cv.MoveWindow("im2", 640, 0)
# cv.ShowImage("im1", im1)
# cv.ShowImage("im2", im2)
# weighted images
filename = "../data/output/weighted.avi"
# Codec is OS dependant.
# FIXME : Find an unified version
if "win" in sys.platform:
fourcc = cv.CV_FOURCC('C', 'V', 'I', 'D')
else: # some kind of Linux/Unix platform
fourcc = cv.CV_FOURCC('F', 'M', 'P', '4')
fps = 5
frameSize = cv.GetSize(im1)
my_video = cv.CreateVideoWriter(filename,
fourcc,
fps,
frameSize,
1)
num_inter_im = 10
step = float(1)/10
for i in range(num_inter_im + 1 ):
print i
im3 = cv.CreateImage(cv.GetSize(im1), im1.depth, im1.nChannels)
alpha = step * i
beta = 1 - alpha
gamma = 0
cv.AddWeighted(im1, alpha, im2, beta, gamma, im3)
cv.WriteFrame(my_video, im3)
# cv.NamedWindow("im3", cv.CV_WINDOW_NORMAL)
# cv.ResizeWindow("im3", 640, 480)
# cv.MoveWindow("im3", 640, 500)
# cv.ShowImage("im3", im3)
# cv.WaitKey(delay)