# Point Polygon Test

This function block checks whether a test shape (contour/points) is located inside another enclosing shape. It annotates the input image with visual markers and returns a boolean indicating whether all test points are inside the enclosing contour.

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

`Input Image (Grayscale)` A grayscale image used as background for visualization and drawing.

`Test Shape` A shape (contour or list of points) to be tested for inclusion.

`Enclosing Shape` A contour that acts as the reference enclosure.

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

`Output Image` An annotated image showing the test points and the enclosing contour. Points inside are marked in one color, points outside in another.

`Plot Image` A boolean result: True if all test points lie inside the enclosing contour, otherwise False.

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

This block has no additional interactive controls. It runs based on the provided inputs.

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

* Visual annotation of the reference contour and each test point on the image for easy verification.
* Per-point indication (inside vs outside) using color-coded markers.
* Returns a single boolean summarizing whether the test shape is fully enclosed.

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

* When executed, the block reads the three sockets listed under inputs.
* If either shape input is empty, the block returns the input image unchanged and does not perform the test.
* If both shapes are provided, the block draws the enclosing contour and evaluates each point of the test shape against the enclosure.
* Each test point is drawn on the image with a color indicating inside or outside. The boolean output reflects whether all test points are inside.

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

1. Provide a suitable grayscale image to `Input Image (Grayscale)` for visualization.
2. Feed the contour or point list you want to check into `Test Shape`.
3. Feed the enclosing contour into `Enclosing Shape`.
4. Read the annotated image from `Output Image` and the inclusion result from `Plot Image`.

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

* Use `Find Contour` to extract contours from a binary image and connect its result to `Enclosing Shape` or `Test Shape`.
* Use `Approximate Contour` to simplify complex contours before testing to speed up evaluation and reduce false negatives.
* Crop the region of interest first with `Image ROI` or `Image ROI Select` to focus the test on relevant areas and reduce processing.
* To inspect or create the shape to test, use `Contour to Image` or draw points with `Draw Point` and then use that output as the `Test Shape`.
* If the test shape should be derived from segmentation, try `Image Threshold` or `Fill Contour` beforehand to create clean contours for more reliable results.

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

* If all points report outside unexpectedly, verify that the coordinate systems match (cropping or resizing upstream can shift coordinates).
* If the result is inconclusive, visualize intermediate contours using `Show Image` to confirm shapes are fed correctly.
* If contour extraction fails to provide usable shapes, preprocess the image with `Blur` or `Image Threshold` for better edge detection.


---

# 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/point-polygon-test.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.
