# Image ROI Polygon

This function block lets you draw a polygon directly on an image to define a region of interest (ROI). Use left mouse clicks to add points, then extract the cropped polygon area or a polygon shape for downstream processing.

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

`Input Image` Input socket that accepts any image to draw the polygon on.

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

`Image Any` Output socket that provides the cropped image inside the drawn polygon (or None if no polygon defined).

`Polygon` Output socket that provides the polygon point list as a shape value suitable for other ROI-aware blocks.

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

`Interactive Image Area` Click on the image to add polygon vertices. The interactive area also shows visual feedback (points, connecting lines and a translucent highlight of the polygon).

`U` Press this key to undo the last added point.

`C` Press this key to clear all points and start over.

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

* Visual point/edge drawing with immediate feedback: points and connecting lines are drawn on the image as you add vertices.
* Highlighted polygon area overlay for quick preview of the selected ROI.
* Returns both the cropped image inside the polygon and the polygon coordinates as an output shape for further processing.
* Supports serialization: polygon points are kept when saving/loading the scenario so you can restore your ROI.

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

1. Connect an image-producing block to `Input Image`.
2. Run once so the image is visible in the interactive area.
3. Left-click on the image to add polygon vertices in order.
4. Use `U` to undo the last point or `C` to clear all points.
5. After defining the polygon, the block outputs the cropped polygon image on `Image Any` and the polygon coordinates on `Polygon`.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

When evaluated, the block updates the interactive image preview and, if a polygon exists, outputs:

* the cropped polygon image (tight bounding box of the polygon), and
* the polygon coordinates as a shape list ready for downstream blocks.

If no polygon is drawn the `Image Any` output will be None.

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

* To visually inspect the selected ROI in larger detail, send the `Image Any` output to the `Show Image` block.
* If you need multiple crop areas, use the `Image ROI Polygon Multi` block to define and manage several polygons.
* To quickly define a rectangular ROI instead of a polygon, combine this block with `Image ROI Select` or `Image ROI` for faster rectangle-based cropping.
* Use the polygon coordinates with `Apply Mask` to mask the original image while preserving full canvas size (useful when you want to keep image alignment).
* Send the cropped ROI to analysis or detection blocks like `Find Object` or `Contour to Image` to focus processing only inside the selected area.
* When saving examples or records, attach the cropped output to `Image Logger` or `Image Write` to keep dataset images of your ROI.
* If you need a fixed image size for downstream models, add `Image Resize` after the crop to normalize dimensions.

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

* No image visible in the interactive area: ensure an image-producing block is connected to `Input Image` and run once to populate the preview.
* Polygon not producing an output: make sure at least two points are defined; the block only produces a crop when a polygon is formed.
* Cropped area appears empty or transparent: verify the polygon was drawn within image bounds and that the source image is not all zeros.
* Saved project loses polygon points: confirm the project was saved after drawing (this block serializes the point list, but you must save the scenario to persist it).


---

# 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/roi-processing/image-roi-polygon.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.
