OpenCV minEnclosingTriangle_0
The triangle that squeezes your points
- points
- triangle
- float
- nparray
minEnclosingTriangle_0 is the point-set fetishist's node: it finds the minimum-area triangle that contains a given set of points, and returns the triangle's area and its three vertices. It's the third entry in OpenCV's family of enclosing shapes - after the rotated rectangle (minAreaRect) and the circle (minEnclosingCircle) - and it exists for the times when a rectangle is wasteful and a circle is worse, but a triangle hugs the points just right.
Let's be honest about its place in a diffusion workflow: this is a niche of a niche. The realistic use is measurement and hull analysis on point clouds or contours - "how tightly can three points bound this cluster, and what's the area of that bound?" The area output is the genuinely useful bit: it's a compact size metric that adapts to orientation, useful if you're comparing regions across frames or images. The three vertices are what you'd feed to the pack's polygon-drawing nodes (fillConvexPoly / polylines-adjacent) if you wanted to visualize the triangle back on the image.
It's part of opencv-comfyui's auto-generated ~635-node surface, and yes - _0 and _1 are the same node, one per cv2 overload. Identical behavior, pick either.
Inputs and outputs
- points - one
NPARRAY: N×2 point coordinates. As with the pack's other geometry nodes, vanilla OpenCV would normally feed you a contour here, but this pack skips contour-finding, so your points need another source. - triangle - optional, and skip it. It's an out-parameter in the underlying call, same rule as
dstelsewhere. - Output float - the area of the minimum enclosing triangle, a real number you can wire into arithmetic.
- Output nparray - the triangle's three vertices. It's an array, but it is not an image - this is exactly the case the README warns about ("not every return type of nparray is actually an image"). Don't route it to
Nparrays2Image; treat it as a point set for geometry downstream.
Setup
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
or ComfyUI Manager → "opencv-comfyui" → install → restart. Needs opencv-contrib-python, numpy, torch; the usual version-conflict tell is Cannot import name 'guidedFilter' from 'cv2.ximgproc'.
The straight talk: unless you're doing real point-set geometry, minAreaRect and minEnclosingCircle cover 95% of the "bound the thing" jobs. This node is for the remaining 5% where a triangle genuinely fits - a wedge-shaped region, a triangulated marker, a compressed hull. If that's your problem, now you know the vertices are an nparray (fine for geometry) and the area is a float (fine for math), and the only trap is treating the vertex array as a picture.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| points | NPARRAY | — | |
| triangleopt | NPARRAY | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |
| nparray | NPARRAY | — |