Motor shell defect detection method
By performing edge detection and gradient value correction on the surface image of the motor housing, the accuracy problem of the Canny edge detection algorithm when detecting the edges of defective areas is solved, achieving higher detection accuracy and effective offset on the impact of light and texture.
Patent Information
- Application Number
- CN202411976492.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-12-31
AI Technical Summary
When the Canny edge detection algorithm detects the edge of the defect area of the motor housing, due to the texture and light of the motor housing, the edge of the defect area cannot be accurately detected, affecting the accuracy of the detection.
By collecting the surface image of the motor housing, performing edge detection to obtain each edge point, calculating the possibility and correction possibility that the edge point belongs to the defect edge, adjusting the gradient value to obtain the correction gradient value, and then obtaining the real edge detection image to identify the defect type.
Effectively distinguish between defect area edges and non-defect area edges, improve the accuracy of motor housing defect detection and reduce the impact of light and texture.
Smart Images

Figure CN119399189A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and more particularly to a method for detecting defects in a motor housing. Background Art
[0002] Electric motors are essential equipment in modern industry and life, and the motor housing, a crucial component, not only protects the internal mechanical and electronic components but also impacts the motor's heat dissipation and overall structural strength. Therefore, defect detection of motor housings is extremely important. Traditional manual inspection methods can be inefficient and subject to subjective factors. However, automated inspection based on image processing can quickly and accurately detect surface defects on motor housings, improving production line efficiency and product quality consistency. Real-time image processing technology enables instant inspection and monitoring of each motor housing, enabling timely identification of production problems and the implementation of appropriate adjustments to ensure product quality. This process often requires edge detection of the motor housing to identify defects, facilitating subsequent defect detection.
[0003] The patent application document currently published with the publication number CN114972281A discloses a method and terminal for image contour optimization based on visual detection. The method obtains the binary contour and Canny contour corresponding to the source image; weightedly fuses the binary contour and the Canny contour to determine the contour overlap weight; determines whether the overlap weight exceeds a preset threshold, and if so, marks the binary contour as a basic contour; traverses the Canny contour, connects the basic contour to the remaining contour of the Canny contour that exceeds the basic contour, and obtains a target binary contour; combines the target binary contour and the Canny contour to find and fill closed contours to obtain a final contour image.
[0004] When using the Canny edge detection algorithm in the above method to detect defects in the motor casing, the Canny edge detection cannot accurately detect the edges of the defective area of the motor casing due to the edges of non-defective areas such as the texture and lighting of the motor casing itself, thereby affecting the accuracy of defect detection of the motor casing. Summary of the Invention
[0005] In order to solve the problem that the edges of non-defective areas of the motor housing, such as the texture and lighting of the motor housing itself, cannot accurately detect the edges of the defective areas of the motor housing by Canny edge detection, thereby affecting the accuracy of motor housing defect detection, the present invention proposes a motor housing defect detection method, which includes the following steps: Collecting the shell surface image; performing edge detection on the shell surface image to obtain each edge point of the shell surface image; and obtaining the possibility that each edge point belongs to a defect edge; Get the possibility of correction of each edge point belonging to the defect edge: ; Represents the possibility of correction that the i-th edge point belongs to the defect edge; Represents the possibility that the i-th edge point belongs to the defect edge; as well as They represent the gradient directions of the first pixel and the second pixel in the p-th pixel pair of the i-th edge point respectively; C represents the number of pixel pairs of the i-th edge point; exp() represents an exponential function with a natural constant as the base; Obtain a corrected gradient value for each edge point, where the corrected gradient value is the product of the correction probability that each edge point belongs to a defect edge and its gradient value; obtain a true edge detection image based on the corrected gradient value of each edge point; and identify the defect type on the shell surface based on the true edge detection image.
[0006] Preferably, the performing edge detection on the shell surface image to obtain edge points of the shell surface image comprises the steps of: A low threshold T is preset, and edge detection is performed on the shell surface image based on the low threshold T in combination with the Canny edge detection algorithm to obtain an edge detection image. Each edge of the edge detection image is mapped to the shell surface image to obtain each edge point of the shell surface image.
[0007] Preferably, the probability of each edge point belonging to a defect edge is obtained by calculating the formula: ; Where, Represents the possibility that the i-th edge point belongs to the defect edge; Represents the average gradient value of all pixels in the eight-neighborhood range of the i-th edge point; Represents the gradient value of the pixel at the jth row and kth column in the eight-neighborhood range of the i-th edge point; exp() represents the exponential function with a natural constant as the base; || represents the absolute value function.
[0008] Preferably, obtaining the pixel pairs of the edge points includes the steps of: A pixel pair consisting of any two pixels in the eight-neighborhood range of the i-th edge point in the shell surface image is recorded as a group of pixel pairs of the i-th edge point, and all groups of pixel pairs of the i-th edge point are obtained.
[0009] Preferably, the acquisition of the gradient direction includes the steps of: The i-th edge point in the shell surface image and each pixel in the eight-neighborhood of the i-th edge point are recorded as the first pixel point, and the grayscale values of all first pixels are fitted with the least squares pixel method to obtain the first-order derivatives of each first pixel in the x-direction and y-direction of the fitting surface. Based on the existing gradient direction calculation method, the gradient direction of each first pixel is obtained according to the first-order derivatives of each first pixel in the x-direction and y-direction of the fitting surface.
[0010] Preferably, the correction gradient value of each edge point is obtained by the following calculation formula: ; Where, Represents the possibility of correction that the i-th edge point belongs to the defect edge; Represents the corrected gradient value of the i-th edge point; Represents the gradient value of the i-th edge point.
[0011] Preferably, obtaining a true edge detection image according to the corrected gradient value of each edge point comprises the steps of: According to the corrected gradient value of each edge point of the shell surface image, the canny edge detection algorithm is used to perform edge detection on the shell surface image to obtain a true edge detection image.
[0012] Preferably, the step of identifying the defect type on the shell surface based on the real edge detection image comprises the following steps: The real edge detection image of the motor housing is input into the trained defect recognition neural network to identify the defect type of the motor housing.
[0013] The present invention has the following beneficial effects: the present invention corrects the gradient value of each edge point in the shell surface image according to the correction possibility that each edge point belongs to the defect edge, and obtains the corrected gradient value of each edge point in the shell surface image, which can reduce the gradient value of the pixel point in the non-defective area, so that the gradient value of the pixel point in the defective area is prominent; then based on the said corrected gradient value, the real edge detection image is obtained to identify the defect type of the shell surface, so that the real defect edge can be detected, and the accuracy of the shell surface defect detection is improved. Furthermore, the correction possibility that each edge point in the shell surface image belongs to the defect edge is obtained by correcting the possibility that the edge point belongs to the defect edge according to the consistency of the grayscale change direction within the neighborhood range of the edge point, thereby avoiding the influence of the illumination edge and the texture of the shell itself. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood by reading the following detailed description with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present invention are shown in an illustrative and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein: Figure 1 This is a flowchart of the steps of a method for detecting defects in a motor housing according to an embodiment of the present invention. DETAILED DESCRIPTION
[0015] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work shall fall within the scope of protection of the present invention.
[0016] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0017] See also Figure 1 , which shows a flowchart of a method for detecting defects in a motor housing provided by one embodiment of the present invention, the method comprising the following steps: S001. Collect the surface image of the motor housing and perform preprocessing.
[0018] Specifically, a high-resolution industrial camera is used to photograph the outer shell surface of the motor to obtain an RGB image of the outer shell surface. To facilitate subsequent analysis, the RGB image of the outer shell surface is grayscale processed and denoised using a Gaussian filter. The image is then recorded as the outer shell surface image.
[0019] S002: Use an edge detection algorithm to perform edge detection on the shell surface image to obtain each edge point in the shell surface image.
[0020] It should be noted that the purpose of the present invention is to distinguish the edges of defective areas from the edges of non-defective areas (self-texture and illuminated edges) in the surface image of the motor casing. Therefore, it is necessary to first perform edge detection on the casing surface image to obtain the edge points of the casing surface image. In order to include the edge information of all defective areas, the present invention needs to select a smaller threshold for edge detection.
[0021] Specifically, a low threshold T is preset. According to the low threshold, edge detection is performed on the shell surface image in combination with the Canny edge detection algorithm to obtain an edge detection image. Each edge of the edge detection image is mapped to the shell surface image to obtain each edge point of the shell surface image. In an embodiment of the present invention, the low threshold T is preset to 0.06. In other inventive embodiments, the implementer may preset the value of the low threshold according to the specific implementation situation.
[0022] S003. Obtain the possibility that each edge point of the shell surface image belongs to a defect edge, and correct the possibility that each edge point of the shell surface image belongs to a defect edge based on the consistency of the grayscale change direction within the neighborhood of each edge point to obtain the corrected possibility that each edge point of the shell surface image belongs to a defect edge, and adjust the gradient value of the edge point to obtain the corrected gradient value of each edge point in the shell surface image, thereby obtaining a true edge detection image.
[0023] It should be noted that in the image of the motor's housing surface, its own texture, including edges caused by illumination, will appear as high gradient values, which are similar to the high gradient values of defect edges. If these are not distinguished, the defect edges cannot be detected well using Canny edge detection, thus affecting the final defect detection. Therefore, the present invention uses the edge features of the non-defective area (its own texture, illuminated edges) to reflect the possibility of each edge point being a defect edge. That is, the more an edge point exhibits the edge features of the non-defective area, the lower the possibility of it being a defect edge. Therefore, the gradient value of each edge point is corrected based on the possibility of each edge point being a defect edge, so that the true defect edge is displayed in the final Canny edge detection result.
[0024] It should be noted that the pixel value changes of the edge pixels of the defective area are relatively chaotic, that is, the gradient values are uneven, while the texture contour of the motor housing surface itself usually shows a sudden change in grayscale value at the edge, and the grayscale value changes are relatively regular, that is, the gradient value is uniform. Therefore, the uniformity of the gradient values of other pixel points in the neighborhood of the edge point can be used to obtain the possibility that each edge point belongs to a defective edge. Among them, the larger the gradient value in the neighborhood of the edge point and the better the uniformity of the gradient value, the more sudden and regular the change of the grayscale value of the edge point is, and the higher the possibility that it is the texture contour of the motor housing surface itself, and the lower the possibility that it belongs to a defective edge.
[0025] Specifically, the probability that each edge point of the shell surface image belongs to the defect edge is obtained: ; Where, Represents the possibility that the i-th edge point of the shell surface image belongs to the defect edge; Represents the average gradient value of all pixels in the eight-neighborhood range of the i-th edge point of the shell surface image; The gradient value of the pixel at row j and column k in the eight-neighborhood range of the i-th edge point of the shell surface image; The larger the value of , the larger the overall gradient value of the pixels in the neighborhood of the i-th edge point is, indicating that the i-th edge point is more likely to be a pixel point at the texture contour in the shell surface image; Represents the uniformity of the gradient values of all pixels in the neighborhood of the i-th edge point. The smaller the value, the more likely the i-th edge point is to be a pixel at the texture contour. The larger the value, the more likely the i-th edge point is to be a defective edge pixel. exp() represents an exponential function with a natural constant as the base. In the embodiment of the present invention, the exp(-x) model is used to present an inverse proportional relationship. x represents the input of the model. The implementer can set the inverse proportional function according to the actual implementation situation. || represents the absolute value function. The larger the value of , the greater the possibility that the i-th edge point of the shell surface image belongs to the defect edge.
[0026] It should be noted that since there may be light in the shell surface image, light will also cause the edge of the non-defective area to appear in the shell surface image (due to the material problem of the motor shell, light will cause a highlight area to appear on the surface of the motor shell, and a non-defective edge will appear at the junction of the highlight area and the normal area). Therefore, it is necessary to use the edge features caused by light to correct the possibility that each edge point belongs to a defective edge. Since the grayscale value of the edge of the non-defective area in a certain direction in the local range is gradually weakened due to light, that is, the grayscale value of the edge point caused by light in the neighborhood range is often reduced along a fixed direction (actually a divergent decrease, but in a very small neighborhood range it can be considered as a unified direction). Therefore, the consistency of the grayscale change direction within the neighborhood range of the edge point can be used to correct the possibility that the edge point belongs to a defective edge. The more consistent the grayscale change direction within the neighborhood range of the edge point, the higher the possibility that the edge point is an edge caused by light, and the lower the possibility that it belongs to a defective edge, then the possibility of the edge point belonging to a defective edge needs to be reduced.
[0027] It should be further explained that the gradient direction of the edge point actually describes the direction of change of the grayscale value of the edge point in the shell surface image. Therefore, the consistency of the gradient direction of the pixel points within the eight-neighborhood range of the edge point can be used to represent the consistency of the grayscale change direction.
[0028] Specifically, each group of pixel pairs of each edge point of the shell surface image is obtained: any two pixel points among all the pixel points in the eight-neighborhood range of the i-th edge point of the shell surface image are recorded as a group of pixel pairs of the i-th edge point of the shell surface image, and all groups of pixel pairs of the i-th edge point of the shell surface image are obtained.
[0029] The i-th edge point of the shell surface image and each pixel in the eight-neighborhood of the i-th edge point are recorded as the first pixel point, and the grayscale values of all first pixels are fitted with the least squares pixel method to obtain the first-order derivative of each first pixel in the x-direction and the y-direction of the fitting surface. Based on the existing gradient direction calculation method, the gradient direction of each first pixel is obtained according to the first-order derivative of each first pixel in the x-direction and the y-direction of the fitting surface, that is, the gradient direction of the i-th edge point of the shell surface image and each pixel in the eight-neighborhood of the i-th edge point.
[0030] Get the possibility of correction of each edge point of the shell surface image belonging to the defect edge: ; Where, Represents the correction possibility that the i-th edge point of the shell surface image belongs to the defect edge; Represents the possibility that the i-th edge point of the shell surface image belongs to the defect edge; The gradient direction of the first pixel in the p-th pixel pair representing the i-th edge point of the shell surface image; represents the gradient direction of the second pixel in the p-th pixel pair of the i-th edge point of the shell surface image; C represents the number of pixel pairs of the i-th edge point of the shell surface image; exp() represents an exponential function with a natural constant as the base. In the embodiment of the present invention, the exp(-x) model is used to present an inverse proportional relationship. x represents the input of the model. The implementer can set the inverse proportional function according to the actual implementation situation; || represents the absolute value function; Represents the consistency of the grayscale change direction within the neighborhood of the edge point. The larger the value, the more likely the i-th edge point is to be a pixel at the edge of the illuminated area. The larger the value of , the more likely the i-th edge point in the shell surface image is to belong to a defect edge.
[0031] It should be noted that the present invention adjusts the gradient value of each edge point in the shell surface image using the correction possibility of its defect edge, with the aim of reducing the gradient value of the pixel points in the non-defective area and making the gradient value of the pixel points in the defective area stand out, thereby enabling the canny edge detection to detect the real defective edge.
[0032] Specifically, obtain the corrected gradient value of each edge point in the shell surface image: ; Where, Represents the correction possibility that the i-th edge point of the shell surface image belongs to the defect edge; Represents the corrected gradient value of the i-th edge point of the shell surface image; Represents the gradient value of the i-th edge point of the shell surface image; when the correction possibility that the i-th edge point of the shell surface image belongs to the defect edge is greater, the degree of correction of the gradient value of the i-th edge point is greater.
[0033] According to the corrected gradient value of each edge point of the shell surface image, the canny edge detection algorithm is used to perform edge detection on the shell surface image to obtain a true edge detection image.
[0034] S004. Identify the defect type on the surface of the motor housing according to the real edge detection image.
[0035] Specifically, the real edge detection image of the motor housing is input into the trained defect recognition neural network to identify the defect type of the motor housing. The defect recognition neural network used in this embodiment is Resnet50. The method for obtaining the data set of the defect recognition neural network is as follows: A large number of real edge detection images of the motor housing are collected, and the defect type is manually marked in each real edge detection image of the motor housing. That is, the crack edge in the real edge detection image of the motor housing is marked as 1, and the scratch edge is marked as 0. This marking result is recorded as the label of the real edge detection image of the motor housing; a large number of real edge detection images of the motor housing and their corresponding labels are collected to form a dataset; the dataset is used to train a defect recognition neural network, and the loss function used in the training process is the cross loss function; The specific training process is well-known in neural networks and will not be described in detail in this embodiment.
[0036] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for detecting defects in a motor housing, characterized in that: Includes steps: Collect the shell surface image; perform edge detection on the shell surface image to obtain each edge point of the shell surface image; obtain the possibility that each edge point belongs to a defect edge; Get the possibility of correction for each edge point belonging to the defect edge: ; Represents the possibility of correction that the i-th edge point belongs to the defect edge; Represents the possibility that the i-th edge point belongs to the defect edge; as well as Respectively represent the gradient directions of the first pixel and the second pixel in the pth pixel pair of the ith edge point; C represents the number of pixel pairs of the ith edge point; exp() represents an exponential function with a natural constant as the base; Obtain a corrected gradient value for each edge point, wherein the corrected gradient value is the product of the correction possibility that each edge point belongs to a defective edge and its gradient value; obtain a true edge detection image according to the corrected gradient value of each edge point; and identify the defect type on the shell surface according to the true edge detection image.
2. A motor housing defect detection method according to claim 1, characterized in that: The step of performing edge detection on the shell surface image to obtain edge points of the shell surface image comprises the following steps: A low threshold T is preset, and edge detection is performed on the shell surface image according to the low threshold T in combination with the canny edge detection algorithm to obtain an edge detection image, and each edge of the edge detection image is mapped to the shell surface image to obtain each edge point of the shell surface image.
3. A motor housing defect detection method according to claim 1, characterized in that: The probability of obtaining each edge point belonging to a defect edge is calculated by the following formula: ; In the formula, Represents the possibility that the i-th edge point belongs to the defect edge; Represents the average gradient value of all pixels in the eight-neighborhood range of the i-th edge point; Represents the gradient value of the pixel at the jth row and kth column in the eight-neighborhood range of the i-th edge point; exp() represents an exponential function with a natural constant as the base; || represents the absolute value function.
4. A motor housing defect detection method according to claim 1, characterized in that: The acquisition of the pixel point pairs of the edge points comprises the steps of: A pixel pair consisting of any two pixels in the eight-neighborhood range of the i-th edge point in the shell surface image is recorded as a group of pixel pairs of the i-th edge point, and all groups of pixel pairs of the i-th edge point are obtained.
5. The method for detecting defects in a motor housing according to claim 1, characterized in that: The acquisition of the gradient direction comprises the steps of: The i-th edge point in the shell surface image and each pixel point in the eight neighborhood of the i-th edge point are recorded as the first pixel point, and the grayscale values of all first pixel points are fitted with the least squares pixel point to obtain the first-order derivative of each first pixel point in the x-direction and the y-direction of the fitting surface. Based on the existing gradient direction calculation method, the gradient direction of each first pixel point is obtained according to the first-order derivative of each first pixel point in the x-direction and the y-direction of the fitting surface.
6. A motor housing defect detection method according to claim 1, characterized in that: The calculation formula for obtaining the corrected gradient value of each edge point is: ; In the formula, Represents the possibility of correction that the i-th edge point belongs to the defect edge; Represents the corrected gradient value of the i-th edge point; Represents the gradient value of the i-th edge point.
7. A motor housing defect detection method according to claim 1, characterized in that: The method of obtaining a true edge detection image according to the corrected gradient value of each edge point comprises the following steps: According to the corrected gradient value of each edge point of the shell surface image, the canny edge detection algorithm is used to perform edge detection on the shell surface image to obtain a true edge detection image.
8. A method for detecting defects in a motor housing according to claim 1, characterized in that: The method of identifying the defect type on the shell surface according to the real edge detection image comprises the following steps: The real edge detection image of the motor housing is input into the trained defect recognition neural network to identify the defect type of the motor housing.
Citation Information
Patent Citations
Image contour optimization method based on visual detection and terminal
CN114972281A
Plastic mold injection molding surface defect detection method
CN116912261A
Watch shell quality detection method based on image data
CN117218122A
Intelligent detection method for production quality of photovoltaic connecting line
CN117351021A