private string Dump(Array data, List<int> indices, int dimension = 0)
{
string result = "[ ";
for (var i = 0; i < data.GetLength(dimension); i++)
{
if (dimension == data.Rank - 1)
{
var temp = data.GetValue(indices.Concat(new int[] { i }).ToArray()).ToString();
temp = Regex.Replace(temp, @"(Vec[2346][bdfisw] )|([xyz]:)", "");
temp = Regex.Replace(temp, @"\(", "[");
temp = Regex.Replace(temp, @"\)", "]");
result += temp;
if (i != data.GetLength(dimension) - 1) result += ", ";
}
else
{
result += Dump(data, indices.Concat(new int[] { i }).ToList(), dimension + 1);
if (i != data.GetLength(dimension) - 1) result += ", ";
}
}
return result += " ]";
}
private void Test()
{
byte[,] array = { { 255, 255, 255, 255, 255, 255, 255, 255 },
{ 255, 255, 255, 255, 255, 255, 255, 255 },
{ 255, 255, 0, 0, 0, 0, 255, 255 },
{ 255, 255, 255, 255, 255, 255, 255, 255 },
{ 255, 255, 255, 255, 255, 255, 255, 255 },
};
Mat mat = InputArray.Create(array).GetMat();
mat.GetRectangularArray(out byte[,] data);
string dump = Dump(data, new List<int>());
Console.WriteLine(dump);
}
結果:
[ [ 255, 255, 255, 255, 255, 255, 255, 255 ],
[ 255, 255, 255, 255, 255, 255, 255, 255 ],
[ 255, 255, 0, 0, 0, 0, 255, 255 ],
[ 255, 255, 255, 255, 255, 255, 255, 255 ],
[ 255, 255, 255, 255, 255, 255, 255, 255 ] ]