Industrial workpiece visual defect detection method and system based on multi-scale feature fusion

CN122551069APending Publication Date: 2026-08-11LANGFANG HENGTU TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-26
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

若将各个异常小块分别作为检测结果输出,容易使同一处连续缺陷被拆分为多个零散结果,导致后续难以准确获得该缺陷的整体范围、中心位置和形状类型

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122551069A_ABST
    Figure CN122551069A_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for detecting visual defects in industrial workpieces based on multi-scale feature fusion, relating to the field of visual inspection of workpieces. The method includes: acquiring a standard image of the workpiece to be inspected; dividing the standard image of the workpiece to be inspected into P detection grids; constructing an adjacency relationship set between candidate defect grids; constructing an effective defect region containing at least one candidate defect grid based on the adjacency relationship set; extracting the perimeter coordinate set of the effective defect region based on the grid boundary coordinate set inherited by each candidate defect grid in the effective defect region; and pairing the defect shape label, defect center coordinates, and defect area into a defect ternary record for the industrial workpiece to be inspected. This invention reduces the influence of isolated weak response grids on the detection results, and the detection results are characterized as defect ternary records corresponding to the effective defect region, enabling the defects of the industrial workpiece to be inspected to be expressed simultaneously in terms of shape, position, and area.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of visual inspection of workpieces, specifically to a method and system for detecting visual defects in industrial workpieces based on multi-scale feature fusion. Background Technology

[0002] In the visual inspection of industrial workpieces, it is typically necessary to determine the presence of surface defects such as scratches, cracks, stains, and gaps based on the workpiece surface image. Existing inspection methods commonly involve analyzing the grayscale, texture, and edge features of the entire image or a small local area, and directly outputting the detected abnormal locations or patches as the inspection result. While this approach can identify locations on the workpiece surface that differ from the standard appearance, its detection results usually remain at the level of outputting localized anomalies.

[0003] In real-world inspection scenarios, surface defects on workpieces are rarely isolated points. Slender scratches may span multiple local areas, cracks may be continuous or zigzag-shaped, and stains, indentations, or defects may cover a certain area. If each anomalous patch is output as a separate inspection result, a continuous defect at the same location is easily split into multiple fragmented results, making it difficult to accurately determine the overall extent, center position, and shape type of the defect. Furthermore, some isolated weak anomalous patches may be caused by lighting fluctuations, surface texture interference, or image noise. If these isolated anomalous patches are directly output as defect results, false alarms are likely to increase. Therefore, existing industrial workpiece visual inspection methods still suffer from problems such as the splitting of continuous defects into smaller outputs, interference from isolated weak anomalous patches with inspection results, and insufficient representation of the overall defect morphology. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a method and system for visual defect detection of industrial workpieces based on multi-scale feature fusion. By merging candidate defect grids into effective defect regions through a grid boundary coordinate set, and outputting the defect shape, location, and area based on the perimeter coordinate set of the effective defect regions, the visual defect detection results are transformed from grid-level judgment to region-level recording, thus solving the technical problems raised in the background art.

[0005] To achieve the above objectives, the present invention provides the following technical solution: In a first aspect, the present invention discloses a method for detecting visual defects in industrial workpieces based on multi-scale feature fusion, comprising the following steps: S1. Obtain the standard image of the industrial workpiece to be inspected; wherein, the standard image of the workpiece to be inspected is a workpiece image whose main body position, workpiece posture and image scale all meet the preset inspection benchmark. S2. Divide the standard image of the workpiece to be inspected into P detection grids; wherein, the detection grid is a square grid, and each detection grid is configured with a grid number and a grid boundary coordinate set; S3. Based on the grid number configured for each detection grid, mark the candidate defect grids in the P detection grids and construct a set of adjacency relationships between the candidate defect grids; S4. Based on the adjacency relationship set, connect and merge adjacent candidate defect meshes to construct an effective defect region containing at least one candidate defect mesh; wherein, the candidate defect meshes in the effective defect region inherit the mesh number and mesh boundary coordinate set of the corresponding detection mesh; S5. Based on the grid boundary coordinate set inherited by each candidate defect grid in the effective defect region, extract the perimeter coordinate set of the effective defect region; S6. Perform shape recognition, center positioning, and area calculation on the perimeter coordinate set to determine the defect shape label, defect center coordinates, and defect area of ​​the effective defect area, and pair the defect shape label, defect center coordinates, and defect area to form a ternary defect record for the industrial workpiece to be inspected.

[0006] In some embodiments, constructing a set of adjacency relationships between candidate defect meshes includes: S3-1. Based on the grid number, select the current detection grid from P detection grids in sequence, and calculate the multi-scale defect deviation of the current detection grid; wherein, the multi-scale defect deviation is used to characterize the degree of appearance deviation of the current detection grid in terms of detail texture, edge morphology and regional structure. S3-2. Compare the multi-scale defect deviation of the current detection grid with the preset defect deviation threshold; If the multi-scale defect deviation is greater than the preset defect deviation threshold, the current detection grid is marked as a candidate defect grid. S3-3. Traverse the P detection grids and repeatedly perform grid marking until the marking of the P detection grids is completed, resulting in P1 candidate defect grids; where each candidate defect grid inherits the grid number and grid boundary coordinate set of the corresponding detection grid; S3-4. Based on the grid boundary coordinate set inherited from P1 candidate defect grids, construct the set of adjacency relationships between candidate defect grids.

[0007] In some of these embodiments, the calculation of the multi-scale defect bias of the current detection grid includes: S3-1-1, Obtain the detailed texture features, edge morphology features, and region structure features of the current detection mesh; S3-1-2. Calculate the feature distance between the detailed texture features, edge morphology features, and region structure features of the current detected mesh and the standard detailed texture features, standard edge morphology features, and standard region structure features corresponding to the same mesh number in the pre-built standard appearance feature library, and generate texture feature deviation, edge feature deviation, and structure feature deviation. S3-1-3. Arrange the texture feature deviation, edge feature deviation, and structural feature deviation into a feature deviation vector; S3-1-4. Read the texture allowable deviation, edge allowable deviation, and structural allowable deviation corresponding to the same grid number from the standard appearance feature library, and arrange the texture allowable deviation, edge allowable deviation, and structural allowable deviation into an allowable deviation vector; S3-1-5. Divide the deviation of each dimension in the feature deviation vector by the allowable deviation of the same dimension in the allowable deviation vector to generate a normalized deviation vector; wherein, the normalized deviation vector includes normalized texture deviation, normalized edge deviation and normalized structure deviation. S3-1-6. Extract texture response values, edge response values, and structural response values ​​from the detailed texture features, edge morphology features, and regional structure features of the current detection mesh, and arrange the texture response values, edge response values, and structural response values ​​into a scale response vector; S3-1-7. Weight the scale response vector to construct a fusion weight vector; wherein, the fusion weight vector includes texture fusion weight, edge fusion weight, and structure fusion weight; S3-1-8. Perform a dot product between the normalized bias vector and the fusion weight vector to calculate the multi-scale defect bias of the current detection grid.

[0008] In some embodiments, the feature distance calculation includes: A1. Perform a one-dimensional difference calculation between the target feature of the current detection grid and the standard target feature corresponding to the same grid number in the standard appearance feature library to obtain the one-dimensional feature difference; wherein, the target feature is a detailed texture feature, edge morphology feature or region structure feature; A2. Take the absolute value of the feature difference in each dimension, and sum the absolute differences of each dimension according to the preset dimension weights to generate the weighted magnitude difference of the target feature. A3. Calculate the target feature deviation based on the weighted amplitude difference and the directional consistency between the target feature and the standard target feature; A4. Using the detailed texture features, edge morphology features, and region structure features as target features, repeat A1-A3 to generate texture feature deviation, edge feature deviation, and structure feature deviation respectively.

[0009] In some embodiments, constructing the fusion weight vector includes: B1. Add the texture response value, edge response value, and structure response value in the scale response vector to generate the total response value; B2. Divide the texture response value, edge response value, and structure response value by the total response value to generate texture fusion weight, edge fusion weight, and structure fusion weight, respectively. B3. Arrange the texture blending weights, edge blending weights, and structure blending weights into a blending weight vector.

[0010] In some embodiments, based on the grid boundary coordinate set inherited by P1 candidate defect grids, a set of adjacency relationships between candidate defect grids is constructed, including: S3-4-1. Read the grid boundary coordinate sets inherited by each of the P1 candidate defect grids; S3-4-2. Extract the minimum horizontal coordinate, maximum horizontal coordinate, minimum vertical coordinate, and maximum vertical coordinate from the grid boundary coordinate set of each candidate defect grid; S3-4-3. If the maximum horizontal coordinate of one of the two candidate defect meshes is equal to the minimum horizontal coordinate of the other candidate defect mesh, and their vertical coordinate intervals intersect, then the two candidate defect meshes are identified as horizontally adjacent candidate defect meshes. S3-4-4 If the maximum vertical coordinate of one of the two candidate defect meshes is equal to the minimum vertical coordinate of the other candidate defect mesh, and their horizontal coordinate intervals intersect, then the two candidate defect meshes are identified as vertically adjacent candidate defect meshes. S3-4-5. Traverse P1 candidate defect meshes and construct a set of adjacency relationships between candidate defect meshes based on the mesh numbers of the candidate defect meshes that are identified as horizontally or vertically adjacent.

[0011] In some embodiments, adjacent candidate defect meshes are connected and merged according to an adjacency set to construct an effective defect region containing at least one candidate defect mesh, including: S4-1. Based on the set of adjacency relationships between candidate defect meshes, candidate defect meshes with direct or indirect adjacency relationships are grouped into the same connected mesh group. S4-2. Merge the grid boundary coordinate sets of each candidate defect grid in the same connected grid group to generate the region boundary coordinate set; S4-3. Determine the image region corresponding to the region boundary coordinate set as the initial defect region; S4-4. Count the number of candidate defect meshes in the initial defect region and calculate the average multi-scale defect deviation of the candidate defect meshes in the initial defect region; S4-5. If the number of candidate defect meshes in the initial defect region is less than the preset number of meshes, and the average multi-scale defect deviation is less than the preset region retention deviation, then the initial defect region is removed. S4-6. Identify the initial defect areas that were not eliminated as valid defect areas.

[0012] In some embodiments, the extraction of the perimeter coordinate set of the effective defect region includes: S5-1. Merge the grid boundary coordinate sets of each candidate defect grid in the effective defect region to generate the effective region boundary coordinate set; S5-2. Delete the internal common-edge coordinates between adjacent candidate defect meshes from the effective region boundary coordinate set, and retain the outermost boundary coordinates of the effective defect region. S5-3. Arrange the outermost boundary coordinates in the order of their connection on the effective defect area contour to generate the perimeter coordinate set.

[0013] The industrial workpiece visual defect detection method based on multi-scale feature fusion provided by this invention has the following beneficial effects: This invention divides the standard image of the workpiece to be inspected into P inspection grids. Features at three scales—detail texture, edge morphology, and regional structure—are extracted from each grid and compared with a standard appearance feature library. Multi-scale defect deviations are calculated to label candidate defect grids. Then, based on the grid boundary coordinate set inherited by the candidate defect grids, adjacency relationships are identified and connected and merged to form effective defect regions. Finally, the perimeter coordinate set of the effective defect regions is extracted for shape recognition, center location, and area calculation, generating a ternary defect record containing a defect shape label, defect center coordinates, and defect area. This method identifies positional adjacency relationships through the grid boundary coordinate set inherited by the candidate defect grids and connects and merges adjacent candidate defect grids. Therefore, candidate defect grids belonging to the same continuous anomaly region can be grouped into the same initial defect region, avoiding the splitting of the same defect into multiple isolated grids for output. Furthermore, based on the number of candidate defect meshes and the average multi-scale defect deviation within the initial defect region, the initial defect region is either retained or eliminated, and the initial defect regions that are not eliminated are identified as effective defect regions. This allows isolated interference regions with fewer meshes and lower average multi-scale defect deviations to be eliminated, while the retained effective defect regions are closer to the continuous abnormal regions on the workpiece surface, reducing the impact of isolated weak response meshes on the detection results.

[0014] Based on this, the perimeter coordinate set is extracted from the grid boundary coordinate set of each candidate defect grid in the effective defect area, and the defect shape label, defect center coordinates and defect area are generated based on the perimeter coordinate set. Thus, the detection result is characterized as a ternary record of defects corresponding to the effective defect area, so that the defects of the industrial workpiece to be inspected can be expressed in terms of shape, position and area at the same time.

[0015] Secondly, the present invention discloses an industrial workpiece visual defect detection system based on multi-scale feature fusion, used to perform the industrial workpiece visual defect detection method based on multi-scale feature fusion described in the first aspect, comprising: The workpiece image acquisition module is used to acquire a standard image of the industrial workpiece to be inspected; wherein, the standard image of the workpiece to be inspected is a workpiece image whose main body position, workpiece posture and image scale all meet the preset inspection benchmark. The detection grid division module is used to divide the standard image of the workpiece to be inspected into P detection grids; wherein, the detection grid is a square grid, and each detection grid is configured with a grid number and a grid boundary coordinate set; The candidate grid identification module is used to mark candidate defect grids in P detection grids according to the grid number configured for each detection grid, and to construct a set of adjacency relationships between candidate defect grids; The effective region generation module is used to connect and merge adjacent candidate defect meshes according to the adjacency relationship set to construct an effective defect region containing at least one candidate defect mesh; wherein, the candidate defect meshes in the effective defect region inherit the mesh number and mesh boundary coordinate set of the corresponding detection mesh; The perimeter coordinate extraction module is used to extract the perimeter coordinate set of the effective defect region based on the grid boundary coordinate set inherited by each candidate defect grid in the effective defect region. The defect record pairing module is used to perform shape recognition, center positioning, and area calculation on the perimeter coordinate set, determine the defect shape label, defect center coordinates, and defect area of ​​the effective defect area, and pair the defect shape label, defect center coordinates, and defect area into a three-dimensional defect record for the industrial workpiece to be inspected.

[0016] Compared with the prior art, the beneficial effects of the industrial workpiece visual defect detection system based on multi-scale feature fusion of the present invention are the same as those of the above-mentioned industrial workpiece visual defect detection method based on multi-scale feature fusion, so they will not be repeated here. Attached Figure Description

[0017] Figure 1 This is a flowchart illustrating the industrial workpiece visual defect detection method based on multi-scale feature fusion according to the present invention. Figure 2This is a schematic diagram of the identification process for adjacent candidate defect meshes in this invention; Figure 3 This is a schematic diagram of the calculation process for the target feature deviation described in this invention; Figure 4 This is a schematic diagram illustrating the process of generating the adjacent relationship set described in this invention; Figure 5 This is a schematic diagram of the process for generating the perimeter coordinate set described in this invention; Figure 6 This is a structural block diagram of the industrial workpiece visual defect detection system based on multi-scale feature fusion according to the present invention. Detailed Implementation

[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. 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 skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] Example 1: Please see Figure 1 This invention provides a method for detecting visual defects in industrial workpieces based on multi-scale feature fusion, comprising the following steps: S1. Obtain the standard image of the industrial workpiece to be inspected; wherein, the standard image of the workpiece to be inspected is a workpiece image whose main body position, workpiece posture and image scale all meet the preset inspection benchmark. Specifically, the standardized image of the workpiece to be inspected refers to an image formed by performing workpiece subject positioning, posture correction, and scale unification on the original acquired image of the industrial workpiece to be inspected. Workpiece subject positioning involves cropping the main body area of ​​the workpiece from the original image and centering it in the image to eliminate background interference. Posture correction involves rotating the workpiece to a preset horizontal direction to avoid different grid coordinates for the same physical position due to workpiece tilt. Scale unification involves scaling the workpiece to a fixed pixel size to ensure consistent workpiece size across different batches of images. After the original image is acquired by an industrial camera, it can be achieved through contour positioning (e.g., extracting the workpiece's bounding rectangle based on edge detection), reference point correction (e.g., performing affine transformation using positioning holes or corner points on the workpiece), or template registration (e.g., feature matching between the acquired image and a standard template).

[0020] The industrial workpieces to be inspected include metal stampings, injection molded parts, electronic structural parts, ceramic parts, or other industrial workpieces that require surface visual inspection.

[0021] To facilitate a better understanding of the steps in this embodiment, the workpiece to be tested will be a metal fixing plate of a new energy vehicle battery pack.

[0022] This new energy vehicle battery pack metal fixing plate is used to press and fix the battery module. It is a flat battery pack metal fixing plate, that is, a plate-shaped metal stamping part. It includes a flat workpiece body surface, a stamped and blanked workpiece outer edge, and multiple mounting holes arranged at preset positions on the workpiece body surface. The reference outer contour of the industrial workpiece to be inspected is rectangular, with only the corners rounded. Its body surface is a complete, continuous, flat metal plane, without stamped protruding reinforcing ribs, grooves, or uneven steps. The plate thickness is uniform, with no height difference. Its mounting holes are through round holes, without circumferential flanges or countersunk edges.

[0023] The method for obtaining the standard image of the metal fixing plate of the new energy vehicle battery pack to be inspected includes: when locating the main body of the workpiece in the original acquired image, the outer rectangle of the plate is extracted by the edge detection algorithm, and the main body area of ​​the plate is cropped from the original acquired image based on the outer rectangle, so that it is located in the center of the image; when performing posture correction, the geometric center of the mounting hole or the straight edge of the plate can be used as the reference feature for affine transformation. Specifically, the straight edge of the outer edge of the plate or the center of two or more mounting holes can be selected as the reference point, and the plate is rotated to a preset horizontal direction so that the length direction of the plate is parallel to the horizontal axis of the image and the width direction is parallel to the vertical axis of the image. After posture correction, the same physical position should correspond to the same grid coordinates in the standard images of different batches of workpieces to be inspected; when performing scale unification, since the plate of different batches may present different pixel sizes in the original acquired image due to factors such as camera distance and lens parameters, the posture-corrected plate image needs to be scaled to a fixed pixel scale. Specifically, the pressure plate can be adjusted to a preset pixel size by scaling it proportionally according to the length or short side of the rectangle circumscribed by the pressure plate, so as to ensure that the physical size and pixel size of the pressure plate are consistent in the specification images of different batches of workpieces to be inspected.

[0024] After the above-mentioned workpiece positioning, posture correction, and dimensional standardization processing, a standardized image of the metal fixing plate of the new energy vehicle battery pack can be obtained. In this standardized image, the plate body is located in the center of the image, the length of the plate extends along the horizontal direction of the image, and the width extends along the vertical direction of the image. The pixel size of the plate is consistent with the preset detection benchmark. The surface of the workpiece body, the outer edge of the workpiece, and the surrounding areas of each mounting hole are all presented in the standardized image in a unified coordinate system, providing standardized image input for subsequent detection mesh division and candidate defect mesh marking.

[0025] S2. Divide the standard image of the workpiece to be inspected into P detection grids; wherein, the detection grid is a square grid, and each detection grid is configured with a grid number and a grid boundary coordinate set; Specifically, P detection grids refer to P square grids obtained by regularly dividing the effective detection area of ​​the workpiece's standard image into grids. After dividing the grid equally along the horizontal and vertical directions, each square grid is a detection grid.

[0026] The effective detection area refers to the image area in the standard image of the workpiece to be inspected that needs to participate in defect detection. It can be determined according to the outer contour of the industrial workpiece to be inspected, the inspection process requirements, and the location where defects are prone to occur. For example, for metal stamping parts, the effective detection area can be the formed surface area of ​​the stamping part; for injection molded parts, the effective detection area can be the appearance surface, assembly surface, or the inspection surface specified by the customer; for electronic structural parts, the effective detection area can be the shell surface, connection edge, or the area around the mounting hole.

[0027] Furthermore, the value of P can be determined based on the size of the effective detection area, the minimum identifiable size of the defect to be detected, and the required detection accuracy. Specifically, the effective detection area can be divided according to the horizontal and vertical pixel lengths, combined with a preset grid side length; wherein the preset grid side length is less than or equal to the pixel scale corresponding to the minimum identifiable size of the defect to be detected, ensuring that at least one detection grid can cover the corresponding defect. If the number of horizontal divisions of the effective detection area is R, and the number of vertical divisions is C, then P = R × C. For industrial workpieces with larger structural dimensions, higher detection accuracy requirements, or smaller defect sizes, the preset grid side length can be reduced, increasing the value of P; for industrial workpieces with smaller structural dimensions, lower detection accuracy requirements, or only needing to identify larger defects, the preset grid side length can be increased, decreasing the value of P. After dividing the effective detection area equally along the horizontal and vertical directions, each square grid is a detection grid.

[0028] Furthermore, the grid number is used to distinguish different detection grids; for example, the detection grid in row r and column c can be labeled G(r,c). The grid boundary coordinate set is used to record the boundary position of the detection grid in the specification image of the workpiece to be inspected. It includes at least the coordinates of the four corner points of the detection grid, as well as the boundary pixel coordinates on the upper, lower, left, and right boundaries determined by the four corner point coordinates. Among them, the four corner point coordinates are used to determine the minimum horizontal coordinate, maximum horizontal coordinate, minimum vertical coordinate, and maximum vertical coordinate of the detection grid, and the boundary pixel coordinates are used to characterize the common edge position between the detection grid and adjacent detection grids.

[0029] For the metal fixing plate of the new energy vehicle battery pack described in this embodiment, the main surface of the workpiece, the outer edge of the workpiece, and the area around the mounting holes can all be used as effective detection areas in the standard image of the workpiece to be inspected. The main surface of the workpiece is prone to scratches, stains, or indentations; the outer edge of the workpiece is prone to notches or edge defects; and the area around the mounting holes is prone to hole edge cracks or local burrs. The method for determining the number P of the detection grid to be divided is as follows: first, determine the horizontal pixel length of the effective detection area in the standard image. =800 pixels, vertical pixel length =400 pixels; then, the preset grid side length s is determined based on the minimum identifiable size of the defect to be detected. Since the minimum width of a scratch that may appear on the pressure plate surface is approximately 0.1 mm, and the spatial resolution of the industrial camera acquiring the original image is 0.05 mm / pixel, the pixel scale corresponding to the minimum defect is 2 pixels. To ensure that at least one detection grid can cover the above minimum defect, the preset grid side length s should be less than or equal to 2 pixels. If higher detection accuracy is required or more precise positioning of the defect boundary is needed, the preset grid side length s can be further set to 1 pixel. In this example, the preset grid side length s = 2 pixels is used for illustration; based on this, the number of horizontal divisions is... Quantity of vertical division ,in, For the floor operation, the total number of detection grids is P = R × C = 400 × 200 = 80,000. That is, the effective detection area of ​​the metal fixing plate of the new energy vehicle battery pack is divided into 80,000 square detection grids. Each detection grid is equipped with a grid number and a grid boundary coordinate set, which are used for candidate defect grid marking, adjacent relationship set construction and effective defect area generation in subsequent steps.

[0030] S3. Based on the grid number configured for each detection grid, candidate defect grids are marked in the P detection grids, and an adjacency relationship set between candidate defect grids is constructed; wherein, the candidate defect grid is the detection grid obtained by marking in the P detection grids, and the adjacency relationship set represents the grid numbers of adjacent candidate defect grids and their connection relationship. Specifically, step S3 includes: S3-1. Based on the grid number, select one of the P detection grids as the current detection grid, and calculate the multi-scale defect deviation of the current detection grid; wherein, the multi-scale defect deviation is used to characterize the degree of appearance deviation of the current detection grid in terms of detail texture, edge morphology and regional structure; In this embodiment, the multi-scale defect deviation is generated by the detailed texture features, edge morphology features, and regional structure features of the current detection mesh; the larger the multi-scale defect deviation, the more likely the current detection mesh is to have defects.

[0031] S3-2. Compare the multi-scale defect deviation of the current detection grid with the preset defect deviation threshold; If the multi-scale defect deviation is greater than the preset defect deviation threshold, the current detection grid is marked as a candidate defect grid; if the multi-scale defect deviation is less than or equal to the preset defect deviation threshold, the current detection grid is marked as a defect-free grid. In this embodiment, the preset defect deviation threshold can be taken as the sum of the mean of multi-scale defect deviations in the qualified workpiece samples and the standard deviation of a preset multiple. Specifically, the preset defect deviation threshold is set separately for each grid number. Specifically, for multiple qualified workpiece samples of the same specification (the number of qualified workpiece samples is not less than 30), the multi-scale defect deviations under the same grid number are extracted, and their mean and standard deviation are calculated; the preset defect deviation threshold corresponding to the grid number is generated according to the method of "threshold = mean + k × standard deviation", where k is a preset multiple. Different grid numbers can have different thresholds to adapt to the natural appearance differences of different areas of the workpiece (such as the central area and the outer edge area of ​​the main surface). The value of the preset multiple k is in the range of 3 to 6, preferably 4, to achieve a balance between the defect detection rate and the false alarm rate; this multiple can be adjusted according to the false alarm tolerance and the risk of missed detection in the actual detection scenario.

[0032] Using the example of the metal fixing plate for new energy vehicle battery packs, assuming the mean multi-scale defect deviation of the qualified workpiece samples under this grid number is 0.85 and the standard deviation is 0.18, and calculating with an optimal multiple k=4, the preset defect deviation threshold corresponding to this grid number is 0.85+4×0.18=1.57. The multi-scale defect deviation of the currently detected grid is 1.616, which is greater than 1.57, therefore this grid is marked as a candidate defect grid.

[0033] S3-3. Traverse the P detection grids and repeatedly perform grid marking until the marking of the P detection grids is completed, resulting in P1 candidate defect grids; where each candidate defect grid inherits the grid number and grid boundary coordinate set of the corresponding detection grid; Where P1 represents the number of grids marked as candidate defects; after marking P detection grids, the detection grids not marked as candidate defects are considered defect-free grids. Candidate defect grids inherit the grid number and grid boundary coordinate set of the corresponding detection grids, so that the candidate defect grids still correspond to the original grid positions in the specification image of the workpiece to be inspected.

[0034] S3-4. Based on the grid boundary coordinate set inherited from P1 candidate defect grids, construct the set of adjacency relationships between candidate defect grids.

[0035] It should be noted that "adjacent in position" does not refer to the consecutive grid numbers of the candidate defect meshes, but rather to their adjacent image positions within the specification image of the workpiece to be inspected. For two candidate defect meshes, the existence of a shared edge relationship or boundary contact relationship can be determined based on their inherited mesh boundary coordinate sets.

[0036] For example, if two candidate defect meshes share a common left and right edge, they can be identified as horizontally adjacent; if two candidate defect meshes share a common top and bottom edge, they can be identified as vertically adjacent.

[0037] Furthermore, the detection method further includes: S4. Based on the adjacency relationship set, connect and merge adjacent candidate defect meshes to construct an effective defect region containing at least one candidate defect mesh; wherein, the candidate defect meshes in the effective defect region inherit the mesh number and mesh boundary coordinate set of the corresponding detection mesh; In this embodiment, if there is a direct or indirect adjacent relationship between multiple candidate defect meshes, these candidate defect meshes are merged into the same effective defect region.

[0038] For example, if candidate defect mesh A is adjacent to candidate defect mesh B, and candidate defect mesh B is adjacent to candidate defect mesh C, then candidate defect meshes A, B, and C can be merged into the same valid defect region. In this way, candidate defect meshes with consecutive positions can be grouped into the same valid defect region, and isolated candidate defect meshes are not directly output as complete defect regions, thereby reducing the impact of isolated meshes on visual inspection results.

[0039] S5. Based on the grid boundary coordinate set inherited by each candidate defect grid in the effective defect region, extract the perimeter coordinate set of the effective defect region; Specifically, the perimeter coordinate set is used to represent the outer contour of the effective defect region. Since the effective defect region consists of one or more candidate defect meshes, and each candidate defect mesh inherits a mesh boundary coordinate set, the boundary coordinates located outside the region can be extracted based on the mesh boundary coordinate sets of each candidate defect mesh within the effective defect region to form the perimeter coordinate set.

[0040] S6. Perform shape recognition, center positioning, and area calculation on the perimeter coordinate set to determine the defect shape label, defect center coordinates, and defect area of ​​the effective defect area, and pair the defect shape label, defect center coordinates, and defect area to form a ternary defect record for the industrial workpiece to be inspected.

[0041] Specifically, the perimeter coordinate set is used to represent the outer contour of the effective defect area, and therefore can be used to generate defect shape labels, defect center coordinates, and defect area.

[0042] In shape recognition, the aspect ratio of the circumscribed rectangle, the degree of curvature of the perimeter, and the main extension direction can be extracted based on the perimeter coordinate set, and defect shape labels can be generated through rule mapping. For example, when the aspect ratio of the circumscribed rectangle is large and the main extension direction is continuous, a scratch shape label is generated; when the degree of curvature of the perimeter is high and the perimeter coordinate set is irregularly linearly distributed, a crack shape label is generated; when the region is concentrated in a blocky distribution, a stain shape label is generated; when the perimeter coordinate set coincides with the outer edge of the workpiece, an edge defect shape label is generated. In another implementation, a shape classification model can be constructed based on supervised learning. The aspect ratio of the circumscribed rectangle, the degree of curvature of the perimeter, the main extension direction, the perimeter length, and the defect area are input into the shape classification model, and the shape classification model outputs defect shape labels.

[0043] In center localization, the defect center coordinates can be generated based on the arithmetic mean center of the perimeter coordinate set, the centroid of the region enclosed by the perimeter, or the center point of the smallest circumscribed rectangle. In area calculation, the defect area can be generated based on the area of ​​the region enclosed by the perimeter coordinate set, which more accurately reflects the actual physical area of ​​the defect; alternatively, the defect area can be obtained by multiplying the number of candidate defect grids within the effective defect area by the area of ​​a single detected grid, serving as a fast estimation method.

[0044] Finally, the defect shape label, defect center coordinates, and defect area corresponding to the same valid defect area are paired to generate a ternary record of the defect corresponding to that valid defect area.

[0045] Example 2: See Figures 2 to 5 This embodiment, based on Embodiment 1, further explains the specific implementation methods of each step. The specific implementation methods of each step are described below.

[0046] In this embodiment, step S3-1 includes: S3-1-1, Obtain the detailed texture features, edge morphology features, and region structure features of the current detection mesh; Specifically, detail texture features, edge morphology features, and region structure features are all extracted from the image pixel region corresponding to the current detection grid. Before extraction, the image pixel region can be processed by grayscale conversion, filtering for noise reduction, or grayscale normalization. Among them, detail texture features may include grayscale variation amplitude or local contrast, used to characterize local detail changes within the current detection grid; edge morphology features may include edge intensity or edge pixel ratio, used to characterize contour changes within the current detection grid; region structure features may include region grayscale mean, region contrast, or neighborhood grayscale difference, used to characterize the overall appearance changes of the current detection grid and its neighboring regions.

[0047] In this embodiment, the detailed texture features, edge morphology features, and region structure features are obtained in the following ways: Detail texture features can be obtained by calculating the standard deviation of the grayscale values ​​of all pixels within the current detection grid. Specifically, first, the average grayscale values ​​of all pixels within the current detection grid are calculated. Then, the deviation of each pixel's grayscale value from this average is calculated. The squares of each deviation are then summed and divided by the total number of pixels within the current detection grid. Finally, the square root of the result is taken to obtain the grayscale standard deviation. This feature is a one-dimensional scalar used to characterize the dispersion of grayscale distribution within the current detection grid, i.e., the roughness or drastic change in local detail texture. A larger grayscale standard deviation indicates more drastic grayscale changes within the grid and a coarser texture; a smaller grayscale standard deviation indicates more uniform grayscale within the grid and a smoother texture.

[0048] Edge morphology feature acquisition: The Sobel operator is used to perform convolution operations on the current detection grid, calculating the gradients in the horizontal and vertical directions respectively. Then, the gradient magnitude of each pixel is calculated based on the horizontal and vertical gradients. A preset edge threshold is set, and the number of pixels with gradient magnitudes greater than the edge threshold is counted. The count of pixels is divided by the total number of pixels in the current detection grid to obtain the edge pixel ratio; at the same time, the average gradient magnitude of all pixels in the grid is calculated. The edge pixel ratio and the average gradient magnitude are arranged in order to form a two-dimensional edge morphology feature vector, which is used to characterize the contour change intensity and edge density in the current detection grid. The higher the edge pixel ratio, the denser the edges in the grid; the larger the average gradient magnitude, the clearer and sharper the edges in the grid. The preset edge threshold can be determined using the Otsu adaptive thresholding algorithm, or it can be preset to a fixed grayscale gradient value according to the actual detection scenario.

[0049] The region structure feature uses the current detection grid as the center and takes a surrounding window as the reference region, meaning the side length of the reference region is two pixels longer than the side length of the current detection grid. The average grayscale value of all pixels within the current detection grid and the average grayscale value of all pixels within the neighboring window (excluding the current detection grid) are calculated. The absolute value of the difference between these two values ​​is used as the structural dissimilarity, characterizing the overall grayscale difference between the current detection grid and its surrounding neighborhood. Simultaneously, the variance of the pixel grayscale values ​​within the current detection grid (i.e., the square of the grayscale standard deviation in the above detail texture features) is calculated. The grayscale variance and structural dissimilarity are arranged into a two-dimensional region structure feature vector to characterize the overall appearance change of the current detection grid and its neighboring regions. A larger structural dissimilarity indicates a more significant appearance difference between the current detection grid and its surrounding neighborhood, and a greater likelihood of structural defects.

[0050] Furthermore, detail texture features, edge morphology features, and region structure features are all represented as feature vectors and stored in a preset dimensional order; that is, detail texture features are one-dimensional feature vectors, edge morphology features are two-dimensional feature vectors, and region structure features are two-dimensional feature vectors. These three are stored separately for subsequent feature distance calculations. Corresponding standard features in the standard appearance feature library are generated in exactly the same way to ensure consistent dimensions and aligned physical meanings during feature distance calculations.

[0051] S3-1-2. Calculate the feature distance between the detailed texture features, edge morphology features, and region structure features of the current detected mesh and the standard detailed texture features, standard edge morphology features, and standard region structure features corresponding to the same mesh number in the pre-built standard appearance feature library, and generate texture feature deviation, edge feature deviation, and structure feature deviation. Specifically, the standard appearance feature library can be constructed from the standardized images of qualified workpieces of the same specifications. After dividing the standardized images of qualified workpieces of the same specifications into inspection grids according to the same rules as the standardized images of the workpiece to be inspected, the standard detail texture features, standard edge morphology features, and standard region structure features under the same grid number are extracted and stored in the standard appearance feature library.

[0052] By calculating feature distance using the same grid number, the current detection grid can be compared only with standard features at the same location, reducing misjudgments caused by natural appearance differences between different workpiece areas.

[0053] Furthermore, the feature distance calculation includes: A1. Perform a one-dimensional difference calculation between the target feature of the current detection grid and the standard target feature corresponding to the same grid number in the standard appearance feature library to obtain the one-dimensional feature difference; wherein, the target feature is a detailed texture feature, edge morphology feature or region structure feature; A2. Take the absolute value of the feature difference in each dimension, and sum the absolute differences of each dimension according to the preset dimension weights to generate the weighted magnitude difference of the target feature. A3. Calculate the target feature deviation based on the weighted amplitude difference and the directional consistency between the target feature and the standard target feature; Specifically, in this embodiment, the formula for calculating the target feature deviation is: ; in: denoted by target feature deviation, x represents the type of target feature currently calculated, where the xth type of target feature is a detailed texture feature, edge morphology feature, or region structure feature; This represents the normalized dimension weight corresponding to the j-th dimension, and the sum of the normalized dimension weights is 1. It can be preset according to the contribution of each dimension. This represents the absolute deviation of the x-th type target feature of the current detection grid from the x-th type standard target feature of the same grid number in the standard appearance feature library in the j-th dimension; d represents the number of dimensions of the target feature; This represents the directional difference adjustment coefficient, used to control the correction strength of directional consistency to characteristic deviation, and its value ranges from 0.5 to 1.0, preferably 1.0; This represents the directional consistency between the x-th class target feature and the corresponding x-th class standard target feature in the current detection grid. The directional consistency is the cosine similarity between the two, and the value ranges from -1 to 1. The larger the value, the more consistent the directions are. In the formula for calculating the target characteristic deviation, This represents the weighted magnitude difference between the target features of the current detection grid and the standard target features, which is obtained by multiplying the absolute deviation of each dimension by the corresponding normalized dimension weight and then summing the results. This represents a correction term based on directional consistency. The higher the directional consistency, the better the directionality of the target feature compared to the standard target feature. The closer the value is to 1, the closer the correction term is to 1; the more significant the difference in direction between the two, the greater the directional consistency. The smaller the value, the larger the correction term.

[0054] A4. Using the detailed texture features, edge morphology features, and region structure features as target features, repeat A1 to A3 to generate texture feature deviation, edge feature deviation, and structure feature deviation respectively.

[0055] S3-1-3. Arrange the texture feature deviation, edge feature deviation, and structural feature deviation into a feature deviation vector; Specifically, according to the definition in S3-1-1, detail texture features are one-dimensional scalars, edge morphology features are two-dimensional vectors, and region structure features are two-dimensional vectors; correspondingly, texture feature deviation is a one-dimensional scalar, edge feature deviation is a two-dimensional vector, and structure feature deviation is a two-dimensional vector. The two dimensions of texture feature deviation, edge feature deviation, and structure feature deviation are concatenated sequentially to form a five-dimensional feature deviation vector. This five-dimensional feature deviation vector is arranged in the order of texture deviation, first dimension of edge deviation, second dimension of edge deviation, first dimension of structure deviation, and second dimension of structure deviation, and is used to express the deviation state of the current detection mesh at three scales.

[0056] S3-1-4. Read the texture allowable deviation, edge allowable deviation, and structural allowable deviation corresponding to the same grid number from the standard appearance feature library, and arrange the texture allowable deviation, edge allowable deviation, and structural allowable deviation into an allowable deviation vector; The allowable deviations for texture, edge, and structure can be generated from the standard feature statistics of qualified workpiece samples under the same grid number. Specifically, for multiple qualified workpiece samples of the same specification, standard detail texture features, standard edge morphology features, and standard region structural features under the same grid number are extracted, and the standard deviation of each feature in each dimension is calculated. A preset multiple of the standard deviation of each dimension (such as three times the standard deviation) is used as the allowable deviation value for the corresponding dimension to ensure that feature changes within the normal process fluctuation range are not misjudged as defects. The allowable deviation vector and the feature deviation vector adopt the same dimensional order and number of dimensions, that is, arranged in the order of texture allowable deviation, first dimension of edge allowable deviation, second dimension of edge allowable deviation, first dimension of structural allowable deviation, and second dimension of structural allowable deviation.

[0057] S3-1-5. Divide the deviation of each dimension in the feature deviation vector by the allowable deviation of the same dimension in the allowable deviation vector to generate a normalized deviation vector; wherein, the normalized deviation vector includes normalized texture deviation, normalized edge deviation and normalized structure deviation. Specifically, the feature deviation vector and the allowable deviation vector have the same dimensional order and number of dimensions. Dividing each dimension's deviation in the feature deviation vector by the corresponding dimension's allowable deviation in the allowable deviation vector yields the normalized deviation value for each dimension. Organized in the order of texture, edge, and structure, these form normalized texture deviation, normalized edge deviation, and normalized structure deviation, respectively. This normalization process transforms the texture feature deviation, edge feature deviation, and structural feature deviation to a relative deviation scale, reducing the impact of different feature dimensions and numerical ranges on the fusion process.

[0058] S3-1-6. Extract texture response values, edge response values, and structural response values ​​from the detailed texture features, edge morphology features, and regional structure features of the current detection mesh, and arrange the texture response values, edge response values, and structural response values ​​into a scale response vector; Specifically, the texture response value, edge response value, and structure response value represent the degree of response of the current detection grid at the texture, edge, and structure scales, respectively. To ensure complete consistency with the feature extraction in S3-1-1 and without requiring additional computation, the texture response value can be directly obtained from the detailed texture features of the current detection grid; that is, the detailed texture features themselves (grayscale standard deviation) are the texture response value. The edge response value can be obtained from the edge morphology features of the current detection grid, taking the proportion of edge pixels in the edge morphology features as the edge response value. The structure response value can be obtained from the regional structure features of the current detection grid, taking the structural difference in the regional structure features as the structure response value. The three are arranged in the order of texture, edge, and structure to form the scale response vector.

[0059] S3-1-7. Weight the scale response vector to construct a fusion weight vector; wherein, the fusion weight vector includes texture fusion weight, edge fusion weight, and structure fusion weight; The steps for constructing the fusion weight vector include: B1. Add the texture response value, edge response value, and structure response value in the scale response vector to generate the total response value; B2. Divide the texture response value, edge response value, and structure response value by the total response value to generate texture fusion weight, edge fusion weight, and structure fusion weight, respectively. B3. Arrange the texture blending weights, edge blending weights, and structure blending weights into a blending weight vector.

[0060] Specifically, the total response represents the overall response intensity of the current detection grid across the three scales. Dividing each response value by the total response yields the relative proportion of each scale within the current detection grid; the more pronounced the texture response, the higher the texture fusion weight; the more pronounced the edge response, the higher the edge fusion weight; and the more pronounced the structural response, the higher the structural fusion weight. If the total response is 0, the texture fusion weight, edge fusion weight, and structural fusion weight are all set to 1 / 3 to avoid division by zero.

[0061] S3-1-8. Perform a dot product between the normalized bias vector and the fusion weight vector to calculate the multi-scale defect bias of the current detection grid.

[0062] Specifically, the normalized bias vector and the fusion weight vector have the same dimensional order, both consisting of three dimensions: texture, edge, and structure. The edge and structure dimensions are not further subdivided; instead, the normalized edge bias is multiplied by the edge fusion weight, and the normalized structure bias is multiplied by the structure fusion weight, respectively. Multiplying these two vectors by their respective fusion weights allows the normalized biases of the texture, edge, and structure dimensions to participate in the calculation. The dimensional biases in the normalized bias vector have had their dimensions eliminated, while the weights in the fusion weight vector reflect the proportion of the current detection mesh's response at each scale. The result of the fusion weight vector is the weighted comprehensive bias value. The resulting multi-scale defect bias is a summative bias formed under a unified relative scale, capable of simultaneously characterizing the degree of defect bias in the current detection mesh's local texture, edge morphology, and regional structure.

[0063] To facilitate a more intuitive understanding of the above calculation process, the example of the metal fixing plate of the new energy vehicle battery pack will be used for illustration. Taking a current detection grid among the aforementioned 80,000 detection grids as an example, assume that the detailed texture features (grayscale standard deviation) obtained by this grid after S3-1-1 calculation are 25.6, edge morphology features (edge ​​pixel ratio of 0.32, average gradient magnitude of 18.4), and region structure features (grayscale variance of 655.4, structure difference of 12.8). After feature distance calculation by S3-1-2, the texture feature deviation is 30.2, the two dimensions of the edge feature deviation are 0.18 and 15.6, and the two dimensions of the structure feature deviation are 180.5 and 9.6, thus forming a five-dimensional feature deviation vector [30.2, 0.18, 15.6, 180.5, 9.6]. Assuming the allowable deviation vector corresponding to the grid number read from the standard appearance feature library is [25.0, 0.10, 12.0, 150.0, 8.0], then after S3-1-5 normalization, a five-dimensional normalized deviation vector [1.21, 1.80, 1.30, 1.20, 1.20] is obtained. After organizing by texture, edge, and structure, the normalized texture deviation is 1.21, the normalized edge deviation is [1.80, 1.30], and the normalized structure deviation is [1.20, 1.20]. Meanwhile, the texture response value (detail texture feature) of the mesh is 25.6, the edge response value (edge ​​pixel ratio) is 0.32, and the structure response value (structure difference) is 12.8. The sum of the three is the total response value of 38.8. After calculation by B2, the texture fusion weight is 25.6 / 38.8≈0.66, the edge fusion weight is 0.32 / 38.8≈0.008, and the structure fusion weight is 12.8 / 38.8≈0.33. Finally, the normalized bias vector [1.21, 1.80, 1.30, 1.20, 1.20] is multiplied by the fusion weight vector [0.66, 0.008, 0.008, 0.33, 0.33] to obtain the multi-scale defect bias = 1.21×0.66 + 1.80×0.008 + 1.30×0.008 + 1.20×0.33 + 1.20×0.33 ≈ 0.80 + 0.014 + 0.010 + 0.396 + 0.396 = 1.616. This bias value is the weighted comprehensive bias of the current detection mesh at the texture, edge, and structure scales.

[0064] In this embodiment, step S3-4 includes: S3-4-1. Read the grid boundary coordinate sets inherited by each of the P1 candidate defect grids; S3-4-2. Extract the minimum horizontal coordinate, maximum horizontal coordinate, minimum vertical coordinate, and maximum vertical coordinate from the grid boundary coordinate set of each candidate defect grid; S3-4-3. If the maximum horizontal coordinate of one of the two candidate defect meshes is equal to the minimum horizontal coordinate of the other candidate defect mesh, and their vertical coordinate intervals intersect (including complete overlap and partial overlap), then the two candidate defect meshes are identified as horizontally adjacent candidate defect meshes. Specifically, lateral adjacency indicates that two candidate defect meshes share an edge or are in contact in the left-right direction. By checking whether the maximum and minimum lateral coordinates are equal, it can be determined whether two candidate defect meshes are in contact in the lateral direction; by checking whether the vertical coordinate intervals overlap, cases where they only meet at corner points but do not constitute a lateral edge can be excluded.

[0065] S3-4-4 If the maximum vertical coordinate of one of the two candidate defect meshes is equal to the minimum vertical coordinate of the other candidate defect mesh, and their horizontal coordinate intervals intersect (including complete overlap and partial overlap), then the two candidate defect meshes are identified as vertically adjacent candidate defect meshes. Specifically, vertical adjacency indicates that two candidate defect meshes share an edge or are in contact in the vertical direction. By checking whether the maximum and minimum vertical coordinates are equal, it can be determined whether two candidate defect meshes are in contact in the vertical direction; by checking whether the horizontal coordinate intervals overlap, cases where they only meet at corner points but do not constitute a vertically shared edge can be excluded.

[0066] S3-4-5. Traverse P1 candidate defect meshes and construct a set of adjacency relationships between candidate defect meshes based on the mesh numbers of the candidate defect meshes that are identified as horizontally or vertically adjacent.

[0067] Specifically, the adjacency set consists of multiple grid connection relationships, each recording the positional connection status between two candidate defect grids. Each grid connection relationship includes at least the grid number of the first candidate defect grid, the grid number of the second candidate defect grid, and the adjacent direction; the adjacent direction includes lateral adjacency or vertical adjacency. If two candidate defect grids are identified as laterally adjacent, their grid numbers and a lateral adjacency marker are written into the adjacency set; if two candidate defect grids are identified as vertically adjacent, their grid numbers and a vertical adjacency marker are written into the adjacency set. Thus, the adjacency set can clearly indicate which candidate defect grids are connected to each other and serves as the basis for dividing the same connected grid group.

[0068] In this embodiment, step S4 includes: S4-1. Based on the set of adjacency relationships between candidate defect meshes, candidate defect meshes with direct or indirect adjacency relationships are grouped into the same connected mesh group. Indirect adjacency refers to the connectivity formed through one or more intermediate candidate defect networks (the length of the transmission chain is unlimited). S4-2. Merge the grid boundary coordinate sets of each candidate defect grid in the same connected grid group to generate the region boundary coordinate set; S4-3. Determine the image region corresponding to the region boundary coordinate set as the initial defect region; S4-4. Count the number of candidate defect meshes in the initial defect region and calculate the average multi-scale defect deviation of the candidate defect meshes in the initial defect region; Specifically, the average multi-scale defect deviation is obtained by summing the multi-scale defect deviations of each candidate defect mesh within the initial defect region and then dividing by the number of candidate defect meshes within that initial defect region. The average multi-scale defect deviation is used to characterize the overall deviation intensity of the initial defect region.

[0069] S4-5. If the number of candidate defect meshes in the initial defect region is less than the preset number of meshes, and the average multi-scale defect deviation is less than the preset region retention deviation, then the initial defect region is removed. The preset number of grids can be determined based on the physical size of a single detection grid and the typical size of an isolated interference region, ranging from 2 to 5, preferably 3. This means that a connected region composed of 2 or fewer candidate defect grids is more likely to be classified as an isolated interference. The preset region retention deviation can be determined based on the statistical distribution of isolated interference regions in qualified workpiece samples, ranging from 0.3 to 0.6 times the maximum allowable value of multi-scale defect deviation, preferably 0.5 times. This means that regions with an average deviation below this threshold are more likely to be classified as isolated interference. Both conditions must be met simultaneously for a defect to be rejected, to prevent the accidental rejection of real defects with large areas but low deviations (such as large-area minor scratches or shallow indentations).

[0070] S4-6. Identify the initial defect areas that were not eliminated as valid defect areas.

[0071] For an initial defect region containing only a single candidate defect mesh, if its multi-scale defect deviation is greater than or equal to the preset region retention deviation, it is retained as a valid defect region; if its multi-scale defect deviation is less than the preset region retention deviation, it is eliminated according to the provisions of S4-5.

[0072] This embodiment utilizes the adjacency relationships between candidate defect meshes to group them into a single connected mesh group, generating an initial defect region from this connected mesh group. Furthermore, by analyzing the number of candidate defect meshes and the average multi-scale defect deviation within the initial defect region, it can be determined whether the initial defect region belongs to an isolated interference region. Initial defect regions with a small number of meshes and a low average multi-scale defect deviation are discarded, and the remaining initial defect regions are considered valid defect regions. This reduces the impact of a single weak-response mesh on the detection results, making the valid defect region closer to the continuous abnormal region on the workpiece surface.

[0073] In this embodiment, step S5 includes: S5-1. Merge the grid boundary coordinate sets of each candidate defect grid in the effective defect region to generate the effective region boundary coordinate set; S5-2. Delete the internal common-edge coordinates between adjacent candidate defect meshes from the effective region boundary coordinate set, and retain the outermost boundary coordinates of the effective defect region. Specifically, for any two adjacent candidate defect meshes, if their shared edge coordinates belong to the boundary coordinate sets of both meshes in the merged effective region boundary coordinate set, these coordinate points are identified as internal shared edge coordinates and deleted from the effective region boundary coordinate set. If a candidate defect mesh shares edges with multiple adjacent meshes, all shared edge coordinates are identified and deleted in the same manner.

[0074] S5-3. Arrange the outermost boundary coordinates in the order of their connection on the effective defect area contour to generate the perimeter coordinate set.

[0075] Specifically, the shared edges between adjacent candidate defect meshes belong to the internal boundary of the effective defect region, not its outer contour. After deleting the coordinates of the shared internal edges, the remaining outermost boundary coordinates represent the outer contour of the effective defect region. Starting from the top-left corner of the remaining outermost boundary coordinates, a boundary tracing algorithm (such as Moore's neighborhood tracing algorithm) is used to sequentially find the next adjacent outermost boundary coordinates in a clockwise direction until the starting point is reached, forming a set of perimeter coordinates arranged in the order of contour connections. If the effective defect region has multiple independent contours (such as annular holes), each contour is traced separately and stored sequentially according to its area.

[0076] This invention also provides an industrial workpiece visual defect detection system based on multi-scale feature fusion. This system implements the aforementioned industrial workpiece visual defect detection method based on multi-scale feature fusion, and details already described will not be repeated. The terms "module," "unit," and "subunit" used below refer to combinations of software and / or hardware that perform a predetermined function. Although the system described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0077] Figure 6 This is a structural block diagram of the industrial workpiece visual defect detection system based on multi-scale feature fusion of the present invention. The system includes: The workpiece image acquisition module is used to acquire a standard image of the industrial workpiece to be inspected; wherein, the standard image of the workpiece to be inspected is a workpiece image whose main body position, workpiece posture and image scale all meet the preset inspection benchmark. The detection grid division module is used to divide the standard image of the workpiece to be inspected into P detection grids; wherein, the detection grid is a square grid, and each detection grid is configured with a grid number and a grid boundary coordinate set; The candidate grid identification module is used to mark candidate defect grids in P detection grids according to the grid number configured for each detection grid, and to construct a set of adjacency relationships between candidate defect grids; The effective region generation module is used to connect and merge adjacent candidate defect meshes according to the adjacency relationship set to construct an effective defect region containing at least one candidate defect mesh; wherein, the candidate defect meshes in the effective defect region inherit the mesh number and mesh boundary coordinate set of the corresponding detection mesh; The perimeter coordinate extraction module is used to extract the perimeter coordinate set of the effective defect region based on the grid boundary coordinate set inherited by each candidate defect grid in the effective defect region. The defect record pairing module is used to perform shape recognition, center positioning, and area calculation on the perimeter coordinate set, determine the defect shape label, defect center coordinates, and defect area of ​​the effective defect area, and pair the defect shape label, defect center coordinates, and defect area into a three-dimensional defect record for the industrial workpiece to be inspected.

[0078] In the above system, the workpiece image acquisition module acquires a standard image of the workpiece to be inspected, the detection grid division module divides the standard image of the workpiece to be inspected into P detection grids, the candidate grid identification module constructs a set of adjacency relationships between candidate defect grids, the effective region generation module determines the effective defect region, the perimeter coordinate extraction module extracts the perimeter coordinate set of the effective defect region, and the defect record pairing module pairs the defect shape label, defect center coordinates, and defect area into a three-element defect record of the industrial workpiece to be inspected, reducing the situation where the same continuous defect is split into multiple scattered results and improving the consistency between the defect region record and the actual surface defect morphology of the workpiece.

[0079] To verify the detection effect of this embodiment on continuous defects on the surface of industrial workpieces, 120 images of industrial workpieces of the same specifications were selected as test samples, including appearance defects such as scratches, cracks, stains, and edge defects. The detection method that directly outputs small abnormal blocks was used as a comparison method, while the method of determining the effective defect area based on the adjacency relationship of candidate defect grids and outputting a ternary defect record in this embodiment was used as the basis for this embodiment. The data is shown in Table 1 below: Table 1

[0080] Specifically, the average number of defect region splits is used to indicate the degree to which the same actual defect is split into multiple detection results; the number of isolated false alarms is used to indicate the number of false alarms caused by lighting fluctuations, texture interference, or a single weak response patch; the average error of defect center coordinates is used to indicate the average distance between the center coordinates of the detection result and the center coordinates of the manually labeled result; the average error rate of defect area is used to indicate the degree of deviation between the detected area and the manually labeled area; and the accuracy rate of defect shape labels is used to indicate the correct classification rate of shape labels such as scratches, cracks, stains, and edge defects.

[0081] As can be seen from the above data, the detection method of directly outputting small abnormal blocks easily breaks continuous defects into multiple scattered results and retains some isolated false alarms. This embodiment, however, uses the adjacency relationship set between candidate defect grids to group candidate defect grids belonging to the same continuous abnormal region into the same connected grid group, and further determines the effective defect region, significantly reducing the situation where the same defect is split and output. Simultaneously, this invention generates defect shape labels, defect center coordinates, and defect area based on the perimeter coordinate set of the effective defect region, enabling the detection results to be transformed from single grid labels into region-level defect records, thereby improving the completeness of defect localization and defect representation.

[0082] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A method for detecting visual defects in industrial workpieces based on multi-scale feature fusion, characterized in that, include: S1. Obtain the standard image of the industrial workpiece to be inspected; wherein, the standard image of the workpiece to be inspected is a workpiece image whose main body position, workpiece posture and image scale all meet the preset inspection benchmark. S2. Divide the standard image of the workpiece to be inspected into P detection grids; wherein, the detection grid is a square grid, and each detection grid is configured with a grid number and a grid boundary coordinate set; S3. Based on the grid number configured for each detection grid, candidate defect grids are marked in the P detection grids, and an adjacency relationship set between candidate defect grids is constructed; wherein, the candidate defect grid is the detection grid obtained by marking in the P detection grids, and the adjacency relationship set represents the grid numbers of adjacent candidate defect grids and their connection relationship. S4. Based on the adjacency relationship set, connect and merge adjacent candidate defect meshes to construct an effective defect region containing at least one candidate defect mesh; wherein, the candidate defect meshes in the effective defect region inherit the mesh number and mesh boundary coordinate set of the corresponding detection mesh; S5. Based on the grid boundary coordinate set inherited by each candidate defect grid in the effective defect region, extract the perimeter coordinate set of the effective defect region; S6. Perform shape recognition, center positioning, and area calculation on the perimeter coordinate set to determine the defect shape label, defect center coordinates, and defect area of ​​the effective defect area, and pair the defect shape label, defect center coordinates, and defect area to form a ternary defect record for the industrial workpiece to be inspected.

2. The method for detecting visual defects in industrial workpieces based on multi-scale feature fusion according to claim 1, characterized in that, Based on the grid number configured for each detection grid, candidate defect grids are marked in the P detection grids, and a set of adjacency relationships between candidate defect grids is constructed, including: S3-1. Based on the grid number, select one of the P detection grids as the current detection grid, and calculate the multi-scale defect deviation of the current detection grid; wherein, the multi-scale defect deviation is used to characterize the degree of appearance deviation of the current detection grid in terms of detail texture, edge morphology and regional structure; S3-2. Compare the multi-scale defect deviation of the current detection grid with the preset defect deviation threshold; If the multi-scale defect deviation is greater than the preset defect deviation threshold, the current detection grid is marked as a candidate defect grid. S3-3. Traverse the P detection grids and repeatedly perform grid marking until the marking of the P detection grids is completed, resulting in P1 candidate defect grids; where each candidate defect grid inherits the grid number and grid boundary coordinate set of the corresponding detection grid; S3-4. Based on the grid boundary coordinate set inherited from P1 candidate defect grids, construct the set of adjacency relationships between candidate defect grids.

3. The method for detecting visual defects in industrial workpieces based on multi-scale feature fusion according to claim 2, characterized in that, Calculate the multi-scale defect bias of the current detection grid, including: S3-1-1, Obtain the detailed texture features, edge morphology features, and region structure features of the current detection mesh; S3-1-2. Calculate the feature distance between the detailed texture features, edge morphology features, and region structure features of the current detected mesh and the standard detailed texture features, standard edge morphology features, and standard region structure features corresponding to the same mesh number in the pre-built standard appearance feature library, and generate texture feature deviation, edge feature deviation, and structure feature deviation. S3-1-3. Arrange the texture feature deviation, edge feature deviation, and structural feature deviation into a feature deviation vector; S3-1-4. Read the texture allowable deviation, edge allowable deviation, and structural allowable deviation corresponding to the same grid number from the standard appearance feature library, and arrange the texture allowable deviation, edge allowable deviation, and structural allowable deviation into an allowable deviation vector; S3-1-5. Divide the deviation of each dimension in the feature deviation vector by the allowable deviation of the same dimension in the allowable deviation vector to generate a normalized deviation vector; wherein, the normalized deviation vector includes normalized texture deviation, normalized edge deviation and normalized structure deviation. S3-1-6. Extract texture response values, edge response values, and structural response values ​​from the detailed texture features, edge morphology features, and regional structure features of the current detection mesh, and arrange the texture response values, edge response values, and structural response values ​​into a scale response vector; S3-1-7. Weight the scale response vector to construct a fusion weight vector; wherein, the fusion weight vector includes texture fusion weight, edge fusion weight, and structure fusion weight; S3-1-8. Perform a dot product between the normalized bias vector and the fusion weight vector to calculate the multi-scale defect bias of the current detection grid.

4. The method for detecting visual defects in industrial workpieces based on multi-scale feature fusion according to claim 3, characterized in that, The feature distance calculation includes: A1. Perform a one-dimensional difference calculation between the target feature of the current detection grid and the standard target feature corresponding to the same grid number in the standard appearance feature library to obtain the one-dimensional feature difference; wherein, the target feature is a detailed texture feature, edge morphology feature or region structure feature; A2. Take the absolute value of the feature difference in each dimension, and sum the absolute differences of each dimension according to the preset dimension weights to generate the weighted magnitude difference of the target feature. A3. Calculate the target feature deviation based on the weighted amplitude difference and the directional consistency between the target feature and the standard target feature; A4. Using the detailed texture features, edge morphology features, and region structure features as target features, repeat A1-A3 to generate texture feature deviation, edge feature deviation, and structure feature deviation respectively.

5. The method for detecting visual defects in industrial workpieces based on multi-scale feature fusion according to claim 3, characterized in that, The construction of the fusion weight vector includes: B1. Add the texture response value, edge response value, and structure response value in the scale response vector to generate the total response value; B2. Divide the texture response value, edge response value, and structure response value by the total response value to generate texture fusion weight, edge fusion weight, and structure fusion weight, respectively. B3. Arrange the texture blending weights, edge blending weights, and structure blending weights into a blending weight vector.

6. The method for detecting visual defects in industrial workpieces based on multi-scale feature fusion according to claim 2, characterized in that, Based on the grid boundary coordinate set inherited from P1 candidate defect grids, a set of adjacency relationships between candidate defect grids is constructed, including: S3-4-1. Read the grid boundary coordinate sets inherited by each of the P1 candidate defect grids; S3-4-2. Extract the minimum horizontal coordinate, maximum horizontal coordinate, minimum vertical coordinate, and maximum vertical coordinate from the grid boundary coordinate set of each candidate defect grid; S3-4-3. If the maximum horizontal coordinate of one of the two candidate defect meshes is equal to the minimum horizontal coordinate of the other candidate defect mesh, and their vertical coordinate intervals intersect, then the two candidate defect meshes are identified as horizontally adjacent candidate defect meshes. S3-4-4 If the maximum vertical coordinate of one of the two candidate defect meshes is equal to the minimum vertical coordinate of the other candidate defect mesh, and their horizontal coordinate intervals intersect, then the two candidate defect meshes are identified as vertically adjacent candidate defect meshes. S3-4-5. Traverse P1 candidate defect meshes and construct a set of adjacency relationships between candidate defect meshes based on the mesh numbers of the candidate defect meshes that are identified as horizontally or vertically adjacent.

7. The method for detecting visual defects in industrial workpieces based on multi-scale feature fusion according to claim 6, characterized in that, Based on the adjacency set, adjacent candidate defect meshes are connected and merged to construct an effective defect region containing at least one candidate defect mesh, including: S4-1. Based on the set of adjacency relationships between candidate defect meshes, candidate defect meshes with direct or indirect adjacency relationships are grouped into the same connected mesh group. S4-2. Merge the grid boundary coordinate sets of each candidate defect grid in the same connected grid group to generate the region boundary coordinate set; S4-3. Determine the image region corresponding to the region boundary coordinate set as the initial defect region; S4-4. Count the number of candidate defect meshes in the initial defect region and calculate the average multi-scale defect deviation of the candidate defect meshes in the initial defect region; S4-5. If the number of candidate defect meshes in the initial defect region is less than the preset number of meshes, and the average multi-scale defect deviation is less than the preset region retention deviation, then the initial defect region is removed. S4-6. Identify the initial defect areas that were not eliminated as valid defect areas.

8. The method for detecting visual defects in industrial workpieces based on multi-scale feature fusion according to claim 7, characterized in that, Extract the boundary coordinate set of the effective defect region, including: S5-1. Merge the grid boundary coordinate sets of each candidate defect grid in the effective defect region to generate the effective region boundary coordinate set; S5-2. Delete the internal common-edge coordinates between adjacent candidate defect meshes from the effective region boundary coordinate set, and retain the outermost boundary coordinates of the effective defect region. S5-3. Arrange the outermost boundary coordinates in the order of their connection on the effective defect area contour to generate the perimeter coordinate set.

9. An industrial workpiece visual defect detection system based on multi-scale feature fusion, used to execute the industrial workpiece visual defect detection method based on multi-scale feature fusion as described in any one of claims 1 to 8, characterized in that, include: The workpiece image acquisition module is used to acquire a standard image of the industrial workpiece to be inspected; wherein, the standard image of the workpiece to be inspected is a workpiece image whose main body position, workpiece posture and image scale all meet the preset inspection benchmark. The detection grid division module is used to divide the standard image of the workpiece to be inspected into P detection grids; wherein, the detection grid is a square grid, and each detection grid is configured with a grid number and a grid boundary coordinate set; The candidate grid identification module is used to mark candidate defect grids in P detection grids according to the grid number configured for each detection grid, and to construct a set of adjacency relationships between candidate defect grids; The effective region generation module is used to connect and merge adjacent candidate defect meshes according to the adjacency relationship set to construct an effective defect region containing at least one candidate defect mesh; wherein, the candidate defect meshes in the effective defect region inherit the mesh number and mesh boundary coordinate set of the corresponding detection mesh; The perimeter coordinate extraction module is used to extract the perimeter coordinate set of the effective defect region based on the grid boundary coordinate set inherited by each candidate defect grid in the effective defect region. The defect record pairing module is used to perform shape recognition, center positioning, and area calculation on the perimeter coordinate set, determine the defect shape label, defect center coordinates, and defect area of ​​the effective defect area, and pair the defect shape label, defect center coordinates, and defect area into a three-dimensional defect record for the industrial workpiece to be inspected.