Nodes/opencv-comfyui/OpenCV minEnclosingTriangle_1
ComfyUI Node

OpenCV minEnclosingTriangle_1

The tightest triangle around your points

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV minEnclosingTriangle_1
  • points
  • triangle
  • float
  • nparray

First, the freebie: minEnclosingTriangle_1 and minEnclosingTriangle_0 are the same node. opencv-comfyui emits one node per cv2 overload, cv2.minEnclosingTriangle has two, and you got both. Nothing about the _1 is different or better. Pick it and move on.

What the function does: compute the minimum-area triangle that encloses a set of 2D points, and return its area plus its three vertices. It's the third shape in OpenCV's enclosing-family (after the rotated rectangle and the circle), and it earns its keep specifically when a point cluster is wedge-shaped - a triangular region where a rectangle would be half empty and a circle would be worse.

In a ComfyUI graph this is a specialist's tool, and it's worth saying plainly: most people never need it. The rectangle and circle nodes handle the common "bound the blob" jobs, and they're easier to reason about. Where the triangle pulls ahead: compact hull measurements - you want the smallest polygon with exactly three sides that still contains your points, and the area as a rotation-independent size metric. The vertices are also what you'd feed to the pack's polygon drawing nodes if you want the triangle drawn back over the image.

Inputs and outputs

  • points - one NPARRAY, N×2 coordinates. The pack skips contour-finding functions, so points have to come from a mask, corners, or another node pack rather than findContours.
  • triangle - optional; leave it empty. Out-parameter, same rule as dst.
  • float - the area of the minimum enclosing triangle, a real number for your math chain.
  • nparray - the triangle's three vertices. It's an array, but it is not an image. Routing it to Nparrays2Image is how you meet the pack's 'NoneType' object has no attribute 'shape' error - the README calls this out specifically: not every nparray return is a picture.

Setup

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

or ComfyUI Manager → "opencv-comfyui" → install → restart. Dependencies: opencv-contrib-python, numpy, torch. The standard conflict to watch for is Cannot import name 'guidedFilter' from 'cv2.ximgproc' when another custom node disagrees about the OpenCV install.

Bottom line: reach for this one when a wedge-shaped point cluster makes the rectangle and circle look silly. It returns a useful area float and a vertex array that's for geometry, not pictures - keep those two facts straight and there's nothing else to trip on.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
pointsNPARRAY
triangleoptNPARRAY

Outputs (2)

NameTypeDescription
floatFLOAT
nparrayNPARRAY