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.
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)
| Name | Type | Default | Description |
|---|---|---|---|
| corners | NPARRAY | 4x1x2 quad ordered TL/TR/BR/BL (from 'CV Find Quadrilateral'). | |
| max_size | INT | 819264–32768 | Cap on the output width/height; larger results are scaled down proportionally. |
| image_widthopt | INT | 00–32768 | Width 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_heightopt | INT | 00–32768 | Height 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_ratioopt | FLOAT | 0.780.05–5 | Assumed 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)
| Name | Type | Description |
|---|---|---|
| rect_corners | NPARRAY | 4x1x2 float32 destination rectangle, same TL/TR/BR/BL order. |
| dsize | STRING | '(width, height)' literal, for the composite cv2 params that are still free-text. |
| width | INT | — |
| height | INT | — |
| size | CV_TUPLE | The target (width, height) as ONE composite value - wire it into cv2.warpPerspective's dsize. |