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 Any The image used as background for visualization.

  • Contour The shape/contour to be enclosed by the minimum rectangle.

πŸ“€ Outputs

  • Image The image with the bounding rectangle drawn.

  • Center The center position of the rectangle (x, y).

  • Width The rectangle width in pixels.

  • Height The rectangle height in pixels.

  • Rectangle The 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

  1. Provide a detected contour to the Contour input (for example, from a contour detection block).

  2. Provide the source image to the Image Any input so the rectangle can be drawn on top of it.

  3. 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 Contour block.

  • 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 ROI or Contour to Image.

  • Visualize or emphasize results by piping the output image into Draw Rectangle or Draw Result On Image.

  • If you need a tighter or rotated fit, compare results with Minimum Rotated Rectangle, Minimum Ellipse, or Minimum Circle.

  • For shape validation or filtering, consider Hull Convex before measuring, or use Measure Object Distance to compare positions between multiple detected objects.

πŸ› οΈ Troubleshooting

  • No rectangle appears: ensure a valid contour is provided (use Find Contour or 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?