Ask Your Question
9

max and min values in a Mat

asked 2014-01-27 04:54:43 -0600

ati gravatar image

updated 2020-11-30 00:53:37 -0600

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
16

answered 2014-01-27 05:05:34 -0600

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);
edit flag offensive delete link more

Comments

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

opencvnoob29838 gravatar imageopencvnoob29838 ( 2015-05-01 16:17:15 -0600 )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 ( 2015-05-03 05:25:53 -0600 )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 ( 2015-12-10 07:43:45 -0600 )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 ( 2015-12-10 07:44:41 -0600 )edit

Probably you print the points wrongly.

Guanta gravatar imageGuanta ( 2015-12-11 05:46:43 -0600 )edit

Question Tools

Stats

Asked: 2014-01-27 04:54:43 -0600

Seen: 156,803 times

Last updated: Jan 27 '14