# Approximate Contour

This function block simplifies a given contour by creating an enclosing polygon with a reduced number of edges. It visualizes both the original contour and the simplified approximation, and provides geometric information such as center, perimeter and corner count.

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

`Image Any` The image used for visualization (draws original and approximated contours on this image).

`Contour` The input contour to be approximated (shape data).

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

`Image Any` Image that shows the original contour and the approximated polygon with corner markers.

`Contour` The approximated contour as a shape output.

`Center` The centroid of the approximated contour (x, y).

`Perimeter` Perimeter length of the approximated contour.

`Number of corners` Number of vertices in the approximated polygon.

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

`Epsilon` Slider to set the approximation tolerance. Higher values produce simpler polygons with fewer corners; lower values keep more detail.

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

* When the block runs, it receives an image and a contour through its input sockets.
* The block uses the `Epsilon` control to determine how aggressively the contour is simplified (epsilon is applied relative to contour perimeter).
* The block creates a simplified polygon and draws both the original contour and the approximation onto the provided image for visual feedback.
* The block then calculates the approximated contour's centroid, perimeter and corner count and sends these values through the output sockets.

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

* Visual comparison: original contour (one color) and approximated polygon (another color) are both shown on the output image, with corner points marked for quick inspection.
* Numeric outputs: center position, perimeter and number of corners are provided for downstream logic or logging.
* Adjustable approximation: the slider gives an intuitive way to balance between simplification and fidelity.

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

1. Provide a contour (for example from a contour-finding block) to the `Contour` input.
2. Provide the image you want to annotate to the `Image Any` input.
3. Adjust `Epsilon` until the approximated shape matches the desired level of detail.
4. Use the outputs for visualization, measurement or further processing.

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

* To obtain contours suitable for approximation, use the `Find Contour` block first. That block detects contours you can feed into this block.
* Preprocess the source image with `Blur`, `Image Threshold` or `Morphological Transformations` to reduce noise and produce cleaner contours.
* Use `Image ROI` or `Image ROI Select` to crop the region of interest before contour detection and approximation to speed up processing and avoid irrelevant shapes.
* After approximation, you may want to:
  * Convert the approximated contour into an image crop with `Contour to Image` for focused inspection.
  * Fit simple enclosing shapes using `Minimum Rectangle`, `Minimum Circle` or `Minimum Ellipse` for measurements or alignment tasks.
  * Fill the approximated shape with `Fill Contour` when you need a binary mask of the region.
* Use `Draw Rectangle`, `Draw Point` or other draw blocks to overlay additional annotations or combine with detection results.
* To shift shapes in coordinate space (for ROI adjustments or alignment), use `Translate Shape`.

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

* If the approximated polygon is too coarse or too detailed, tweak the `Epsilon` slider gradually until you get the desired corner count.
* If contour outputs are empty or invalid, ensure the contour source (for example `Find Contour`) is producing valid shapes and that any preprocessing steps produce a clear foreground/background separation.
* If visual markers are misplaced after cropping or coordinate transforms, verify that subsequent blocks (ROI, translation or drawing) use consistent coordinate systems.


---

# 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/approximate-contour.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.
