OpenCV approxPolyDP_1
ApproxPolyDP_1 — the identical twin of the polygon simplifier
- curve
- approxCurve
- nparray
Short version: approxPolyDP_1 does exactly what approxPolyDP_0 does, and you can use either one. The _0/_1 split exists because OpenCV's type stubs declare the same function twice - once for MatLike arrays and once for UMat - and the auto-generator in this pack numbered every overload it found rather than deduplicating them. Both wrappers call cv2.approxPolyDP with identical arguments. Pick one and forget the sibling exists.
That said, this is one of the genuinely useful nodes in opencv-comfyui, so it's worth knowing what it's for: it simplifies a noisy contour into a clean polygon using the Douglas-Peucker algorithm. Feed it a contour that traces every wobble of a mask edge and it returns a handful of corner points instead.
What you're setting
- curve - the contour as an
NPARRAYof points (N×1×2 or N×2, ideally float). - epsilon - the tolerance: the max allowed distance between the original curve and the simplified one. The standard starting point is
0.01 * arcLength(curve, True), which scales with the shape's size. - closed -
Truefor closed loops (contours from masks),Falsefor open polylines. - approxCurve (optional) - the out-parameter; leave it unwired.
- Output: one nparray of simplified polygon points.
The honest gotcha
Like everything in this pack, the output is a point array, not a picture. Send it to Nparrays2Image and you'll get the README's 'NoneType' object has no attribute 'shape' error, because OpenCV returns raw points and the converter assumes an image. Points belong in point-consuming nodes, or you redraw them onto a canvas with a drawing node before you can look at them.
Install and plumbing
The node ships in opencv-comfyui - install via ComfyUI Manager (search "opencv-comfyui") or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib
Then restart. No model files, no downloads beyond OpenCV itself. And remember the pack-wide rule: this node speaks NPARRAY, so images come in through Image2Nparray and go out through Nparrays2Image - with a cvtColor (code 6, BGR2GRAY) in the middle if the function demands grayscale.
If you came here from a search for "approxPolyDP" and you're new to the pack, use this as your cheat sheet: _0 and _1 are the same node, and the only knob you'll actually tune is epsilon. Everything else in this pack is more hostile than this - enjoy the easy one.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| curve | NPARRAY | — | |
| epsilon | FLOAT | — | |
| closed | BOOLEAN | — | |
| approxCurveopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |