Visual inspection method and system for stepped shafts

By employing operations such as median filtering, color inversion, and fixed threshold segmentation, combined with area threshold and aspect ratio constraints, the target contour is automatically filtered, and the fitted straight line is iteratively optimized. This solves the problems of uneven illumination and noise interference in the visual inspection of stepped axes, and enables accurate measurement and position recognition of multiple segments of stepped axes.

CN121639763BActive Publication Date: 2026-04-21CHENGDU IND VOCATIONAL TECHN COLLEGE
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHENGDU IND VOCATIONAL TECHN COLLEGE
Filing Date
2026-02-04
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

Visual inspection of stepped axes faces challenges such as uneven lighting, noise pollution, and low contrast between the target and the background. Traditional edge detection algorithms struggle to accurately extract the complete contour, and traditional line fitting methods are susceptible to outliers, leading to size measurement errors.

Method used

The system employs a combination of median filtering for noise reduction, color inversion to enhance contrast, and fixed threshold segmentation. It also automatically filters target contours by combining area thresholds, aspect ratio constraints, and sorting strategies. Based on the geometric parameters of the minimum bounding rectangle, it quickly generates an initial straight line model. Through iterative optimization of the fitted line, it eliminates the influence of outliers and achieves accurate measurement of multi-step dimensions.

Benefits of technology

It improves the anti-interference capability of the detection system in complex environments, enhances its robustness to noise and anomalies, and realizes the synchronous measurement and position recognition of multi-segment dimensions of stepped shafts, meeting the detection needs of complex structural parts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121639763B_ABST
    Figure CN121639763B_ABST
Patent Text Reader

Abstract

The present application relates to the field of visual detection, and discloses a kind of visual detection method and system of stepped shaft, for satisfying multiple step size jump accurate measurement, edge extraction under the interference of metal reflection, high real-time requirement of no training data.It includes generating high-quality binary image through multi-stage image preprocessing, accurately extracting target contour combined with geometric constraint, and calculating its minimum circumscribed rectangle parameters.Based on initial geometric parameters, noise interference is eliminated through iterative linear fitting optimization algorithm, and high-precision straight line model is obtained.Further, the measurement section is divided along the axial direction, the diameter of each section is calculated, and the stepped transition position is identified, and finally a complete size report is generated and the measurement results are visualized on the original image.The present application realizes the sub-pixel level precision detection of stepped shaft size, adapts to complex industrial scenes, has high detection efficiency and strong robustness, and can be widely applied in mechanical manufacturing, quality detection and other fields, and promotes the development of industrial automation and intelligent manufacturing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of visual inspection, and more particularly to a visual inspection method and system for stepped axes. Background Technology

[0002] In modern manufacturing, stepped shafts are common mechanical parts widely used in various transmission systems, mechanical structures, and precision instruments. Their dimensional accuracy and geometric tolerances directly affect the operating performance and service life of mechanical equipment. With the rapid development of industrial automation and intelligent manufacturing, traditional manual inspection methods are gradually being replaced by non-contact inspection technologies based on machine vision due to their low efficiency, high subjectivity, and inability to meet the needs of mass production.

[0003] Machine vision inspection technology, through the combination of high-resolution cameras, image processing algorithms, and automated control systems, can achieve rapid and accurate measurement of parameters such as the size, shape, and surface defects of stepped shafts. However, the visual inspection of stepped shafts faces the following technical challenges:

[0004] Uneven lighting, noise pollution, and low contrast between the target and the background in industrial settings make image segmentation difficult.

[0005] The surface of the stepped shaft may have scratches, oil stains and other interference, making it difficult for traditional edge detection algorithms to accurately extract the complete contour;

[0006] Because the stepped shaft can rotate, tilt, or undergo local deformation, traditional straight-line fitting methods are susceptible to outliers, leading to dimensional measurement errors.

[0007] Therefore, we propose a visual detection method and system for stepped axes to solve the above problems. Summary of the Invention

[0008] This invention provides a visual inspection method and system for stepped axes, which can meet the requirements of accurate measurement of multi-step size changes, edge extraction under metal reflection interference, and high real-time performance without training data.

[0009] The first aspect of this invention provides a visual inspection method for stepped shafts. The method includes: acquiring an original image of a stepped shaft bar; performing denoising processing on the original image to generate a denoised image; performing a color inversion operation on the denoised image to generate an inverted image; converting the inverted image into a single-channel grayscale image to generate a grayscale image; binarizing the grayscale image using a fixed threshold segmentation method to generate a binary image containing only the target object and the background; extracting the contours of all connected regions from the binary image; filtering out the target contour and calculating its minimum bounding rectangle; obtaining the center point coordinates, width, height, and rotation angle of the minimum bounding rectangle; determining the long side direction based on the width and height values ​​of the minimum bounding rectangle; and calculating the long side direction based on the coordinates of the two endpoints of the long side direction using a two-point linear equation. Calculate the initial slope and initial intercept. Based on the center point coordinates and the initial slope, calculate the reference intercept passing through the center point. Using the initial intercept and reference intercept as a reference, set the iteration start point, end point, and step size. In each iteration, update the current intercept. In the contour point set of the binary image, count the number of points located within the tolerance zone of the linear equation. Gradually narrow the iteration range and decrease the step size, repeating until the preset number of iterations is reached. Select the intercept corresponding to the largest number of points as the candidate intercept. Extract all contour points located within the tolerance zone of the linear equation to form a point set. Refit the line using the least squares method on the point set to obtain the final slope and optimal intercept. Based on the final slope and optimal intercept, calculate the distance between two parallel lines as the measurement dimension of the stepped shaft bar. Output the dimension result and mark the measurement position on the original image.

[0010] Optionally, in a first implementation of the first aspect of the present invention, the method includes: vertically capturing an image of a stepped shaft bar placed horizontally using a fixedly installed high-resolution industrial camera to generate an original image; applying a median filter with a window size of 3×3 pixels to the original image to eliminate noise and generate a denoised image; performing a 255-to-pixel subtraction operation on each pixel of the denoised image to generate an inverted image; converting the inverted image from an RGB three-channel mode to a single-channel grayscale mode to generate a grayscale image; and based on a preset fixed threshold, setting the areas in the grayscale image with pixel values ​​greater than the fixed threshold to a white background and the remaining areas to a black target to generate a binary image containing only the target object and the background.

[0011] Optionally, in a second implementation of the first aspect of the present invention, the method includes: performing a full-image scan of the binary image to identify the outer boundaries of all connected regions and generate an initial contour set; target contour filtering: calculating the area of ​​the minimum bounding rectangle of each contour and retaining contours with an area greater than a preset threshold; calculating the aspect ratio of the minimum bounding rectangle of the retained contours and filtering out contours with aspect ratios exceeding the interval [1.5, 20]; sorting the remaining contours in descending order of area and selecting the contour with the largest area as the target contour; minimum bounding rectangle calculation: calculating the minimum bounding rectangle of the target contour based on the pixel coordinate point set; extracting the center point coordinates, width value, height value, and rotation angle of the rectangle. If the rotation angle >90°, then update ° and swap the width and height values ​​to ensure that they always represent the length of the longer side.

[0012] Optionally, in a third implementation of the first aspect of the present invention, the method includes: setting the height value of the minimum bounding rectangle... The length of the longer side is used as the value of the shorter side, and the height direction is taken as the direction of the longer side; based on the coordinates of the center point. and rotation angle Extending to both sides along the long side Distance is calculated using the geometric projection formula, determining the coordinates of the two endpoints of the longer side: Endpoint 1: Endpoint 2: ; Calculate the initial slope k based on the coordinates of endpoint 1 and endpoint 2. Substitute the coordinates of any endpoint into the equation of the line. Generate the initial intercept ; the coordinates of the center point Substituting the initial slope k into the equation of the line Generate reference intercept .

[0013] Optionally, in the fourth implementation of the first aspect of the present invention, the method includes: iterative interval initialization: calculating the initial intercept. With reference intercept median value Set the initial iteration starting point. End point Set initial step size For each iteration: from to With the current step size Traversing intercept values For each In the target contour point set of the binary image, straight lines were statistically counted. The vertical distance is less than the tolerance threshold Points Record the maximum score in this round. and its corresponding intercept Shrinking the iteration range: updating The shrinkage coefficient = 1.2; Decrease step size: Update After completing the preset 3 rounds of iterations, the final output is given. as a candidate intercept .

[0014] Optionally, in a fifth implementation of the first aspect of the present invention, it includes: based on the candidate intercept. Given an initial slope k, select all points in the target contour point set that satisfy the vertical distance condition. The contour points constitute the initial point set. ,in Set a preset tolerance threshold; calculate the initial point set. From each point in the line Distance; exclude distances greater than The points generate a refined point set. ; For the refined point set Perform least squares line fitting: calculate the point set Coordinate mean and Coordinate mean According to the covariance formula Find the final slope; use the intercept formula. Find the optimal intercept; if the average distance between the fitted line and the refined point set exceeds... Then output As the final intercept.

[0015] Optionally, in a sixth implementation of the first aspect of the present invention, it includes: based on the rotation angle and center point coordinates The bar stock is divided into multiple measurement segments along the stepped shaft axis; for each measurement segment: based on the final slope... and optimal intercept Generate two parallel lines: the upper boundary line. Lower boundary line: ;in Set a preset reference diameter; calculate the perpendicular distance between two parallel lines. , which serves as the diameter of the current segment.

[0016] Optionally, in the seventh implementation of the first aspect of the present invention, it includes: if the diameter difference between adjacent measurement segments is... If the position is a stepped transition point, mark the double measuring line at the transition point and record the diameters on both sides.

[0017] Optionally, in the eighth implementation of the first aspect of the present invention, the method includes: merging all the diameter data of the measurement segments to generate a complete dimension report of the stepped shaft, marking each measurement line on the original image with different colors, and superimposing and displaying the dimension values ​​and tolerance judgment results.

[0018] The second aspect of the present invention provides a visual inspection system for stepped shafts, the visual inspection system for stepped shafts comprising: an acquisition module, configured to acquire an original image of a stepped shaft bar stock, perform denoising processing on the original image to generate a denoised image, perform a color inversion operation on the denoised image to generate an inverted image, convert the inverted image into a single-channel grayscale image to generate a grayscale image, and binarize the grayscale image using a fixed threshold segmentation method to generate a binary image containing only the target object and the background; an extraction module, configured to extract the contours of all connected regions from the binary image, filter out the target contours, calculate its minimum bounding rectangle, and obtain the center point coordinates, width value, height value, and rotation angle of the minimum bounding rectangle; and a calculation module, configured to determine the direction of the long side based on the width and height values ​​of the minimum bounding rectangle, and calculate the direction of the long side based on the coordinates of the two endpoints of the long side using a two-point linear equation. The algorithm calculates the initial slope and initial intercept, and calculates the reference intercept passing through the center point based on the coordinates of the center point and the initial slope. An optimization module sets the iteration start point, end point, and step size based on the initial intercept and reference intercept. In each iteration, it updates the current intercept, counts the number of points within the tolerance zone of the linear equation in the contour point set of the binary image, gradually narrows the iteration range and decreases the step size, repeating this process until a preset number of iterations is reached, and selects the intercept corresponding to the largest number of points as the candidate intercept. An identification module extracts all contour points within the tolerance zone of the linear equation, forming a point set. The least squares method is used to refit the linear line to obtain the final slope and optimal intercept. An allocation module calculates the distance between two parallel lines based on the final slope and optimal intercept, using this distance as the measurement dimension of the stepped shaft bar, outputs the dimension result, and marks the measurement position on the original image.

[0019] The mechanism of this invention is as follows:

[0020] A coordinated control strategy for vibration dispersal and image acquisition, an automatic separation and judgment algorithm for adhering particles, a two-dimensional dynamic size calculation method based on the minimum bounding rectangle, and a quantitative evaluation model for shape qualification rate.

[0021] The slender cylindrical geometry, metallic reflective properties, and abrupt step characteristics of the stepped shaft are transformed into projection formulas, iterative constraints, and jump thresholds to construct a closed-loop data flow system.

[0022] Beneficial effects: By combining median filtering for noise reduction, color inversion to enhance contrast, and fixed threshold segmentation, the problem of uneven lighting and noise interference in industrial scenarios is specifically solved.

[0023] By combining area thresholds, aspect ratio constraints, and sorting strategies, target outlines are automatically filtered to avoid interference from non-target areas.

[0024] Based on the geometric parameters of the minimum bounding rectangle, an initial straight line model is quickly generated. By setting the intercept search range, step size and tolerance threshold, the optimal straight line is gradually approximated. The point set after iteration is then fitted twice to eliminate the influence of outliers.

[0025] Based on the rotation angle and center point coordinates, multiple measurement segments are divided along the stepped shaft axis. The step position is determined by the diameter difference between adjacent measurement segments, and double measurement lines are marked. The data of each segment are merged to generate a complete dimension report, which is then visualized on the original image. This enables simultaneous measurement of the dimensions of multiple segments of the stepped shaft and identification of the step position, meeting the inspection needs of complex structural parts. Attached Figure Description

[0026] Figure 1 This is a schematic diagram of an embodiment of the visual detection method for stepped axes in this invention;

[0027] Figure 2 This is a schematic diagram of another embodiment of the visual detection method for stepped axes in this invention;

[0028] Figure 3 This is a schematic diagram of an embodiment of the visual inspection system for stepped axes in this invention;

[0029] Figure 4 This is a schematic diagram of one embodiment of the visual inspection device for stepped shafts in this invention. Detailed Implementation

[0030] This invention provides a visual inspection method and system for stepped axes, designed to meet the requirements of accurate measurement of multi-step size transitions, edge extraction under metallic reflective interference, and high real-time performance without training data. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings 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 described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" or "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 explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0031] For ease of understanding, the specific process of the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 1 One embodiment of the visual detection method for stepped axes in this invention includes:

[0032] 101. Image Acquisition and Preprocessing: Acquire the original image of the stepped shaft bar using a high-resolution industrial camera; denoise the original image using a median filtering algorithm to generate a denoised image; perform a color inversion operation on the denoised image to generate an inverted image; convert the inverted image into a single-channel grayscale image to generate a grayscale image; binarize the grayscale image using a fixed threshold segmentation method to generate a binary image containing only the target object and the background.

[0033] It is understood that the executing entity of this invention can be a visual inspection system for stepped axes, or it can be a terminal or a server; no specific limitation is made here. This embodiment of the invention will be described using a server as the executing entity as an example.

[0034] It should be noted that the industrial camera parameter settings and image acquisition are as follows: Camera selection: A CCD industrial camera (MER-2000-5GC) with a resolution ≥1280×1024 and a pixel size of 3.45μm was selected to ensure clear details. Light source and environment: A white LED strip light source illuminates the stepped axis at a 45° angle with a brightness of 1500 lux to avoid reflections; the camera exposure time is set to 5000μs, and the gain is adjusted to 12 (to balance brightness and noise). Acquisition output: The original image of the stepped axis (RGB format, 1280×1024 resolution) is acquired, with a black frosted plate background and the axis appearing silver-gray.

[0035] Median filtering for noise reduction: Algorithm parameters: A 5×5 filter kernel is used to scan the original image pixel by pixel, replacing each pixel with the median of its 25 neighboring pixels. Effect: Eliminates salt-and-pepper noise (scattered bright / dark pixels in the image) caused by light source fluctuations or sensor noise, generating a smooth, denoised image.

[0036] Color inversion operation: The method involves inverting each of the RGB channels of the denoised image: the inverted pixel value = 255 - the original pixel value. Effect: This converts the silver-gray step axis (RGB≈180,180,180) in the original image to dark gray (RGB≈75,75,75), and the black background (RGB≈0) to white (RGB=255), facilitating subsequent thresholding.

[0037] Convert to a single-channel grayscale image using the following formula: Weighted method: Grayscale value = 0.299R + 0.587G + 0.114B, fusing information from three channels. Output: Generate a single-channel grayscale image with a grayscale value of approximately 75 in the step axis region and a background value of 255 (pure white).

[0038] Fixed threshold segmentation and binarization: A fixed threshold T=128 is used to convert the grayscale image to a binary image: grayscale values ​​≤128 → target object (step axis), set to white (pixel value 255); grayscale values ​​>128 → background, set to black (pixel value 0). Result: A binary image is generated containing only the white step axis outline and a black background, completely separating the target from the background.

[0039] parameter:

[0040]

[0041] 102. Contour Extraction and Geometric Feature Calculation: Extract the contours of all connected regions from the binary image; filter out the target contours and calculate their minimum bounding rectangle; obtain the center point coordinates, width, height, and rotation angle of the minimum bounding rectangle;

[0042] It should be noted that the binary image (resolution 1280×1024) of the stepped shaft bar stock (material: 45# steel, surface: silver-gray) aims to extract its outer contour and calculate its geometric features. The image contains a small amount of oil noise and two non-target connected regions (both with an area less than 200 pixels).

[0043] Contour extraction, input: preprocessed binary image, target object is white (pixel value 255), background is black (pixel value 0).

[0044] Contour retrieval mode: The RETR_EXTERNAL mode was used to extract only the outermost contour (ignoring internal holes), and a total of 3 connected regions were detected (including 1 target contour and 2 noise contours).

[0045] Contour point set: The target contour contains approximately 1200 boundary point coordinates, while the noise contour contains 85 and 150 points respectively.

[0046] Target contour filtering uses geometric features to filter out non-target contours: Area filtering: Calculate the area of ​​each contour (unit: pixels). Target contour area: 18,500 pixels (meets the expected step axis size); Noise contour area: 85 pixels, 150 pixels (far smaller than the target); Threshold setting: Keep contours with an area > 1000 pixels, directly exclude the two noise contours. Aspect ratio verification: Calculate the minimum bounding rectangle of the target contour, resulting in a width of 420 pixels, a height of 44 pixels, and an aspect ratio ≈ 9.5 (meets the slender step axis characteristic).

[0047] The minimum bounding rectangle is calculated for the target outline, obtaining the following parameters: center point coordinates: (640.2, 512.8) — calculated based on the intersection of the rectangle's diagonals; width and height: width = 420.0 pixels (long side), height = 44.0 pixels (short side); rotation angle: 15.3° (counterclockwise rotation relative to the image's horizontal axis, reflecting the tilt of the stepped axis placement);

[0048] Filtering logic:

[0049]

[0050] 103. Initialization of reference line parameters: Determine the direction of the long side based on the width and height of the minimum bounding rectangle; calculate the initial slope using a two-point line equation based on the coordinates of the two endpoints of the long side. and initial intercept Based on the center point coordinates and the initial slope Calculate the reference intercept through the center point. ;

[0051] It should be noted that the minimum bounding rectangle parameters of the target contour in the stepped axis binary image (resolution 1280×1024) are as follows: center point coordinates: (500.0, 400.0) (unit: pixels); width and height: width = 420.0 pixels, height = 44.0 pixels; rotation angle: 15.3° (counterclockwise rotation relative to the horizontal axis of the image).

[0052] The direction of the long side is determined by comparing the width (420.0 pixels) and height (44.0 pixels). Since width > height, the direction of the long side is the width direction (i.e., the major axis direction of the rotated rectangle). Direction correction: If height > width, then the long side is the height direction. The width and height values ​​need to be swapped, and the angle increased by 90° to unify the direction definition. The coordinates of the endpoints of the long side are calculated based on the principle that the endpoints of the long side of the smallest bounding rectangle can be deduced from the rotation angle and the coordinates of the center point.

[0053] Calculation process: Half-length of the longer side L = width / 2 = 210.0 pixels. Angle conversion: radian system radian.

[0054] Endpoint offset: Pixel; Pixel;

[0055] Coordinates of both endpoints: Endpoint A: (500.0+ 400.0+ = (702.65, 454.39); Endpoint B: (500.0— 400.0— = (297.35, 345.61).

[0056] Calculation of initial slope and intercept, two-point form of straight line equation: slope (Keep 3 decimal places).

[0057] intercept Substitute the coordinates of endpoint A: 266.08;

[0058] Reference intercept Calculate the line parallel to the center point: center point (500.0, 400.0). Substitute the slope k=0.268: ;

[0059] parameter:

[0060]

[0061] Output: Initial slope k≈0.268, initial intercept ≈266.08, Reference intercept =266.0. These parameters provide a benchmark for subsequent iterations to optimize the intercept of the fitted line.

[0062] 104. Iterative optimization of the intercept of the fitted line: using the initial intercept and reference intercept Set the iteration starting point as the baseline. End point and step length In each iteration: a) Update the current intercept. b) In the set of contour points in the binary image, statistically analyze the points located on the line equation. tolerance band Points within Gradually narrow the iteration range and decrease the step size, repeating until the preset number of iterations is reached; select the number of points. The intercept corresponding to the maximum As a candidate intercept;

[0063] It should be noted that the target contour point set (a total of 1200 boundary points) extracted from the step axis binary image (resolution 1280×1024) has already obtained the baseline line parameters through step 103: slope k=0.268, initial intercept. =266.08, Reference intercept =266.0. The goal is to find the optimal intercept through iterative optimization. .

[0064] Iteration parameter initialization, iteration baseline range: and mean Centered on.

[0065] First iteration parameters: Initial intercept End intercept Step size Tolerance band =1.0 pixel (line) A strip-shaped area with a height of 1 pixel at the top and bottom.

[0066] Iterative optimization process, first iteration (coarse adjustment): intercept traversal: from =265.04 to =267.04, with Step by step, generate the intercept sequence: 265.04, 265.54, 266.04, 266.54, 267.04.

[0067] Statistical tolerance band points: when When the value is 266.04, the straight line covers the most contour points. =1050 points, accounting for 87.5%). Update iteration scope: based on Using 266.04 as the center, narrow the range to... =265.54、 =266.54, step size halved =0.25.

[0068] Second iteration (mid-tuning): Intercept traversal: sequence is 265.54, 265.79, 266.04, 266.29, 266.54. Optimal intercept: =266.29 The maximum number of time points ( =1120 points). Update parameters: range narrowed to =266.04、 =266.54, step size =0.1.

[0069] Third iteration (fine-tuning): Intercept traversal: 266.04, 266.14, 266.24, 266.34, 266.44, 266.54. Optimal intercept: =266.34 The number of points reached its peak ( =1185 points, accounting for 98.75%.

[0070] Candidate intercepts determined, final selection The maximum value corresponding to .

[0071] Termination condition: The preset number of iterations (3 times) is reached, and the step size is... Reduced to 0.1 (accuracy meets ±0.1 pixels).

[0072] Summary of results:

[0073]

[0074] 105. Determining the best-fit line: Extract all lines that lie on the line. tolerance band The contour points within the boundary form a point set S; the least squares method is used to refit the line on the point set S to obtain the final slope. and optimal intercept ;

[0075] It should be noted that, based on the target contour point set (a total of 1200 boundary points) of the step axis binary image (resolution 1280×1024), the candidate line parameters were obtained through iterative optimization in step 104: slope k=0.268, candidate intercept. =266.34, tolerance band =1.0 pixel. The goal is to fit the final line parameters using the least squares method.

[0076] Point set S filtering, tolerance band definition: Centered on the line y = 0.268x + 266.34, extend upwards and downwards by 1 pixel (i.e., y ± 1.0), forming a band-shaped region with a width of 2 pixels. Filtering logic: Traverse all 1200 contour points; if a point... satisfy: If the condition is not met, then the point is retained. Filtering results: A total of 1185 points were selected for point set S (accounting for 98.75%), and 15 outliers (oil stain noise points or edge break points) were removed.

[0077] Least squares fitting, input data: coordinates of point set S ,in Range [280, 800], Range [345, 480] (unit: pixels).

[0078] Calculation parameters: Mean calculation: (Center position of the point set).

[0079] slope : ;

[0080] intercept : ;

[0081] Fitted equation: y = 0.271x + 264.95.

[0082] Parameter correction instructions, slope fine-tuning: from k=0.268 → =0.271, because the point set within the tolerance band is closer to the true edge, correcting the deviation of the initial slope caused by the error of the rectangular endpoints.

[0083] Intercept optimization: From =266.34 → =264.95, because the least squares method balances the positional errors of all points.

[0084] Fitting results:

[0085]

[0086] Residual analysis: The average vertical distance from the point set S to the fitted line is 0.15 pixels (less than the 0.3 pixels required for industrial testing), which meets the accuracy requirements.

[0087] Output: Final slope =0.271, optimal intercept =264.95. This step combines tolerance band filtering with the least squares method to suppress noise interference while preserving edge details, providing a high-precision reference line for dimensional calculations.

[0088] 106. Dimension Calculation and Output: Based on the final slope and optimal intercept Calculate two parallel lines and Distance between The dimensions are used as the measurement dimensions of the stepped shaft bar stock; the dimensional results are output and the measurement locations are marked on the original image.

[0089] It should be noted that, based on the target contour of the step-axis binary image (resolution 1280×1024), the final fitted line parameters are obtained through step 105: slope. =0.271, intercept =264.95. The diameter of the stepped axis (i.e., the distance d between two parallel lines) needs to be calculated, and the result output to the original image.

[0090] Dimension calculations, definition of parallel lines: Upper edge line: y = 0.271x + 264.95; Lower edge line: based on the step axisymmetry, intercept offset. =22.0 pixels (calculated from the distribution of the contour point set), so y=0.271x+(264.95—22.0)=0.271x+242.95.

[0091] Distance formula: Distance between two parallel lines Substitute parameters: Pixel.

[0092] Physical size conversion: System calibration coefficient: 0.025 mm / pixel (calibrated by standard gauge blocks); Actual diameter: 21.24 × 0.025 = 0.531 mm.

[0093] Results and annotations: Data output: Measured value: 0.531 mm (retain 3 decimal places); Tolerance comparison: The design tolerance requirement is 0.530±0.010 mm, which is considered acceptable.

[0094] Image annotations (overlaid on the original RGB image): Draw two red fitted lines (2 pixels wide); add dimension text at the center of the axis: Diameter: 0.531 mm (green font, size 20); add a conclusion box in the lower right corner of the image: PASS | Tolerance: 0.530±0.010 mm.

[0095] Result verification:

[0096]

[0097] In this embodiment of the invention, during the image acquisition and preprocessing stage, a median filtering algorithm is used to eliminate salt-and-pepper noise caused by light source fluctuations or sensor noise. During contour extraction, area filtering and aspect ratio verification are used to eliminate oil stain noise and non-target connected regions, ensuring the accuracy and reliability of the extracted target contour and improving the anti-interference capability of the detection system in complex environments. In the process of determining the best-fit line, tolerance band filtering is used to remove outliers, retaining only the contour points that meet the conditions for least-squares fitting, further enhancing the system's robustness against noise and outliers. The entire detection process, from image acquisition, preprocessing, contour extraction, geometric feature calculation, line fitting to scale... The system automates the dimensional calculation and output process, eliminating the need for manual intervention, thus improving inspection efficiency and reducing labor costs. During the iterative optimization of the fitted line intercept, the system automatically adjusts the iteration range and step size based on changes in the number of points within the tolerance band, achieving adaptive parameter optimization and enhancing the system's intelligence. Measurement positions and dimensional results are marked on the original images, providing a clear visual representation of the measurement information and facilitating quick understanding of the results by operators. Detailed measurement data is output, including measured values, tolerance comparisons, and fitting parameters, providing strong support for quality traceability and data analysis, and aiding enterprises in quality control and production optimization. The use of a high-resolution CCD industrial camera, along with appropriate camera parameters and lighting conditions, ensures clear acquisition of stepped shaft images of different sizes and materials, adapting to the needs of various production scenarios. The image processing and geometric calculation algorithms are highly versatile, applicable not only to stepped shaft inspection but also, with appropriate adjustments, to the dimensional measurement of other similarly shaped objects, demonstrating excellent scalability.

[0098] Please see Figure 2 Another embodiment of the visual detection method for stepped axes in this invention includes:

[0099] 201. Acquire the original image of the stepped shaft bar, perform denoising on the original image to generate a denoised image, perform color inversion on the denoised image to generate an inverted image, convert the inverted image into a single-channel grayscale image to generate a grayscale image, and binarize the grayscale image using a fixed threshold segmentation method to generate a binary image containing only the target object and the background.

[0100] Specifically, the process includes: image acquisition: capturing images of the stepped shaft bar material placed horizontally using a fixed, high-resolution industrial camera to generate the original image; noise reduction: applying a 3×3 pixel median filter to the original image to eliminate noise, generating a denoised image; color inversion: performing a 255-to-pixel subtraction operation on each pixel of the denoised image to generate an inverted image; grayscale conversion: converting the inverted image from RGB three-channel mode to single-channel grayscale mode to generate a grayscale image; and binarization segmentation: based on a preset fixed threshold. , to convert pixel values ​​in a grayscale image greater than The target area is set to a white background, and the remaining area is set to a black target, generating a binary image containing only the target object and the background.

[0101] It should be noted that the object of the test was a 15mm / 25mm diameter double-step stainless steel stepped shaft with slight oil stains on the surface, placed against a gray conveyor belt background.

[0102] Image acquisition equipment configuration: 20-megapixel industrial camera (IMX183 sensor), vertically mounted 50cm above the axis. Ring LED light source (color temperature 6000K), illuminance uniformity ≥90%. Output: Original image (resolution 5312×2988, RGB format), axis body is dark gray (average pixel value R=60 / G=65 / B=70), background is light gray (R=180 / G=185 / B=190).

[0103] Denoising process: Apply a median filter (3×3 window), iterate through each pixel of the image, and replace the center pixel with the median value of its 9 neighboring pixels. Results: Eliminates 3 salt grain noise points (original value [255,255,255] → corrected to [182,187,192]), smooths oil stain areas (local standard deviation reduced from 25 to 8). Output: Denoising image (size unchanged).

[0104] Color inversion, operation: Calculate pixel-by-pixel for the denoised image: New R value = 255 - original R value; New G value = 255 - original G value; New B value = 255 - original B value; Effect: The axis becomes light gray (R=195 / G=190 / B=185), the background becomes dark gray (R=75 / G=70 / B=65), and the contrast is increased to 65% (originally 30%). Output: Inverted image (RGB format).

[0105] Grayscale conversion operation: Grayscale value = 0.299×R + 0.587×G + 0.114×B, merging three channels. Output: Single-channel grayscale image (size 5312×2988), axial region grayscale value ≈ 190, background ≈ 70.

[0106] Binary segmentation, parameter settings: fixed threshold T=125 (preset based on the reflective properties of stainless steel). Operation: Traverse the grayscale image: pixel value > 125 → set to 255 (white background); pixel value ≤ 125 → set to 0 (black target); effect: complete closed axis outline (connected region area 15240 pixels), no background residue. Output: binary image (0 / 255 values ​​only).

[0107] 202. Extract the contours of all connected regions from the binary image, filter out the target contours, calculate their minimum bounding rectangle, and obtain the center point coordinates, width, height and rotation angle of the minimum bounding rectangle.

[0108] Specifically, contour extraction involves scanning the entire binary image to identify the outer boundaries of all connected regions and generating an initial contour set; target contour filtering involves calculating the minimum bounding rectangle area of ​​each contour and retaining those with areas greater than a preset threshold. The contour is calculated; the aspect ratio of the minimum bounding rectangle of the retained contour is calculated, and contours with aspect ratios exceeding the interval [1.5, 20] are filtered out; the remaining contours are sorted in descending order of area, and the contour with the largest area is selected as the target contour; the minimum bounding rectangle is calculated: based on the pixel coordinate set of the target contour, its minimum bounding rectangle is calculated; the center point coordinates of the rectangle are extracted. Width value (Short side length), height value (Length of the longer side) and rotation angle (The angle between the principal axis of the rectangle and the horizontal axis); Standardization of rotation angle: If >90°, then update ° and swap the width values With height value ,make sure It always represents the length of the longer side.

[0109] It should be noted that the input is the binary image generated in step 201, with a resolution of 5312×2988, the target axis is pure black (0 value), and the background is pure white (255 value).

[0110] Contour extraction: A boundary tracking algorithm is used to scan the entire image and identify the outer boundaries of all connected regions. Output: The initial contour set contains 3 contours: Contour 1: Main axis (15240 pixels); Contour 2: Oil smudge noise (area 28 pixels); Contour 3: Reflective false contour (area 3500 pixels, aspect ratio 1.2);

[0111] Target contour filtering parameter settings: Area threshold Pixels 2 (Filter out small noise); Aspect ratio range [1.5, 20] (screen non-bar materials);

[0112] Screening process:

[0113]

[0114] Target selection: Select the retained contour 1 (unique contour) directly as the target contour.

[0115] Minimum bounding rectangle calculation. Input: A set of pixel coordinates of the target contour (15240 points). Calculation process: The minimum bounding rectangle is calculated using the rotating caliper algorithm: center point... (Image coordinate system); width Pixels (short side); Height h = 3200 pixels (long side); Rotation angle (Angle between the main axis and the horizontal axis);

[0116] Standardized processing: because > Execute: Update Swap width and height values: new width Pixels; New Heights =530 pixels; Effect: Ensure Always use the longer side (3200>530) to avoid directional ambiguity.

[0117] Output:

[0118]

[0119] 203. Determine the direction of the long side based on the width and height of the minimum bounding rectangle. Calculate the initial slope and initial intercept using a two-point linear equation based on the coordinates of the two endpoints of the long side. Calculate the reference intercept through the center point based on the coordinates of the center point and the initial slope.

[0120] Specifically, the direction of the longer side is determined by: the height value of the smallest bounding rectangle. As the length of the long side, the width value The length of the shorter side is taken as the height direction, with the length of the longer side defined as the height direction. The coordinates of the endpoints of the longer side are calculated based on the coordinates of the center point. and rotation angle Extending to both sides along the long side Distance; calculate the coordinates of the two endpoints of the longer side using the geometric projection formula: Endpoint 1: Endpoint 2: Initial slope and intercept calculation: Based on the coordinates of endpoint 1 and endpoint 2, the slope is calculated using the slope formula k. Calculate the initial slope k; substitute the coordinates of any endpoint into the equation of the line. Generate the initial intercept Reference intercept calculation: Using the center point coordinates... Substituting the initial slope k into the equation of the line Generate reference intercept .

[0121] It should be noted that the input is the minimum bounding rectangle parameter output in step 202, and the coordinates of the center point. (pixels); Width w = 530 (short side, in pixels); Height h = 3200 (long side, in pixels); Rotation angle (After standardization);

[0122] Long side direction determination: The height value h=3200 is directly used as the long side length (because h is always the long side after standardization); the width w=530 is used as the short side length; the long side direction is set to the height direction of the rectangle (axial direction). Effect: Avoids the computational overhead of dynamically comparing width and height using traditional methods; direction determination time is reduced to 0.1ms.

[0123] Calculation of long side endpoint coordinates, application of geometric projection formula: extension distance: Pixel;

[0124] Trigonometric function values: Trigonometric function values: ; ;

[0125] Endpoint 1 calculation:

[0126] ;

[0127] ;

[0128] Endpoint 2 calculation:

[0129] ;

[0130] ;

[0131] Note: The negative y value of endpoint 2 indicates that it exceeds the upper boundary of the image (the origin of the coordinate system is at the upper left corner). In actual applications, it will be automatically truncated to the boundary.

[0132] Initial slope and intercept calculation, slope calculate:

[0133] ;

[0134] Initial intercept Calculate (taking endpoint 1):

[0135] ;

[0136] Refer to the intercept calculation formula: ;calculate: ;

[0137] Output:

[0138]

[0139] 204. Based on the initial intercept and the reference intercept, set the iteration start point, end point and step size. In each iteration, update the current intercept. In the contour point set of the binary image, count the number of points located within the tolerance band of the linear equation. Gradually reduce the iteration range and decrease the step size. Repeat the process until the preset number of iterations is reached. Select the intercept corresponding to the largest number of points as the candidate intercept.

[0140] Specifically, iterative interval initialization: calculate the initial intercept. With reference intercept median value Set the initial iteration starting point. End point The expansion coefficient =1.5; Set the initial step size. Multi-round iterative optimization: For each iteration: a) From to With the current step size Traversing intercept values b) For each In the target contour point set of the binary image, straight lines were statistically found. The vertical distance is less than the tolerance threshold Points c) Record the maximum score in this round. and its corresponding intercept d) Shrink the iteration range: update The shrinkage coefficient = 1.2; e) Decrease step size: Update Candidate intercept generation: After completing 3 preset iterations, the final intercept is output. as a candidate intercept .

[0141] It should be noted that the input is the initial intercept. =—13035.82; Reference intercept =—13035.44; Initial slope =5.674; Target contour point set (15240 points, from step 202); Tolerance threshold; =5 pixels; Preset parameter: expansion factor The shrinkage coefficient β = 1.2;

[0142] Iterative interval initialization, calculation of baseline value: intermediate value ; intercept difference ;

[0143] Setting range: starting point End point ;

[0144] Initial step size: ;

[0145] First iteration (range-wide search), traversing the intercept: from... =—13036.20 to =—13035.06, step size 0.038;

[0146] Key event: When =—13035.63: Statistics are obtained from the straight line. Number of pixels with a distance of less than 5 pixels =12410 (maximum); others The number of value points is less than 12000;

[0147] Updated parameters: Optimal intercept for this round =—13035.63;

[0148] Shrinkage range: New ;new Step size halved: ;

[0149] The second iteration (medium-precision search) traverses the intercept from -13035.68 to -13035.58 with a step size of 0.019. The key event is when... =—13035.62 hours: =12475 (Breaking the highest record);

[0150] Update parameters: ; Contraction range: ; ; Halve the step size again: ;

[0151] The third iteration (high-precision search) traverses the intercept from -13035.64 to -13035.60 with a step size of 0.0095; key events: when... =—13035.615 hours: =12492 (peak value reached); Final output: Candidate intercept ;

[0152] Iterative process:

[0153]

[0154] 205. Extract all contour points within the tolerance zone of the linear equation to form a point set. Refit the line using the least squares method on the point set to obtain the final slope and the optimal intercept.

[0155] Specifically, tolerance band point set extraction: based on candidate intercept. Given an initial slope k, select all points in the target contour point set that satisfy the vertical distance condition. The contour points constitute the initial point set. ,in Preset tolerance threshold; Point set optimization: Calculate the initial point set. From each point in the line Distance; exclude distances greater than The points generate a refined point set. To ensure a tight distribution of the point set; least squares fitting: for the refined point set Perform least squares line fitting: calculate the point set Coordinate mean and Coordinate mean According to the covariance formula Find the final slope; use the intercept formula. Find the optimal intercept; Fit verification: If the average distance between the fitted line and the refined point set exceeds... Then output As the final intercept.

[0156] It should be noted that the input candidate intercept =—13035.615; Initial slope k=5.674; Target contour point set (15240 points, from step 202); Tolerance threshold δ=5 pixels;

[0157] Tolerance band point set extraction, filtering criteria: vertical distance (pixels); Operation: Traverse the contour point set (15240 points), calculate the perpendicular distance of each point to the line y = 5.674x - 13035.615; keep points with a distance ≤ 5 pixels. Output: Initial point set It contains 12,492 points (accounting for 82% of the total).

[0158] Point set optimization, secondary filtering: calculation The distance from each point to the same straight line is calculated; points with a distance greater than 0.8 × 5 = 4 pixels are excluded. Key data: 1872 points are excluded (mainly distributed as: 1205 points of shaft end burrs and 667 points of oil stain noise); 10620 points are retained to form a refined point set. Results: The standard deviation of the point set distribution decreased from 2.8 pixels to 1.2 pixels, resulting in a 57% improvement in concentration.

[0159] Least squares fitting, mean calculation: ; ;

[0160] Slope Fitting: Molecular ; denominator ; ;

[0161] Intercept fitting: ;

[0162] Fit verification, average distance calculation: Calculate the perpendicular distance from the refined point set to the new line y = 5.672x - 13034.98; average distance = Pixel;

[0163] Threshold determination: 1.8 < 0.5 × 5 = 2.5 → Fitting is valid; if the average distance > 2.5 pixels, then fall back to the candidate intercept. .

[0164] Output parameters:

[0165]

[0166] 206. Based on the final slope and the optimal intercept, calculate the distance between the two parallel lines as the measurement dimension of the stepped shaft bar, output the dimension results and mark the measurement position on the original image;

[0167] Specifically, multi-segment dimension measurement: based on rotation angle and center point coordinates The bar stock is divided into multiple measurement sections along the stepped shaft axis; for each measurement section: based on the final slope and optimal intercept Generate two parallel lines: the upper boundary line. Lower boundary line: ;in Set a preset reference diameter; calculate the perpendicular distance between two parallel lines. The diameter of the current segment is used as the reference value; Step transition zone identification: if the diameter difference between adjacent measurement segments is... If the measurement is not accurate, it is determined to be a stepped transition position; mark the double measurement line at the transition position and record the diameters on both sides; result synthesis and output: merge the diameter data of all measurement segments to generate a complete dimension report of the stepped shaft; mark each measurement line segment with different colors on the original image: use solid green lines for straight segments; use dashed red lines for transition areas; overlay and display the dimension values ​​and tolerance judgment results.

[0168] It should be noted that the final slope is input. =5.672; optimal intercept =—13034.98; Center point coordinates Pixels; Rotation angle Preset reference diameter Pixel resolution r = 0.02 mm / pixel;

[0169] Axial segmentation, segmentation logic: along the axial direction (rotation angle) (Direction) Divide the stepped axis into 5 equal segments, each segment being 640 pixels long (total length 3200 pixels).

[0170] Calculation of the coordinates of the center point of each segment (along) (Directional Projection): Segment 1: L = -1280 pixels → (2782.2, 2750.5); Segment 2: L = -640 pixels → (2671.1, 2120.3); Segment 3: L = 0 → (2560.0, 1490.0); Segment 4: L = 640 pixels → (2448.9, 859.7); Segment 5: L = 1280 pixels → (2337.8, 229.5);

[0171] Diameter measurement of each segment, parallel line generation: Small end segment (segments 1-3): Offset Pixels; Top boundary line: Lower boundary line: Large end segment (4-5 segments): Offset Pixel;

[0172] Vertical distance calculation (Example 1): Pixel;

[0173] ;

[0174] Results for each segment:

[0175]

[0176] Step transition zone identification, diameter jump detection:

[0177] ;

[0178] The area between segments 3 and 4 is a transition zone, with coordinates from (2448.9, 859.7) to (2560.0, 1490.0).

[0179] Results output and annotation, dimension report: Stepped shaft dimension inspection report:

[0180] Section 1: Ø15.004 mm (Pass);

[0181] Section 2: Ø15.008 mm (Pass);

[0182] Section 3: Ø15.122 mm (transition zone);

[0183] Section 4: Ø24.951 mm (Pass);

[0184] Section 5: Ø24.973 mm (Pass);

[0185] Transition position: x = 2504.5 ± 55.5, y = 1174.8 ± 315.1;

[0186] Image annotations: Segment 1-2-3: solid green line (indicating the center line of each segment); Segment 3-4: double red dashed line (transition zone marker); Text annotations: diameter value and tolerance status of each segment (green for acceptable / yellow for out of tolerance).

[0187] In this embodiment of the invention, a boundary tracking algorithm is used to scan the entire image to identify the outer boundary of the connected region, which can comprehensively and accurately obtain the contour information in the image, providing rich basic data for subsequent target contour screening. By setting the area threshold and aspect ratio range, the contours of small noise points and non-bar objects are effectively filtered out, ensuring that the final selected target contour is accurate and reliable, thus improving the accuracy and efficiency of detection. The height value is directly used as the length of the long side, avoiding the computational overhead of dynamically comparing width and height in traditional methods, and improving the speed of direction determination. Accurate calculation of the long side endpoint coordinates using geometric projection formulas provides a precise foundation for subsequent linear parameter calculations. Through multiple rounds of iterative optimization, the search range is gradually narrowed and the step size reduced, enabling more precise identification of the intercept corresponding to the maximum number of points as a candidate intercept, thus improving intercept accuracy and consequently enhancing the linear fitting effect. The least squares method is used to refit the line within the tolerance zone, obtaining the final slope and optimal intercept, further improving the accuracy of linear fitting and making the measurement results more reliable. Dividing the stepped shaft bar into multiple measurement segments along its axial direction and calculating the diameter of each segment comprehensively and accurately reflects the dimensions of the stepped shaft, providing detailed data support for quality inspection. Accurately identifying the step transition position by detecting the diameter difference between adjacent measurement segments helps in a deeper analysis of the stepped shaft's structural characteristics. Marking each measurement line segment with different colors on the original image and overlaying the dimensional values ​​and tolerance judgment results makes the inspection results intuitive and easy to understand, facilitating quick judgment of the stepped shaft's quality status by operators.

[0188] The visual inspection method for stepped axes in the embodiments of the present invention has been described above. The visual inspection system for stepped axes in the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 3An embodiment of the visual inspection system for stepped shafts in this invention includes: an acquisition module 301, used to acquire the original image of the stepped shaft bar stock, perform denoising processing on the original image to generate a denoised image, perform a color inversion operation on the denoised image to generate an inverted image, convert the inverted image into a single-channel grayscale image to generate a grayscale image, and binarize the grayscale image using a fixed threshold segmentation method to generate a binary image containing only the target object and the background; an extraction module 302, used to extract the contours of all connected regions from the binary image, filter out the target contours, calculate its minimum bounding rectangle, and obtain the center point coordinates, width value, height value, and rotation angle of the minimum bounding rectangle; and a calculation module 303, used to determine the direction of the long side based on the width and height values ​​of the minimum bounding rectangle, and calculate the initial slope and angle based on the coordinates of the two endpoints of the long side direction using a two-point linear equation. The initial intercept is calculated based on the coordinates of the center point and the initial slope, and a reference intercept is calculated through the center point. The optimization module 304 is used to set the iteration start point, end point and step size based on the initial intercept and the reference intercept. In each iteration, the current intercept is updated. In the contour point set of the binary image, the number of points located within the tolerance zone of the linear equation is counted. The iteration range is gradually reduced and the step size is decreased. This process is repeated until the preset number of iterations is reached. The intercept corresponding to the largest number of points is selected as the candidate intercept. The identification module 305 is used to extract all contour points located within the tolerance zone of the linear equation, form a point set, and refit the line using the least squares method to obtain the final slope and the optimal intercept. The allocation module 306 is used to calculate the distance between two parallel lines based on the final slope and the optimal intercept, which is used as the measurement dimension of the stepped shaft bar. The dimension result is output and the measurement position is marked on the original image.

[0189] In this embodiment of the invention, through refined processing from the original image to a binary image, and subsequent optimization of the straight-line fitting process, the edge information of the stepped shaft bar can be extracted more accurately, thereby significantly improving the accuracy of dimensional measurement and reducing measurement errors caused by image noise, edge blurring, and other factors. The entire detection process is automated through modular design, requiring minimal manual intervention and greatly improving detection efficiency. From image acquisition to dimensional measurement result output, each module executes sequentially, quickly completing the dimensional inspection of the stepped shaft bar, suitable for the rapid quality inspection needs in large-scale production environments; and adaptable to the inspection of stepped shaft bars of different shapes and sizes. By extracting the target contour and calculating the minimum bounding rectangle, and then using a linear fitting method based on the contour point set, the edge features of stepped shaft bars of different specifications can be accurately extracted and their dimensions measured, demonstrating strong versatility and adaptability. It not only outputs the measured dimensions but also marks the measurement positions on the original image, making the detection results more intuitive and clear, facilitating operators' quick understanding and judgment of product quality. It also provides a strong basis for subsequent quality traceability and problem analysis. The optimization module effectively avoids fitting errors caused by unreasonable initial parameter settings by iteratively counting the number of points within the tolerance band and gradually reducing the iteration range and step size, improving the stability and accuracy of linear fitting and further ensuring the reliability of dimensional measurements.

[0190] above Figure 3 The visual inspection system for stepped shafts in this embodiment of the invention is described in detail from the perspective of modular functional entities. The visual inspection device for stepped shafts in this embodiment of the invention is described in detail from the perspective of hardware processing.

[0191] Figure 4 This is a schematic diagram of the structure of a visual inspection device 400 for a stepped axis according to an embodiment of the present invention. The visual inspection device 400 for the stepped axis can vary considerably due to differences in configuration or performance. The device 400 includes a transmitter 401, a receiver 402, and a processor 403. The processor 403 can also be a controller. Figure 4 The device is designated as "controller / processor 403". Optionally, the device 400 may also include a modem processor 405, which may include an encoder 406, a modulator 407, a decoder 408, and a demodulator 409.

[0192] In one example, transmitter 401 modulates (e.g., analog-to-analog conversion, filtering, amplification, and up-conversion, etc.) the output sample and generates an uplink signal, which is transmitted via an antenna to an access network device. On the downlink, the antenna receives the downlink signal transmitted by the access network device. Receiver 402 modulates (e.g., filtering, amplification, down-conversion, and digitization, etc.) the signal received from the antenna and provides an input sample. In modem processor 405, encoder 406 receives traffic data and signaling messages to be transmitted on the uplink and processes (e.g., formatting, encoding, and interleaving) the traffic data and signaling messages. Modulator 407 further processes (e.g., symbol mapping and modulation) the encoded traffic data and signaling messages and provides an output sample. Demodulator 409 processes (e.g., demodulates) the input sample and provides a symbol estimate. Decoder 408 processes (e.g., deinterleaving and decoding) the symbol estimate and provides decoded data and signaling messages to device 400. Encoder 406, modulator 407, demodulator 409, and decoder 408 can be implemented by a combined modem processor 405. These units perform processing according to the radio access technology adopted by the radio access network (e.g., LTE and other evolved systems access technologies). It should be noted that when device 400 does not include modem processor 405, the above-mentioned functions of modem processor 405 can also be performed by processor 403.

[0193] The processor 403 controls and manages the operation of the device 400, and is used to execute the processing procedures performed by the device 400 in the above embodiments of this disclosure. For example, the processor 403 is also used to execute various steps of the transmitting or receiving device in the above method embodiments, and / or other steps of the technical solutions described in the embodiments of this disclosure.

[0194] Furthermore, the device 400 may also include a memory 404 for storing program code and data for the device 400.

[0195] Understandable, Figure 4 Only a simplified design of device 400 is shown. In practical applications, device 400 can include any number of transmitters, receivers, processors, modem processors, memory, etc., and all devices that can implement the embodiments of this disclosure are within the protection scope of the embodiments of this disclosure.

[0196] The present invention also provides a visual inspection device for stepped shafts, the visual inspection device for stepped shafts including a memory and a processor, the memory storing computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor performs the steps of the visual inspection method for stepped shafts in the above embodiments.

[0197] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when the instructions are executed on a computer, cause the computer to perform the steps of the visual inspection method for the stepped axis.

[0198] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0199] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0200] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. 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 of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A visual inspection method for stepped axes, characterized in that, The visual detection method for the stepped axis includes: The original image of the stepped shaft bar is acquired, the original image is denoised to generate a denoised image, the denoised image is color inverted to generate an inverted image, the inverted image is converted into a single-channel grayscale image to generate a grayscale image, and the grayscale image is binarized by a fixed threshold segmentation method to generate a binary image containing only the target object and the background. Extract the contours of all connected regions from the binary image, filter out the target contours, calculate their minimum bounding rectangle, and obtain the center point coordinates, width, height and rotation angle of the minimum bounding rectangle. Based on the width and height of the minimum bounding rectangle, the direction of the long side is determined. Based on the coordinates of the two endpoints of the long side, the initial slope and initial intercept are calculated using a two-point linear equation. Based on the coordinates of the center point and the initial slope, the reference intercept through the center point is calculated. Based on the initial intercept and reference intercept, the iteration start point, end point, and step size are set. In each iteration, the current intercept is updated. In the contour point set of the binary image, the number of points located within the tolerance band of the linear equation is counted. The iteration range is gradually reduced and the step size is decreased. This process is repeated until the preset number of iterations is reached. The intercept corresponding to the largest number of points is selected as the candidate intercept, including: Iterative interval initialization: Calculate the initial intercept With reference intercept median value Set the initial iteration starting point. End point Set initial step size ; For each iteration: From to With the current step size Traversing intercept values For each In the target contour point set of the binary image, straight lines were statistically counted. The vertical distance is less than the tolerance threshold Points Record the maximum score in this round. and its corresponding intercept Shrinking the iteration range: updating The shrinkage coefficient = 1.2; Decrease step size: Update ; After completing the preset 3 rounds of iterations, the final output is given. as a candidate intercept ; Extract all contour points within the tolerance zone of the linear equation to form a point set. Refit the line using the least squares method on the point set to obtain the final slope and the optimal intercept. Based on the final slope and optimal intercept, the distance between the two parallel lines is calculated as the measurement dimension of the stepped shaft bar, the dimension result is output, and the measurement position is marked on the original image.

2. The visual inspection method for stepped axes according to claim 1, characterized in that, include: The original image is generated by vertically capturing images of the stepped shaft bar material placed horizontally using a fixed, high-resolution industrial camera. The original image is noise-removed using a median filter with a window size of 3×3 pixels to generate a denoised image; Perform a 255 subtraction operation on each pixel of the denoised image to generate an inverted image; The inverted image is converted from RGB three-channel mode to single-channel grayscale mode to generate a grayscale image; Based on a preset fixed threshold, the regions in the grayscale image with pixel values ​​greater than the fixed threshold are set to a white background, and the remaining regions are set to a black target, generating a binary image containing only the target object and the background.

3. The visual inspection method for stepped axes according to claim 2, characterized in that, include: The binary image is scanned in its entirety to identify the outer boundaries of all connected regions and generate an initial contour set. Target contour filtering: Calculate the minimum bounding rectangle area of ​​each contour and retain contours with an area greater than a preset threshold; calculate the aspect ratio of the minimum bounding rectangle of the retained contours and filter out contours with aspect ratios exceeding the range [1.5, 20]; sort the remaining contours in descending order of area and select the contour with the largest area as the target contour. Minimum bounding rectangle calculation: Based on the pixel coordinate set of the target contour, calculate its minimum bounding rectangle; extract the center point coordinates, width, height, and rotation angle of the rectangle. ; If the rotation angle > 90°, then update ° and swap the width and height values ​​to ensure that they always represent the length of the longer side.

4. The visual inspection method for stepped axes according to claim 3, characterized in that, include: The height value of the minimum bounding rectangle The length of the longer side is used as the length of the shorter side, and the height direction is the direction of the longer side. Based on the coordinates of the center point and rotation angle Extending to both sides along the long side Distance is calculated using the geometric projection formula, determining the coordinates of the two endpoints of the longer side: Endpoint 1: Endpoint 2: ; Calculate the initial slope k based on the coordinates of endpoint 1 and endpoint 2. Substitute the coordinates of any endpoint into the equation of the line. Generate the initial intercept ; The coordinates of the center point Substituting the initial slope k into the equation of the line Generate reference intercept .

5. The visual inspection method for stepped axes according to claim 1, characterized in that, include: Based on the candidate intercept Given an initial slope k, select all points in the target contour point set that satisfy the vertical distance condition. The contour points constitute the initial point set. ,in The preset tolerance threshold; Calculate the initial point set From each point in the line Distance; exclude distances greater than The points generate a refined point set. ; Refinement Point Set Perform least squares line fitting: calculate the point set Coordinate mean and Coordinate mean According to the covariance formula Find the final slope; use the intercept formula. Find the optimal intercept; If the average distance between the fitted line and the refined point set exceeds Then output As the final intercept.

6. The visual inspection method for stepped axes according to claim 5, characterized in that, include: Based on rotation angle and center point coordinates The bar stock is divided into multiple measurement segments along the stepped shaft axis; for each measurement segment: based on the final slope... and optimal intercept Generate two parallel lines: the upper boundary line. Lower boundary line: ;in Set a preset reference diameter; calculate the perpendicular distance between two parallel lines. , which serves as the diameter of the current segment.

7. The visual inspection method for stepped axes according to claim 6, characterized in that, If the diameter difference between adjacent measurement sections If the position is a stepped transition point, mark the double measuring line at the transition point and record the diameters on both sides.

8. The visual inspection method for stepped axes according to claim 7, characterized in that, Merge all diameter data of the measured segments to generate a complete dimension report of the stepped shaft. Mark each measurement line on the original image with different colors and overlay the dimension values ​​and tolerance judgment results.

9. A visual inspection system for stepped axes, characterized in that, The visual inspection system for the stepped axis includes: The acquisition module is used to acquire the original image of the stepped shaft bar, perform denoising processing on the original image to generate a denoised image, perform a color inversion operation on the denoised image to generate an inverted image, convert the inverted image into a single-channel grayscale image to generate a grayscale image, and binarize the grayscale image using a fixed threshold segmentation method to generate a binary image containing only the target object and the background. The extraction module is used to extract the contours of all connected regions from the binary image, filter out the target contours, calculate their minimum bounding rectangle, and obtain the center point coordinates, width value, height value and rotation angle of the minimum bounding rectangle. The calculation module is used to determine the direction of the long side based on the width and height of the minimum bounding rectangle, calculate the initial slope and initial intercept based on the coordinates of the two endpoints of the long side direction using a two-point linear equation, and calculate the reference intercept through the center point based on the coordinates of the center point and the initial slope. The optimization module is used to set the iteration start point, end point, and step size based on the initial intercept and reference intercept. In each iteration, it updates the current intercept, counts the number of points within the tolerance band of the linear equation in the contour point set of the binary image, gradually narrows the iteration range and decreases the step size, and repeats the process until a preset number of iterations is reached. The intercept corresponding to the largest number of points is selected as the candidate intercept, including: Iterative interval initialization: Calculate the initial intercept With reference intercept median value Set the initial iteration starting point. End point Set initial step size ; For each iteration: From to With the current step size Traversing intercept values For each In the target contour point set of the binary image, straight lines were statistically counted. The vertical distance is less than the tolerance threshold Points Record the maximum score in this round. and its corresponding intercept Shrinking the iteration range: updating The shrinkage coefficient = 1.2; Decrease step size: Update ; After completing the preset 3 rounds of iterations, the final output is given. as a candidate intercept ; The identification module is used to extract all contour points within the tolerance zone of the linear equation, forming a point set. The point set is then refitted with the linear equation using the least squares method to obtain the final slope and the optimal intercept. The allocation module is used to calculate the distance between two parallel straight lines based on the final slope and the optimal intercept, as the measurement dimension of the stepped shaft bar, output the dimension result, and mark the measurement position on the original image.

Citation Information

Patent Citations

  • Gear keyway width measuring method applying machine vision

    CN120689384A