This is the Python implementation of paper for perspective transformation. By using line detector, this approach creates a loss function which contains information of tilt angle of vertical and horizontal lines, and an optimization algorithm tries to minimize loss value, simultaneously update rotate angles in perspective matrix. In this implementation, I used Gradient Descent instead of Levenberg–Marquardt algorithm
Install line detector package for python 3
pip install pylsd
pip install ocrd-fork-pylsd