Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix face detection failures for non-photorealistic images
When using --preprocess full with anime/illustrated images, face
detection fails at two points and crashes with unhelpful errors:

1. croper.py: `raise 'string'` was invalid Python 3 syntax and
   lm=None check didn't handle the full-mode case. Now returns the
   full image as crop/quad ([0,0,W,H]) so processing continues
   without a detected face.

2. extract_kp_videos_safe.py: `bboxes[0]` raises IndexError when
   detect_faces() returns an empty array. Added IndexError to the
   existing TypeError handler so it falls back to -1 keypoints,
   which preprocess.py already handles gracefully.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
  • Loading branch information
cab66420 and claude committed Apr 19, 2026
commit 29aaa472e73ed53eb521253fd3244b5a76864679
4 changes: 2 additions & 2 deletions src/face3d/extract_kp_videos_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 10 additions & 2 deletions src/utils/croper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down