我正在 iOS 上编写 AR 应用程序,并在 UIView 上使用 CATransform3D 转换。
通过OpenCV,我可以通过调用cvGetPerspectiveTransform()得到一个透视矩阵。这将返回一个 3x3 矩阵。
我不记得在哪里找到它了,但我有执行以下操作的示例代码:
//the opencv transform matrix is put into map_matrix
cvGetPerspectiveTransform (src_pnt, dst_pnt, map_matrix);
CATransform3D t = CATransform3DIdentity;
// map over the CATransform3D 4x4 matrix from the opencv 3x3 matrix
t.m11 = cvmGet(map_matrix,0,0);
t.m12 = cvmGet(map_matrix,1,0);
t.m14 = cvmGet(map_matrix,2,0);
t.m21 = cvmGet(map_matrix,0,1);
t.m22 = cvmGet(map_matrix,1,1);
t.m24 = cvmGet(map_matrix,2,1);
t.m41 = cvmGet(map_matrix,0,2);
t.m42 = cvmGet(map_matrix,1,2);
t.m44 = cvmGet(map_matrix,2,2);
myView.layer.transform = t;
然而,应用这种形式会使我的观点变得疯狂并到处乱跳。通过一些试验,我发现只有这三个映射有点工作:
t.m14 = cvmGet(map_matrix,2,0); //left and right transform
t.m24 = cvmGet(map_matrix,2,1); //up and down transform
t.m21 = cvmGet(map_matrix,0,1); //some kind of skew?
我一直在阅读 3d 图形和变换数学,但这是一项艰巨的任务。
从 3x3 矩阵到 4x4 矩阵的正确映射是什么?
谢谢!