In fact, you do not need to deal with 3D information, it is just a function of displaying from one set of coordinates to another.
Look at affine transformations; they can correct simple oblique and promising effects. You should find somewhere a code that will calculate a 4-point transformation in the corners of your rectangle.
I almost forgot - if “fast” is really important, you can simplify the system only by using simple shear transforms in combination, although this will adversely affect the image quality for strongly inclined objects.
source share