Nodes/opencv-comfyui/OpenCV fillConvexPoly_0
ComfyUI Node

OpenCV fillConvexPoly_0

FillConvexPoly_0 and the literal-string color gotcha

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV fillConvexPoly_0
  • img
  • points
  • nparray
color
lineType
shift

Sometimes you don't want to filter an image, you want to draw on it - block out a region, stamp a censor bar, build a mask, or just mark where something is so a downstream node can find it. That's what fillConvexPoly_0 is: it takes an image, fills a convex polygon into it, and hands back the result. It wraps cv2.fillConvexPoly, the OpenCV drawing primitive that fills any shape that's convex (no dents, no self-intersections - think rounded blob rather than star).

It's the drawing node you reach for when you want a solid, filled region rather than an outline. Fill a region solid black and you've got a mask. Fill it solid white on a black canvas and you've got a cutout. Fill it with a flat color and you've got a "censor the face/plate/watermark" pass - a deterministic, millisecond drawing operation instead of re-rolling a generation and hoping the model puts a blur where you asked.

The inputs that matter

  • img (NPARRAY) - the canvas. BGR, 0–255, exactly what Image2Nparray produces.
  • points (NPARRAY) - the polygon's vertices. This is a numpy array of (x, y) coordinates, and here's the friction: you have to get that array from somewhere. The pack ships sibling nodes that produce exactly this shape - findChessboardCorners outputs corner points, approxPolyDP simplifies a contour into a polygon, convexHull wraps a point set. Feed one of those into points and you have a real contour-drawing pipeline.
  • color (STRING) - and here's the gotcha. The generator represents OpenCV's Scalar type as a Python literal string that gets ast.literal_eval'd. So you type the color as a tuple literal in the text field: (0, 0, 255) for red. Remember this is BGR, so (0, 0, 255) is red, (255, 0, 0) is blue.
  • lineType (INT) - the rasterization style: 8 (LINE_8, default) or 4; 16 gives antialiasing.
  • shift (INT) - subpixel precision bit-shift; leave it at 0.

Output is a single nparray: the image with the polygon painted in, same size. Back through Nparrays2Image to get a Comfy IMAGE.

Installing it

One of ~600 nodes in geroldmeisinger/opencv-comfyui - one install gets them all. ComfyUI Manager → search opencv-comfyui, or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

then restart. Needs opencv-contrib-python, numpy, torch. If startup throws Cannot import name 'guidedFilter' from 'cv2.ximgproc', you have conflicting OpenCV installs - consolidate to one.

Pack rules: nparrays in BGR 0–255 in/out (Image2Nparray / Nparrays2Image), batch size 1 only.

Where people get burned

The color literal. It's easy to type (255, 0, 0) expecting red and get blue, because you're thinking RGB and the array is BGR. And if you type 255, 0, 0 without the parentheses, the ast parser throws invalid syntax (<unknown>, line 0) - the README's exact documented error. Get into the habit of writing colors as full parenthesized tuples, BGR, and this node behaves. For the version with antialiased edges, prefer this _0 overload's LINE_AA=16; the _1 twin is identical in the UI, so just use whichever you found.

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
imgNPARRAY
pointsNPARRAY
colorSTRING
lineTypeINT
shiftINT

Outputs (1)

NameTypeDescription
nparrayNPARRAY