Nodes/opencv-comfyui/OpenCV arcLength_0
ComfyUI Node

OpenCV arcLength_0

The perimeter node that every contour recipe starts with

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV arcLength_0
  • curve
  • float
closed

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 NPARRAY of points (N×1×2 or N×2). Same shape you'd hand to approxPolyDP or contourArea.
  • closed - whether to measure a closed loop. True adds the segment from the last point back to the first; False measures the open polyline. For contours pulled out of a mask, it's True.
  • 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:

  1. Image2NparraycvtColor (code 6, BGR2GRAY) → findContours gives you a curve.
  2. arcLength_0 measures it.
  3. Multiply by 0.01 (a math/primitive node or another pack's float multiply).
  4. Feed that into approxPolyDP_0 as 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.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
curveNPARRAY
closedBOOLEAN

Outputs (1)

NameTypeDescription
floatFLOAT