C++ 如何计算和使用 cvMat 平均值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12687437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:31:34  来源:igfitidea点击:

how to calculate and use cvMat mean value

c++opencvmatrixmean

提问by EyalG

In the openCV cheat sheet (C++), I have found the matrix opration mean(). When I use it:

在 openCV 备忘单(C++)中,我找到了矩阵 opration mean()。当我使用它时:

float myMatMean = mean( MyMat );

I get the error:

我收到错误:

no suitable conversion function from "cv::Scalar" to "float" exists

不存在从“cv::Scalar”到“float”的合适转换函数

What can I do in order to use this data?

我该怎么做才能使用这些数据?

回答by EyalG

Thanks.

谢谢。

The problem was that although myMatwas a 2D image. The return type was still a Scalarof size 4.

问题是虽然myMat是 2D 图像。返回类型仍然是Scalar大小为4 的 a

The solution was

解决办法是

cv:Scalar tempVal = mean( myMat );
float myMAtMean = tempVal.val[0];