# 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 <a href="#inputs" id="inputs"></a>

* `Image Any` The image used as background for visualization.
* `Contour` The shape/contour to be enclosed by the minimum rectangle.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

* `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 <a href="#controls" id="controls"></a>

This block has no additional user-facing controls.

## 🎨 Features <a href="#features" id="features"></a>

* 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 <a href="#usage" id="usage"></a>

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 <a href="#evaluation" id="evaluation"></a>

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 <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* 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 <a href="#troubleshooting" id="troubleshooting"></a>

* 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/blocks-reference/detections-shapes/shape-analysis/minimum-rectangle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
