# Perspective Transform

This function block lets you interactively define a four-point perspective mapping on an image and produce a rectified (top‑down) view plus the transform matrix. Use it when you need to remove perspective distortion or generate a bird’s-eye view from a photographed plane.

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

This block accepts the following input socket:

* `Image Any`\
  The source image used to pick the four reference points and compute the perspective transform.

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

This block provides the following output sockets:

* `Image Any`\
  The warped (perspective‑corrected) image produced after four points are defined. Empty until four points are set.
* `Transform Matrix`\
  The perspective transform matrix that can be reused by other blocks that accept a transform or perspective matrix.

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

* `Image Preview`\
  Click on the preview area to place points on the image.
* `Place Points (mouse left click)`\
  Place up to four points in the displayed image.
* `Undo (U)`\
  Remove the most recently placed point.
* `Clear (C)`\
  Remove all placed points and start over.
* `Point Markers and Lines`\
  Visual markers and connecting lines are drawn on the preview so you can see the selected polygon before generating the output.

Tip: Select four points starting from the bottom‑left and proceed clockwise for predictable results.

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

* Interactive point selection directly on the image preview for intuitive setup.
* Visual feedback with circles and connecting lines so you can verify point order and placement.
* Outputs both a rectified image and the transform matrix for downstream processing or reuse.
* Point selection is persisted so you can save and reload your configuration.

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

1. Provide an image to the `Image Any` input socket.
2. Click on the preview to place up to four reference points. Use `U` to undo and `C` to clear.
3. Once four points are placed (recommended order: bottom‑left, then clockwise), the block computes the perspective mapping and outputs the rectified image on the `Image Any` output and the mapping on the `Transform Matrix` output.
4. The transform matrix can be consumed by other blocks that accept a perspective or transform matrix.

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

1. Connect a camera or image source to the `Image Any` input.
2. Run once so the image appears in the preview.
3. Click four points on the image in the required order (bottom‑left → clockwise).
4. Inspect the preview; when four points are present the rectified image appears on the output.
5. Use the `Transform Matrix` output for measurements, metric corrections or other perspective‑aware tasks.

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

* Combine with `Show Image` to inspect the selected area in a larger viewer before or after placing points.
* Use `Image ROI Select` or `Image ROI` to crop a region first if you want to limit the interactive point picking to a smaller area.
* Feed the `Transform Matrix` output into `Social Distance Detector` (as the `Perspective Matrix`) to enable accurate distance measurements in world coordinates.
* After rectifying, use `Image Resize` to scale the result for downstream processing or to match other blocks’ expected sizes.
* If you need to extract the rectified region back into other processing steps, pair with `Get ROI` to pass the corrected image into analysis blocks.

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

* If the output is blank or not appearing: ensure an image is connected and visible in the preview, then place four points.
* If the rectified output looks skewed: verify the point order (start bottom‑left and go clockwise) and reposition points using `Undo (U)` or `Clear (C)` and retry.
* If measurements appear incorrect downstream: confirm you passed the block’s `Transform Matrix` to blocks that require a perspective matrix and that the matrix corresponds to the same image used for picking points.


---

# 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/perspective-transform.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.
