Nodes/comfyui-instantId-faceswap/Get Angle from KPS data
ComfyUI Node

Get Angle from KPS data

The cheaper way to check face alignment

By nosiu·Created 3 years ago·Updated about a year ago· 264
Get Angle from KPS data
  • kps_data
  • angle
rotate_mode

Same job as AngleFromFace - figure out how many degrees a face needs to rotate to sit upright - but computed directly from keypoint data you already have, instead of re-running face detection on an image and a mask. If you've already extracted or drawn kps_data somewhere upstream (via Kps3dFromImage or KpsDraw), this is the cheaper, more reliable way to get an angle out of it: no insightface call, no risk of it losing the face in a masked search, just geometry on points you already trust.

Why this exists separately from AngleFromFace

AngleFromFace runs insightface fresh, every time, on a photo - which means it's subject to the same failure mode as everything else in this pack that depends on detection: extreme angles confuse it, and a bad mask can make it search the wrong region entirely. Once you have kps_data, though, the angle calculation is pure math on five known point positions - nothing to detect, nothing to get wrong from a bad crop. If your workflow already produces kps_data for another reason (you're using KpsDraw, or you pulled it from Kps3dFromImage), reach for this node instead of re-running detection through AngleFromFace.

The inputs and outputs that matter

Just two required inputs:

  • kps_data (KPS_DATA) - from any node in the pack that produces keypoint data: KpsDraw, Kps3dFromImage, or the output of any of the KPS transform nodes (KpsRotate, KpsScale, KpsCrop, the randomizers).
  • rotate_mode - same three options as AngleFromFace: none (always 0), loseless (snaps to the nearest 90/180/270°), any (exact angle).

Output: angle (FLOAT), which typically feeds KpsRotate to actually apply the correction, or a separate image-rotation step if you're straightening the underlying pixels too.

Install

ComfyUI Manager: search comfyui-instantId-faceswap, or git clone https://github.com/nosiu/comfyui-instantId-faceswap into custom_nodes/ and pip install -r requirements.txt. This node has no model dependency of its own - it's pure geometry on kps_data, no insightface call involved, so it works even if antelopev2 isn't installed at all, as long as something else in your graph is producing keypoint data.

Common issues & troubleshooting

Always returns 0. Check rotate_mode - it's set to none by default in some copy-pasted workflows, which silently disables this node's whole purpose.

Angle looks off relative to what you'd expect visually. Since this works purely off kps_data, if the keypoints themselves were misplaced upstream - a bad manual draw in KpsDraw, or a 3D extraction from a low-quality reference photo - this node will faithfully compute the angle for the wrong points. The fix is upstream, not here: check where your kps_data actually came from before assuming this node's math is broken.

Unsure whether to use this or AngleFromFace. If you already have kps_data in hand for another reason, use this one - it's cheaper and doesn't depend on insightface finding anything. If all you have is a raw photo and a mask, AngleFromFace is the one that does the detection work for you.

CategoryInstantId Faceswap

Inputs (2)

NameTypeDefaultDescription
kps_dataKPS_DATA
rotate_modeCOMBO3 options: none, loseless, any

Outputs (1)

NameTypeDescription
angleFLOAT