Welcome to RDK X5 Robot repository
2. Adjust the color HSV value
Adjust the color HSV value
2.1 Introduction
This course mainly uses the IMX219 camera to obtain the camera image, select the corresponding color, and then adjust its HSV value to achieve the best recognition effect.
This course mainly optimizes the recognition effect by modifying the image HSV value, and then provides more accurate HSV values for color recognition related routines.
2.2 Core content analysis
g_ENABLE_CHINESE represents the Chinese character switch of the control. The default is False for English characters. If you need to display Chinese, please set it to True.
g_ENABLE_CHINESE = FalseName_widgets = {'Red': ("Red", "红色"),'Green': ("Green", "绿色"),'Blue': ("Blue", "蓝色"),'Yellow': ("Yellow", "黄色"),'Custom': ("Custom", "自定义"),'Close_Camera': ("Close_Camera", "关闭摄像头")}
The range of color HSV values is shown in the figure below:

When you click the color button for the first time, the initial HSV value will be used first. Then you need to 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 to accurately identify the color without confusing it with other colors.
2.3 Operation steps
Open the jupyterLab client and find the code path:
xxxxxxxxxx/home/sunrise/sunriseRobot/Samples/2_AI/02_color_hsv/color_hsv.ipynb
Click to run all cells, then pull to the bottom to see the generated controls.

The control displays three color boxes. The image control on the left displays the original image. The function of the image control in the middle is: the recognized color is displayed as white, and the others are displayed as black. The function of the image control on the right is: the recognized color is displayed normally, and the other colors are displayed as black.
You can put a single color into the camera screen, but in order to get the HSV value more accurately, you can put the four colors of red, green, blue and yellow into the camera screen. Select a color from red, green, blue and yellow. At this time, a √ will appear on the left of the selected color. Please slightly adjust the six sliders to modify the color HSV value so that the selected color is displayed completely and not mixed 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 will be read first. If the local file cannot be read, the default HSV value will be used. If you need to restore the default HSV value, please delete the HSV_VALUE.TXT file of the corresponding color.
For example, select red here. If the color recognition is incomplete or wrong, please slightly adjust the six sliders to modify the HSV value of the color. When the color effect reaches the appropriate effect, click the red button again to save the current HSV value of the color to the local file.

For example, the red color in the above picture is saved in the RED_HSV_VALUE.TXT file, where the HSV value is 0,59,81,10,255,255. The value represents: Hmin,Smin,Vmin,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 to save the value to the GREEN_HSV_VALUE.TXT file.

The blue HSV calibration effect is as follows. After calibration, please click the blue button again to save the value to the BLUE_HSV_VALUE.TXT file.

The yellow HSV calibration effect is as follows. After calibration, please click the yellow button again to save the value to the YELLOW_HSV_VALUE.TXT file.

Custom color button. After calibration, please click the custom button again to save the value to the CUSTOM_HSV_VALUE.TXT file.
Finally, click the Close_Camera button to close the camera.