OpenCV polarToCart_0
Converting flow magnitude and angle with OpenCV polarToCart_0
- magnitude
- angle
- x
- y
- nparray_0
- nparray_1
polarToCart_0 is a coordinate-conversion node with a very specific appetite: you give it a per-pixel magnitude array and a per-pixel angle array, and it gives you back the equivalent Cartesian components x and y. It's the math x = magnitude·cos(angle), y = magnitude·sin(angle) applied to every pixel of your arrays.
It's one of ~635 nodes that opencv-comfyui auto-generated straight from OpenCV's Python type stubs. No models, no API, no weights - the only "dependency" is OpenCV itself, which the author (Gerold Meisinger, who launched the pack on r/comfyui in April 2025) made the pack's one real install requirement. His README preface is worth taking seriously: the nodes are thin auto-generated wrappers and "ugly and complex to use. Expect dragons!" polarToCart_0 is mid-dragon - the mechanism is clean, but it's easy to misuse because it's a math node that looks like an image node.
How it works
The inputs are three required values:
magnitude(NPARRAY) - per-pixel lengths.angle(NPARRAY) - per-pixel directions.angleInDegrees(BOOLEAN) - what units your angle array is in.Truemeans degrees,Falsemeans radians. Get this wrong and every result is garbage in a way that's hard to spot.
Both arrays must be the same size, and cv2.polarToCart works on single- or multi-channel float arrays. Feed it uint8 and it'll refuse.
The outputs are nparray_0 (the x components) and nparray_1 (the y components). Note the _0/_1 suffix - the pack's generator renames duplicate outputs so you can tell which socket is which. Also note the optional x and y inputs: those are OpenCV out-parameters, and the README's advice applies - leave optional out-params unconnected.
Why you'd ever reach for this
The realistic ComfyUI use is optical-flow work. Some flow pipelines hand you magnitude and direction rather than (dx, dy) displacement fields (the pair function cartToPolar in this pack produces that form). To go from "how far and which way" to "horizontal shift and vertical shift" - which is what warping and displacement-map nodes want - you run polarToCart_0. It's also the natural inverse step after you've visualized a flow as hue (angle) and brightness (magnitude) and want the actual vectors back.
Honest take: it's niche. If you aren't doing flow math, you'll never touch it. But when you need it, there is no pleasant alternative - this is the function.
Install and the usual pack gotchas
Install via ComfyUI Manager (search "opencv-comfyui") or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart, and ensure OpenCV is installed:
pip install opencv-contrib-python
You operate on NPARRAYs: IMAGE → Image2Nparray → polarToCart_0 → Nparrays2Image → IMAGE. Batch size 1 only - use ImageFromBatch (length 1) if you hit the batch error. And a reminder specific to this node: the outputs are component arrays, not displayable images. If you wire them straight into Nparrays2Image you'll get a blob or the "NoneType object has no attribute shape" error the README mentions - that error usually means "this return value isn't an image."
Set angleInDegrees to match your angle source, keep x/y optional inputs empty, and this is a solid little vector-arithmetic node.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| magnitude | NPARRAY | — | |
| angle | NPARRAY | — | |
| angleInDegrees | BOOLEAN | — | |
| xopt | NPARRAY | — | |
| yopt | NPARRAY | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| nparray_0 | NPARRAY | — |
| nparray_1 | NPARRAY | — |