Nodes/opencv-comfyui/OpenCV clipLine_0
ComfyUI Node

OpenCV clipLine_0

Clip a line to a rectangle and keep only the part that fits — pure geometry

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV clipLine_0
    • bool
    • literal_1
    • literal_2
    imgRect
    pt1
    pt2

    clipLine is a pure-geometry helper: you give it a rectangle and two points defining a line segment, and it clips the segment to the rectangle, returning the parts that survive. If the line misses the rectangle entirely, you get False; if it crosses or lands inside, you get True plus the two clipped endpoints. No images involved at all - it's the OpenCV equivalent of "intersect this line with this box."

    When would this be useful in ComfyUI? Whenever your workflow computes or generates lines and you need to keep them inside a frame boundary. The classic case: you have some detector or animation producing line segments between points - say, motion paths, Hough-detected lines, or procedural connectors - and you want to draw them but only the on-screen portion. Clip first, draw the clipped result, and you never paint outside the canvas. It's also a building block for UI-ish overlays: figure out whether a line crosses a region of interest, and where.

    Inputs and outputs. All three inputs are STRING literals (this node has no image input at all), parsed with literal_eval:

    • imgRect - the clipping rectangle, (x, y, w, h), e.g. (0, 0, 1024, 1024)
    • pt1 / pt2 - the line's two endpoints, (x, y) tuples

    Outputs: bool (did any part of the segment survive?), then literal_1 and literal_2 - the clipped endpoints, returned as string literals you'd feed back into a drawing node.

    The pack's quirk, front and center. Because everything is a string literal, the syntax discipline matters more here than in most nodes: (0, 0, 1024, 1024) is fine, but "0,0,1024,1024" without parens or any stray character will throw the README's invalid syntax (unknown, line 0). This node is also a good example of why the author calls the pack "ugly" - a function that takes three geometry objects has no image output to look at, so you're wiring raw coordinates through strings. It works, but it's not pretty, and you'll likely pair it with a drawing node to see anything.

    Install is the standard pack story - ComfyUI Manager, search "OpenCV", or:

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

    Restart after; no model files. There's no _1 twin for this one in the pack - some functions only got one generated node - but the rules are the same either way: auto-generated, literals everywhere, "expect dragons."

    Categoryimage/OpenCV

    Inputs (3)

    NameTypeDefaultDescription
    imgRectSTRING
    pt1STRING
    pt2STRING

    Outputs (3)

    NameTypeDescription
    boolBOOLEAN
    literal_1STRING
    literal_2STRING