OpenCV approxPolyN_1
The identical twin of the N-sided polygon fitter
- curve
- approxCurve
- nparray
approxPolyN_1 is approxPolyN_0 wearing a different badge. This pack auto-generates a node for every overload OpenCV's type stubs declare, and cv2.approxPolyN is declared twice - once with MatLike and once with UMat - so you get two identical wrappers. Same inputs, same call, same output. Use whichever you clicked first.
Since you're here, a quick recap of what the node actually does, because it's a good one: it fits an exactly-N-sided polygon to a contour. Whereas approxPolyDP simplifies until it hits an epsilon and takes whatever corner count comes out, approxPolyN holds the side count fixed and fits the polygon to the curve as tightly as it can.
The inputs
- curve - the contour as an
NPARRAYof points (N×1×2 or N×2). - nsides - the exact number of sides you want. This is the input that makes the node worth having.
- epsilon_percentage - fit tolerance in percent (OpenCV's default is 5.0). Higher = looser fit.
- ensure_convex -
Trueforces a convex result; handy for hardware/frame fitting, off by default. - approxCurve (optional) - out-parameter; leave unwired.
- Output: one nparray of fitted polygon points.
The catch everyone hits
This is newer OpenCV territory. cv2.approxPolyN only landed in OpenCV 4.10, so if your install is older you'll get AttributeError: module 'cv2' has no attribute 'approxPolyN' the moment the node executes. Update with pip install -U opencv-python-contrib and you're fine.
Also remember the pack rule: the output is a point array, not an image. Feed it to Nparrays2Image and you'll get the pack's signature 'NoneType' object has no attribute 'shape' error - the converter assumes an image, and this isn't one. Points belong in geometry consumers, or get drawn back onto a canvas first.
Install
Same as every node in opencv-comfyui:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install -U opencv-python-contrib
or install via ComfyUI Manager by searching "opencv-comfyui", then restart. No models, no extra weights - just OpenCV, numpy, and torch, which the pack's requirements list.
One light note before you go: this whole pack is auto-generated and rough around the edges, and the _0/_1 twins are the least of its quirks. If you've already read approxPolyN_0, you know everything this page knows. If you haven't, go read that one for the mechanism and the epsilon/convexity tuning - this page is just the duplicate the generator left behind.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| curve | NPARRAY | — | |
| nsides | INT | — | |
| epsilon_percentage | FLOAT | — | |
| ensure_convex | BOOLEAN | — | |
| approxCurveopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |