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

# Perspective Transform

This function block lets you define a quadrilateral region on an image and generate a corrected, top-down (perspective‑transformed) view of that region. It is interactive — select four points on the image, drag them to refine, and use keyboard shortcuts to edit your selection.

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

* `Image` — Source image shown inside the block for point selection.

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

* `Image` — The perspective-transformed (warped) image of the selected quadrilateral.
* `Transform Matrix` — The perspective transform matrix (useful to feed other blocks that require a perspective or homography matrix).

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

* `Interactive Image Area` — Click on the image to add points. Points are shown as an overlay polygon as you add them.
* `Drag Points` — Click and drag a point to adjust its position.
* `C` — Clear all selected points.
* `U` — Undo the last added point.
* `Help Text` — Small on-block instructions reminding you how to add, drag, clear, and undo points.

Note: The overlay will indicate whether the polygon is complete and highlights the vertex under the mouse for easier adjustment.

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

* The block displays the connected image so you can interactively pick four points.
* If fewer than four points are defined the block returns empty outputs so downstream blocks know the transform is not ready.
* Once four points are provided the block orders them, computes the output rectangle size from the selected points, builds a perspective transform, and outputs the warped image together with the transform matrix.
* The block caches the last computed transform for the same image and point set to avoid unnecessary recomputation while adjusting other parts of the scenario.

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

* Interactive, visual ROI selection with click-and-drag editing.
* Keyboard shortcuts for fast editing.
* Visual overlay shows polygon, vertex highlight, and completion state.
* Outputs both the corrected image and the transform matrix for reuse.
* Automatic sizing chooses an appropriate output rectangle based on the selected points.

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

1. Connect an image-producing block to `Image` input.
2. Click on the image area inside the block to set up to four corner points (any order).
3. Drag points to fine-tune their locations.
4. Use `U` to undo the last point and `C` to clear all points.
5. When four points are present the block will provide a corrected image and the `Transform Matrix` output.

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

* Use `Show Image` to preview the source or transformed image in a larger viewer window while you fine-tune the points.
* If you need to crop the area first, add `Image ROI Select` or `Image ROI` before this block so you work on a smaller region.
* If your source image is very large, add `Image Resizer` before this block to speed up interaction and reduce memory use.
* The produced `Transform Matrix` can be fed into the `Social Distance Detector` block as the required `Perspective Matrix` input to enable real-world distance measurements from the warped view.
* Save transformed results with `Image Write` if you want to keep a copy of the corrected images.

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

* If no output appears, ensure four points are defined — the block will not produce a transform until the quadrilateral is complete.
* If the warped image looks skewed, adjust the corner points by dragging them; using `Show Image` helps to inspect details while tuning.
* If interaction feels slow on large images, insert `Image Resizer` before this block or work on a cropped region with `Image ROI Select`.
* If you accidentally add a point in the wrong place, press `U` to remove the last point or `C` to start over.
