# Perspective Transform

This function block allows users to apply a perspective transformation to an image by selecting four points. These points define a rectangular area in the input image that will be transformed to fit a given target rectangle.

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

`Image Any` The input image that you want to apply the perspective transformation on.

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

`Image Any` The output image after applying the perspective transformation.

`Transform Matrix` The matrix used for the perspective transformation, useful for understanding how the transformation has been applied.

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

`Mouse Clicks` Click on the image displayed in the block to define four points for the perspective transformation in a clockwise order starting from the bottom left corner.

`Keyboard Controls`

* Press `C` to clear the existing points.
* Press `U` to undo the last point added.

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

`Interactive User Input` Users can interactively select points on the image using mouse clicks, allowing for easy adjustments.

`Visual Feedback` The points and lines drawn on the image provide immediate visual feedback, helping users understand how the transformation will occur.

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

1. **Input an Image**: Connect an image to the input of the block.
2. **Select Four Points**: Click on the image to define four corners of the region you want to transform in a clockwise manner starting from the bottom left.
3. **Clear or Undo**: If you make a mistake, you can press `C` to clear all points or `U` to undo the last point.
4. **Evaluate**: Run the block to perform the perspective transformation. The output image will reflect the transformation, and the matrix will be available for further usage.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

When evaluated, this function block returns the transformed image based on the points selected and the corresponding transformation matrix.

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

<details>

<summary>Defining Points Accurately</summary>

For the best results, ensure the points are defined accurately, especially on non-rectangular shapes. Take your time clicking to ensure each point is as close to the desired location as possible.

</details>

<details>

<summary>Using an Image Resizer</summary>

If the image size is too large and affects performance, consider using the `Image Resizer` function block before applying the perspective transformation.

</details>

<details>

<summary>Cropping Before Transforming</summary>

If you only need to transform a specific area, use `Image ROI` to crop the area first before applying the perspective transformation to improve focus and performance.

</details>

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

<details>

<summary>No Points Registered</summary>

If nothing seems to be drawn on the image, ensure you are clicking on the correct area and that you have allowed enough time for the draw action to respond before moving on.

</details>

<details>

<summary>Transformation Result Does Not Appear Correct</summary>

Double-check that the points were selected in the correct order and are defining a valid rectangle. If points are too close together or not positioned correctly, the outcome may not be as expected.

</details>
