Printed circuit board defect detection method, device, equipment and storage medium
By performing feature calculation and model training on the sample training image of the printed circuit board, a preset defect detection model is obtained, which solves the problem of low PCB defect detection accuracy in the prior art, and realizes high-precision online defect detection.
Patent Information
- Application Number
- CN202210434417.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-24
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2042-04-24
AI Technical Summary
In the prior art, the defect detection accuracy of printed circuit boards (PCBs) is low and cannot meet the requirements of online detection.
By obtaining the sample training image and the image to be detected on the sample printed circuit board, the characteristics of the image to be detected are calculated, including the target size outline characteristics, image variance characteristics, direction gradient histogram characteristics, etc., the model is trained to obtain a preset defect detection model, which is used to detect defects on the image to be detected.
It improves the defect detection accuracy and accuracy of PCB online detection, and meets the needs of PCB online defect detection.
Smart Images

Figure CN114897797B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of detection technology, and in particular to a defect detection method, device, equipment and storage medium for a printed circuit board. Background Art
[0002] In the automated production process of vehicle-mounted screens, PCB (Printed Circuit Board) is an important component, but in the PCB production process, defects such as missing, offset, and misalignment of PCB components often occur. Traditional manual inspection cannot meet the requirements of online inspection, so machine vision inspection of PCB defects has become the main inspection method at present, but the inspection accuracy in existing technologies is low. Summary of the invention
[0003] The main purpose of the present invention is to provide a printed circuit board defect detection method, device, equipment and storage medium, aiming to solve the technical problem of low PCB defect detection accuracy in the prior art.
[0004] To achieve the above object, the present invention provides a method for defect detection of a printed circuit board, the method comprising:
[0005] Acquire a sample training image of a sample printed circuit board and an image to be detected of a printed circuit board to be detected;
[0006] Perform feature calculation according to the sample training image to obtain sample training features corresponding to the sample training image;
[0007] Performing model training according to the sample training features and the sample training images to obtain a preset defect detection model;
[0008] Defect detection is performed on the image to be detected according to the preset defect detection model to obtain a defect detection result of the printed circuit board.
[0009] Optionally, the sample training features include at least one of target size contour features, image variance features, directional gradient histogram features, edge density features, average gradient intensity features, accumulated gradient value features, Fourier spectrum features, and correlation surface features;
[0010] The performing feature calculation according to the sample training image to obtain the sample training feature corresponding to the sample training image includes:
[0011] Calculate the target size contour feature according to the sample training image to obtain the target size contour feature;
[0012] Calculating image variance features based on the sample training images to obtain image variance features;
[0013] Performing cell division according to the sample training image to obtain division units;
[0014] Calculating directional histogram features according to the division units to obtain directional histogram features;
[0015] Determine edge pixel values, row image elements, and column image elements according to the sample training image;
[0016] Calculate edge density features according to the edge pixel values, row image elements, and column image elements to obtain edge density features;
[0017] Calculate the average gradient intensity according to the sample training image to obtain an average gradient intensity feature;
[0018] Determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image;
[0019] Calculate the accumulated gradient value according to the gradient of the coordinate direction of each pixel point to obtain the accumulated gradient value feature;
[0020] Determining an image size according to the sample training image;
[0021] Calculate Fourier spectrum features according to the image size to obtain Fourier spectrum features;
[0022] The relevant surface features are calculated according to the sample training images to obtain the relevant surface features.
[0023] Optionally, the calculating target size contour features according to the sample training image to obtain the target size contour features includes:
[0024] Determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image;
[0025] Determine the gradient angle of each pixel point according to the gradient of the coordinate direction of each pixel point;
[0026] Determine the gradient direction entropy according to the gradient angle and the preset angle interval;
[0027] The target size contour feature is determined according to the gradient directional entropy and the corresponding number of the preset angle intervals.
[0028] Optionally, the calculating image variance features according to the sample training images to obtain image variance features includes:
[0029] Determine the grayscale value, row image element and column image element corresponding to each pixel point according to the sample training image;
[0030] Determine the average grayscale value of the image according to the grayscale value corresponding to each pixel point;
[0031] The image variance feature is determined according to the grayscale value corresponding to each pixel point, the row image element, the column image element and the image grayscale average value.
[0032] Optionally, the calculating the average gradient strength according to the sample training image to obtain the average gradient strength feature includes:
[0033] Determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image;
[0034] Determine the gradient intensity value of each pixel point according to the gradient in the coordinate direction of each pixel point;
[0035] Determining a gradient intensity map of the sample training image according to the gradient intensity value;
[0036] Performing a mean filtering operation on the gradient intensity map to obtain an average gradient intensity map;
[0037] An average gradient intensity feature is determined based on the average gradient intensity map.
[0038] Optionally, the calculating relevant surface features according to the sample training image to obtain relevant surface features includes:
[0039] Performing cell division according to the sample training image to obtain division units;
[0040] Performing gradient strength calculation according to the division unit image corresponding to the division unit and the sample training image to obtain a first gradient strength corresponding to the sample training image and a second gradient strength corresponding to the division unit image;
[0041] A correlation coefficient is calculated according to the first gradient strength, the second gradient strength, the sample training image and the divided unit image to obtain a correlation surface feature.
[0042] Optionally, performing model training according to the sample training features and the sample training images to obtain a preset defect detection model includes:
[0043] Obtain preset evaluation indicators;
[0044] Performing model training according to the sample training features and the sample training images to obtain an initial training model and a confusion matrix index of the initial training model;
[0045] Perform model evaluation according to the preset evaluation index and the confusion matrix index to obtain an evaluation result;
[0046] When the evaluation result is a preset result, a preset defect detection model is obtained according to the initial training model.
[0047] In addition, to achieve the above-mentioned purpose, the present invention also provides a defect detection device for a printed circuit board, the defect detection device for a printed circuit board comprising:
[0048] An acquisition module, used for acquiring a sample training image of a sample printed circuit board and an image to be detected of a printed circuit board to be detected;
[0049] A calculation module, used to perform feature calculation according to the sample training image to obtain sample training features corresponding to the sample training image;
[0050] A training module, used for performing model training according to the sample training features and the sample training images to obtain a preset defect detection model;
[0051] The detection module is used to perform defect detection on the image to be detected according to the preset defect detection model to obtain a defect detection result of the printed circuit board.
[0052] In addition, to achieve the above-mentioned purpose, the present invention also proposes a printed circuit board defect detection device, the printed circuit board defect detection device comprising: a memory, a processor, and a printed circuit board defect detection program stored in the memory and executable on the processor, the printed circuit board defect detection program being configured to implement the printed circuit board defect detection method as described above.
[0053] In addition, to achieve the above objectives, the present invention also proposes a storage medium, on which a printed circuit board defect detection program is stored. When the printed circuit board defect detection program is executed by a processor, the printed circuit board defect detection method described above is implemented.
[0054] The present invention obtains a sample training image of a sample printed circuit board and an image to be detected of a printed circuit board to be detected; performs feature calculation based on the sample training image to obtain a sample training feature corresponding to the sample training image; performs model training based on the sample training feature and the sample training image to obtain a preset defect detection model; performs defect detection on the image to be detected based on the preset defect detection model to obtain a defect detection result of the printed circuit board. In the above manner, model training is performed based on the sample training feature corresponding to the sample training image of the sample printed circuit board to obtain a preset defect detection model that can accurately identify whether there are defects in the corresponding image of the printed circuit board, thereby performing defect detection on the image to be detected based on the preset defect detection model, thereby improving the defect detection precision and accuracy during PCB online detection, and meeting the needs of PCB online defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 It is a structural schematic diagram of a printed circuit board defect detection device in a hardware operating environment involved in an embodiment of the present invention;
[0056] Figure 2 It is a schematic flow chart of a first embodiment of a defect detection method for a printed circuit board according to the present invention;
[0057] Figure 3 It is a schematic flow chart of a second embodiment of a defect detection method for a printed circuit board according to the present invention;
[0058] Figure 4 It is a structural block diagram of the first embodiment of the defect detection device for printed circuit boards of the present invention.
[0059] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0060] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0061] Reference Figure 1 , Figure 1 The present invention is a schematic diagram of the structure of a defect detection device for a printed circuit board in a hardware operating environment according to an embodiment of the present invention.
[0062] like Figure 1 As shown, the defect detection device for a printed circuit board may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0063] Those skilled in the art will understand that Figure 1The structure shown in the figure does not constitute a limitation on the defect detection device for printed circuit boards, and may include more or less components than those shown in the figure, or combine certain components, or arrange the components differently.
[0064] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a defect detection program for a printed circuit board.
[0065] exist Figure 1 In the printed circuit board defect detection device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the printed circuit board defect detection device of the present invention can be set in the printed circuit board defect detection device, and the printed circuit board defect detection device calls the printed circuit board defect detection program stored in the memory 1005 through the processor 1001, and executes the printed circuit board defect detection method provided by the embodiment of the present invention.
[0066] The embodiment of the present invention provides a defect detection method for a printed circuit board. Figure 2 , Figure 2 The figure is a flow chart of a first embodiment of a defect detection method for a printed circuit board according to the present invention.
[0067] The defect detection method of the printed circuit board comprises the following steps:
[0068] Step S10: Acquire a sample training image of a sample printed circuit board and an image to be inspected of a printed circuit board to be inspected.
[0069] It should be noted that the execution subject of this embodiment is a terminal device, and a defect detection system for a printed circuit board is installed on the terminal device. When the terminal device receives a detection instruction, the detection instruction is forwarded to the defect detection system for the printed circuit board, and the defect detection system for the printed circuit board obtains sample training images and images to be detected according to the detection instruction. Feature calculation is performed based on the sample training images to obtain sample training features corresponding to each sample training image, and model training is performed based on the sample training features and the sample training images to obtain a preset defect detection model. Defect detection is performed on the image to be detected based on the obtained preset defect detection model to obtain a defect detection result for the printed circuit board.
[0070] It can be understood that a large number of sample training images of sample printed circuit boards are obtained from the preset database, and the sample training images can be defective sample training images or non-defective sample training images. The sample training images corresponding to the sample printed circuit boards are manually judged, and the labels corresponding to the defective sample training images are set to 1, and the labels corresponding to the non-defective sample training images are set to 0. Finally, all the sample training images of the sample printed circuit boards and the corresponding labels are stored to obtain the sample training image data set.
[0071] In a specific implementation, the image to be inspected is an image corresponding to the printed circuit board to be inspected.
[0072] Step S20: performing feature calculation according to the sample training image to obtain sample training features corresponding to the sample training image.
[0073] It should be noted that the sample training feature refers to the image feature value obtained after feature calculation based on the sample training image. The sample training feature includes at least one of the target size contour feature, image variance feature, directional gradient histogram feature, edge density feature, average gradient intensity feature, accumulated gradient value feature, Fourier spectrum feature and correlation surface feature.
[0074] Step S30: performing model training according to the sample training features and the sample training images to obtain a preset defect detection model.
[0075] It should be noted that the sample training features and the corresponding sample training images are split according to a preset ratio to obtain a test set and a training set. GBDT (Gradient Boosting Decision Tree) is used to perform model training and fitting based on the training set, and a detection experiment is performed on the initial training model after model training based on the test set, and finally a preset defect detection model that can accurately identify whether there are defects in the corresponding image of the printed circuit board is obtained.
[0076] It can be understood that in order to ensure the accuracy of model training and improve the accuracy of subsequent defect detection, further, the model training is performed according to the sample training features and the sample training images to obtain a preset defect detection model, including: obtaining preset evaluation indicators; performing model training according to the sample training features and the sample training images to obtain an initial training model and a confusion matrix indicator of the initial training model; performing model evaluation according to the preset evaluation indicators and the confusion matrix indicator to obtain an evaluation result; when the evaluation result is a preset result, obtaining a preset defect detection model according to the initial training model.
[0077] In a specific implementation, the preset evaluation index refers to an index that is preset so that the model can stop training. The GBDT classification algorithm is used to train the model according to the sample training features and the sample training images to obtain the initial training model and the confusion matrix index of the initial training model. The preset evaluation index and the confusion matrix index are used to evaluate the model to obtain an evaluation result of whether the confusion matrix index meets the requirements. When the evaluation result is that the confusion matrix index meets the preset result, the initial training model can be used as the preset defect detection model. When the evaluation result is that the confusion matrix index does not meet the requirements, it is necessary to adjust the training parameters during model training according to the preset evaluation index, such as step size, learning rate, number of iterations, and number of nodes for model classification, and then retrain the model.
[0078] Step S40: performing defect detection on the image to be detected according to the preset defect detection model to obtain a defect detection result of the printed circuit board.
[0079] It should be noted that after obtaining the preset defect detection model, the image to be detected is input into the preset defect detection model to perform defect detection on the image to be detected, and a defect detection result of whether there are missing components, offsets, misalignments, etc. on the printed circuit board is obtained.
[0080] This embodiment obtains a sample training image of a sample printed circuit board and an image to be detected of a printed circuit board to be detected; performs feature calculation based on the sample training image to obtain a sample training feature corresponding to the sample training image; performs model training based on the sample training feature and the sample training image to obtain a preset defect detection model; performs defect detection on the image to be detected based on the preset defect detection model to obtain a defect detection result of the printed circuit board. In the above manner, model training is performed based on the sample training feature corresponding to the sample training image of the sample printed circuit board to obtain a preset defect detection model that can accurately identify whether there are defects in the corresponding image of the printed circuit board, thereby performing defect detection on the image to be detected based on the preset defect detection model, thereby improving the defect detection precision and accuracy during PCB online detection and meeting the needs of PCB online defect detection.
[0081] refer to Figure 3 , Figure 3 It is a flow chart of a second embodiment of a defect detection method for a printed circuit board according to the present invention.
[0082] Based on the above first embodiment, the sample training features include at least one of target size contour features, image variance features, directional gradient histogram features, edge density features, average gradient intensity features, cumulative gradient value features, Fourier spectrum features, and correlation surface features. Step S20 in the defect detection method for a printed circuit board in this embodiment includes:
[0083] Step S21: Calculate the target size contour feature according to the sample training image to obtain the target size contour feature.
[0084] It should be noted that the target size contour feature is the large-scale contour feature H corresponding to each sample training image. nor .
[0085] It can be understood that in order to obtain the accurate target size contour feature H nor Further, the target size contour feature is calculated according to the sample training image to obtain the target size contour feature, including: determining the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image; determining the gradient angle of each pixel point according to the gradient of the coordinate direction of each pixel point; determining the gradient direction entropy according to the gradient angle and a preset angle interval; determining the target size contour feature according to the gradient direction entropy and the corresponding number of the preset angle interval.
[0086] In the specific implementation, the gradient of each pixel coordinate direction refers to the gradient G in the x direction of each pixel in the sample training image. x (x,y) and the gradient G in the y direction y (x,y). The gradient angle of each pixel refers to the gradient angle of each pixel
[0087] It should be noted that the preset angle interval refers to the n angle intervals obtained by evenly dividing the gradient direction from 0 to 360 degrees into n intervals. n is the number of preset angle intervals. The sample pixel image is divided into cells to obtain multiple division units with a size of approximately w*h=10*10. The pixel probability p of each division unit in each sample pixel image in which the gradient angle is within each preset angle interval is calculated. i The probability of each direction in the gradient direction histogram of the division unit is counted separately to obtain the gradient direction entropy of each division unit. Getting the gradient direction entropy Finally, according to the definition of entropy, when the probability of the gradient in each direction is equal, the entropy takes the maximum value and the normalized gradient direction entropy is obtained. in, The normalized entropy value is counted, and the pixels in H are sorted from large to small. The first 30% of the pixels in the sorting result are weighted, which is the value of the final target area of the trip. w and h are the width and height of the target area respectively, H nor The target size contour feature
[0088] Step S22: Calculating image variance features based on the sample training images to obtain image variance features.
[0089] It should be noted that the image variance feature refers to the grayscale variance feature of the image, which reflects the degree of fluctuation of the overall grayscale of the image. The image variance feature is calculated based on the sample training image to obtain the image variance feature V ar .
[0090] It can be understood that in order to obtain accurate image variance features, further, the image variance features are calculated based on the sample training image to obtain the image variance features, including: determining the grayscale value, row image element and column image element corresponding to each pixel point according to the sample training image; determining the image grayscale average value according to the grayscale value corresponding to each pixel point; determining the image variance features according to the grayscale value, row image element, column image element and image grayscale average value corresponding to each pixel point.
[0091] In the specific implementation, the grayscale value X(i,j) corresponding to each pixel is determined according to the sample training image, where (i,j) refers to the coordinates of the pixel, the row image element m and the column image element n of the sample training image. The average grayscale value E(X(i,j)) of the sample training image can be determined according to the grayscale value corresponding to each pixel, the row image element, the column image element and the average grayscale value of the image to determine the image variance feature
[0092] Step S23: performing cell division according to the sample training image to obtain division units.
[0093] It should be noted that the sample training image is divided into cells to obtain divided units of the same size.
[0094] Step S24: Calculate the directional histogram features according to the division units to obtain directional histogram features.
[0095] It should be noted that the sum of the entropy values of all the division units is calculated to obtain the Hog entropy of the directional histogram feature.
[0096] Step S25: determining edge pixel values, row image elements, and column image elements according to the sample training image.
[0097] It should be noted that the edge pixel value is obtained by using the edge operator according to the sample training image, and the row image element m and the column image element n of the sample training image are determined.
[0098] Step S26: Calculate edge density features according to the edge pixel values, row image elements, and column image elements to obtain edge density features.
[0099] It should be noted that the edge density feature is used to determine whether the edge feature distribution in the sample training image is dense, and is an indicator that reflects the amount of image information. The edge density feature can be obtained by calculating the edge pixel value, row image element, and column image element. Among them, edge is the absolute value of the edge pixel value.
[0100] Step S27: Calculate the average gradient intensity according to the sample training image to obtain an average gradient intensity feature.
[0101] It should be noted that the average gradient intensity can be calculated based on the sample training image to obtain the average gradient intensity feature.
[0102] It can be understood that in order to obtain accurate average gradient strength, further, the average gradient strength is calculated based on the sample training image to obtain the average gradient strength feature, including: determining the gradient in the coordinate direction of each pixel point in the sample training image based on the sample training image; determining the gradient strength value of each pixel point based on the gradient in the coordinate direction of each pixel point; determining the gradient strength map of the sample training image based on the gradient strength value; performing a mean filtering operation on the gradient strength map to obtain an average gradient strength map; and determining the average gradient strength feature based on the average gradient strength map.
[0103] In the specific implementation, the gradient of each pixel coordinate direction refers to the gradient G in the x direction of each pixel in the sample training image. x (x,y) and the gradient G in the y direction y (x, y), and then get the gradient intensity value of each pixel Thus, the gradient intensity map of the sample training image is obtained. The sample training image is divided into cells to obtain the division units, and the mean filtering operation is performed with the size of the division unit as a template to obtain the average gradient intensity map of the division unit. According to the ranking of the average gradient intensity map, the average value of the gradient intensity values of the top 30% is taken as the average gradient intensity value of the sample training image.
[0104] Step S28: determining the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image.
[0105] It should be noted that the gradient of each pixel coordinate direction refers to the gradient G in the x direction of each pixel in the sample training image. x (x,y) and the gradient G in the y direction y (x,y).
[0106] Step S29: Calculate the accumulated gradient value according to the gradient in the coordinate direction of each pixel point to obtain an accumulated gradient value feature.
[0107] It should be noted that the cumulative gradient value feature describes the sum of the gradient strengths in a region. The stronger the number of accumulated edges in a region, the more obvious the gradient feature. The cumulative gradient value is calculated based on the gradient in the coordinate direction of each pixel point. final
[0108] Step S210: determining the image size according to the sample training image.
[0109] It should be noted that the original image size I of the sample training image is determined according to the sample training image.
[0110] Step S211: Calculate Fourier spectrum features according to the image size to obtain Fourier spectrum features.
[0111] It should be noted that the Fourier spectrum feature describes the texture feature of the sample training image. After obtaining the image size, the Fourier transform energy map FI of the sample training image is obtained. FI = |F(I)|, F(I) is the two-dimensional Fourier transform of I, and the size of FI is also m×n. E = sum(FI) = sum[|F(I)|], E is the Fourier energy sum, then
[0112]
[0113]
[0114]
[0115]
[0116] Among them, BW2, BW4, BW8, and BW16 are respectively called 1 / 2 radius energy sum, 1 / 4 radius energy sum, 1 / 8 radius energy sum, and 1 / 16 radius energy sum.
[0117] Step S212: Calculate relevant surface features according to the sample training image to obtain relevant surface features.
[0118] It should be noted that the correlation surface feature refers to the correlation coefficient between the sample training image and the divided unit image.
[0119] It can be understood that in order to obtain accurate related surface features, further, the related surface features are calculated based on the sample training image to obtain the related surface features, including: cell division according to the sample training image to obtain division units; gradient strength calculation based on the division unit image corresponding to the division unit and the sample training image to obtain the first gradient strength corresponding to the sample training image and the second gradient strength corresponding to the division unit image; correlation coefficient calculation based on the first gradient strength, the second gradient strength, the sample training image and the division unit image to obtain the related surface features.
[0120] In a specific implementation, cell division is performed according to the sample training image to obtain division units of the same size, and a division unit image corresponding to the division unit is obtained. The first gradient strength refers to the gradient strength of the sample training image at each pixel point. The second gradient strength refers to the gradient strength of the divided unit image at each pixel point
[0121] It should be noted that after obtaining the first gradient strength, the second gradient strength, the sample training image and the division unit image, the correlation coefficient can be calculated to obtain the correlation surface feature. The division unit image is traversed on the sample training image with a pixel as the step size. The size of the correlation surface coefficient S is (W-w+1)×(H-h+1). Each pixel value is the correlation coefficient value of the corresponding area of the division unit image and the sample training image. The local maximum value in the correlation surface is the peak value, and the local range size is set by the outside world. The final correlation surface feature Where, E(ai) is the mean value of the gradient intensity of the partition unit image, E(AI) is the mean value of the gradient intensity of the corresponding area of the sample training image. (x, y) is the coordinate of the upper left corner of the partition unit image in the sample training image.
[0122] This embodiment obtains target size contour features by calculating target size contour features according to the sample training image; calculates image variance features according to the sample training image to obtain image variance features; divides cells according to the sample training image to obtain division units; calculates directional histogram features according to the division units to obtain directional histogram features; determines edge pixel values, row image elements and column image elements according to the sample training image; calculates edge density features according to the edge pixel values, row image elements and column image elements to obtain edge density features; calculates average gradient intensity according to the sample training image to obtain average gradient intensity features; determines the gradient of each pixel point coordinate direction in the sample training image according to the sample training image; calculates accumulated gradient values according to the gradient of each pixel point coordinate direction to obtain accumulated gradient value features; determines image size according to the sample training image; calculates Fourier spectrum features according to the image size to obtain Fourier spectrum features; calculates related surface features according to the sample training image to obtain related surface features. Thus, accurate sample training features can be obtained, providing accurate training data for subsequent model training.
[0123] In addition, refer to Figure 4 The embodiment of the present invention further provides a defect detection device for a printed circuit board, the defect detection device for a printed circuit board comprising:
[0124] The acquisition module 10 is used to acquire a sample training image of a sample printed circuit board and an image to be inspected of a printed circuit board to be inspected.
[0125] The calculation module 20 is used to perform feature calculation according to the sample training image to obtain sample training features corresponding to the sample training image.
[0126] The training module 30 is used to perform model training according to the sample training features and the sample training images to obtain a preset defect detection model.
[0127] The detection module 40 is used to perform defect detection on the image to be detected according to the preset defect detection model to obtain a defect detection result of the printed circuit board.
[0128] This embodiment obtains a sample training image of a sample printed circuit board and an image to be detected of a printed circuit board to be detected; performs feature calculation based on the sample training image to obtain a sample training feature corresponding to the sample training image; performs model training based on the sample training feature and the sample training image to obtain a preset defect detection model; performs defect detection on the image to be detected based on the preset defect detection model to obtain a defect detection result of the printed circuit board. In the above manner, model training is performed based on the sample training feature corresponding to the sample training image of the sample printed circuit board to obtain a preset defect detection model that can accurately identify whether there are defects in the corresponding image of the printed circuit board, thereby performing defect detection on the image to be detected based on the preset defect detection model, thereby improving the defect detection precision and accuracy during PCB online detection and meeting the needs of PCB online defect detection.
[0129] In one embodiment, the calculation module 20 is further used to calculate the target size contour feature according to the sample training image to obtain the target size contour feature;
[0130] Calculating image variance features based on the sample training images to obtain image variance features;
[0131] Performing cell division according to the sample training image to obtain division units;
[0132] Calculating directional histogram features according to the division units to obtain directional histogram features;
[0133] Determine edge pixel values, row image elements, and column image elements according to the sample training image;
[0134] Calculate edge density features according to the edge pixel values, row image elements, and column image elements to obtain edge density features;
[0135] Calculate the average gradient intensity according to the sample training image to obtain an average gradient intensity feature;
[0136] Determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image;
[0137] Calculate the accumulated gradient value according to the gradient of the coordinate direction of each pixel point to obtain the accumulated gradient value feature;
[0138] Determining an image size according to the sample training image;
[0139] Calculate Fourier spectrum features according to the image size to obtain Fourier spectrum features;
[0140] The relevant surface features are calculated according to the sample training images to obtain the relevant surface features.
[0141] In one embodiment, the calculation module 20 is further used to determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image;
[0142] Determine the gradient angle of each pixel point according to the gradient of the coordinate direction of each pixel point;
[0143] Determine the gradient direction entropy according to the gradient angle and the preset angle interval;
[0144] The target size contour feature is determined according to the gradient directional entropy and the corresponding number of the preset angle intervals.
[0145] In one embodiment, the calculation module 20 is further used to determine the gray value, row image element and column image element corresponding to each pixel point according to the sample training image;
[0146] Determine the average grayscale value of the image according to the grayscale value corresponding to each pixel point;
[0147] The image variance feature is determined according to the grayscale value corresponding to each pixel point, the row image element, the column image element and the image grayscale average value.
[0148] In one embodiment, the calculation module 20 is further used to determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image;
[0149] Determine the gradient intensity value of each pixel point according to the gradient in the coordinate direction of each pixel point;
[0150] Determining a gradient intensity map of the sample training image according to the gradient intensity value;
[0151] Performing a mean filtering operation on the gradient intensity map to obtain an average gradient intensity map;
[0152] An average gradient intensity feature is determined based on the average gradient intensity map.
[0153] In one embodiment, the calculation module 20 is further used to perform cell division according to the sample training image to obtain division units;
[0154] Performing gradient strength calculation according to the division unit image corresponding to the division unit and the sample training image to obtain a first gradient strength corresponding to the sample training image and a second gradient strength corresponding to the division unit image;
[0155] A correlation coefficient is calculated according to the first gradient strength, the second gradient strength, the sample training image and the divided unit image to obtain a correlation surface feature.
[0156] In one embodiment, the training module 30 is further used to obtain a preset evaluation index;
[0157] Performing model training according to the sample training features and the sample training images to obtain an initial training model and a confusion matrix index of the initial training model;
[0158] Perform model evaluation according to the preset evaluation index and the confusion matrix index to obtain an evaluation result;
[0159] When the evaluation result is a preset result, a preset defect detection model is obtained according to the initial training model.
[0160] Since the present device adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0161] In addition, an embodiment of the present invention further proposes a storage medium on which a printed circuit board defect detection program is stored. When the printed circuit board defect detection program is executed by a processor, the steps of the printed circuit board defect detection method described above are implemented.
[0162] Since the storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0163] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.
[0164] In addition, for technical details that are not described in detail in this embodiment, reference can be made to the printed circuit board defect detection method provided in any embodiment of the present invention, and will not be repeated here.
[0165] In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0166] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0167] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0168] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for defect detection of a printed circuit board, characterized in that: The defect detection method of the printed circuit board comprises: Acquire a sample training image of a sample printed circuit board and an image to be detected of a printed circuit board to be detected; Perform feature calculation according to the sample training image to obtain sample training features corresponding to the sample training image; Performing model training according to the sample training features and the sample training images to obtain a preset defect detection model; Performing defect detection on the image to be detected according to the preset defect detection model to obtain a defect detection result of the printed circuit board; The sample training features include at least one of target size contour features, image variance features, directional gradient histogram features, edge density features, average gradient intensity features, cumulative gradient value features, Fourier spectrum features, and correlation surface features; The performing feature calculation according to the sample training image to obtain the sample training feature corresponding to the sample training image includes: Calculate the target size contour feature according to the sample training image to obtain the target size contour feature; Calculating image variance features based on the sample training images to obtain image variance features; Performing cell division according to the sample training image to obtain division units; Calculating directional histogram features according to the division units to obtain directional histogram features; Determine edge pixel values, row image elements, and column image elements according to the sample training image; Calculate edge density features according to the edge pixel values, row image elements, and column image elements to obtain edge density features; Calculate the average gradient intensity according to the sample training image to obtain an average gradient intensity feature; Determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image; Calculate the accumulated gradient value according to the gradient of the coordinate direction of each pixel point to obtain the accumulated gradient value feature; Determining an image size according to the sample training image; Calculate Fourier spectrum features according to the image size to obtain Fourier spectrum features; Calculating relevant surface features according to the sample training image to obtain relevant surface features; The step of calculating relevant surface features according to the sample training image to obtain relevant surface features includes: Performing cell division according to the sample training image to obtain division units; Performing gradient strength calculation according to the division unit image corresponding to the division unit and the sample training image to obtain a first gradient strength corresponding to the sample training image and a second gradient strength corresponding to the division unit image; A correlation coefficient is calculated according to the first gradient strength, the second gradient strength, the sample training image and the divided unit image to obtain a correlation surface feature.
2. The defect detection method for a printed circuit board according to claim 1, characterized in that: The step of calculating the target size contour feature according to the sample training image to obtain the target size contour feature includes: Determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image; Determine the gradient angle of each pixel point according to the gradient of the coordinate direction of each pixel point; Determine the gradient direction entropy according to the gradient angle and the preset angle interval; The target size contour feature is determined according to the gradient directional entropy and the corresponding number of the preset angle intervals.
3. The defect detection method for a printed circuit board according to claim 1, characterized in that: The step of calculating the image variance feature according to the sample training image to obtain the image variance feature includes: Determine the grayscale value, row image element and column image element corresponding to each pixel point according to the sample training image; Determine the average grayscale value of the image according to the grayscale value corresponding to each pixel point; The image variance feature is determined according to the grayscale value corresponding to each pixel point, the row image element, the column image element and the image grayscale average value.
4. The defect detection method for a printed circuit board according to claim 1, characterized in that: The calculating the average gradient strength according to the sample training image to obtain the average gradient strength feature includes: Determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image; Determine the gradient intensity value of each pixel point according to the gradient in the coordinate direction of each pixel point; Determining a gradient intensity map of the sample training image according to the gradient intensity value; Performing a mean filtering operation on the gradient intensity map to obtain an average gradient intensity map; An average gradient intensity feature is determined based on the average gradient intensity map.
5. The defect detection method for a printed circuit board according to claim 1, characterized in that: The performing model training according to the sample training features and the sample training images to obtain a preset defect detection model includes: Obtain preset evaluation indicators; Performing model training according to the sample training features and the sample training images to obtain an initial training model and a confusion matrix index of the initial training model; Perform model evaluation according to the preset evaluation index and the confusion matrix index to obtain an evaluation result; When the evaluation result is a preset result, a preset defect detection model is obtained according to the initial training model.
6. A defect detection device for a printed circuit board, characterized in that: The defect detection device for a printed circuit board comprises: An acquisition module, used for acquiring a sample training image of a sample printed circuit board and an image to be detected of a printed circuit board to be detected; A calculation module, used to perform feature calculation according to the sample training image to obtain sample training features corresponding to the sample training image; A training module, used for performing model training according to the sample training features and the sample training images to obtain a preset defect detection model; A detection module, used to perform defect detection on the image to be detected according to the preset defect detection model to obtain a defect detection result of the printed circuit board; The calculation module is further used to calculate the target size contour feature according to the sample training image to obtain the target size contour feature; calculate the image variance feature according to the sample training image to obtain the image variance feature; divide the cell according to the sample training image to obtain the division unit; calculate the directional histogram feature according to the division unit to obtain the directional histogram feature; determine the edge pixel value, row image element and column image element according to the sample training image; calculate the edge density feature according to the edge pixel value, row image element and column image element to obtain the edge density feature; calculate the average gradient intensity according to the sample training image to obtain the average gradient intensity feature; determine the gradient of the coordinate direction of each pixel point in the sample training image according to the sample training image; calculate the accumulated gradient value according to the gradient of the coordinate direction of each pixel point to obtain the accumulated gradient value feature; determine the image size according to the sample training image; calculate the Fourier spectrum feature according to the image size to obtain the Fourier spectrum feature; calculate the related surface feature according to the sample training image to obtain the related surface feature; The calculation module is also used to perform cell division according to the sample training image to obtain a division unit; perform gradient strength calculation according to the division unit image corresponding to the division unit and the sample training image to obtain a first gradient strength corresponding to the sample training image and a second gradient strength corresponding to the division unit image; perform correlation coefficient calculation according to the first gradient strength, the second gradient strength, the sample training image and the division unit image to obtain a correlation surface feature.
7. A defect detection device for a printed circuit board, characterized in that: The device comprises: a memory, a processor, and a printed circuit board defect detection program stored in the memory and executable on the processor, wherein the printed circuit board defect detection program is configured to implement the printed circuit board defect detection method according to any one of claims 1 to 5.
8. A storage medium, characterized in that: The storage medium stores a defect detection program for a printed circuit board, and when the defect detection program for a printed circuit board is executed by a processor, the defect detection method for a printed circuit board as claimed in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Sewing stitch defect detection method
CN110348499A
Deep learning defect image recognition method and system based on ensemble learning
CN113139932A
Metal part surface quality control method and system based on image processing
CN114240942A