gpt4 book ai didi

c++ - 查找 cv::Mat 的最大值

转载 作者:IT老高 更新时间:2023-10-28 22:23:55 31 4
gpt4 key购买 nike

我正在尝试查找 cv::Mat 的最大像素值。

问题:*maxValue 总是返回 0

来自 this S.O. thread ,我知道 'max_element 返回迭代器,而不是值。这就是我使用 *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

最佳答案

您应该使用 OpenCV 内置函数 minMaxLoc 而不是 std 函数。

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;

关于c++ - 查找 cv::Mat 的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15955305/

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