Two-dimensional code defect detection method and device, electronic equipment and readable storage medium
By performing defect detection and edge detection on QR code and workpiece images, the QR code area, defect area and workpiece profile are determined, and the problem of low QR code detection accuracy in the prior art is solved, and higher detection accuracy is achieved.
Patent Information
- Application Number
- CN202510620054.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-14
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2045-05-14
AI Technical Summary
In the prior art, the QR code defect detection scheme has the problem of limited detection accuracy.
By obtaining the target workpiece image and QR code image, the defect detection model is used to perform defect detection, determine the QR code area and defect area, and obtain the workpiece outline information in combination with the edge detection model to determine whether the QR code has regional offset defects.
It improves the accuracy of QR code defect detection and can quickly determine whether there are printing defects and regional offset defects in QR codes.
Smart Images

Figure CN120125922A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of defect detection, and particularly to a method, device, electronic device and readable storage medium for detecting two-dimensional code defects. Background Art
[0002] In high-precision traceability scenarios such as industrial production lines and intelligent warehouses, as the core data carrier, the integrity of the printing quality of two-dimensional codes directly affects the information readability and production yield. Therefore, it is necessary to detect two-dimensional code defects to ensure the usability of two-dimensional codes. However, in actual applications, due to the interference of complex environments and the superposition of multiple types of defects, the traditional two-dimensional code defect detection scheme has the problem of limited detection accuracy. Summary of the Invention
[0003] The main purpose of the present invention is to provide a method, device, electronic device and readable storage medium for detecting two-dimensional code defects, aiming to solve the problem of limited detection accuracy in the existing two-dimensional code defect detection scheme.
[0004] To achieve the above object, the present invention provides a method for detecting two-dimensional code defects, which includes: Obtain a target workpiece image and a two-dimensional code image corresponding to the two-dimensional code set on the target workpiece; Perform defect detection on the two-dimensional code image through a trained defect detection model to obtain a two-dimensional code area and a defect area corresponding to the target workpiece image; Determine whether there is a two-dimensional code printing defect on the target workpiece according to the two-dimensional code area and the defect area; Perform edge detection on the target workpiece image through a trained edge detection model to obtain workpiece contour information; Obtain two-dimensional code contour information corresponding to the two-dimensional code image, and determine whether there is a regional offset defect in the two-dimensional code of the target workpiece according to the two-dimensional code contour information and the workpiece contour information.
[0005] Optionally, before performing defect detection on the two-dimensional code image through a trained defect detection model to obtain a two-dimensional code area and a defect area corresponding to the target workpiece image, it includes: Obtain an initial defect detection model, where the pyramid pooling layer in the initial defect detection model is a dilated spatial pyramid pooling layer; Obtain defect detection training samples, and train the initial defect detection model through the defect detection training samples to obtain a trained defect detection model.
[0006] Optionally, training the initial defect detection model through the defect detection training samples includes: Obtain the real-time iteration count and the target iteration count; Determine the corresponding target learning rate according to the target iteration count and the real-time iteration count, where the target learning rate decreases in a cosine curve during the training of the initial defect detection model; Update the learning rate corresponding to the initial defect detection model to the target learning rate.
[0007] Optionally, the defect detection model includes a first dropout layer, and performing defect detection on the QR code image through the trained defect detection model includes: Obtain the real-time workpiece type quantity and the quantity of the first dataset categories corresponding to the defect detection model; Determine the first target dropout probability corresponding to the real-time workpiece type quantity according to the quantity of the first dataset categories, where the first target dropout probability is negatively correlated with the real-time workpiece type quantity; Set the dropout probability of the first dropout layer to the first target dropout probability.
[0008] Optionally, the determining whether the target workpiece has a QR code printing defect according to the QR code area and the defect area includes: Judge whether there is an overlapping area between the QR code area and the defect area; If there is an overlapping area between the QR code area and the defect area, determine that the target workpiece has a QR code printing defect.
[0009] Optionally, the workpiece contour information includes a set of workpiece contour point coordinates, the QR code contour includes QR code contour points, and the determining whether the QR code of the target workpiece has a regional offset defect according to the QR code contour information and the workpiece contour information includes: Map the QR code contour points onto the target workpiece image to obtain a set of QR code contour point coordinates corresponding to the QR code contour points; Construct the set of workpiece contour point coordinates into a K-D tree; For each QR code coordinate point in the set of QR code contour point coordinates, determine the nearest neighbor point to the QR code coordinate point in the K-D tree, and determine the edge distance between the QR code coordinate point and the nearest neighbor point; Judge whether the smallest edge distance is less than the distance threshold; If the smallest edge distance is less than the distance threshold, determine that the QR code of the target workpiece has a regional offset defect.
[0010] Optionally, the edge detection model includes a second dropout layer, and performing edge detection on the target workpiece image through the trained edge detection model includes: Obtaining the number of real-time workpiece types and the number of categories of the second dataset corresponding to the edge detection model; Determining a second target discard probability corresponding to the number of real-time workpiece types according to the number of categories of the second dataset, where the second target discard probability is negatively correlated with the number of real-time workpiece types; Setting the discard probability of the second dropout layer to the second target discard probability.
[0011] To achieve the above object, the present invention further provides a two-dimensional code defect detection device, and the two-dimensional code defect detection device includes: A first acquisition module, configured to acquire a target workpiece image and a two-dimensional code image corresponding to a two-dimensional code set on the target workpiece; A first detection module, configured to perform defect detection on the two-dimensional code image through a trained defect detection model to obtain a two-dimensional code area and a defect area corresponding to the target workpiece image; A first determination module, configured to determine whether there is a two-dimensional code printing defect on the target workpiece according to the two-dimensional code area and the defect area; A second detection module, configured to perform edge detection on the target workpiece image through a trained edge detection model to obtain workpiece contour information; A second acquisition module, configured to acquire two-dimensional code contour information corresponding to the two-dimensional code image, and determine whether there is a regional offset defect in the two-dimensional code of the target workpiece according to the two-dimensional code contour information and the workpiece contour information.
[0012] To achieve the above object, the present invention further provides an electronic device, and the electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the two-dimensional code defect detection method described above are implemented.
[0013] To achieve the above object, the present invention further provides a computer-readable storage medium, and a computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, the steps of the two-dimensional code defect detection method described above are implemented.
[0014] A method, device, electronic device and readable storage medium for detecting two-dimensional code defects proposed by the present invention, which acquire a target workpiece image and a two-dimensional code image corresponding to the two-dimensional code set on the target workpiece; perform defect detection on the two-dimensional code image through a trained defect detection model to obtain a two-dimensional code area and a defect area corresponding to the target workpiece image; determine whether there is a two-dimensional code printing defect on the target workpiece according to the two-dimensional code area and the defect area; perform edge detection on the target workpiece image through a trained edge detection model to obtain workpiece contour information; obtain two-dimensional code contour information corresponding to the two-dimensional code image, and determine whether there is a regional offset defect in the two-dimensional code of the target workpiece according to the two-dimensional code contour information and the workpiece contour information. The defect detection module is used to detect the two-dimensional code area and the defect area, so that it is possible to quickly judge whether there is a printing defect in the two-dimensional code. The edge detection module is used to detect the contour of the workpiece, so that it is possible to determine whether there is an offset in the position of the two-dimensional code image on the workpiece by comparison, improving the accuracy of two-dimensional code defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present invention and used together with the specification to explain the principles of the present invention.
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0017] Figure 1 It is a schematic flowchart of the first embodiment of the method for detecting two-dimensional code defects of the present invention; Figure 2 It is a schematic block diagram of the modules of the electronic device of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0018] 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. In order to enable those skilled in the art to better understand the solutions of the present application, the following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0019] The present invention provides a method for detecting two-dimensional code defects, referring to Figure 1 ,Figure 1 The flowchart of the first embodiment of the method for detecting two-dimensional code defects of the present invention is shown. The method includes the following steps: Step S10: Obtain an image of a target workpiece and a two-dimensional code image corresponding to the two-dimensional code set on the target workpiece; The target workpiece image is an image obtained by collecting an image of the target workpiece. The target workpiece is the workpiece with a two-dimensional code set in the product. The specific type of the target workpiece can be set based on the actual two-dimensional code setting requirements. In this embodiment and subsequent embodiments, the target workpiece is taken as a steering knuckle for illustration.
[0020] The two-dimensional code image is an image obtained by collecting an image of the two-dimensional code on the target workpiece.
[0021] In specific implementation, an image of the target workpiece containing the two-dimensional code can be obtained, and the position of the two-dimensional code in the target workpiece image can be extracted to obtain the two-dimensional code image; alternatively, the two-dimensional code on the target workpiece can be directly collected to obtain the two-dimensional code image; when the two-dimensional code image is extracted from the target workpiece image, the target workpiece image can be recognized to obtain the ROI (Region of Interest) corresponding to the two-dimensional code, or the user can mark the ROI of the two-dimensional code in the target workpiece image, and then the two-dimensional code image can be obtained.
[0022] Step S20: Perform defect detection on the two-dimensional code image through a trained defect detection model to obtain the two-dimensional code region and the defect region corresponding to the target workpiece image; The defect detection model is used to locate the two-dimensional code and defects in the two-dimensional code image, so as to determine the two-dimensional code region and the defect region.
[0023] The two-dimensional code region indicates the region where the two-dimensional code is located in the two-dimensional code image; the defect region indicates the region where the defect is located in the two-dimensional code image.
[0024] The specific type of the defect detection model can be set based on actual needs; in this embodiment and subsequent embodiments, the defect detection model is taken as the YOLOv8 instance segmentation network model for illustration.
[0025] Step S30: Determine whether the target workpiece has two-dimensional code printing defects according to the two-dimensional code region and the defect region; When there are defects in the QR code area, it indicates that the QR code was printed at the defective position during printing. Since the defects appear as unevenness such as depressions and protrusions on the surface of the workpiece, the part of the QR code printed on the defects will also be uneven, thus affecting the recognition of the QR code. Therefore, by comparing the QR code area with the defect area, it is possible to determine whether there are QR code printing defects on the target workpiece. Specifically, when there is an overlapping part between the QR code area and the defect area, it is considered that the target workpiece has a QR code printing defect. When there is no overlapping part between the QR code area and the defect area, it is considered that the target workpiece does not have a QR code printing defect.
[0026] Step S40: Perform edge detection on the target workpiece image through the trained edge detection model to obtain workpiece contour information. The edge detection model is used to detect the edge of the workpiece in the target workpiece image, so as to obtain the workpiece contour information of the target workpiece.
[0027] The workpiece contour information indicates the contour of the target workpiece; specifically, the workpiece contour information may include a set of coordinates of multiple contour points on the edge of the target workpiece.
[0028] The specific type of the edge detection model can be set according to actual needs. In this embodiment and subsequent embodiments, the edge detection model is taken as ConvNeXt-T as an example for illustration. The training dataset of the edge detection model can be obtained by collecting images of the coding angle, using the Canny operator to detect the edge of the steering knuckle in the image, and using the obtained edge map as the label image to construct a steering knuckle edge detection training dataset.
[0029] Step S50: Obtain the QR code contour information corresponding to the QR code image, and determine whether there is a regional offset defect in the QR code of the target workpiece according to the QR code contour information and the workpiece contour information.
[0030] The QR code contour information indicates the contour of the QR code; specifically, the QR code contour information can be obtained by detecting the QR code image; for example, the QR code contour information can be obtained through the edge of the ROI of the QR code in the QR code image; the QR code contour information may include a set of coordinates of multiple contour points of the QR code or the ROI edge.
[0031] It can be understood that the QR code contour information indicates the main position of the QR code, and the workpiece contour information indicates the main position of the workpiece. Therefore, by comparing the QR code contour information with the workpiece contour information, the relative position relationship between the QR code and the workpiece edge can be known. And when the QR code is too close to the edge of the target workpiece, it is considered that the printing position of the QR code is offset too much, and it is determined that there is a regional offset defect in the QR code.
[0032] After determining whether there are QR code printing defects and regional offset defects, analyze the results of the two types of defects. If the target workpiece has no QR code printing defects and no regional offset defects, it is considered that the QR code setting of the target workpiece is normal and can enter the next process; if the target workpiece has QR code printing defects or regional offset defects, it is considered that the QR code setting of the target workpiece is abnormal and needs to reprint the QR code or be scrapped; the subsequent operations based on whether the QR code setting is normal can be set according to actual needs.
[0033] In this embodiment, the defect detection module is used to detect the QR code area and the defect area, so that it can quickly determine whether there are printing defects in the QR code. The edge detection module is used to detect the contour of the workpiece, so that it can determine whether there is an offset in the position of the QR code image on the workpiece by comparison, improving the accuracy of QR code defect detection.
[0034] Furthermore, in the second embodiment of the QR code defect detection method of the present invention proposed based on the first embodiment of the present invention, before step S20, the following steps are included: Step S60, obtaining an initial defect detection model, where the pyramid pooling layer in the initial defect detection model is an atrous spatial pyramid pooling layer; Step S70, obtaining defect detection training samples and training the initial defect detection model with the defect detection training samples to obtain a trained defect detection model.
[0035] The existing pyramid pooling layer of YOLOv8 is SPPF (Spatial Pyramid Pooling Fast), but this application is used for defect detection of QR codes on workpieces, and defects on workpieces such as scratches usually appear as small features, and the pooling operation of SPPF will lose local details, so it will reduce the accuracy of defect detection; in order to improve the accuracy in the scenario of defect detection of QR codes on workpieces, in this embodiment, the SPPF of YOLOv8 is replaced with ASPP (Atrous Spatial Pyramid Pooling), and the atrous convolution of ASPP can expand the receptive field without reducing the resolution and retain spatial details, so it is more suitable for the application scenario of defect detection of QR codes on workpieces in this application and can improve the detection accuracy.
[0036] The defect detection training samples are used to train the defect detection model. Specifically, during the process of detecting appearance defects of the steering knuckle, an image containing a QR code can be collected at the angle of the printed QR code, and the image can be cropped into a QR code training image according to the ROI, and the QR code area and the defect area can be marked on the QR code training image to obtain the training samples. The defect detection training samples are a training data set containing multiple training samples. The number of training samples in the defect detection training samples can be set according to actual needs.
[0037] It should be noted that the specific settings in model training can be set according to actual needs, such as the loss function, the number of iterations, etc.
[0038] Furthermore, the step S70 includes the steps of: Step S71, obtaining the real-time iteration number and the target iteration number; Step S72, determining the corresponding target learning rate according to the target iteration number and the real-time iteration number, where the target learning rate decreases in a cosine curve during the training process of the initial defect detection model; Step S73, updating the learning rate corresponding to the initial defect detection model to the target learning rate.
[0039] The number of iterations epoch refers to the number of times that the entire training data set is completely traversed by the model once. The real-time iteration number is the number corresponding to the current iteration being performed. The target iteration number is the total number of iterations for training the defect detection model.
[0040] The learning rate is a parameter that controls the step size of gradient descent in each iteration update.
[0041] It can be understood that if the learning rate is too large, the convergence speed can be accelerated, but it may cause missing the optimal point or oscillation; while if the learning rate is too small, the chance of reaching the optimal point is increased, but it may cause slow convergence and increase the training time. In order to achieve a more optimal learning rate setting, in this embodiment, the learning rate is dynamically adjusted during the training process of the defect detection model. Specifically, the learning rate is set to decrease in a cosine curve:
[0042] where lr(t) is the target learning rate, t is the real-time iteration number, T is the target iteration number, lr max is the maximum learning rate, lr min is the minimum learning rate; the maximum learning rate and the minimum learning rate can be set in advance according to actual training needs.
[0043] By setting the learning rate to decrease in a cosine curve, the learning rate is set relatively high at the initial stage of training the defect detection model, thereby helping the defect detection model avoid local optima. Then, gradually reducing the learning rate can achieve fine feature extraction, enabling the defect detection model to converge stably and quickly while improving the defect detection accuracy of the defect detection model.
[0044] Furthermore, in the third embodiment of the QR code defect detection method of the present invention proposed based on the first embodiment of the present invention, the defect detection model includes a first dropout layer, and the step S20 includes the steps: Step S21, obtaining the number of real-time workpiece types and the number of categories of the first dataset corresponding to the defect detection model; Step S22, determining a first target discard probability corresponding to the number of real-time workpiece types according to the number of categories of the first dataset, where the first target discard probability is negatively correlated with the number of real-time workpiece types; Step S23, setting the discard probability of the first dropout layer to the first target discard probability.
[0045] YOLOv8 adopts a multi-level pyramid structure, and is gradually downsampled to 1 / 32 resolution through five 3×3 convolutions with a stride of 2, and feature layers P1 (64 channels), P2 (128 channels), P3 (256 channels), P4 (512 channels), and P5 (1024 channels) are constructed in sequence. Starting from the P2 layer, cross-stage feature fusion is performed through the C2f module (repeated 3, 6, 6, and 3 times respectively) after each level of downsampling.
[0046] In this embodiment, a first dropout layer is added between P4 and P5, which is used to randomly discard a part of neurons to prevent the model from overfitting.
[0047] The number of categories of the first dataset is the number of categories included in the dataset corresponding to the pre-trained model adopted by the defect detection model; for example, YOLOv8 adopts a pre-trained model on the COCO dataset, and the COCO (Microsoft Common Objects in Context) dataset contains 80 categories, so the corresponding number of categories of the first dataset is 80.
[0048] The number of real-time workpiece types is the number of models of workpieces that need to be processed on the current production line, such as the number of models of steering knuckles included on the current production line; in this embodiment, the first target discard probability is set to be negatively correlated with the number of real-time workpiece types. When the number of steering knuckle models on the production line is small, the number of steering knuckles with the same model is large, so the first target discard probability is increased to avoid overfitting. When the number of steering knuckle models on the production line is large, the first target discard probability is decreased to retain the defect features of the steering knuckle QR code; specifically:
[0049] Among them, p1 is the first target rejection probability, n is the number of real-time workpiece types, and C1 is the number of categories in the first dataset.
[0050] Taking the COCO dataset as an example, C1 is 80; The number of steering knuckle models is small and less than 80. It can be seen from the above formula that the smaller n is, the larger the probability p1 is, and more neurons are discarded; from the perspective of categories, in this case, the number of steering knuckle models is less than the number of categories in the COCO dataset. Therefore, more neurons are discarded, which is equivalent to discarding more features of the dataset and fewer features of the steering knuckle QR code, that is, highlighting the defective features of the steering knuckle QR code.
[0051] The number of steering knuckle models is large and greater than 80. In this case, the probability p1 directly jumps to 0, that is, no neurons are discarded; from the perspective of categories, in this case, the number of steering knuckle models is already greater than the number of categories in the COCO dataset. Discarding neurons in this case will result in discarding more steering knuckle QR code features compared to the dataset features. Therefore, setting the probability to 0 can retain the defective features of the steering knuckle QR code and ensure the detection accuracy.
[0052] Further, in the fourth embodiment of the QR code defect detection method of the present invention proposed based on the first embodiment of the present invention, the step S30 includes the steps: Step S31, determining whether there is an overlapping area between the QR code area and the defect area; Step S32, if there is an overlapping area between the QR code area and the defect area, determining that the target workpiece has a QR code printing defect.
[0053] If there is no overlapping area between the QR code area and the defect area, determining that the target workpiece does not have a QR code printing defect.
[0054] When there is an overlapping area between the QR code area and the defect area, it means that the QR code is printed on the defect, which will affect the recognition of the QR code. Therefore, it is determined that the target workpiece has a QR code printing defect; conversely, when there is no overlapping area between the QR code area and the defect area, it means that the QR code is printed on a flat surface, which can ensure the recognition of the QR code. Therefore, it is determined that the target workpiece does not have a QR code printing defect.
[0055] Furthermore, in the fifth embodiment of the QR code defect detection method of the present invention proposed based on the first embodiment of the present invention, the workpiece contour information includes a set of workpiece contour point coordinates, the QR code contour includes QR code contour points, and the step S50 includes the steps: determining whether there is a regional offset defect in the QR code of the target workpiece based on the QR code contour information and the workpiece contour information includes: Step S51, mapping the QR code contour points onto the target workpiece image to obtain a set of QR code contour point coordinates corresponding to the QR code contour points; Step S52, constructing the set of workpiece contour point coordinates into a K-D tree; Step S53, for each QR code coordinate point in the set of QR code contour point coordinates, determining the nearest neighbor point to the QR code coordinate point in the K-D tree, and determining the edge distance between the QR code coordinate point and the nearest neighbor point; Step S54, determining whether the smallest edge distance is less than a distance threshold; Step S55, if the smallest edge distance is less than the distance threshold, determining that there is a regional offset defect in the QR code of the target workpiece.
[0056] If the smallest edge distance is greater than or equal to the distance threshold, determining that there is no regional offset defect in the QR code of the target workpiece.
[0057] A K-D (k-dimensional) tree is a tree-shaped data structure for storing instance points in a k-dimensional space for quick retrieval thereof; The QR code contour points can be obtained from the QR code area output by the defect detection module.
[0058] When the QR code image is cropped from the target workpiece image, the ROI position corresponding to the QR code during the cropping process can be obtained, and based on the position of the ROI on the target workpiece image, the position of the QR code contour points on the target workpiece image can be determined, realizing the mapping of the QR code contour points on the target workpiece image, thereby determining the QR code contour point coordinates corresponding to the QR code contour points on the target workpiece image, and further obtaining the set of QR code contour point coordinates by integrating the QR code contour point coordinates, realizing accurate coordinate mapping.
[0059] When the QR code image is directly acquired, it can be mapped onto the target workpiece image by means of coordinate matching.
[0060] The nearest neighbor point is the point in the K-D tree that is closest to the QR code coordinate point, that is, it symbolizes the point in the contour of the target workpiece that is closest to the QR code coordinate point; the edge distance is the distance between the QR code coordinate point and the nearest neighbor point.
[0061] After determining all the edge distances, the positional relationship between the two-dimensional code contour and the target workpiece contour can be determined based on the edge distances. When there is a too small edge distance, it indicates that there is a position with a too small distance between the two-dimensional code contour and the target workpiece contour. Therefore, it is considered that there is a positional deviation. To simplify the comparison, in this embodiment, the minimum edge distance is first determined, and then the minimum edge distance is compared with the distance threshold. When the minimum edge distance is less than the distance threshold, it is considered that there is a position with a too small distance between the two-dimensional code contour and the target workpiece contour, and there is a regional deviation defect. When the minimum edge distance is greater than the distance threshold, it is considered that the required distance is maintained between the two-dimensional code contour and the target workpiece contour, and there is no regional deviation defect.
[0062] The specific value of the distance threshold can be set based on actual needs.
[0063] Further, in the sixth embodiment of the two-dimensional code defect detection method of the present invention proposed based on the first embodiment of the present invention, the edge detection model includes a second dropout layer, and the step S40 includes the steps: Step S41, obtaining the real-time workpiece type quantity and the second data set category quantity corresponding to the edge detection model; Step S42, determining a second target discard probability corresponding to the real-time workpiece type quantity according to the second data set category quantity, where the second target discard probability is negatively correlated with the real-time workpiece type quantity; Step S43, setting the discard probability of the second dropout layer to the second target discard probability.
[0064] In this embodiment, the edge detection model ConvNeXt-T is taken as an example for illustration. Since the target workpiece image is larger than the two-dimensional code image, in order to improve the detection efficiency, the fully connected layer in ConvNeXt-T is replaced with a second dropout layer in this embodiment.
[0065] The second data set category quantity is the number of categories included in the data set corresponding to the pre-trained model adopted by the edge detection model. For example, ConvNeXt-T adopts a pre-trained model on the ImageNet data set, and the ImageNet data set contains 1000 categories. Therefore, the corresponding second data set category quantity is 1000.
[0066] The number of real-time workpiece types is the number of models of workpieces to be processed on the current production line, such as the number of models of steering knuckles included on the current production line; in this embodiment, the second target discard probability is set to be negatively correlated with the number of real-time workpiece types. When the number of steering knuckle models on the production line is small, the number of steering knuckles with the same model is large. Therefore, the second target discard probability is increased to avoid overfitting. When the number of steering knuckle models on the production line is large, the second target discard probability is decreased to retain the steering knuckle features; specifically:
[0067] Among them, p2 is the second target discard probability, n is the number of real-time workpiece types, and C2 is the number of categories in the second dataset.
[0068] Taking the use of the ImageNet dataset as an example, C2 is 1000; The number of models of steering knuckles is small and less than 1000. It can be seen from the above formula that the smaller n2 is, the larger the probability p2 is, and more neurons are discarded; from the perspective of categories, in this case, the number of models of steering knuckles is less than the number of categories in the ImageNet dataset. Therefore, discarding more neurons is equivalent to discarding more features of the dataset and less features of the steering knuckle, that is, highlighting the features of the steering knuckle.
[0069] The number of models of steering knuckles is large and greater than 1000. In this case, the probability p2 directly jumps to 0, that is, no neurons are discarded; from the perspective of categories, in this case, the number of models of steering knuckles is already greater than the number of categories in the ImageNet dataset. Discarding neurons in this case will result in discarding more steering knuckle features than dataset features. Therefore, setting the probability to 0 can retain the steering knuckle features and ensure the detection accuracy.
[0070] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that this application is not limited by the described action sequence, because according to this application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0071] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present application, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc) and includes several instructions to enable a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present application.
[0072] The present application also provides a two-dimensional code defect detection device for implementing the above two-dimensional code defect detection method. The two-dimensional code defect detection device includes: A first acquisition module, configured to acquire a target workpiece image and a two-dimensional code image corresponding to the two-dimensional code set on the target workpiece; A first detection module, configured to perform defect detection on the two-dimensional code image through a trained defect detection model to obtain a two-dimensional code area and a defect area corresponding to the target workpiece image; A first determination module, configured to determine whether there is a two-dimensional code printing defect on the target workpiece according to the two-dimensional code area and the defect area; A second detection module, configured to perform edge detection on the target workpiece image through a trained edge detection model to obtain workpiece contour information; A second acquisition module, configured to acquire two-dimensional code contour information corresponding to the two-dimensional code image, and determine whether there is a regional offset defect in the two-dimensional code of the target workpiece according to the two-dimensional code contour information and the workpiece contour information.
[0073] This two-dimensional code defect detection device detects the two-dimensional code area and the defect area through the defect detection module, so as to quickly determine whether there is a printing defect in the two-dimensional code. The edge detection module detects the contour of the workpiece, so as to determine whether there is an offset in the position of the two-dimensional code image on the workpiece by comparison, improving the accuracy of two-dimensional code defect detection.
[0074] It should be noted that the first acquisition module in this embodiment can be used to execute step S10 in the embodiment of the present application, the first detection module in this embodiment can be used to execute step S20 in the embodiment of the present application, the first determination module in this embodiment can be used to execute step S30 in the embodiment of the present application, the second detection module in this embodiment can be used to execute step S40 in the embodiment of the present application, and the second acquisition module in this embodiment can be used to execute step S50 in the embodiment of the present application.
[0075] Further, the device further includes: A third acquisition module, configured to acquire an initial defect detection model, where the pyramid pooling layer in the initial defect detection model is an atrous spatial pyramid pooling layer; A fourth acquisition module, configured to acquire defect detection training samples, and train the initial defect detection model with the defect detection training samples to obtain a trained defect detection model.
[0076] Further, the fourth acquisition module includes: A first acquisition unit, configured to acquire a real-time iteration number and a target iteration number; A first determination unit, configured to determine a corresponding target learning rate according to the target iteration number and the real-time iteration number, where the target learning rate decreases in a cosine curve during the training process of the initial defect detection model; A first update unit, configured to update the learning rate corresponding to the initial defect detection model to the target learning rate.
[0077] Further, the defect detection model includes a first dropout layer, and the first detection module includes: A second acquisition unit, configured to acquire the real-time workpiece type number and the number of categories of the first data set corresponding to the defect detection model; A second determination unit, configured to determine a first target discard probability corresponding to the real-time workpiece type number according to the number of categories of the first data set, where the first target discard probability is negatively correlated with the real-time workpiece type number; A first setting unit, configured to set the discard probability of the first dropout layer to the first target discard probability.
[0078] Further, the first determination module includes: A first judgment unit, configured to judge whether there is an overlapping area between the two-dimensional code area and the defect area; A third determination unit, configured to determine that the target workpiece has a two-dimensional code printing defect if there is an overlapping area between the two-dimensional code area and the defect area.
[0079] Further, the workpiece contour information includes a set of workpiece contour point coordinates, the two-dimensional code contour includes two-dimensional code contour points, and the second acquisition module includes: A first mapping unit, configured to map the two-dimensional code contour points to the target workpiece image to obtain a set of two-dimensional code contour point coordinates corresponding to the two-dimensional code contour points; A first construction unit, configured to construct the set of workpiece contour point coordinates into a K-D tree; A fourth determination unit, configured to, for each two-dimensional code coordinate point in the set of two-dimensional code contour point coordinates, determine a nearest neighbor point in the K-D tree that is closest to the two-dimensional code coordinate point, and determine an edge distance between the two-dimensional code coordinate point and the nearest neighbor point; A second determination unit, configured to determine whether the smallest one of the edge distances is less than a distance threshold; A fifth determination unit, configured to, if the smallest one of the edge distances is less than the distance threshold, determine that there is an offset defect in the two-dimensional code existence area of the target workpiece.
[0080] Further, the edge detection model includes a second dropout layer, and the second detection module includes: A third acquisition unit, configured to acquire the number of real-time workpiece types and the number of categories of the second data set corresponding to the edge detection model; A sixth determination unit, configured to determine a second target discard probability corresponding to the number of real-time workpiece types according to the number of categories of the second data set, where the second target discard probability is negatively correlated with the number of real-time workpiece types; A second setting unit, configured to set the discard probability of the second dropout layer to the second target discard probability.
[0081] Referring to Figure 2 , in terms of hardware structure, the electronic device may include components such as a communication module 10, a memory 20, and a processor 30. In the electronic device, the processor 30 is respectively connected to the memory 20 and the communication module 10. A computer program is stored on the memory 20, and the computer program is simultaneously executed by the processor 30. When the computer program is executed, the steps of the above method embodiment are implemented.
[0082] The communication module 10 can be connected to an external communication device through a network. The communication module 10 can receive requests sent by the external communication device, and can also send requests, instructions, and information to the external communication device. The external communication device can be other electronic devices, servers, or Internet of Things devices, such as a TV, etc.
[0083] The memory 20 can be used to store software programs and various data. The memory 20 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function (such as acquiring an image of a target workpiece and a two-dimensional code image corresponding to a two-dimensional code set on the target workpiece), etc.; the data storage area can include a database, and the data storage area can store data or information created according to the use of the system. In addition, the memory 20 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0084] The processor 30 is the control center of the electronic device. It connects various parts of the entire electronic device using various interfaces and circuits. By running or executing software programs and / or modules stored in the memory 20, and by invoking the data stored in the memory 20, it executes various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 30 may include one or more processing units; optionally, the processor 30 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 30 either.
[0085] Although Figure 2 not shown, the above-mentioned electronic device may further include a circuit control module, which is used to connect to the power supply to ensure the normal operation of other components. Those skilled in the art can understand that Figure 2 the structure of the electronic device shown in does not constitute a limitation on the electronic device, and it may include more or fewer components than shown in the figure, or combine some components, or have different component arrangements.
[0086] The present invention also proposes a computer-readable storage medium, on which a computer program is stored. The computer-readable storage medium may be Figure 2 the memory 20 in the electronic device as described above, or at least one of ROM (Read-Only Memory), RAM (Random Access Memory), magnetic disk, and optical disc. The computer-readable storage medium includes several instructions for causing a terminal device having a processor (which may be a TV, a car, a mobile phone, a computer, a server, a terminal, or a network device, etc.) to execute the methods described in various embodiments of the present invention.
[0087] In the present invention, the terms "first", "second", "third", "fourth", and "fifth" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0088] In the description of this specification, the descriptions referring to terms such as "one embodiment", "some embodiments", "examples", "specific examples", or "some examples", etc., mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0089] Although the embodiments of the present invention have been shown and described above, the scope of protection of the present invention is not limited thereto. It can be understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those of ordinary skill in the art can make changes, modifications, and substitutions to the above embodiments within the scope of the present invention, and these changes, modifications, and substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A two-dimensional code defect detection method, characterized in that: The two-dimensional code defect detection method comprises: Acquire a target workpiece image and a two-dimensional code image corresponding to a two-dimensional code set on the target workpiece; Perform defect detection on the two-dimensional code image through the trained defect detection model to obtain the two-dimensional code area and defect area corresponding to the target workpiece image; Determining whether the target workpiece has a two-dimensional code printing defect according to the two-dimensional code area and the defect area; Performing edge detection on the target workpiece image through a trained edge detection model to obtain workpiece contour information; The two-dimensional code contour information corresponding to the two-dimensional code image is obtained, and it is determined whether the two-dimensional code of the target workpiece has a regional offset defect according to the two-dimensional code contour information and the workpiece contour information.
2. The two-dimensional code defect detection method according to claim 1, characterized in that: The method of performing defect detection on the two-dimensional code image through a trained defect detection model to obtain the two-dimensional code area and the defect area corresponding to the target workpiece image comprises: Acquire an initial defect detection model, wherein the pyramid pooling layer in the initial defect detection model is a hole space pyramid pooling layer; A defect detection training sample is obtained, and the initial defect detection model is trained using the defect detection training sample to obtain a trained defect detection model.
3. The two-dimensional code defect detection method according to claim 2, characterized in that: The training of the initial defect detection model by using the defect detection training samples includes: Get the real-time iteration number and the target iteration number; Determining a corresponding target learning rate according to the target number of iterations and the real-time number of iterations, wherein the target learning rate decreases in a cosine curve during the training process of the initial defect detection model; The learning rate corresponding to the initial defect detection model is updated to the target learning rate.
4. The two-dimensional code defect detection method according to claim 1, characterized in that: The defect detection model includes a first discarded layer, and performing defect detection on the two-dimensional code image through the trained defect detection model includes: Obtaining the number of real-time workpiece types and the number of first data set categories corresponding to the defect detection model; Determining a first target rejection probability corresponding to the number of the real-time artifact types according to the number of the first data set categories, wherein the first target rejection probability is negatively correlated with the number of the real-time artifact types; The discard probability of the first discard layer is set to the first target discard probability.
5. The two-dimensional code defect detection method according to claim 1, characterized in that: The determining whether the target workpiece has a two-dimensional code printing defect according to the two-dimensional code area and the defect area includes: Determine whether there is an overlapping area between the two-dimensional code area and the defect area; If there is an overlapping area between the two-dimensional code area and the defect area, it is determined that there is a two-dimensional code printing defect in the target workpiece.
6. The two-dimensional code defect detection method according to claim 1, characterized in that: The workpiece contour information includes a workpiece contour point coordinate set, the two-dimensional code contour includes two-dimensional code contour points, and determining whether the two-dimensional code of the target workpiece has a regional offset defect according to the two-dimensional code contour information and the workpiece contour information includes: Mapping the two-dimensional code contour points onto the target workpiece image to obtain a set of two-dimensional code contour point coordinates corresponding to the two-dimensional code contour points; Constructing the workpiece contour point coordinate set into a KD tree; For each two-dimensional code coordinate point in the two-dimensional code contour point coordinate set, determine the adjacent point closest to the two-dimensional code coordinate point in the KD tree, and determine the edge distance between the two-dimensional code coordinate point and the adjacent point; Determine whether the minimum edge distance is less than a distance threshold; If the minimum edge distance is less than the distance threshold, it is determined that the two-dimensional code of the target workpiece has a regional offset defect.
7. The two-dimensional code defect detection method according to claim 1, characterized in that: The edge detection model includes a second discarded layer, and performing edge detection on the target workpiece image through the trained edge detection model includes: Acquire the number of real-time workpiece types and the number of second data set categories corresponding to the edge detection model; Determining a second target rejection probability corresponding to the number of the real-time artifact types according to the number of the second data set categories, wherein the second target rejection probability is negatively correlated with the number of the real-time artifact types; The discard probability of the second discard layer is set to the second target discard probability.
8. A two-dimensional code defect detection device, characterized in that: The two-dimensional code defect detection device comprises: A first acquisition module is used to acquire a target workpiece image and a two-dimensional code image corresponding to a two-dimensional code set on the target workpiece; A first detection module is used to perform defect detection on the two-dimensional code image through a trained defect detection model to obtain a two-dimensional code area and a defect area corresponding to the target workpiece image; A first determination module, configured to determine whether the target workpiece has a two-dimensional code printing defect according to the two-dimensional code area and the defect area; A second detection module is used to perform edge detection on the target workpiece image through a trained edge detection model to obtain workpiece contour information; The second acquisition module is used to acquire the two-dimensional code contour information corresponding to the two-dimensional code image, and determine whether the two-dimensional code of the target workpiece has a regional offset defect according to the two-dimensional code contour information and the workpiece contour information.
9. An electronic device, characterized in that: The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the two-dimensional code defect detection method as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the two-dimensional code defect detection method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Photovoltaic panel defect diagnosis method based on edge detection convolutional neural network
CN113837994A
Two-dimensional code defect identification method and device of battery, equipment and storage medium
CN116542926A
Deep learning-based jet printing color two-dimensional code defect detection method
CN118115782A
Classification detection method and system for detecting two-dimensional code label defects based on lightweight convolution
CN119250091A
Apparatus and method for generating image-included two dimensional code
US20160078336A1