# Perspective transformation

**URL:** <https://forum.opencv.org/t/perspective-transformation/9755>\
**Category:** Uncategorized\
**Created:** [August 7, 2022, 8:12pm UTC](https://forum.opencv.org/t/perspective-transformation/9755 "2022-08-07T20:12:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 7, 2022, 10:28pm UTC](https://forum.opencv.org/t/perspective-transformation/9755/2 "2022-08-07T22:28:13Z")

</div>

that might be tricky, yes. I don’t think OpenCV has anything _ready-made_ for your situation.

you might have to come up with an algorithm to fit a parallelogram around your contour.

I could think of something fairly ad-hoc but viable…

- take the convex hull

then either:

- come up with an algorithm that splits contours into (mostly) straight runs and curved runs (OpenCV needs that still, halcon has it already)
- see if the hull contour has four straight runs that pair up to be somewhat parallel

or:

- turn it dense and equally spaced
- try to fit a pair of lines onto the contour for various angles (hypotheses), allowing for outliers (those sides of the parallelogram that _aren’t_ currently considered, and see how many points are inliers. find the best hypothesis lines.

for the line fitting algorithm, that could be done by projecting the points onto an axis (for a given angle) and seeing where the points form clusters.

for the rectification of scans, also document layout analysis, something like that is a common step to rotate the picture to be axis-aligned.

---

_[View the full topic](https://forum.opencv.org/t/perspective-transformation/9755)._
