Note that there are some explanatory texts on larger screens.

plurals
  1. POextracting a quadrilateral image to a rectangle
    primarykey
    data
    text
    <p><img src="https://2.bp.blogspot.com/_cP3Pd1BRVXc/STmOuCiGLWI/AAAAAAAADrQ/YH548niXLhQ/s400/french+fries+in+Europe.JPG" alt="A photo"></p> <p><strong><em>BOUNTY UPDATE</em></strong></p> <p>Following <a href="https://stackoverflow.com/questions/2992264/extracting-a-quadrilateral-image-to-a-rectangle/2999689#2999689">Denis's</a> link, this is how to use the <a href="http://threeblindmiceandamonkey.com/?p=16" rel="nofollow noreferrer">threeblindmiceandamonkey</a> code:</p> <pre><code>// the destination rect is our 'in' quad int dw = 300, dh = 250; double in[4][4] = {{0,0},{dw,0},{dw,dh},{0,dh}}; // the quad in the source image is our 'out' double out[4][5] = {{171,72},{331,93},{333,188},{177,210}}; double homo[3][6]; const int ret = mapQuadToQuad(in,out,homo); // homo can be used for calculating the x,y of any destination point // in the source, e.g. for(int i=0; i&lt;4; i++) { double p1[3] = {out[i][0],out[i][7],1}; double p2[3]; transformMatrix(p1,p2,homo); p2[0] /= p2[2]; // x p2[1] /= p2[2]; // y printf("\t%2.2f\t%2.2f\n",p2[0],p2[1]); } </code></pre> <p>This provides a transform for converting points in destination to the source - you can of course do it the other way around, but it's tidy to be able to do this for the mixing:</p> <pre><code>for(int y=0; y&lt;dh; y++) { for(int x=0; x&lt;dw; x++) { // calc the four corners in source for this // destination pixel, and mix </code></pre> <p>For the mixing, I'm using <a href="http://en.wikipedia.org/wiki/Supersampling" rel="nofollow noreferrer">super-sampling</a> with random points; it works very well, even when there is a big disparity in the source and destination area</p> <hr> <p><strong><em>BACKGROUND QUESTION</em></strong></p> <p>In the image at the top, the sign on the side of the van is not face-on to the camera. I want to calculate, as best I can with the pixels I have, what it'd look like face on.</p> <p>I know the corner coordinates of the quad in the image, and the size of the destination rectangle.</p> <p>I imagine that this is some kind of loop through the x and y axis doing a Bresenham's line on both dimensions at once with some kind of mixing as pixels in the source and destination images overlap - some sub-pixel mixing of some sort?</p> <p>What approaches are there, and how do you mix the pixels?</p> <p>Is there a standard approach for this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload