OpenCV study notes (10) HSV color space conversion and color space (RGB-HSV)

1.1 Color Space Introduction


RGB color space is the most familiar color space, that is, three-color space, any color can be made by mixing the three colors. In general, however image color space efficient processing is performed in the HSV space, HSV (hue Hue, Saturation, Saturation, Brightness Value) color space is a color created by a visual characteristic, also known as hexagonal pyramid model.

Reference: https: //


Why did you choose HSV space instead of RGB space? For images, identify the appropriate color space in RGB, HSV color space or other space are possible. Chose HSV, since the hue H is represented by a color can be determined basically, combined saturation and brightness information determining a threshold larger than a certain value. And it consists of three RGB components, necessary to determine the contribution ratio of each component. I.e. a broader recognition of HSV space, and more convenient.


1-1 HSV color space model of FIG.


1.2 three color space conversion (gray BGR HSV)


There are ways color space conversion of more than 150 kinds in the OpenCV, but also we often use only two, namely BGR-> Gray and BGR-> HSV. Note that Gray and HSV can not interchangeable. Color space conversion: cv2.cvtColor (input_image, flag)

BGR-> Gray: flag is cv2.COLOR_BGR2GRAY

BGR-> HSV: flag is cv2.COLOR_BGR2HSV


OpenCV in HSV color space ranges:

H [0, 179] S [0, 255] V [0, 255]



In the range of colors used in FIG 1-2


Demo, source programs are located /home/pi/yahboom/colorBlcok/


Figures 1-3 identify the color space conversion in the yellow and red image portion





In this program, we first contact with the mask, to mask some small partner may not understand the concept of a mask is not a good understanding of the description, it can be understood as a bitmap and can be expanded and other corrosion morphology operation. We just need to know, in the region of interest extraction, mask image for some areas, special structural feature extraction and image production are likely to use a mask, you can.


progress: self trying to achieve recognition of a plurality of colors.




Guess you like