With the advancement of artificial intelligence, visual ranging has become a widely researched field. This paper introduces a novel method for distance measurement by evaluating the sharpness of objects in the current frame. It is well known that the image is sharpest at the camera’s focal point and becomes blurry when moving away from it. Leveraging this characteristic, this study utilizes sharpness to achieve distance measurement. Initially, the specific orientation of the target object is identified and located. The image area of the target object is cropped in a certain direction, and its image quality is assessed through sharpness calculation. Subsequently, the relationship between sharpness and distance values is analysed statistically, and a function curve depicting their correlation is plotted. Consequently, the distance between the target object and the detector can be determined based on sharpness with an extremely small margin of error using this method.