Skip to content

Instantly share code, notes, and snippets.

@martin-etchart
Created November 11, 2016 15:08
Show Gist options
  • Save martin-etchart/cb5ea2a32706106c7637ec665da918f4 to your computer and use it in GitHub Desktop.
Save martin-etchart/cb5ea2a32706106c7637ec665da918f4 to your computer and use it in GitHub Desktop.
Change coord system of 2x3 transformation matrix estimated in opencv coord system to a coord system equivalent of doing y'=height-y
/**
* Changes the coordinate system of the transformation matrix from regular image
* coords (opencv-like) to a different coords system like this:
*
* .-------> x ^ y
* | V |
* | ---> |
* | |
* v y .-------> x
*
* This is, y_{S2}=h-y_{S1}, where h is the height of the image.
*
* Change of base matrix is V = {{1,0,0},{0,-1,h},{0,0,1}}
* Inverse of V is exactly V.
*
* T_{S2} = V * T_{S1} * V
*
* Where V:S1->S2 and S1 is the OpenCV coords space and S2 the new coord space.
*
* @param tmat_s1 transformation matrix transform input in S1 coords
* @param tmat_s2 transformation matrix transform output in S2 coords
* @param h height of the image
*/
void transform_matrix_change_base(cv::Matx23f tmat_s1, cv::Matx23f &tmat_s2, int h)
{
tmat_s2(0,0) = tmat_s1(0,0);
tmat_s2(0,1) = -tmat_s1(0,1);
tmat_s2(0,2) = tmat_s1(0,2)+h*tmat_s1(0,1);
tmat_s2(1,0) = -tmat_s1(1,0);
tmat_s2(1,1) = tmat_s1(1,1);
tmat_s2(1,2) = -tmat_s1(1,2)+h*(1-tmat_s1(1,1));
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment