HSV values in openCV
Hi,
I've tried to isolate yellow-orange-ish color from an image, using inRange function.
I've used an online color picker (https://pinetools.com/image-color-picker)
and than tried to isolate by the values it gave me - even with half of Hue value.
but it failed.
The Hue value that the picker gave me is 30 (tried half - also incorrect) The true value is around 120 - I know this because I've started to 'play' with the value, until I get the desired result.
for future reference, What is wrong here ? The online picker ?
code :
public void colorMask(View view)
{
//Image Input :
Bitmap one =
drawableToBitmap(getResources().getDrawable(R.drawable.dsc_1250, this.getTheme()));
Mat img1 = new Mat();
Utils.bitmapToMat(one, img1, true);// moving one to img1 Mat structure.
//one.recycle(); //Undefined behaviour ..
System.gc();
// downsize the image.
Mat pyrDown = new Mat();
Imgproc.resize(img1, pyrDown, new Size(img1.cols() / 4, img1.rows() / 4));
img1.release();
Mat hsvImg = new Mat();
cvtColor(pyrDown, hsvImg, COLOR_BGR2HSV);
Mat yellowMask = new Mat();
Mat greenMask = new Mat();
inRange(hsvImg, new Scalar(100, 41, 40), new Scalar(130, 255, 255), yellowMask ); // try
Mat res = new Mat();
Mat NotYellowMask= new Mat();
bitwise_not(greenMask, NotYellowMask);
pyrDown.copyTo(res, yellowMask );
Bitmap imageMatched =Bitmap.createBitmap(res.cols(), res.rows(), Bitmap.Config.RGB_565);
Utils.matToBitmap(res, imageMatched);
imageViewMy.setImageBitmap(imageMatched);
}
A piece of code could be helpful. How do you convert rgb image to hsv?
yes I did.. full code : https://pastebin.com/raw/RVB2GYGR
edited.. The true value is still a mystery for me.. around 120~150
your Mat (from
Utils.matToBitmap
) is probably RGBA, not BGR, thus you're looking at the wrong channel ordering ?try
COLOR_RGB2HSV
instead.(just saying, it might be a java/android specific problem)
my code is working.. I just dont understand why .. because the Hue values are allegedly incorrect ..
try with COLOR_RGB2HSV is it helping?