两个 AR 标记之间的相对平移矩阵
我现在正在尝试编写一个简单的 AR 应用程序,特别是我正在尝试计算两个方形标记之间的翻译,类似于他们在底部的网站上所做的操作: hitl.washington.edu/artoolkit/documentation/tutorialcamera.htm" rel="nofollow noreferrer">Artoolkit
我使用的标记尺寸相同 (100mm x 100mm),并且我的图像没有相机失真(我目前正在使用测试图像)。
目前我的流程遵循以下步骤:
- 从图像中检测标记并提取角点。
- 给定标记角,运行共面 POSIT。
- 给定 2 个标记变换(A 和 B),计算 Inverse(A) * B
- 分解以获取标记 B 相对于标记 A 的 x、y 和 z 平移
。问题是我的结果似乎完全不对劲。下面是程序的屏幕:
橙色方块代表角的位置,我已经检查过这些并且它们是正确的。
我已经使用 XNA 覆盖了轴。 我正在使用 AForge.net 进行共面 POSIT。 图像尺寸为 640x480。 共面位置知道标记为 100mm,焦距设置为 640。
我在 c# 中运行执行此操作的确切代码:
private void computePOSIT()
{
matrixes.Clear();
AForge.Math.Matrix3x3 matrix;
AForge.Math.Vector3 trans;
foreach (Marker m in markers)
{
AForge.Point[] points = new AForge.Point[4];
for (int i = 0; i < 4; i++)
{
points[i] =
new AForge.Point(m.corners[i].X-320 ,240 - m.corners[i].Y);
}
posit.EstimatePose(points, out matrix, out trans);
float yaw, pitch, roll;
matrix.ExtractYawPitchRoll(out yaw, out pitch, out roll);
Matrix rotation =
Matrix.CreateFromYawPitchRoll(-yaw, -pitch, roll);
Matrix translation =
Matrix.CreateTranslation(new Vector3(trans.X, trans.Y, -trans.Z));
Matrix complete = rotation * translation;
List<Matrix> all = new List<Matrix>();
all.Add(rotation);
all.Add(translation);
all.Add(complete);
matrixes.Add(all);
}
Matrix res = Matrix.Invert(matrixes[0][4]) * matrixes[1][5];
Vector3 scaleR;
Vector3 translationR;
Quaternion rotationR;
res.Decompose(out scaleR, out rotationR, out translationR);
}
结果矩阵显示:
TranslationR: X:-402.2295 Y:191.7873 Z:-135.3166} 旋转R:{X:0.007288148 Y:-0.4478231 Z:-0.5093549 W:0.734819} scaleR:1,1,1
更新:我已经修复了 POSIT 问题并且轴现在正确对齐,但是平移问题仍然存在。我的数学计算正确吗?
I am trying to write a simple AR app at the moment, specifically I am trying to compute the translation between two square markers similar to how they are doing it on this website at the bottom: Artoolkit
The markers I am using are both the same size (100mm x 100mm) and my image has no camera distortion (I am using a test image at the moment).
Currently my process is following these steps:
- Detect markers from image and extract out corners.
- Run Co-planar POSIT given the marker corners.
- Given 2 marker transformations (A and B), compute Inverse(A) * B
- Decompose to grab marker B's x,y, and z translation relative to marker A.
The problem is my results seem totally off. Below is a screen of the program:
The orange squares represent where the corners are, I have checked these and they are correct.
I have overlain the axes using XNA.
I am using AForge.net for the coplanar POSIT.
Image is 640x480.
Coplanar posit knows the markers are 100mm and the focal length is set to 640.
The exact code I am running to do this in c#:
private void computePOSIT()
{
matrixes.Clear();
AForge.Math.Matrix3x3 matrix;
AForge.Math.Vector3 trans;
foreach (Marker m in markers)
{
AForge.Point[] points = new AForge.Point[4];
for (int i = 0; i < 4; i++)
{
points[i] =
new AForge.Point(m.corners[i].X-320 ,240 - m.corners[i].Y);
}
posit.EstimatePose(points, out matrix, out trans);
float yaw, pitch, roll;
matrix.ExtractYawPitchRoll(out yaw, out pitch, out roll);
Matrix rotation =
Matrix.CreateFromYawPitchRoll(-yaw, -pitch, roll);
Matrix translation =
Matrix.CreateTranslation(new Vector3(trans.X, trans.Y, -trans.Z));
Matrix complete = rotation * translation;
List<Matrix> all = new List<Matrix>();
all.Add(rotation);
all.Add(translation);
all.Add(complete);
matrixes.Add(all);
}
Matrix res = Matrix.Invert(matrixes[0][4]) * matrixes[1][5];
Vector3 scaleR;
Vector3 translationR;
Quaternion rotationR;
res.Decompose(out scaleR, out rotationR, out translationR);
}
Resulting matrix shows that:
TranslationR: X:-402.2295 Y:191.7873 Z:-135.3166}
RotationR: {X:0.007288148 Y:-0.4478231 Z:-0.5093549 W:0.734819}
scaleR: 1,1,1
Update: I have fixed the POSIT problem and the axes align correctly now, however the translation issue still exists. Is my maths correct to work out the relative translation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论