A desktop app that undoes unwanted perspective, unbends pages, and cleans up stains.
The maths behind all the transformations are explained in my book Geometry for Programmers.
And also partially on Words and Buttons Online:
The project is abandoned. I tried to extract any useful math from it to reimplement it in C++, and some code was later reused in other programs. But as a desktop application, it is done.
The code is unlicensed though, so you can pick it up and reuse in your own work.
If you want to try the app, here's the release: https://github.com/akalenuk/unpager/releases/tag/0.1
I also have a GIMP script for darning (that's what the cleaning method is called): https://github.com/akalenuk/darning
And also an Android application for undoing perspective: https://github.com/akalenuk/Docam