Color recognition based on OpenCV
Color model
The commonly used models in digital image processing are RGB (red, green, blue) model and HSV (hue, saturation, brightness). RGB is widely used in color monitors and color video cameras. Our daily pictures are generally RGB models. The HSV model is more in line with the way people describe and interpret colors. The color description of HSV is natural and very intuitive to people.
HSV model
The color parameters in the HSV model are: hue (H: hue), saturation (S: saturation), and brightness (V: value). A color space created by AR Smith in 1978, also known as the Hexcone Model.
Hue (H): measured in degrees, ranging from 0° to 360°, starting from red and counting counterclockwise, red is 0°, green is 120°, and blue is 240°. Their complementary colors are: yellow is 60°, cyan is 180°, and magenta is 300°;
Saturation (S): ranges from 0.0 to 1.0, the larger the value, the more saturated the color.
Brightness (V): ranges from 0 (black) to 255 (white).
Convert RGB to HSV
Let (r, g, b) be the red, green, and blue coordinates of a color, respectively, and their values are real numbers between 0 and 1. Let max be equivalent to the maximum of r, g, and b. Let min be equal to the minimum of these values. To find the (h, s, v) value in HSV space, where h ∈ [0, 360) is the hue angle, and s, v ∈ [0,1] are the saturation and brightness. There is a function under OpenCV that can directly convert the RGB model to the HSV model. In OpenCV, H ∈ [0, 180), S ∈ [0, 255], V ∈ [0, 255]. We know that the H component can basically represent the color of an object, but the values of S and V must also be within a certain range, because S represents the degree of mixing of the color represented by H and white, that is, the smaller the S, the whiter the color, that is, the lighter; V represents the degree of mixing of the color represented by H and black, that is, the smaller the V, the darker the color. The value of blue is roughly 100 to 140 for H, and 90 to 255 for S and V.
|