c# - opencvsharp:如何将MatExpr更改为Mat

时间:2015-05-26 10:26:09

标签: c# opencvsharp

        Mat a = new Mat(3, 1, MatType.CV_8UC1);
        Mat b = new Mat(1,3, MatType.CV_8UC1);

        for( int i = 0; i < 3; i++ )
        {
            a.Set<byte>(i, 0, (byte)i);
            b.Set<byte>(0, i, (byte)(i + 3));
        }
        var c = a * b;  
        mat = c.ToMat(); // error

a.Mul(b)的结果是MatExpr类
我想创建3x3矩阵 我该如何制作Mat Class?

1 个答案:

答案 0 :(得分:-1)

自我答案:Opencv的矩阵乘法仅支持双重类型 如果要以字节格式计算,请参阅此内容。

        Mat a = new Mat(3, 1, MatType.CV_64FC1, new double[] { 1.0, 2.0, 3.0 });
        Mat b = new Mat(1, 3, MatType.CV_64FC1, new double[] { 4.0, 5.0, 6.0 });
        Mat c = new Mat(3, 3, MatType.CV_64FC1);


        var c = (a * b).ToMat();
        c.ConvertTo(c, MatType.CV_8UC1);
        Trace.WriteLine(c.At<byte>(0,0)); // 4