Nodes/opencv-comfyui/OpenCV boundingRect_0
ComfyUI Node

OpenCV boundingRect_0

Get the tight rectangle around any point set

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV boundingRect_0
  • array
  • literal

Give OpenCV boundingRect_0 a pile of 2D points and it hands you back the tightest axis-aligned rectangle that contains them all - x, y, width, height. It's the geometry workhorse of object detection: every face detector, every contour analysis, every "where is the thing" question in classical CV ends with a bounding box. In a ComfyUI workflow it's the bridge between "I have points" (detected corners, optical-flow tracks, the output of boxPoints) and "I have a region" - which is what a crop, a mask, or a detail pass actually wants.

The post-processing and detailing layer this fits into is full of bbox logic - the KB's detailing doc notes that a rectangle patch is the crudest mask shape (segmentation polygons beat it for seams), but a bbox is still where every detection starts. If you're doing deterministic CV analysis rather than asking a model, this node is the cv2.boundingRect primitive sitting on your graph.

Inputs and output

  • array - one NPARRAY in: a set of points, shaped (N, 2) as float, e.g. the 4×2 corner output of boxPoints, or a list of feature points from a tracking step. Note it wants a point set, not a binary mask - if you have a mask you're thinking of contours, which is a different node.

Output: here's the pack's quirk - the result is returned as a literal STRING like (10, 20, 300, 400), because the generator had no widget type for OpenCV's Rect and serialized composite types as text. You won't plug that straight into a crop node's numeric fields; you'll read the four numbers out of the string and type them into whatever node does the cropping. It's ugly. It's the stated trade-off of an auto-generated pack - the author's own README calls these composite types "ugly" and punts on widget support.

  • boundingRect_1 - the identical overload. No behavioral difference.

Install and gotchas

ComfyUI Manager → opencv-comfyui, or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. Needs opencv-contrib-python.

Realistic use: wire in the 4×2 points from boxPoints_0 (the rotated-rect corners) and you get the axis-aligned bounds of a rotated box - the classic way to turn an oriented rectangle into something a crop node can use. The output-as-string thing is the one real friction; don't expect to chain it into a node that wants BOUNDING_BOX typed input, because it won't convert automatically. If your need is "I have a mask, give me the box around it," you're better off with a mask→bbox utility from a node suite that speaks Comfy's native types - this node speaks OpenCV's, and it expects you to read the result like a human.

Categoryimage/OpenCV

Inputs (1)

NameTypeDefaultDescription
arrayNPARRAY

Outputs (1)

NameTypeDescription
literalSTRING