A dot matrix code generation and decoding method
By setting the best seed value and the best number of copies, the original encoded data is converted into a digital sequence and the dot matrix code image is generated, which solves the problem of black dot adhesion when the printer prints small-sized dot matrix codes, and improves the recognition accuracy and encoding capacity of dot matrix codes.
Patent Information
- Application Number
- CN202411390405.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-10-08
AI Technical Summary
In the prior art, when a printer prints a small dot matrix code on paper, problems such as black dot sticking may occur, which affects the recognition and reading of the dot matrix code and leads to poor recognition accuracy.
By setting the optimal seed value and the optimal number of copies, the original encoded data is converted into a digital sequence and a dot code image is generated to ensure that the dot code can still be accurately identified in the presence of adhesion or defilement.
The accuracy of dot matrix code recognition is improved, and the recognition ability of small-sized dot matrix diagrams is ensured. When the size of the recognition element is 1 pixel, a code block unit only needs 9 pixels, and a large-capacity code block requires only 81 pixels.
Smart Images

Figure CN118966258B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of dot matrix codes, and in particular relates to a dot matrix code generation and decoding method. Background Art
[0002] Dot matrix code is a coding method that represents Chinese characters or other characters in the form of dot matrix, usually used for display or print output. It is formed by selectively filling black dots in the virtual coding grid, and the filled black dots can be used to store information.
[0003] For example, a Chinese patent with publication number CN111832680B discloses a coding method, a reading method, a coding device and a reading device of a dot matrix code, wherein the dot matrix code includes at least one coding block, and the coding block includes a plurality of virtual coding grids arranged in a two-dimensional array. The coding method includes: forming a coding block by selectively filling micro-image units in a coding area defined by a plurality of virtual coding grids, wherein the coding block has at least a positioning block for indicating the orientation of the coding block and a content block for storing data information. In particular, the distance between at least two micro-image units in the positioning block is formed to be smaller than the distance between any two micro-image units in the content block, so as to mark the characteristics of the positioning block. Using the coding method thereof, it is possible to flexibly expand the data storage capacity of the dot matrix code.
[0004] However, due to the limitations of paper materials and printers, when current printers print smaller dot codes on paper, the black dots in the dot codes may stick together, affecting the reading of the dot codes and resulting in poor dot code recognition accuracy.
[0005] Therefore, it is urgent to develop a dot matrix code generation and decoding method to solve the problems in the prior art. Summary of the invention
[0006] The present invention aims to provide a dot matrix code generation method and a decoding method, which solves the problem of poor recognition accuracy of dot matrix codes printed by printers proposed in the above background technology by setting an optimal seed value and an optimal number of copies.
[0007] In order to solve the above technical problems, the specific technical solutions of the present invention are as follows:
[0008] A method for generating a dot matrix code comprises the following steps:
[0009] Get the original encoded data;
[0010] According to the original coding data, the optimal seed value and the optimal number of copies are obtained;
[0011] According to the optimal seed value and the optimal number of copies, the original encoded data is converted into a digital sequence;
[0012] Convert the digital sequence into a coded array;
[0013] A dot matrix code image is generated according to the coding array.
[0014] Further, the method of calculating the optimal seed value and the optimal number of copies according to the original encoded data comprises the following steps:
[0015] According to the original coding data and the current copy number, the coding copy data is obtained;
[0016] Obtain the coded scrambled data according to the coded copy data and the current seed value;
[0017] According to the error correction rate, the error-simulated original coded data is obtained;
[0018] The restoration error simulates the original encoded data to obtain the encoded restored data.
[0019] Furthermore, if the encoded restoration data is the same as the original encoded data, the current number of copies at this time is used as the optimal number of copies, and the current seed value at this time is used as the optimal seed value; if the encoded restoration data is different from the input original encoded data or the erroneous simulation of the original encoded data cannot be restored, the current seed value is replaced; if after traversing the seed value, the encoded restoration data are all different from the input original encoded data or the erroneous simulation of the original encoded data cannot be restored, the current number of copies is replaced.
[0020] Furthermore, the method of converting the original coded data into a digital sequence according to the optimal seed value and the optimal number of copies comprises the following steps:
[0021] According to the optimal seed value and the optimal number of copies, the original encoded data is converted into encoded scrambled data;
[0022] According to the scrambled data and the preset coding table, the scrambled data is converted into a corresponding digital sequence.
[0023] Furthermore, the step of converting the digital sequence into a coding array comprises the following steps:
[0024] According to the number of elements in the digital sequence, the array side length of the encoding array will be determined;
[0025] Convert the digital sequence into a coded array according to the length of the array side;
[0026] The step of generating a dot matrix code image according to the coding array comprises the following steps:
[0027] Determine the side length of the code block of the dot code image;
[0028] Create a full white image based on the side length of the code block;
[0029] Filling the coding block in the middle area of the all-white image according to the coding array;
[0030] Setting a positioning module in a first edge region of the all-white image;
[0031] Filling data information in the second edge area of the all-white image;
[0032] The calculation formula of the code block side length is as follows:
[0033] PixelBlockSideLen = 9 * k1 + 2 * k2;
[0034] Among them, PixelBlockSideLen is the side length of the code block, k1 is the length of the minimum printable unit, and k2 is the length of the gap between code blocks.
[0035] Further, the dot code image includes a positioning code block and a coding code block;
[0036] The encoding code block includes at least nine code block units, wherein at least two code block units are provided with identification elements, and the identification elements are provided at the center of the code block units; the ratio of the length of the code block unit to the length of the identification element is 3:1;
[0037] The positioning code block includes at least nine code block units, wherein at least four code block units are provided with identification elements.
[0038] A dot code decoding method, applied to a dot code image generated by the method, comprises the following steps:
[0039] Get the dot matrix code image;
[0040] Binarize the dot matrix code image to obtain a binary image;
[0041] Capturing the positioning code block in the binary image;
[0042] Performing affine correction based on the coordinates of the positioning code blocks, calculating the coding symbols between the positioning code blocks, and obtaining the image grid length;
[0043] Rasterize the binary image based on the image grid length to obtain a raster image;
[0044] Calculate data length and redundancy rate based on the raster image to obtain data blocks;
[0045] Decoding of coded symbols is performed on a block basis.
[0046] Further, the decoding of the coded symbol based on the data block comprises the following steps:
[0047] Calculate the best seed value and the best number of copies according to the data length and redundancy rate;
[0048] Get the correct index based on the optimal seed value and return the encoding symbols corresponding to the encoded data in the correct order.
[0049] A computer device comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the dot code generation method or the steps of the dot code decoding method.
[0050] A computer program product comprises a computer program, which implements the steps of the dot code generation method or the steps of the dot code decoding method when executed by a processor.
[0051] The present invention has the following advantages:
[0052] The dot code generation method of the present application sets the optimal seed value and the optimal number of copies, so that even if the dot code printed by a printer or the like has problems such as adhesion or contamination, the information in the dot code can still be recognized with the help of other areas, thereby improving the accuracy of dot code recognition.
[0053] The coding code block of the dot code image of the present application includes at least nine code block units, and at least two of the code block units are provided with identification elements, so that the coding capacity of the dot code image of the present application is larger to support small-size and large-capacity coding.
[0054] The dot matrix code image of the present application sets the identification element at the center of the code block unit, and the ratio of the length of the code block unit to the length of the identification element is 3:1; so that when the dot matrix image of the present application is printed in a small size, the adhesion problem of the identification element of the dot matrix code can be avoided, which is convenient for the recognition of the small-sized dot matrix image, so that the size of the dot matrix image generated by the present application can be set smaller. When the size of the identification element is 1 pixel, a code block unit only needs 9 pixels, and a large-capacity encoding code block only needs 81 pixels.
[0055] The dot code decoding method of the present application can realize the recognition of small-sized dot patterns on poor quality media with high recognition accuracy.
[0056] Other features and advantages of the present invention will be disclosed in detail in the following specific embodiments and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a schematic diagram of the overall process of the dot code generation method of the present invention;
[0058] Figure 2 is a schematic diagram of a code block table of the present invention;
[0059] Figure 3 It is a structural schematic diagram of the main positioning code block and the auxiliary positioning code block of the present invention;
[0060] Figure 4 It is a structural schematic diagram of the encoding code block of the present invention;
[0061] Figure 5 It is a structural schematic diagram of the dot code image of the present invention. DETAILED DESCRIPTION
[0062] In order to better understand the purpose, structure and function of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings.
[0063] A dot code generation method, such as Figure 1 As shown, the following steps are included:
[0064] S1: Get the original encoded data;
[0065] S2: Obtain the optimal seed value and the optimal number of copies according to the original encoding data;
[0066] S3: converting the original coded data into a digital sequence according to the optimal seed value and the optimal number of copies;
[0067] S4: converting the digital sequence into a coding array;
[0068] S5: Generate a dot matrix code image according to the coding array.
[0069] The original coded data in S1 may include coded symbols such as digital symbols, uppercase and lowercase letters, and English punctuation marks. In this embodiment, each symbol has a corresponding digital serial number in a coding table, thereby ensuring the accuracy and uniqueness of the coding, which is suitable for a variety of information processing and transmission scenarios.
[0070] Table 1: Coding table
[0071]
[0072] Table 1 is a specific coding table of this embodiment. The symbols in the table refer to coding symbols, and each symbol has a corresponding serial number.
[0073] In the coding table of this embodiment, there are 9 digital symbols in total, including Arabic numerals from 0 to 8;
[0074] There are 52 uppercase and lowercase letters in total, including 26 uppercase letters (A to Z) and 26 lowercase letters (a to z);
[0075] There are 24 English punctuation marks in total, including common English punctuation marks such as commas, periods, question marks, etc.
[0076] Optionally, the coding table may include more or fewer symbols as needed, and each coding symbol only needs to correspond to a digital serial number.
[0077] In S2, the optimal seed value and the optimal number of copies are calculated according to the original encoded data, including the following steps:
[0078] S21: Obtaining coded copy data according to the original coded data and the current number of copies;
[0079] S22: Obtaining coded scrambled data according to the coded copy data and the current seed value;
[0080] S23: obtaining error-simulated original coded data according to a preset error correction rate;
[0081] S24: Restoring the error-simulated original coded data to obtain coded restored data.
[0082] If the encoded restoration data is the same as the input original encoded data, the current number of copies at this time is used as the optimal number of copies, and the current seed value at this time is used as the optimal seed value; if the encoded restoration data is different from the input original encoded data or the erroneous simulation of the original encoded data cannot be restored, the current seed value is replaced; if the encoded restoration data is still different from the input original encoded data or the erroneous simulation of the original encoded data cannot be restored after traversing the seed value, the current number of copies is replaced.
[0083] In this embodiment, the current seed value is a positive integer, which gradually increases from 1. When the current seed value increases to the maximum, the encoded restoration data is different from the input original encoded data or both cannot restore the erroneously simulated original encoded data, the current number of copies is changed. In this embodiment, the current number of copies is a positive integer, which gradually increases from 1. Optionally, the current seed value or the current number of copies may also be 0. The error correction rate is preset as required.
[0084] Restoring the error-simulated original coded data in S24 includes the following steps:
[0085] According to the current seed value, the symbol with the highest frequency of occurrence is taken as the decoding symbol value.
[0086] For example, the original signal is 123456789, and after two redundant backups, it is 111222333444555666777888999. After randomly shuffling the index through the seed value, it is 419528637746855964173282391. After introducing some errors, it is 41*528637*46855964*73282391. According to the current seed value, the values corresponding to symbol 1 are 1, 1, *, and the "1" with the highest frequency is taken as the decoding symbol value; the values corresponding to symbol 7 are 7, 7, *, and the "7" with the highest frequency is taken as the decoding symbol value; the values corresponding to symbol 9 are 9, 9, *, and the "9" with the highest frequency is taken as the decoding symbol value.
[0087] Specifically, if the input original encoding data org_strchars is 1234567890abcdefghijk, the error correction rate error_rate is 0.10.
[0088] When the current number of copies is 0, the original encoded data org_strchars is copied 0 times, the encoded copy data is 1234567890abcdefghijk, the current seed value increases from 0 to 21, and the encoded scrambled data after returning the scrambled index according to the current seed value is (0a1b2c3d4e5f6g7h8i9jk).
[0089] According to the preset error correction rate error_rate, an error is simulated and introduced to obtain the error simulated original coded data (0a1b2c*d4e5f6g7*8i9jk).
[0090] Get the correct index according to the current seed value to restore the original encoded data with error simulation. If the encoded restored data is correct, return the current number of copies and the corresponding current seed value as the optimal number of copies repet_num and the corresponding optimal seed value seed_value. If the optimal seed value seed_value fails to correctly encode and restore the data after traversing 0 to 21, add 1 to the current number of copies.
[0091] When the current number of copies is 1, the original encoded data org_strchars is copied once, the original encoded data org_strchars is 1234567890abcdefghijk1234567890abcdefghijk, the best seed value seed_value increases from 0 to 21, and the encoded scrambled data after the scrambled index is returned according to the best seed value seed_value is (0a1b2c3d4e5f6g7h8i9jk0a1b2c3d4e5f6g7h8i9jk).
[0092] According to the error correction rate error_rate, the error is simulated and the error simulation original coding data (0a1b2*3d4e5f6g7*8i9jk0a1b2c*d4e5f6g7h*i9jk) is obtained.
[0093] The current seed value obtains the correct index to restore the incorrectly simulated original encoded data. If the encoded restored data is correct, the current number of copies and the corresponding current seed value are returned as the optimal number of copies repet_num and the corresponding optimal seed value seed_value. If the optimal seed value seed_value fails to correctly encode and restore the data after traversing 0 to 21, the current number of copies will continue to be increased by 1.
[0094] Optionally, the optimal seed value and the optimal number of copies may also be preset according to the length of the original encoded data.
[0095] The present application sets the optimal seed value and the optimal number of copies so that even if the dot code printed by a printer or the like has problems such as adhesion or contamination, the information in the dot code can still be recognized, thereby improving the accuracy of dot code recognition, so that the dot code can still be accurately recognized by the device when printed in a small size, with high reliability.
[0096] In S3, the original coded data is converted into a digital sequence according to the optimal seed value and the optimal number of copies, including the following steps:
[0097] S31: converting the original coded data into scrambled coded data according to the optimal seed value and the optimal number of copies;
[0098] S32: According to the scrambled data and a preset coding table, the scrambled data is converted into a corresponding digital sequence.
[0099] Specifically, if the best seed value seed_value=25, the best number of copies repet_num=2, and the original coded data is 1234567890abcdefghijk, S3 includes the following:
[0100] According to the optimal number of copies, the original coded data is repeated twice to obtain the coded copy data 1234567890abcdefghijk1234567890abcdefghijk1234567890abcdefghijk;
[0101] According to the optimal seed value, the coded copy data is scrambled to obtain the coded scrambled data 0a1b2c3d4e5f6g7h8i9jk0a1b2c3d4e5f6g7h8i9jk0a1b2c3d4e5f6g7h8i9jk;
[0102] According to the preset coding table, the scrambled data is converted into a digital sequence dotencode_data, and the digital sequence dotencode_data=[77, 1, 78, 2, 79, 3, 80, 4, 81, 5, 82, 6, 83, 7, 84, 8, 85, 9, 86, 10, 11, 77, 1, 78, 2, 79, 3, 80, 4, 81, 5, 82, 6, 83, 7, 84, 8, 85, 9, 86, 10, 11].
[0103] The step of converting the digital sequence into a coding array in S4 includes the following steps:
[0104] S41: According to the number of elements in the digital sequence, the array side length K of the encoding array is determined;
[0105] S42: Convert the digital sequence into a coding array according to the array side length K.
[0106] Specifically, the array side length K is rounded up to the integer of the square root of the number of elements of the corresponding digital sequence.
[0107] The number of elements of the aforementioned digital sequence dotencode_data is 63, and the square root and the number of elements are rounded up to determine that the array side length K of the encoding array is 8. If there is no corresponding element in a part of the encoding array, it is a blank area.
[0108] like Figure 2 , is the code block table of the present application. The serial number in the code block table is the corresponding serial number in the encoding table, and the code block in the code block table is the encoding code block corresponding to the serial number.
[0109] In S5, a dot matrix code image is generated according to the coding array, comprising the following steps:
[0110] S51: Determine the side length of the code block of the dot code image, wherein the side length of the code block PixelBlockSideLen is calculated by the following formula:
[0111] PixelBlockSideLen = 9 * k1 + 2 * k2;
[0112] PixelBlockSideLen is the side length of the code block, k1 is the length of the minimum printable unit, and k2 is the length of the gap between code blocks. The minimum printable unit is at least 2 pixels, so k1 is preferably 2 and k2 is preferably 2.
[0113] This step of the present application is used to achieve rapid reconstruction and resizing of the image through simple parameter settings and image processing, replace specific areas in the original image with preset patterns, and add additional pixel blocks at the edge of the image to achieve the purpose of changing the image size and layout, thereby quickly increasing the gaps between black areas in the dot code image so that dots will not be stuck or missing during printing; in addition, this step can also adapt to different printing DPIs, so that users can select the appropriate dot code image size based on data length, redundancy rate and printing DPI.
[0114] S52: Create a full white image according to the side length of the code block, wherein the value of each pixel in the full white image is 255.
[0115] The image side length SideLength of the all-white image is calculated as follows:
[0116] SideLength = (K + 1)*PixelBlockSideLen;
[0117] Among them, SideLength is the image side length of the all-white image, K is the array side length, and PixelBlockSideLen is the code block side length.
[0118] S53: Filling the middle area of the all-white image with coding blocks according to the coding array.
[0119] The all-white image is divided into (K + 1)* (K + 1) sub-image units, and the middle K*K area is taken, from left to right and from top to bottom, and the current all-white sub-image unit is replaced according to the code block corresponding to the sequence number in the coding array.
[0120] S54: Setting a positioning module in a first edge region of the all-white image.
[0121] In this embodiment, the positioning module is a positioning code block, including a main positioning code block and an auxiliary positioning code block, which is used for positioning during decoding. The first edge area is the four corners of the all-white image. In this embodiment, the main positioning code block and the auxiliary positioning code block are as follows: Figure 3 shown.
[0122] S55: Filling data information in the second edge area of the all-white image; the data information includes data length and error correction rate processing information.
[0123] Specifically, 1*K or K*1 code block units of four edges are traversed, specifically from the second to the seventh, and the data length and error correction rate processing information are embedded.
[0124] The data length and error correction rate processing information can become version information. The string of version information is obtained. In this embodiment, it is uniformly 5 bits, Codeversionstr=f"{len(org_strchars):03d}{int(error_rate*100):02d}", such as 02110, which is further converted into a version information list codeversion_list=[0,2,1,1,0]. According to the order of traversal, a modulo operation is performed on 5, and the code block corresponding to the codeversion_list list element corresponding to the result is filled.
[0125] like Figure 5 As shown, it is the dot matrix code image of the present application, and the dot matrix code image includes a plurality of positioning code blocks and encoding code blocks.
[0126] The encoding code block includes at least nine code block units, wherein at least two code block units are provided with identification elements, and the identification elements are provided at the center position of the code block units; the ratio of the length of the code block unit to the length of the identification element is 3:1.
[0127] The coding code block of the dot code image of the present application includes at least nine code block units, and at least two of the code block units are provided with identification elements, so that the coding capacity of the dot code image of the present application is larger to support small-size and large-capacity coding.
[0128] The positioning code block includes at least nine code block units, at least four of which are provided with identification elements. Preferably, at least seven of the code block units are provided with identification elements, so that the reading device can identify the positioning code block.
[0129] One coding block represents one coding symbol. In this embodiment, Figure 4 As shown, a coding code block includes nine code block units, and a code block unit includes 9 areas 1-9, wherein the area 5 located in the middle can be set with an identification element for decoding and identifying the dot matrix code. In this embodiment, the identification element is a black block.
[0130] The coding code block of the dot code image of the present application includes at least nine code block units, and at least two of the code block units are provided with identification elements, so that the coding capacity of the dot code image of the present application is larger to support small-size and large-capacity coding.
[0131] The positions of the black identification elements of the present application are all located at the center point of the 3*3 grid in the 9*9 grid, that is, there are 9 candidate center points, and the encoding code block contains at least 2 center points, c(9,2)+c(9,3)=36+84=120, which can meet the representation of 100 symbols. Only the cells of the center point are taken as candidate identification elements to ensure that the printed dot matrix code is not stuck together; at the same time, it can ensure that the data point code block is eliminated as much as possible after the corrosion expansion during decoding, and the positioning code block is retained, which is easy to identify and locate the positioning code block.
[0132] A decoding method for identifying the above-mentioned dot matrix code image comprises the following steps:
[0133] S601: Acquire a dot matrix code image;
[0134] S602: Binarize the dot matrix code image to obtain a binary image;
[0135] S603: Capturing a positioning code block in a binary image;
[0136] S604: performing affine correction based on the coordinates of the positioning code blocks, calculating the coding symbols between the positioning code blocks, and obtaining the image grid length;
[0137] S605: rasterizing the binary image based on the image grid length to obtain a raster image;
[0138] S606: Calculate data length and redundancy rate based on the grid image to obtain data blocks;
[0139] S607: Perform symbol decoding based on the data block.
[0140] The dot matrix code image can be collected by using a mobile phone camera, and optionally, can also be collected by other devices.
[0141] In S602, the dot matrix code image is binarized to obtain a binary image, which specifically includes the following steps:
[0142] The processor reads the dot matrix code image to obtain a first grayscale image, wherein the first grayscale image is scaled to a pixel size of 500*500;
[0143] Adaptive thresholding technology is used to enhance the first grayscale image to effectively process images with uneven illumination and highlight the details and edges of the image. The resulting image will have better contrast and clarity, which is convenient for subsequent image analysis and processing.
[0144] Perform contour detection, traverse the contours in the first grayscale image, remove contours with less than 5 and more than 40 contour points, and obtain a second grayscale image;
[0145] Using a threshold, black dots and background are separated and the second grayscale image is converted into a binary image.
[0146] The capturing of the positioning code block in the binary image in S603 specifically includes the following steps:
[0147] The kernel size of the erosion operation is defined as m1_size = (10, 10), and the kernel sizes of the dilation operation are defined as m21_size = (15, 15) and m22_size = (20, 20).
[0148] The erosion operation is performed according to the kernel size of the erosion operation to obtain the image img_eroded.
[0149] Dilation operations are performed according to the preset kernel sizes m21_size and m22_size of the dilation operation to obtain images img_dilated1 and img_dilated2.
[0150] Perform contour detection on the images img_dilated1 and img_dilated2 respectively, calculate the contour bounding box, and remove the contours with a height or width less than 4; for the remaining contours, calculate the ratio of width to height, and remove the contours with a ratio greater than 1.325, that is, remove the contours that are not close to a square.
[0151] Perform a bitwise OR operation on the images img_dilated1 and img_dilated2 to obtain a new image img_dilated.
[0152] Initialize a list to store contours that meet the conditions, then perform contour detection on the image img_dilated, traverse the contours, and if the zero-order moment of the contour, that is, the area of the contour, is not equal to 0, use the approximate polygon method to calculate the number of contour edges; for contours with less than or equal to 16 contour edges, calculate the number of black pixels in the contour; for contours with less than or equal to 10 black pixels in the contour, calculate the ratio of the minimum enclosing rectangle width to the height based on the minimum enclosing rectangle of the contour, and compare it with the threshold to determine whether it is close to a square. Contours that are close to a square are used as images of positioning code blocks, and the remaining contours are used as candidate contours for the next step of processing.
[0153] For the contour of the acquired positioning code block image, the minimum area and the maximum area of the contour are calculated.
[0154] Traverse the candidate contours and calculate the contour area. If the contour area is between the minimum area and the maximum area, it is identified as a positioning code block image. If the contour area is between 0.75 and 1.0 times the minimum area, use the RETR_CCOMP mode to find the contour of the minimum circumscribed rectangular sub-image and calculate the total number of second-layer contours. If the total number of second-layer contours is equal to 2 and the contour area of 1.4 times is greater than the maximum contour area, it is identified as a positioning code block image.
[0155] Traverse the contour corresponding to the positioning code block image and calculate the contour's moment and centroid coordinates.
[0156] In S604, affine correction is performed based on the coordinates of the positioning code blocks, coding symbols between the positioning code blocks are calculated, and the image grid length is obtained, which specifically includes the following steps:
[0157] The points of the contour centroid coordinates corresponding to the acquired positioning code block image are sorted in the order of upper left, upper right, lower right, and lower left to obtain a corner point coordinate set P1.
[0158] The corresponding target point coordinates P2 are calculated based on the four corner points, and the transformation matrix is calculated to perform perspective transformation on the image.
[0159] Traverse the coordinates [50,450] in the horizontal and vertical directions respectively, and then traverse the coordinates [50-450] in the corresponding vertical (or horizontal) direction, record the coordinates of the black dot pixels, extract the starting coordinates of each continuous black dot block according to the coordinate set of the black dot pixels, calculate the average difference average_diff according to the starting coordinate set, and calculate the image grid length according to average_diff.
[0160] The obtained image grid length is calculated based on the four sides, and the final image grid length SideLength is calculated.
[0161] In S605, the binary image is rasterized based on the image grid length to obtain a raster image, which specifically includes the following steps:
[0162] The affine-corrected image is divided into grids of SideLength*SideLength according to the final image grid length SideLength.
[0163] The step S606 calculates the data length and redundancy rate based on the rasterized image to obtain the data block, which specifically includes the following steps:
[0164] According to the SideLength*SideLength grid, the four sides of the uterus grid are obtained, excluding the first and last two, and the uterus grid is divided into 3*3 units. The proportion of black pixels in each uterus grid image inside the 3*3 unit is calculated. The uterus grids with a proportion greater than 0.5 are replaced with "0", otherwise they are replaced with "255". A list is constructed from left to right and from top to bottom, and the corresponding coding symbols can be returned. The data length and redundancy rate can be obtained according to the arrangement of the obtained coding symbols and version information.
[0165] The decoding of the coded symbol based on the data block in S607 specifically includes the following:
[0166] Traverse the (SideLength-1)*(SideLength-1) grids inside the rasterized image to obtain the encoding symbols and store them as a two-dimensional list.
[0167] The optimal seed value and optimal number of copies are calculated based on the data length and redundancy rate.
[0168] Get the correct index of the shuffled index based on the best seed value and return the encoded symbols corresponding to the encoded data in the correct order.
[0169] A computer device comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method.
[0170] A computer program product comprises a computer program, which implements the steps of the method when executed by a processor.
[0171] A computer-readable storage medium stores a computer program, which implements the steps of the method when executed by a processor.
[0172] It is to be understood that the present invention is described by some embodiments, and it is known to those skilled in the art that various changes or equivalent substitutions may be made to these features and embodiments without departing from the spirit and scope of the present invention. In addition, under the teachings of the present invention, these features and embodiments may be modified to adapt to specific circumstances and materials without departing from the spirit and scope of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application are within the scope of protection of the present invention.
[0173] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
Claims
1. A method for generating a dot code, characterized in that: The steps include: Get the original encoded data; According to the original coding data, the optimal seed value and the optimal number of copies are obtained; Converting the original coded data into a digital sequence according to the optimal seed value and the optimal number of copies; Convert the digital sequence into a coded array; Generate a dot matrix code image according to the coding array; The method of calculating the optimal seed value and the optimal number of copies according to the original encoded data comprises the following steps: According to the original coding data and the current copy number, the coding copy data is obtained; Obtain the coded scrambled data according to the coded copy data and the current seed value; According to the error correction rate, the error-simulated original coded data is obtained; Restoring the error-simulated original encoded data to obtain encoded restored data; If the encoded restored data is different from the input original encoded data or the original encoded data cannot be restored and the error is simulated, the current seed value is changed; if after traversing the seed value, the encoded restored data is different from the input original encoded data or the error is simulated, the current number of copies is changed; If the encoded restored data is the same as the original encoded data, the current number of copies at this time is used as the optimal number of copies, and the current seed value at this time is used as the optimal seed value.
2. The method for generating a dot matrix code according to claim 1, characterized in that: The method of converting the original coded data into a digital sequence according to the optimal seed value and the optimal number of copies comprises the following steps: According to the optimal seed value and the optimal number of copies, the original encoded data is converted into encoded scrambled data; According to the scrambled data and the preset coding table, the scrambled data is converted into a corresponding digital sequence.
3. The method for generating a dot matrix code according to claim 2, characterized in that: The step of converting the digital sequence into a coding array comprises the following steps: According to the number of elements in the digital sequence, the array side length of the encoding array will be determined; Convert the digital sequence into a coded array according to the length of the array side; The step of generating a dot matrix code image according to the coding array comprises the following steps: Determine the side length of the code block of the dot code image; Create a full white image based on the side length of the code block; Filling the coding block in the middle area of the all-white image according to the coding array; Setting a positioning module in a first edge region of the all-white image; Filling data information in the second edge area of the all-white image; The calculation formula of the code block side length is as follows: PixelBlockSideLen = 9 * k1 + 2 * k2; Among them, PixelBlockSideLen is the side length of the code block, k1 is the length of the minimum printable unit, and k2 is the length of the gap between code blocks.
4. The method for generating a dot matrix code according to any one of claims 1 to 3, characterized in that: The dot matrix code image includes a positioning code block and a coding code block; The encoding code block includes at least nine code block units, wherein at least two code block units are provided with identification elements, and the identification elements are provided at the center of the code block units; the ratio of the length of the code block unit to the length of the identification element is 3:1; The positioning code block includes at least nine code block units, wherein at least four code block units are provided with identification elements.
5. A dot code decoding method, characterized in that: The method for generating a dot code image according to any one of claims 1 to 4 comprises the following steps: Get the dot matrix code image; Binarize the dot matrix code image to obtain a binary image; Capturing the positioning code block in the binary image; Performing affine correction based on the coordinates of the positioning code blocks, calculating the coding symbols between the positioning code blocks, and obtaining the image grid length; Rasterize the binary image based on the image grid length to obtain a raster image; Calculate data length and redundancy rate based on the raster image to obtain data blocks; Decoding coded symbols based on data blocks; The step of calculating the data length and redundancy rate based on the raster image and obtaining the data block comprises the following steps: Get version information; The decoding of the coded symbols based on the data block comprises the following steps: According to the version information, the optimal seed value and the optimal number of copies are calculated; Get the correct index based on the optimal seed value and return the encoding symbols corresponding to the encoded data in the correct order.
6. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the dot code generation method according to any one of claims 1 to 4 or the steps of the dot code decoding method according to claim 5.
7. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the dot code generation method according to any one of claims 1 to 4 or the steps of the dot code decoding method according to claim 5 are implemented.
Citation Information
Patent Citations
Encoding method, reading method, encoding device and reading device of dot matrix code
CN111832680B
Image processing apparatus, image processing method and printer
JP2008092397A
Variable formatting of digital data into a pattern
US6098882A