diff --git a/src/face3d/extract_kp_videos_safe.py b/src/face3d/extract_kp_videos_safe.py index 5141ba3a..25dde130 100644 --- a/src/face3d/extract_kp_videos_safe.py +++ b/src/face3d/extract_kp_videos_safe.py @@ -89,10 +89,10 @@ def extract_keypoint(self, images, name=None, info=True): else: print(e) break - except TypeError: + except (TypeError, IndexError): print('No face detected in this image') shape = [68, 2] - keypoints = -1. * np.ones(shape) + keypoints = -1. * np.ones(shape) break if name is not None: np.savetxt(os.path.splitext(name)[0]+'.txt', keypoints.reshape(-1)) diff --git a/src/utils/croper.py b/src/utils/croper.py index 3d9a0ac5..5b96f715 100644 --- a/src/utils/croper.py +++ b/src/utils/croper.py @@ -127,8 +127,16 @@ def crop(self, img_np_list, still=False, xsize=512): # first frame for all vi img_np = img_np_list[0] lm = self.get_landmark(img_np) - if lm is None: - raise 'can not detect the landmark from source image' + # 顔未検出 + full モード時のフォールバック + if lm is None or len(lm) == 0: + if not still: # still=False = full モード + H, W = img_np_list[0].shape[:2] + # 画像全体を crop/quad に設定(クロップなし) + # preprocess.py が lx, ly, rx, ry = quad と4スカラーで受け取るため + crop = [0, 0, W, H] + quad = [0, 0, W, H] # [lx, ly, rx, ry] + return img_np_list, crop, quad + raise Exception('can not detect the landmark from source image') rsize, crop, quad = self.align_face(img=Image.fromarray(img_np), lm=lm, output_size=xsize) clx, cly, crx, cry = crop lx, ly, rx, ry = quad