A method, device, equipment and storage medium for decoding contour two-dimensional code
By calculating the grayscale projection vector of the QR code image and determining the segmentation line, the image is divided into modules, and the contour line is determined based on the boundary grayscale value. Finally, the attributes of the unknown module are determined based on the attributes of the known module for decoding, which solves the problem that the contour QR code cannot be decoded in the prior art, and achieves efficient and accurate decoding effect.
Patent Information
- Application Number
- CN202211597274.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-12
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2042-12-12
AI Technical Summary
The prior art cannot directly judge the color attributes of the module based on the contrast of the outline QR code module, resulting in the inability to effectively decode the outline QR code.
By calculating the grayscale projection vector of the QR code image, the horizontal and vertical segmentation lines are determined, the image is divided into multiple modules, and the contour lines are determined based on the boundary grayscale value of the module, and finally the black and white attributes of the unknown module are determined based on the properties of the known module for decoding.
It realizes efficient and accurate decoding of contour QR codes, enhances the robustness of contour recognition and improves the accuracy of decoding.
Smart Images

Figure CN116090485B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device, equipment and storage medium for decoding a contour-type two-dimensional code. Background Art
[0002] With the rapid development of QR code technology, QR codes have been widely used in daily life and industrial production processes. Printed QR codes are a common type of QR code in daily life. Its main feature is that it uses modules of different colors to record data. The decoding method of printed QR codes is also based on the different contrast of each module color, so as to identify the color attributes of each module to complete the decoding process of printed QR codes.
[0003] In industrial production, QR codes need to accompany the entire life cycle of the product. To ensure that the information on the QR code will not be easily damaged, the QR code on the product is often made into an outline QR code through laser engraving, chemical etching, etc. However, the outline QR code only retains the edge outline of the matrix QR code module, and the color of each module is consistent with the color of the background, resulting in the problem that the existing QR code technology cannot directly determine the color attribute of the module based on the contrast of the module to complete the decoding. An efficient and accurate outline QR code decoding method is urgently needed. Summary of the invention
[0004] The present application provides a method, apparatus, device and storage medium for decoding an outline-type two-dimensional code, so as to support decoding of an outline-type two-dimensional code.
[0005] In a first aspect, the present application provides a method for decoding a contour-type two-dimensional code, the method comprising:
[0006] A first grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image, and a second grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image;
[0007] Determine multiple horizontal segmentation lines of the two-dimensional code image according to the positions of multiple valley values in the first grayscale projection vector, and determine multiple vertical segmentation lines of the two-dimensional code image according to the positions of multiple valley values in the second grayscale projection vector;
[0008] Dividing the two-dimensional code image into a plurality of modules according to the plurality of horizontal dividing lines and the plurality of vertical dividing lines;
[0009] According to the boundary grayscale value of each boundary line of each module of the two-dimensional code image, determining the boundary line whose boundary grayscale value is less than the boundary grayscale threshold as a contour line;
[0010] Determine the black and white attributes of the modules with unknown black and white attributes in the two-dimensional code image according to the number of contour lines between the modules with known black and white attributes and the modules with unknown black and white attributes in the two-dimensional code image;
[0011] The two-dimensional code image is decoded according to the black and white attributes of each module of the two-dimensional code image.
[0012] Furthermore, after dividing the two-dimensional code image into a plurality of modules, the method further includes:
[0013] Determine an average height and an average width of the two-dimensional code image module according to the multiple horizontal dividing lines, the multiple vertical dividing lines, and the number of rows and columns of the two-dimensional code image module;
[0014] Each boundary line of each module of the two-dimensional code image is adjusted according to the average height and the average width of the two-dimensional code image modules.
[0015] Further, adjusting each boundary line of each module of the two-dimensional code image according to the average height of the two-dimensional code image module includes:
[0016] Adjusting the height between two horizontal boundary lines of each module of the two-dimensional code image to the average height of each module of the two-dimensional code image to obtain the expected horizontal boundary line of each module;
[0017] For each expected horizontal boundary line of each module, a third grayscale projection vector is obtained based on the cumulative sum of the grayscale values of each row of pixels in a horizontal frame with a width set with the expected horizontal boundary line as the center, and the expected horizontal boundary line is updated based on the position of the minimum value in the third grayscale projection vector.
[0018] Further, adjusting each boundary line of each module of the two-dimensional code image according to the average width of the two-dimensional code image module includes:
[0019] Adjusting the width between two vertical boundary lines of each module of the two-dimensional code image to the average height of each module of the two-dimensional code image to obtain the expected vertical boundary line of each module;
[0020] For each expected vertical boundary line of each module, a fourth grayscale projection vector is obtained based on the cumulative sum of the grayscale values of each column of pixels in a vertical box with a height set with the expected vertical boundary line as the center, and the expected vertical boundary line is updated based on the position of the minimum value in the fourth grayscale projection vector.
[0021] Furthermore, the method further comprises:
[0022] The boundary grayscale threshold is updated according to the boundary grayscale value of the module with known black and white attributes.
[0023] Furthermore, the method further comprises:
[0024] When there are three boundary lines that have the same intersection point with a boundary line determined as a contour line, the boundary line with the smallest boundary grayscale value among the three boundary lines is determined as the contour line.
[0025] Furthermore, the method further comprises:
[0026] When there is only one unknown boundary line between two known same-color modules in the same row or column that has not been determined as a contour line, and the number of contour lines that have been determined between the two known same-color modules in the same row or column is an odd number, the unknown boundary line is determined to be a contour line;
[0027] When there is only one unknown boundary line between two known different-color modules in the same row or column that has not been determined as a contour line, and the number of contours determined to be included between the two known different-color modules in the same row or column is an even number, the unknown boundary line is determined to be a contour line.
[0028] In a second aspect, the present application provides a contour-type two-dimensional code decoding device, the device comprising:
[0029] A grayscale projection module, used to obtain a first grayscale projection vector according to the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image, and to obtain a second grayscale projection vector according to the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image;
[0030] a division module, configured to determine a plurality of horizontal segmentation lines of the two-dimensional code image according to the positions of a plurality of valley values in the first grayscale projection vector, and to determine a plurality of vertical segmentation lines of the two-dimensional code image according to the positions of a plurality of valley values in the second grayscale projection vector; and to divide the two-dimensional code image into a plurality of modules according to the plurality of horizontal segmentation lines and the plurality of vertical segmentation lines;
[0031] A contour confirmation module, used to determine, based on the boundary grayscale value of each boundary line of each module of the two-dimensional code image, a boundary line whose boundary grayscale value is less than a boundary grayscale threshold as a contour line;
[0032] The black and white attribute confirmation module is used to determine the black and white attributes of the modules with unknown black and white attributes in the two-dimensional code image according to the number of contour lines between the modules with known black and white attributes and the modules with unknown black and white attributes in the two-dimensional code image; and decode the two-dimensional code image according to the black and white attributes of each module in the two-dimensional code image.
[0033] Furthermore, after the division module divides the two-dimensional code image into a plurality of modules, it is also used to:
[0034] According to the multiple horizontal dividing lines, the multiple vertical dividing lines and the number of rows and columns of the two-dimensional code image module, the average height and the average width of the two-dimensional code image module are determined; and according to the average height and the average width of the two-dimensional code image module, each boundary line of each module of the two-dimensional code image is adjusted.
[0035] Furthermore, the division module adjusts each boundary line of each module of the two-dimensional code image according to the average height of the two-dimensional code image module, specifically for:
[0036] The height between the two horizontal boundary lines of each module of the two-dimensional code image is adjusted to the average height of each module of the two-dimensional code image to obtain the expected horizontal boundary line of each module; and for each expected horizontal boundary line of each module, a third grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each row of pixel points in a horizontal frame with a width set with the expected horizontal boundary line as the center, and the expected horizontal boundary line is updated according to the position of the minimum value in the third grayscale projection vector.
[0037] Furthermore, the division module adjusts each boundary line of each module of the two-dimensional code image according to the average width of the two-dimensional code image module, specifically for:
[0038] The width between the two vertical boundary lines of each module of the two-dimensional code image is adjusted to the average height of each module of the two-dimensional code image to obtain the expected vertical boundary line of each module; and for each expected vertical boundary line of each module, a fourth grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each column of pixel points in a vertical frame with a height set with the expected vertical boundary line as the center, and the expected vertical boundary line is updated according to the position of the minimum value in the fourth grayscale projection vector.
[0039] Furthermore, the contour confirmation module is also used for:
[0040] The boundary grayscale threshold is updated according to the boundary grayscale value of the module with known black and white attributes.
[0041] Furthermore, the contour confirmation module is also used for:
[0042] When there are three boundary lines that have the same intersection point with a boundary line determined as a contour line, the boundary line with the smallest boundary grayscale value among the three boundary lines is determined as the contour line.
[0043] Furthermore, the contour confirmation module is also used for:
[0044] When there is only one unknown boundary line between two known same-color modules in the same row or column that has not been determined as a contour line, and the number of contour lines that have been determined between the two known same-color modules in the same row or column is an odd number, the unknown boundary line is determined to be a contour line;
[0045] When there is only one unknown boundary line between two known different-color modules in the same row or column that has not been determined as a contour line, and the number of contours determined to be included between the two known different-color modules in the same row or column is an even number, the unknown boundary line is determined to be a contour line.
[0046] In a third aspect, the present application provides an electronic device, which includes at least a processor and a memory, and when the processor executes a computer program or instruction stored in the memory, the method of the first aspect is implemented.
[0047] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program or instructions, which, when executed by a processor, implements the method of the first aspect.
[0048] The present application divides the two-dimensional code image into multiple modules according to the positions of multiple valley values in the horizontal grayscale projection vector and the vertical grayscale projection vector of the two-dimensional code image, and determines the boundary line with a boundary grayscale value less than the boundary grayscale threshold in each boundary line of each module of the two-dimensional code image as a contour line, and then determines the black and white properties of the module with unknown black and white properties according to the number of contour lines between the module with known black and white properties and the module with unknown black and white properties, and obtains the black and white properties of each module of the two-dimensional code image, thereby completing the decoding of the two-dimensional code image, solving the problem that the color properties of the module cannot be directly judged according to the contrast of the module to complete the decoding, enhancing the robustness of contour line recognition, and improving the accuracy of contour-type two-dimensional code decoding. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0050] Figure 1 A schematic diagram comparing an outline-type two-dimensional code and a printed two-dimensional code provided in this application.
[0051] Figure 2 This is a flow chart of a contour-type two-dimensional code decoding method provided in this application.
[0052] Figure 3This is a schematic diagram of correcting a two-dimensional code image through affine transformation provided in this application.
[0053] Figure 4 A schematic diagram of determining a segmentation line using a grayscale projection vector provided in this application.
[0054] Figure 5 A schematic diagram of a module for determining a plurality of known black and white attributes provided in the present application.
[0055] Figure 6 This is a schematic diagram of an expected horizontal boundary line and an expected vertical boundary line of a grayscale projection vector minimum value updating module in a rectangular frame provided in the present application.
[0056] Figure 7 This is a schematic diagram of a method provided in the present application for determining whether other boundary lines are contour lines based on a "broken end" boundary.
[0057] Figure 8 This is a schematic diagram provided in the present application of determining whether a remaining unknown boundary line is a contour line according to the number of contours between two modules of the same line and known colors.
[0058] Fig. 9 This is a general flow chart of a contour-type two-dimensional code decoding method provided in this application.
[0059] Fig.10 This is a schematic diagram of the structure of a contour-type two-dimensional code decoding device provided in this application.
[0060] Fig.11 This is a schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0061] In order to make the purpose and implementation method of the present application clearer, the exemplary implementation method of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, rather than all the embodiments.
[0062] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their ordinary and common meanings.
[0063] The terms "first", "second", "third", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or text entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances.
[0064] The terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.
[0065] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.
[0066] In industrial production, contour QR codes are better at preserving data information than printed QR codes, and are less likely to be damaged or lost during the production process. Therefore, contour QR codes containing product information are often made directly on the surface of products through laser engraving, chemical etching, etc., such as on very smooth surfaces such as the surface of glass panels in the LCD industry. Figure 1 For example, Figure 1 The figure is a comparison diagram of outline QR code and printed QR code. Figure 1 The middle left picture shows a printed QR code that records data using black and white modules, and the right picture shows an outlined QR code that records data using the outlines of each module.
[0067] However, because the outline QR code only retains the edge outline of the matrix QR code module, the color of each module is consistent with the background color, which makes it impossible to directly judge the black and white attributes of the module based on the contrast of the module, and thus complete the decoding of the outline QR code.
[0068] Based on this, the present application provides a contour-type QR code decoding method, device, equipment and storage medium, which can accurately identify the contour line of the QR code image, and determine the black and white attributes of each module of the QR code according to the contour line of the QR code, thereby completing the decoding of the contour-type QR code.
[0069] Figure 2 FIG. 1 is a flowchart of a method for decoding a contour-type two-dimensional code. Figure 2 As shown, the method is mainly applied to electronic equipment, and the method includes:
[0070] S201: Obtain a first grayscale projection vector according to the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image, and obtain a second grayscale projection vector according to the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image.
[0071] Perform horizontal grayscale projection and vertical grayscale projection on each pixel of the two-dimensional code image to obtain a horizontal grayscale projection vector and a vertical grayscale projection vector (i.e., a first grayscale projection vector and a second grayscale projection vector). The first grayscale projection vector includes the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image and the row coordinates corresponding to the cumulative sum of the grayscale values of each row of pixels, and the second grayscale projection vector includes the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image and the column coordinates corresponding to the cumulative sum of the grayscale values of each column of pixels.
[0072] To better illustrate the method of obtaining the horizontal projection vector and the vertical grayscale projection vector of the two-dimensional code image, take the horizontal grayscale projection vector of the two-dimensional code image as an example. For example, the two-dimensional code image of M rows and N columns contains M*N pixels. The two-dimensional code image is horizontally projected to obtain the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image (that is, the cumulative sum of the grayscale values of the N pixels in each row from the 1st row to the Mth row in the two-dimensional code image). The row coordinate corresponding to the cumulative sum of the grayscale values of the N pixels in the 1st row is 1, the row coordinate corresponding to the cumulative sum of the grayscale values of the N pixels in the 2nd row is 2, ..., and the row coordinate corresponding to the cumulative sum of the grayscale values of the N pixels in the Mth row is M. The method of obtaining the vertical grayscale projection vector of the two-dimensional code image is similar to the method of obtaining the horizontal grayscale projection vector of the two-dimensional code image, and will not be repeated.
[0073] In a possible implementation, in order to further improve the decoding accuracy, before the above processing, the orientation of the two-dimensional code image may be corrected by affine transformation. Figure 3 Schematic diagram of correcting a QR code image through affine transformation. Figure 3 As shown, the left picture is the original image of the QR code before correction, and the right picture is the corrected QR code image. After correcting the orientation of the QR code image through affine transformation, a QR code image with rows parallel to the preset horizontal axis (x-axis) and columns parallel to the preset vertical axis (y-axis) can be obtained to improve the decoding accuracy.
[0074] S202: Determine multiple horizontal dividing lines of the two-dimensional code image according to the positions of multiple valley values in the first grayscale projection vector, determine multiple vertical dividing lines of the two-dimensional code image according to the positions of multiple valley values in the second grayscale projection vector, and divide the two-dimensional code image into multiple modules according to the multiple horizontal dividing lines and the multiple vertical dividing lines.
[0075] Optionally, before determining each segmentation line (i.e., horizontal segmentation line or vertical segmentation line) of the two-dimensional code image according to the position of the valley value in the grayscale projection vector (i.e., the first grayscale projection vector or the second grayscale projection vector), the electronic device may also perform a one-bit Gaussian filter on the cumulative sum of the grayscale values in the first grayscale projection vector and the second grayscale projection vector, thereby preventing the valley value generated by noise interference from affecting the determination of the position of each segmentation line of the two-dimensional code image. A valley value threshold may also be set, and based on the position of the valley value in the grayscale projection vector that is lower than the valley value threshold, it is used to filter the valley value generated by noise interference, thereby more accurately determining the position of each segmentation line of the two-dimensional code.
[0076] Since the contour-type QR code uses contour lines to record data, the background around the contour lines is basically one color, so the position of the valley value in the first grayscale projection vector and the second grayscale projection vector is the position where the contour lines are most dense. In order to better illustrate the process of determining the position of the segmentation line according to the position of the valley value in the grayscale projection vector, it is assumed that the cumulative sum of the grayscale values of 7 rows of pixels is 100, 100, 70, 20, 40, 50, and 50, respectively, among which the cumulative sum of the grayscale values of the pixels in the 4th row of the 7 rows is the lowest and lower than the cumulative sum of the grayscale values of the pixels in the 3rd and 5th rows (that is, the cumulative sum of the grayscale values of the pixels in the 4th row is the lowest and lower than the cumulative sum of the grayscale values of the adjacent 2 rows), the cumulative sum of the grayscale values of the pixels in the 4th row is determined as a valley value in the grayscale projection vector, and a horizontal segmentation line is determined at the position where the pixels in the 4th row are located. Similarly, the accumulated sum of the grayscale values of the pixels in the 4th row can be determined as a valley value in the grayscale projection vector, based on the fact that the accumulated sum of the grayscale values of the pixels in the 4th row is the lowest and lower than the accumulated sum of the grayscale values of the pixels in the 2nd and 3rd rows and the 5th and 6th rows. In other words, the accumulated sum of the grayscale values of the pixels in the Jth row can be determined as a valley value in the grayscale projection vector, based on the fact that the accumulated sum of the grayscale values of the pixels in the Jth row is lower than the accumulated sum of the grayscale values of the pixels in the J+Kth row and lower than the accumulated sum of the grayscale values of the pixels in the JLth row, and the position of the pixels in the Jth row can be determined as a horizontal dividing line, where J, K, and L are all positive integers greater than 1, L is less than J, and J+K is less than the number of rows of pixels in the two-dimensional code image.
[0077] The method is not limited to the above method, and other methods can be used to determine the valley value in the grayscale projection vector. For example, the findpeaks function in the Matrix Laboratory (MATLAB) can be used to determine the valley value in the grayscale projection vector.
[0078] Figure 4 It is a schematic diagram of the segmentation line determined according to the valley position in the grayscale projection vector. Figure 4As shown, the white horizontal dividing lines and vertical dividing lines basically cover the most densely populated positions of the contour lines in the QR code image of the contour-type QR code (the black lines without ends in the figure are the contour lines, and the gray is the background color of the QR code image), and divide the QR code image into multiple modules.
[0079] S203: According to the boundary grayscale value of each boundary line of each module of the two-dimensional code image, determine that the boundary line whose boundary grayscale value is less than the boundary grayscale threshold is a contour line.
[0080] The boundary grayscale value of each boundary of each module of the two-dimensional code is obtained by calculating the mean value of the grayscale value of each pixel on each boundary line of each module of the two-dimensional code image, or the cumulative sum of the grayscale value of each pixel on each boundary line of each module of the two-dimensional code image is calculated as the boundary grayscale value of each boundary of each module of the two-dimensional code. The boundary grayscale value is determined to be a contour line if it is less than a boundary grayscale threshold, wherein the boundary grayscale threshold can be preconfigured.
[0081] S204: Determine the black and white attributes of the modules with unknown black and white attributes in the two-dimensional code image according to the number of contour lines between the modules with known black and white attributes and the modules with unknown black and white attributes in the two-dimensional code image.
[0082] S205: Decoding the two-dimensional code image according to the black and white attribute of each module of the two-dimensional code image.
[0083] In the embodiment of the present application, the electronic device can determine multiple modules with known black and white attributes by using the preset coding rules of the two-dimensional code. The preset coding rules of the two-dimensional code can be the Chinese-shaped locator and clock line of the Quick Response (Quick Response, QR) code, the L-shaped real edge and virtual edge locator of the Data Matrix (Data Matrix, DM) code, etc. In order to better illustrate the determination of multiple modules with known black and white attributes by using the coding rules of the two-dimensional code, the DM code is now taken as an example. Figure 5 , Figure 5 Schematic diagram of a module for determining multiple known black and white attributes. Figure 5 As shown, the left and lower boundaries of the rectangular DR code are L-shaped solid edges unique to the DM code. Based on the color attribute of the L-shaped real edge, it can be seen that the modules of the left and lower boundaries are black, while the upper and right boundaries of the DR code are virtual edge locators unique to the DM code. Based on the color attribute of the virtual edge locator, it can be seen that the modules of the upper and right boundaries are black and white.
[0084] According to the number of contour lines contained between the module with known black and white attributes and the module with unknown black and white attributes, the black and white attributes of the module with unknown black and white attributes are determined. Specifically, for a module A with unknown black and white attributes, a module B with known black and white attributes in the same row or column as the module A with unknown black and white attributes is searched. If the number of contour lines contained between the module A with unknown black and white attributes and the module B with known black and white attributes is an even number, the module A with unknown black and white attributes is the same color as the module B with known black and white attributes; conversely, if the number of contour lines contained between the module A with unknown black and white attributes and the module B with known black and white attributes is an odd number, the module A with unknown black and white attributes is different in color from the module B with known black and white attributes. In the above manner, all modules with unknown black and white attributes are traversed to obtain the black and white attributes of all modules of the two-dimensional code image, thereby completing the decoding of the two-dimensional code image.
[0085] The present application obtains a first grayscale projection vector and a second grayscale projection vector respectively according to the cumulative sum of the grayscale values of each row of pixels and the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image; determines the horizontal dividing lines and the vertical dividing lines of the two-dimensional code image according to the positions of the valley values in the first grayscale projection vector and the positions of the valley values in the second grayscale projection vector, and divides the two-dimensional code image into multiple modules; then determines the boundary lines of each module whose boundary grayscale values are less than the boundary grayscale threshold as contour lines; determines the black and white properties of the modules with unknown black and white properties according to the number of contour lines between the modules with known black and white properties and the modules with unknown black and white properties; decodes the two-dimensional code image according to the black and white properties of each module, which can solve the problem that the color properties of the module cannot be directly judged according to the contrast of the module to complete the decoding, enhances the robustness of contour line recognition, and improves the accuracy of contour-type two-dimensional code decoding.
[0086] Furthermore, in order to more accurately obtain the boundaries of each module, after dividing the two-dimensional code image into a plurality of modules, the method further includes:
[0087] Determine an average height and an average width of the two-dimensional code image module according to the multiple horizontal dividing lines, the multiple vertical dividing lines, and the number of rows and columns of the two-dimensional code image module;
[0088] Each boundary line of each module of the two-dimensional code image is adjusted according to the average height and the average width of the two-dimensional code image modules.
[0089] Optionally, the average width of each module is calculated as:
[0090]
[0091] W mean is the average width of each module, x nx1 and x2 are the column coordinates of the nth and first vertical dividing lines in the multiple vertical dividing lines of the two-dimensional code image, respectively. col is the number of columns of modules between the nth vertical dividing line and the first vertical dividing line, and n is the number of vertical dividing lines contained in the two-dimensional code image.
[0092] The average height of each module is calculated as:
[0093]
[0094] H mean is the average width of each module, y m , y1 are the row coordinates of the mth horizontal dividing line and the first horizontal dividing line in the multiple horizontal dividing lines of the two-dimensional code image, respectively. row is the number of rows of modules between the mth horizontal dividing line and the first horizontal dividing line, and m is the number of horizontal dividing lines contained in the two-dimensional code image.
[0095] After obtaining the average height and average width of the two-dimensional code image module, the electronic device can adjust the height and width between each boundary line of each module of the two-dimensional code image to the average height and average width, and use the adjusted boundary line of each module as the expected horizontal boundary line and the expected vertical boundary line of each module, and then determine whether the expected horizontal boundary line and the expected vertical boundary line of each module are contour lines, so as to determine the contour lines more accurately.
[0096] On the basis of the above embodiments, in this embodiment, adjusting each boundary line of each module of the two-dimensional code image according to the average height of the two-dimensional code image module includes:
[0097] Adjusting the height between two horizontal boundary lines of each module of the two-dimensional code image to the average height of each module of the two-dimensional code image to obtain the expected horizontal boundary line of each module;
[0098] For each expected horizontal boundary line of each module, a third grayscale projection vector is obtained based on the cumulative sum of the grayscale values of each row of pixels in a horizontal frame with a width set with the expected horizontal boundary line as the center, and the expected horizontal boundary line is updated based on the position of the minimum value in the third grayscale projection vector.
[0099] Figure 6 It is a schematic diagram of the expected horizontal boundary line and the expected vertical boundary line of the module through the minimum value of the grayscale projection vector in the rectangular box. Figure 6As shown, four white rectangular boxes of preset sizes are located at the upper, lower, left and right positions of the module respectively, and the upper and lower rectangular boxes are horizontally projected respectively to obtain the third grayscale projection vectors corresponding to the upper and lower rectangular boxes respectively, and the positions of the expected horizontal boundary lines of the upper and lower modules are updated according to the position of the minimum value in the third grayscale projection vectors. The positions of the expected vertical boundary lines of the left and right modules can also be updated in the same way.
[0100] In order to more accurately determine whether there is a more obvious contour line near the expected horizontal boundary line, after adjusting the height between each horizontal boundary line of each module of the two-dimensional code image to the average height, and taking the adjusted horizontal boundary line of each module as the expected horizontal boundary line of each module, for each expected horizontal boundary line of each module, the third grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each row of pixels in the width horizontal box centered on the expected horizontal boundary line, and the position of the minimum value in the third grayscale projection vector is taken as the position of the updated expected horizontal boundary line. The width of the width horizontal box can be set to the average width of each module, or 80% of the average width of each module, and the height of the width horizontal box can be set to the average height of each module, or 80% of the average height of each module. Figure 6 Taking the expected horizontal boundary line surrounded by the rectangular frame in the upper middle as an example, after determining the expected horizontal boundary line according to the average height of each module, a white rectangular frame with a width of 80% of the average width of each module and a height of 80% of the average height of each module is obtained with the expected horizontal boundary line as the center (i.e. Figure 6 The third grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each row of pixels in the rectangular box, and the position of the minimum value in the third grayscale projection vector is used as the position of the updated expected horizontal boundary line. The expected horizontal boundary line should pass through the center of the white rectangular box and be parallel to the upper and lower sides of the white rectangular box.
[0101] On the basis of the above embodiments, in this embodiment, adjusting each boundary line of each module of the two-dimensional code image according to the average width of the two-dimensional code image module specifically includes:
[0102] The width between the two vertical boundary lines of each module of the two-dimensional code image is adjusted to the average width of each module of the two-dimensional code image to obtain the expected vertical boundary line of each module; for each expected vertical boundary line of each module, a fourth grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each column of pixel points in a vertical frame with a height set with the expected vertical boundary line as the center, and the expected vertical boundary line is updated according to the position of the minimum value in the fourth grayscale projection vector.
[0103] In order to more accurately determine whether there is a more obvious contour line near the expected vertical boundary line, after adjusting the width between each vertical boundary line of each module of the two-dimensional code image to the average width, and taking the adjusted vertical boundary line of each module as the expected vertical boundary line of each module, for each expected vertical boundary line of each module, according to the cumulative sum of the grayscale values of each column of pixel points in the height vertical frame set with the expected vertical boundary line as the center, a fourth grayscale projection vector is obtained, and the position of the minimum value in the fourth grayscale projection vector is taken as the position of the updated expected vertical boundary line. The height of the height vertical frame can be the average height of each module, or 80% of the average height of each module, and the width of the height vertical frame can be the average width of each module, or 80% of the average width of each module.
[0104] On the basis of the above embodiments, in order to more accurately determine whether a boundary line is a contour line, in this embodiment, a method for determining whether a boundary line is a contour line based on an updated boundary grayscale threshold is provided, the method comprising: the electronic device can update the boundary grayscale threshold based on the boundary grayscale value of a module with known black and white attributes.
[0105] Specifically, it includes: obtaining the boundary grayscale values between the same-color modules in the modules with known black and white attributes, and selecting the boundary grayscale values greater than the set ratio as the same-color boundary grayscale threshold. For example, if the ten boundary grayscale values between the same-color modules in the modules with known black and white attributes are 1 to 10, and the set ratio is 80%, then 8 is selected as the same-color boundary grayscale threshold; similarly, the different-color boundary grayscale threshold can be determined according to the boundary grayscale values between the different-color modules in the modules with known black and white attributes. Traverse all boundary lines that are not determined to be contour lines, where the boundary grayscale values less than the same-color boundary grayscale threshold are determined to be contour lines, and the boundary grayscale values greater than the different-color boundary grayscale threshold are determined to be not contour lines.
[0106] On the basis of the above embodiments, in this embodiment, a method for determining whether a boundary line is a contour line according to a "broken end" boundary is further provided to further improve the accuracy of contour line determination. The method includes:
[0107] When there are three boundary lines that have the same intersection point with a boundary line determined as a contour line, the boundary line with the smallest boundary grayscale value among the three boundary lines is determined as the contour line.
[0108] Specifically, when there are three boundary lines that are not determined to be contour lines and have the same intersection with a boundary line that is determined to be a contour line (the boundary line determined to be a contour line is a "broken end" boundary), the boundary line with the smallest boundary grayscale value among the three boundary lines that are not determined to be contour lines is determined to be the contour line. Figure 7A schematic diagram of a method for determining whether other boundary lines are contour lines based on the "broken end" boundary, such as Figure 7 As shown, the boundary line covered by the white solid rectangle is determined as the contour line (i.e., the "broken end" boundary), and three white rectangular frames respectively circle three boundary lines that have not yet been determined to be contour lines, and the boundary line with the smallest boundary grayscale value among the above three boundary lines that have not yet been determined to be contour lines is determined as the contour line.
[0109] On the basis of the above embodiments, in this embodiment, a method for determining whether a boundary line is a contour line according to the number of contours between two modules in the same row or column is provided, the method comprising:
[0110] When there is only one unknown boundary line between two known same-color modules in the same row or column that has not been determined as a contour line, and the number of contour lines that have been determined between the two known same-color modules in the same row or column is an odd number, the unknown boundary line is a contour line;
[0111] When there is only one unknown boundary line between two known different-color modules in the same row or column that has not been determined as a contour line, and the number of contours determined to be included between the two known different-color modules in the same row or column is an even number, the unknown boundary line is a contour line.
[0112] by Figure 8 For example, Figure 8 It is a schematic diagram of judging whether the remaining unknown boundary line is a contour line according to the number of contours between two modules with known colors in the same row. Figure 8 As shown, there are 4 modules in the same row, namely A, B, C, and D, and the border lines between A and B, and between C and D have been determined to be contour lines. Assumption 1: A and D are of the same color and the number of contour lines between A and D is known to be 2 (i.e. an even number). According to Assumption 1, it can be known that the border line between B and C is not a contour line, because if the border line between B and C is a contour line, then B and C are of different colors. According to the assumption, it is known that A and B and C and D are of different colors, so it can be inferred that A and D are of different colors, which refutes the assumption, so the border line between B and C cannot be a contour line.
[0113] Assumption 2: A and D are different colors and the number of known contour lines between A and D is 2 (i.e. an even number). According to Assumption 2, the boundary line between B and C is a contour line, because if the boundary line between B and C is not a contour line, then B and C are the same color. According to the assumption that A and B and C and D are different colors, it can be inferred that A and D are the same color, which contradicts Assumption 2 that A and D are different colors, so the boundary line between B and C can only be a contour line. Similarly, judging whether the remaining unknown boundary lines are contour lines based on the number of contours between two modules of the same column and known colors is the same as the above process.
[0114] Fig. 9 This is the overall flow chart of the outline type two-dimensional code decoding method provided in this application. Fig. 9 As shown, the overall process of the contour two-dimensional code decoding method is:
[0115] S901: Obtain a corrected two-dimensional code image through affine transformation.
[0116] Through affine transformation, the original QR code image (such as Figure 3 After the orientation of the two-dimensional code image (as shown in the left figure) is corrected, the corrected two-dimensional code image (as shown in the left figure) is obtained. Figure 3 (right picture in the figure).
[0117] S902: Perform grayscale projection on the two-dimensional code image, and determine each segmentation line of the two-dimensional code image according to the position of each valley value in the grayscale projection vector.
[0118] A grayscale projection is performed on each pixel point of the corrected two-dimensional code image in the horizontal and vertical directions respectively to obtain a horizontal grayscale projection vector and a vertical grayscale projection vector (i.e., a first grayscale projection vector and a second grayscale projection vector), and the horizontal dividing lines of the two-dimensional code image are determined according to the first grayscale projection vector, and the vertical dividing lines of the two-dimensional code image are determined according to the positions of the valley values in the second grayscale projection vector.
[0119] S903: Divide the two-dimensional code image into multiple modules according to each horizontal dividing line and each vertical dividing line.
[0120] According to the average height of each module, the horizontal boundary line of each module is adjusted one by one, so that the height between each horizontal boundary line of each module is adjusted to the average height, and the expected horizontal boundary line of each module is obtained. For each expected horizontal boundary line of each module, the third grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each row of pixel points in the horizontal frame with a width set with the expected horizontal boundary line as the center, and the expected horizontal boundary line is updated according to the position of the minimum value in the third grayscale projection vector.
[0121] The vertical boundary lines of each module are adjusted one by one according to the average width of each module, so that the width between each vertical boundary line of each module is adjusted to the average width, and the expected vertical boundary line of each module is obtained. For each expected vertical boundary line of each module, the fourth grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each column of pixel points in the vertical frame with the expected vertical boundary line as the center and the height is set, and the expected vertical boundary line is updated according to the position of the minimum value in the fourth grayscale projection vector.
[0122] S904: Determine a boundary grayscale threshold according to the boundary grayscale value of the module with known black and white attributes.
[0123] A plurality of modules with known black and white attributes are determined by the encoding rules of the two-dimensional code, and a grayscale threshold of a same-color boundary is determined according to the grayscale value of the boundary between modules with the same color in the modules with the known black and white attributes, and a grayscale threshold of a different-color boundary is determined according to the grayscale value of the boundary between modules with different colors in the modules with the known black and white attributes. Optionally, the average of the grayscale threshold of the same-color boundary and the grayscale threshold of the different-color boundary is used as the mandatory boundary grayscale threshold.
[0124] S905: Determine that a boundary line whose boundary grayscale value is less than a boundary grayscale threshold is a contour line.
[0125] Traverse all boundary lines that are not determined to be contour lines, determine the boundary lines whose boundary grayscale values are less than the same-color boundary grayscale threshold as contour lines, and determine the boundary lines whose boundary grayscale values are greater than the different-color boundary grayscale threshold as not contour lines.
[0126] Then traverse the remaining boundary lines that are not determined to be contour lines, determine whether the boundary line is a contour line based on the "broken end" boundary, and determine whether the boundary line is a contour line based on the number of contours between two modules in the same row or column.
[0127] Finally, the remaining boundary lines that are not determined to be contour lines are traversed, and the boundary lines whose boundary grayscale values are less than the mandatory boundary grayscale threshold are determined to be contour lines.
[0128] S906: Determine the black and white attributes of each module and complete the decoding of the two-dimensional code image.
[0129] According to the number of contour lines between the modules with known black and white attributes and the modules with unknown black and white attributes, the black and white attributes of the modules with unknown black and white attributes are determined, and then the two-dimensional code image is decoded according to the black and white attributes of each module of the two-dimensional code image.
[0130] Based on the above-mentioned contour type two-dimensional code decoding method, the present application provides a contour type two-dimensional code decoding device, Fig.10 A schematic diagram of the structure of a contour-type two-dimensional code decoding device provided in an embodiment of the present application, the device comprising:
[0131] A grayscale projection module 1001 is used to obtain a first grayscale projection vector according to the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image, and to obtain a second grayscale projection vector according to the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image;
[0132] A division module 1002 is used to determine a plurality of horizontal segmentation lines of the two-dimensional code image according to the positions of a plurality of valley values in the first grayscale projection vector, and to determine a plurality of vertical segmentation lines of the two-dimensional code image according to the positions of a plurality of valley values in the second grayscale projection vector; and to divide the two-dimensional code image into a plurality of modules according to the plurality of horizontal segmentation lines and the plurality of vertical segmentation lines;
[0133] The contour confirmation module 1003 is used to determine, according to the boundary gray value of each boundary line of each module of the two-dimensional code image, a boundary line whose boundary gray value is less than a boundary gray threshold as a contour line;
[0134] The black and white attribute confirmation module 1004 is used to determine the black and white attributes of the modules with unknown black and white attributes in the two-dimensional code image according to the number of contour lines between the modules with known black and white attributes and the modules with unknown black and white attributes in the two-dimensional code image; and decode the two-dimensional code image according to the black and white attributes of each module in the two-dimensional code image.
[0135] Furthermore, after dividing the two-dimensional code image into a plurality of modules, the division module 1002 is further used to:
[0136] According to the multiple horizontal dividing lines, the multiple vertical dividing lines and the number of rows and columns of the two-dimensional code image module, the average height and the average width of the two-dimensional code image module are determined; and according to the average height and the average width of the two-dimensional code image module, each boundary line of each module of the two-dimensional code image is adjusted.
[0137] Furthermore, the division module 1002 adjusts each boundary line of each module of the two-dimensional code image according to the average height of the two-dimensional code image module, specifically for:
[0138] The height between the two horizontal boundary lines of each module of the two-dimensional code image is adjusted to the average height of each module of the two-dimensional code image to obtain the expected horizontal boundary line of each module; and for each expected horizontal boundary line of each module, a third grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each row of pixel points in a horizontal frame with a width set with the expected horizontal boundary line as the center, and the expected horizontal boundary line is updated according to the position of the minimum value in the third grayscale projection vector.
[0139] Furthermore, the division module 1002 adjusts each boundary line of each module of the two-dimensional code image according to the average width of the two-dimensional code image module, specifically for:
[0140] The width between the two vertical boundary lines of each module of the two-dimensional code image is adjusted to the average height of each module of the two-dimensional code image to obtain the expected vertical boundary line of each module; and for each expected vertical boundary line of each module, a fourth grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each column of pixel points in a vertical frame with a height set with the expected vertical boundary line as the center, and the expected vertical boundary line is updated according to the position of the minimum value in the fourth grayscale projection vector.
[0141] Furthermore, the contour confirmation module 1003 is also used for:
[0142] The boundary grayscale threshold is updated according to the boundary grayscale value of the module with known black and white attributes.
[0143] Furthermore, the contour confirmation module 1003 is also used for:
[0144] When there are three boundary lines that have the same intersection point with a boundary line determined as a contour line, the boundary line with the smallest boundary grayscale value among the three boundary lines is determined as the contour line.
[0145] Furthermore, the contour confirmation module 1003 is also used for:
[0146] When there is only one unknown boundary line between two known same-color modules in the same row or column that has not been determined as a contour line, and the number of contour lines that have been determined between the two known same-color modules in the same row or column is an odd number, the unknown boundary line is a contour line;
[0147] When there is only one unknown boundary line between two known different-color modules in the same row or column that has not been determined as a contour line, and the number of contours determined to be included between the two known different-color modules in the same row or column is an even number, the unknown boundary line is a contour line.
[0148] Fig.11 Figure 1 is a schematic diagram of the structure of an electronic device. Fig.11 As shown, the electronic device includes: a processor 1101 , a communication interface 1102 , a memory 1103 and a communication bus 1104 , wherein the processor 1101 , the communication interface 1102 , and the memory 1103 communicate with each other via the communication bus 1104 .
[0149] The memory 1103 stores a computer program, and when the program is executed by the processor 1101, the processor 1101 implements the steps of any one of the above-mentioned contour-type two-dimensional code decoding methods.
[0150] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0151] The communication interface 1102 is used for communication between the above electronic device and other devices.
[0152] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as a plurality of disk memories. Alternatively, the memory may also be a plurality of storage devices located away from the aforementioned processor.
[0153] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0154] Based on the above embodiments, an embodiment of the present application also provides a computer-readable storage medium, which stores a computer program that can be executed by an electronic device. When the program runs on the electronic device, the electronic device implements the steps of any of the above-mentioned contour-type two-dimensional code decoding methods when executed.
[0155] The above-mentioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in the electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc., optical storage such as CD, DVD, BD, HVD, etc., and semiconductor storage such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD), etc.
[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0157] For the convenience of explanation, the above description has been made in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.
[0158] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0159] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0160] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0161] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0162] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for decoding a contour two-dimensional code, characterized in that: The method comprises: A first grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image, and a second grayscale projection vector is obtained according to the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image; Determine multiple horizontal segmentation lines of the two-dimensional code image according to the positions of multiple valley values in the first grayscale projection vector, and determine multiple vertical segmentation lines of the two-dimensional code image according to the positions of multiple valley values in the second grayscale projection vector; Dividing the two-dimensional code image into a plurality of modules according to the plurality of horizontal dividing lines and the plurality of vertical dividing lines; According to the boundary grayscale value of each boundary line of each module of the two-dimensional code image, determining the boundary line whose boundary grayscale value is less than the boundary grayscale threshold as a contour line; Determine the black and white attributes of the modules with unknown black and white attributes in the two-dimensional code image according to the number of contour lines between the modules with known black and white attributes and the modules with unknown black and white attributes in the two-dimensional code image; The two-dimensional code image is decoded according to the black and white attributes of each module of the two-dimensional code image.
2. The method according to claim 1, characterized in that After dividing the two-dimensional code image into a plurality of modules, the method further comprises: Determine an average height and an average width of the two-dimensional code image module according to the multiple horizontal dividing lines, the multiple vertical dividing lines, and the number of rows and columns of the two-dimensional code image module; Each boundary line of each module of the two-dimensional code image is adjusted according to the average height and the average width of the two-dimensional code image modules.
3. The method according to claim 2, characterized in that Adjusting each boundary line of each module of the two-dimensional code image according to the average height of the two-dimensional code image module includes: Adjusting the height between two horizontal boundary lines of each module of the two-dimensional code image to the average height of each module of the two-dimensional code image to obtain the expected horizontal boundary line of each module; For each expected horizontal boundary line of each module, a third grayscale projection vector is obtained based on the cumulative sum of the grayscale values of each row of pixels in a horizontal frame with a width set with the expected horizontal boundary line as the center, and the expected horizontal boundary line is updated based on the position of the minimum value in the third grayscale projection vector.
4. The method according to claim 2, characterized in that: Adjusting each boundary line of each module of the two-dimensional code image according to the average width of the two-dimensional code image module includes: Adjusting the width between two vertical boundary lines of each module of the two-dimensional code image to the average height of each module of the two-dimensional code image to obtain the expected vertical boundary line of each module; For each expected vertical boundary line of each module, a fourth grayscale projection vector is obtained based on the cumulative sum of the grayscale values of each column of pixels in a vertical box with a height set with the expected vertical boundary line as the center, and the expected vertical boundary line is updated based on the position of the minimum value in the fourth grayscale projection vector.
5. The method according to claim 1, characterized in that The method further comprises: The boundary grayscale threshold is updated according to the boundary grayscale value of the module with known black and white attributes.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When there are three boundary lines that have the same intersection point with a boundary line determined as a contour line, the boundary line with the smallest boundary grayscale value among the three boundary lines is determined as the contour line.
7. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When there is only one unknown boundary line between two known same-color modules in the same row or column that has not been determined as a contour line, and the number of contour lines that have been determined between the two known same-color modules in the same row or column is an odd number, the unknown boundary line is determined to be a contour line; When there is only one unknown boundary line between two known different-color modules in the same row or column that has not been determined as a contour line, and the number of contours determined to be included between the two known different-color modules in the same row or column is an even number, the unknown boundary line is determined to be a contour line.
8. A contour type two-dimensional code decoding device, characterized in that: The device includes: A grayscale projection module, used to obtain a first grayscale projection vector according to the cumulative sum of the grayscale values of each row of pixels in the two-dimensional code image, and to obtain a second grayscale projection vector according to the cumulative sum of the grayscale values of each column of pixels in the two-dimensional code image; a division module, configured to determine a plurality of horizontal segmentation lines of the two-dimensional code image according to the positions of a plurality of valley values in the first grayscale projection vector, and to determine a plurality of vertical segmentation lines of the two-dimensional code image according to the positions of a plurality of valley values in the second grayscale projection vector; and to divide the two-dimensional code image into a plurality of modules according to the plurality of horizontal segmentation lines and the plurality of vertical segmentation lines; A contour confirmation module, used to determine, based on the boundary grayscale value of each boundary line of each module of the two-dimensional code image, a boundary line whose boundary grayscale value is less than a boundary grayscale threshold as a contour line; The black and white attribute confirmation module is used to determine the black and white attributes of the modules with unknown black and white attributes in the two-dimensional code image according to the number of contour lines between the modules with known black and white attributes and the modules with unknown black and white attributes in the two-dimensional code image; and decode the two-dimensional code image according to the black and white attributes of each module in the two-dimensional code image.
9. An electronic device, characterized in that: The electronic device comprises at least a processor and a memory, and when the processor executes a computer program or instruction stored in the memory, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: It stores a computer program or instruction, and when the computer program or instruction is executed by a processor, the method as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
DM two-dimensional code identification method and device based on image processing
CN107545207A
Two-dimensional code recognition method, storage medium and computer
CN114692661A