Find maximum value of a cv::Mat(查找 cv::Mat 的最大值)
问题描述
我正在尝试查找 cv::Mat
的最大像素值.
I am trying to find the maximum pixel value of a cv::Mat
.
问题:*maxValue
总是返回 0
.
来自 这个 S.O.线程,我知道 'max_element
返回迭代器,而不是值.这就是我使用 *maxValue
'
From this S.O. thread, I understand that 'max_element
return iterators, not values. This is why I use *maxValue
'
cv::Mat imageMatrix;
double sigmaX = 0.0;
int ddepth = CV_16S; // ddepth – The desired depth of the destination image
cv::GaussianBlur( [self cvMatFromUIImage:imageToProcess], imageMatrix, cv::Size(3,3), sigmaX);
cv::Laplacian(imageMatrix, imageMatrix, ddepth, 1);
std::max_element(imageMatrix.begin(),imageMatrix.end());
std::cout << "The maximum value is : " << *maxValue << std::endl;
注意:如果用 min_element
代替 max_element
,用 minValue
代替 maxValue
,*minValue
将始终返回 0
.
Note : If min_element
is substituted in place of max_element
, and minValue
in place of maxValue
, *minValue
will always return 0
.
推荐答案
你应该使用 OpenCV 内置函数 minMaxLoc
而不是 std
函数.
You should use the OpenCV built-in function minMaxLoc
instead of std
function.
Mat m;
//Initialize m
double minVal;
double maxVal;
Point minLoc;
Point maxLoc;
minMaxLoc( m, &minVal, &maxVal, &minLoc, &maxLoc );
cout << "min val: " << minVal << endl;
cout << "max val: " << maxVal << endl;
这篇关于查找 cv::Mat 的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:查找 cv::Mat 的最大值


基础教程推荐
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- C++,'if' 表达式中的变量声明 2021-01-01