Welding seam black spot defect detection method and device
By pre-processing and dynamic threshold detection of weld images, combined with multi-threading and grayscale difference judgment, the problem of weld black spot defect detection in complex background is solved, and efficient and accurate weld defect detection is achieved.
Patent Information
- Application Number
- CN202510128796.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-05
- Publication Date
- 2025-06-06
AI Technical Summary
Existing weld detection technology is difficult to effectively identify and detect weld black spot defects, especially in complex backgrounds, resulting in low detection efficiency and poor accuracy.
By preprocessing the collected weld images, including grayscale transformation and mean filtering, weld black spot defects are found, and dynamic threshold detection and multi-threading are used, combining area screening and absolute value judgment of the difference between average grayscale, weld black spot defects are identified and detected.
It improves the accuracy and efficiency of weld black spot defect detection, can more effectively suppress noise interference in complex backgrounds, and enhances the stability of detection.
Smart Images

Figure CN120107166A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of digital image processing, and specifically provides a method and a device for detecting black spot defects in a weld. Background Art
[0002] Welding is a vital process in the manufacturing industry, and its products are widely used in many fields such as construction, shipbuilding, aerospace, machinery manufacturing, metal smelting, petrochemicals, energy and transportation. Welding quality directly affects the performance, safety and service life of the product, so weld defect detection is an important link to ensure welding quality.
[0003] In traditional weld inspection, manpower is an indispensable factor. However, with the continuous increase in labor costs and the development of welding automation technology, traditional manual inspection methods have gradually exposed many limitations. First, manual inspection is labor-intensive and has low inspection efficiency; second, due to factors such as differences in inspection personnel's experience and eye fatigue, false inspections and missed inspections are prone to occur; finally, under the harsh conditions of high temperature, radiation, and small space at the welding site, manual inspection is extremely inconvenient.
[0004] With the rapid development of computer technology and image processing technology, digital image processing technology has been widely used in weld defect detection. This technology uses a high-precision camera to capture weld images, and analyzes and processes the images through image processing algorithms, thereby achieving automatic, fast and accurate detection of weld defects. Digital image processing technology can not only overcome the limitations of manual detection, but also improve detection efficiency and accuracy and reduce labor intensity.
[0005] Black spot defects are a common type of defect in the welding process. They are manifested as black spots or holes on the weld surface. These defects have a serious impact on the mechanical properties and service life of the weld. However, since weld images usually have low contrast, large background fluctuations, and high noise, the detection of black spot defects becomes particularly difficult.
[0006] Therefore, how to effectively identify black spot defects from complex backgrounds is an important research direction in the field of weld defect detection. Summary of the invention
[0007] The present invention aims at solving the above-mentioned deficiencies of the prior art and provides a method for detecting black spot defects in welds with strong practicability.
[0008] A further technical task of the present invention is to provide a weld black spot defect detection device that is reasonably designed, safe and applicable.
[0009] The technical solution adopted by the present invention to solve the technical problem is:
[0010] A method for detecting black spot defects in welds comprises the following steps:
[0011] S1, preprocessing the collected image, including image grayscale transformation and image mean filtering;
[0012] S2, find the middle area and find the bright area in the middle;
[0013] S3, find the middle weld area, accurately search the middle area, and find the middle weld area;
[0014] S4, perform algorithm processing on the image, use dynamic threshold to detect the dark part, and perform intersection operation on the defect area and the middle weld area;
[0015] S5, defect screening, preliminarily screen out a certain area by area, and then calculate the absolute value of the difference in the average grayscale of the area as the basis for judgment, and start multi-threaded accelerated calculation processing.
[0016] Furthermore, in step S1, it includes:
[0017] (1) Convert the image grayscale into a single-channel image;
[0018] (2) Image mean filtering to reduce image noise interference.
[0019] Furthermore, in step S2, it includes:
[0020] S2-1, the big law method is used to segment the image and obtain the threshold value;
[0021] S2-2, select a threshold value and binarize the image;
[0022] S2-3, filter the area, and filter the area that meets the requirements according to the area threshold;
[0023] S2-4, find the contour with the largest area, sort the regions, and obtain the contour of the region with the largest area;
[0024] S2-5. Obtain the mask area of the regular rectangle circumscribing the outline, perform minimum circumscribing rectangle transformation on the outline, and fill it to form the mask area.
[0025] Furthermore, in step S3, it includes:
[0026] S3-1, regional mask cropping image, adding mask operation to the image;
[0027] S3-2, image mean filtering, filtering the image to form background and foreground images;
[0028] S3-3, dynamic threshold detection, set two detection modes, Light and Dark, to obtain bright and dark areas;
[0029] S3-4, region union, merging the bright and dark regions into one region;
[0030] S3-5, erode the edge of the mask area, and erode the upper and lower areas of the mask area formed in S2 with a structure size of Size(3,500);
[0031] S3-6, find the intersection of the mask area and the bright and dark areas;
[0032] S3-7, region expansion, expansion operation is performed after the region intersection;
[0033] S3-8, area screening and filtering, eliminating smaller areas by area;
[0034] S3-9, region merging, multiple regions are merged into one connected domain;
[0035] S3-10, minimum bounding rectangle transformation, perform minimum bounding rectangle transformation on the merged area to form a mask area.
[0036] Further, in step S3-1, the region mask is cropped to the image, firstly the mask region is mapped to the image, and secondly, the threshold of the region outside the mask is set to 0;
[0037] In step S3-2, filter kernels with kernel sizes of Size(300,10) and Size(300,30) are used for image filtering, and the height and width of the filter kernel meet a certain ratio to prepare for dynamic threshold detection;
[0038] The image filtered by kernel Size(300,10) is used as the background, and the image filtered by kernel Size(300,30) is used as the foreground;
[0039] In step S3-3, dynamic threshold discrimination is performed on the background image and the foreground image to obtain the weld area, wherein the Light area and the Dark area need to be obtained separately.
[0040] Furthermore, in step S4, it includes:
[0041] S4-1, dynamic threshold detection, filter the images of size Size(10,8) and size Size(100,8) respectively, determine the foreground and background of the image respectively, set the detection parameter to Dark, and perform dynamic threshold detection on both;
[0042] S4-2, area intersection, the target dark area and the minimum circumscribed rectangular area in S3 are intersected.
[0043] Furthermore, in step S5, it includes:
[0044] S5-1. Screening by area, eliminating areas smaller than a certain area threshold;
[0045] S5-2, screening by the absolute value of the difference in average grayscale of the regions, performing morphological operations on each region to obtain the corresponding average grayscale difference;
[0046] S5-3. Enable multi-threaded acceleration processing, enable thread processing for each area separately, and perform parallel calculations.
[0047] A weld black spot defect detection device comprises: at least one memory and at least one processor;
[0048] The at least one memory is used to store a machine-readable program;
[0049] The at least one processor is used to call the machine-readable program to execute a weld black spot defect detection method.
[0050] Compared with the prior art, the weld black spot defect detection method and device of the present invention have the following outstanding beneficial effects:
[0051] The purpose of the present invention is to determine whether there are black spot defects in the weld area of aluminum-clad steel. Compared with other methods, the algorithm uses two-part dynamic threshold detection. The first part is used to determine the middle weld area, and the second part is used to detect the black spot area. The detection is more accurate and is judged by the absolute value of the difference in average grayscale, which effectively suppresses the area where the spots are not obvious and improves the stability of the algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0053] Attached Figure 1 It is a flow chart of a method for detecting black spot defects in welds;
[0054] Attached Figure 2 This is a rendering of a weld black spot defect detection method. DETAILED DESCRIPTION
[0055] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0056] A best embodiment is given below:
[0057] like Figure 1 As shown, a weld black spot defect detection method in this embodiment has the following steps:
[0058] S1, preprocessing the collected image, including image grayscale transformation and image mean filtering;
[0059] To obtain an image from the camera, the imaging must meet certain conditions, set the camera frame rate, exposure, acquisition mode, etc. Next:
[0060] (1) Image grayscale conversion: each frame of image acquired from the camera is converted into a single channel.
[0061] (2) Image mean filtering: Use a 3x3 filter kernel to perform mean filtering to reduce image noise.
[0062] S2, find the middle area and find the bright area in the middle;
[0063] include:
[0064] S2-1. Segment the image using the Otsu method. Calculate the image segmentation threshold, count the variance, and divide the image into background and foreground. The threshold with the largest variance is used as the segmentation threshold.
[0065] S2-2, threshold selection, binarize the image according to the segmentation threshold and select the foreground area.
[0066] S2-3, area screening, segment the foreground area into connected domains, call the connectedComponentsWithStats connected domain segmentation function internally, obtain the area value corresponding to each connected domain, judge the area value, set the area value to 255 for areas within the range, and set the area value to 0 for areas that do not meet the range.
[0067] S2-4. Find the contour with the largest area, obtain the contour of the filtered area, call the findContours function, calculate the area corresponding to the contour, and return the contour with the largest corresponding area.
[0068] S2-5. Get the mask area of the outline's circumscribed rectangle, perform circumscribed rectangle transformation on the outline, and call the boundingRect function; draw and fill the circumscribed rectangular area, and call the rectangle function.
[0069] S3, find the middle weld area, accurately search the middle area, and find the middle weld area;
[0070] include:
[0071] (1) Area mask cropping: crop the image according to the mask area and call the object copyTo(dst,mask) method with its own mask parameter.
[0072] (2) Image mean filtering: Use filter kernels with kernel sizes of Size(300,10) and Size(300,30) to perform image filtering and call the blur mean filter function.
[0073] (3) Dynamic threshold detection: the image filtered by kernel Size(300,10) is used as the background, and the image filtered by kernel Size(300,30) is used as the foreground. The two images are subjected to dynamic threshold discrimination, Value = datasrc[j] - datasrcMean[j], where datasrc is the foreground image and datasrcMean is the background image. The discrimination is performed by checking whether the pixel difference Value satisfies a certain offset.
[0074] (4) Region union: Union the light region and the dark region detected by dynamic threshold and call the overloaded operator “|” in Mat.
[0075] (5) Erosion of the mask area edges, upper and lower edge erosion operations, the erosion structure size is Size(3,500), and the erode function is called to shrink the upper and lower mask areas.
[0076] (6) Find the intersection of the mask area and the bright and dark areas. To perform the intersection operation, call the overloaded operator “&” in Mat.
[0077] (7) Region dilation, dilation morphological operation, the structure element size is Size(30,3), and the dilate function is called.
[0078] (8) Area screening and filtering: segment the expanded area into connected domains, filter out small areas, select large areas, call the connectedComponentsWithStats function, obtain the area value corresponding to each connected domain, judge the area value, set the area value to 255 for areas within the range, and set the area value to 0 for areas that do not meet the range.
[0079] (9) Region merging: Merge the regions that meet the requirements after area screening and call the findContours function to obtain the contour vectors of each region. <point>, merge them into a contour vector <point>.
[0080] (10) Minimum bounding rectangle transformation: perform minimum bounding rectangle transformation on the merged connected domain area and call the boundingRect function; fill the minimum bounding rectangle to form a mask area and call the rectangle function.
[0081] S4, perform algorithm processing on the image, use dynamic threshold to detect the dark part, and perform intersection operation on the defect area and the middle weld area;
[0082] include:
[0083] S4-1. Dynamic threshold detection. Use the image filtered by kernel Size(10,8) as the background and the image filtered by kernel Size(100,8) as the foreground. Set the detection target parameter to Dark, Value = datasrc[j] - datasrcMean[j]. Datasrc is the foreground image and datasrcMean is the background image. The difference in pixels is determined by the offset.
[0084] S4-2. Region intersection operation and set intersection operation can be performed by calling the overloaded operator "&" in Mat.
[0085] S5, defect screening, preliminarily screen out a certain area by area, and then calculate the absolute value of the difference in average grayscale of the area as the basis for judgment, and start multi-threaded accelerated calculation processing;
[0086] include:
[0087] S5-1. Through area screening, the defect area is segmented into connected domains, the findContours function is called to calculate the area corresponding to the contour, and the convexHull convexity transformation is performed. Then contourArea is executed to obtain the area. For the contours that meet the area threshold, drawContours is executed to fill and draw, and the filled and drawn area is pushed into vector <mat>middle.
[0088] S5-2. Filter by the difference of the average grayscale value of the region, call the dilate function, and perform a morphological dilation operation on the region; call the overloaded operator "-" in Mat to subtract the two regions to obtain the difference region; call the mean function to obtain the average grayscale value of the difference region; call the mean function again to obtain the average grayscale value of the unexpanded region; subtract the values obtained in the above two steps and calculate their absolute values; if the absolute value meets a certain threshold, it is determined to be a defect, and vice versa.
[0089] S5-3, start multi-threaded acceleration processing, and convert the result vector in (1) <mat>The middle area performs the processing of (2) algorithm and starts a separate thread to execute. The thread returns a task object and advances the task queue vector <std::future <result>>, concurrent execution is achieved; the for loop traverses the task queue, obtains the results of task execution one by one, and achieves task synchronization.
[0090] The above-mentioned specific implementations are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementations. Any technical solutions that conform to the above-mentioned specific implementations of the present invention and any appropriate changes or substitutions made by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.
[0091] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.< / result> < / mat> < / mat> < / point> < / point>
Claims
1. A method for detecting black spot defects in welds, characterized in that: The steps are as follows: S1, preprocessing the collected image, including image grayscale transformation and image mean filtering; S2, find the middle area and find the bright area in the middle; S3, find the middle weld area, accurately search the middle area, and find the middle weld area; S4, perform algorithm processing on the image, use dynamic threshold to detect the dark part, and perform intersection operation on the defect area and the middle weld area; S5, defect screening, preliminarily screen out a certain area by area, and then calculate the absolute value of the difference in average grayscale of the area as the basis for judgment, and start multi-threaded accelerated calculation processing.
2. A weld black spot defect detection method according to claim 1, characterized in that: In step S1, it includes: (1) Convert the image grayscale into a single-channel image; (2) Image mean filtering to reduce image noise interference.
3. A weld black spot defect detection method according to claim 2, characterized in that: In step S2, it includes: S2-1, the big law method is used to segment the image and obtain the threshold value; S2-2, select a threshold value and binarize the image; S2-3, filter the area, and filter the area that meets the requirements according to the area threshold; S2-4, find the contour with the largest area, sort the regions, and obtain the contour of the region with the largest area; S2-5. Obtain the mask area of the regular rectangle circumscribing the outline, perform minimum circumscribing rectangle transformation on the outline, and fill it to form the mask area.
4. A weld black spot defect detection method according to claim 3, characterized in that: In step S3, it includes: S3-1, regional mask cropping image, adding mask operation to the image; S3-2, image mean filtering, filtering the image to form background and foreground images; S3-3, dynamic threshold detection, set two detection modes, Light and Dark, to obtain bright and dark areas; S3-4, region union, merging the bright and dark regions into one region; S3-5, erode the edge of the mask area, and erode the upper and lower areas of the mask area formed in S2 with a structure size of Size(3,500); S3-6, find the intersection of the mask area and the bright and dark areas; S3-7, region expansion, expansion operation is performed after the region intersection; S3-8, area screening and filtering, eliminating smaller areas by area; S3-9, region merging, multiple regions are merged into one connected domain; S3-10, minimum bounding rectangle transformation, perform minimum bounding rectangle transformation on the merged area to form a mask area.
5. A weld black spot defect detection method according to claim 4, characterized in that: In step S3-1, the region mask is cropped to the image, firstly the mask region is mapped to the image, and secondly the threshold of the region outside the mask is set to 0; In step S3-2, filter kernels with kernel sizes of Size(300,10) and Size(300,30) are used for image filtering, and the height and width of the filter kernel meet a certain ratio to prepare for dynamic threshold detection; The image filtered by kernel Size(300,10) is used as the background, and the image filtered by kernel Size(300,30) is used as the foreground; In step S3-3, dynamic threshold discrimination is performed on the background image and the foreground image to obtain the weld area, wherein the Light area and the Dark area need to be obtained separately.
6. A weld black spot defect detection method according to claim 5, characterized in that: In step S4, it includes: S4-1, dynamic threshold detection, filter the images of size Size(10,8) and size Size(100,8) respectively, determine the foreground and background of the image respectively, set the detection parameter to Dark, and perform dynamic threshold detection on both; S4-2, area intersection, the target dark area and the minimum circumscribed rectangular area in S3 are intersected.
7. A weld black spot defect detection method according to claim 6, characterized in that: In step S5, it includes: S5-1. Screening by area, eliminating areas smaller than a certain area threshold; S5-2, screening by the absolute value of the difference in average grayscale of the regions, performing morphological operations on each region to obtain the corresponding average grayscale difference; S5-3. Enable multi-threaded acceleration processing, enable thread processing for each area separately, and perform parallel calculations.
8. A weld black spot defect detection device, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 7.