Find Contours π¦
Trace the outlines of everything in a binary image
- Np_bins
- contours
- hierarchy
Contour detection is the workhorse of classical computer vision: take a binary image, trace the boundary of every connected region, and get back vector outlines you can measure, filter, or draw. This node wraps OpenCV's findContours and hands you both the contour list and the topology hierarchy. If you're doing plan analysis, floor-plan vectorization, or object measurement in ComfyUI, this is where the geometry gets extracted.
The inputs
Np_bins: a binary NPARRAY - non-zero pixels are foreground. The tooltip names the producers: compare, threshold, inRange, Canny, etc. from this pack's OpenCV set. Garbage in, garbage out: a noisy threshold means a thousand spurious contours.mode(defaultRETR_CCOMP): how contours are organized.RETR_EXTERNAL: only the outermost contours - no holes. Simplest, often all you want.RETR_LIST: all contours, no hierarchy.RETR_CCOMP: two-level hierarchy (outer + holes). The default, and the middle ground.RETR_TREE: full nesting tree. Most information, most confusing.
method(defaultCHAIN_APPROX_SIMPLE): how tightly to store each contour.SIMPLEcompresses straight segments to their endpoints (smaller, sufficient for most drawing/measuring);NONEkeeps every boundary pixel; the twoTC89options run a compression algorithm.
The outputs
contours(CV_CONTOURS): each contour is a vector of points. This is exactly what the pack's Draw Contours node eats - the pairing is point-and-shoot.hierarchy(CV_HIERARCHY): same length as contours; each entry is[next, prev, first child, parent]describing the nesting. Most beginners can ignore it; the moment you want "only the contours inside other contours," this is the map.
The constraint
This node is single-batch only (SINGULAR_ONLY). A batch of images raises a ValueError. The pack is full of these single-image OpenCV nodes - batch, then process one at a time.
Install
ComfyUI Manager β search ComfyUI-ArchiGraph, or:
cd ComfyUI/custom_nodes
git clone https://github.com/vincentfs/ComfyUI-ArchiGraph
Restart and run the pack's install script once. OpenCV is the real dependency; no models to download.
Gotchas
- It wants binary input. Feeding a raw color photo "works" (it converts to gray) but the contours will be noise.
RETR_EXTERNAL+SIMPLEis the beginner-friendly combo for "outlines of the main shapes."TREEis for when you're debugging nested structures and are prepared to think.- Pair it with Connected Components With Stats when you care about areas - contours give you geometry, stats give you bounding boxes and sizes.
For classical shape extraction, this is the pack's centerpiece OpenCV node. Feed it a clean binary image and you get the geometry back.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| Np_bins | NPARRAY | Binary image. Non-zero pixels are treated as 1's. You can use compare(), threshold(), inRange(), Canny() etc. to create a binary image. | |
| mode | COMBO | RETR_CCOMP | Contour retrieval mode |
| method | COMBO | CHAIN_APPROX_SIMPLE | Contour approximation method |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| contours | CV_CONTOURS | β |
| hierarchy | CV_HIERARCHY | β |