First time here? Check out the FAQ!

Ask Your Question
0

inRange with HSV values

asked Jan 30 '15

Terrible Child gravatar image

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
3

answered Jan 30 '15

Dionysos gravatar image

updated Jan 30 '15

Convert your image to HSV using the cvtcolor function before feeding it to inRange

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Jan 30 '15

Seen: 3,704 times

Last updated: Jan 30 '15