Reputation: 1
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.
Upvotes: 0
Views: 4769
Reputation: 5354
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.
Upvotes: 1