Ask Your Question
0

inRange with HSV values

asked 2015-01-30 05:18:26 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-01-30 07:29:39 -0600

Dionysos gravatar image

updated 2015-01-30 07:42:44 -0600

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-01-30 05:18:26 -0600

Seen: 3,617 times

Last updated: Jan 30 '15