Opencv仿射和透射变换的坐标变换
Submitted by hubdog on Fri, 2019-02-22 09:15
OpenCV里面通过getAffineTransform或者findTransformECC获取变形矩阵的饿时候会得到一个2x3或者3x3的变形矩阵,分别对应仿射矩阵和透视矩阵.
变形的时候如果想要算出原始图像坐标到目标图像的坐标的时候,可以使用下面方法计算
if (matrixSize == 3) { //计算透视变换坐标 double w= warp_matrix.at<float>(2, 0)*orgX + warp_matrix.at<float>(2, 1)*orgY + warp_matrix.at<float>(2, 2); targetX = (warp_matrix.at<float>(0, 0)*orgX + warp_matrix.at<float>(0, 1)*orgY + warp_matrix.at<float>(0, 2))/w; targetY = (warp_matrix.at<float>(1, 0)*orgX + warp_matrix.at<float>(1, 1)*orgY + warp_matrix.at<float>(1, 2))/w; } else { //计算仿射变换坐标 targetX = warp_matrix.at<float>(0, 0)*orgX + warp_matrix.at<float>(0, 1)*orgY + warp_matrix.at<float>(0, 2); targetY = warp_matrix.at<float>(1, 0)*orgX + warp_matrix.at<float>(1, 1)*orgY + warp_matrix.at<float>(1, 2); }