In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to analyze the HSV color space in OpenCV, I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Preface
In OpenCV, we sometimes extract samples by color, then the HSV color space can be used at this time, mainly to solve the HSV color space, for a basic understanding of HSV. Brief introduction of HSV Color system
HSV is an even more common color system in people's lives. It is common on TV remote controls, in drawing palettes, and when you adjust the brightness with an art video, because it is more in line with the way people describe colors-what color it is, how dark it is, how bright it is.
H--Hue is hue, which is what we usually call red and green. If you divide it in more detail, there may be magenta, grass green, and so on. In the HSV model, hue is described in degrees, where red corresponds to 0 degrees, green corresponds to 120 degrees, and blue corresponds to 240 degrees.
S--Saturation is saturation, color depth (0-100%), for a color such as red, we can use light red-bright red-crimson-purple and other words to describe it (please forgive a pure science student's lack of color system), corresponding to the painting of watercolor, that is, a pigment plus different amounts of water to form different saturation. V--Value means hue, purity, and brightness of colors (0-100%), which is common when adjusting screen brightness.
Note: in model 2: h is the center angle formed by the color point on the corresponding circular section and the red radius (for H = 0 degrees). V is the distance from the circular section of the color point to the cone vertex. On the top surface, the vertex Vroom0S is the proportional value of the distance from the color point to the center of the circular tangent plane and the radius of the circle, on the conical surface, the influence of the value of S = 0HSV on the color at the center of the circle.
For example, the above picture shows the Smuri V plane of Hang 120, and the S and V values increase from left to right and from bottom to top to 1, respectively. We can find the pattern:
On the left side of the picture, the S value is 0, showing varying degrees of gray, determined by the V value.
The V value at the bottom of the picture is 0, showing a black color.
In the upper right corner of the picture, the S and V values are both 1, showing a solid color, with an RGB value of (0,255,0).
Therefore, our conclusions for HSV are as follows:
Any color represented by H is called a solid color when it comes to Spot1 Vist1.
When the saturation is 0, the color is the lightest, and the lightest is described as gray (gray also has brightness, black and white also belong to gray). The brightness of gray is determined by V, and H is meaningless.
When Vroom0, the color is the darkest and the darkest is described as black, so H (black regardless of the darkest color) and S (black no matter the darkest color) are meaningless.
Mutual Transformation between HSV and RGB
RGB ➡ HSV
1. V = max (R, G, B) / 255.0f-Luminance V is the largest of the RGB values to be normalized.
Inference:
One of the solid-color RGB must be 255th. At the same time, it is impossible to have 3 255 RGB values, because 3 255 are white, and white is the product of HGrain1 and Spot0 for any color. The Vogue 1 Swatch 0 is not a solid color. At the same time, if RGB 0, then the maximum value of the three RGB is 0, that is, the GRB is 0, that is, the pixel is black.
2. S = (max (R, G, B)-min (R, G, B)) / (float) max (R, G, B)-saturation S is the ratio of the difference between the maximum and minimum values in RGB.
Inference:
There must be a 0 in the RGB value of the solid color (max 1, G, B), because when RGBMin=0 (R, G, B)-min (R, G, B) = = RGB (R, G, B), I. E. This also shows that white (RGB (255255255) is not a solid color).
When RGBMax-RGBMin==0, or R==G==B, appears in varying degrees of gray (from white to black, the brightness varies from V, because the higher the V, the higher the RGBMax==R==G==B, the brighter the gray). This can also be seen from the rectangle given above.
So for solid colors, there must be a 255and a 0 in RGB.
Formula conversion:
HSV ➡ RGB
The difference between the HSV color system in OpenCV and the above HSV color system is that if you directly use the cvtColor function in OpenCV and set the parameter to CV_BGR2HSV, then the range of H, S and V values obtained is [0180), [0255), [0255), rather than [0360], [0jue 1], [0jue 1]. At this time, we can check the table below to determine the approximate range of colors.
From the result of the output, it is consistent with what we said above.
Another hsv approach-- when we want to revert to the system we first introduced, we only need to add one step-- normalize the bgr of pixels, and then go to hsv and get the same result as we introduced. The code and output are as follows
At this point, the range of the output results is consistent with what was described at the beginning. After reading the above, have you mastered how to analyze the HSV color space in OpenCV? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.