Motor shaft size measurement and surface defect detection method based on machine vision
Through machine vision-based detection methods, combined with OTSU threshold method, Tukey fitting algorithm and Huber fitting algorithm, the ceramic motor shaft is measured and defect detection, which solves the problems of low production efficiency and low accuracy in the existing technology, and achieves efficient and accurate detection effects.
Patent Information
- Application Number
- CN202510089791.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-02-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art has problems such as low production efficiency, low accuracy and fatigue caused by missed inspections and missed inspections in the dimensional measurement and surface defect detection of ceramic motor shafts.
Using machine vision-based detection methods, by building a visual acquisition environment, image acquisition and binarization of the motor shaft is carried out, and combined with OTSU threshold method, Tukey fitting algorithm and Huber fitting algorithm, size measurement and defect detection are achieved.
It realizes rapid and accurate measurement and defect detection of ceramic motor shafts, improves detection efficiency and accuracy, reduces labor costs, and improves production efficiency.
Smart Images

Figure CN119515880A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of ceramic motor shaft detection, and in particular to a motor shaft dimension measurement and surface defect detection method based on machine vision. Background Art
[0002] Since the motor shaft is small in size, the standard is 2.3mm in length and 1mm in width, and the tolerance range is ±0.03mm in length and ±0.002mm in width. The motor shaft has chamfers on both the top and bottom, and the chamfer tolerance is ±0.0015mm. The dimensional accuracy requirement is extremely high, and some motor shafts have yellow spots, spots, and cracks on the surface, which are difficult to distinguish with the naked eye, and defect detection is also difficult. At present, the dimensional measurement and appearance inspection of motor shafts are mainly completed by employees manually measuring with a micrometer and manually inspecting surface defects under a high-precision camera. This inspection method has the following shortcomings: (1) The production efficiency is slow and it is difficult to meet the output requirements.
[0003] (2) The dimensional accuracy requirement is high and the detection is done manually, which can easily affect the detection accuracy.
[0004] (3) Employees working in front of the screen for a long time are prone to fatigue and distraction, which may lead to missed detections and false detections.
[0005] Therefore, a motor shaft dimension measurement and surface defect detection method based on machine vision is needed to solve the above problems. Summary of the invention
[0006] The purpose of the present invention is to provide a motor shaft dimension measurement and surface defect detection method based on machine vision to solve the problems existing in the prior art mentioned in the above background technology.
[0007] To achieve the above object, the present invention provides the following technical solutions: A method for measuring motor shaft dimensions and detecting surface defects based on machine vision comprises the following steps: S1: Build a visual acquisition environment to collect images of the motor shaft; S2: Binarize the acquired motor shaft image to clearly display the edge information of the motor shaft image; S3: Select the ROI area and perform sub-pixel extraction to lock the contour edge, fit it into a straight line through the fitting algorithm, and obtain the product size information; S4: Select the ROI area where the chamfer is located, and locate the chamfer radian information by fitting a circle using the Huber algorithm to obtain the chamfer radian information of the product; S5: Use Gaussian filtering, difference operation and Blob analysis image detection algorithm to locate the position, size and shape information of the defect on the motor shaft to achieve defect detection of the motor shaft; S6: Determine whether the product is qualified by combining the dimension measurement information and defect detection results.
[0008] Preferably, in S1, a 20-megapixel CCD camera is used in combination with a telecentric lens, and a lighting scheme of side surface light and bottom surface light is used to build a visual environment.
[0009] Preferably, in S2, the specific steps of binary processing of the motor shaft image are: The OTSU threshold method is used to binarize the motor shaft image, and each grayscale pixel in the image is classified according to the grayscale value to obtain n0, n1, n2...n i ...n 255 , where n i is the number of pixels with grayscale value i in the image, then the formula for the probability that the pixel grayscale value in the image is i is shown in formula 1-1: (1-1) Among them, the probability satisfies And P i >0, assuming that the threshold is k, the probability that the pixel is assigned to the background area is P m (k), the average grayscale of the background area is G m (k), the probability of being assigned to the target area is P n (k), the average grayscale of the target area is G n (k), the gray value of the entire image is G, and the expression of the inter-class variance is shown in formula 1-2: (1-2) in, is the maximum inter-class square difference, and T is the optimal threshold.
[0010] Preferably, in S3, a Tukey weighted fitting function is used, as shown in Formula 1-3: (1-3) In the above formula, is the distance from the point to the line, is the threshold value set, when Less than or equal to When these points are given weights ,so The smaller it is, the greater the weight; when Greater than When giving weight .
[0011] Preferably, in S4, the Huber loss function combines the linear regression loss function and the absolute value loss function, and is proposed to enhance the robustness of the least squares method to noise outliers. The function formula is shown in Formula 1-4: (1-4) In the above formula, α is the residual, which is the distance between the generated straight line and the discrete point in straight line fitting; δ is the residual threshold, which is used to determine whether it is an error point.
[0012] Preferably, in S5, Gaussian filtering is used for noise reduction processing, and a sliding convolution block is moved to each pixel point of the image. Each pixel point in the convolution kernel is weighted averaged according to the weight of the Gaussian function according to its distance from the center point to obtain a new pixel point value, as shown in Formulas 1-5 and 1-6: (1-5) (1-6) In the formula represents the pixel value of the image in the i-th row and j-th column, represents the pixel value of the filtered image in the i-th row and j-th column, represents the Gaussian kernel, * is the convolution operation, is the standard deviation of the Gaussian kernel, (x, y) is the pixel coordinates on the two-dimensional plane; Perform a difference operation between the original grayscale image and the background image to obtain the difference image : (1-7) In the formula is the denoised image, The image is the background image. After the image is differentiated, the defect area is segmented to the greatest extent. After obtaining the differential image containing only the defect area, Blob analysis is used to determine the location, size, shape and other information of the defect. Combined with the previously measured size and chamfer information, the result is visualized on the image.
[0013] Compared with the prior art, the present invention has the following beneficial effects: In view of the small size and high precision of the ceramic motor shaft and the detection requirements, the present invention designs a full-process detection method for size measurement and defect detection. According to the characteristics of the size and shape of the ceramic motor shaft, the OTSU threshold method, the Tukey fitting algorithm and the Huber fitting algorithm are combined, which can quickly and accurately measure the size and chamfer information of the ceramic motor shaft. According to the defect characteristics of the ceramic motor shaft, the position, size and shape information of the defects on the motor shaft are locked through Gaussian filtering, difference operation and Blob analysis image detection algorithm, so as to realize the defect detection of the motor shaft, thereby realizing accurate and efficient detection of the quality of the ceramic motor shaft. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 It is a flowchart of the detection method of the present invention.
[0015] Figure 2 This is a comparison diagram before and after the image binarization processing of the present invention.
[0016] Figure 3 This is a comparison diagram before and after the image contour edge fitting process of the present invention.
[0017] Figure 4 This is a comparison diagram before and after fitting the four corner points of the image of the present invention.
[0018] Figure 5 This is a comparison diagram before and after the image filtering of the present invention.
[0019] Figure 6 This is the effect diagram after the image difference operation of the present invention.
[0020] Figure 7 This is a diagram showing the effect of motor shaft size measurement and defect detection according to the present invention. DETAILED DESCRIPTION
[0021] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the present invention is further explained below in conjunction with specific implementation methods.
[0022] See also Figure 1-7 , the present invention provides the following technical solutions: A method for measuring motor shaft dimensions and detecting surface defects based on machine vision comprises the following steps: S1: Build a visual acquisition environment to capture images of the motor shaft; select a 20-megapixel CCD camera with a telecentric lens, and use side and bottom lighting to build a visual environment, so as to achieve high-precision measurement of the motor shaft size, with a measurement error as low as 2 μ, and reserve two detection positions on the mechanism for simultaneous detection, which greatly improves the detection efficiency.
[0023] S2: Binarize the collected motor shaft image so that the edge information of the motor shaft image is clearly displayed; image binarization is the process of setting the grayscale value of each pixel of the image to 0 or 255, that is, making the entire image appear to be only black and white; image binarization can further reduce the amount of image data and highlight the outline of the target. The binarization algorithm uses a specific threshold to divide the grayscale value of the image into two areas. Pixels above the threshold are set to white (grayscale value 255), and pixels below the threshold are set to black (grayscale value 0). Binarization can significantly reduce the amount of data in the image, while highlighting the target outline, making image analysis or processing more convenient and efficient.
[0024] The specific steps of the motor shaft image binarization process are: The motor shaft image is binarized using the OTSU threshold method. The OTSU threshold method is an algorithm for binary segmentation of images. It segments the foreground and background of an image based on the inter-class variance. The variance is a measure of the uniformity of grayscale distribution. The larger the inter-class variance, the greater the difference between the parts of the image. Each grayscale pixel in the image is classified according to the grayscale value to obtain n0, n1, n2...n i ...n 255 , where n i is the number of pixels with grayscale value i in the image, then the formula for the probability that the pixel grayscale value in the image is i is shown in formula 1-1: (1-1) Among them, the probability satisfies And P i >0, assuming that the threshold is k, the probability that the pixel is assigned to the background area is P m (k), the average grayscale of the background area is G m (k), the probability of being assigned to the target area is P n (k), the average grayscale of the target area is G n (k), the gray value of the entire image is G, and the expression of the inter-class variance is shown in formula 1-2: (1-2) in, is the maximum inter-class square difference, and T is the optimal threshold. The effect of the image after OTSU threshold binarization is as follows Figure 2 As shown in the figure, it can be seen that the image after binarization has a clearer outline.
[0025] S3: Lock the contour edge by selecting the ROI area and performing sub-pixel extraction, and fit it into a straight line through the fitting algorithm to obtain the product size information; in straight line fitting, the most commonly used fitting method is the least squares method, which requires the observed value yi The weighted sum of squares of the deviations is the smallest, but in practical applications, there are more or less abnormal values x that deviate from the normal value. i , these outliers will cause large errors when using the least squares method for straight line fitting, while the Tukey fitting algorithm can weight the contour points and ignore the outliers, making the straight line fitting result more accurate, and the fitted straight line basically coincides with the actual straight line. Therefore, the Tukey weighted fitting function is used, as shown in formula 1-3: (1-3) In the above formula, is the distance from the point to the line, is the threshold value set. Less than or equal to When these points are given weights ,so The smaller it is, the greater the weight; when Greater than When giving weight The effect after fitting is as follows: Figure 3 shown.
[0026] S4: Locate the four corner points based on the collected size profile information, select the ROI area where the chamfer is located, and locate the chamfer radian information by fitting a circle through the Huber algorithm to obtain the chamfer radian information of the product; The Huber loss function combines the linear regression loss function and the absolute value loss function. It is proposed to enhance the robustness of the least squares method to noise outliers. The function formula is shown in Equation 1-4: (1-4) In the above formula, α is the residual, which is the distance between the generated straight line and the discrete point in straight line fitting; δ is the residual threshold, which is used to determine whether it is an error point. After the introduction of the Huber loss function, it will not be as sensitive to abnormal points in the boundary curve as the least squares fitting function. No matter how large the fitting loss is, the loss function of the least squares method always grows as a quadratic function, while the Huber algorithm will only be effective when the residual value is greater than the residual threshold. When , the loss function grows linearly. Compared with the Tukey weighted fitting algorithm, the application of the Huber weighted algorithm can reduce the influence of outliers on the fitting circle equation, while not losing the information of important contour points. The fitting result of the quasi-circular area is relatively ideal. Therefore, the present invention uses the Huber fitting algorithm to fit the chamfer radian. The effect after fitting is as follows: Figure 4 shown.
[0027] S5: Use Gaussian filtering, difference operation and Blob analysis image detection algorithm to locate the position, size and shape information of the defect on the motor shaft to achieve defect detection of the motor shaft; When using an imaging system for image acquisition, the acquired image will be affected by noise and bad pixels due to environmental factors, the characteristics of the object being measured, and the heat generation of the device itself. These noises that affect the image quality will have a certain impact on the defect detection process, and it is easy to misjudge these noises as defects. Therefore, in order to build a highly accurate defect detection system, the acquired original image must be effectively denoised before defect detection. The present invention uses Gaussian filtering to achieve noise reduction.
[0028] Move a sliding convolution block to each pixel of the image. Each pixel in the convolution kernel will be weighted averaged according to the weight of the Gaussian function based on its distance from the center point to obtain a new pixel value, as shown in formulas 1-5 and 1-6: (1-5) (1-6) In the formula represents the pixel value of the image in the i-th row and j-th column, represents the pixel value of the filtered image in the i-th row and j-th column, represents the Gaussian kernel, * is the convolution operation, is the standard deviation of the Gaussian kernel, (x, y) is the pixel coordinates of the two-dimensional plane; the image comparison before and after filtering is Figure 5 shown.
[0029] Depend on Figure 5 It can be seen that Gaussian filtering can locally remove pixels with large grayscale and gradient differences near edge pixels through convolution, and connect some gaps. This method essentially uses the grayscale median of pixels in a larger neighborhood to estimate the central pixel, thereby obtaining the normal area of the motor shaft surface. Therefore, the image after Gaussian filtering is selected as the defect-free background image.
[0030] Perform a difference operation between the original grayscale image and the background image to obtain the difference image : (1-7) In the formula is the denoised image, is the background image. After the image is differentiated, the defect area is segmented to the greatest extent, such as Figure 6 shown.
[0031] After obtaining the differential image containing only the defect area, Blob analysis is used to determine the location, size, shape and other information of the defect. Combined with the previously measured size and chamfer information, the results are visualized on the image.
[0032] S6: Combine the dimensional measurement information and defect detection results to determine whether the product is qualified; e.g. Figure 7 As shown, it can be seen that the defects are accurately detected, and the size and chamfer are accurately measured, which meets the production requirements. After production verification, this method can achieve high-speed efficiency of detecting two products in an average of 2s based on high-precision detection, which saves the company's labor costs and greatly improves the company's production efficiency.
[0033] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A motor shaft dimension measurement and surface defect detection method based on machine vision, characterized in that: The following steps are involved: S1: Build a visual acquisition environment to collect images of the motor shaft; S2: Binarize the acquired motor shaft image to clearly display the edge information of the motor shaft image; S3: Select the ROI area and perform sub-pixel extraction to lock the contour edge, fit it into a straight line through the fitting algorithm, and obtain the product size information; S4: Select the ROI area where the chamfer is located, and locate the chamfer radian information by fitting a circle using the Huber algorithm to obtain the chamfer radian information of the product; S5: Use Gaussian filtering, difference operation and Blob analysis image detection algorithm to locate the position, size and shape information of the defect on the motor shaft to achieve defect detection of the motor shaft; S6: Determine whether the product is qualified by combining the dimension measurement information and defect detection results.
2. The method for measuring motor shaft dimensions and detecting surface defects based on machine vision according to claim 1, characterized in that: In the S1, a 20-megapixel CCD camera is used in combination with a telecentric lens, and the visual environment is constructed using side and bottom lighting solutions.
3. The method for measuring motor shaft dimensions and detecting surface defects based on machine vision according to claim 1, characterized in that: In S2, the specific steps of the motor shaft image binarization process are: The OTSU threshold method is used to binarize the motor shaft image, and each grayscale pixel in the image is classified according to the grayscale value to obtain n0, n1, n2...n i ...n 255 , where n i is the number of pixels with grayscale value i in the image, then the formula for the probability that the pixel grayscale value in the image is i is shown in formula 1-1: (1-1) Among them, the probability satisfies And P i >0, assuming that the threshold is k, the probability that the pixel is assigned to the background area is P m (k), the average grayscale of the background area is G m (k), the probability of being assigned to the target area is P n (k), the average grayscale of the target area is G n (k), the gray value of the entire image is G, and the expression of the inter-class variance is shown in formula 1-2: (1-2) in, is the maximum inter-class square difference, and T is the optimal threshold.
4. The method for measuring motor shaft dimensions and detecting surface defects based on machine vision according to claim 1, characterized in that: In S3, Tukey weighted fitting function is used, as shown in Formula 1-3: (1-3) In the above formula, is the distance from the point to the line, is the threshold value set. Less than or equal to When these points are given weights ,so The smaller it is, the greater the weight; when Greater than When giving weight .
5. The method for measuring motor shaft dimensions and detecting surface defects based on machine vision according to claim 1, characterized in that: In S4, the Huber loss function combines the linear regression loss function and the absolute value loss function, and is proposed to enhance the robustness of the least squares method to noise outliers. The function formula is shown in Formula 1-4: (1-4) In the above formula, α is the residual, which is the distance between the generated straight line and the discrete point in straight line fitting; δ is the residual threshold, which is used to determine whether it is an error point.
6. The method for measuring motor shaft dimensions and detecting surface defects based on machine vision according to claim 1, characterized in that: In S5, Gaussian filtering is used for noise reduction processing. A sliding convolution block is moved to each pixel of the image. Each pixel in the convolution kernel is weighted averaged according to the weight of the Gaussian function based on its distance from the center point to obtain a new pixel value, as shown in Formulas 1-5 and 1-6: (1-5) (1-6) In the formula represents the pixel value of the image in the i-th row and j-th column, represents the pixel value of the filtered image in the i-th row and j-th column, represents the Gaussian kernel, * is the convolution operation, is the standard deviation of the Gaussian kernel, (x, y) is the pixel coordinates on the two-dimensional plane; Perform a difference operation between the original grayscale image and the background image to obtain the difference image : (1-7) In the formula is the denoised image, is the background image. After the image is differentiated, the defect area is segmented to the greatest extent; After obtaining the differential image containing only the defect area, Blob analysis is used to determine the location, size, shape and other information of the defect. Combined with the previously measured size and chamfer information, the results are visualized on the image.
Citation Information
Patent Citations
Gear burr detection method and a gear high-precision visual measurement system
CN109829897A
Battery coating defect detection method and device and storage medium
CN113592845A
Visual measurement method for round hole size of sheet metal part with imaging interference characteristic
CN118836770A
Ceramic chopper automatic concentricity adjustment grinding technology based on machine vision
CN119141338A