Nodes/comfyui-instantId-faceswap/Get Angle from face
ComfyUI Node

Get Angle from face

Auto-detecting how far off-axis your reference face is

By nosiu·Created 3 years ago·Updated about a year ago· 264
Get Angle from face
  • insightface
  • image
  • mask
  • angle
rotate_mode
pad_top100
pad_right100
pad_bottom100
pad_left100

InstantID likes a roughly upright, aligned face - that's when its landmark detection and IdentityNet conditioning work best. If your pose image has a tilted head, this node figures out exactly how many degrees you'd need to rotate the image to straighten it, so you can auto-correct before generation instead of eyeballing it. It's the node behind this pack's auto_rotate.json example workflow: detect the tilt, rotate, generate, rotate back.

How it works

You give it an image and a mask, and it searches for a face specifically within the masked area - expanded outward by the four pad_* values - rather than scanning the whole image. That matters if your pose image has multiple people in it: without a mask constraining the search, insightface could lock onto the wrong face entirely. Once it finds the face, it measures the angle needed to bring it to upright, according to whichever rotate_mode you picked.

The README is upfront about a real limitation here: at extreme rotation angles, insightface's keypoint detection gets unreliable, so the angle this node returns can be wrong in exactly those cases. If your reference is already tilted more than a little, don't trust this blindly - check the result, or skip straight to drawing your own KPS with KpsDraw instead.

The inputs and outputs that matter

  • insightface - the loaded app from LoadInsightface.
  • image - tooltip straight from the node: "Pose image." - this is your source photo, not a face reference.
  • mask - constrains the face search area.
  • rotate_mode - three options: none (always returns 0, effectively disables this node), loseless (rounds to the nearest 90/180/270°, useful if you know the image is a clean multiple-of-90 rotation and want to avoid introducing any resampling blur from an arbitrary angle), any (returns the exact angle needed).
  • pad_top / pad_right / pad_bottom / pad_left (all default 100) - how far to expand the mask outward in each direction before searching. More padding gives insightface more context to work with, at the cost of potentially catching a second face if one's nearby.

Output: angle (FLOAT) - feed this into whatever rotates your actual pose image (this pack's own image-rotation node, per the README's node list) and, separately, into KpsRotate if you're rotating keypoint data along the same path.

Install

ComfyUI Manager: search comfyui-instantId-faceswap. Manual: git clone https://github.com/nosiu/comfyui-instantId-faceswap into custom_nodes/, pip install -r requirements.txt. Needs antelopev2 in ComfyUI/models/insightface/models/antelopev2 - same dependency as every other insightface-driven node in this pack.

Common issues & troubleshooting

Angle comes back wrong or wildly off. Most likely the face is rotated further than insightface's landmark detection can reliably handle. This isn't a bug you can tune around with pad - it's the node hitting the limit of what automatic detection can do at extreme angles. Switch to KpsDraw and set your keypoints (and the resulting angle) by hand.

Always returns 0. Check rotate_mode first - none always returns 0 by design, which is easy to leave selected by accident if you copied a workflow from elsewhere.

Node can't find a face at all. Same underlying cause as "No face detected in pose image" elsewhere in this pack - widen the mask or increase the pad_* values so more of the surrounding face context is included in the search area.

CategoryInstantId Faceswap

Inputs (8)

NameTypeDefaultDescription
insightfaceINSIGHTFACE_APP
imageIMAGEPose image.
maskMASK
rotate_modeCOMBO3 options: none, loseless, any
pad_topINT1000–16384
pad_rightINT1000–16384
pad_bottomINT1000–16384
pad_leftINT1000–16384

Outputs (1)

NameTypeDescription
angleFLOAT