Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying the range of a color in HSV using openCV

Tags:

python

opencv

I am working on identifying the color yellow using openCV in python. I have come to this step where I have to define the lower and upper range of the color yellow in HSV.

Example for defining the range of Blue:

lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])

The HSV is usually defined in percentage, I want to know how to define the range for yellow like the example.

This is the colorspaces tutorial I've been following.

Edit: There are some suggestions in the blog mentioned above, but it does not give me the desired output.

like image 271
Harish Avatar asked Apr 23 '16 22:04

Harish


People also ask

What is the range of HSV?

1. HSV Color Scale: The HSV (which stands for Hue Saturation Value) scale provides a numerical readout of your image that corresponds to the color names contained therein. Hue is measured in degrees from 0 to 360.

What is HSV color OpenCV?

HSV color space: It stores color information in a cylindrical representation of RGB color points. It attempts to depict the colors as perceived by the human eye. Hue value varies from 0-179, Saturation value varies from 0-255 and Value value varies from 0-255. It is mostly used for color segmentation purpose.

How does HSV work on OpenCV?

The HSV or Hue, Saturation and Value of a given object is the color space associated with the object in OpenCV where Hue represents the color, Saturation represents the greyness and Value represents the brightness and it is used to solve the problems related to computer vision because of its better performance when ...


2 Answers

You can use this sample color palette. First value is the upper limit and second value is the lower limit

color_dict_HSV = {'black': [[180, 255, 30], [0, 0, 0]],
              'white': [[180, 18, 255], [0, 0, 231]],
              'red1': [[180, 255, 255], [159, 50, 70]],
              'red2': [[9, 255, 255], [0, 50, 70]],
              'green': [[89, 255, 255], [36, 50, 70]],
              'blue': [[128, 255, 255], [90, 50, 70]],
              'yellow': [[35, 255, 255], [25, 50, 70]],
              'purple': [[158, 255, 255], [129, 50, 70]],
              'orange': [[24, 255, 255], [10, 50, 70]],
              'gray': [[180, 18, 230], [0, 0, 40]]}
like image 194
Ali Hashemian Avatar answered Oct 13 '22 12:10

Ali Hashemian


if i want to do it ,first find rgb numbers for yellow (i use 'Edit colors 'in paint) then change them to HSV whith this method:

 u = np.uint8([[[0,236,236]]])
 # define range of blue color in HSV
 lower_yellow = np.array(cv2.cvtColor(l,cv2.COLOR_BGR2HSV))
 upper_yellow = np.array( cv2.cvtColor(u,cv2.COLOR_BGR2HSV))```

like image 36
Soma Avatar answered Oct 13 '22 11:10

Soma