OpenCV perspectiveTransform_0
Warping points through a homography (not pixels — points)
- src
- m
- dst
- nparray
First, the thing everyone gets wrong: perspectiveTransform does not warp an image. It warps points. You give it an array of coordinates and a transformation matrix, and it returns where those coordinates land after the perspective transform. The node that actually resamples pixels is warpPerspective (also in this pack); perspectiveTransform is the coordinate-mapping half of the job. They're partners - if you're doing document rectification, homography-based alignment, or any "map point A to point B" geometry, you'll use them together.
The classic pipeline: take four corner correspondences (the corners of a skewed document vs. where they should be), feed them to getPerspectiveTransform (also in this pack) to compute a 3x3 homography matrix m, then use perspectiveTransform to push any other coordinates through that same matrix - say, to remap a detection bbox from the skewed view into the rectified view. Points in, transformed points out.
How it works
cv2.perspectiveTransform(src, m) applies the homography per point: it computes M · (x, y, 1) and normalizes by the homogeneous W component, which is exactly what makes this perspective rather than affine. src must be a floating-point array - (N, 2) for 2D points or (N, 3) for 3D points (a single point also works) - and m is the 3x3 (or 4x4) transformation matrix. The output has the same shape as src; that's a useful invariant for debugging.
The inputs that matter
src(NPARRAY) - the points to transform, float32, one point per row.m(NPARRAY) - the 3x3 homography (or 4x4 matrix). Get it fromgetPerspectiveTransform_0,findHomography(also in this pack), orcv2.getRotationMatrix2D-style sources.dst(NPARRAY, optional) - OpenCV out-parameter; ignore it.
Output: nparray - transformed points, same shape as src.
How to install it
Pack-level install, once:
- ComfyUI Manager → search opencv-comfyui → Install, restart ComfyUI.
- Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
Requires opencv-contrib-python (README's pip install opencv-python-contrib, same wheel). No models.
Common issues & troubleshooting
srcmust be floating point. Integer point arrays throw an assertion error - OpenCV demandsCV_32F/CV_64Fhere. If you're converting from an INT list, cast to float first.- Matrix shape matters.
mmust be 3x3 (2D points) or 4x4 (3D points). A wrong-size matrix is the usual(-215:Assertion failed)source. - It's not warpPerspective. If your output looks like "nothing happened to the image," you're feeding it pixels instead of points. Want the warped image? Use
warpPerspective_0with the samem. - Batch rule:
batch_size==1only - the pack's standard constraint.
This is one of the pack's genuinely useful geometry nodes - it just rewards reading the docs first.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| m | NPARRAY | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |