A machine vision-based method for measuring nut parameters

By employing rapid binarization segmentation and dynamic parameter correction in machine vision nut parameter measurement, the problem of high precision and robustness in multi-model nut parameter measurement was solved, achieving efficient and accurate detection under low computing power conditions.

CN123118728APending Publication Date: 2026-11-17DALIAN MARITIME UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611537506.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-30
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing machine vision methods for measuring nut parameters cannot simultaneously achieve high precision and robustness for parameters of multiple nut models under low-computing-power, pixel-level real-time detection conditions. In particular, measurement results are prone to errors under the influence of factors such as ambient light fluctuations, surface oil stains and reflections, machine vibration and defocusing, lens distortion and perspective projection errors.

Method used

A fast global binarization segmentation algorithm is used to determine the coarse spatial location and region of interest of the nut. Feature matching is performed in combination with a model database. The pixel-level edge detection threshold and physical size calibration coefficient are dynamically corrected. Morphological edge contour extraction and least square matrix equation analytical fitting are used to achieve accurate measurement of nut parameters.

Benefits of technology

High-precision measurement of parameters for multiple nut models was achieved with low hardware overhead and in a short time, eliminating environmental interference and perspective projection errors, and ensuring high robustness and real-time performance of the inspection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123118728A_ABST
    Figure CN123118728A_ABST
Patent Text Reader

Abstract

This invention provides a machine vision-based method for measuring nut parameters, comprising the following steps: S1, determining the approximate spatial position of the nut to be tested in the image coordinate system and the region of interest surrounding the nut; S2, extracting the contour geometric feature vector that characterizes the nut's specification and identifying the target nominal model of the nut; S3, performing pre-processing dynamic correction to obtain the corrected pixel-level edge detection binarization threshold and real-time physical size calibration coefficient; S4, extracting the morphological edge contour of a single pixel width to obtain a pixel-level closed edge point set; calculating and outputting the nut parameters of the nut to be tested. This invention, while ensuring extreme detection speed and cycle time, achieves near-sub-pixel repeatability accuracy for pixel-level detection, greatly reducing computational power. It is suitable for high-real-time, high-robust, non-contact online precision detection of mixed-model nuts on assembly lines.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and more particularly to a method for measuring nut parameters based on machine vision. Background Technology

[0002] In mass production lines for industrial automation fastener manufacturing and automotive parts assembly, nuts, as core basic fastening components, require precise geometric dimension inspection before shipment, which is a crucial step in quality control of mechanical equipment assembly. Parameters such as the inner diameter of the inner hole, the distance between the outer hexagonal edges, the diagonal distance, and the pitch directly affect the reliability of the fastening connection. Machine vision measurement utilizes industrial cameras and digital image processing technology to capture the multi-dimensional spatial features of the target in a non-contact manner. It uses edge detection algorithms to find edge point sets where grayscale values ​​change abruptly in the image, and then converts the discrete pixel-level dimensions into actual physical dimensions based on pre-calibrated physical equivalent coefficients. Production cycles typically require the inspection of a single component to be completed within milliseconds, necessitating a highly real-time and robust inspection system.

[0003] Traditional contact calipers are slow, prone to human error, and unsuitable for online inspection in multi-model production lines. They have been largely replaced by non-contact machine vision measurement systems based on industrial cameras and digital image processing. Existing high-precision machine vision inspection solutions typically employ computationally intensive floating-point sub-pixel edge detection and interpolation algorithms, such as the Zernike moment operator, Gaussian fitting, and cubic spline interpolation, leveraging large-scale matrix differentiation, polynomial iteration, and high-density floating-point operations to improve edge localization accuracy. To meet real-time requirements, another type of existing technology directly employs traditional pixel-level edge extraction algorithms with low computational cost, such as morphological edge extraction, the Sobel operator, and the Canny pixel-level edge contour operator, combined with fixed binarization thresholds and fixed physical dimension calibration coefficients to complete the measurement. System calibration is usually pre-completed for the bottom stage or standard object distance, and the same set of thresholds and equivalent coefficients are used during the inspection process.

[0004] High-performance subpixel algorithms are prone to causing a surge in system latency during continuous, high-speed, large-batch inspections, leading to pipeline stalls, timing errors, and even missed detections. Pure pixel-level algorithms lack subpixel-level spatial dimension subdivision capabilities, and measurement results are easily affected by the actual industrial environment, resulting in several-pixel-level disordered deviations and severe deformations of the extracted physical geometric boundaries. Fluctuations in ambient lighting and material reflections can reduce local contrast at target edges or alter global grayscale levels. Reflections from processing oil stains further exacerbate grayscale fluctuations, causing the nut outline after fixed binarization threshold segmentation to appear visually bulging outwards or contracting inwards, resulting in measurement errors of up to 2-5 pixels. In multi-model mixed production lines, the materials, surface roughness, and reflectivity of nuts of different nominal specifications vary significantly, making a single fixed threshold operator unusable. High-frequency vibrations in the production line and oil and dust contamination on the lens surface can blur the image focus edges, causing the grayscale gradient at the nut's physical boundary to degenerate from a steep abrupt change to a gradual transition, and the physical edge positioning points extracted by pixel-level segmentation to drift randomly within the transition zone. Ordinary industrial lenses suffer from pincushion or barrel geometric distortions that are difficult to completely eliminate. When the nut under test is located at the exact center of the stage or off to the edge of the field of view, the pixel span occupied by the image sensor creates spatial topological asymmetry, leading to positional distortion errors. Digital images are perspective projections of three-dimensional objects onto a two-dimensional plane; objects with physical thickness exhibit a perspective effect where objects appear larger when closer and smaller when farther away. When multiple nut models, such as M6, M8, M12, and M16, pass through the same inspection station in a mixed and disordered manner, their physical thicknesses vary greatly. The greater the thickness, the shorter the actual object distance from the nut's upper surface to the camera lens, passively increasing the image magnification due to the perspective projection effect. If the system still uniformly uses a fixed equivalent coefficient pre-calibrated for the stage bottom surface multiplied by the pixel span, it will cause a systematic deviation in the final physical measurement results of the inner diameter and side distance of thicker nuts, resulting in significant skewness. These defects limit the application of machine vision measurement in high-precision, high-real-time, and high-robust production lines with large-volume, mixed-model production. Summary of the Invention

[0005] In view of this, the purpose of this invention is to propose a machine vision-based nut parameter measurement method to solve the technical problem that existing nut parameter measurement methods cannot achieve both high precision and high robustness of parameters for multiple nut models under low computing power and pixel-level real-time detection conditions.

[0006] The technical means employed in this invention are as follows: A machine vision-based method for measuring nut parameters includes the following steps: S1. Acquire a single image of the workstation under test using an industrial camera to obtain the original grayscale image of the nut to be tested; use a fast global binarization segmentation algorithm to coarsely measure the original grayscale image to determine the approximate spatial position of the nut to be tested in the image coordinate system. And the region of interest (ROI) surrounding the nut to be tested; S2. Extract the contour geometric feature vector that can characterize the nut's standard specification within the region of interest (ROI) determined in S1. Perform distance matching between the contour geometric feature vector and a pre-set database of standard nut models to identify the target nominal model of the nut to be tested. ; S3. Region of Interest (ROI) and rough spatial location determined by S1. and the target nominal model identified by S2 The pixel-level edge detection binarization threshold and physical size calibration coefficients in the fine measurement stage are dynamically corrected beforehand to obtain the corrected pixel-level edge detection binarization threshold. and real-time physical dimension calibration factor ; S4. Apply the corrected pixel-level edge detection binarization threshold. Within the region of interest (ROI) defined by S1, morphological edge contours with a single pixel width are extracted to obtain a set of pixel-level closed edge points; real-time physical size calibration coefficients are then used. The algorithm performs fast least-squares matrix equation analytical fitting on the pixel-level closed edge point set, calculates and outputs the nut parameters of the nut to be tested.

[0007] Furthermore, S3 specifically includes the following steps: S31. Within the region of interest (ROI) determined in S1, the local grayscale mean and local contrast are calculated in real time, and the target nominal model is determined based on the local grayscale mean, local contrast, and S2. The surface material's reflective properties are used to calculate and refresh the pixel-level edge detection binarization threshold during the fine measurement phase. ; S32. The rough spatial location determined by S1 Based on the relative offset from the optical center point of the image, a preset optical distortion matrix is ​​retrieved, and the spatial distortion correction factor is calculated; simultaneously, based on the target nominal model identified by S2... The system retrieves the corresponding standard thickness H from the standard nut model database preset in S2, calculates the object distance change based on the standard thickness H to quantify the perspective projection error, and substitutes the spatial distortion correction factor and the object distance change into the system calibration formula to dynamically refresh the real-time physical dimension calibration coefficient of the current precision measurement station. .

[0008] Furthermore, in S1, a fast global binarization segmentation algorithm is used to determine the coarse spatial location. The specific methods are as follows: The global segmentation threshold of the original grayscale image is calculated using the Otsu method and then binarized. The largest connected component is extracted using a connected component labeling algorithm, and the geometric centroid of the largest connected component is calculated as the coarse spatial coordinates of the nut to be tested. .

[0009] Furthermore, in S2, the contour geometric feature vector includes the pixel span of the diagonal of the smallest bounding rectangle of the largest connected region, the pixel span of the largest inscribed opposite side of the outer hexagon, and the pixel average from the center of the inner hole to the edge; the standard nut model database stores the nominal size range of M-series standard fasteners.

[0010] Furthermore, in S31, the pixel-level edge detection binarization threshold The formula is as follows:

[0011] In the formula, Based on the basic experience threshold, This represents the local grayscale mean within the region of interest (ROI). Here, C is the dynamic brightness adjustment coefficient based on the grayscale mean, and C is the standard deviation of local contrast within the region of interest (ROI). This is the edge sensitivity correction amount. This is a dedicated calibration constant for the reflective properties of a specific type of material surface.

[0012] Furthermore, in S31, when refreshing the binarization threshold... In addition, it also includes a step of performing fast pixel-level sharpening filtering on image edges: The gradient change rate of the image edges within the Region of Interest (ROI) in the spatial domain is statistically analyzed. When the gradient change rate is lower than a preset sharpness threshold, it is determined that the system has vibration or out-of-focus blur, and a 3×3 window Laplacian sharpening filter matrix is ​​automatically invoked to perform convolution enhancement on the ROI.

[0013] Furthermore, in S32, the real-time physical dimension calibration coefficient The formula is as follows:

[0014] In the formula, L is the standard base calibration coefficient of the camera relative to the bottom stage; H is the standard vertical distance from the camera principal point to the bottom stage; and H is the distance from the target nominal model number. The standard physical thickness is mapped from the database; Based on the coarse coordinates The two-dimensional optical distortion correction factor retrieved from the spatial distortion lookup table.

[0015] Furthermore, in S4, the specific steps for extracting the morphological edge contour with a single pixel width are as follows: Using binarization threshold The region of interest (ROI) is segmented into pixels. A morphological erosion operator with a 3×3 structuring element is used to perform a single erosion on the segmented binary image. The binary image and the eroded image are then subtracted by integers to remove redundant pixels and generate a single-pixel closed edge contour with a width of one pixel.

[0016] Furthermore, in S4, the output nut parameters include the precise inner diameter of the nut's inner circle, the precise distance between opposite sides of the outer hexagonal profile, the precise distance between opposite corners, and the precise pitch; wherein, the specific calculation steps for the precise pitch are as follows: Thread region positioning: Using the center of the nut's inner hole obtained from S4 as the center and the inner hole pixel radius as the reference, construct an annular thread region of interest that encloses the top and bottom of the thread teeth; Radial span extraction: A polar coordinate system is established in the region of interest of the annular thread, and radial scanning is performed along the circumference at a preset angle step to obtain the polar diameter of the thread edge pixel under each polar angle, generating a one-dimensional thread radial span undulation sequence. Noise and Anomaly Handling: Sliding median filtering is used to remove abnormal abrupt changes in the one-dimensional radial span fluctuation sequence of the thread, and one-dimensional Gaussian smoothing filtering is used to smooth the sequence and smooth high-frequency random noise. Peak determination and pitch calculation: The first and second differences are calculated from the smoothed undulation sequence, and the polar angle position corresponding to the screw peak is determined by combining this with a preset peak amplitude threshold. The pixel span between adjacent peaks is calculated and multiplied by the real-time physical size calibration coefficient. The precise pitch is calculated.

[0017] Compared with the prior art, the present invention has the following advantages: This invention, through its innovative control architecture of coarse feature extraction, pre-feedback closed loop, and rapid pixel precision measurement, completely breaks the deadlock of traditional visual measurement, which relies on sub-pixel algorithms with high hardware costs and high computational consumption, or can only use fixed calibration parameters and fixed image processing thresholds. It shifts the focus of precise optimization from traditional post-processing high-complexity floating-point fitting to pre-processing dynamic parameter feedback compensation.

[0018] The entire image processing and parameter calculation chain employs pure integer Boolean operations, 3×3 integer convolution, and simple matrix algebra equations for one-time analytical solution, without any complex floating-point polynomial differentiation or iterative processes. The overall processing time of a single detection algorithm is strictly controlled within 2-3 milliseconds, greatly freeing up the processing power of industrial computers. Before the low-overhead pixel-level morphological operator runs, the system has already perfectly eliminated ambient lighting fluctuations, surface oil reflections, machine vibration defocusing, lens edge optical geometric distortion, and perspective projection magnification errors caused by varying nut thicknesses within the resolution range through coarse measurement feedback. This allows the low-complexity, pixel-level fast algorithm to achieve near-subpixel level excellent repeatability accuracy, perfectly realizing high real-time performance, low hardware overhead, and high robustness precision online detection of multi-type mixed fasteners on mechanical production lines. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a flowchart of the method of the present invention.

[0021] Figure 2 This is a schematic diagram illustrating the visual imaging geometry and magnification compensation principle of the present invention, which addresses the perspective projection error caused by the difference in physical thickness of different nut models, where near objects appear larger than distant objects.

[0022] Figure 3 This is a top-view geometric feature of the nut to be tested and a schematic diagram of the region of interest of the thread.

[0023] In the figure: 1. Industrial camera; 2. Nut to be tested; 3. Base stage reference plane; 21. Morphological boundary of a single pixel at the outer hexagonal angle; 22. Closed edge of a single pixel at the inner hole; 23. Region of interest (ROI) of the annular thread; L. Standard vertical object distance; H. Thickness corresponding to the model; LH. Actual imaging object distance; R. Fitted pixel radius; R in 1. Inner radius of the thread ROI; R out Thread ROI outer radius; W pixel , External hexagonal side margin pixel span; L pixel 1. Diagonal distance from the outer hexagon to the pixel span; θ, polar coordinate polar angle; r(θ), radial span of the thread edge (polar diameter). Detailed Implementation

[0024] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0025] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0026] like Figure 1 As shown, the present invention provides a machine vision-based method for measuring nut parameters, comprising the following steps: S1. Acquire a single image of the workstation under test using an industrial camera to obtain the original grayscale image of the nut to be tested; use a fast global binarization segmentation algorithm to coarsely measure the original grayscale image to determine the approximate spatial position of the nut to be tested in the image coordinate system. And the region of interest (ROI) surrounding the nut to be tested; Specifically, the camera acquires a single image of the target at the test station, and the algorithm uses the low-overhead, pure integer Otsu's method for global coarse measurement, locking the approximate centroid space coordinates of the nut target within seconds. It also cuts out the local ROI that only wraps around the nut, thus locking the subsequent complex calculations completely within the local area.

[0027] S2. Extract the contour geometric feature vector that can characterize the nut's standard specification within the region of interest (ROI) determined in S1. Perform distance matching between the contour geometric feature vector and a pre-set database of standard nut models to identify the target nominal model of the nut to be tested. ; The contour geometric feature vector includes the pixel span of the diagonal of the smallest bounding rectangle of the largest connected region, the pixel span of the largest inscribed opposite side of the outer hexagon, and the pixel average from the center of the inner hole to the edge; the standard nut model database stores the nominal size range of M-series standard fasteners.

[0028] Within the cut-out ROI, basic geometric feature vectors, including the span of the outer rectangle and the approximate span of the inner circle, are extracted. By performing distance interval matching with a locally preset standard nut type feature library, the specific nominal model of the nut to be tested is intelligently identified. .

[0029] S3. Region of Interest (ROI) and rough spatial location determined by S1. and the target nominal model identified by S2 The pixel-level edge detection binarization threshold and physical size calibration coefficients in the fine measurement stage are dynamically corrected beforehand to obtain the corrected pixel-level edge detection binarization threshold. and real-time physical dimension calibration factor ; S31. Within the region of interest (ROI) determined in S1, the local grayscale mean and local contrast are calculated in real time, and the target nominal model is determined based on the local grayscale mean, local contrast, and S2. The surface material's reflective properties are used to calculate and refresh the pixel-level edge detection binarization threshold during the fine measurement phase. ; The pixel-level edge detection binarization threshold The formula is as follows:

[0030] In the formula, Based on the basic experience threshold, This represents the local grayscale mean within the region of interest (ROI). Here, C is the dynamic brightness adjustment coefficient based on the grayscale mean, and C is the standard deviation of local contrast within the region of interest (ROI). This is the edge sensitivity correction amount. This is a dedicated calibration constant for the reflective properties of a specific type of material surface.

[0031] Refreshing the binarization threshold In addition, it also includes a step of performing fast pixel-level sharpening filtering on image edges: The gradient change rate of the image edges within the Region of Interest (ROI) in the spatial domain is statistically analyzed. When the gradient change rate is lower than a preset sharpness threshold, it is determined that the system has vibration or out-of-focus blur, and a 3×3 window Laplacian sharpening filter matrix is ​​automatically invoked to perform convolution enhancement on the ROI.

[0032] This invention uses real-time statistics of the local grayscale mean and standard deviation (representing contrast) within the ROI region, combined with the surface reflectivity of the target nominal model material, to dynamically calculate the pixel-level binarization segmentation threshold for the precision measurement stage. Simultaneously, edge gradients are calculated, and when edges become blurred, a pixel-level 3×3 fast Laplacian sharpening matrix is ​​automatically activated to reduce edge drift caused by lighting reflections and vibrations at the spatial pixel level.

[0033] S32. The rough spatial location determined by S1 Based on the relative offset from the optical center point of the image, a preset optical distortion matrix is ​​retrieved, and the spatial distortion correction factor is calculated; simultaneously, based on the target nominal model identified by S2... The system retrieves the corresponding standard thickness H from the standard nut model database preset in S2, calculates the object distance change based on the standard thickness H to quantify the perspective projection error, and substitutes the spatial distortion correction factor and the object distance change into the system calibration formula to dynamically refresh the real-time physical dimension calibration coefficient of the current precision measurement station. .

[0034] Real-time physical dimension calibration factor The formula is as follows:

[0035] In the formula, L is the standard base calibration coefficient of the camera relative to the bottom stage; H is the standard vertical distance from the camera principal point to the bottom stage; and H is the distance from the target nominal model number. The standard physical thickness is mapped from the database; Based on the coarse coordinates The two-dimensional optical distortion correction factor retrieved from the spatial distortion lookup table.

[0036] This invention will coarsely measure the centroid coordinates Spatial topological position correction is performed using the input lens optical distortion matrix; simultaneously, the identified model number is... The standard physical thickness H corresponding to the object in the industrial specification is mapped in reverse. Based on this height feedback, the true projection magnification under the current actual object distance is calculated, thereby dynamically updating the physical size calibration coefficient. This completely eliminates perspective projection errors and edge distortion errors caused by objects appearing larger when closer and smaller when farther away.

[0037] S4. Apply the corrected pixel-level edge detection binarization threshold. Within the region of interest (ROI) defined by S1, morphological edge contours with a single pixel width are extracted to obtain a set of pixel-level closed edge points; real-time physical size calibration coefficients are then used. The algorithm performs fast least-squares matrix equation analytical fitting on the pixel-level closed edge point set to calculate and output the nut parameters of the nut under test. The output nut parameters include the accurate inner diameter of the nut's inner circle, the accurate side-to-side distance and the accurate diagonal distance of the outer hexagonal profile, and the accurate pitch calculated based on the periodic amplitude fluctuations of the grayscale in the threaded area.

[0038] Specifically, using a binarization threshold The region of interest (ROI) is segmented into pixels. A morphological erosion operator with a 3×3 structuring element is used to perform a single erosion on the segmented binary image. The binary image and the eroded image are then subtracted by integers to remove redundant pixels and generate a single-pixel closed edge contour with a width of one pixel.

[0039] This invention uses the refreshed binarized threshold. The set of closed edge contour points with a width of exactly one pixel was extracted using a pure integer morphological erosion subtraction method that takes very little time. Finally, this set was directly multiplied by the real-time physical dimension calibration coefficient after distortion and perspective correction. The final accurate geometric and physical parameters are output by analytically solving the fast least square matrix equation.

[0040] Example A machine vision-based method for measuring nut parameters includes the following steps: S1. Image preprocessing and coarse positioning; When the nut to be tested enters the optical field of view directly below the industrial camera along the conveyor belt of the industrial automated production line, the front-end photoelectric proximity sensor triggers the camera to perform synchronous exposure and acquire a raw grayscale digital image containing the nut target.

[0041] Since the core metric at this stage is operational response speed, the detection algorithm first uses a 5×5 window median filter to quickly reshape and denoise the acquired original grayscale image, removing random noise and high-frequency electromagnetic glitches commonly found in industrial environments. Subsequently, the Otsu method, which consumes low computational power, is applied to adaptively find the optimal inter-class variance segmentation threshold of the global image grayscale histogram, quickly converting the original grayscale image into a binarized image.

[0042] By employing a connected component labeling algorithm based on pixel neighborhood topology, target connected components in the image whose area dimensions conform to the nominal interval of a standard nut are extracted. The first and zeroth moments of these connected components are then calculated, thereby quickly determining the coarse centroid coordinates of the nut target under test. The algebraic mathematical model for solving it is shown in Table 1 below: Table 1: Mathematical Model for Solving the Spatial Position (Center Coordinates) of the Nut Target during the Coarse Measurement Stage

[0043] Using the centroid space coordinates Using a geometric center, a preset fixed pixel increment is extended outward as a buffer boundary to construct a rectangular region of interest (ROI) that tightly encloses the target nut in the discrete matrix. The algorithm then completely restricts all subsequent fine edge extraction and fitting operations to operate within this ROI, effectively eliminating large-area environmental interference from non-target background areas and significantly compressing the amount of pixel data involved in the calculation by more than 85%.

[0044] S2. Feature extraction and intelligent model recognition; Within the cropped local ROI, since background impurities have been completely removed, the algorithm performs a pixel-level fast row / column edge scan with extremely low time consumption, directly extracts the minimum outer rectangle diagonal pixel span and the maximum inner side pixel span of the outer hexagon of the target connected region, and uses a fast polar coordinate transformation projection method to expand the edge of the circular inner hole inside the nut, quickly extracting the rough pixel radius of the inner hole.

[0045] The extracted basic geometric features are combined into a one-dimensional feature vector, which is then matched with the "Standard Nut Specification and Feature Database" pre-stored locally in the industrial control system based on Euclidean distance. Because the physical differences in design dimensions and offsets between standard nuts of different nominal specifications (such as M6, M8, M10, M12, M16, etc.) in international and national standard fastener specifications are typically greater than 1.5mm, the pixel differences displayed by the sensor in the digital image are extremely large. Therefore, this invention uses a coarse feature vector with low computational overhead to perform multi-level threshold interval matching, which can accurately and intelligently identify and lock the specific nominal specification of the nut being tested with 100% accuracy. .

[0046] S3, multiple forward feedback mechanisms and dynamic parameter compensation; This step is the core control loop of this invention. Its purpose is to use the position and model parameters obtained from the coarse measurements S1 and S2 as back feedback control quantities before the pixel-level rapid precision measurement operator runs, to pre-refresh and correct the algorithm's operating environment and physical projection space. S31. Dynamic feedback correction of pixel-level algorithm operator thresholds to eliminate illumination fluctuations and reflection interference: Analyze the gray-level histogram of the ROI region obtained from the coarse measurement and calculate its mean gray level. The grayscale standard deviation C represents the current local contrast. When local lighting on the production line dims or brightens, or when processing oil stains on the nut surface cause strong local reflections, the overall grayscale histogram may shift or compress. To prevent pixel boundary deviation caused by a fixed threshold leading to thicker or thinner contour edges, this invention establishes a pixel-level adaptive dynamic threshold feedback model:

[0047] In the formula, The behavioral system has a preset basic experience threshold; The behavior is based on the brightness dynamic adjustment coefficient of the real-time grayscale average (the threshold is increased proportionally when the global brightness increases). Behavioral edge sensitivity correction (fine-tuning edge response sensitivity based on contrast standard deviation); The behavior utilizes a dedicated empirical calibration constant (directly retrieved from the standard database along with model identification) tailored to the surface reflectivity characteristics of materials of specific specifications and models. The precision measurement algorithm dynamically calculates and updates the dynamic precision measurement threshold for the current binary segmentation based on histogram feedback. This fundamentally eliminates pixel edge extraction errors caused by lighting and exposure.

[0048] Simultaneously, the fast gradient operator is used to statistically analyze the grayscale change rate at the edges of the ROI image. If high-frequency vibrations occur on the production line equipment or the lens experiences slight defocusing, the grayscale transition band at the physical boundary will widen (image edges will become blurred). Once the system determines that this gradient change rate is below a set sharpness hard threshold, it immediately issues a feedback command and automatically initiates a pixel-level Laplacian 3×3 fast reshaping sharpening filter matrix to convolve and enhance the ROI.

[0049] The entire process involves only integer addition, subtraction, and displacement operations, without introducing any complex floating-point subpixel interpolation. It forcibly restores the steepness of the blurred edges at the spatial pixel level, directly reducing the positioning divergence caused by blurring at the pixel level.

[0050] S3. Geometric feedback correction of dimensional calibration coefficients to eliminate edge distortion and perspective projection errors: Optical distortion pre-compensation: Read the centroid coordinates obtained from the coarse measurement When it is discovered that the coordinates deviate from the optical center of the lens. When the distortion is large, the third-order spatial geometric distortion matrix pre-fitted by the calibration block is invoked to quickly retrieve the two-dimensional optical distortion correction factor at that specific coordinate. It is used to locally stretch and straighten the spatial topology of edge pixels, eliminating pixel size deformation caused by barrel or pincushion distortion.

[0051] Perspective projection magnification feedback compensation: Addressing the perspective effect caused by the thickness of objects, which makes objects appear larger when closer and smaller when farther away, the system intelligently identifies the target nominal model based on step two. The system automatically retrieves the standard physical height (thickness) value H of the nut model from the local standard database (e.g., M6 yields a standard height of 5.2mm, and M12 yields a standard height of 10.8mm). The standard vertical distance from the principal point of the industrial camera to the bottom surface of the stage is a fixed installation distance L. Because the nut under test has a physical thickness H, the actual vertical distance between its top surface (the actual imaging surface) being photographed and the camera lens is passively shortened to... According to the principles of optical imaging, a shorter object distance results in a passive enlargement of the projected pixel size on a two-dimensional digital image. Therefore, the system must dynamically refresh and update the size calibration coefficient (the physical number of millimeters represented by a single pixel). Real-time physical size calibration coefficient. The solution formula model is shown in Table 2 below: Table 2: Adaptive Feedback Solution Model for Real-Time Physical Dimension Calibration Coefficients in the Precision Measurement Stage

[0052] By converting the thickness H obtained from the nominal model of the nut into a distance variation scaling factor and directly multiplying it into the system calibration loop for pre-refresh, real-time updates of the physical equivalent are achieved. This perfectly overcomes and eliminates the perspective projection system error of near objects appearing larger than distant objects before the pixel-level algorithm runs.

[0053] S4. Pixel-level fast and fine measurement based on multiple compensation; Binarization threshold in the algorithm Dynamic sharpening filter parameters and real-time physical dimension calibration coefficients of the current workstation. After all data has been refreshed by the front-end feedback, the system initiates high-speed pixel-level precision measurement.

[0054] The algorithm utilizes the refreshed threshold Fast binarization segmentation is performed on the ROI local image. Then, a fast basic erosion operation is performed on the binary image using a 3×3 structuring element morphological erosion operator. Next, integer matrix subtraction is performed between the original binary image matrix and the eroded binary image matrix. Since the two binary matrices differ by only one pixel in physical space, the subtraction immediately removes all redundant entity pixels, instantly extracting and generating a set of points representing the inner circle of a nut hole and the closed contour of the outer hexagonal inner edge, both with a width strictly defined by a single pixel. This process is entirely composed of integer Boolean addition and subtraction operations, typically taking less than 2 milliseconds.

[0055] Finally, on the extracted set of single-pixel-width closed edge points, the fast least squares method is used to fit pixel-level equations for each straight line of the hexagon and curve fitting for the inner hole circle. Since this invention resolutely avoids high-overhead sub-pixel iteration, the least squares method here directly solves the matrix algebraic equations of the homogeneous linear equation system in one step (by substituting all edge point coordinates into the analytical equations, the equation coefficients are directly output without any iterative process), instantly calculating the pixel span of each geometric element (inner hole pixel diameter, number of pixels between parallel lines of the outer hexagon).

[0056] Finally, the pixel spans acquired at such high speeds are directly multiplied by the real-time physical size calibration coefficients, which were corrected for both distortion and perspective effects in step three. The calculation model is shown in Table 3 below: Table 3: Final accurate physical parameter output solution model

[0057] Calculate and output the precise inner diameter of the nut's inner hole, and the precise distances between the sides and diagonals of the hexagonal outer contour.

[0058] Furthermore, to address the technical challenge of online precision measurement of internal thread parameters, this invention achieves automatic calculation of accurate thread pitch in step S4 by performing polar coordinate expansion and periodic fluctuation analysis on the thread region. The specific process includes the following four steps: (1) Precise positioning of the threaded area (threaded ROI): The geometric center of the nut's inner hole (X) obtained by least squares fitting c Y c () is the pole, and the inner hole pixel radius R pixel Based on this, a region of interest (ROI) for the thread is constructed, encompassing the crest and root of the internal thread teeth. The inner radius of the ROI is set to R. in = R pixel - Δr1, outer radius set to R out = R pixel + Δr2, where Δr1 and Δr2 are the target nominal model M identified in step S2. target The preset thread height pixel tolerance increment in the database ensures that the crest and root of all threads are completely locked within the annular area.

[0059] (2) Determination of radial span and polar coordinate sampling: Within the annular thread ROI, with (X c Y cA polar coordinate system (θ, r) is established with the origin as the origin. A radial scan is performed from 0° to 360° along the circumference with a fixed angular step size Δθ (Δθ = 0.5° in this embodiment), extracting each polar angle θ. i The pixel distance from the thread edge point to the center of the inner hole (Xc, Yc), i.e., the radial span (polar diameter) r(θ). i The extracted polar diameters are arranged in polar angle order to construct a one-dimensional radial span sequence r(θ) representing the periodic fluctuations of the stud / thread morphology.

[0060] (3) Noise and abnormal fluctuation handling: To address the issues of machining oil stains, metal burrs, and uneven lighting causing abrupt changes in the radial diameter and high-frequency noise that easily adhere to the inner hole of nuts in industrial settings, this algorithm employs a two-stage filtering mechanism: First, a one-dimensional sliding median filter with a window size of 5 is used to filter the radial span sequence r(θ), effectively eliminating isolated burrs and outlier abrupt changes caused by oil stains; second, a one-dimensional Gaussian smoothing filter with a standard deviation σ=1.0 is used to perform convolution smoothing on the sequence, suppressing high-frequency random noise in the image and obtaining the smoothed thread morphology undulation curve r~(θ).

[0061] (4) Crest determination and pitch calculation: For the smoothed thread undulation curve r~(θ), obtain the first-order difference sequence Δr~(θ) and the second-order difference sequence Δ²r~(θ). The condition for determining the peak is: the first-order difference undergoes a zero-crossing point where it changes from positive to negative (i.e., Δr~(θ)). k ) · Δr~(θ k+1 ) ≤0 and Δr~(θ) k ()>0), and the second difference Δ²r~(θ) k <0; Meanwhile, to prevent misjudgment caused by minute texture fluctuations, a peak threshold T is introduced. peak Only those fluctuation amplitudes greater than T peak The extreme points are determined as the true spiral peaks, and the polar coordinates θ corresponding to each peak are marked. p1 , θ p2 , ..., θ pn Calculate the average polar angle span Δθ between consecutive adjacent wave crests. p And convert it into the corresponding circumferential pixel arc length or axial projection span P. pixel Finally, the pixel pitch P pixel Multiply by the real-time physical dimension calibration factor K, which has undergone double correction in step S3. real This allows for the accurate calculation of the nut's true physical pitch P = P pixel × K real .

[0062] Figure 2This is a schematic diagram illustrating the perspective projection error compensation principle of the present invention. Figure 2 As shown, 1 is an industrial camera, 2 is the nut to be measured, and 3 is the bottom stage; L is the standard vertical object distance from the principal point of the camera to the bottom stage, H is the standard physical thickness of the nut to be measured, and LH is the actual vertical object distance from the camera to the top surface of the nut, which is used to characterize the geometric relationship of calculating the object distance change based on the thickness H feedback to quantify the perspective projection error.

[0063] Figure 3 This is a schematic diagram showing the top-view geometric features of the nut to be tested and the region of interest of the thread. (See diagram below.) Figure 3 As shown, 21 represents the outer hexagonal profile of the nut, 22 represents the inner circular profile of the nut hole, and 23 represents the constructed annular thread region of interest (ROI); R is the fitted pixel radius of the nut hole. in With R out These are the inner and outer radii of the ROI of the annular thread, respectively; W pixel With L pixel These represent the precise pixel span between the edges and the pixel span between the diagonals of the external hexagonal profile, respectively; θ and r(θ) represent the polar angle and polar diameter in the polar coordinate system, respectively; these are used to characterize the feature annotations and region construction basis for measuring the external hexagonal dimensions and calculating the thread parameters in the polar coordinate system during the precision measurement stage.

[0064] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for measuring nut parameters based on machine vision, characterized in that, Includes the following steps: S1. Acquire a single image of the workstation under test using an industrial camera to obtain the original grayscale image of the nut to be tested; use a fast global binarization segmentation algorithm to coarsely measure the original grayscale image to determine the approximate spatial position of the nut to be tested in the image coordinate system. And the region of interest (ROI) surrounding the nut to be tested; S2. Extract the contour geometric feature vector that can characterize the nut's standard specification within the region of interest (ROI) determined in S1. Perform distance matching between the contour geometric feature vector and a pre-set database of standard nut models to identify the target nominal model of the nut to be tested. ; S3. Region of Interest (ROI) and rough spatial location determined by S1. and the target nominal model identified by S2 The pixel-level edge detection binarization threshold and physical size calibration coefficients in the fine measurement stage are dynamically corrected beforehand to obtain the corrected pixel-level edge detection binarization threshold. and real-time physical dimension calibration factor ; S4. Apply the corrected pixel-level edge detection binarization threshold. Within the region of interest (ROI) defined by S1, morphological edge contours with a single pixel width are extracted to obtain a set of pixel-level closed edge points; real-time physical size calibration coefficients are then used. The algorithm performs fast least-squares matrix equation analytical fitting on the pixel-level closed edge point set, calculates and outputs the nut parameters of the nut to be tested.

2. The nut parameter measurement method based on machine vision according to claim 1, characterized in that, S3 specifically includes the following steps: S31. Within the region of interest (ROI) determined in S1, the local grayscale mean and local contrast are calculated in real time, and the target nominal model is determined based on the local grayscale mean, local contrast, and S2. The surface material's reflective properties are used to calculate and refresh the pixel-level edge detection binarization threshold during the fine measurement phase. ; S32. The rough spatial location determined by S1 Based on the relative offset from the optical center point of the image, a preset optical distortion matrix is ​​retrieved, and the spatial distortion correction factor is calculated; simultaneously, based on the target nominal model identified by S2... The system retrieves the corresponding standard thickness H from the standard nut model database preset in S2, calculates the object distance change based on the standard thickness H to quantify the perspective projection error, and substitutes the spatial distortion correction factor and the object distance change into the system calibration formula to dynamically refresh the real-time physical dimension calibration coefficient of the current precision measurement station. .

3. The nut parameter measurement method based on machine vision according to claim 1, characterized in that, In S1, a fast global binarization segmentation algorithm is used to determine the coarse spatial location. The specific methods are as follows: The global segmentation threshold of the original grayscale image is calculated using the Otsu method and then binarized. The largest connected component is extracted using a connected component labeling algorithm, and the geometric centroid of the largest connected component is calculated as the coarse spatial coordinates of the nut to be tested. .

4. The nut parameter measurement method based on machine vision according to claim 1, characterized in that, In S2, the contour geometric feature vector includes the pixel span of the diagonal of the smallest bounding rectangle of the largest connected region, the pixel span of the largest inscribed opposite side of the outer hexagon, and the pixel average from the center of the inner hole to the edge; the standard nut model database stores the nominal size range of M-series standard fasteners.

5. The nut parameter measurement method based on machine vision according to claim 2, characterized in that, In S31, the pixel-level edge detection binarization threshold The formula is as follows: In the formula, Based on the basic experience threshold, This represents the local grayscale mean within the region of interest (ROI). Here, C is the dynamic brightness adjustment coefficient based on the grayscale mean, and C is the standard deviation of local contrast within the region of interest (ROI). This is the edge sensitivity correction amount. This is a dedicated calibration constant for the reflective properties of a specific type of material surface.

6. The nut parameter measurement method based on machine vision according to claim 2, characterized in that, In S31, the binarization threshold is refreshed. In addition, it also includes a step of performing fast pixel-level sharpening filtering on image edges: The gradient change rate of the image edges within the Region of Interest (ROI) in the spatial domain is statistically analyzed. When the gradient change rate is lower than a preset sharpness threshold, it is determined that the system has vibration or out-of-focus blur, and a 3×3 window Laplacian sharpening filter matrix is ​​automatically invoked to perform convolution enhancement on the ROI.

7. The nut parameter measurement method based on machine vision according to claim 2, characterized in that, In S32, the real-time physical dimension calibration coefficient The formula is as follows: In the formula, L is the standard base calibration coefficient of the camera relative to the bottom stage; H is the standard vertical distance from the camera principal point to the bottom stage; and H is the distance from the target nominal model number. The standard physical thickness is mapped from the database; Based on the coarse coordinates The two-dimensional optical distortion correction factor retrieved from the spatial distortion lookup table.

8. The nut parameter measurement method based on machine vision according to claim 1, characterized in that, In S4, the specific steps for extracting morphological edge contours with a single pixel width are as follows: Using binarization threshold The region of interest (ROI) is segmented into pixels. A morphological erosion operator with a 3×3 structuring element is used to perform a single erosion on the segmented binary image. The binary image and the eroded image are then subtracted by integers to remove redundant pixels and generate a single-pixel closed edge contour with a width of one pixel.

9. The nut parameter measurement method based on machine vision according to claim 1, characterized in that, In S4, the output nut parameters include the precise inner diameter of the nut's inner circle, the precise distance between opposite sides of the outer hexagonal profile, the precise distance between opposite corners, and the precise pitch; the specific calculation steps for the precise pitch are as follows: Thread region positioning: Using the center of the nut's inner hole obtained from S4 as the center and the inner hole pixel radius as the reference, construct an annular thread region of interest that encloses the top and bottom of the thread teeth; Radial span extraction: A polar coordinate system is established in the region of interest of the annular thread, and radial scanning is performed along the circumference at a preset angle step to obtain the polar diameter of the thread edge pixel under each polar angle, generating a one-dimensional thread radial span undulation sequence. Noise and Anomaly Handling: Sliding median filtering is used to remove abnormal abrupt changes in the one-dimensional radial span fluctuation sequence of the thread, and one-dimensional Gaussian smoothing filtering is used to smooth the sequence and smooth high-frequency random noise. Peak determination and pitch calculation: The first and second differences are calculated from the smoothed undulation sequence, and the polar angle position corresponding to the screw peak is determined by combining this with a preset peak amplitude threshold. The pixel span between adjacent peaks is calculated and multiplied by the real-time physical size calibration coefficient. The precise pitch is calculated.