我能够在纹理和目标对象上获得WebcamTexture
的Homography。
现在,我想基于Homography改变Unity相机的变换。我已经找到了一种从Homography中获取相机位置的方法:
void cameraPoseFromHomography(const Mat& H, Mat& pose)
{
pose = Mat::eye(3, 4, CV_32FC1); // 3x4 matrix, the camera pose
float norm1 = (float)norm(H.col(0));
float norm2 = (float)norm(H.col(1));
float tnorm = (norm1 + norm2) / 2.0f; // Normalization value
Mat p1 = H.col(0); // Pointer to first column of H
Mat p2 = pose.col(0); // Pointer to first column of pose (empty)
cv::normalize(p1, p2); // Normalize the rotation, and copies the column to pose
p1 = H.col(1); // Pointer to second column of H
p2 = pose.col(1); // Pointer to second column of pose (empty)
cv::normalize(p1, p2); // Normalize the rotation and copies the column to pose
p1 = pose.col(0);
p2 = pose.col(1);
Mat p3 = p1.cross(p2); // Computes the cross-product of p1 and p2
Mat c2 = pose.col(2); // Pointer to third column of pose
p3.copyTo(c2); // Third column is the crossproduct of columns one and two
pose.col(3) = H.col(2) / tnorm; //vector t [R|t] is the last column of pose
}
来源:https://stackoverflow.com/a/10781165/4382683
现在,这与OpenCV图像相关,OpenCV图像的维数为数百个。但在Unity中,Quad有LocalScale
(1,1,1)
- 我不知道如何用这个来翻译姿势。
此外,Mat
3x4
如何在Unity中使用某个位置 - 其中位置只是Vector3
,如(1,5,4)
,旋转也是{{1}像Vector3
一样。
任何提示或方向都足够好。感谢。