A long time ago I did something like this with ImageMagick using what it called "Extract SIFT Correspondences". I don't know if that still exists, but the homography feature in OpenCV looks like the same idea: https://learnopencv.com/image-alignment-feature-based-using-...
I've seen various tools that let you take a picture and that then automatically align the paper to scan it (sometimes with and sometimes without QR codes in the corners) and I wish there was some general "how to" tutorial out there for that kind of trick