Río*_*ire 17 c++ opencv pointers iterator computer-vision
我试图找到a的最大像素值cv::Mat.
问题:*maxValue总是回归0.
从这个SO线程,我理解' 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;
Run Code Online (Sandbox Code Playgroud)
注意:如果min_element替换代替max_element,则minValue代替maxValue,*minValue将始终返回0.
shi*_*mar 37
您应该使用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;
Run Code Online (Sandbox Code Playgroud)