# Minimum Rotated Rectangle

This function block computes the smallest rotated rectangle that encloses a given shape (contour) in an image. It is useful for measuring oriented object size and orientation, and for visualizing bounding geometry that is not axis-aligned.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

* `Image`\
  The source image used for visualization and reference.
* `Contour`\
  Shape/contour used to calculate the minimum rotated rectangle.

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

* `Image`\
  The source image annotated with the computed rotated rectangle and contour.
* `Center`\
  Center point of the computed rotated rectangle.
* `Width`\
  Width value of the rotated rectangle.
* `Height`\
  Height value of the rotated rectangle.
* `Angle`\
  Rotation angle of the rectangle (orientation).
* `Contour`\
  The contour representation of the rotated rectangle (as a shape output).
* `Rectangle Image`\
  A separate visualization showing the cropped/rectified rectangle region.

## 🕹️ Controls <a href="#controls" id="controls"></a>

This function block has no user-editable controls. It runs automatically when both inputs are provided.

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

* Computes a minimum-area rectangle that may be rotated relative to image axes.
* Provides geometric measurements: center, width, height and angle.
* Visualizes results directly on the source image and as a separate rectangle image.
* Outputs the rectangle as a contour/shape so it can be routed to other blocks for further processing.

## ⚙️ Running mechanism <a href="#running-mechanism" id="running-mechanism"></a>

When an image and a contour are provided, the block analyses the contour shape to determine the smallest-area rectangle that encloses it. The block then produces numeric measurements for size and orientation, draws the rectangle on the image for immediate visual feedback, and also provides the rectangle as a separate shape and image output. If no valid contour is provided, the block will not produce geometric results (it will emit empty or default outputs).

## 📝 Usage instructions <a href="#usage" id="usage"></a>

1. Provide a contour input that represents the object of interest (see Tips and Tricks for how to obtain contours).
2. Feed the same reference image (or a copy) to the `Image` input if you want annotated visualization.
3. Read values from the `Center`, `Width`, `Height`, and `Angle` outputs for measurements or decision logic.
4. Use the `Rectangle Image` output when you need a cropped or rectified view of the detected object.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* To obtain contours from raw images, combine with `Find Contour` or `Feature Detector` to extract object contours before feeding into this block.
* If contours are noisy or contain many points, use `Approximate Contour` to simplify the contour and improve measurement stability.
* For shapes that are better enclosed by convex hulls, try using `Hull Convex` first and feed the hull into this block.
* Compare different enclosing geometries by pairing this block with `Minimum Circle`, `Minimum Ellipse`, or `Minimum Rectangle` to pick the best fit for your application.
* Use `Image ROI Select` or `Image ROI` to crop the region before contour extraction when you only care about a sub-region of the image.
* Visualize or export results with `Draw Rectangle` or `Draw Result On Image` for clear overlays in reports or UI.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* No measurements produced: ensure a valid contour is connected to the `Contour` input and that the contour is not empty.
* Unexpected orientation or size: try simplifying the contour with `Approximate Contour` or verify that the contour corresponds to the intended object (use `Contour to Image` to inspect).
* Rectangle not covering object correctly: check the contour extraction step for holes or disconnected fragments; consider using `Hull Convex` to create an envelope before measurement.


---

# 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/detections-shapes/shape-analysis/minimum-rotated-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.
