DEV Community

Peiguan
Peiguan

Posted on

Is This Selfie Tilted (Roll)? A Python Head-Tilt Check Before a Malfoid AI Upload

A selfie can be front-facing and still be tilted. Yaw is a turn to the side. Pitch is a look from below or above. Roll is the in-plane tilt — the line through the two eyes is no longer level. This script measures that angle, and only that angle, before you upload a photo to a Malfoid portrait preset.

I run the studio at Malfoid AI. It makes a still Female Malfoy / Fem Draco portrait, from a photo of an adult or without a photo, for $4.99 / 2 credits. The resolution setting is 1K. There is no video and no prompt box. Credit packs, if you want them, are one-time purchases after sign-in: $13.99 for 30, $35.99 for 100, $59.99 for 200. Prices are from the pricing page, re-checked 30 November 2026, 18:24:49–18:25:22 Asia/Shanghai. There is no Cyber Monday sale on the live pages. The photos in this article are synthetic construction drawings — shapes only — not studio outputs and not anyone's picture.

This is not a yaw / profile check, not a pitch check, and not a remake of the 11-14 "level a tilted selfie" guide (YuNet plus a mirror-symmetry estimate that then rotates and crops the frame). That guide corrects a tilt. This one only reports it. The official photo-requirements guide already asks for a clear, front-facing photo of one adult. A strongly rolled selfie is a common reason a face looks "off" before you spend $4.99 / 2 credits.

The eye line, in degrees

The detector looks for a pair of open eyes in the construction face box. Each construction eye is a white sclera split by a grey-green iris, so a raw connected-component pass can treat one eye as a vertical pair. A morphological close joins the two crescents, then the script picks the pair whose areas are close and whose separation is a plausible inter-ocular distance. The signed roll is the angle of that line:

ROLL_KEEP = 8.0
ROLL_FAIL = 15.0

# Positive roll_deg is clockwise in image coordinates
# (the right eye sits lower on the page, because +y is down).
roll_deg = degrees(atan2(right_y - left_y, right_x - left_x))

if abs(roll_deg) < ROLL_KEEP:
    state = "level"
elif abs(roll_deg) < ROLL_FAIL:
    state = "mild"
else:
    state = "tilted"
Enter fullscreen mode Exit fullscreen mode

If two eyes cannot be found, the result is no_eye_line. The script does not rotate or crop the photo.

The bench

Eight sitters × six known rolls (0°, +5°, −7°, +12°, −18°, +25°) × PNG + JPEG q95 = 96 files, 96/96. Median analyse 27.16118050739169 ms. Thresholds stay at |roll| < 8° keep and |roll| ≥ 15° fail. Seed 1, PNG:

  • 0°: roll 0.0, two eyes at (330.0, 388.6526104417671) and (438.0, 388.6526104417671), level
  • +5°: roll 4.988600898584292, level
  • −7°: roll −6.9373557365127905, level
  • +12°: roll 12.000477686635428, mild
  • −18°: roll −18.020426272479764, tilted
  • +25°: roll 25.094715479897346, tilted

The script is roll_check.py, with make_roll_fixtures.py, bench_roll.py, and test_roll_check.py. It uses Pillow, NumPy, and OpenCV. If the face is already level, you can upload it. If it is rolled past 15°, level the selfie first — this checker will not do that step for you.

Top comments (0)