OpenCV line_0
Draw an annotation line without touching a single pixel of your workflow
- img
- nparray
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
NPARRAYimage. - thickness - line width in pixels.
1or2for a hairline, more for a fat marker.-1would fill a shape (that's for the shape-drawing functions, not really this one). - lineType -
16is anti-aliased (LINE_AA),8is plain 8-connected,4is 4-connected. Use16unless 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 withImageFromBatch(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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| img | NPARRAY | — | |
| pt1 | STRING | — | |
| pt2 | STRING | — | |
| color | STRING | — | |
| thickness | INT | — | |
| lineType | INT | — | |
| shift | INT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |