Defect detection method based on double-threshold template

Through the defect detection method based on the dual-threshold template, the problem that traditional template matching methods are susceptible to environmental interference is solved, and more efficient and accurate defect detection is achieved.

CN120125522APending Publication Date: 2025-06-10GUILIN MEASURING & CUTTING TOOLS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510184115.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-19
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

Traditional template matching methods are susceptible to environmental factors, resulting in high error detection rates and inability to correctly locate and align images.

Method used

The defect detection method based on the dual threshold template is adopted, and multiple defect-free images are collected through high-resolution industrial cameras to generate templates, and geometric position segmentation and contrast detection are performed based on the dual threshold templates, eliminating the image alignment step and improving efficiency.

Benefits of technology

It effectively reduces the impact of environmental factors on defect detection, reduces the false detection rate, and improves the robustness and accuracy of defect detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120125522A_ABST
    Figure CN120125522A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image processing, in particular to a defect detection method based on a double-threshold template, which comprises the following steps of: acquiring a plurality of defect-free images through a high-resolution industrial camera to generate a template; segmenting the to-be-detected image through the geometric position based on the dual-threshold template; according to the method, accurate edge angular points are obtained through circumscribed rectangles and contour points, so that the images are directly intercepted, the step of image alignment can be omitted, efficiency is effectively improved, noise interference is reduced, multiple images are collected to generate the double-threshold template to relieve interference of environmental factors, and the defect detection accuracy is improved. According to the method, the detection image is extracted through image geometric positioning, compared with a traditional defect detection method based on template matching, the step of template matching is omitted, the efficiency of the method is greatly improved, the template is generated through multiple images, the influence of environmental factors such as illumination and vibration on defect detection is effectively reduced, and the detection accuracy is improved. The false detection rate is reduced, and the robustness of defect detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular to a defect detection method based on a dual-threshold template. Background Art

[0002] The traditional template matching method is to collect a single defect-free image as a template. Through rough positioning and the correlation coefficient matching method, it is matched with the image to be detected. Finally, by subtracting the template image and the image to be detected pixel by pixel, a difference map is generated to judge defects.

[0003] However, the traditional template matching method is easily interfered by environmental factors such as light, vibration, and dust, resulting in incorrect image positioning and alignment, and prone to a large number of false detections. Summary of the Invention

[0004] The purpose of the present invention is to provide a defect detection method based on a dual-threshold template, aiming to solve the problem that the traditional template matching method is easily interfered by environmental factors and has errors.

[0005] To achieve the above purpose, the present invention provides a defect detection method based on a dual-threshold template, including the following steps:

[0006] Collect multiple defect-free images through a high-resolution industrial camera to generate a template;

[0007] Segment the image to be detected based on the geometric position of the dual-threshold template;

[0008] Compare the image to be detected with the dual-threshold template for defect detection.

[0009] Among them, the specific method for collecting multiple defect-free images through a high-resolution industrial camera to generate a template:

[0010] Collect images of defect-free samples through a high-resolution industrial camera to obtain multiple defect-free images;

[0011] Preprocess the multiple defect-free images to reduce noise and obtain multiple processed images;

[0012] Calculate the maximum and minimum values of each pixel position and each channel of the multiple processed images, construct two template images, and generate a dual-threshold template.

[0013] Among them, the number of images of defect-free samples collected by the high-resolution industrial camera is 5-15.

[0014] Among them, the specific method for segmenting the image to be detected based on the geometric position of the dual-threshold template:

[0015] Calculate the Euclidean distance from each contour point to the corner point based on the double-threshold template, and select the contour point with the closest distance as the new corner point;

[0016] Calculate the distance of the new corner point to obtain the width and height of the target image;

[0017] Define the coordinates of the new corner points before and after transformation, and then generate the image to be detected through perspective transformation.

[0018] Among them, the specific method of comparing the image to be detected with the double-threshold template for defect detection:

[0019] Compare the gray value of each pixel of the image to be detected with the double-threshold template with the maximum and minimum thresholds to detect the possible defect area;

[0020] Then binarize the image to be detected and find the contours, and merge the contours with relatively close distances;

[0021] Calculate the area of the defect area and calculate the average contrast between the image to be detected and the double-threshold template image.

[0022] The defect detection method based on the double-threshold template of the present invention generates a template by collecting multiple defect-free images through a high-resolution industrial camera; divides the image to be detected based on the geometric position of the double-threshold template; compares the image to be detected with the double-threshold template for defect detection. This method can directly intercept the image by obtaining accurate edge corner points through the circumscribed rectangle and contour points, omitting the image alignment step, effectively improving the efficiency and reducing noise interference. Collecting multiple images to generate a double-threshold template can alleviate the interference of environmental factors. This method directly performs image geometric positioning to extract the detected image. Compared with the traditional defect detection method based on template matching, it omits the template matching step, greatly improving the efficiency of the method. Generating a template through multiple images effectively reduces the influence of environmental factors such as light and vibration on defect detection, reduces the false detection rate, improves the robustness of defect detection, and solves the problem that the traditional template matching method is easily interfered by environmental factors and has errors. Description of the Drawings

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0024] Figure 1 It is a schematic diagram of establishing a double-threshold template.

[0025] Figure 2 It is a schematic diagram of geometrically locating and segmenting the target image.

[0026] Figure 3 It is a schematic diagram of detecting defects based on a dual-threshold template.

[0027] Figure 4 It is a flowchart of the defect detection method based on a dual-threshold template provided by the present invention.

[0028] Figure 5 It is a flowchart of the specific method for generating a template by collecting multiple defect-free images through a high-resolution industrial camera.

[0029] Figure 6 It is a flowchart of the specific method for segmenting the image to be detected by geometric position based on the dual-threshold template.

[0030] Figure 7 It is a flowchart of the specific method for comparing the image to be detected with the dual-threshold template for defect detection. Detailed implementation manners

[0031] The embodiments of the present invention will be described in detail below. The examples of the embodiments are shown in the drawings, where the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the drawings are exemplary and are intended to explain the present invention and should not be construed as limiting the present invention.

[0032] Please refer to Figures 1 to 7 , the present invention provides a defect detection method based on a dual-threshold template, including the following steps:

[0033] S1 Generate a template by collecting multiple defect-free images through a high-resolution industrial camera;

[0034] In the embodiment of the present invention, 5 - 15 defect-free sample images are collected through a high-resolution industrial camera. Noise is reduced through operations such as filtering and morphology. Subsequently, the maximum and minimum values of each pixel position and each channel are calculated from the multiple collected images, thereby constructing two template images: the maximum-value template and the minimum-value template, to generate a dual-threshold template.

[0035] Specifically, for the pixel (i, j) in the t-th image with a total of n images, define its blue, green, and red channel values as Bt(i, j), Gt(i, j), and Rt(i, j) respectively, then the maximum value is:

[0036]

[0037] Similarly for the minimum value, and finally calculate

[0038] Mh = [max b (i, j), max g (i, j), max r (i, j)]

[0039] M l = [min b (i, j), min g (i, j), min r (i, j)]

[0040] Thus, a high - threshold template Mh and a low - threshold template Ml are established. The establishment of the standard template is crucial for the subsequent defect detection method. Compared with a single template, the dual - threshold template can better adapt to the detection in the industrial environment and improve the detection accuracy.

[0041] Specific method:

[0042] S11 Collect images of defect - free samples through a high - resolution industrial camera to obtain multiple defect - free images;

[0043] S12 Pre - process the multiple defect - free images to reduce noise and obtain multiple processed images;

[0044] S13 Calculate the maximum and minimum values of each pixel position and each channel of the multiple processed images, construct two template images, and generate a dual - threshold template.

[0045] S2 Segment the image to be detected based on the dual - threshold template through geometric position;

[0046] In the embodiment of the present invention, the method of using an external rectangle is adopted to extract four corner points. To ensure the accuracy of extracting corner points, this step is optimized through contours. First, calculate the Euclidean distance from each contour point to the corner point, and then select the contour point with the closest distance as the new corner point. By calculating the corner - point distance, the width and height of the target image are obtained. Subsequently, define the corner - point coordinates before and after transformation. Then, through perspective transformation, generate the transformed image for subsequent defect detection.

[0047] Specifically, first, binarize the image and perform a morphological 'opening' operation to segment out multiple rectangular frames and sort them. Then, extract the upper - left TL and upper - right TR corner points of the first rectangular frame and the lower - left BL and lower - right BR corner points of the last rectangular frame and store them in the point set FPT.

[0048]

[0049] Since the accuracy required for pixel - level difference is very high, the contour corner points are used to further optimize the above - mentioned point set FPT. By traversing all contour points, the Euclidean distances from each point to the four vertices of the rectangle are calculated one by one, and the minimum distance and its corresponding point index are maintained. Finally, the contour points closest to each vertex are found, which are the final edge corner points.

[0050] The distance calculation for point p(x1, y1) and point q(x2, y2) is as follows:

[0051]

[0052] For the top - left vertex TL, find the point index (i, j) that satisfies the following conditions

[0053]

[0054] Similarly, the top - right vertex TR, bottom - left vertex BR, and bottom - right vertex BL are obtained.

[0055] The width of the target to be detected is obtained by calculating the Euclidean distance between the top - right vertex TR and the top - left vertex TL, and the length is obtained by calculating the Euclidean distance between the bottom - left vertex BR and the bottom - right vertex BL. Finally, a quadrilateral region defined by four points is mapped to a rectangular region using perspective transformation. The affine transformation matrix is calculated using the getPerspectiveTransform function in the open - source computer vision library OpenCv and the transformation operation is performed to obtain the target image to be detected from the large image.

[0056] Specific method:

[0057] S21 Calculate the Euclidean distance from each contour point to the corner point based on the double - threshold template, and select the contour point with the closest distance as the new corner point;

[0058] S22 Calculate the distance of the new corner points to obtain the width and height of the target image;

[0059] S23 Define the coordinates of the new corner points before and after transformation, and then generate the image to be detected through perspective transformation.

[0060] S3 Compare the image to be detected with the double - threshold template for defect detection.

[0061] In the embodiments of the present invention, by comparing the gray - scale value of each pixel with the maximum and minimum thresholds, possible defect regions are detected. Then it is binarized and contours are found, and contours that are relatively close to each other are merged. Finally, the area of the defect and the average contrast with the template image are calculated to achieve defect filtering and improve the accuracy of defect detection.

[0062] Specifically, the pixel gray values of the image to be detected are compared row by row with the corresponding gray values of the double-threshold template. For the pixels outside the range of the high gray threshold and the low gray threshold, their gray values are marked as 225 in the result image, which are the possible defect positions. For each pixel point T(i, j), it is compared with the corresponding point M(i, j) of the template.

[0063]

[0064] The pixel gray values of the image to be detected are compared row by row with the corresponding gray values of the double-threshold template. For the pixels outside the range of the high gray threshold and the low gray threshold, their gray values are marked as 225 in the result image, which are the possible defect positions. For each pixel point T(i, j), it is compared with the corresponding point M(i, j) of the template.

[0065]

[0066] Specific method:

[0067] S31 Compare the gray values of each pixel of the image to be detected and the double-threshold template with the maximum and minimum thresholds to detect the possible defect areas;

[0068] S32 Then binarize the image to be detected and find the contours, and merge the contours that are relatively close to each other;

[0069] S33 Calculate the area of the defect area and calculate the average contrast of the image to be detected and the double-threshold template image.

[0070] The above-disclosed is only the preferred embodiment of the defect detection method based on the double-threshold template of the present invention. Of course, the scope of the rights of the present invention cannot be limited thereby. Those of ordinary skill in the art can understand all or part of the processes of implementing the above embodiments, and the equivalent changes made according to the claims of the present invention still fall within the scope covered by the invention.

Claims

1. A defect detection method based on a dual threshold template, characterized in that: The following steps are involved: Generate templates by collecting multiple defect-free images with high-resolution industrial cameras; Segment the image to be detected by geometric position based on the dual threshold template; The image to be detected is compared with the dual threshold template to perform defect detection.

2. The defect detection method based on a dual threshold template according to claim 1, characterized in that; The specific method of generating a template by collecting multiple defect-free images with a high-resolution industrial camera is as follows: Capture images of defect-free samples using a high-resolution industrial camera to obtain multiple defect-free images; Preprocessing the plurality of defect-free images to reduce noise and obtain a plurality of processed images; The maximum and minimum values ​​of each pixel position and each channel of the multiple processed images are calculated, two template images are constructed, and a dual-threshold template is generated.

3. The defect detection method based on a dual threshold template as claimed in claim 1, characterized in that ; The number of images of defect-free samples captured by the high-resolution industrial camera is 5-15.

4. The defect detection method based on a dual threshold template according to claim 1, It is characterized by: The specific method of segmenting the image to be detected by geometric position based on the dual threshold template is: Calculate the Euclidean distance from each contour point to the corner point based on the dual threshold template, and select the contour point with the closest distance as the new corner point; Calculate the distance between the new corner points to obtain the width and height of the target image; The new corner point coordinates before and after the transformation are defined, and then the image to be detected is transformed and generated through perspective transformation.

5. The defect detection method based on a dual threshold template according to claim 1, characterized in that; The specific method of comparing the image to be detected with the dual threshold template for defect detection is: Compare the grayscale value of each pixel of the image to be detected and the dual-threshold template with the maximum and minimum thresholds to detect possible defect areas; Then, the image to be detected is binarized and contours are found, and contours that are close to each other are merged; The area of ​​the defect region is calculated, and the average contrast between the image to be detected and the dual-threshold template image is calculated.