C# opencvsharp学习笔记 (mat转array)

  • opencvsharp函数
    public void GetArray(int row, int col, data);
    row:起始行
    col:起始列
    data:输出数据,包含类型byte[],byte[,],int[],double[],Vec3b[]等等
  • 调用方法
    Mat.GetArray

例子1:

//设置一个1*4的数组a
byte[] a = new byte[4] { 1, 3, 2, 4 };
//将数组a放入mat类型aa中
Mat aa = new Mat(1,4,MatType.CV_8UC1,a);
//初始化一个类型为byte一维长度为4的数组b
byte[] b = new byte[4];
//mat类型aa转数组b
aa.GetArray(0,0,b);
//验证正确性
for (int i = 0;i < 4; i++)
{
   Console.Write(b[i]);
   Console.Write(" ");
}

结果
C# opencvsharp学习笔记 (mat转array)_第1张图片
例子2:

byte[,] a = new byte[2, 4] { { 1, 3, 2, 4 },{ 4,5,6,7} };
Mat aa = new Mat(2,4,MatType.CV_8UC1,a);
byte[,] b = new byte[2,4];
aa.GetArray(1,1,b);
for (int i = 0;i < 2; i++)
{
   for (int j = 0; j < 4; j++)
   {
      Console.Write(b[i,j]);
      Console.Write(" ");
   }
   Console.WriteLine(" ");
}

结果
C# opencvsharp学习笔记 (mat转array)_第2张图片

你可能感兴趣的:(C# opencvsharp学习笔记 (mat转array))