Ask Your Question

min and max values hsv in an image

asked 2016-09-22 03:56:45 -0500

zms gravatar image

Hi, Im trying to get the value for the max for S and V inside an image. In this example, the mean of the value can be obtained, but how to get the max and min?

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>

using namespace cv;

int main(void)
    vector<Mat> channels;
    Mat img = imread("Documents/forest.jpg");
    cvtColor(img, img, CV_BGR2HSV);
    split(img, channels);
    Scalar m = mean(channels[0]);
    printf("%f\n", m[0]);

    return 0;
edit retag flag offensive close merge delete


@berak what is your opinion on deleting this. there is a post a bit more detailed

sturkmen gravatar imagesturkmen ( 2017-09-03 16:31:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-09-22 05:02:22 -0500

berak gravatar image

minMaxLoc() will do the trick !

double  minVal, maxVal;
Point minPos, maxPos;

minMaxLoc( channel[0], &minVal, &maxVal, &minPos, &maxPos );
edit flag offensive delete link more


it works! thanks

zms gravatar imagezms ( 2016-09-22 07:58:27 -0500 )edit

Question Tools

1 follower


Asked: 2016-09-22 03:56:45 -0500

Seen: 2,660 times

Last updated: Sep 22 '16