A method and system for generating a multi-type defect dataset with labels
By randomly generating defect outlines and superimposing fill pixels, multiple types of defect images and labels are generated, which solves the problem of difficulty in obtaining defect detection data sets, and realizes efficient generation and labeling of defect data sets.
Patent Information
- Application Number
- CN202211379147.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-04
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-11-04
AI Technical Summary
In the prior art, it is difficult to obtain defect detection data sets, and it is time-consuming to acquire defect samples. In addition, traditional data enhancement methods have strong limitations on defect data sets, making it difficult to meet the needs of deep learning.
By obtaining defect-free initial images, randomly generate defect profiles, including closed curved and elongated defect profiles, superimpose and fill pixels, generate multiple types of defect images, and directly generate corresponding labels.
Generating a variety of defect samples reduces the difficulty of obtaining data sets, saves manpower, improves work efficiency, and is suitable for different detection models.
Smart Images

Figure CN115546587B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of deep learning defect detection, and more specifically, to a method and system for generating a multi-type defect data set with labels. Background Art
[0002] Defect detection is a very important application in life and industry. Due to the variety of defects, it is difficult for traditional machine vision algorithms to model and transfer the complete defect features, and the reusability is not high, which will waste a large amount of human costs during detection; deep learning has achieved very good results in feature extraction and localization, but the acquisition of defect samples is difficult in various defect detections. At present, the data sets in the field of defect detection are extremely limited, such as tiles, fabrics, PCB boards, etc. The acquisition of such defect samples also requires a large amount of manpower and material resources, and the relatively small defect sample data sets are also difficult to meet the needs of a deep convolutional network for large training data;
[0003] The acquisition of defect data sets usually uses data augmentation (flipping, rotating, cropping, scaling, translating, jittering, affine transformation, etc.) methods to expand the data set on very limited samples; in semantic segmentation and object detection data sets, data augmentation methods can enrich the data set to a certain extent, but in defect data sets, due to the lack of fixed shapes and colors of defects and on fixed labels, the limitations of data augmentation methods in defect data sets are very strong; data augmentation can enrich the data to a certain extent, but the data it generates also retains some characteristics of the original data, with relatively large limitations;
[0004] The current prior art discloses a defect detection method, device, equipment and storage medium. The method in the prior art includes: obtaining a defect-free image and a target detection image; generating defects for the defect-free image according to a preset defect sample generation model to obtain simulated defect samples; performing defect detection on the target detection image according to the simulated defect samples to obtain a defect detection result; although the method in the prior art can increase the number of defect samples and use the increased number of defect samples to detect and identify the target detection image, the types of generated defect samples are single and the quantity is small, still unable to meet wide applications; in addition, the defect samples generated by the above method need to be manually labeled, which is time-consuming and laborious. Summary of the Invention
[0005] In order to overcome the above defects of the prior art in the acquisition of multi-type defect data sets, the present invention provides a method and system for generating a multi-type defect data set with labels, which can generate a variety of defect samples and directly generate corresponding labels, saving time and effort.
[0006] To solve the above technical problems, the technical solution of the present invention is as follows:
[0007] A method for generating a multi-type defect data set with labels, comprising the following steps:
[0008] S1: Obtain an initial defect-free image;
[0009] S2: Randomly generate defect contours and obtain defect contour images of different types;
[0010] S3: Superimpose the defect contour images of different types on the initial defect-free image to obtain an initial image with defect contours of different types;
[0011] S4: Fill the pixels inside the defect contour regions in the initial image with defect contours of different types to obtain defect images of different types;
[0012] S5: Generate labels corresponding to the defect images of different types, and save the defect images of different types and their corresponding labels as a multi-type defect data set with labels.
[0013] Preferably, in the step S2, the specific method for randomly generating defect contours and obtaining defect contour images of different types is:
[0014] The defect contours include closed curve-shaped defect contours, and the specific method for generating the closed curve-shaped defect contours is:
[0015] S2.1.1: Randomly generate a number of defect contour base points in the polar coordinate system and obtain the polar angles corresponding to each defect contour base point;
[0016] S2.1.2: Randomly generate corresponding polar radii for each defect contour base point;
[0017] S2.1.3: Convert the polar angles and corresponding polar radii of each contour base point in the polar coordinate system to the rectangular coordinate system to obtain the rectangular coordinates of each contour base point;
[0018] S2.1.4: According to the rectangular coordinates of each contour base point, perform curve fitting using a preset function to obtain a number of closed curve-shaped defect contour images.
[0019] Preferably, in the step S2.1.3, the method for converting the polar angles and corresponding polar radii of each contour base point in the polar coordinate system to the rectangular coordinate system to obtain the rectangular coordinates of each contour base point is:
[0020] Convert the polar angle α i and the polar radius R i of the i-th contour base point in the polar coordinate system to the rectangular coordinate system, and the conversion formula is specifically:
[0021] x i = Ri *cos(α i )
[0022] y i =R i *sin(α i )
[0023] where x i and y i are respectively the abscissa and ordinate of the rectangular coordinates of the i-th contour base point.
[0024] Preferably, in the step S2.1.4, the preset function is specifically the interp1d() interpolation function.
[0025] Preferably, in the step S2, the specific method for randomly generating a defect contour and obtaining defect contour images of different types is as follows:
[0026] The defect contour further includes an elongated defect contour, and the specific method for generating the elongated defect contour is as follows:
[0027] S2.2.1: In polar coordinates, randomly select two polar angles within the range of (0, π), and the difference in the angle values of the two polar angles is less than a preset angle threshold;
[0028] S2.2.2: Add any one of the two polar angles to a random polar angle, and keep the other polar angle unchanged to obtain a first polar angle and a second polar angle;
[0029] S2.2.3: Randomly generate corresponding elongated defect contour polar radii for the first polar angle and the second polar angle respectively;
[0030] S2.2.4: Obtain the elongated defect contour according to the first polar angle, the second polar angle and their corresponding elongated defect contour polar radii;
[0031] S2.2.5: Repeat steps S2.2.1 - 2.2.4 to obtain a plurality of elongated defect contours.
[0032] Preferably, in the step S3, the method for superimposing defect contour images of different types on the defect-free initial image to obtain an initial image with different types of defect contours is as follows:
[0033] S3.1: Convert the defect-free initial image into a grayscale image and obtain the length and width data of the initial image;
[0034] S3.2: Detect the contour of the grayscale image using the first detection function to obtain the contour point data of the grayscale image;
[0035] S3.3: Detect the minimum rectangular box in the contour point data of the grayscale image using the second detection function to obtain the upper left corner coordinates of the rectangular box and the length and width data of the rectangular box;
[0036] S3.4: Add random values to the upper-left corner coordinates of the rectangular box to obtain superimposed coordinates, denoted as (x + x add , y + y add ), where x add and y add are the random values of the abscissa and ordinate of the upper-left corner of the rectangular box respectively, and the magnitude of the random value is less than the magnitude of the length and width data of the initial image; Coincide a certain point of the defect contour images of different types with the superimposed coordinates to obtain the initial image with different types of defect contours.
[0037] Preferably, in the step S3, the first detection function is the cv2.findContours() function, and the second detection function is the cv2.boundingRect() function.
[0038] Preferably, in the step S4, perform pixel filling on the inside of the defect contour area in the initial image with different types of defect contours to obtain defect images of different types. The specific method is as follows:
[0039] Perform partial scanning on the initial image with different types of defect contours according to the superimposed coordinates and the length and width data of the rectangular box, and judge the number of grayscale image contour points in the smallest rectangular box containing the superimposed coordinates; When the number of grayscale image contour points is greater than 1, obtain the maximum value y of the ordinate of the grayscale image contour points in the smallest rectangular box containing the superimposed coordinates max and the minimum value y min , and perform random filling on the pixels within the range of (x + x add , y + y add ) and (y min , y max ) in the defect contour area to obtain defect images of different types.
[0040] Preferably, in the step S5, the label is in the yolo format label;
[0041] The specific method for generating labels corresponding to defect images of different types is as follows:
[0042] S5.1: Obtain the type data of the defect image;
[0043] S5.2: Use the length and width data of the initial image to normalize the superimposed coordinates and the length and width data of the rectangular box to obtain the normalized center point coordinates and the normalized length and width data;
[0044] S5.2: Save the defect type data, the normalized center point coordinates, and the normalized length and width data as an array with a length of 5, and generate labels corresponding to each type of defect image.
[0045] The present invention also provides a multi-type defect dataset generation system with labels, which applies the above-mentioned multi-type defect dataset generation method with labels, and includes:
[0046] An initial image acquisition unit for acquiring an initial defect-free image;
[0047] A defect contour generation unit for randomly generating defect contours and obtaining defect contour images of different types;
[0048] A contour superposition unit for superposing defect contour images of different types with the initial defect-free image to obtain an initial image with defect contours of different types;
[0049] A contour filling unit for pixel filling inside the defect contour regions in the initial image with defect contours of different types to obtain defect images of different types;
[0050] A label generation unit for generating labels corresponding to defect images of different types, and saving the defect images of different types and their corresponding labels as a multi-type defect dataset with labels.
[0051] Compared with the prior art, the beneficial effects of the technical solution of the present invention are:
[0052] The present invention provides a multi-type defect dataset generation method and system with labels. The method includes acquiring an initial defect-free image, randomly generating defect contours, and obtaining defect contour images of different types; superposing defect contour images of different types with the initial defect-free image to obtain an initial image with defect contours of different types; performing pixel filling on the internal regions of the defect contours in the initial image with defect contours of different types to obtain defect images of different types; and finally generating labels corresponding to defect images of different types, and saving the defect images of different types and their corresponding labels as a multi-type defect dataset with labels.
[0053] The present invention can generate a variety of defect samples, can generate the amount of data according to its own needs, and significantly reduces the difficulty of obtaining the defect dataset; in addition, the present invention can directly generate labels corresponding to defect images, can generate corresponding training labels for different detection models, without manual annotation, saving a large amount of manpower and improving work efficiency. Description of the Drawings
[0054] Figure 1 It is a flowchart of a multi-type defect dataset generation method with labels provided for Example 1.
[0055] Figure 2 It is a flowchart of a method for generating a closed curve-shaped defect contour provided for Example 2.
[0056] Figure 3 Flowchart of the method for generating YOLO format tags corresponding to different types of defect images provided in Embodiment 2.
[0057] Figure 4 Closed curve-shaped defect contour image generated in Embodiment 2.
[0058] Figure 5 Elongated defect contour image generated in Embodiment 2.
[0059] Figure 6 Ordinary defect image provided in Embodiment 2.
[0060] Figure 7 Missing printing defect image provided in Embodiment 2.
[0061] Figure 8 Structure diagram of a multi-type defect dataset generation system with tags provided in Embodiment 3. Detailed implementation manners
[0062] The accompanying drawings are only for illustrative purposes and should not be construed as limitations on this patent;
[0063] To better illustrate this embodiment, some components in the accompanying drawings are omitted, enlarged or reduced, and do not represent the dimensions of the actual product;
[0064] For those skilled in the art, it is understandable that some well-known structures and their descriptions in the accompanying drawings may be omitted.
[0065] The technical solutions of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0066] Embodiment 1
[0067] As Figure 1 shown, this embodiment provides a method for generating a multi-type defect dataset with tags, including the following steps:
[0068] S1: Obtain an initial defect-free image;
[0069] S2: Randomly generate defect contours and obtain different types of defect contour images;
[0070] S3: Superimpose different types of defect contour images on the initial defect-free image to obtain an initial image with different types of defect contours;
[0071] S4: Fill the pixels inside the defect contour regions in the initial image with different types of defect contours to obtain different types of defect images;
[0072] S5: Generate labels corresponding to different types of defective images, and save the different types of defective images and their corresponding labels as a multi-type defective dataset with labels.
[0073] In the specific implementation process, first obtain an initial defect-free image, then randomly generate defect contours to obtain different types of defective contour images; superimpose the different types of defective contour images on the initial defect-free image to obtain an initial image with different types of defective contours; fill the internal area of the defect contours in the initial image with different types of defective contours to obtain different types of defective images; finally, generate labels corresponding to different types of defective images, and save the different types of defective images and their corresponding labels as a multi-type defective dataset with labels.
[0074] This method can generate a variety of defective samples, can generate the amount of data according to its own needs, and significantly reduces the difficulty of obtaining a defective dataset; in addition, this method can directly generate labels corresponding to defective images, and can generate corresponding training labels for different detection models without manual annotation, saving a lot of manpower and improving work efficiency.
[0075] Embodiment 2
[0076] This embodiment provides a method for generating a multi-type defective dataset with labels, including the following steps:
[0077] S1: Obtain an initial defect-free image;
[0078] S2: Randomly generate defect contours to obtain different types of defective contour images, where the defect contours include closed-curve-shaped defect contours and elongated defect contours;
[0079] As Figure 2 shown, the specific method for generating the closed-curve-shaped defect contour is as follows:
[0080] S2.1.1: Randomly generate a number of defect contour base points in the polar coordinate system, and obtain the polar angle corresponding to each defect contour base point;
[0081] S2.1.2: Randomly generate a corresponding polar radius for each defect contour base point;
[0082] S2.1.3: Convert the polar angle and the corresponding polar radius of each contour base point in the polar coordinate system to the rectangular coordinate system to obtain the rectangular coordinates of each contour base point;
[0083] Convert the polar angle α i and the polar radius R i of the i-th contour base point in the polar coordinate system to the rectangular coordinate system, and the conversion formula is specifically:
[0084] xi = R i * cos(α i )
[0085] y i = R i * sin(α i )
[0086] where x i and y i are the abscissa and ordinate of the rectangular coordinates of the i-th contour base point, respectively;
[0087] S2.1.4: According to the rectangular coordinates of each contour base point, use the interp1d() interpolation function for curve fitting to obtain several closed curve-shaped defect contour images;
[0088] The method for generating the elongated defect contour is specifically as follows:
[0089] S2.2.1: In polar coordinates, randomly select two polar angles within the range of (0, π), and the difference between the angle values of the two polar angles is less than a preset angle threshold;
[0090] S2.2.2: Add any one of the two polar angles to a random polar angle, and keep the other polar angle unchanged to obtain a first polar angle and a second polar angle;
[0091] S2.2.3: Randomly generate corresponding elongated defect contour polar radii for the first polar angle and the second polar angle respectively;
[0092] S2.2.4: Obtain the elongated defect contour according to the first polar angle, the second polar angle and their corresponding elongated defect contour polar radii;
[0093] S2.2.5: Repeat steps S2.2.1 - 2.2.4 to obtain several elongated defect contours;
[0094] S3: Superimpose defect contour images of different types on the initial defect-free image to obtain an initial image with defect contours of different types. The specific method is as follows:
[0095] S3.1: Convert the initial defect-free image to a grayscale image and obtain the length and width data of the initial image;
[0096] S3.2: Use the cv2.findContours() function to detect the contours of the grayscale image to obtain the contour point data of the grayscale image;
[0097] S3.3: Use the cv2.boundingRect() function to detect the smallest rectangular box in the contour point data of the grayscale image to obtain the upper left corner coordinates of the rectangular box and the length and width data of the rectangular box;
[0098] S3.4: Add a random value to the upper - left corner coordinates of the rectangular box to obtain the superimposed coordinates, denoted as (x + x add , y + y add ), where x add and y add are the random values of the abscissa and ordinate of the upper - left corner of the rectangular box respectively, and the magnitude of the random value is less than the size of the length and width data of the initial image; Coincide a certain point of the defect contour images of different types with the superimposed coordinates to obtain the initial image with different types of defect contours;
[0099] S4: Perform pixel filling inside the defect contour area in the initial image with different types of defect contours to obtain defect images of different types. The specific method is as follows:
[0100] Perform partial scanning on the initial image with different types of defect contours according to the superimposed coordinates and the length and width data of the rectangular box, and judge the number of grayscale image contour points in the smallest rectangular box containing the superimposed coordinates; When the number of grayscale image contour points is greater than 1, obtain the maximum value y max and the minimum value y min of the ordinate of the grayscale image contour points in the smallest rectangular box containing the superimposed coordinates, and randomly fill the pixels within the range of (x + x add , y + y add ) and (y min , y max ) in the defect contour area to obtain defect images of different types;
[0101] S5: As Figure 3 shown, generate yolo - format labels corresponding to defect images of different types. The specific method is as follows:
[0102] S5.1: Obtain the type data of the defect image;
[0103] S5.2: Use the length and width data of the initial image to normalize the superimposed coordinates and the length and width data of the rectangular box to obtain the normalized center point coordinates and the normalized length and width data;
[0104] S5.2: Save the defect type data, the normalized center point coordinates and the normalized length and width data as an array with a length of 5, and generate labels corresponding to each type of defect image;
[0105] Save the defect images of different types and their corresponding labels as a multi - type defect dataset with labels.
[0106] In the specific implementation process, first obtain the initial image without defects, and then randomly generate defect contours. The defect contours include closed - curve - shaped defect contours and long - shaped defect contours, and obtain defect contour images of different types;
[0107] In this embodiment, for a closed curve-shaped defect contour, first, in the polar coordinate system, uniformly take values within the range of (0, 2π) to obtain the base points of the defect contour; the selection of the polar radius is also very important because to a certain extent, the polar radius determines the size, basic shape, and shape diversity of the generated defect. In this embodiment, randomly take values within the interval [2, 20] to determine the polar radius of each contour base point; convert the polar angle and the corresponding polar radius of each contour base point in the polar coordinate system to the rectangular coordinate system to obtain the rectangular coordinates of each contour base point.
[0108] Convert the polar angle α i and the polar radius R i of the i-th contour base point in the polar coordinate system to the rectangular coordinate system. The conversion formula is specifically:
[0109] x i = R i * cos(α i )
[0110] y i = R i * sin(α i )
[0111] where x i and y i are respectively the abscissa and ordinate of the rectangular coordinates of the i-th contour base point.
[0112] According to the rectangular coordinates of each contour base point, use the interp1d() interpolation function for curve fitting to obtain several closed curve-shaped defect contour images.
[0113] For a long-shaped defect contour such as a scratch, in this embodiment, first, in the polar coordinate system, randomly select two polar angles within the range of (0, π). The difference in the angle values of the two polar angles is less than a preset angle threshold. A too large difference will affect the width of the long-shaped defect contour and thus affect the actual effect; then add any one of the two polar angles to a random polar angle within the range of (0.9π, 1.1π), and keep the other polar angle unchanged to obtain the first polar angle and the second polar angle; then randomly generate the corresponding long-shaped defect contour polar radii for the first polar angle and the second polar angle respectively; obtain the long-shaped defect contour according to the first polar angle, the second polar angle, and their corresponding long-shaped defect contour polar radii; repeat the above steps to obtain several long-shaped defect contours.
[0114] As Figure 4 and Figure 5 shown, Figure 4 is the generated closed curve-shaped defect contour image. Figure 5For the generated long-shaped defect contour image, it can be seen from the defect contours in the figure that the defect contour images randomly generated according to this method are all closed curves, and there are many types and quantities, which can meet the needs of the deep convolutional network for large training data;
[0115] After that, different types of defect contour images are superimposed on the defect-free initial image to obtain the initial image with different types of defect contours;
[0116] As Figure 6 and Figure 7 shown, pixel filling is performed on the defect contours in the initial image with different types of defect contours to obtain different types of defect images. In this embodiment, different types of defect images can be obtained according to different pixel filling contents. For example: pure color filling is performed on the internal area of the defect contour in the initial image with different types of defect contours to obtain ordinary defect images; the pixels in the internal area of the defect contour in the initial image with different types of defect contours are changed to the pixels required for missing printing to obtain missing printing defect images. This method can achieve randomness and irregularity in the missing printing part, which is closer to the real missing printing;
[0117] Finally, yolo format labels corresponding to different types of defect images are generated. The method provided in this embodiment can generate yolo format labels for ordinary defect images and missing printing defect images. Finally, different types of defect images and their corresponding labels are saved as a multi-type defect dataset with labels for training neural network models such as object detection and semantic segmentation;
[0118] This method can automatically generate a multi-type defect dataset with labels, can adjust the type and shape of defect pixel values according to its own needs, and can be flexibly applied to the generation of other types of defects;
[0119] This method can generate a variety of defect samples, can generate the amount of data according to its own needs, and significantly reduces the difficulty of obtaining the defect dataset; in addition, this method can directly generate the labels corresponding to the defect images, can generate corresponding training labels for different detection models, without manual annotation, saving a lot of manpower and improving work efficiency.
[0120] Embodiment 3
[0121] As Figure 8 shown, this embodiment provides a multi-type defect dataset generation system with labels, which applies the multi-type defect dataset generation method with labels described in Embodiment 1 or 2, including:
[0122] Initial image acquisition unit 301: used to acquire a defect-free initial image;
[0123] Defect contour generation unit 302: used to randomly generate defect contours and obtain defect contour images of different types;
[0124] Contour superposition unit 303: used to superpose defect contour images of different types with the initial defect-free image to obtain initial images with defect contours of different types;
[0125] Contour filling unit 304: used to perform pixel filling inside the defect contour regions in the initial images with defect contours of different types to obtain defect images of different types;
[0126] Label generation unit 305: used to generate labels corresponding to defect images of different types, and save the defect images of different types and their corresponding labels as a multi-type defect dataset with labels;
[0127] In the specific implementation process, first, the initial image acquisition unit 301 acquires the initial defect-free image; then, the defect contour generation unit 302 randomly generates defect contours and obtains defect contour images of different types, where the defect contours include closed curve-shaped defect contours and elongated defect contours; then, the contour superposition unit 303 superposes the defect contour images of different types with the initial defect-free image to obtain initial images with defect contours of different types; then, the contour filling unit 304 performs pixel filling inside the defect contour regions in the initial images with defect contours of different types, and according to different filled pixels, obtains defect images of different types; finally, the label generation unit 305 generates labels corresponding to defect images of different types, and saves the defect images of different types and their corresponding labels as a multi-type defect dataset with labels;
[0128] This system can generate a variety of defect samples, can generate the amount of data according to its own needs, and significantly reduces the difficulty of obtaining the defect dataset; in addition, this method can directly generate the labels corresponding to the defect images, can generate corresponding training labels for different detection models, without manual annotation, saving a large amount of manpower and improving work efficiency.
[0129] Identical or similar reference numerals correspond to identical or similar components;
[0130] The terms describing the positional relationship in the drawings are for illustrative purposes only and should not be construed as a limitation of this patent;
[0131] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, rather than limitations on the implementation manners of the present invention. For those of ordinary skill in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to enumerate all implementation manners here. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the claims of the present invention.
Claims
1. A method for generating a multi-type defect data set with labels, characterized in that, It includes the following steps: S1: Obtain an initial defect-free image; S2: Randomly generate defect contours and obtain defect contour images of different types; S3: Superimpose the defect contour images of different types on the initial defect-free image to obtain an initial image with defect contours of different types; specifically: S3.1: Convert the initial defect-free image to a grayscale image and obtain the length and width data of the initial image; S3.2: Use the first detection function to detect the contours of the grayscale image and obtain the contour point data of the grayscale image; S3.3: Use the second detection function to detect the minimum rectangle in the contour point data of the grayscale image and obtain the upper left corner coordinates of the rectangle and the length and width data of the rectangle; S3.4: Add a random value to the upper left corner coordinates of the rectangular box to obtain the superimposed coordinates, denoted as (x + x add , y + y add ), where x add and y add are the random values of the abscissa and ordinate of the upper left corner of the rectangular box respectively, and the magnitude of the random value is less than the magnitude of the length and width data of the initial image; Coincide a certain point of the defect contour images of different types with the superimposed coordinates to obtain the initial image with defect contours of different types; S4: Fill the pixels inside the defect contour areas in the initial images with different types of defect contours to obtain defect images of different types; Specifically, according to the superimposed coordinates and the length and width data of the rectangular box, perform partial scanning on the initial image with different types of defect contours, and judge the number of grayscale image contour points in the smallest rectangular box containing the superimposed coordinates; when the number of grayscale image contour points is greater than 1, obtain the maximum value y of the ordinate of the grayscale image contour points in the smallest rectangular box containing the superimposed coordinates max and the minimum value y min , for the pixels within the defect contour area (x + x add , y + y add ) and (y min , y max ), perform random filling to obtain defect images of different types; S5: Generate labels corresponding to the defect images of different types, and save the defect images of different types and their corresponding labels as a multi-type defect dataset with labels; the labels are in the yolo format; The specific steps for generating labels corresponding to the defect images of different types are: S5.1: Obtain the type data of the defect images; S5.2: Use the length and width data of the initial image to normalize the superimposed coordinates and the length and width data of the rectangle to obtain the normalized center point coordinates and the normalized length and width data; S5.2: Save the type data, the normalized center point coordinates, and the normalized length and width data as an array with a length of 5, and generate labels corresponding to each type of defect image.
2. The method for generating a multi-type defect data set with labels according to claim 1, wherein In step S2, the specific method for randomly generating defect contours and obtaining defect contour images of different types is: The defect contours include closed curve-shaped defect contours, and the generation method of the closed curve-shaped defect contours is specifically: S2.1.1: Randomly generate several defect contour base points in the polar coordinate system and obtain the polar angles corresponding to each defect contour base point; S2.1.2: Randomly generate corresponding polar radii for each defect contour base point; S2.1.3: Convert the polar angles and the corresponding polar radii of each contour base point in the polar coordinate system to the rectangular coordinate system to obtain the rectangular coordinates of each contour base point; S2.1.4: According to the rectangular coordinates of each contour base point, use a preset function for curve fitting to obtain several closed curve-shaped defect contour images.
3. A method for generating a multi-type defect data set with labels according to claim 2, characterized in that, In step S2.1.3, the method for converting the polar angles and the corresponding polar radii of each contour base point in the polar coordinate system to the rectangular coordinate system to obtain the rectangular coordinates of each contour base point is specifically: Convert the polar angle α i and the polar radius R i of the i-th contour base point in the polar coordinate system to the rectangular coordinate system. The conversion formula is specifically as follows: x i =R i ·cos(α i ) y i =R i ·sin(α i ) where x i and y i are the abscissa and ordinate of the right-angle coordinates of the i-th contour base point, respectively.
4. A method for generating a multi-type defect data set with labels according to claim 2, characterized in that, In step S2.1.4, the preset function is specifically the interp1d() interpolation function.
5. A method for generating a multi-type defect data set with labels according to claim 1, characterized in that, In step S2, the specific method for randomly generating defect contours and obtaining defect contour images of different types is: The defect contours also include long-shaped defect contours, and the generation method of the long-shaped defect contours is specifically: S2.2.1: In the polar coordinate system, randomly select two polar angles within the range of (0, π), and the difference between the angle values of the two polar angles is less than a preset angle threshold; S2.2.2: Add any one of the two polar angles to a random polar angle, and keep the other polar angle unchanged to obtain a first polar angle and a second polar angle; S2.2.3: Randomly generate corresponding polar radii of the long defect contour for the first polar angle and the second polar angle respectively; S2.2.4: Obtain the long defect contour according to the first polar angle, the second polar angle and their corresponding polar radii of the long defect contour; S2.2.5: Repeat steps S2.2.1 - 2.2.4 to obtain a number of long defect contours.
6. A method for generating a multi-type defect data set with labels according to claim 1, characterized in that, In the said step S3, the first detection function is the cv2.findContours() function, and the second detection function is the cv2.boundingRect() function.
7. A multi-type defect dataset generation system with labels, which applies the multi-type defect dataset generation method with labels described in any one of claims 1-6, characterized in that, Including: An initial image acquisition unit for acquiring an initial defect-free image; A defect contour generation unit for randomly generating defect contours to obtain defect contour images of different types; A contour superposition unit for superposing defect contour images of different types with the initial defect-free image to obtain an initial image with defect contours of different types; A contour filling unit for pixel filling inside the defect contour regions in the initial image with defect contours of different types to obtain defect images of different types; A label generation unit for generating labels corresponding to defect images of different types, and saving the defect images of different types and their corresponding labels as a multi-type defect dataset with labels.
Citation Information
Patent Citations
Defect detection method and device and electronic device
CN110619619A
Method for detecting unbalanced defect sample based on convolutional neural network
CN111932639A