Nodes/comfyui_bmad_nodes/Draw Contour(s)
ComfyUI Node Runs on cloud

Draw Contour(s)

See the contours you found, on top of the image

By bmad4ever·Created 3 years ago·Updated 9 months ago· 70
Draw Contour(s)
  • image
  • contours
  • color
  • IMAGE
index_to_draw-1
thickness5

When you run Contours on a mask, you can't see what it found - contours are just coordinate lists, invisible until something draws them. Draw Contour(s) is the visualization step: it takes the CV_CONTOURS output and draws them directly onto your image, in any color you pick, so you can actually check that your segmentation found the right shapes before you commit to masking with them.

It's also genuinely useful for debugging a whole CV chain. "Did Filter Contour pick the right blob?" One Draw Contour(s) node answers it visually.

How it works

A wrapper around OpenCV's drawContours:

  • image - the canvas. Usually the original image you're analyzing, so the drawn contours appear in context.
  • contours - the CV_CONTOURS output from Contours.
  • index_to_draw - which contour to draw. -1 (default) draws all of them. Set 0, 1, 2, ... to draw just that one. This is how you inspect a single shape.
  • thickness - line width in pixels, 1–32. Set -1 to fill the contour instead of outlining it.
  • color - a COLOR, from the pack's Color (RGB) node.

Output: the image with contours drawn on it, as an IMAGE.

Reading the settings

The two values that do most of the work are index_to_draw and thickness, and they combine surprisingly well:

  • index_to_draw = -1, thin thickness → outline every shape (the "show me everything" mode).
  • index_to_draw = 3, fill → see exactly what shape #3 occupies.
  • index_to_draw = -1, thickness -1 → flood-fill every contour, which is a quick way to turn the whole contour set into a single filled canvas (this is close to what Contour To Mask does for one contour).

Contours are ordered by OpenCV, which depends on your retrieval mode - with RETR_EXTERNAL you typically get outermost shapes first. So "which index is the car" usually means a quick eyeball test: draw all, find the index, then draw just that one.

Gotchas

  • If the drawn outlines look tiny or missing, the contour coordinates probably came from a different-size image than the canvas. Same source-size rule as Contour To Mask: keep the Contours input image and the Draw Contour(s) canvas the same dimensions.
  • Color is required. Don't forget to wire a Color (RGB) node, or the socket stays empty and the node warns.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt

or install "comfyui_bmad_nodes" via ComfyUI Manager and restart. Pure OpenCV drawing - no models, no downloads beyond the pack's shared requirements. Cheap to add to any contour workflow, and it'll save you a lot of "why is my mask wrong" debugging.

CategoryBmad/CV/Contour

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
contoursCV_CONTOURS
index_to_drawINT-1-1–1000
thicknessINT5-1–32
colorCOLOR

Outputs (1)

NameTypeDescription
IMAGEIMAGE