Commit 718bb603 authored by YvanM's avatar YvanM

- avoid failure when face detection does not work on a picture and "-names" is

  used
- rotate picture before face detection
parent f270dcf8
......@@ -52,11 +52,11 @@ parser = argparse.ArgumentParser(
"- CSV must not contain empty line\n"
"- lines must be in the form \"surname,name\" or\n"
" \"surname,name,NOPIC\" if you do not have this person's picture\n"
"- lines order must match pictures order\n"
"- lines order must match pictures alphanumerical order\n"
"If you provide people names from pictures name, those should be \n"
"in the form \"surname_name.jpg\".\n"
"\n"
"ImageMagick and Ghostscript tools must be in your PATH.")
"ImageMagick and Ghostscript tools must be in your $PATH.")
parser.add_argument("directory",
help="DIRECTORY that contains pictures, one for each person")
parser.add_argument("-n", "--names",
......@@ -151,21 +151,25 @@ if args.crop:
# get face position
f = open(pic, 'rb')
img = Image.open(f)
face = img.detect_faces()
# face detection does not work when picture is rotated
face = img.auto_orient().detect_faces()
if len(face) == 0:
eprint("Warning: " + pic + ": no face has been detected")
eprint("Warning: " + pic + ": no face has been detected, using "
"original picture")
with open(os.path.join(directory, os.path.basename(pic)), 'wb') as out:
img.save_as_jpeg(out)
continue
elif len(face) > 1:
eprint("Warning: " + pic + ": more than one face has been "
"detected, the first one will be used")
"detected, the first one will be used")
# makes the square around face a bit bigger to ease recognition
face = enlargeFace(img.get_size(), face[0])
face = enlargeFace(img.auto_orient().get_size(), face[0])
# crop picture
img = img.crop((face))
img = img.auto_orient().crop((face))
# enventually replace alpha channel by white color (avoids crash)
img = img.set_background_color_rgb((255,255,255))
# save a copy
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment