Minimum Rectangle
This function block calculates and draws the minimum enclosing rectangle around a provided contour. It is useful to quickly get the bounding box, center position and size of a detected shape for further processing or visualization.
π₯ Inputs
Image AnyThe image used as background for visualization.ContourThe shape/contour to be enclosed by the minimum rectangle.
π€ Outputs
ImageThe image with the bounding rectangle drawn.CenterThe center position of the rectangle (x, y).WidthThe rectangle width in pixels.HeightThe rectangle height in pixels.RectangleThe rectangle shape data representing the enclosing box.
πΉοΈ Controls
This block has no additional user-facing controls.
π¨ Features
Draws a clear bounding rectangle around the supplied contour for immediate visual feedback.
Returns both geometric measurements (center, width, height) and a rectangle shape that can be fed into other blocks.
Works with any contour-like shape produced by contour detection or shape analysis blocks.
π Usage Instructions
Provide a detected contour to the
Contourinput (for example, from a contour detection block).Provide the source image to the
Image Anyinput so the rectangle can be drawn on top of it.Use the outputs for visualization, measurement, downstream ROI extraction or logic decisions.
π Evaluation
When executed, the block computes the axis-aligned bounding rectangle for the input contour, overlays this rectangle on the provided image, and outputs the annotated image plus the rectangle center, width, height and rectangle data.
π‘ Tips and Tricks
To obtain contours to feed into this block, use the
Find Contourblock.For a simplified contour with fewer vertices before bounding, use
Approximate Contour.To crop the region inside the rectangle for further analysis, combine this block with
Get ROIorContour to Image.Visualize or emphasize results by piping the output image into
Draw RectangleorDraw Result On Image.If you need a tighter or rotated fit, compare results with
Minimum Rotated Rectangle,Minimum Ellipse, orMinimum Circle.For shape validation or filtering, consider
Hull Convexbefore measuring, or useMeasure Object Distanceto compare positions between multiple detected objects.
π οΈ Troubleshooting
No rectangle appears: ensure a valid contour is provided (use
Find Contouror confirm the contour source block produced results).Unexpected rectangle size: verify the contour coordinates are in the same image coordinate system and that the provided image matches the contour source.
Noisy contours: apply preprocessing such as
Blur,Image Threshold, or morphological operations to clean the contour before passing it to this block.
Last updated
Was this helpful?