I was using OpenCV’s cv::minMaxLoc()
funtion in my code. But due to some restrictions on the device, I can’t call it from OpenCV and have to implement it myself from scratch. But it doesn’t work as expected. What is the issue with the code?
The way I was calling through OpenCV:
double minScore, maxScore;
cv::Point minClassLoc, maxClassLoc;
cv::minMaxLoc(classes_scores, &minScore, &maxScore, &minClassLoc, &maxClassLoc);
And my manual implementation:
void minMaxLoc(cv::Mat& input, double* minVal, double* maxVal, cv::Point* minLoc, cv::Point* maxLoc) {
int rows = input.rows;
int cols = input.cols;
int minRow = 0, minCol = 0, maxRow = 0, maxCol = 0;
double minValue = input.at<double>(0, 0);
double maxValue = input.at<double>(0, 0);
for (int row = 0; row < rows; ++row) {
const double* rowData = input.ptr<double>(row);
for (int col = 0; col < cols; ++col) {
double value = rowData[col];
if (value < minValue) {
minValue = value;
minRow = row;
minCol = col;
}
if (value > maxValue) {
maxValue = value;
maxRow = row;
maxCol = col;
}
}
}
*minVal = minValue;
*maxVal = maxValue;
*minLoc = cv::Point(minCol, minRow);
*maxLoc = cv::Point(maxCol, maxRow);
}