DM two-dimensional code identification method and system and readable storage medium

Through the algorithm of yolov5 coarse positioning and affine transformation correction, the problem of low success rate of DM QR code recognition in complex environments is solved, and higher recognition accuracy and robustness are achieved.

CN120373325APending Publication Date: 2025-07-25HANGZHOU HUICUI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510211785.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-25
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

The prior art is difficult to effectively identify DM QR codes in complex environments, especially in dynamic and complex environments with low recognition success rate.

Method used

Yolov5 is used to replace traditional threshold binarization, combined with connectivity domain screening, and the new positioning DM code "L"-type edge algorithm and affine transformation correction are used to improve the recognition accuracy through three processing.

Benefits of technology

It significantly improves the recognition success rate of DM QR code in complex environments and enhances the robustness of environmental interference.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120373325A_ABST
    Figure CN120373325A_ABST
Patent Text Reader

Abstract

The invention discloses a DM two-dimensional code recognition method and system and a readable storage medium. According to the method, aiming at the problem of difficulty in positioning the DM two-dimensional code under a complex environment condition, a method of carrying out coarse positioning by adopting the yov5 is adopted to replace a traditional method of carrying out coarse positioning by carrying out connected domain screening after threshold binarization, so that the positioning accuracy is greatly improved, and meanwhile, the analysis processing speed of a DM code region is also obviously improved. According to the method, a novel DM code L-shaped edge positioning algorithm is provided, and then the algorithm scheme of affine transformation correction is carried out by finding three positioning points, so that the influence on environmental interference is obviously improved, and the DM analysis algorithm has higher robustness. DM code analysis is carried out on the different processed images for three times, so that the DM code identification success rate is further improved. According to the method, the DM two-dimensional code under various illumination conditions can be effectively identified, and the identification success rate of the DM code under the complex environment condition is obviously improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of two-dimensional code recognition, and more particularly, to a method, system, and readable storage medium for recognizing DM two-dimensional codes. Background Art

[0002] In the industrial field, using two-dimensional codes to identify industrial products and components to achieve production tracking, assembly management, life cycle maintenance, etc. of products and components has become an industry standard for automated industries. Among them, Data Matrix (DM) two-dimensional codes are favored by the industrial and logistics industries due to their excellent data compression ability and strong error correction ability. Different from the packaging of food, drugs, and other consumer products, the application environment of industrial two-dimensional codes is usually relatively harsh, and the recognition of two-dimensional codes is usually accompanied by problems such as noise, overexposure, wear, and pollution. Therefore, the DM code extraction algorithm for complex backgrounds has important significance and urgent market demand.

[0003] Currently, the technology for recognizing a single DM code in an ideal environment has been very mature. The main challenges of DM codes in actual application scenarios come from the recognition of two-dimensional codes in dynamic and complex environments. At present, no recognition algorithm for parsing DM codes in complex environments has been found. Summary of the Invention

[0004] The purpose of the present application is to provide a method, system, and readable storage medium for recognizing DM two-dimensional codes. By designing a new algorithm for locating the "L" - shaped edge of the DM code and then an algorithm for affine transformation correction by finding three positioning points, the influence of environmental interference is significantly improved, making the DM parsing algorithm more robust, thereby improving the recognition success rate of DM codes under complex environmental conditions.

[0005] The first aspect of the present application provides a method for recognizing a DM two - dimensional code, the method comprising:

[0006] Obtain the original image with a DM two - dimensional code;

[0007] Use the yolov5 detection model to obtain the ROI area of the DM two - dimensional code,

[0008] Extract the ROI image from the ROI area of the DM two - dimensional code and pre - process the ROI image;

[0009] Use lindmtx to recognize the pre - processed ROI image. If the recognition is successful, output the recognized DM two - dimensional code; if the recognition is not successful, perform the following steps:

[0010] Use the Otsu method to binarize the pre - processed ROI image and extract the contour of the DM two - dimensional code;

[0011] Filter out the interference area according to the contour of the DM two-dimensional code to obtain the binary ROI image after removing the interference;

[0012] Use lindmtx to identify the binary ROI image after removing the interference. If the identification is successful, output the identified DM two-dimensional code; if the identification is not successful, perform the following steps:

[0013] Perform line detection according to the inflection points on the contour of the DM two-dimensional code,

[0014] Locate the edge points according to the line detection results and determine the affine transformation matrix according to the edge points;

[0015] Perform affine correction on the binary ROI image after removing the interference using the affine matrix;

[0016] Use Zbar to identify the binary ROI image after affine correction. If the identification is successful, output the identified DM two-dimensional code; if the identification is not successful, determine it as an identification failure and exit the identification task.

[0017] Optionally, the preprocessing of the ROI image includes: performing median filtering on the ROI graph, grayscaling, and finally performing gray enhancement.

[0018] Optionally, the extraction of the DM two-dimensional code contour is specifically:

[0019] Perform morphological closing operation on the binary ROI image, and find the largest circumscribed rectangle in the binary ROI image as the DM two-dimensional code contour.

[0020] Optionally, the performing line detection according to the inflection points on the DM two-dimensional code contour is specifically:

[0021] Find all the inflection points on the largest circumscribed rectangle in the binary ROI image, set the found inflection points and the nearby neighborhoods to zero, disconnect the contour, and obtain several line segments;

[0022] Sort all the line segments in descending order according to their lengths, take the first four line segments, perform Hough line detection, and screen out the two lines on the "L" sides of the DM two-dimensional code.

[0023] Optionally, the screening out of the two lines on the "L" sides of the DM two-dimensional code is specifically:

[0024] Find the line segment L1 with the longest length;

[0025] Find all the line segments that are closest to 90 degrees to the line segment L1 with the longest length from the other line segments, then take the line segment L2 with the longest length from these line segments, and use L1 and L2 as the lines on the "L" sides of the DM two-dimensional code.

[0026] Optionally, locate the edge points according to the straight line detection result, and determine the affine transformation matrix according to the edge points. Specifically:

[0027] Calculate the intersection point A1 of two line segments L1 and L2;

[0028] Find two points A2 and A3 on the DM two-dimensional code contour that are both less than a preset threshold from line segment L1 and line segment L2 and are farthest from the intersection point A1. Then, judge the order of the three points A1, A2, and A3 through the positive and negative of the inner product of vectors;

[0029] According to the order of the three points A1, A2, and A3, obtain three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of A1, A2, and A3;

[0030] Calculate the affine transformation matrix according to rectP1, rectP2, and rectP3.

[0031] The second aspect of the present invention provides a DM two-dimensional code recognition system, including a memory and a processor. The memory includes a DM two-dimensional code recognition method program. When the DM two-dimensional code recognition method program is executed by the processor, the following method steps are implemented:

[0032] Obtain the original image with the DM two-dimensional code;

[0033] Use the yolov5 detection model to obtain the ROI area of the DM two-dimensional code,

[0034] Extract the ROI image in the ROI area of the DM two-dimensional code and preprocess the ROI image;

[0035] Use lindmtx to recognize the preprocessed ROI image. If the recognition is successful, output the recognized DM two-dimensional code; if the recognition is not successful, execute the following steps:

[0036] Use the Otsu method to binarize the preprocessed ROI image and extract the DM two-dimensional code contour;

[0037] Filter out the interference area according to the DM two-dimensional code contour to obtain the binarized ROI image after removing interference;

[0038] Use lindmtx to recognize the binarized ROI image after removing interference. If the recognition is successful, output the recognized DM two-dimensional code; if the recognition is not successful, execute the following steps:

[0039] Perform straight line detection according to the inflection points on the DM two-dimensional code contour,

[0040] Locate the edge points according to the straight line detection result, and determine the affine transformation matrix according to the edge points;

[0041] Perform affine correction on the binarized ROI image after removing interference using an affine matrix;

[0042] Use Zbar to recognize the binarized ROI image after affine correction. If the recognition is successful, output the recognized DM QR code; if the recognition is unsuccessful, determine it as a recognition failure and exit the recognition task.

[0043] Optionally, the preprocessing of the ROI image includes: performing median filtering on the ROI graph, graying it, and finally performing gray-scale enhancement;

[0044] The extraction of the DM QR code contour is specifically:

[0045] Perform morphological closing operation on the binarized ROI image, and find the largest circumscribed rectangle in the binarized ROI image as the DM QR code contour;

[0046] The straight line detection based on the inflection points on the DM QR code contour is specifically:

[0047] Find all the inflection points on the largest circumscribed rectangle in the binarized ROI image, set the found inflection points and their nearby neighborhoods to zero, disconnect the contour, and obtain several line segments;

[0048] Sort all the line segments in descending order according to their lengths, take the first four line segments, perform Hough straight line detection, and screen out two straight lines on the "L" sides of the DM QR code.

[0049] Optionally, the screening of the two straight lines on the "L" sides of the DM QR code is specifically:

[0050] Find the line segment L1 with the longest length;

[0051] Find all the line segments that are closest to 90 degrees to the longest line segment L1 from the other line segments, then take the line segment L2 with the longest length from these line segments, and use L1 and L2 as the straight lines on the "L" sides of the DM QR code.

[0052] Optionally, locate the edge points according to the straight line detection result, and determine the affine transformation matrix according to the edge points, specifically:

[0053] Calculate the intersection point A1 of the two line segments L1 and L2;

[0054] Find two points A2 and A3 on the DM QR code contour that are both less than a preset threshold distance from the line segments L1 and L2 and are the farthest from the intersection point A1, and then judge the order of the three points A1, A2, and A3 through the positive and negative of the inner product of vectors;

[0055] According to the order of three points A1, A2, and A3, obtain three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of A1, A2, and A3;

[0056] Calculate the affine transformation matrix based on rectP1, rectP2, and rectP3.

[0057] The third aspect of the present invention provides a computer-readable storage medium, which includes a program for the DM two-dimensional code recognition method. When the program for the DM two-dimensional code recognition method is executed by a processor, the steps of a DM two-dimensional code recognition method are implemented.

[0058] As can be seen from the above, the present application provides a DM two-dimensional code recognition method, system, and readable storage medium. The present application can effectively recognize DM two-dimensional codes under diverse lighting conditions, and significantly improve the recognition success rate of DM codes under complex environmental conditions.

[0059] Aiming at the problem of difficult positioning of DM two-dimensional codes under complex environmental conditions, the present application uses the method of rough positioning with yolov5 to replace the method of rough positioning by performing connected component screening after traditional threshold binarization, which greatly improves the positioning accuracy. At the same time, for the analysis and processing of the DM code area, the rate will also be significantly improved. The present application proposes a new "L"-shaped edge algorithm for positioning DM codes, and then an algorithm scheme for affine transformation correction by finding three positioning points, which significantly improves the influence of environmental interference and makes the DM parsing algorithm more robust. By parsing the DM code three times on the images processed differently, the recognition success rate of the DM code is further improved.

[0060] Other features and advantages of the present application will be described in the subsequent specification, and part of them will become obvious from the specification, or can be understood by implementing the embodiments of the present application. The objectives and other advantages of the present application can be achieved and obtained through the structures specifically pointed out in the written specification, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required for the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.

[0062] Figure 1 It is a flowchart of a DM two-dimensional code recognition method provided for an embodiment of the present application.

[0063] Figure 2The original image with a DM two-dimensional code provided by the embodiment of the present application.

[0064] Figure 3 The ROI region image of the DM two-dimensional code provided by the embodiment of the present application.

[0065] Figure 4 The preprocessed ROI image provided by the embodiment of the present application.

[0066] Figure 5 The binary ROI image after removing interference provided by the embodiment of the present application.

[0067] Figure 6 The maximum circumscribed contour diagram provided by the embodiment of the present application.

[0068] Figure 7 The schematic diagram of the line segment obtained from the maximum circumscribed contour diagram provided by the embodiment of the present application.

[0069] Figure 8 The schematic diagram of the DM straight line edge provided by the embodiment of the present application.

[0070] Figure 9 The vector relationship diagram in the two-dimensional plane provided by the embodiment of the present application.

[0071] Figure 10 The image after affine transformation correction of the binary image provided by the embodiment of the present application.

[0072] Figure 11 The image in which the DM two-dimensional code is successfully recognized by using the method described in the present application provided by the embodiment of the present application.

[0073] Figure 12 A DM two-dimensional code recognition system provided by the embodiment of the present application. Detailed implementation manners

[0074] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with 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 the embodiments. Usually, the components of the embodiments of the present application described and illustrated herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application claimed, but merely represents the selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.

[0075] It should be noted that similar reference numerals and letters denote similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, terms such as "first" and "second" are only used for distinguishing descriptions and cannot be construed as indicating or implying relative importance.

[0076] Please refer to Figure 1 , which is a method for identifying DM two-dimensional codes in some embodiments of the present application. The method includes:

[0077] S102: Obtain the original image with a DM two-dimensional code;

[0078] It should be noted that the DM two-dimensional code, namely the Data Matrix two-dimensional code, is a matrix two-dimensional barcode, belonging to a high-density and high-reliability information storage and transmission technology, and is widely used in many fields.

[0079] As a specific embodiment, the original image with a DM two-dimensional code obtained in this embodiment is as Figure 2 shown.

[0080] S104: Use the yolov5 detection model to obtain the ROI region of the DM two-dimensional code;

[0081] It should be noted that the present application uses the yolov5 detection model to obtain the ROI region of the DM two-dimensional code, which solves the problem of low success rate of traditional image processing in locating the ROI region of the DM two-dimensional code. Image preprocessing for the ROI region can greatly reduce the influence of interference on subsequent recognition. In addition, it will have a higher operation efficiency than libdmtx in searching and locating in the whole image.

[0082] The YOLOv5 is an efficient object detection model implemented based on PyTorch, developed and maintained by the Ultralytics team. YOLOv5 can perform object detection and classification simultaneously in a single forward pass.

[0083] ROI refers to "Region of Interest". The ROI image is a partial image with specific significance or value delimited and extracted from the original image through a specific algorithm or manual interaction.

[0084] As a specific embodiment, in this embodiment, the yolov5 detection model is used to obtain the ROI region of the DM two-dimensional code from Figure 2 as Figure 3 shown.

[0085] S106: Extract the ROI image in the ROI region of the DM two-dimensional code and preprocess the ROI image; The preprocessed ROI image is as Figure 4as shown

[0086] S108: Use lindmtx to identify the preprocessed ROI image. If the identification is successful, output the identified DM two-dimensional code; if the identification is not successful, execute S110;

[0087] It should be noted that lindmtx is a software tool specifically used for image analysis and identification.

[0088] S110: Binarize the preprocessed ROI image using the Otsu method, and extract the DM two-dimensional code contour;

[0089] S112: Filter out the interference area according to the DM two-dimensional code contour to obtain the binarized ROI image after removing interference; The binarized ROI image after removing interference is as Figure 5 as shown

[0090] S114: Use lindmtx to identify the binarized ROI image after removing interference. If the identification is successful, output the identified DM two-dimensional code; if the identification is not successful, execute S116;

[0091] S116: Perform line detection according to the inflection points on the DM two-dimensional code contour,

[0092] S118: Locate the edge points according to the line detection result, and determine the affine transformation matrix according to the edge points;

[0093] S120: Perform affine correction on the binarized ROI image after removing interference using the affine matrix;

[0094] S122: Use Zbar to identify the binarized ROI image after affine correction. If the identification is successful, output the identified DM two-dimensional code; if the identification is not successful, determine it as an identification failure and exit the identification task.

[0095] According to the embodiment of the present invention, the preprocessing of the ROI image includes: performing median filtering on the ROI graph, graying it, and finally performing gray enhancement.

[0096] According to the embodiment of the present invention, the extraction of the DM two-dimensional code contour is specifically:

[0097] Perform morphological closing operation on the binarized ROI image, and find the largest circumscribed rectangle existing in the binarized ROI image as the DM two-dimensional code contour.

[0098] It should be noted that in this application, the Otsu method is used to binarize the gray ROI image, and morphological closing operation is performed to find the area with the largest circumscribed rectangle in the image, that is, the foreground area of the DM two-dimensional code, to further filter the influence of other noises.

[0099] This application Figure 5 obtains the maximum circumscribed contour diagram as Figure 6 shown.

[0100] According to an embodiment of the present invention, for the straight line detection based on the inflection points on the DM two-dimensional code contour, specifically:

[0101] Find all the inflection points on the maximum circumscribed rectangle in the binarized ROI image, set the found inflection points and their nearby neighborhoods to zero, disconnect the contour, and obtain several line segments;

[0102] Sort all the line segments in descending order according to their lengths, take the first four line segments, perform Hough straight line detection, and screen out the two straight lines on the "L" sides of the DM two-dimensional code.

[0103] According to an embodiment of the present invention, for the screening out of the two straight lines on the "L" sides of the DM two-dimensional code, specifically:

[0104] Find the line segment L1 with the longest length;

[0105] Find all the line segments that are closest to 90 degrees to the line segment L1 with the longest length from the other line segments, and then take the line segment with the longest length L2 from these line segments. Take L1 and L2 as the straight lines on the "L" sides of the DM two-dimensional code.

[0106] It should be noted that the method described in this application finds all the inflection points on the maximum circumscribed contour diagram, sets the found inflection points and their nearby neighborhoods to zero, and disconnects the contour, which is convenient for subsequent straight line edge screening.

[0107] Sort all the line segments in descending order according to their lengths, take the first four line segments, perform Hough straight line detection, and screen out the two straight lines on the "L" sides of the DM code. The screening rules are as follows:

[0108] (1) Find the line segment with the maximum fitting length.

[0109] (2) Find all the line segments that are closest to 90 degrees to the maximum line segment from the other line segments, and take the maximum line segment from these line segments.

[0110] This application is based on Figure 6 the line segments obtained from the Figure 7 maximum circumscribed contour diagram as

[0111] shown. Figure 8 According to an embodiment of the present invention, locate the edge points according to the straight line detection result, and the edge is as

[0112] shown, and determine the affine transformation matrix according to the edge points, specifically:

[0113] Calculate the intersection point A1 of the two line segments L1 and L2;

[0113] Find two points A2 and A3 on the contour of the DM QR code whose distances to line segment L1 and line segment L2 are both less than a preset threshold and are farthest from the intersection point A1, and then determine the order of the three points A1, A2, and A3 through the positive or negative of the inner product of vectors;

[0114] According to the order of the three points A1, A2, and A3, obtain the three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of A1, A2, and A3;

[0115] Calculate the affine transformation matrix based on rectP1, rectP2, and rectP3.

[0116] It should be noted that in this application, the edge points are located according to the straight line detection results, and the affine transformation matrix is determined according to the edge points. First, the intersection point of two line segments is calculated. In addition, two points on the edge whose distances to two straight lines are less than a certain threshold and are farthest from the intersection point are found, and then the order of the three points is determined through the positive or negative of the inner product of vectors:

[0117] Principle of order judgment: There are vectors p1 and p2 in a two-dimensional plane, and their cross product is equal to the area of the parallelogram formed by vectors p1 and p2, as Figure 9 shown.

[0118] If p1 is (x1, y1) and p2 is (x2, y2); then p1 * p2 = x1 * y2 - x2 * y1.

[0119] From the properties of the cross product, the clockwise and counterclockwise relationships between two vectors are obtained:

[0120] If p1 * p2 > 0, then p1 is in the clockwise direction of p2;

[0121] If p1 * p2 < 0, then p1 is in the counterclockwise direction of p2;

[0122] If p1 * p2 = 0, then p1 and p2 are collinear (they may be in the same direction or in the opposite direction);

[0123] Calculate the three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of the centers of the three contours, calculate the affine transformation matrix, and then perform affine transformation correction on the binary image. The effect of the corrected image is as Figure 10 shown.

[0124] Use the method described in this application for Figure 2 recognition, where the successfully recognized image is as Figure 11 shown.

[0125] As Figure 12As shown in the figure, the second aspect of the present invention provides a DM two-dimensional code recognition system. The DM two-dimensional code recognition system 12 includes a memory 121 and a processor 122. The memory 121 includes a DM two-dimensional code recognition method program. When the DM two-dimensional code recognition method program is executed by the processor 122, the following method steps are implemented:

[0126] S102: Obtain the original image with a DM two-dimensional code;

[0127] It should be noted that the DM two-dimensional code, namely the Data Matrix two-dimensional code, is a matrix two-dimensional barcode, belonging to a high-density and high-reliability information storage and transmission technology, and is widely used in many fields.

[0128] S104: Use the yolov5 detection model to obtain the ROI area of the DM two-dimensional code;

[0129] It should be noted that in this application, the yolov5 detection model is used to obtain the ROI area of the DM two-dimensional code, which solves the problem of low success rate of traditional image processing in locating the ROI area of the DM two-dimensional code. Performing image preprocessing on the ROI area can greatly reduce the impact of interference on subsequent recognition. In addition, it will have higher operating efficiency than libdmtx in searching and locating the entire image.

[0130] YOLOv5 is an efficient object detection model implemented based on PyTorch, developed and maintained by the Ultralytics team. YOLOv5 can perform object detection and classification simultaneously in a single forward pass.

[0131] ROI refers to "Region of Interest". The ROI image is a partial image with specific significance or value delimited and extracted from the original image through a specific algorithm or manual interaction.

[0132] S106: Extract the ROI image in the ROI area of the DM two-dimensional code and perform preprocessing on the ROI image;

[0133] S108: Use lindmtx to recognize the preprocessed ROI image. If the recognition is successful, output the recognized DM two-dimensional code; if the recognition is not successful, execute S110;

[0134] It should be noted that lindmtx is a software tool specifically used for image analysis and recognition.

[0135] S110: Use the Otsu method to binarize the preprocessed ROI image and extract the contour of the DM two-dimensional code;

[0136] S112: Filter out the interference area according to the contour of the DM two-dimensional code to obtain a binarized ROI image after removing interference;

[0137] S114: Use lindmtx to identify the binarized ROI image after removing interference. If the identification is successful, output the identified DM two-dimensional code; if the identification is not successful, execute S116;

[0138] S116: Perform line detection according to the inflection points on the contour of the DM two-dimensional code,

[0139] S118: Locate the edge points according to the line detection result, and determine the affine transformation matrix according to the edge points;

[0140] S120: Perform affine correction on the binarized ROI image after removing interference by using the affine matrix;

[0141] S122: Use Zbar to identify the binarized ROI image after affine correction. If the identification is successful, output the identified DM two-dimensional code; if the identification is not successful, determine it as an identification failure and exit the identification task.

[0142] It should be noted that ZBar is an open-source software library for image recognition. It is mainly used to identify various types of one-dimensional and two-dimensional barcodes and plays an important role in identifying the binarized ROI (region of interest) image.

[0143] According to the embodiment of the present invention, the preprocessing of the ROI image includes: performing median filtering on the ROI graph, graying it, and finally performing gray enhancement.

[0144] According to the embodiment of the present invention, the extraction of the DM two-dimensional code contour is specifically:

[0145] Perform morphological closing operation on the binarized ROI image, and find the largest circumscribed rectangle existing in the binarized ROI image as the DM two-dimensional code contour.

[0146] It should be noted that this application uses the Otsu method to binarize the gray ROI image, performs morphological closing operation, and finds the area with the largest circumscribed rectangle in the image, that is, the foreground area of the DM two-dimensional code, to further filter the influence of other noises.

[0147] According to the embodiment of the present invention, the performing line detection according to the inflection points on the contour of the DM two-dimensional code is specifically:

[0148] Find all the inflection points on the largest circumscribed rectangle existing in the binarized ROI image, set the found inflection points and their nearby neighborhoods to zero, disconnect the contour, and obtain several line segments;

[0149] Sort all the line segments in descending order of length, select the first four line segments, perform Hough line detection, and filter out two lines on the "L" side of the DM two-dimensional code.

[0150] According to the embodiment of the present invention, the two lines on the "L" side of the DM two-dimensional code filtered out are specifically:

[0151] Find the line segment L1 with the longest length;

[0152] Find all the line segments from the other line segments that are closest to 90 degrees to the line segment L1 with the longest length, and then select the line segment L2 with the longest length from these line segments. Take L1 and L2 as the lines on the "L" side of the DM two-dimensional code.

[0153] It should be noted that the method described in this application finds all the inflection points on the maximum circumscribed contour map, sets the found inflection points and their nearby neighborhoods to zero, and disconnects the contour to facilitate subsequent straight-edge screening.

[0154] Sort all the line segments in descending order of length, select the first four line segments, perform Hough line detection, and filter out two lines on the "L" side of the DM code. The screening rules are as follows:

[0155] (1) Find the line segment with the maximum length obtained by fitting.

[0156] (2) Find all the line segments from the other line segments that are closest to 90 degrees to the maximum line segment, and select the maximum line segment from these line segments.

[0157] According to the embodiment of the present invention, locate the edge points according to the line detection result, and determine the affine transformation matrix according to the edge points, specifically:

[0158] Calculate the intersection point A1 of the two line segments L1 and L2;

[0159] Find two points A2 and A3 on the DM two-dimensional code contour that are both less than a preset threshold from the line segments L1 and L2 and are farthest from the intersection point A1. Then, judge the order of the three points A1, A2, and A3 through the positive and negative of the inner product of vectors;

[0160] According to the order of the three points A1, A2, and A3, obtain the three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of A1, A2, and A3;

[0161] Calculate the affine transformation matrix according to rectP1, rectP2, and rectP3.

[0162] It should be noted that in this application, edge points are located based on the straight-line detection results, and an affine transformation matrix is determined according to the edge points. First, the intersection points of two line segments are calculated. In addition, two points on the edge that are less than a certain threshold distance from the two lines and are farthest from the intersection point are found. Then, the order of the three points is determined by the positive and negative of the inner product of vectors:

[0163] Principle of order judgment: In a two-dimensional plane, there are vectors p1 and p2, and their cross product is equal to the area of the parallelogram formed by vectors p1 and p2.

[0164] If p1 is (x1, y1) and p2 is (x2, y2); then p1 * p2 = x1 * y2 - x2 * y1.

[0165] Based on the properties of the cross product, the clockwise and counterclockwise relationships between two vectors are obtained:

[0166] If p1 * p2 > 0, then p1 is in the clockwise direction of p2;

[0167] If p1 * p2 < 0, then p1 is in the counterclockwise direction of p2;

[0168] If p1 * p2 = 0, then p1 and p2 are collinear (they may be in the same direction or in the opposite direction);

[0169] Calculate the three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of the centers of the three contours, calculate the affine transformation matrix, and then perform affine transformation correction on the binary image. The effect of the corrected image is as Figure 10 shown.

[0170] The third aspect of this application provides a computer-readable storage medium, which includes a program for the DM two-dimensional code recognition method. When the program for the DM two-dimensional code recognition method is executed by a processor, the steps of the above-mentioned DM two-dimensional code recognition method are implemented.

[0171] As can be seen from the above, this application provides a DM two-dimensional code recognition method, system, and readable storage medium. This application can effectively recognize DM two-dimensional codes under various lighting conditions, and significantly improve the recognition success rate of DM codes under complex environmental conditions.

[0172] In view of the problem of difficult positioning of DM two-dimensional codes under complex environmental conditions, this application uses the yolov5-based rough positioning method to replace the traditional rough positioning method of connected component screening after threshold binarization, which greatly improves the positioning accuracy. At the same time, for the analysis and processing of the DM code area, the rate will also be significantly improved. This application proposes a new "L"-shaped edge algorithm for positioning DM codes, and then an algorithmic solution for affine transformation correction by finding three positioning points, which significantly improves the impact of environmental interference and makes the DM parsing algorithm more robust. By parsing the DM code on the image processed three times, the success rate of DM code recognition is further improved.

[0173] In several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed with each other can be through some interfaces. The indirect coupling or communication connection of devices or units can be electrical, mechanical, or other forms.

[0174] The units described above as separate components may or may not be physically separated. The components shown as units may or may not be physical units; they can be located in one place or distributed to multiple network units; some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0175] In addition, in each embodiment of the present invention, each functional unit can be all integrated in one processing unit, or each unit can be separately used as one unit, or two or more units can be integrated in one unit; the above-mentioned integrated units can be implemented in the form of hardware, or in the form of a combination of hardware and software functional units.

[0176] Those of ordinary skill in the art can understand that all or part of the steps to implement the above method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a readable storage medium. When the program is executed, it executes the steps including the above method embodiments; and the foregoing storage medium includes: various media that can store program codes such as mobile storage devices, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks, or optical discs.

[0177] Alternatively, if the above integrated units of the present invention are implemented in the form of software functional modules and sold or used as independent products, they can also be stored in a readable storage medium. Based on such an understanding, the technical solution of the embodiments of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. The software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as removable storage devices, ROM, RAM, magnetic disks, or optical discs.

Claims

1. A method for identifying DM two-dimensional codes, characterized in that, The method includes: Obtain the original image with a DM QR code; Use the yolov5 detection model to obtain the ROI area of the DM QR code, Extract the ROI image from the ROI area of the DM QR code and preprocess the ROI image; Use lindmtx to recognize the preprocessed ROI image. If the recognition is successful, output the recognized DM QR code; if the recognition is not successful, perform the following steps: Use the Otsu method to binarize the preprocessed ROI image and extract the contour of the DM QR code; Filter out the interference area according to the contour of the DM QR code to obtain the binarized ROI image after removing interference; Use lindmtx to recognize the binarized ROI image after removing interference. If the recognition is successful, output the recognized DM QR code; if the recognition is not successful, perform the following steps: Perform line detection according to the inflection points on the contour of the DM QR code, Locate the edge points according to the line detection results and determine the affine transformation matrix according to the edge points; Perform affine correction on the binarized ROI image after removing interference using the affine matrix; Use Zbar to recognize the binarized ROI image after affine correction. If the recognition is successful, output the recognized DM QR code; if the recognition is not successful, determine that the recognition fails and exit the recognition task.

2. The DM two-dimensional code recognition method according to claim 1, characterized in that, The preprocessing of the ROI image includes: performing median filtering on the ROI graph, graying it, and finally performing gray enhancement.

3. A method for identifying a DM two-dimensional code according to claim 2, characterized in that, The extraction of the contour of the DM QR code is specifically: Perform morphological closing operation on the binarized ROI image, and find the largest circumscribed rectangle in the binarized ROI image as the contour of the DM QR code.

4. A method for identifying a DM two-dimensional code according to claim 3, characterized in that, The performing of line detection according to the inflection points on the contour of the DM QR code is specifically: Find all the inflection points on the largest circumscribed rectangle in the binarized ROI image, set the found inflection points and their nearby neighborhoods to zero, disconnect the contour, and obtain several line segments; Sort all the line segments in descending order according to their lengths, take the first four line segments, perform Hough line detection, and screen out the two lines on the "L" sides of the DM QR code.

5. A method for identifying a DM two-dimensional code according to claim 4, characterized in that, The screening out of the two lines on the "L" sides of the DM QR code is specifically: Find the line segment L1 with the longest length; Find all the line segments that are closest to 90 degrees to the line segment L1 with the longest length from other line segments, and then take the line segment L2 with the longest length from these line segments. Take L1 and L2 as the lines on the "L" sides of the DM QR code.

6. A DM two-dimensional code recognition method according to claim 5, characterized in that, Locating the edge points according to the line detection results and determining the affine transformation matrix according to the edge points is specifically: Calculate the intersection point A1 of the two line segments L1 and L2; Find two points A2 and A3 on the contour of the DM QR code that are both less than a preset threshold distance from the line segments L1 and L2 and are the farthest from the intersection point A1. Then, judge the order of the three points A1, A2, and A3 through the positive and negative of the inner product of vectors; According to the order of the three points A1, A2, and A3, obtain the three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of A1, A2, and A3; Calculate the affine transformation matrix according to rectP1, rectP2, and rectP3.

7. A DM two-dimensional code recognition system, characterized in that, It includes a memory and a processor. The memory includes a DM two-dimensional code recognition method program. When the DM two-dimensional code recognition method program is executed by the processor, the following method steps are implemented: Obtain the original image with a DM two-dimensional code; Use the yolov5 detection model to obtain the DM two-dimensional code ROI region, Extract the ROI image from the DM two-dimensional code ROI region and preprocess the ROI image; Use lindmtx to recognize the preprocessed ROI image. If the recognition is successful, output the recognized DM two-dimensional code; if the recognition is not successful, perform the following steps: Use the Otsu method to binarize the preprocessed ROI image and extract the DM two-dimensional code contour; Filter out the interference region according to the DM two-dimensional code contour to obtain the binarized ROI image after removing interference; Use lindmtx to recognize the binarized ROI image after removing interference. If the recognition is successful, output the recognized DM two-dimensional code; if the recognition is not successful, perform the following steps: Perform line detection according to the inflection points on the DM two-dimensional code contour, Locate the edge points according to the line detection results and determine the affine transformation matrix according to the edge points; Perform affine correction on the binarized ROI image after removing interference using the affine matrix; Use Zbar to recognize the binarized ROI image after affine correction. If the recognition is successful, output the recognized DM two-dimensional code; if the recognition is not successful, determine it as a recognition failure and exit the recognition task.

8. A DM two-dimensional code recognition system according to claim 7, characterized in that, The preprocessing of the ROI image includes: performing median filtering on the ROI graph, graying it, and finally performing gray-scale enhancement; The extraction of the DM two-dimensional code contour is specifically: Perform morphological closing operation on the binarized ROI image, and find the largest circumscribed rectangle in the binarized ROI image as the DM two-dimensional code contour; The performing of line detection according to the inflection points on the DM two-dimensional code contour is specifically: Find all the inflection points on the largest circumscribed rectangle in the binarized ROI image, set the found inflection points and their nearby neighborhoods to zero, disconnect the contour, and obtain several line segments; Sort all the line segments in descending order according to their lengths, take the first four line segments, perform Hough line detection, and screen out the two lines on the "L" sides of the DM two-dimensional code.

9. The DM two-dimensional code recognition system according to claim 8, wherein, The screening out of the two lines on the "L" sides of the DM two-dimensional code is specifically: Find the line segment L1 with the longest length; Find all the line segments that are closest to 90 degrees to the longest line segment L1 from the other line segments, and then take the line segment L2 with the longest length from these line segments. Take L1 and L2 as the lines on the "L" sides of the DM two-dimensional code; The locating of the edge points according to the line detection results and the determining of the affine transformation matrix according to the edge points are specifically: Calculate the intersection point A1 of the two line segments L1 and L2; Find two points A2 and A3 on the DM two-dimensional code contour that are both less than the preset threshold distance from the line segments L1 and L2 and are the farthest from the intersection point A1. Then, judge the order of the three points A1, A2, and A3 through the positive and negative of the inner product of vectors; According to the order of three points A1, A2, and A3, obtain three points rectP1, rectP2, and rectP3 corresponding to the circumscribed rectangle of A1, A2, and A3; Calculate the affine transformation matrix based on rectP1, rectP2, and rectP3.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a DM two-dimensional code recognition method program, and when the DM two-dimensional code recognition method program is executed by a processor, the steps of a DM two-dimensional code recognition method described in any one of claims 1 to 6 are implemented.