Nodes/opencv-comfyui/OpenCV line_0
ComfyUI Node

OpenCV line_0

Draw an annotation line without touching a single pixel of your workflow

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV line_0
  • img
  • nparray
pt1
pt2
color
thickness
lineType
shift

OpenCV line_0 wraps cv2.line, which draws a straight line onto an image. In a generative workflow that sounds like a toy, but it's the building block for every overlay and annotation job: guidelines, before/after markers, bounding-box outlines, HUD-style callouts. You feed it an image, tell it where the line goes, and get the same image back with a line baked in. That's the whole trick - and the whole pack in miniature.

The part that will annoy you first

This node has two quirks that come straight from the auto-generated design of opencv-comfyui, and both are worth knowing before you wire anything up.

First, it works on NPARRAY, not ComfyUI IMAGE. In: Image2Nparray. Out: Nparrays2Image. You'll get used to this pairing - every node in the pack needs it.

Second, the "composite" inputs - the points and the color - are strings parsed as Python literals. So to draw a line from (10, 20) to (300, 200), you type:

  • pt1 = [10, 20]
  • pt2 = [300, 200]
  • color = [255, 0, 0]

Brackets or parens both work ((10, 20) is fine too). Get the syntax wrong and you'll get the pack's signature error: invalid syntax (<unknown>, line 0). And note the color is in BGR, not RGB - because the nparray conversion flips channels. [255, 0, 0] is blue, not red. Every OpenCV user has been betrayed by this at least once.

The rest of the inputs

  • img - your NPARRAY image.
  • thickness - line width in pixels. 1 or 2 for a hairline, more for a fat marker. -1 would fill a shape (that's for the shape-drawing functions, not really this one).
  • lineType - 16 is anti-aliased (LINE_AA), 8 is plain 8-connected, 4 is 4-connected. Use 16 unless you want crunchy pixels for some aesthetic reason.
  • shift - fractional-pixel precision via bit-shifting. Leave 0; nobody in a ComfyUI workflow needs sub-pixel line start points.

Output is a single nparray - the image with the line drawn. Pipe it to Nparrays2Image and preview, or keep the chain going into more OpenCV nodes.

Install

ComfyUI Manager, search "opencv", install opencv-comfyui. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python

Restart, done. No model files. The pack's real dependency list is just opencv-contrib-python, numpy, torch.

Troubleshooting

  • invalid syntax - one of your string literals is malformed. Check for commas, brackets, and stray spaces.
  • Batch error - the pack only handles batch_size==1. Slice with ImageFromBatch (length=1).
  • The line is invisible or the wrong color - check BGR ordering and that you're drawing on a converted nparray, not the raw tensor.

Honest take: if all you want is a bbox overlay, a purpose-built annotation node (plenty of packs ship them) will be nicer - proper int inputs instead of string literals. This node is for when you're already inside the OpenCV pipeline and want to stay there.

Categoryimage/OpenCV

Inputs (7)

NameTypeDefaultDescription
imgNPARRAY
pt1STRING
pt2STRING
colorSTRING
thicknessINT
lineTypeINT
shiftINT

Outputs (1)

NameTypeDescription
nparrayNPARRAY