"--input", help="input image", type=str, default='play/1.jpg') parser.add_argument("-o", "--out", help="output image file", default='x.jpg') parser.add_argument("--crop_size", help="specify size of aligned faces", default=112, type=int) args = parser.parse_args() crop_size = args.crop_size scale = crop_size / 112. reference = get_reference_facial_points(default_square=True) * scale img = Image.open(args.input).convert('RGB') start = time.time() bounding_boxes, landmarks = detect_faces(img) print(bounding_boxes) print(len(bounding_boxes)) end = time.time() print(end - start) show_results(img, bounding_boxes, landmarks).save(args.out) for i in range(len(landmarks)): facial5points = [[landmarks[i][j], landmarks[i][j + 5]] for j in range(5)] warped_face = warp_and_crop_face(np.array(img), facial5points, reference, crop_size=(crop_size, crop_size)) Image.fromarray(warped_face).save(f'y{i}.jpg')
os.chdir(source_root) os.system("find . -name '*.DS_Store' -type f -delete") os.chdir(cwd) if not os.path.isdir(dest_root): os.mkdir(dest_root) for subfolder in tqdm(os.listdir(source_root)): if not os.path.isdir(os.path.join(dest_root, subfolder)): os.mkdir(os.path.join(dest_root, subfolder)) for image_name in os.listdir(os.path.join(source_root, subfolder)): print("Processing\t{}".format( os.path.join(source_root, subfolder, image_name))) img = Image.open(os.path.join(source_root, subfolder, image_name)) try: # Handle exception _, landmarks = detect_faces(img) except Exception: print("{} is discarded due to exception!".format( os.path.join(source_root, subfolder, image_name))) continue if len( landmarks ) == 0: # If the landmarks cannot be detected, the img will be discarded print("{} is discarded due to non-detected landmarks!".format( os.path.join(source_root, subfolder, image_name))) continue facial5points = [[landmarks[0][j], landmarks[0][j + 5]] for j in range(5)] warped_face = warp_and_crop_face(np.array(img), facial5points, reference,
#!/usr/bin/env python from PIL import Image import numpy as np from evolveface import detect_faces, show_results from evolveface import get_reference_facial_points, warp_and_crop_face import time crop_size = 112 scale = crop_size / 112. reference = get_reference_facial_points(default_square=True) * scale for img in [ "play/img_00005.jpg", "play/img_00276.jpg", "play/img_00277.jpg", "play/img_00278.jpg", "play/img_00279.jpg", "play/img_00280.jpg", "play/img_00281.jpg", "play/img_00282.jpg", "play/img_00283.jpg", "play/img_00284.jpg", "play/img_00285.jpg", "play/img_00286.jpg", "play/img_00287.jpg", "play/img_00288.jpg", "play/img_00323.jpg", "play/img_01718.jpg", "play/img_02692.jpg", "play/img_03152.jpg", "play/img_05397.jpg" ]: bounding_boxes, landmarks = detect_faces(Image.open(img).convert('RGB'))