Skip to content Skip to sidebar Skip to footer

What Is The Range Of Hsv Values For Brown Color In Opencv?

I am new to openCV. I am already able to count green and yellow pixels of an image with a mask. I would like to know what is the HSV range of Brown in openCV. private void test

Solution 1:

You can check out my answer here which goes in-depth on how to plot/view a range of different HSV values.

You can also check out external sites which let you play around with values to get an idea of the colorspace. In HSV, browns correspond to higher saturation level (lower values become more gray) and middle value levels (low is black, high is white), and the hue is between (roughly) 20 degrees for a reddish brick color to 40 degrees for a sand color. But in OpenCV, the hue degrees are divided by two to get them to fit under 255, so thats more like 10 to 20 for the hue values.

Using the code in the linked answer, I generated this gif of a range of brown values from [10, 100, 20] to [20, 255, 200] in HSV:

Brown values

This seems to encompass most ideas of brown, but you can play with the values if you want some darker, lighter, grayer, etc ones to appear.

Another way to play around with finding good thresholding values is to create a program that lets you try it out. For example, I built a tool in python and OpenCV similar to the magic wand selector in photoshop, which lets you define a threshold, click a pixel, and it will select pixels of a similar color connected to where you clicked. This tool will print out the highest and lowest color values, and also will print out the mean color and standard deviation for better control of thresholding values similar to the color you selected. You can see a little gif of it being used here.

One more way to play around with values is to create trackbars with OpenCV giving all the minimum and maximum thresholding values, and having the screen update with the thresholded image every time you change a value. I built a tool for this as well in python and OpenCV. You can see a little gif of it being used here.

If you peruse the code for both those projects, you can get an idea of how to build similar programs to toy around with values to get more comfortable working in different colorspaces.

Solution 2:

Also, from Wiki: Color coordinates

"HSV (h, s, v) (30°, 100%, 59%)",

so "ideal" Open CV Hue value for BROWN is 15, because Hue for OpenCV 8-bit images is Hue/2, so 30 / 2 = 15. Also 100% for Saturation means 255 (because 255 is max value of Scalar channel in Open CV) and 59% for Value for means (59 / 100) * 255 = 150 for Scalar channel. So, "ideal" BROWN Scalar() is:

Scalarideal_brown=newScalar(15,255,150);

To add some "near to BROWN" colored pixels, you can:

1) subtract some value from Hue for "more red" colored pixels;

2) add some value to Hue for "more green" colored pixels;

3) subtract some value from Saturation for "less colored" pixels (you can't add because 255 is already max value);

4) subtract some value from Value for "more darker" pixels;

5) add some value to Value for "more lighter" pixels.

So,

Scalar min_brown = new Scalar(15-<delta1_for_hue>,255-<delta1_for_saturation>,150-<delta1_for_value>);
Scalar max_brown = new Scalar(15+<delta2_for_hue>,255,<delta2_for_saturation>,150+<delta2_for_value>);

Also, take a look at this answer of Miki.

Post a Comment for "What Is The Range Of Hsv Values For Brown Color In Opencv?"