【问题标题】:Understanding Reduce() function exception: Unsupported combination of input and output array formats了解 Reduce() 函数异常:输入和输出数组格式的不支持组合
【发布时间】:2019-07-11 14:27:03
【问题描述】:

我是 OpenCV 新手,我想学习如何正确使用函数 reduce()。

OpenCVSharp中函数说明:https://shimat.github.io/opencvsharp_docs/html/7bb05237-7ff6-0e19-bfeb-36ea352b3051.htm

我创建了一个自定义 Mat 对象并在其上应用了 Reduce 函数。

        int[,] mat2d = new int[,] 
        { 
            { 0, 0, 0, 5, 10, 15, 15, 15, 15, 10, 5, 0, 0, 0 }, 
            { 0, 0, 0, 5, 10, 15, 15, 15, 15, 10, 5, 0, 0, 0 },
            { 0, 0, 0, 5, 10, 15, 15, 15, 15, 10, 5, 0, 0, 0 },
            { 0, 0, 0, 5, 10, 15, 15, 15, 15, 10, 5, 0, 0, 0 },
        };
        Mat testMat = new Mat(4, 14, MatType.CV_32S, mat2d);
        Mat reducedMat = testMat.Reduce(ReduceDimension.Row, 
                                           ReduceTypes.Sum, 
                                           MatType.CV_32S);

我期望 reduceMat 将是一个一维数组,其中索引 i 处的每个元素都包含 testMat 中第 i 行的总和。

不幸的是,我得到一个异常“OpenCVException:输入和输出数组格式的不支持组合”。

我还尝试将 ReduceDimension 参数和 dtype 参数更改为每个可能的选项,但没有任何成功。

【问题讨论】:

    标签: c# opencv opencvsharp


    【解决方案1】:

    答案是将int[,] mat2d 替换为byte[,] mat2d

    原来int 不是有效的reduce类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 2019-11-09
      • 1970-01-01
      • 2017-07-11
      • 2018-07-25
      • 1970-01-01
      相关资源
      最近更新 更多