0
votes

I want to pick the color range from pink to yellow to put the range in inRange() function. However I can only pick from pink to red and red to yellow separately.

For pink to red the H value is from 125 to 255, then red to yellow is 0 to 10.

What is the value for the range i should put in?

Update #1

The way to use in range is

Core.inRange(mRgba, new Scalar(0, 100, 30), new Scalar(10, 255, 255), yellowMat); Core.inRange(mRgba, new Scalar(125, 100, 30), new Scalar(255, 255, 255), pinkMat);

Scalar doesn't accept value that's greater than 255.

1
I think the question has nothing to do with opencv... but Pink to Red is 300 -> 360, Red to Yellow is 360/0 -> 60 if the issue you have is creating a single range 300 -> 360 -> 0 -> 60 you can define a range of 300 -> 420 and use modulo 360 - Rosa Gronchi
what exactly you want to filter? Do u want to filter only Pink & Yellow or you want to filter all the colors in between this colors? - Balaji R

1 Answers

1
votes

Alternatively, you can make a left circular shift for each H value by 125. Thereafter pink to red is 0-130, and red to yellow 131-141 -> the range is 0-141. After inRange() don't forget to rotate back the H channel.

Update #1:
Okay, so there are more options. Firstly:

Core.inRange(mRgba, new Scalar(0, 100, 30), new Scalar(10, 255, 255), yellowMat); 
Core.inRange(mRgba, new Scalar(125, 100, 30), new Scalar(255, 255, 255), pinkMat); 
Core.bitwise_or(yellowMat, pinkMat, pinkToYellowMat);

Secondly, you can calculate Hue channel in range 0..255 with CV_BGR2HSV_FULL and then the image's colors can be 'rotated', so that:

Imgproc.cvtColor(imageBgr, imageHsv, CV_BGR2HSV_FULL);
Core.add(imageHsv, new Scalar(-125, 0, 0), imageHsv);
Core.inRange(imageHsv, new Scalar(0, 100, 30), new Scalar(141, 255, 255), pinkToYellowMat);

I couldn't try the examples. The second may not work, you wrote

Scalar doesn't accept value that's greater than 255

and I'm not sure that it can accept values less then zero.