Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cglukas/9bb97f3ccba5d4fc95d7f10e632c2cdd to your computer and use it in GitHub Desktop.
Save cglukas/9bb97f3ccba5d4fc95d7f10e632c2cdd 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;
}
@cglukas
Copy link
Author

cglukas commented Sep 29, 2022

Just changed the docstring because the formatting confused me while reading it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment