Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

inRange with HSV values

I was wondering how to use inRange function with HSV values as range instead of RGB.

Mat image = imread("pic.png", 1);
Mat mask = Mat::zero(image.size(), 8UC3);
Mat output = image.clone();

Scalar min = Scalar(20, 50, 50); //HSV VALUE
Scalar max = Scalar(25, 255, 255); //HSV VALUE
Scalar blue = Scalar(255, 0, 0);  //BGR VALUE
inRange(image, min, max, mask);
output.setTo(blue, mask);

The inRange function seem to take in BGR values but not HSV. How would I go about modifying the code so that inRange would filter by HSV?