0

I have a cv::Mat of type CV_8U. If I use the cv::minMaxLoc function like so:

cv::Mat img(rows, cols, CV_8U, data);

double minVal, maxVal;
cv::Point minLoc, maxLoc;

cv::minMaxLoc(img, &minVal, &maxVal, &minLoc, &maxLoc);

I get:

maxVal = 255, maxLoc = [127, 126]

Then if I use the following code:

img.at<uint8_t>(maxLoc); //or img.at<uint8_t>(127,126);

Result is 0

I actually get zero for every element of the matrix using both cv::Mat::at and cv::imshow(). But cv::minMaxLoc is giving the correct answer. So I was wondering if anyone had any insight as to why these two functions would not agree.

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39
Jobasha
  • 15
  • 4
  • 2
    In `at` method first index means **row**, second one is **col**. Because `maxLoc` is point with `x = 127`, `y = 126`, so when calling `at` it should be: `img.at(126,127)`. – rafix07 Jan 22 '20 at 05:02
  • You can also check [this post](https://stackoverflow.com/questions/25642532/opencv-pointx-y-represent-column-row-or-row-column) – Yunus Temurlenk Jan 22 '20 at 05:28

0 Answers0