Ask Your Question

Revision history [back]

HSV v RGB with inRange

I used a colour picker and worked out equivalent range values in HSV and RGB for my special yellow.

Scalar yellowHsvMin = new Scalar(50, 35, 40);
Scalar yellowHsvMax = new Scalar(55, 91, 71);

Scalar yellowRgbMin = new Scalar(139, 127, 66);
Scalar yellowRgbMax = new Scalar(249, 238, 114);

But when I apply a filter using the HSV values:

Mat raw = Imgcodecs.imread("file.jpg");
Matt colours = new Matt(raw.size(), raw.type());
Matt yel = new Matt(raw.size(), raw.type());
Imgproc.cvtColor(raw, colours, Imgproc.COLOR_BGR2HSV);
Core.inRange(colours, yellowHsvMin, yellowHsvMax, yel);

I get a hugely different answer to using RGB values:

Mat raw = Imgcodecs.imread("file.jpg");
Matt colours = new Matt(raw.size(), raw.type());
Matt yel = new Matt(raw.size(), raw.type());
Imgproc.cvtColor(raw, colours, Imgproc.COLOR_BGR2RGB);
Core.inRange(colours, yellowRgbMin, yellowRgbMax, yel);

I would expect it to be slightly different from rounding errors etc but it's completely different. Can anyone help me understand what I'm doing wrong?