A surface defect intelligent detection system for die castings based on machine vision
Patent Information
- Application Number
- CN202610753272.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-28
- Publication Date
- 2026-08-18
AI Technical Summary
[0004]为此,本发明提供一种基于机器视觉的压铸件用表面缺陷智能检测系统,用以克服现有技术中因未考虑表面纹理差异对检测策略的影响、未考虑缺陷边缘方向分散程度对缺陷与铸造纹理的区分的影响,以及未考虑缺陷的位置和形态对危害性量化评估的影响,从而导致压铸件的表面缺陷检测效率差的问题
1.本发明通过构建从图像采集、纹理自适应分区、边缘方向一致性判定、灰度对比二次确认到形状复杂度预警的全流程智能检测体系,实现对压铸件表面缺陷的精细化分级检测;利用子区域的灰度梯度方差自动划分高风险与低风险区域,并分别采用基于连通域面积的快速判定和基于方向分散指数与灰度对比表征值的多级精细判定,解决统一检测策略造成的计算冗余与精度不足;同时,通过边缘方向角标准差量化缺陷边缘的规则程度,结合背景灰度信噪比二次甄别,提高缺陷与铸造纹理的区分能力;此外,基于缺陷与预设关键区域的重叠比例及轮廓几何复杂度评估缺陷危害性,仅对具有较高应力集中风险的缺陷触发预警,避免过度报警,从而提高了压铸件的表面缺陷的检测效率。
Smart Images

Figure CN122597350A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and more specifically, to an intelligent surface defect detection system for die-cast parts based on machine vision. Background Technology
[0002] Die-cast parts, such as automotive motor end caps and gearbox housings, often exhibit surface defects such as microcracks, porosity, and cold shuts after die casting. These defects directly affect the product's sealing performance, structural strength, and assembly precision. Especially minute defects located in critical areas such as sealing surfaces and bearing housings can lead to leaks or fatigue fractures, causing serious quality incidents. Therefore, efficient and accurate detection of surface defects in die-cast parts is a crucial step in ensuring product quality.
[0003] Currently, machine vision-based methods for detecting surface defects in die-cast parts are mainly divided into two categories: traditional image processing (such as grayscale thresholding and morphological filtering) and deep learning-based end-to-end recognition. However, existing methods have the following problems: First, they are difficult to distinguish between real defects and complex textures such as reinforcing rib edges and casting flow lines, which easily leads to false detections or missed detections; second, they lack strategies for adaptive partitioning and differentiated detection based on local texture complexity, resulting in computational redundancy in simple texture areas and insufficient accuracy in complex texture areas; third, they cannot assess the harm of defects to subsequent processes, nor can they locate whether defects are located in critical areas such as sealing surfaces, causing a large number of irrelevant defects to trigger alarms. Summary of the Invention
[0004] To address this, the present invention provides a machine vision-based intelligent surface defect detection system for die castings, which overcomes the problems of poor surface defect detection efficiency in the prior art due to the failure to consider the impact of surface texture differences on detection strategies, the failure to consider the impact of the dispersion of defect edge direction on the distinction between defects and casting textures, and the failure to consider the impact of defect location and shape on the quantitative assessment of hazard.
[0005] To achieve the above objectives, the present invention provides a machine vision-based intelligent surface defect detection system for die-cast parts, comprising: Image acquisition module, which is used to acquire surface images of die-cast parts; The texture determination module, which is connected to the image acquisition module, is used to divide the surface image of the die casting into several sub-regions and determine the texture complexity representation value of each sub-region based on the gray-level gradient distribution of the pixels in each sub-region. A classification module, which is connected to the texture determination module, is used to classify the sub-region into a high-risk region or a low-risk region based on the texture complexity representation value of the sub-region. A dispersion determination module, which is connected to the level division module, is used to determine the directional dispersion index of the high-risk area based on the gradient direction angle of all edge pixels in the edge connected region within the high-risk area; A grayscale determination module, which is connected to the dispersion determination module, is used to determine the grayscale contrast characterization value of the edge connected region based on the grayscale distribution of the edge connected region and the background ring region; The defect detection module is connected to the level classification module, the dispersion determination module, and the grayscale determination module, respectively. When the sub-region is determined to be a low-risk region, it is used to determine whether there is a defect in the low-risk region based on the defect area ratio of the low-risk region. When the sub-region is determined to be a high-risk region, it is used to determine whether there is a defect in the high-risk region based on the directional dispersion index of the high-risk region and the grayscale contrast characterization value. The early warning decision module, which is connected to the defect detection module, is used to determine the type of early warning signal based on the shape complexity of the defect area and the percentage of overlap between the defect area and the preset key area. The types of early warning signals include a first early warning signal and a second early warning signal.
[0006] Preferably, the classification module determines the sub-region as a low-risk region in response to the sub-region's texture complexity characterization value being less than a preset texture complexity characterization value. The classification module determines a sub-region as a high-risk region in response to the sub-region's texture complexity value being greater than or equal to the preset texture complexity value.
[0007] Preferably, the texture determination module includes: The sub-region division unit is used to uniformly divide the surface image of the die casting into several rectangular sub-regions according to a preset grid size; A gradient magnitude calculation unit is used to determine the gradient magnitude of each pixel based on its horizontal and vertical gradients. The sub-region variance calculation unit is used to calculate the variance of the gradient magnitude based on the gradient magnitude of all pixels in each sub-region, and use it as the texture complexity representation value of the sub-region.
[0008] Preferably, when the sub-region is determined to be a low-risk region, the defect detection module determines that there are no defects in the low-risk region in response to the defect area ratio of the low-risk region being less than a preset area ratio. The defect detection module determines that there is a defect in the low-risk area when the defect area ratio of the low-risk area is greater than or equal to the preset area ratio. The defect area ratio is the ratio of the total area of all candidate connected regions in the low-risk area to the area of the low-risk area. The candidate connected region is a connected region in the low-risk area composed of pixels with a gray value less than a first preset gray value or greater than a second preset gray value. The first preset gray value is less than the second preset gray value.
[0009] Preferably, when the sub-region is determined to be a high-risk region, the defect detection module determines that there is no defect in the high-risk region in response to the directional dispersion index of the high-risk region being less than a first preset directional dispersion index. The defect detection module responds to the fact that the directional dispersion index of the high-risk area is greater than or equal to the first preset directional dispersion index and less than the second preset directional dispersion index, and then makes a secondary determination on whether there is a defect in the high-risk area based on the grayscale contrast characterization value of the high-risk area. The defect detection module determines that there is a defect in the high-risk area when the directional dispersion index of the high-risk area is greater than or equal to the second preset directional dispersion index; wherein the first preset directional dispersion index is less than the second preset directional dispersion index.
[0010] Preferably, the dispersion determination module includes: The gradient direction angle calculation unit is used to determine the gradient direction angle of the edge pixel based on the horizontal and vertical gradients of each edge pixel in several edge connected regions; wherein, the edge connected region is a connected region composed of pixels with gray values of preset edge identifier values in the edge binary image obtained based on the high-risk region; The directional dispersion index calculation unit is used to determine the directional dispersion index of the edge connected region based on the standard deviation of the gradient direction angles of all edge pixels within the edge connected region.
[0011] Preferably, the defect detection module determines that there is no defect in the high-risk area when the grayscale contrast value of the high-risk area is less than a preset grayscale contrast threshold; the defect detection module determines that there is a defect in the high-risk area when the grayscale contrast value is greater than or equal to the preset grayscale contrast threshold.
[0012] Preferably, the grayscale determination module includes: The background ring extraction unit is used to extract the minimum bounding rectangle of the edge connected region and extend it to the outside of the minimum bounding rectangle by a preset number of pixels to obtain the background ring region. The gray-scale mean calculation unit is used to calculate the gray-scale mean of all pixels in the edge-connected region, denoted as the edge-connected region gray-scale mean; and to calculate the gray-scale mean of all pixels in the background ring region, denoted as the background ring region gray-scale mean. The background standard deviation calculation unit is used to calculate the gray standard deviation of all pixels in the background ring region, denoted as the gray standard deviation of the background ring region. The characterization value calculation unit is used to determine the gray-level contrast characterization value based on the mean gray level of the edge connected region, the mean gray level of the background ring region, and the standard deviation of the gray level of the background ring region.
[0013] Preferably, the early warning decision module determines and issues a first early warning signal in response to the shape complexity of the defect area being greater than or equal to a preset shape complexity. The early warning decision module determines to issue a second early warning signal when the shape complexity of the defect area is less than the preset shape complexity and the overlap area ratio between the defect area and the preset key area is greater than or equal to the preset overlap area ratio. The early warning decision module determines not to issue an early warning signal if the shape complexity of the defective area is less than the preset shape complexity and the overlapping area ratio is less than the preset overlapping area ratio.
[0014] Preferably, the shape complexity of the defect region is determined based on the goodness of fit of the defect contour and the number of inflection points; the overlapping area ratio is the ratio of the overlapping area of the defect region and the preset key region to the area of the defect region; the defect region is a sub-region in which a defect is determined to exist in a low-risk region or a high-risk region.
[0015] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. This invention constructs a fully intelligent detection system encompassing image acquisition, adaptive texture partitioning, edge direction consistency determination, secondary grayscale comparison confirmation, and shape complexity warning, enabling refined hierarchical detection of surface defects in die-cast parts. It automatically divides high-risk and low-risk areas using the grayscale gradient variance of sub-regions, employing rapid determination based on connected region area and multi-level refined determination based on directional dispersion index and grayscale comparison value, respectively, to address computational redundancy and insufficient accuracy caused by a unified detection strategy. Simultaneously, it quantifies the regularity of defect edges using the standard deviation of edge direction angles, combined with secondary discrimination using background grayscale signal-to-noise ratio, improving the ability to distinguish defects from casting textures. Furthermore, it assesses the hazard of defects based on the overlap ratio and contour geometric complexity of predefined key areas, triggering warnings only for defects with a high risk of stress concentration, avoiding excessive alarms, thereby improving the detection efficiency of surface defects in die-cast parts.
[0016] 2. This invention sets a classification module that responds to the comparison result of the texture complexity representation value of a sub-region with a preset threshold, and classifies sub-regions with simple textures as low-risk regions and sub-regions with complex textures as high-risk regions. This achieves objective risk level classification based on local image statistics, thereby avoiding the strategy mismatch problem caused by manually setting regions or uniform processing, and providing accurate input for subsequent differential detection.
[0017] 3. This invention achieves rapid defect screening in low-risk areas, i.e., areas with simple textures, by using defect area ratio determination in low-risk areas, i.e., calculating the ratio of the total area of all candidate connected regions to the area of the sub-regions and comparing it with a preset area ratio threshold. This improves the detection efficiency of the intelligent surface defect detection system while ensuring effective defect detection.
[0018] 4. This invention sets a first preset directional dispersion index and a second preset directional dispersion index in high-risk areas. Areas with a directional dispersion index less than the first threshold are judged as defect-free, while areas with a directional dispersion index greater than or equal to the second threshold are judged as having defects. Areas between the two are triggered to trigger a secondary judgment of grayscale contrast characterization value. This achieves fine-grained discrimination of edge directional consistency features, thereby effectively distinguishing regular structures such as reinforcing ribs and casting streamlines from irregular defects such as cracks and pores, and reducing the false detection rate in high-risk areas.
[0019] 5. This invention, through a warning decision module, responds to the comparison results of the shape complexity of the defect area with the preset shape complexity, and the comparison results of the overlap area ratio between the defect area and the preset key area with the preset overlap area ratio. The warning decision is divided into three levels: when the shape complexity is high, a first warning signal (high-level warning) is issued; when the shape complexity is low but the overlap area ratio is large, a second warning signal (low-level warning) is issued; and when the shape complexity is low and the overlap area ratio is small, no warning is issued. This achieves refined hierarchical management of the hazard of defects. Attached Figure Description
[0020] The present application will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0021] Figure 1 This is a schematic diagram of the module connection of the intelligent surface defect detection system for die castings based on machine vision, according to an embodiment of the present invention. Figure 2 This is a flowchart illustrating how a sub-region is divided into a high-risk region or a low-risk region based on its texture complexity characterization value, according to an embodiment of the present invention. Figure 3 This is a flowchart illustrating how to determine whether a defect exists in a low-risk area based on the defect area ratio of the low-risk area, according to an embodiment of the present invention. Figure 4This is a flowchart illustrating how an embodiment of the present invention determines whether a high-risk area has defects based on the directional dispersion index of the high-risk area. Detailed Implementation
[0022] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0023] Please see Figure 1 , Figure 2 , Figure 3 as well as Figure 4 The diagrams shown are: a schematic diagram of the module connection of the intelligent surface defect detection system for die castings based on machine vision according to an embodiment of the present invention; a flowchart of dividing the sub-region into high-risk or low-risk regions according to the texture complexity characterization value of the sub-region according to an embodiment of the present invention; a flowchart of determining whether there is a defect in the low-risk region according to the defect area ratio of the low-risk region according to an embodiment of the present invention; and a flowchart of determining whether there is a defect in the high-risk region according to the directional dispersion index of the high-risk region according to an embodiment of the present invention.
[0024] This invention relates to a machine vision-based intelligent surface defect detection system for die-cast parts, comprising: Image acquisition module, which is used to acquire surface images of die-cast parts; The texture determination module, which is connected to the image acquisition module, is used to divide the surface image of the die casting into several sub-regions and determine the texture complexity representation value of each sub-region based on the gray-level gradient distribution of the pixels in each sub-region. A classification module, which is connected to the texture determination module, is used to classify the sub-region into a high-risk region or a low-risk region based on the texture complexity representation value of the sub-region. A dispersion determination module, which is connected to the level division module, is used to determine the directional dispersion index of the high-risk area based on the gradient direction angle of all edge pixels in the edge connected region within the high-risk area; A grayscale determination module, which is connected to the dispersion determination module, is used to determine the grayscale contrast characterization value of the edge connected region based on the grayscale distribution of the edge connected region and the background ring region; The defect detection module is connected to the level classification module, the dispersion determination module, and the grayscale determination module, respectively. When the sub-region is determined to be a low-risk region, it is used to determine whether there is a defect in the low-risk region based on the defect area ratio of the low-risk region. When the sub-region is determined to be a high-risk region, it is used to determine whether there is a defect in the high-risk region based on the directional dispersion index of the high-risk region and the grayscale contrast characterization value. The early warning decision module, which is connected to the defect detection module, is used to determine the type of early warning signal based on the shape complexity of the defect area and the percentage of overlap between the defect area and the preset key area. The types of early warning signals include a first early warning signal and a second early warning signal.
[0025] Specifically, there are no restrictions on the specific structure of the texture determination module, the level classification module, the dispersion determination module, the grayscale determination module, the defect detection module, and the early warning decision module. They themselves and each unit therein can be composed of logical components, including field-programmable components, computers, or microprocessors in computers.
[0026] Those skilled in the art will understand that the image acquisition module in this embodiment can be a high-resolution industrial camera (such as a 5-megapixel CMOS camera with an image resolution of 2448×2048 pixels), coupled with a ring LED light source or a coaxial light source, to trigger an image capture when the die-cast part is conveyed to the inspection position, thereby obtaining a clear surface grayscale image. To suppress specular reflection on the aluminum alloy surface, the ring LED light source can be configured with a polarizer, and the coaxial light source can provide low-angle illumination to enhance the grayscale contrast between the defect and the background. Those skilled in the art will understand that the camera resolution, frame rate, and specific type of light source can be adjusted according to the inspection accuracy and production line speed. For example, a 20-megapixel camera can be used for detecting finer defects, while a camera with a higher frame rate can be used for high-speed production lines.
[0027] Specifically, the classification module determines the sub-region as a low-risk region in response to the sub-region's texture complexity characterization value being less than a preset texture complexity characterization value of 120. The classification module determines a sub-region as a high-risk region in response to the sub-region's texture complexity value being greater than or equal to the preset texture complexity value.
[0028] Specifically, a higher texture complexity value indicates more dramatic and diverse grayscale changes within a sub-region, corresponding to geometrically abrupt areas such as the roots of reinforcing ribs, rounded transition zones, and thickness junctions on the die-cast surface. These areas are prone to stress concentration and disordered molten metal filling during die-casting, making them high-risk areas for defects such as cracks, porosity, and cold shuts. Conversely, sub-regions with lower texture complexity values correspond to simple texture areas such as sealing surfaces and smooth appearance surfaces, with a lower defect incidence. This allows for the effective separation of high-risk areas with complex textures from low-risk areas with simple textures, providing a reliable spatial basis for subsequent differentiated detection strategies—that is, using fine detection for high-risk areas and rapid detection for low-risk areas.
[0029] In this embodiment, the preset texture complexity characterization value is set to 120. This value was obtained through statistical analysis of surface images of 200 qualified die-casting samples. The statistical results show that over 95% of smooth surface sub-regions have a texture complexity characterization value less than 120, while over 90% of sub-regions containing complex structures such as reinforcing ribs and parting lines have a texture complexity characterization value greater than or equal to 120. Therefore, the preset texture complexity characterization value is set to 120.
[0030] Specifically, the texture determination module includes: The sub-region division unit is used to uniformly divide the surface image of the die-cast part into several rectangular sub-regions according to a preset grid size. The preset grid size can be set according to the image resolution and detection accuracy requirements. In this embodiment, the image size is 2448×2048 pixels, and the preset grid size is 32×32 pixels, resulting in 76 sub-regions in the horizontal direction and 64 sub-regions in the vertical direction, for a total of 4864 sub-regions. The grid size can also be adaptively adjusted: for scenarios requiring higher precision, 16×16 pixels can be used; for scenarios prioritizing real-time performance, 64×64 pixels can be used. The principle for determining the grid size is: each sub-region contains enough pixels to ensure the stability of gradient statistics (usually no less than 200 pixels). The gradient magnitude calculation unit calculates the horizontal gradient G of each pixel using the Sobel operator. x and vertical gradient G y Horizontal gradient: G x =(Z3+2×Z5+Z8)-(Z1+2×Z4+Z6); Vertical gradient: G y =(Z6+2×Z7+Z8)-(Z1+2×Z2+Z3); where Z1-Z9 are the gray values of each pixel in the 3×3 neighborhood; then calculate the gradient magnitude: ; The sub-region variance calculation unit is used to calculate the variance of the gradient magnitude based on the gradient magnitude of all pixels in each sub-region, and use it as the texture complexity representation value of the sub-region.
[0031] Specifically, when the sub-region is determined to be a low-risk region, the defect detection module determines that there are no defects in the low-risk region when the defect area ratio of the low-risk region is less than a preset area ratio of 0.1%. The defect detection module determines that a defect exists in the low-risk area when the defect area ratio of the low-risk area is greater than or equal to the preset area ratio.
[0032] Specifically, the low-risk area is a smooth surface area selected through the complex texture characterization value. Under normal circumstances, the gray scale distribution is uniform, with only a very small number of harmless spots caused by fluctuations in the production process. There are no large areas of gray scale abnormalities caused by normal structural edges such as reinforcing ribs and parting lines. Using the defect area ratio as the judgment index, it can not only effectively detect independent defects such as pores and sand holes that exceed the size limit, but also accurately identify the cumulative effect of multiple small defects. When there are a large number of scattered small defects in the low-risk area, even if the size of a single defect does not exceed the allowable limit, if the total area ratio exceeds the threshold, it will lead to the surface appearance quality of the die casting not meeting the standard, or affect the implementation of subsequent processes such as spraying and assembly.
[0033] Specifically, the preset area percentage is set to 0.1%. Fifty known acceptable (no surface defects affecting function) and 50 known unacceptable (excessive defects) low-risk sub-images are selected, and their defect area percentages are calculated and ROC curves are plotted. The optimal threshold is determined by minimizing the sum of the false negative and false positive rates. Experimental data shows that when the preset area percentage is greater than or equal to 0.1%, more than 95% of unacceptable samples are correctly detected, while the false positive rate for acceptable samples is less than 5%. Therefore, this embodiment uses a preset area percentage of 0.1%. It is understood that the value of the preset area percentage can be adjusted by those skilled in the art based on the sensitivity requirements for detecting surface defects in die-cast parts; the higher the required detection sensitivity, the smaller the value of the preset area percentage.
[0034] Specifically, grayscale thresholding is performed on the low-risk area image to extract all pixels with grayscale values less than a first preset grayscale value or greater than a second preset grayscale value. Connected regions, called candidate connected regions, are formed using the 8-adjacency rule (i.e., adjacent pixels connected horizontally, vertically, or diagonally are considered connected). The first preset grayscale value is less than the second preset grayscale value. The first and second preset grayscale values are determined by statistically analyzing the grayscale histogram of the low-risk area image, taking the grayscale value at the trough to the left of the main peak of the background as the first preset grayscale value, and the trough to the right as the second preset grayscale value. For the surface of aluminum alloy die-cast parts, the background grayscale is typically between 100 and 150, so the first preset grayscale value is 80, and the second preset grayscale value is 170. The first preset gray value is used to extract defects with gray values lower than the background (such as pores and cracks under dark lighting), and the second preset gray value is used to extract defects with gray values higher than the background (such as cracks under bright lighting). Let the total area of all candidate connected regions in the low-risk area be S1 and the area of the low-risk area be S0, then the defect area ratio P = S1 / S0.
[0035] Specifically, when the sub-region is identified as a high-risk region, the defect detection module determines that there is no defect in the high-risk region in response to the directional dispersion index of the high-risk region being less than a first preset directional dispersion index of 0.2. The defect detection module responds to the fact that the directional dispersion index of the high-risk area is greater than or equal to the first preset directional dispersion index and less than the second preset directional dispersion index of 0.6, and then makes a second determination on whether there is a defect in the high-risk area based on the grayscale contrast characterization value of the high-risk area. The defect detection module determines that there is a defect in the high-risk area when the directional dispersion index of the high-risk area is greater than or equal to the second preset directional dispersion index; wherein the first preset directional dispersion index is less than the second preset directional dispersion index.
[0036] In practice, the first preset directional dispersion index is generally selected within the range of [0.1, 0.3], and the second preset directional dispersion index is generally selected within the range of [0.5, 0.7]. Preferably, the first preset directional dispersion index is 0.2, and the second preset directional dispersion index is 0.6. These preferred values are based on pre-collected samples of 200 high-risk area edge connectivity regions, including 50 normal structures (reinforcing rib edges, casting streamlines), 50 cracks, 50 pores, and 50 pseudo-defects (water stains, scratches, etc.). The directional dispersion index of each sample is calculated using the aforementioned method. Statistical results show that: the directional dispersion index of samples with normal structures ∈ [0.01, 0.28], with a mean of 0.12; the directional dispersion index of samples with cracks ∈ [0.55, 0.95], with a mean of 0.78; the directional dispersion index of samples with pores ∈ [0.32, 0.68], with a mean of 0.51; and the directional dispersion index of samples with pseudo-defects ∈ [0.15, 0.55]. To ensure low false positives for normal structures and high crack detection while ensuring all porosity enters the secondary judgment interval, with the goal of minimizing the sum of false positive and false negative rates, a first preset directional dispersion index of 0.2 and a second preset directional dispersion index of 0.6 were determined through grid search optimization. However, these values are not limited to these values, and those skilled in the art can adjust these values according to different die-casting part types and process conditions.
[0037] Specifically, the three-level judgment strategy avoids the "one-size-fits-all" problem caused by a single threshold. It ensures efficient exclusion of regular structures and direct detection of typical cracks, while retaining the ability to make secondary fine judgments for ambiguous areas, thus achieving a balance between accuracy and efficiency.
[0038] Specifically, the process of obtaining the directional dispersion index includes: Gaussian filtering was applied to images of high-risk areas with a filter size of 5×5 and a standard deviation of 1.0 to suppress Gaussian noise interference generated during image acquisition. Edges are extracted using the Canny edge detection algorithm. The Canny algorithm includes the following steps: calculating the gradient magnitude and direction of each pixel in the image using a 3×3 Sobel operator; performing non-maximum suppression on the gradient magnitude, retaining local maxima as candidate edge points; and using a dual thresholding method for edge connection, where the low threshold is 50 and the high threshold is 100, retaining only weak edges connected to strong edges, ultimately obtaining a binary edge image. In this binary edge image, the grayscale value of edge pixels is 255, i.e., the preset edge identifier value is 255, and the grayscale value of non-edge pixels is 0. The binary edge image is labeled with the 8-adjacency rule, and each independent region composed of edge pixels that are connected to each other in the horizontal, vertical or diagonal direction is recorded as an edge connected region. For each edge pixel within each edge-connected region, the gradient direction angle calculation unit uses the standard 3×3 Sobel operator to calculate its gradient direction angle. The specific calculation process is as follows: Let the coordinates of an edge pixel be (x, y), and its grayscale value be f(x, y). Let the grayscale values of pixels within a 3×3 neighborhood centered on this point be f(x-1, y-1), f(x, y-1), f(x+1, y-1), f(x-1, y), f(x, y), f(x+1, y), f(x-1, y+1), f(x, y+1), and f(x+1, y+1). Then the horizontal gradient G at this point... x and vertical gradient G y They are respectively: G x =f(x+1,y-1)+2f(x+1,y)+f(x+1,y+1)-[f(x-1,y-1)+2f(x-1,y)+f(x-1,y+1)]; G y =f(x-1,y+1)+2f(x,y+1)+f(x+1,y+1)-[f(x-1,y-1)+2f(x,y-1)+f(x+1,y-1)]; The above formula is the mathematical expression of the standard Sobel operator. In actual calculation, it can be quickly implemented by convolving the image with a 3×3 convolution kernel. Then, the gradient direction angle θ of the pixel is calculated as follows: θ=arctan2(G y G x ); Here, arctan2() is the arctangent function in the four quadrants. The calculated result θ ranges from (-π, π], and the unit is radians. This angle represents the direction of the fastest gray-scale change at the pixel point, that is, the normal direction of the edge.
[0039] For each edge-connected region, the directional dispersion index calculation unit first obtains the set of gradient orientation angles {θ1, θ2, ..., θ3} of all edge pixels in that region. N}, where N is the total number of edge pixels within the edge-connected region.
[0040] Calculate the circular standard deviation σ of these angle values. θ Because angles are periodic (-π is equivalent to π), directly using the linear standard deviation will result in serious calculation errors. Therefore, the vector synthesis method is used to calculate the circular standard deviation. First, set each angle θ i Convert to vector coordinates on the unit circle (cosθ) i sinθ i ); Next, calculate the length of the resultant vector of all vectors: ; Finally, calculate the circular standard deviation using the following formula: ; When all angles are exactly the same, the resultant vector length R = 1, σ θ =0; the more dispersed the angular distribution, the smaller the R value, σ θ The larger the value, the more pronounced the gradient direction angle of edge pixels will be in actual die-cast part surface images, which will not be completely uniformly distributed. θ The actual maximum value usually does not exceed π.
[0041] Finally, calculate the directional dispersion index (DDI) using the following formula: DDI = σ θ / π; As can be seen from the formula, the range of the directional dispersion index is [0, 1]. Its physical meaning is: DDI=0 indicates that the gradient direction angles of all edge pixels are completely consistent, corresponding to an ideal straight edge (such as a reinforcing rib edge); DDI=1 indicates that the edge direction is extremely dispersed, corresponding to a completely irregular defect edge.
[0042] Specifically, the defect detection module determines that there is no defect in the high-risk area if the grayscale contrast value of the high-risk area is less than the preset grayscale contrast threshold of 2.0; and determines that there is a defect in the high-risk area if the grayscale contrast value is greater than or equal to the preset grayscale contrast threshold.
[0043] Specifically, the preset grayscale contrast threshold was set to 2.0. 200 samples of high-risk edge connectivity areas were collected from the die-casting production line, covering different lighting conditions and surface states. Through manual and destructive testing, 100 samples were confirmed to have defects (including porosity and cracks), and 100 were identified as pseudo-defects (including reinforcing rib edges, casting flow lines, water stains, oil stains, and minor scratches). The grayscale contrast characterization value of each sample was calculated. Statistically, the grayscale contrast characterization values of the defective samples were concentrated between 1.8 and 10.0, with a lower limit of the 95th percentile of approximately 1.9. The grayscale contrast characterization values of the pseudo-defective samples were concentrated between 0.2 and 2.2, with an upper limit of the 95th percentile of approximately 2.1. There was some overlap between the two types of samples in the 1.8-2.2 range. With the goal of minimizing the sum of the false negative rate (misclassifying defective samples as defect-free) and the false positive rate (misclassifying samples with spurious defects as defects), candidate thresholds ranging from 1.5 to 2.5 were explored. Experimental data showed that: when the preset grayscale contrast ratio was 1.8, the false negative rate was 4%, the false positive rate was 8%, and the total error was 12%; when the preset grayscale contrast ratio was 2.0, the false negative rate was 5%, the false positive rate was 4%, and the total error was 9%; and when the preset grayscale contrast ratio was 2.2, the false negative rate was 9%, the false positive rate was 2%, and the total error was 11%. The preset grayscale contrast ratio of 2.0, which minimized the total error, was selected as the preferred threshold in this embodiment. At this value, the actual defect detection rate was 95%, and the false defect elimination rate was 96%, which met the accuracy requirements for surface defect detection of most die-cast parts. The above thresholds can be recalibrated or used as configurable parameters of the system based on factors such as the quality requirements of different products, lighting environment, and camera parameters. For example, for products with extremely high sealing requirements, the preset grayscale contrast characterization value can be appropriately reduced to 1.8 to improve the detection rate, while for products with appearance requirements, the preset grayscale contrast characterization value can be increased to 2.2 to reduce the false detection rate.
[0044] Specifically, the directional dispersion index can effectively separate regular structures (such as the edges of reinforcing ribs and casting streamlines) from directionally dispersed real defects (such as cracks) through the consistency of edge directions. However, it is difficult to distinguish between circular pores with moderate directional dispersion and pseudo-defects with similarly dispersed directions (such as water stains, oil stains, mold release agent residue, and halos formed by uneven local lighting). The fundamental reason is that real defects such as pores are physical structural damages to the die-casting matrix material, which will form stable and significant grayscale differences in imaging (pores appear as dark spots); while pseudo-defects such as water stains and oil stains are merely surface attachments that do not change the properties of the matrix material, resulting in weak grayscale differences that are easily affected by environmental interference. Although the color difference areas caused by mold release agent residue show visible grayscale / chromatic changes, the background texture is usually complex (the grayscale standard deviation of the background ring area is large), resulting in a small grayscale contrast characterization value. Therefore, when the directional dispersion index is determined to be in a fuzzy range, a gray-scale contrast characterization value needs to be introduced for secondary determination: the larger the gray-scale contrast characterization value, the more significant the gray-scale difference between the defect area and the background, and the more uniform the background, the more likely it is to be a real defect; the smaller the gray-scale contrast characterization value, the less significant the difference between the area and the background or the unevenness of the background itself, the more likely it is to be a false defect.
[0045] Specifically, the grayscale determination module includes: Background ring extraction unit: Extracts the smallest bounding rectangle of the edge connected region, and extends it to the outside of each of the four sides of the rectangle by a preset number of pixels (in this embodiment, the preset number is 5). The extension method is as follows: the left boundary of the rectangle is moved to the left by a preset number of pixels, the right boundary is moved to the right by a preset number of pixels, the upper boundary is moved upward by a preset number of pixels, and the lower boundary is moved downward by a preset number of pixels to obtain the background ring region. The background ring region is the annular region remaining after the expanded rectangle is subtracted from the original smallest bounding rectangle. It represents the local background around the defect and is used to estimate the grayscale statistical characteristics of the normal surface around the defect. The purpose of extending by a preset number of pixels is to avoid the edge connected region itself from overlapping with the background ring region, while ensuring that the background ring region is adjacent to the defect region and can truly reflect the environment around the defect. Gray-scale mean calculation unit: Calculates the gray-scale mean of all pixels within the edge-connected region, denoted as the edge-connected region gray-scale mean; calculates the gray-scale mean of all pixels within the background ring region, denoted as the background ring region gray-scale mean. The background standard deviation calculation unit is used to calculate the gray standard deviation of all pixels in the background ring region, denoted as the gray standard deviation of the background ring region. Characteristic value calculation unit: Calculates grayscale contrast characteristic values. Where LCR represents the grayscale contrast characterization value; μ1 represents the mean grayscale value of the edge connected region; μ0 represents the mean grayscale value of the background ring region; σ0 represents the standard deviation of the grayscale value of the background ring region. When the standard deviation of the grayscale value of the background ring region σ0=0 (i.e., all pixels in the background ring have the same grayscale value), the denominator being zero will result in an infinitely large grayscale contrast characterization value. In actual images, due to camera noise and subtle textures, σ0=0 almost never occurs. If it does occur, this embodiment stipulates that the grayscale contrast characterization value is directly determined to be greater than the preset grayscale contrast threshold, which is considered a high-risk area with defects.
[0046] Specifically, the early warning decision module determines to issue a first early warning signal in response to the shape complexity of the defect area being greater than or equal to a preset shape complexity of 1.5. The early warning decision module determines to issue a second early warning signal when the shape complexity of the defect area is less than the preset shape complexity and the overlap area ratio between the defect area and the preset key area is greater than or equal to the preset overlap area ratio of 0.3. The early warning decision module determines not to issue an early warning signal if the shape complexity of the defective area is less than the preset shape complexity and the overlapping area ratio is less than the preset overlapping area ratio.
[0047] Specifically, the shape complexity of the defect region is determined based on the goodness of fit of the defect contour and the number of inflection points; the overlapping area ratio is the ratio of the overlapping area of the defect region and the preset key region to the area of the defect region; the defect region is a sub-region in which a defect is determined to exist in a low-risk region or a high-risk region.
[0048] Specifically, the preset shape complexity value is 1.5. Thirty known defect samples that lead to seal leakage or fatigue fracture and 30 known defect samples that do not affect function were collected, and their respective shape complexity values were calculated. Experiments show that the preset shape complexity of hazardous defects is concentrated between 1.5 and 6.0, while the preset shape complexity of harmless defects is concentrated between 0 and 1.2. Therefore, 1.5 is chosen as the preset shape complexity.
[0049] In this example, the preset overlap area ratio is set to 0.3. One hundred defect samples located at the edge of the critical area were collected, and the overlap area ratio of each defect was calculated. Statistical analysis was then performed based on the results of actual product sealing or strength tests. Experimental data shows that when the overlap area ratio is less than 0.3, 85% of the defects do not substantially affect the product's sealing performance or structural strength (e.g., scratches only slightly intrude into the edge of the sealing surface). When the overlap area ratio between the defect area and the preset critical area is greater than or equal to the preset overlap area ratio of 0.3, the defect significantly reduces the performance of the critical area (e.g., pores or cracks penetrate the central area of the sealing surface). Therefore, this embodiment uses a preset overlap area ratio of 0.3 as the distinction threshold. It is understandable that for products with extremely high sealing requirements (such as high-pressure seals), a preset overlap area ratio of 0.1 can be used to more sensitively capture any defects intruding into the critical area; for products where appearance is the primary requirement (such as non-load-bearing exterior parts), a preset overlap area ratio of 0.5 can be used to avoid over-alarming of minor edge intrusion defects.
[0050] Specifically, the process of obtaining the shape complexity includes: For each defect region, the early warning decision module uses a contour extraction algorithm known in the art to obtain its outer boundary contour. Specifically, a boundary tracing algorithm based on connected component analysis, such as the eight-neighbor boundary tracing algorithm, is applied to the binary image of the defect region. Starting from the edge starting point of the defect region, the algorithm traces pixel by pixel along the boundary between the defect region and the background region until it returns to the starting point, thus obtaining a closed contour composed of the boundary pixel coordinate sequence. The following two parameters are calculated using methods known in the art: Goodness of fit R 2 The coefficient of determination R is obtained by performing a least-squares linear fitting on the defect contour points. 2 R 2 The closer to 1, the closer the contour is to a straight line; the closer to 0, the more curved the contour is. Number of inflection points N: Traverse the contour sequentially, calculate the turning angle between adjacent line segments, and count an inflection point when the turning angle exceeds a preset angle threshold (e.g., 30°). Count the total number of inflection points N; Then calculate the shape complexity S using the following formula: S=(1-R) 2 )×(N+1); where (1-R²) reflects the curvature of the profile, and (N+1) reflects the complexity of the profile's twists and turns (adding 1 is to avoid S being 0 when there are no inflection points). S is a dimensionless number, and the larger its value, the more complex the defect morphology and the higher the risk of stress concentration.
[0051] Specifically, the preset critical area refers to the surface area on the die-cast part that is crucial to the product's function. In this embodiment, the preset critical area includes, but is not limited to, the following types: Sealing mating surface: an annular or flat surface that fits into the motor housing or other components to form a seal; Bearing housing mating surface: the cylindrical surface or end face that mates with the outer ring of the bearing; Root of the reinforcing rib: The rounded corner area where the reinforcing rib connects to the substrate; High stress-strain zone: a stress concentration area identified through CAE (Computer-Aided Engineering) analysis; Assembly and connection area: The area involving functional coordination such as bolt connections and locating pin installation; Product edge stress area: The area on the edge of the die casting that bears assembly stress, working load or impact load.
[0052] The geometric boundaries of the aforementioned key regions are pre-defined using any of the following methods before system deployment: Method 1 (based on CAD model): Import the CAD 3D model of the die casting, project the key areas marked in the design drawing onto the 2D image plane, and use image registration technology (such as the ICP iterative nearest point algorithm based on edge features) to align the projected contour with the acquired die casting surface image to obtain the coordinates of the closed polygons of each key area in the image pixel coordinate system.
[0053] Method 2 (Manual Teaching): Place the die-cast part at the inspection station, acquire a reference image, and the operator draws the boundary polygon of the key area on the image with the mouse. The system automatically saves its vertex coordinates.
[0054] Method 3 (Automatic Recognition): Based on a deep learning model, semantic segmentation is performed on the die-cast part image to automatically identify areas such as sealing surfaces and bearing chambers and output their mask boundaries. This method requires pre-training of the segmentation model and is suitable for large batches of products of the same model.
[0055] Regardless of the method used, the data for the preset key areas is stored in the system configuration file as a list of closed polygons at image pixel coordinates, and is directly read and used during detection. Those skilled in the art can choose any method to implement this based on actual production line conditions, without requiring any creative effort.
[0056] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A machine vision-based intelligent surface defect detection system for die-cast parts, characterized in that, include: Image acquisition module, which is used to acquire surface images of die-cast parts; The texture determination module, which is connected to the image acquisition module, is used to divide the surface image of the die casting into several sub-regions and determine the texture complexity representation value of each sub-region based on the gray-level gradient distribution of the pixels in each sub-region. A classification module, which is connected to the texture determination module, is used to classify the sub-region into a high-risk region or a low-risk region based on the texture complexity representation value of the sub-region. A dispersion determination module, which is connected to the level division module, is used to determine the directional dispersion index of the high-risk area based on the gradient direction angle of all edge pixels in the edge connected region within the high-risk area; A grayscale determination module, which is connected to the dispersion determination module, is used to determine the grayscale contrast characterization value of the edge connected region based on the grayscale distribution of the edge connected region and the background ring region; The defect detection module, which is connected to the level classification module, the dispersion determination module and the grayscale determination module respectively, is used to determine whether there is a defect in the low-risk area based on the defect area ratio of the low-risk area when the sub-region is determined to be a low-risk area. When the sub-region is identified as a high-risk region, it is used to determine whether there is a defect in the high-risk region based on the directional dispersion index of the high-risk region and the grayscale contrast characterization value. The early warning decision module, which is connected to the defect detection module, is used to determine the type of early warning signal based on the shape complexity of the defect area and the percentage of overlap between the defect area and the preset key area. The types of early warning signals include a first early warning signal and a second early warning signal.
2. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 1, characterized in that, The classification module determines the sub-region as a low-risk region in response to the sub-region's texture complexity value being less than a preset texture complexity value. The classification module determines a sub-region as a high-risk region in response to the sub-region's texture complexity value being greater than or equal to the preset texture complexity value.
3. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 2, characterized in that, The texture determination module includes: The sub-region division unit is used to uniformly divide the surface image of the die casting into several rectangular sub-regions according to a preset grid size; A gradient magnitude calculation unit is used to determine the gradient magnitude of each pixel based on its horizontal and vertical gradients. The sub-region variance calculation unit is used to calculate the variance of the gradient magnitude based on the gradient magnitude of all pixels in each sub-region, and use it as the texture complexity representation value of the sub-region.
4. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 3, characterized in that, When the sub-region is determined to be a low-risk region, the defect detection module determines that there are no defects in the low-risk region in response to the defect area ratio of the low-risk region being less than a preset area ratio. The defect detection module determines that there is a defect in the low-risk area when the defect area ratio of the low-risk area is greater than or equal to the preset area ratio. The defect area ratio is the ratio of the total area of all candidate connected regions in the low-risk area to the area of the low-risk area. The candidate connected region is a connected region in the low-risk area composed of pixels with a gray value less than a first preset gray value or greater than a second preset gray value. The first preset gray value is less than the second preset gray value.
5. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 4, characterized in that, When the sub-region is identified as a high-risk region, the defect detection module determines that there is no defect in the high-risk region in response to the directional dispersion index of the high-risk region being less than a first preset directional dispersion index. The defect detection module responds to the fact that the directional dispersion index of the high-risk area is greater than or equal to the first preset directional dispersion index and less than the second preset directional dispersion index, and then makes a secondary determination on whether there is a defect in the high-risk area based on the grayscale contrast characterization value of the high-risk area. The defect detection module determines that there is a defect in the high-risk area when the directional dispersion index of the high-risk area is greater than or equal to the second preset directional dispersion index; wherein the first preset directional dispersion index is less than the second preset directional dispersion index.
6. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 5, characterized in that, The dispersion determination module includes: The gradient direction angle calculation unit is used to determine the gradient direction angle of the edge pixel based on the horizontal and vertical gradients of each edge pixel in several edge connected regions; wherein, the edge connected region is a connected region composed of pixels with gray values of preset edge identifier values in the edge binary image obtained based on the high-risk region; The directional dispersion index calculation unit is used to determine the directional dispersion index of the edge connected region based on the standard deviation of the gradient direction angles of all edge pixels within the edge connected region.
7. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 6, characterized in that, The defect detection module determines that there is no defect in the high-risk area when the grayscale contrast value of the high-risk area is less than the preset grayscale contrast threshold. The defect detection module, in response to the grayscale contrast characterization value being greater than or equal to the preset grayscale contrast threshold, makes a secondary determination that a defect exists in the high-risk area.
8. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 7, characterized in that, The grayscale determination module includes: The background ring extraction unit is used to extract the minimum bounding rectangle of the edge connected region and extend it to the outside of the minimum bounding rectangle by a preset number of pixels to obtain the background ring region. The gray-scale mean calculation unit is used to calculate the gray-scale mean of all pixels in the edge-connected region, denoted as the edge-connected region gray-scale mean; and to calculate the gray-scale mean of all pixels in the background ring region, denoted as the background ring region gray-scale mean. The background standard deviation calculation unit is used to calculate the gray standard deviation of all pixels in the background ring region, denoted as the gray standard deviation of the background ring region. The characterization value calculation unit is used to determine the gray-level contrast characterization value based on the mean gray level of the edge connected region, the mean gray level of the background ring region, and the standard deviation of the gray level of the background ring region.
9. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 8, characterized in that, The early warning decision module determines and issues a first early warning signal in response to the shape complexity of the defect area being greater than or equal to a preset shape complexity. The early warning decision module determines to issue a second early warning signal when the shape complexity of the defect area is less than the preset shape complexity and the overlap area ratio between the defect area and the preset key area is greater than or equal to the preset overlap area ratio. The early warning decision module determines not to issue an early warning signal if the shape complexity of the defective area is less than the preset shape complexity and the overlapping area ratio is less than the preset overlapping area ratio.
10. The intelligent surface defect detection system for die-casting parts based on machine vision according to claim 9, characterized in that, The shape complexity of the defect region is determined based on the goodness of fit of the defect contour and the number of inflection points; the overlap area ratio is the ratio of the overlap area between the defect region and the preset key region to the area of the defect region. The defective region is a sub-region in which a defect is determined to exist in either a low-risk region or a high-risk region.