Nodes/opencv-comfyui/OpenCV intersectConvexConvex_0
ComfyUI Node

OpenCV intersectConvexConvex_0

How much do these two polygons overlap?

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV intersectConvexConvex_0
  • p1
  • p2
  • p12
  • float
  • nparray
handleNested

OpenCV intersectConvexConvex_0 answers a geometry question: give it two convex polygons and it returns the area of their overlap and the polygon that forms that intersection. It's cv2.intersectConvexConvex wrapped, and it's the kind of node you reach for in a pipeline that's already doing contour/region math - checking whether a detected region overlaps another, measuring how much of one shape sits inside another, or gating a branch on "do these two areas touch?"

Let's be straight about where this fits in ComfyUI: it's a niche tool, and its inputs are the reason. Both polygons come in as NPARRAYs of points (N×2), and this pack can't actually produce those from an image - OpenCV's findContours isn't among the auto-generated nodes (its stub returns a Sequence type the generator skipped). So you need your point arrays from somewhere else: a scripting node, or a chain of this pack's own geometry nodes like convexHull_0 or approxPolyDP_0, which do output point nparrays. If that plumbing sounds like more trouble than the job warrants, you're probably right - this node is for people already swimming in contour data, not for threshold-first masking.

How it works

cv2.intersectConvexConvex(p1, p2, p12, handleNested) clips one convex polygon against the other (Sutherland–Hodgman style) and returns both the intersection area and the vertex list of the clipped polygon. It assumes the inputs are convex; give it concave shapes and the result is undefined. handleNested decides what counts when one polygon sits fully inside the other: with it True, a completely nested polygon's own area counts as the intersection; with it False, fully-enclosed cases report zero.

Inputs and outputs

  • p1, p2 - NPARRAYs of polygon vertices, N×2.
  • handleNested - BOOLEAN, how to treat fully-nested polygons (default True in OpenCV).
  • p12 - optional NPARRAY out-parameter for the intersection polygon; ignore it, it's returned anyway.
  • Outputs: float (intersection area) and nparray (the intersection polygon's vertices).

The float is the output to actually use in a workflow - wire it into a threshold/compare so your graph behaves differently when overlap crosses a value.

Installing

From opencv-comfyui, one install covers the whole pack:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
cd opencv-comfyui
pip install -r requirements.txt

Or ComfyUI Manager → "opencv-comfyui". No models; deps are opencv-contrib-python, numpy, torch.

Gotchas

The big one: no findContours in this pack, so there's no native "image → polygons" hop. Get your point arrays from convexHull_0, approxPolyDP_0, or an external scripting node. Also remember the convexity assumption - isContourConvex_0, also in the pack, is the honest way to check before you trust the area. And intersectConvexConvex_0 vs _1 are identical overload duplicates; pick one. Keep batch_size == 1 as always.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
p1NPARRAY
p2NPARRAY
handleNestedBOOLEAN
p12optNPARRAY

Outputs (2)

NameTypeDescription
floatFLOAT
nparrayNPARRAY