I bounced around Alains comment about QuadrilateralTransform and got it implemented in OpenGL before really looking at that original link and seeing that Alains project is already doing the QuadrilateralTransform.
This is how to modify Alains project to go the other way
In mPerspective.ABBackwardQuadrilateralTransformation swap the parameters, so srcRect is first.
dim matrix(2,2) as Double = MapQuadToQuad(srcRect, destinationQuadrilateral)
srcRect is the 4 corners of the unmolested picture. destination is the 4 corners of the arbitrary quad that is dragged around. Instead of mapping src to dest we flip them so the matrix maps dest to src (map arbitrary quad to the rectangular picture)
Also, in this same method we need to change the values on these lines. These are the output range of pixels and want the whole picture scanned.
dim startX as integer = 0
dim startY as integer = 0
dim stopX as integer = srcPic.Width - 1
dim stopY as integer = srcPic.Height - 1
You may also comment out these lines
[code]'Dim minXY as ABPoint
'Dim maxXY as ABPoint
'get bounding rectangle of the quadrilateral
'GetBoundingRectangle destinationQuadrilateral, minXY, maxXY[/code]
That’s it. Now the region the rect is placed around is drawn rectangularly below. It’s difficult to see the correspondence though so add this line which draws the image underneath the quad.
In Main.DrawPerspectivePoints add the marked line
[code]tmpBuffer.Graphics.ForeColor = &c000000
tmpBuffer.Graphics.FillRect 0,0,tmpBuffer.Width, tmpBuffer.Height
tmpBuffer.Graphics.DrawPicture(OrigPic, 0, 0) //<<<<<<<<<<<<<<< add
dim a as integer[/code]
Maybe that’s enough for you to wrap up in a class.
My OpenGL test redraws effortlessly but I only know how to do it with an OpenGLSurface control. An offscreen OpenGL Context is needed to do it in the background.
download distorted.zip (readme Note in Window)
Trying it on realworld pictures is fun but I wonder if the curved distortion in the output on the right comes from OpenGLs math or the optics of the camera.