ComfyUI Node

Crop 2d KPS

Keeping keypoints lined up when you crop the pose image

By nosiu·Created 3 years ago·Updated about a year ago· 264
Crop 2d KPS
  • kps_data
  • kps_data
x0
y0
width1024
height1024

The moment you crop a pose image - say, via PreprocessImage pulling out just the masked face region - any keypoint data you had for the original image is now pointing at the wrong coordinates. This node is the fix: it crops kps_data the same way you crop a pixel image, using an x/y offset and a target width/height, so your keypoints stay aligned to whatever cropped region you're actually generating against.

Why this matters in practice

InstantID's ControlNet conditions on the keypoint image lining up with the pose image it's paired with. If you crop your photo down to just the face area but forget to crop your keypoints to match, IdentityNet ends up conditioning on landmark positions that describe a region of the image that no longer exists in your cropped frame - the geometry and the pixels disagree, and results get unpredictable fast. This node exists specifically so that never has to happen by accident: crop the image, crop the KPS with the same numbers, done.

The inputs and outputs that matter

  • kps_data - required, from any upstream KPS-producing node.
  • x / y (both default 0) - the top-left corner of the crop region, in the same coordinate space your keypoints already live in.
  • width / height (both default 1024, minimum 1) - the size of the cropped region.

Output: kps_data, with coordinates shifted and clipped to the new crop window.

Where this actually shows up

The most natural pairing is with PreprocessImage, which outputs x, y, new_width, and new_height alongside your resized image - those are exactly the numbers this node wants if you're maintaining a separate KPS stream in parallel with the image crop that node performs. It's also relevant any time you're manually cropping a pose photo in a workflow and have keypoint data (drawn or extracted) that needs to track that crop.

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. Pure geometry node, no model dependency of its own.

Common issues & troubleshooting

Keypoints disappear or end up outside the visible frame after cropping. If your x/y/width/height values don't actually overlap with where the keypoints currently sit, you'll crop them right out of the frame. Double-check the crop region against the keypoints' actual coordinate space before assuming the node is broken - it's doing exactly what you told it to.

Generated face doesn't match the keypoint positions anymore. This almost always means the image crop and the KPS crop used different numbers somewhere - a manual crop on the image side that isn't mirrored here, or values pulled from the wrong output of PreprocessImage. Keep the x/y/width/height feeding both the image crop and this node coming from the same source.

Not sure if you even need this node. If you're not manually cropping your pose image outside of what PreprocessImage already handles internally, you likely don't - PreprocessImage builds its own aligned control_image when given an insightface input, without requiring you to wire this node in separately.

CategoryInstantId Faceswap

Inputs (5)

NameTypeDefaultDescription
kps_dataKPS_DATA
xINT00–16384
yINT00–16384
widthINT10241–16384
heightINT10241–16384

Outputs (1)

NameTypeDescription
kps_dataKPS_DATA