【发布时间】:2023-03-28 03:42:01
【问题描述】:
我正在尝试查找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。
【问题讨论】:
-
也许 imageMatrix 是全零?尝试打印它以查看它包含的内容。
-
感谢星尘_。我将它打印到控制台,但它不是。
-
当我尝试使用
std::max_element(imageMatrix.begin(),imageMatrix.end());时,我收到了错误No matching member function call to begin。我不完全理解<typename_tp>。 -
是的,我明白了,我以为这是一个普通的容器。我认为 OpenCV 有它自己的容器。也许这就是 std::max_element 对它们不起作用的原因。
-
imageMatrix 包含哪些元素?
标签: c++ pointers opencv iterator computer-vision