# Find Contour

This function block detects and selects contours in a grayscale image. Use it to locate shapes, get their position, area, rotation, and preview the selected contour on the image. Adjustable area limits and approximation methods help you filter and refine results.

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

`Image Gray` Input grayscale image used for contour detection (single-channel image).

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

`Selected Contour` The chosen contour (shape) based on selection or automatic selection.

`Contours` A list of all detected contours that passed filtering.

`Contour Image` Preview image with the selected contour drawn and center marked.

`Object Position` The center (x, y) position of the selected contour.

`Object Rotation` The orientation angle of the selected contour (degrees).

`Object Area` The area value of the selected contour (pixel units).

`Object Count` Number of contours found after filtering.

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

`Minimum Contour Area (%)` A horizontal range slider to set minimum and maximum contour area as percentages of the image area; contours outside this range are ignored.

`Approximation Method` A dropdown to choose contour approximation strategy (affects contour detail vs. simplification).

`Contour Selection` A dropdown that lists detected contours (with area percentages) so you can pick one for inspection or measurement.

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

* Visual preview of the selected contour with center marker and drawn contour lines.
* Area-based filtering to ignore very small or excessively large shapes.
* Multiple approximation options to control contour detail and smoothing.
* Outputs both geometry (shape, center, angle, area) and a list of all validated contours.
* Automatic guarding against overwhelming results by limiting the number of processed contours for performance.

## ⚙️ How it runs <a href="#how-it-works" id="how-it-works"></a>

When executed, the block analyzes the supplied grayscale image, detects contours, filters them by the configured area range, sorts them by size, and makes a selected contour available for inspection. The preview image shows the selected contour and its center, and the block exports numeric and shape data for further processing.

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

* Preprocess images with `Image Threshold`, `Image Adaptive Threshold`, or `Blur` to improve contour detection on noisy inputs.
* Use `Image ROI Select` or `Image ROI` to crop the area of interest before running this block to avoid irrelevant contours.
* Pair with `Approximate Contour`, `Minimum Rectangle`, `Minimum Ellipse`, or `Minimum Circle` to derive simpler geometric representations from the selected contour.
* Use `Translate Shape` to shift detected shapes into a common coordinate frame when combining multiple inputs.
* Visualize or annotate results using `Draw Rectangle`, `Draw Result On Image`, or `Draw Detections` for clearer UI overlays.
* If you need polygonal areas as inputs or to limit analysis, combine with `Image ROI Polygon` or `Image ROI Polygon Multi`.
* Log images or results using `Image Logger`, `Image Write`, or export numeric data with `CSV Export` / `Data to JSON`.
* Combine with `Find Object` (template matching) or `Feature Detector` to perform finer object identification after rough contour filtering.
* For quality control systems, connect downstream to `Measure Object Distance`, `Check Area`, or `Rectangles in Rectangle` to implement pass/fail logic.

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

* If no contours are found, widen the `Minimum Contour Area (%)` range or improve input contrast with `Auto Contrast` or `Denoising`.
* If many small spurious contours appear, increase the minimum area or apply `Image Threshold` / `Blur` to remove noise.
* If contours appear too detailed, choose a simpler `Approximation Method` to reduce vertex count and simplify shape outputs.


---

# 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/find-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.
