
Unskewing Photos of Documents with Python
A small python utility to unskew photos of documents somewhat automatically
When working on exercise sheets for university, I often find myself taking photos of the sheets with my phone and dropping them onto my laptop via KDE Connect to append them to the submission. However, these photos are often taken at an angle, resulting in a skewed appearance of the document. There are various android apps that can correct this skew, but my phone is quite old, so I would prefer to do this on my laptop directly, for which I surprisingly could not find any good tools. Therefore, I decided to write a small python utility that can unskew photos of documents.
The script uses OpenCV to detect the edges of the document in the photo. Based on that, initial guesses for the 4 corners of the document are made. Then, the user can adjust these corners manually if the automatic detection was not perfect. Finally, a perspective transformation is applied to unskew the document and save the result as a new image.


Feel free to leave your opinion or questions in the comment section below.