Abstract:Dimensional measurement is a critical step in the visual inspection of industrial products. Traditional contact-based measurement methods suffer from low efficiency and significant susceptibility to subjective factors. Meanwhile, vision-based measurement requires tailored dimensional boundary extraction schemes for different objects, and high-precision 3D measurement techniques often involve high development complexity and limited applicability. To address these challenges, this study proposes a non-contact method for measuring main workpiece parameters based on the segment anything model 2 (SAM2) with RGB-D coordinate transformation. First, the mask segmentation performance of four traditional image segmentation algorithms—threshold segmentation, edge segmentation, color space segmentation, and GrabCut segmentation—is evaluated. Among them, GrabCut segmentation, identified as the optimal traditional method, is compared with mainstream deep learning segmentation algorithms and SAM2 to demonstrate the superiority of SAM2. Subsequently, a binocular stereo vision experimental platform is constructed to capture high-precision point clouds of workpieces. The point clouds undergo processing steps such as filtering, smoothing, and hole filling. Depth maps and RGB images of the target workpieces are then acquired. Leveraging SAM2′s zero-shot generalization capability, high-precision target segmentation is achieved on RGB images through positive and negative point interaction guidance, yielding initial masks. These masks are further refined via morphological optimization and connected component analysis to generate topologically closed smooth masks. A feature skeleton is extracted using principal component analysis (PCA). Finally, perpendicular segments are generated along the skeleton, and geometric parameters are calculated by integrating 3D coordinates from the aligned depth maps. The measurement results of the proposed method are analyzed by comparing them with those obtained using digital calipers and point cloud data. Experimental results demonstrate that, in measurements of sleeves, pliers, and motors, the mean absolute error for sleeve diameter is 0.0175 mm, while the mean absolute errors for plier and motor parameters are 0.028 3 and 0.023 7 mm, respectively, all meeting the required precision standards.