Ask Your Question
9

max and min values in a Mat

asked Jan 27 '14

ati gravatar image

updated Nov 30 '0

Hi..How do I get the max and min value in a Mat? Is there any function in Opencv which return these two values?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
16

answered Jan 27 '14

Guanta gravatar image

minMaxLoc(), see http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=minmaxloc#minmaxloc

Usage:

double min, max;
cv::minMaxLoc(your_mat, &min, &max);

The function can also give you the location of the min and max-values:

cv::Point min_loc, max_loc
cv::minMaxLoc(your_mat, &min, &max, &min_loc, &max_loc);
Preview: (hide)

Comments

is there any way to do this for a float? or do i have to write my own?

opencvnoob29838 gravatar imageopencvnoob29838 (May 1 '15)edit

Don't worry, you can use the function also for float matrices, just the result will be always double (which you can then cast to float).

Guanta gravatar imageGuanta (May 3 '15)edit

@Guanta, I had tried the code to get the location in a mat for the min and max for the array and the result is like this... What does this mean?

00000000002DF458 00000000002DF438

Thanks

zms gravatar imagezms (Dec 10 '15)edit

@Guanta, I had tried using the code to look on the max and min location. I got these answers. Can I know what is this mean?

00000000002DF458 00000000002DF438

Thanks

zms gravatar imagezms (Dec 10 '15)edit

Probably you print the points wrongly.

Guanta gravatar imageGuanta (Dec 11 '15)edit

Question Tools

Stats

Asked: Jan 27 '14

Seen: 159,034 times

Last updated: Jan 27 '14