Nodes/opencv-comfyui/OpenCV minAreaRect_1
ComfyUI Node

OpenCV minAreaRect_1

The rotated-bounding-box twin

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV minAreaRect_1
  • points
  • literal

minAreaRect_1 is minAreaRect_0 in a slightly different hat: same function, same inputs, same string output, just the other cv2 overload. The pack generated one node per type-stub overload, so you have two identical entries. Stop hunting for a difference and pick this one because it's the one you're on.

What it does, concretely: given a set of 2D points, it returns the minimum-area rotated rectangle that contains them - ((center_x, center_y), (width, height), angle). Unlike an axis-aligned bounding box, the result can be tilted, which is exactly what makes it useful: the angle tells you how the object is oriented, and the tight box tells you its true size without the wasted space of an upright crop.

That's the engine behind every "find the tilted card/poster/part and straighten it" pipeline in classical CV, and it ports cleanly to a diffusion workflow. Detect or segment something, pull its points, measure the tilt here, then rotate-and-crop straight with the pack's getRotationMatrix2D / warpAffine nodes. It's a deterministic, millisecond operation - exactly the kind of thing to reach for instead of re-rolling a generation because a subject is crooked.

The one input, the one output

  • points - a single NPARRAY: N×2 coordinates of the points you're bounding. In stock OpenCV these usually come from findContours, but this pack deliberately skipped contour-finding functions (their return types didn't survive the auto-generation filter), so your points have to arrive from another source - mask coordinates, detected corners, or a nparray built by another node pack.
  • literal - the output, and it's a STRING. The RotatedRect repr, like ((241.5, 173.2), (87.0, 45.0), -27.4). Center, size, angle-in-degrees, as text.

That's the gotcha that defines how you use this node: the measurement comes out as a printable string, not as arrays you can math on directly. Read it in the queue output, route it to a string-eating node, or parse it in whatever logic layer your workflow has. Don't send it toward Nparrays2Image - it's not an image, and treating it like one triggers the pack's "not every return type is an image" failure family.

Setup

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

or ComfyUI Manager → "opencv-comfyui" → install → restart (opencv-contrib-python, numpy, torch). The usual pack failures apply: OpenCV version clashes from other custom nodes (Cannot import name 'guidedFilter' from 'cv2.ximgproc' is the signature), and treating non-image outputs as images. Handle those two and this becomes a quietly reliable measurement node for the "straighten the tilted thing" family of workflows.

Categoryimage/OpenCV

Inputs (1)

NameTypeDefaultDescription
pointsNPARRAY

Outputs (1)

NameTypeDescription
literalSTRING