mirror of
https://github.com/jlengrand/Ivolution.git
synced 2026-03-10 08:21:18 +00:00
Test with Thread. Seems ok. Facemoviefier to me modified
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ packaging
|
||||
doc/build
|
||||
*~
|
||||
README.rst
|
||||
test.py
|
||||
|
||||
@@ -15,7 +15,7 @@ class FaceParams(object):
|
||||
'''
|
||||
Simple class used to store parameters used for Face detection
|
||||
'''
|
||||
def __init__(self, xml_folder, training_type, input_folder, output_folder, sort="name", mode="conservative",speed=2):
|
||||
def __init__(self, xml_folder, input_folder, output_folder, training_type="frontal_face", sort="name", mode="conservative",speed=1):
|
||||
"""
|
||||
Creates dictionary for all types of training files
|
||||
some of them shall never be used. Perhaps would it be good to lower the dict size, or hide some of them
|
||||
@@ -38,8 +38,8 @@ class FaceParams(object):
|
||||
:type sort: string
|
||||
"""
|
||||
|
||||
self.input_folder = "."
|
||||
self.output_folder = "."
|
||||
self.input_folder = input_folder
|
||||
self.output_folder = output_folder
|
||||
self.speed = 1 # between 0 and 2
|
||||
self.mode = "conservative" # conservative or crop
|
||||
self.sort = "name" # name or exif
|
||||
@@ -63,14 +63,14 @@ class FaceParams(object):
|
||||
print "Selected parameters for your Facemovie:"
|
||||
print "Input Folder: %s" % (self.input_folder)
|
||||
print "Output Folder: %s" % (self.output_folder)
|
||||
print "Speed for movie: %s" % (["slow", "medium", "fast"][self.speed + 1])
|
||||
print "Video Mode: %" % (self.mode)
|
||||
print "Files sorting method: %" % (self.sort)
|
||||
print "Speed for movie: %s" % (["slow", "medium", "fast"][self.speed])
|
||||
print "Video Mode: %s" % (self.mode)
|
||||
print "Files sorting method: %s" % (self.sort)
|
||||
print "-----"
|
||||
print "Selected parameters for Face Detection:"
|
||||
print "Selected cascade for Face detection : %s" % ("haarcascade_frontalface_alt")
|
||||
print "Minimum Size (x, y): %d" % (self.min_size[0], self.min_size[1])
|
||||
print "Image scaling: %d, %d)" % (self.image_scale)
|
||||
print "Minimum Size (x, y): %d, %d" % (self.min_size[0], self.min_size[1])
|
||||
print "Image scaling: %d)" % (self.image_scale)
|
||||
print "Haar scaling: %f" % (self.haar_scale)
|
||||
print "Number of Haar flags: %d" % (self.haar_flags)
|
||||
print "Minimum number of neighbors: %d" % (self.min_neighbors)
|
||||
|
||||
41
facemovie/FacemovieThread.py
Normal file
41
facemovie/FacemovieThread.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
.. module:: Facemovie
|
||||
:platform: Unix, Windows
|
||||
:synopsis: Main class of the application. Contains the core image processing functions.Plays the role of a controller for the application, as it supports the communication layer with the end user interface.
|
||||
|
||||
.. moduleauthor:: Julien Lengrand-Lambert <jlengrand@gmail.com>
|
||||
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from facemovie import Facemovie_lib
|
||||
|
||||
class FacemovieThread(threading.Thread):
|
||||
'''
|
||||
Creates a Thread version of Facemovie using the facemovie_lib.
|
||||
This class can then be run anywhere, from a GUI, script, ...
|
||||
'''
|
||||
def __init__(self, face_params):
|
||||
"""
|
||||
Initializes all parameters of the application. Input and output folders
|
||||
are defined, together with the classifier profile.
|
||||
|
||||
:param face_params: A faceparams object that contains all needed information to run the Facemovie.
|
||||
:type face_params: FaceParams
|
||||
"""
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
self.face_params = face_params
|
||||
self.facemovie = Facemovie_lib.FaceMovie(self.face_params)
|
||||
|
||||
def run(self):
|
||||
print "In thread !"
|
||||
|
||||
self.facemovie.list_guys()
|
||||
self.facemovie.prepare_faces() # I want to search for the faces, and characteristics of the images
|
||||
self.facemovie.find_final_dimensions() # finds output size for desired mode.
|
||||
self.facemovie.save_movie()
|
||||
|
||||
print "Finished!"
|
||||
@@ -40,6 +40,14 @@ class FaceMovie(object):
|
||||
# Retrieving parameters for Face Detection
|
||||
self.face_params = face_params
|
||||
|
||||
|
||||
out_folder = self.face_params.output_folder
|
||||
self.out_path = "./data"
|
||||
self.out_name = "output"
|
||||
self.out_format = "avi"
|
||||
# updating the out_folder if needed
|
||||
self.check_out_name(out_folder)
|
||||
|
||||
self.face_params.output_folder
|
||||
self.out_path = "./data"
|
||||
self.out_name = "output"
|
||||
@@ -260,7 +268,7 @@ class FaceMovie(object):
|
||||
"""
|
||||
return os.path.join(self.out_path, (self.out_name + "." + self.out_format))
|
||||
|
||||
def save_movie(self, speed=2):
|
||||
def save_movie(self):
|
||||
"""
|
||||
Creates a movie with all faces found in the inputs.
|
||||
Guy is skipped if no face is found.
|
||||
@@ -271,7 +279,7 @@ class FaceMovie(object):
|
||||
:param fps: the number of frames per second to be displayed in final video (3)
|
||||
:type fps: int
|
||||
"""
|
||||
|
||||
speedrate = self.face_params.speed
|
||||
if "win" in sys.platform:
|
||||
fourcc = cv.CV_FOURCC('C', 'V', 'I', 'D')
|
||||
else: # some kind of Linux/Unix platform
|
||||
@@ -280,10 +288,10 @@ class FaceMovie(object):
|
||||
frameSize = (self.dims[0], self.dims[1])
|
||||
|
||||
pace = ["slow", "normal", "fast"]
|
||||
print "Speed is set to %s" %(pace[speed - 1])
|
||||
print "Speed is set to %s" %(pace[speedrate])
|
||||
my_video = cv.CreateVideoWriter(self.get_out_file(),
|
||||
fourcc,
|
||||
self.speed[speed - 1],
|
||||
self.speed[speedrate],
|
||||
frameSize,
|
||||
1)
|
||||
ii = 0
|
||||
|
||||
Reference in New Issue
Block a user