> For the complete documentation index, see [llms.txt](https://docs.augelab.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.augelab.com/function-blocks/blocks-reference/detections-shapes/roi-processing/image-roi-polygon.md).

# Image ROI Polygon

This function block lets you draw a polygon directly on an image to define a custom region of interest (ROI). Use it to select irregular shapes, edit vertices interactively, and output both the cropped image inside the polygon and the polygon coordinates for downstream processing.

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

* `Image Any` The image to display and annotate. Connect any image-producing block here so you can draw the polygon on a live preview.

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

* `Image Any` The cropped image corresponding to the polygon area. If no polygon is defined this output may be empty.
* `Polygon` The polygon coordinates returned as a contour/shape list suitable for use by other blocks.

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

* `Left Click` Add a vertex at the clicked location.
* `Drag` Click and drag an existing vertex to reposition it.
* `U` Undo the last added vertex.
* `C` Clear all vertices and start again.
* `Overlay Preview` Visual markers and fill are shown while editing so you can see the polygon, vertices and the selection area in real time.

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

* Connect an image source to the `Image Any` input and run the scenario once to populate the preview.
* Draw the polygon by clicking to add vertices. The overlay updates immediately.
* Use drag and keyboard shortcuts to refine the shape.
* When a polygon is present the block produces a cropped image (tight bounding rectangle of the polygon) and the polygon coordinate list on each evaluation.

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

* Interactive polygon drawing with vertex editing.
* Undo/clear shortcuts for quick corrections.
* Visual overlay with vertex highlights while hovering or dragging.
* Outputs both a cropped image and precise polygon coordinates.
* Supports non-rectangular and multi-point ROIs for irregular objects.

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

* Draw at least three points to form a filled polygon; fewer points will not yield a valid ROI crop.
* After drawing, run downstream blocks to process the cropped image or polygon coordinates.
* Use the drag feature to fine-tune vertex positions for accurate measurements.

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

* Preview larger images by connecting the output to `Show Image` so you can draw more precisely on a separate viewer.
* If you need multiple ROIs in one image, use `Image ROI Polygon Multi` to store several polygon selections and then feed each to processing blocks.
* Combine with `Get ROI` or `Image ROI Select` if you prefer rectangular crops first, then refine with polygon for complex shapes.
* Use `Apply Mask` after this block to mask the original image with the polygon and feed that masked image into analysis blocks.
* Feed the cropped polygon image into detection or analysis blocks such as `Find Object`, `Object Detection`, `Mask Detection`, `Histogram On Line` or `Color Density Percentage` to focus processing on the selected area.
* If the image is too large to draw comfortably, add `Image Resizer` or `Image Resize` before this block; remember that resizing changes pixel coordinates used by downstream geometry-sensitive blocks.
* Save selected ROIs with `Image Logger`, `Image Write` or `Multi Image Write` for dataset collection or later review.

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

* No image displayed: make sure an image-producing block is connected to `Image Any` and run once to populate the preview.
* ROI not produced: ensure you have at least three vertices; fewer points cannot form a filled polygon.
* Polygon appears misplaced after resizing upstream images: either draw at the final resolution or insert `Image Resizer` consistently in the pipeline so coordinates remain aligned.
* Need exact coordinates for other blocks: use the `Polygon` output (coordinate list) and verify with a preview via `Show Image` or re-run after adjustments.
