我已經寫在XNA一個簡單的AR程序,現在我試圖找到我的2個標記之間的相對轉變。試圖找到兩個位置之間的相對變換 - XNA
我已經找到了我的標誌相對於我的相機,並提取了平移和旋轉矩陣的標記。
我想要做的是找出從標記1到標記2的相對平移。例如,如果標記1和標記2位於同一個Z平面上,則Z平移分量將爲0mm。
圖像下面正在爲在同一平面上2個位置的應用:
我假定由第一標記的逆只需將第二標記的矩陣乘以我可以得到譯文。但是,我得到完全錯誤的結果。
我正在運行的代碼如下:
posit.EstimatePose(點,出矩陣,出反式);
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][2]) * matrixes[1][2];
Vector3 scaleR;
Vector3 translationR;
Quaternion rotationR;
res.Decompose(out scaleR, out rotationR, out translationR);
其結果是:
TranslationR:{X:-103.4285 Y:-104.1754 Z:104.9243}
我已覆蓋的三維軸到圖像如上所示使用XNA所以我假定相對於相機的旋轉和平移已正確計算出來。
好像我做的事一起來計算平移的方式是錯誤的。我絕對不會指望Z等於104毫米。我期待的線沿線的東西:
{X:0 Y:150 Z:0}類似於此之前