Is This Selfie a Profile or a Three-Quarter View? A Python Face-Yaw Check Before a Malfoid AI Upload A developer built a Python pre-upload yaw check that uses OpenCV's YuNet face detector and its five landmarks to estimate head turn via solvePnP with the SQPNP solver, then labels a still as front, three-quarter, or near-profile. Benchmarked on synthetic homography-warped fixtures at 45° and 75°, the script locks thresholds at |yaw| under 15° for ok, 15–50° for warn, and 50° or more for retake, with the code and tests released alongside the post. The photo-requirements https://malfoidai.com/guides/photo-requirements/ guide for Malfoid AI https://malfoidai.com/ asks for one clear, front-facing photo of one adult, with the whole face visible. The good/bad table on that page is blunt: "Facing the camera, eyes open" versus "Profile shots and faces turned far away." A file can still contain a face and fail that test. The head is turned. You see one ear clearly and the far eye is almost gone. That is yaw — left/right head turn — not tilt, and not a small face in a wide room. This is a pre-upload check for that case. It is not a roll or leveling check I wrote one of those on 14 November, using YuNet and a symmetry measure of tilt . It is not a minimum-face-size check, and it is not a blink or sunglasses check. It estimates yaw from face landmarks on a still, then labels the view as front, three-quarter, or near-profile. I run the studio. It makes a still 3:4 Female Malfoy / Fem Draco portrait at a 1K setting, from one photo of an adult or without a photo. A portrait is $4.99 and spends 2 credits. There is no video, no prompt box, and no clip length. The look is unofficial fan art, not affiliated with the author, the publishers, or the studios. The fixtures in this post are synthetic sitters — shapes only, platinum hair, an oval face, academy clothes. No real photograph, no customer render, no studio showcase. The script, tests, and bench live next to this post as yaw check.py , make yaw fixtures.py , test yaw check.py , and bench yaw.py , plus the YuNet model file yunet.onnx . OpenCV's YuNet face detector cv2.FaceDetectorYN returns a box and five landmarks: the sitter's right eye, left eye, nose tip, right mouth corner, and left mouth corner. On a frontal photo the sitter's right eye is the one on the left side of the image. I take the highest-scoring face whose box is at least 15% of the image height, so a tiny ghost box in a corner cannot win. From those five points I compute two numbers: nose offset over iod . yaw deg . cv2.solvePnP with the SOLVEPNP SQPNP flag. OpenCV 5's default iterative solver wants six points; YuNet only gives five, and SQPNP accepts five. I use a small generic 3D face model in millimetres, y down, +z toward the camera: right eye -30, -32, -26 left eye 30, -32, -26 nose tip 0, 0, 0 right mouth -22, 28, -24 left mouth 22, 28, -24 The camera has fx = fy = image width and the principal point at the centre. Yaw is atan2 R 0, 2 , R 2, 2 in degrees, the same sign convention as the offset ratio. The check does not use the construction landmarks at test time. It only sees what YuNet returns on the pixels. After the bench below I locked two cuts, in degrees: |yaw| < 15 → ok 15 ≤ |yaw| < 50 → warn |yaw| ≥ 50 → retake The photo-requirements page wants a front-facing photo, so a three-quarter view is a warning retake if you can and a near-profile, or a file YuNet cannot find a face in, is a retake. Fifteen degrees is a round number that sat in a clear gap in the measurements. Fifty degrees is well above anything the detector returned on a detectable three-quarter fixture; in this bench the near-profile cases never produced a yaw at all. Every sitter starts from the same frontal drawing symmetric face geometry, seed 1 of the helper I use for these guides . Sitters 2–8 are mild brightness and colour shifts of that drawing, so they are not byte-identical, but they are not left/right biased. A three-quarter view is that frontal drawing, yawed 45° with a planar homography a rotation about the vertical axis through the image centre, camera distance 1.6 × image width . A near-profile is the same warp at 75° . These are synthetic plane warps of a drawing, not photographed heads, and I label them that way. I also tried a horizontal flip of the 45° warp as a right-hand three-quarter. YuNet often placed a weaker box that did not follow the flipped face, so I did not use a flipped pose as a signed-yaw fixture. The official bench is three poses: front, three-quarter left, near-profile. 8 sitters × 3 poses × PNG + JPEG quality 95 = 48 files. All 48 classified as intended: 16/16 front ok , 16/16 three-quarter warn , 16/16 near-profile retake . Median analyse time was 24.74 ms mean 25.78 ms on this box. Elapsed 1.490 s. Tests: 6 passed . Front 16 detected / 16 : yaw mean 8.653° , min 6.211° , max 12.064° . Ratio mean 0.0582 , min 0.0391 , max 0.0844 . Three-quarter 45° left 16 detected / 16 : yaw mean 32.708° , min 30.850° , max 34.869° . Ratio mean 0.2460 , min 0.2126 , max 0.2714 . Near-profile 75°: 0 detections, 16 no face . YuNet did not return a face that cleared the 15% height and 0.50 score gates. The default sitter seed 1, PNG is the distinctive walk-through: front yaw +6.906° , ratio 0.0441 , score 0.8175 ; three-quarter yaw +32.345° , ratio 0.2254 , score 0.7605 ; near-profile no face . The JPEG q95 copies sat within half a degree of the PNG front +6.50°, three-quarter +31.89° . The gap between the highest front yaw 12.064° and the lowest three-quarter yaw 30.850° is what made 15° a comfortable cut. I did not have to shave the threshold to fit a messy overlap. A 75° plane warp of a frontal drawing is not a true photographed profile, and I will not pretend it is. What I can say is: on this fixture family, YuNet stops reporting a usable face somewhere between 45° always detected here and 75° never detected here . That is still a useful pre-upload result. The studio asks for a front-facing photo. If the detector that would find a face in a normal selfie cannot find one, the file is already a bad candidate. The check labels that no face and tells you to retake, rather than guessing a yaw from no landmarks. A frontal drawing still measures a few degrees of yaw — 6° to 12° on these sitters, not 0.000°. The landmarks are slightly imperfect, and the generic 3D model is not this drawing's head. I treat anything under 15° as front-facing and do not chase a zero residual. python yaw check.py selfie.jpg python yaw check.py selfie.jpg --json python -m pytest test yaw check.py python bench yaw.py A typical line looks like: selfie.jpg: state=three quarter advice=warn yaw=+32.35 deg ratio=0.2254 score=0.7605 iod=84.3 The script exits 0 only when the advice is ok . A warning or a retake is exit 1, so you can use it in a small pre-upload hook if you want. If you take a new selfie for a Malfoid https://malfoidai.com/ portrait, hold the phone at eye level and look at the camera. The requirements page already says that. This check is only there to catch the file where the face is clear, the eyes are open, and the head has still been turned too far to be a front-facing upload. The three-quarter fixture is a homography, not a 3D-rendered head. I treat the frontal drawing as a plane at z = 0, rotate it about the vertical axis through the image centre, and project it with a pinhole camera whose distance is 1.6 times the image width. In image coordinates, a source point at X, Y from the centre maps to u = D X cos θ / D + X sin θ v = D Y / D + X sin θ with D = 1.6 W. I fit a 3×3 matrix to a handful of those correspondences and warp with cv2.warpPerspective , filling empty pixels with a dark corridor colour 18, 16, 14 . At 45° the near cheek is enlarged and the far cheek is compressed, and YuNet still finds the five points. At 75° the far side collapses far enough that the detector returns nothing that clears the gates. I would rather report that miss than invent a profile angle. I kept face geometry left/right symmetric on purpose. An earlier draft varied the construction width from sitter to sitter, and some "frontal" drawings already measured as a three-quarter view because the oval was no longer balanced. Colour and brightness shifts were enough to make eight files, and they stayed under the 15° cut. The 14 November guide uses the same YuNet model, but it measures roll : is the head tilted or sideways, and can I level it? It even has a yaw proxy on the landmarks — a nose offset in units of IOD — which it only uses as a warning that the pose may not be frontal. Today's script turns that idea into a degree estimate, gives it thresholds, and tests it on yawed fixtures. It does not rotate the photo, it does not crop a leveled rectangle, and it does not look at mirror symmetry of the face. If your selfie is both tilted and turned, run the leveling check first, then this one on the leveled crop. They fail for different reasons. YuNet here is the 2023 face detection yunet ONNX, 232,589 bytes, loaded with FaceDetectorYN.create . The score threshold is 0.50 and NMS is 0.30, with a 320×320 input size. On this box OpenCV 5.1.0 each create call prints a warning that "Targets are not supported by the new graph engine for now." The detections still return; I left the warning in the logs rather than hiding it. If you are on OpenCV 4, SOLVEPNP SQPNP and FaceDetectorYN are also present; I only tested 5.1.0. The JSON record includes the box, the IOD in pixels, the raw offset, the ratio, the yaw, the state, and the advice. It also repeats the locked thresholds, so a later change cannot silently shift a published number. This is a first-party check on synthetic drawings, not a published accuracy claim on real phone selfies. A real three-quarter portrait has a far-side ear, a nose silhouette, and lighting that a plane warp cannot invent. YuNet may be more or less willing to detect a photographed profile than it was on these 75° warps. The 15° and 50° cuts are locked on this fixture family; if you change the 3D model or the camera matrix, re-run the bench before you keep the same labels. Do not upload a real customer's photo to a public post in order to "try it." Use a picture of yourself that you are willing to retake, or a synthetic fixture like the ones in the repo. A portrait from malfoidai.com https://malfoidai.com/ is still $4.99 / 2 credits, still 3:4, still 1K, still unofficial fan art. The check only asks whether the photo you are about to pay for is actually facing the camera.