Nodes/comfyui_cv/CV Quad To Rectangle
ComfyUI Node

CV Quad To Rectangle

Computes the axis-aligned target rectangle for a TL/TR/BR/BL-ordered quadrilateral. By default the output width/height are the longest of the opposing edge pairs (projected edge lengths) - fine for mild perspective, but a strongly foreshortened page (shot from its bottom edge) comes out with the WRONG orientation, e.g. a portrait document rectified into a stretched landscape. Wire image_width/image_height (e.g. from 'CV Array Shape' of the photo) to recover the rectangle's TRUE aspect ratio from the perspective itself (Zhang's whiteboard method: square pixels + centered principal point). Feed 'corners' and 'rect_corners' into cv2.getPerspectiveTransform (src/dst) and warp with the dsize output.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Quad To Rectangle
  • corners
  • rect_corners
  • dsize
  • width
  • height
  • size
max_size8192
image_width0
image_height0
focal_ratio0.78
Categoryimage/CV/contours

Inputs (5)

NameTypeDefaultDescription
cornersNPARRAY4x1x2 quad ordered TL/TR/BR/BL (from 'CV Find Quadrilateral').
max_sizeINT819264–32768Cap on the output width/height; larger results are scaled down proportionally.
image_widthoptINT00–32768Width of the photo the corners live in. Both dimensions > 0 enable perspective-corrected aspect recovery; 0 keeps the projected-edge-length behavior. Wire from 'CV Array Shape'.
image_heightoptINT00–32768Height of the photo the corners live in. Both dimensions > 0 enable perspective-corrected aspect recovery; 0 keeps the projected-edge-length behavior. Wire from 'CV Array Shape'.
focal_ratiooptFLOAT0.780.05–5Assumed focal length as a fraction of max(image_width, image_height), used ONLY when the quad has a single vanishing point (opposing edges parallel in the photo), where the focal length cannot be recovered from the quad. 0.78 ~ a 28mm-equivalent phone lens; smaller = wider lens = stronger foreshortening correction.

Outputs (5)

NameTypeDescription
rect_cornersNPARRAY4x1x2 float32 destination rectangle, same TL/TR/BR/BL order.
dsizeSTRING'(width, height)' literal, for the composite cv2 params that are still free-text.
widthINT
heightINT
sizeCV_TUPLEThe target (width, height) as ONE composite value - wire it into cv2.warpPerspective's dsize.