I'm working with a homography calculated by OpenCV. I currently use this homography to transform points using the function below. This function performs the task I require however I have no clue how it actually works.
Can anyone explain, line by line exactly, the logic/theory behind the last 3 lines of code, I understand that this transforms the point x,y but I'm unclear as to why this works:
Why are Z
, px
and py
calculated in this way, what do the elements in h
correspond to?
Your comments are greatly appreciated :)
double h[9];
homography = cvMat(3, 3, CV_64F, h);
CvMat ps1 = cvMat(MAX_CALIB_POINTS/2,2,CV_32FC1, points1);
CvMat ps2 = cvMat(MAX_CALIB_POINTS/2,2,CV_32FC1, points2);
cvFindHomography(&ps1, &ps2, &homography, 0);
...
// This is the part I don't fully understand
double x = 10.0;
double y = 10.0;
double Z = 1./(h[6]*x + h[7]*y + h[8]);
px = (int)((h[0]*x + h[1]*y + h[2])*Z);
py = (int)((h[3]*x + h[4]*y + h[5])*Z);