We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to translate 2d quad to 2d quad linear pixels
Page Index Toggle Pages: 1
how to translate 2d quad to 2d quad linear pixels? (Read 260 times)
how to translate 2d quad to 2d quad linear pixels?
Sep 11th, 2008, 1:31pm
 
hello,

i'm trying to find the correct algorythm to convert a 2d quad source to a final 2d quad using a linear matrix transformation.

My final quad is the screen coordinates and the source quad is the four points of a camera image corners.
I find and implement this function, but this is for the opposite effect. Source is the screen and final is the internal coordinates. this is the algorithm.

Can you help me?

maybe it exist a library to do this. I now it exist in opencv, but i dont know if is possible to implement in processing.

thanks a lot,

alex

////////////////////////////////////////////////


  //this is the startx and endx of my src quad
  // top left corner and bottom right corner
  float sx = 0.0;
  float sy = 0.0;
  float ex = 1.0;
  float ey = 1.0;
 
  //this is an array of four points
  //that describe the four corners
  //of the warped quad -
  // currently they are ordered like:
  //
  //  pt0      pt1
  //
  //  pt3      pt2
  //
  //but I have also tried doing top-left, top-right, bottom-left, bottom-right
 
  float wx[4];
  float wy[4];
 
  //corners are in 0.0 - 1.0 range
  for(int i = 0; i < 4; i++){
  wx[i] = corners[i].x ;
  wy[i] = corners[i].y ;
  }
 
  //this is code from Myler and Weeks:
  //calculates the warp coeffecients that describe
  //the transformations between the src and dst quad
  float matrix[8];
 
  matrix[0] = (-wx[0] + wx[1]) / (ey-sy); //a
  matrix[1] = (-wx[0] + wx[3]) / (ex-sx); //b
  matrix[2] = (wx[0] - wx[1] + wx[2] - wx[3]) / ( (ey-sy)  * (ex-sx) ); //c
  matrix[3] =  wx[0]; //d
 
  matrix[4] = (-wy[0] + wy[1]) / (ex-sx); //e
  matrix[5] = (-wy[0] + wy[3]) / (ey-sy); //f
  matrix[6] =  (wy[0] - wy[1] + wy[2] - wy[3]) / ( (ey-sy)  * (ex-sx) ); //i
  matrix[7] = wy[0]; //j
 
  //myler and weeks describes then how to translate a new destination X and Y based
  //on these coeffecients
 
  //  X = a*x + b*y +c*x*y + d
  // Y = e*x + f*y + i*x*y + j;
 

Page Index Toggle Pages: 1