Accurate measurement of the gap between the lower surface of the relay and the ground is critical for ensuring the quality of the finished product. Traditional gap measurement methods have some shortcomings, such as low accuracy, poor robustness, and loss of depth clues in obscured areas. In this study, a novel gap measurement method based on computer vision is proposed, which includes a projection line model based on guided filtering and a 3D surface point cloud model based on a three dimensional plane reference.- The relay gap was measured by calculating the projection lines of the upper and lower surfaces of the gap with an error of ±0.016 mm. A 3D point cloud model captures the key features of the underside of the relay through image processing techniques, and combines convex hull and centroid estimation to construct a three-dimensional reference plane for the gap, which could achieve high-precision, real-time measurement of the gap (with an error less than ±0.0087 mm). The experimental measurement results show that the proposed method is better than the SelfConvNet method, which has a high measurement accuracy and strong anti-interference ability, and an accuracy rate of up to 99.5% in factory relay quality inspection experiments.