A method for detecting defects in motor housing
By performing edge detection and correcting gradient value calculation on the surface image of the motor housing, the problem that the Canny edge detection algorithm is affected by the edge of the non-defective region when detecting the edge of the defective region, achieving more accurate defect detection.
Patent Information
- Application Number
- CN202411976492.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2044-12-31
AI Technical Summary
When detecting the edges of the motor housing defect area, the Canny edge detection algorithm is susceptible to the edges of non-defect areas such as motor housing texture and lighting, resulting in inaccurate detection.
By performing edge detection on the shell surface image, the correction gradient value of each edge point is obtained. The correction gradient value is the product of the correction possibility of the edge point belonging to the defect edge and its gradient value, and then a real edge detection image is obtained to identify the defect type of the shell surface.
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 CN119399189B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and more specifically, to a method for detecting defects in a motor housing. Background Art
[0002] As an indispensable device in modern industry and life, the motor housing is an important part of the motor. It not only protects the internal mechanical and electronic components, but also affects the heat dissipation performance and overall structural strength of the motor. Therefore, it is extremely important to detect defects in the motor housing. Traditional manual inspection methods may be inefficient and affected by subjective factors, while automated inspection based on image processing can quickly and accurately detect surface defects of the motor housing, improve the efficiency of the production line and the consistency of product quality. Through real-time image processing technology, each motor housing can be inspected and monitored in real time, problems in production can be discovered in time, and corresponding adjustment measures can be taken to ensure product quality. In this process, it is often necessary to perform edge detection on the motor housing to detect defective edges, so as to facilitate subsequent defect detection.
[0003] The patent application document with the publication number CN114972281A currently discloses an image contour optimization method and terminal based on visual detection, which 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 the target binary contour; combines the target binary contour and the Canny contour, searches for and fills the closed contour, and obtains the 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 such as the texture and illumination of the motor housing itself cause the Canny edge detection to be unable to accurately detect the edges of the defective areas of the motor housing, thereby affecting the accuracy of the defect detection of the motor housing, the present invention proposes a motor housing defect detection method, the method comprising the following steps:
[0006] 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;
[0007] Get the possibility of correction of each edge point belonging to the defect edge:
[0008] ; 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;
[0009] 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.
[0010] Preferably, the performing edge detection on the shell surface image to obtain edge points of the shell surface image comprises the steps of:
[0011] 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.
[0012] Preferably, the probability of obtaining each edge point belonging to a defect edge is calculated by the following formula:
[0013] ;
[0014] 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.
[0015] Preferably, the acquisition of the pixel pairs of the edge points comprises the steps of:
[0016] 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.
[0017] Preferably, the acquisition of the gradient direction comprises the steps of:
[0018] 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.
[0019] Preferably, the correction gradient value of each edge point is obtained by calculating the formula:
[0020] ;
[0021] 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.
[0022] Preferably, the step of obtaining a true edge detection image according to the corrected gradient value of each edge point comprises the following steps:
[0023] 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.
[0024] Preferably, the step of identifying the defect type on the shell surface according to the real edge detection image comprises the following steps:
[0025] 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.
[0026] The present invention has the following beneficial effects: the present invention corrects the gradient value of each edge point according to the correction possibility that each edge point of the shell surface image 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 corrected gradient value, the real edge detection image is obtained to identify the defect type of the shell surface, so that the real defective edge can be detected, and the accuracy of shell surface defect detection is improved. Furthermore, the correction possibility that each edge point of the shell surface image belongs to the defective edge is obtained by correcting the possibility that the edge point belongs to the defective edge according to the consistency of the grayscale change direction within the neighborhood range of the edge point, thereby avoiding the influence of the illuminated edge and the texture of the shell itself. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:
[0028] Figure 1 It 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
[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0030] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0031] See also Figure 1 , which shows a flow chart of a method for detecting defects in a motor housing provided by an embodiment of the present invention, the method comprising the following steps:
[0032] S001. Collect the surface image of the motor housing and perform preprocessing.
[0033] 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. In order to facilitate subsequent analysis, the RGB image of the outer shell surface is gray-scaled and denoised using a Gaussian filter, which is then recorded as the outer shell surface image.
[0034] 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.
[0035] It should be noted that the purpose of the present invention is to distinguish the edges of defective areas and 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 surface image of the casing to obtain the edge points of the surface image of the casing. In order to include the edge information of all defective areas, the present invention needs to select a smaller threshold for edge detection.
[0036] Specifically, a low threshold T is preset, and edge detection is performed on the shell surface image according to the low threshold in combination with the Canny edge detection algorithm to obtain an edge detection image, and each edge of the edge detection image is corresponded 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.
[0037] S003. Obtain the possibility that each edge point of the shell surface image belongs to the defect edge, and correct the possibility that each edge point of the shell surface image belongs to the defect edge according to 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 the 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.
[0038] It should be noted that in the surface image of the motor housing, its own texture and the edges caused by illumination will show high gradient values, which are similar to the high gradient values of defective edges. If they are not distinguished, the defective edges cannot be detected well using Canny edge detection, thus affecting the final defect detection. Therefore, the present invention will reflect the possibility of each edge point being a defective edge through the edge features of the non-defective area (own texture, illuminated edge), that is, the more an edge point shows the edge features of the non-defective area, the lower the possibility of it being a defective edge, thereby correcting the gradient value of each edge point through the possibility of each edge point being a defective edge, so that the real defective edge is displayed in the final Canny edge detection result.
[0039] 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 grayscale value change of the edge point is, 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.
[0040] Specifically, the possibility of each edge point of the shell surface image belonging to the defect edge is obtained:
[0041] ;
[0042] In the formula, 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 the jth row and the kth column 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 ith edge point, indicating that the ith edge point is more likely to be a pixel at the texture contour in the shell surface image; Represents the uniformity of the gradient values of all pixels within the neighborhood of the ith edge point. The smaller the value, the more likely the ith edge point is to be a pixel at the texture contour. The larger the value, the more likely the ith 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.
[0043] It should be noted that since there may be light in the shell surface image, the 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 to say, 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 that the edge point belongs to a defective edge needs to be reduced.
[0044] It should be further explained that the gradient direction of the edge point essentially 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 characterize the consistency of the grayscale change direction.
[0045] 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.
[0046] The i-th edge point of the shell surface image and each pixel point in the eight neighborhoods of the i-th edge point are recorded as the first pixel point, and the grayscale values of all the 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, that is, the i-th edge point of the shell surface image and the gradient direction of each pixel point in the eight neighborhoods of the i-th edge point.
[0047] Get the possibility of correction that each edge point of the shell surface image belongs to the defect edge:
[0048] ;
[0049] In the formula, Represents the possibility of correction 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 group of pixel pairs representing the i-th edge point of the shell surface image; represents the gradient direction of the second pixel in the pth group of pixel pairs of the i-th edge point of the shell surface image; C represents the number of groups 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 its value is, 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.
[0050] It should be noted that the present invention adjusts the gradient value of each edge point in the shell surface image using the possibility of correction of its defective 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 prominent, thereby enabling the canny edge detection to detect the real defective edge.
[0051] Specifically, obtain the corrected gradient value of each edge point in the shell surface image:
[0052] ;
[0053] In the formula, Represents the possibility of correction 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 ith edge point of the shell surface image; when the correction possibility that the ith edge point of the shell surface image belongs to the defect edge is greater, the degree of correction of the gradient value of the ith edge point is greater.
[0054] 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.
[0055] S004. Identify the defect type on the surface of the motor housing according to the real edge detection image.
[0056] 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:
[0057] A large number of real edge detection images of motor housings are collected, and the defect type is artificially marked in each real edge detection image of the motor housing, that is, the crack edge is marked as 1 and the scratch edge is marked as 0 in the real edge detection image of the motor housing, and this marking result is recorded as the label of each 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 data set; the data set is used to train a defect recognition neural network, and the loss function used in the training process is a cross loss function;
[0058] The specific training process is well-known in neural networks, and this embodiment will not go into details about the specific training process.
[0059] 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 protection scope 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 the defect edge, and the calculation formula is: ; 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 the 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; 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; as well as They represent the gradient directions of the first pixel and the second pixel in the pth pixel pair of the i-th edge point respectively; C represents the number of pixel pairs of the i-th edge point; Obtaining a correction gradient value for each edge point, wherein the correction gradient value is the product of the correction possibility of each edge point belonging to a defect edge and its gradient value; obtaining a true edge detection image according to the correction gradient value of each edge point; and identifying the defect type on the shell surface according to the true edge detection image; 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.
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 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.
4. 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.
5. The method for detecting defects in a motor housing 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.
6. A motor housing defect detection method 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