Nodes/opencv-comfyui/OpenCV getPerspectiveTransform_1
ComfyUI Node

OpenCV getPerspectiveTransform_1

The Perspective Homography Node, Duplicated for Your Convenience (Not Really)

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV getPerspectiveTransform_1
  • src
  • dst
  • nparray
solveMethod

OpenCV getPerspectiveTransform_1 is the same node as getPerspectiveTransform_0 under a second name. The pack auto-generates a node per OpenCV overload, and cv2.getPerspectiveTransform's two overloads flattened to an identical signature - so you have two of the same thing. Same src, dst, and solveMethod inputs, same 3×3 homography output, no hidden behavior in the _1 variant. If this is the one you found in the search, read on - everything here applies to the _0 one too.

What it does

It computes the perspective (homography) matrix mapping four source points to four destination points - the math behind straightening photographed documents, screens, or anything tilted. Output is a 3×3 matrix (nparray), which you feed into the pack's warpPerspective node along with your image to actually get the straightened result. It doesn't touch pixels itself; it's the geometry stage.

The three inputs:

  • src (NPARRAY) - 4×2 float array of source points (e.g. the four corners of the tilted document as detected in your image).
  • dst (NPARRAY) - 4×2 float array of destination points (where those corners should land).
  • solveMethod (INT) - 0 = DECOMP_LU (fast), 1 = DECOMP_SVD (more stable for near-degenerate point sets).

The awkward part, same as its twin: you have to supply those point arrays yourself. There's no click-the-corners widget - you're wiring coordinates in from an upstream node or constructing them manually, and they need to be float32 (4, 2). If your goal is "photograph of a rectangle becomes a front-on rectangle," this is the precise, deterministic tool, and it beats burning a diffusion pass on a job a matrix multiplication does in a millisecond. For more than four correspondences with outliers, use findHomography instead.

Install

Standard for the pack: ComfyUI Manager, search opencv-comfyui (display "OpenCV"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python

Restart, no models.

Usual gotchas: images are NPARRAY (batch size 1) bridged through Image2Nparray/Nparrays2Image; a point-array shape mismatch throws an OpenCV assertion; and since this is a duplicate node, standardize on one variant and don't go looking for a difference - there isn't one.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY
solveMethodINT

Outputs (1)

NameTypeDescription
nparrayNPARRAY