Nodes/comfyui_cv/CV Fit Points To Box
ComfyUI Node

CV Fit Points To Box

Scales and centres a set of 2D points so they fill a width x height pixel box (with a margin), preserving the aspect ratio (one uniform scale for both axes) - turns metric coordinates like a triangulated cloud projected top-down ('CV Project To Plane') or a 'Compose Pose' trajectory into drawable pixels for 'CV Draw Points' / 'CV Draw Polygon'. Failure-tolerant: None/empty passes through as an empty array and a single point (or a zero-extent set) lands at the box centre, so it never divides by zero or raises.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Fit Points To Box
  • points
  • extent_from
  • points
  • scale
  • offset_x
  • offset_y
width300
height300
margin20
y_axisy down (pixel rows)
Categoryimage/CV/points

Inputs (6)

NameTypeDefaultDescription
pointsNPARRAY2D points, Nx2 or Nx1x2 (None/empty -> empty output).
widthINT3001–16384Target box width in pixels (match your canvas).
heightINT3001–16384Target box height in pixels.
marginINT200–4096Padding kept clear inside the box, in pixels.
extent_fromoptNPARRAYTake the range to fit from THESE points instead of 'points'. Two tracks fitted separately each fill the box, so overlaying them silently rescales one against the other - pass both tracks concatenated here (and to 'CV Draw Plot Frame') and every set shares one mapping. Empty = use 'points', as before.
y_axisoptCOMBOy down (pixel rows)Which way the second coordinate grows on the canvas. Pixel rows grow DOWNWARD, so mapping a world axis straight onto them draws it upside down - for a top-down (XZ) map that mirrors the picture and a left turn comes out looking like a right turn. Choose 'y up (world)' whenever the second coordinate is a world axis you want read as a map; leave it 'y down' when the points are already in pixel space. Pass the SAME value to 'OpenCV Draw Plot Frame' so the grid and the data agree.

Outputs (4)

NameTypeDescription
pointsNPARRAYPoints scaled into the box, Nx1x2 float32.
scaleFLOATPixels per world unit, i.e. pixel = world * scale + offset. Feed it to a scale bar or a measurement.
offset_xFLOATPixel column that world x = 0 maps to.
offset_yFLOATPixel row that world y = 0 maps to.