This course mainly uses the CSI camera of the RDK-X3 board to obtain the picture of the camera, select the corresponding color, and then adjust its HSV value to achieve the best recognition effect.
This course focuses on modifying image HSV values, optimizing the recognition effect, and then providing more accurate HSV values to color recognition routines.
g_ENABLE_CHINESE Specifies whether to enable Chinese characters. By default, the value of g_enable_Chinese is False. If Chinese characters need to be displayed, set the value to True.
xxxxxxxxxx
g_ENABLE_CHINESE = False
Name_widgets = {
'Red': ("Red", "红色"),
'Green': ("Green", "绿色"),
'Blue': ("Blue", "蓝色"),
'Yellow': ("Yellow", "黄色"),
'Custom': ("Custom", "自定义"),
'Close_Camera': ("Close_Camera", "关闭摄像头")
}
The range of color HSV values is shown below:
When you click the color button for the first time, you will first use the initial HSV value, and then fine-tune the value of the slider according to the HSV value of the color to make the color effect more accurate. The final effect is that the color can be accurately identified without confusing the recognition of other colors.
Open the jupyterLab client and find the code path:
xxxxxxxxxx
/root/sunriseRobot/Samples/2_AI/02_color_hsv/color_hsv.ipynb
Click Run All Cells, and then drag to the bottom to see the generated controls.
The control displays three color boxes, the image control on the left shows the original image, the image control in the middle has the function of: the recognized color is displayed as white, and the other is displayed as black, the image control on the right has the function of: the recognized color is displayed normally, and the other colors are displayed as black.
A single color can be put into the camera picture, but in order to get the HSV value more accurately, four colors can be put into the camera picture. Select a color among red, green, blue, and yellow, and a √ will appear to the left of the selected color. Please adjust the six sliders slightly to modify the value of the color HSV, so that the selected color is displayed intact and does not mix with other color blocks, and then click the corresponding color again to save the color HSV value to the local file. Each time a color is selected, the local file is read first, and if the local file cannot be read, the default HSV value is used. If you want to restore the default HSV value, delete the HSV_VALUE.TXT file of the corresponding color.
For example, if the color recognition is incomplete or wrong, please slightly adjust the six sliders to modify the value of the color HSV. When the color effect reaches the appropriate effect, click the red button again to save the value of the current color HSV to the local file.
For example, in the preceding figure, the red color is saved in the RED_HSV_VALUE.TXT file, where the HSV value is 0,59,81,10,255,255. Numerical mean: Hmin, Smin, Vmin and Hmax, Smax, Vmax. This value can be copied and updated to the HSV value of other routines.
The green HSV calibration effect is as follows. After calibration, please click the green button again and save the value to GREEN_HSV_VALUE.TXT file.
The blue HSV calibration effect is as follows. After calibration, please click the blue button again and save the value to BLUE_HSV_VALUE.TXT file.
The yellow HSV calibration effect is as follows. After calibration, please click the yellow button again and save the value to YELLOW_HSV_VALUE.TXT file.
After calibration, click the custom button again and save the value to the CUSTOM_HSV_VALUE.TXT file.
Finally click the Close_Camera button to close the camera.