Aiming at the low efficiency and poor adaptability of traditional water level measurement methods, a water level measurement technology based on the residual length ratio of image characters is proposed in this paper. First, by improving YOLOv5, the lightweight MobilenetV3 is used to replace CSPDarkNet53, and the CBAM attention mechanism is introduced to accurately locate the water gauge and the complete "E" character, and obtain the interface area between the residual "E" character and the water. Secondly, by improving U2-Net, the ordinary convolutions of RSU4-RSU7 in the decoding phase are replaced by depth-separable convolutions, and the ECA attention mechanism is introduced to improve the overall inference speed and accuracy to achieve the residual "E" character and the precise segmentation of water bodies. Finally, the water level value is calculated based on the residual length ratio of the characters. The experimental results show that the accuracy of the improved YOLOv5 is 98.12%, the average intersection over union ratio of the improved U2-Net is 86.23%, and the measurement error of water level is less than 1 cm, which meets the requirements of hydrological detection specifications. At the same time, the improved model reduces the number of parameters and computational complexity, which increases the speed of inference.