OpenCV warpPerspective_1
WarpPerspective, take two — the overloads are twins, so just use one
- src
- M
- dst
- nparray
This is the _1 overload of cv2.warpPerspective, and the first thing to know is that it's interchangeable with warpPerspective_0. Same schema, same 3×3 homography math, same output. The pack auto-generates one node per OpenCV overload and for this function they collapsed into identical wrappers. Your only real decision is which one happens to be in the node menu.
The underlying function is one of the pack's most useful. It applies a perspective transform - the "photo taken at an angle of a flat surface" correction that affine warping physically can't do. You give it a 3×3 homography M, usually computed by the pack's getPerspectiveTransform_0 from four corresponding point pairs, and it re-maps the image so the photographed plane lies flat. Straighten a tilted screen capture, flatten a whiteboard photo, or generate a sign head-on and warp it onto a surface in a composite. Deterministic, millisecond-cheap, no model involved - the ideal post-process.
Inputs and outputs
src-NPARRAYimage, viaImage2Nparray.M- the 3×3 homography asNPARRAY, out ofgetPerspectiveTransform_0.dsize- output size as a literal,(1280, 960).flags- interpolation:1linear,0nearest,2cubic,4Lanczos.borderMode/borderValue- edge fill:0constant (withborderValueas a literal like(255, 255, 255)),1replicate.
Optional dst - skip it. Output: one nparray, converted back with Nparrays2Image.
Installing
Pack-standard, both variants:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
or ComfyUI Manager, search "opencv-comfyui", install, restart. Dependencies: opencv-contrib-python, numpy, torch.
The traps, briefly
The four point pairs feeding getPerspectiveTransform_0 must be a consistent quad in the same order in both sets, or you get a folded mess. Literal inputs (dsize, borderValue) must be real Python tuples - invalid syntax (<unknown>, line 0) means you wrote them wrong. And keep borderMode in mind, because a perspective warp opens up big empty triangles that default to black. Fix that with borderMode=1 or a borderValue that matches the scene. Same guidance as warpPerspective_0 - because, functionally, you're using the same node.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| M | NPARRAY | — | |
| dsize | STRING | — | |
| flags | INT | — | |
| borderMode | INT | — | |
| borderValue | STRING | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |