OpenCV arcLength_0
The perimeter node that every contour recipe starts with
- curve
- float
arcLength_0 measures the perimeter of a contour. That's the whole job, and it sounds boring until you realize it's the load-bearing measurement behind half of OpenCV's contour recipes. The canonical one: to simplify a contour with approxPolyDP, you set epsilon as a fraction of the perimeter - 0.01 * arcLength(curve, True) - so the simplification tolerance scales with the shape instead of being a magic constant that breaks on big or small objects. This node is the input to that formula.
It's part of opencv-comfyui, the auto-generated pack of OpenCV wrappers, and it's one of the pack's genuinely clean ones: two inputs, one number out, no dragons involved.
What you set
- curve - a contour as an
NPARRAYof points (N×1×2 or N×2). Same shape you'd hand toapproxPolyDPorcontourArea. - closed - whether to measure a closed loop.
Trueadds the segment from the last point back to the first;Falsemeasures the open polyline. For contours pulled out of a mask, it'sTrue. - Output: one float - the perimeter, in pixels.
That's the entire schema. There's no optional out-parameter to worry about, no literal-string inputs, no color channels to flip. If every node in this pack were this simple, the README wouldn't say "expect dragons."
How to actually use the number
The output is a FLOAT, so it wires straight into any numeric input downstream. The workflow that makes this node earn its keep:
Image2Nparray→cvtColor(code 6, BGR2GRAY) →findContoursgives you a curve.arcLength_0measures it.- Multiply by 0.01 (a math/primitive node or another pack's float multiply).
- Feed that into
approxPolyDP_0as epsilon.
Result: a clean polygon that's simplified proportionally to its own size. Big shapes get room to shed points, small shapes keep their detail - neither gets mangled by a fixed epsilon.
Where it won't help you
The output is a plain number, and that trips people up in two ways. First, don't expect an image out of it - there isn't one, which is correct. Second, if you've got it wired into something that demands an NPARRAY and you're staring at 'NoneType' object has no attribute 'shape', you've confused this pack's data types; floats and images don't mix. Read the value into a preview/primitive node or feed it to a consumer that expects a float.
Install
Everything in opencv-comfyui installs the same way. ComfyUI Manager → search "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib
Restart ComfyUI. No model downloads. The one setup trap in this pack is conflicting OpenCV versions - Cannot import name 'guidedFilter' from 'cv2.ximgproc' - and a clean reinstall in the right environment fixes it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| curve | NPARRAY | — | |
| closed | BOOLEAN | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |