[英]How to perform a matrix transform function on a lists of lists c#
我有一個MCvPoint3D32f類型的列表列表。 MCvPoint3D32f點是包含(x,y,z)浮點值的EmguCV類型3D點。 此列表存儲一個正方形的4個角點。 例如Square 0將具有4個角點Square [0] [0],Square [0] [1 .... Square [0] [3]等。
存儲的角的順序與我想要的順序不一致。 例如,存儲在Square 1中的角點包含Square 3的角點,Square 6的Square 2的角點等。矩陣轉換是我要在列表中執行的操作。
我正在嘗試這樣做,但是由於這不是普通數組而是列表列表。 我沒有以正確的方式訪問或設置值。我得到了超出范圍的數組范圍錯誤。 有沒有更好的方法來實現我想要做的事情?
List<List<MCvPoint3D32f>> tempList = new List<List<MCvPoint3D32f>>();
SortMatrixIndex(Matrix);
private void SortMatrixIndex(List<List<MCvPoint3D32f>> matrix)
{
for (int i = 0; i < matrix.Count; i++)
{
if (i == 0 || i == 3 || i == 4 || i == 8)
{
tempList[i] = matrix[i];
}
else if (i == 5)
{
tempList[i] = matrix[i];
matrix[i] = matrix[i + 2];
matrix[i + 2] = tempList[i];
}
else
{
tempList[i] = matrix[i];
matrix[i] = matrix[i * 3];
matrix[i * 3] = tempList[i];
}
}
}
這可能不是解決上述問題的最佳方法,因為它對於3x3矩陣幾乎是硬編碼的,但現在可以使用。
private void TransposeMatrix(List<List<MCvPoint3D32f>> matrix)
{
//This case applies to both N and W, however N needs column swapping too
for (int i = 0; i < matrix.Count; i++)
{
tempList.Add(new List<MCvPoint3D32f>());
if (i == 1 || i == 2)
{
tempList[i] = matrix[i];
matrix[i] = matrix[i * 3];
matrix[i * 3] = tempList[i];
}
else if (i == 5)
{
tempList[i] = matrix[i];
matrix[i] = matrix[i + 2];
matrix[i + 2] = tempList[i];
}
else
{
tempList[i] = matrix[i];
}
}
tempList.Clear();
this.squareMatt = matrix;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.