gpt4 book ai didi

c# - 了解 Reduce() 函数异常 : Unsupported combination of input and output array formats

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:05 26 4
gpt4 key购买 nike

我是 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);

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

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

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

最佳答案

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

事实证明 int 不是 reduce 的有效类型。

关于c# - 了解 Reduce() 函数异常 : Unsupported combination of input and output array formats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54743297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com