{"slug": "is-this-selfie-a-profile-or-a-three-quarter-view-a-python-face-yaw-check-before", "title": "Is This Selfie a Profile or a Three-Quarter View? A Python Face-Yaw Check Before a Malfoid AI Upload", "summary": "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.", "body_md": "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.\n\nThis 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.\n\nI 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.\n\nThe 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`.\n\nOpenCV'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.\n\nFrom those five points I compute two numbers:\n\n`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:\n\n```\nright eye  (-30, -32, -26)\nleft eye   ( 30, -32, -26)\nnose tip   (  0,   0,   0)\nright mouth(-22,  28, -24)\nleft mouth ( 22,  28, -24)\n```\n\nThe 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.\n\nThe check does not use the construction landmarks at test time. It only sees what YuNet returns on the pixels.\n\nAfter the bench below I locked two cuts, in degrees:\n\n`|yaw| < 15` → `ok`\n`15 ≤ |yaw| < 50` → `warn`\n`|yaw| ≥ 50` → `retake`\nThe 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.\n\nEvery 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.\n\nI 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.\n\n8 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**.\n\nFront (16 detected / 16): yaw mean **8.653°**, min **6.211°**, max **12.064°**. Ratio mean **0.0582**, min **0.0391**, max **0.0844**.\n\nThree-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**.\n\nNear-profile 75°: **0** detections, **16** `no_face`. YuNet did not return a face that cleared the 15% height and 0.50 score gates.\n\nThe 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°).\n\nThe 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.\n\nA 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.\n\nA 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.\n\n```\npython yaw_check.py selfie.jpg\npython yaw_check.py selfie.jpg --json\npython -m pytest test_yaw_check.py\npython bench_yaw.py\n```\n\nA typical line looks like:\n\n```\nselfie.jpg: state=three_quarter advice=warn yaw=+32.35 deg ratio=0.2254 score=0.7605 iod=84.3\n```\n\nThe 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.\n\nIf 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.\n\nThe 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\n\n```\nu = D * X * cos θ / (D + X * sin θ)\nv = D * Y / (D + X * sin θ)\n```\n\nwith 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.\n\nI 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.\n\nThe 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.\n\nYuNet 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.\n\nThe 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.\n\nThis 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.\n\nA 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.", "url": "https://wpnews.pro/news/is-this-selfie-a-profile-or-a-three-quarter-view-a-python-face-yaw-check-before", "canonical_source": "https://dev.to/lpgit/is-this-selfie-a-profile-or-a-three-quarter-view-a-python-face-yaw-check-before-a-malfoid-ai-upload-50a4", "published_at": "2026-11-23 11:02:08+00:00", "updated_at": "2026-11-23 11:12:29.056624+00:00", "lang": "en", "topics": ["computer-vision", "ai-tools", "developer-tools", "artificial-intelligence"], "entities": ["OpenCV", "YuNet", "Malfoid AI", "solvePnP", "SQPNP"], "also_reported_by": [], "takeaway": "YuNet returns only five landmarks, so use cv2.solvePnP with the SOLVEPNP_SQPNP flag rather than the default iterative solver, which needs six points, to estimate yaw from a single still.", "recommendation": {"advice": "Before accepting a face photo, estimate yaw with SQPNP on YuNet's five landmarks and flag anything past 15° as a warning and 50° as a retake.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/is-this-selfie-a-profile-or-a-three-quarter-view-a-python-face-yaw-check-before", "markdown": "https://wpnews.pro/news/is-this-selfie-a-profile-or-a-three-quarter-view-a-python-face-yaw-check-before.md", "text": "https://wpnews.pro/news/is-this-selfie-a-profile-or-a-three-quarter-view-a-python-face-yaw-check-before.txt", "jsonld": "https://wpnews.pro/news/is-this-selfie-a-profile-or-a-three-quarter-view-a-python-face-yaw-check-before.jsonld"}}