Created
March 31, 2020 10:26
-
-
Save galiminus/1fb87cd66cdb31c75f4620c94bbaa0e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import face_alignment | |
from skimage import io | |
from argparse import ArgumentParser | |
def process_image(args): | |
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, flip_input=False) | |
input = io.imread(args.inp) | |
preds = fa.face_detector.detect_from_image(input) | |
(x1, y1, x2, y2, _) = preds[0] | |
width = x2 - x1 | |
height = y2 - y1 | |
size = max(width, height) | |
padding = size * args.increase | |
return "convert %s -crop %dx%d+%d+%d -resize '%dx%d' -gravity center -extent '%dx%d' crop.jpg" % ( | |
args.inp, | |
width, | |
height, | |
x1, | |
y1, | |
args.image_shape[0], | |
args.image_shape[1], | |
args.image_shape[0], | |
args.image_shape[1] | |
) | |
if __name__ == "__main__": | |
parser = ArgumentParser() | |
parser.add_argument("--image_shape", default=(256, 256), type=lambda x: tuple(map(int, x.split(','))), | |
help="Image shape") | |
parser.add_argument("--increase", default=0.1, type=float, help='Increase bbox by this amount') | |
parser.add_argument("--iou_with_initial", type=float, default=0.25, help="The minimal allowed iou with inital bbox") | |
parser.add_argument("--inp", required=True, help='Input image or video') | |
args = parser.parse_args() | |
command = process_image(args) | |
print (command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment