Method, device, equipment and storage medium for encoding and decoding data dot code
By setting multiple functional areas in the dot matrix code and using multiple blocks to store byte data, the problem of single lattice code style and low decoding efficiency in the prior art is solved, and the aesthetics and efficient decoding are improved.
Patent Information
- Application Number
- CN202210176319.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2042-02-25
AI Technical Summary
In the prior art, the dot matrix code has a single style and a monotonous color, and low decoding efficiency, making it difficult to meet users' needs for aesthetics and efficient decoding.
A method of encoding and decoding for data dot matrix codes is proposed. By setting the encoding area, positioning area, auxiliary positioning area and central picture in the dot matrix code, multiple blocks are used to store byte data, and each byte data is encoded into four data modules, and a small black rectangle is used to represent data points, so as to achieve efficient encoding and decoding.
It improves the aesthetics and decoding efficiency of dot matrix codes, improves user experience, and realizes freely layout of dot matrix code encoding and efficient decoding.
Smart Images

Figure CN114565687B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of communication technology, and in particular to a method, device, equipment and storage medium for encoding and decoding a data dot code. Background Art
[0002] With the development of mobile Internet and the popularization of smart terminals, dot matrix codes play an increasingly important role in life. However, traditional dot matrix codes have a single style, monotonous colors, and black and white small rectangles are arranged too closely. In general, their appearance lacks beauty or is even ugly, which makes it difficult to meet the aesthetic requirements of the public. In addition, there are many scenes in life that require high aesthetics. The current dot matrix code style affects the user experience. Among the many solutions for improving the dot matrix code style in the existing technology, there is the problem of low decoding efficiency. Therefore, how to provide a dot matrix code with good appearance and high decoding efficiency is an urgent problem to be solved. Summary of the invention
[0003] The purpose of the present invention is to provide a method, device, equipment and storage medium for encoding and decoding a data dot code to improve user experience in order to solve the problems existing in the prior art.
[0004] According to one aspect of the present disclosure, a method for encoding a data dot matrix code is provided, wherein the data dot matrix code includes a coding area, a positioning area, an auxiliary positioning area, and a center picture;
[0005] The three positioning areas and one auxiliary positioning area are respectively arranged at the four vertex corners of the dot matrix code;
[0006] The central image is set at the center of the dot matrix code;
[0007] The coding area is arranged at the periphery of the central image and between the positioning areas or between the positioning area and the auxiliary positioning area.
[0008] The coding area is divided into multiple blocks, each block stores multiple bytes of data, and each byte of data is encoded into four data modules.
[0009] Each of the data modules is a large rectangle composed of 9 small rectangles of 3*3. Each of the data modules has one and only one data point, which is represented by a small black rectangle. The small black rectangle is located at four optional positions in the large rectangle, namely, the upper left corner, the upper right corner, the lower left corner, and the lower right corner. The four different positions represent four combinations of 2 bits. Multiple data points form a data dot matrix.
[0010] The byte data to be encoded is encoded into a data module and then filled into the encoding area.
[0011] In some embodiments, the encoding area is equally divided into 8 blocks, and each block stores a maximum of 12 bytes of data.
[0012] In some embodiments, the central picture may be one or more.
[0013] In some embodiments, the encoded data dot matrix is filled in sequence according to the number order in the Block number list.
[0014] In some embodiments, the data dot matrix filling order of different blocks is different, and the filling order can be subdivided into two types, the filling order within the byte and the filling order outside the byte;
[0015] The in-byte filling order means that in the dot matrix code, one byte is composed of four data modules, and the arrangement of these four data modules is the in-byte filling order, where there is a gap of data point width between every two data modules in the in-byte filling. The out-byte filling order means that the four data modules are regarded as a unit representing a byte, and the arrangement of this unit is called the out-byte arrangement.
[0016] In some embodiments, each Block is filled in a different order, and is filled in the order from left to right or from top to bottom according to the byte filling order, and the byte filling order is filled in the order from top to bottom and / or from left to right.
[0017] In some embodiments, the ratio of "black-white-black-white-black" line segments in the positioning area is 2:1:5:1:2, and the ratio of "black-white-black-white-black" in the auxiliary positioning area is 2:2:3:2:2.
[0018] According to another aspect of the present disclosure, a method for decoding a data dot code is provided, wherein the data dot code is identified.
[0019] Preprocess the dot code image data.
[0020] Identify the data dot code positioning area and the auxiliary positioning area,
[0021] Correcting the data dot code,
[0022] Decode the header information in the header information area,
[0023] Decode the information stored in other blocks according to the header information.
[0024] Connect the data in the Block storing the data to get the bit stream.
[0025] The bit stream is restored to original data.
[0026] In some embodiments, the preprocessing includes grayscale and binarization processing.
[0027] In some embodiments, the data dot code positioning area and the auxiliary positioning area are identified, specifically,
[0028] Scan the binarized image line by line. If a black-white-black-white-black line segment that meets the pattern 2:1:5:1:2 or 2:2:3:2:2 is found, the coordinates of the pixel at the midpoint of the line segment are recorded.
[0029] Find the area consisting of all connected black pixels;
[0030] Get the black and white line segments that meet the requirements, and find the area composed of black pixels connected to the black and white line segments according to the coordinates of the midpoints of the black and white line segments that meet the requirements. If it is a legal dot matrix code, three connected areas will be found.
[0031] The center coordinates of the three connected areas are calculated respectively, that is, the coordinates of the center points of the corresponding positioning areas or auxiliary positioning areas.
[0032] In some embodiments, the correction of the data dot code includes mapping the distorted graphic to the standard graphic, specifically including establishing a mapping from an xy coordinate system to a uv coordinate system, wherein the xy coordinate system is the distorted graphic coordinate system, the uv coordinate system is the standard graphic coordinate system, and the mapping formula is:
[0033]
[0034]
[0035] Among them, A~H can be solved by taking values of x, y, u, and v.
[0036] In some embodiments, the dot code correction further comprises:
[0037] The distorted image is mapped to the standard image coordinates, specifically, the distorted image is mapped to the standard image through an inverse perspective transformation.
[0038] According to another aspect of the present disclosure, a data dot code encoding device is provided, wherein the data dot code includes an encoding area, a positioning area, an auxiliary positioning area, and a center picture;
[0039] A first setting module, used for setting the three positioning areas and one auxiliary positioning area at the four vertex corners of the dot matrix code respectively;
[0040] The central image is set at the center of the dot matrix code;
[0041] The coding area is arranged at the periphery of the central image and between the positioning areas or between the positioning area and the auxiliary positioning area.
[0042] The first block division module is used to divide the coding area into multiple blocks, each block stores multiple bytes of data,
[0043] The first encoding module is used to encode each of the byte data into four data modules, each of the data modules is a large rectangle composed of 9 small rectangles of 3*3, each of the data modules has one and only one data point, and the data point is represented by a small black rectangle, wherein the small black rectangle is located at four optional positions in the large rectangle, namely, the upper left corner, the upper right corner, the lower left corner, and the lower right corner, and the four different positions represent four combinations of 2 bits, and a plurality of the data points constitute a data dot matrix,
[0044] The filling module is used to encode the byte data to be encoded into a data module and then fill it into the encoding area.
[0045] According to another invention of the present invention, a decoding device for a data dot matrix code is provided, wherein a first recognition module is used to recognize the data dot matrix code.
[0046] Preprocessing module, used for preprocessing dot code image data,
[0047] The second identification module is used to identify the data dot code positioning area and the auxiliary positioning area,
[0048] A correction module, used for correcting the data dot code,
[0049] The first decoding module is used to decode the header information in the header information area.
[0050] The second decoding module is used to decode the information stored in other blocks according to the header information.
[0051] The connection module is used to connect the data in the Block storing the data to obtain the bit stream.
[0052] The restoration module is used to restore the bit stream to original data.
[0053] According to another aspect of the present disclosure, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein:
[0054] When the processor executes the computer program, the steps of the above method are implemented.
[0055] According to another aspect of the present disclosure, a computer-readable storage medium for storing processor-executable instructions is provided. When the processor-executable instructions stored in the computer-readable storage medium are executed, the processor can cause the processor to implement the method for encoding and decoding the data dot code as described above.
[0056] The present disclosure provides a method, device, equipment and storage medium for encoding and decoding of data dot matrix codes, which can improve the user experience. Specifically, a dot matrix data representation method - data dot matrix is proposed, which uses a dot matrix data filling method. The encoder can customize and select some areas to fill the data dot matrix. Compared with the traditional two-dimensional code, the freely laid out dot matrix code has a great improvement in aesthetics. The encoding of the freely laid out dot matrix code is realized, and one or more central images and information to be encoded are received. After a series of processing, a freely laid out dot matrix code can be output. The decoding of the freely laid out dot matrix code is realized, and the decoding efficiency is high, which further improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] The technical solutions and other beneficial effects of the present invention will be made apparent by describing in detail the specific embodiments of the present invention in conjunction with the accompanying drawings.
[0058] Figure 1 A schematic flow chart of a method for encoding a data dot code provided in an embodiment of the present disclosure.
[0059] Figure 2 A schematic diagram of a freely arrangable dot matrix code pattern structure provided in an embodiment of the present disclosure.
[0060] Figure 3 A schematic diagram of a binary data lattice representation provided for an embodiment of the present disclosure.
[0061] Figure 4 A schematic diagram of the horizontal and vertical arrangement of data dot arrays provided in an embodiment of the present disclosure.
[0062] Figure 5 A schematic diagram showing the positioning area provided for an embodiment of the present disclosure.
[0063] Figure 6 A schematic diagram showing the auxiliary positioning area provided for an embodiment of the present disclosure.
[0064] Figure 7 A schematic flow chart of a method for decoding a data dot code provided in an embodiment of the present disclosure.
[0065] Figure 8 A schematic diagram of the finite state machine state transition in the positioning mark recognition algorithm provided in an embodiment of the present disclosure.
[0066] Fig. 9 A schematic diagram of intermediate results of executing the algorithm provided in an embodiment of the present disclosure.
[0067] Fig.10 A schematic diagram of a distorted graph provided in an embodiment of the present disclosure and its comparison with a standard graph.
[0068] Fig.11 A schematic diagram of an encoding device provided in an embodiment of the present disclosure.
[0069] Fig.12 A schematic diagram of a decoding device provided in an embodiment of the present disclosure.
[0070] Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0071] The technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. The terms "first", "second", "third", etc. (if any) in the specification and claims of the present disclosure and the accompanying drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the objects described in this way are interchangeable where appropriate. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. In the description of the present disclosure, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined. For those of ordinary skill in the art, the specific meanings of the above terms in the present disclosure can be understood according to the specific circumstances.
[0072] Embodiment 1:
[0073] Specifically, see Figure 1 , is a schematic flow chart of a data dot code encoding method provided in the first embodiment of the present disclosure. The specific steps are as follows:
[0074] S0 The data dot matrix code includes a coding area, a positioning area, an auxiliary positioning area and a central image; the three positioning areas and one auxiliary positioning area are respectively arranged at the four vertex corners of the dot matrix code;
[0075] S1 The central image is set at the center of the dot matrix code;
[0076] S2 The coding area is arranged at the periphery of the central image and between the positioning areas or between the positioning area and the auxiliary positioning area.
[0077] like Figure 2As shown, in one embodiment, the freely laid out data dot matrix code can be a square image of 912*912 pixels (if necessary, the user can modify the image size later, and the present disclosure does not limit it), and a square area of 768*768 pixels in the center of the freely laid out dot matrix code is used to store the center image, and the center image can be one or more; after obtaining the center image, its size can be adjusted so that the maximum side length of the image is 768 pixels, and it is placed in the specified area; then three positioning marks, namely positioning areas, are generated and adjusted to a size of 72*72 pixels, and then placed in the upper left, upper right, and lower left corners respectively, and then an auxiliary positioning mark, namely the auxiliary positioning area, is generated and adjusted to a size of 72*72 pixels and placed in the lower right corner.
[0078] The encoding area in S3 is divided into multiple blocks, each block stores multiple bytes of data, and each byte of data is encoded into four data modules.
[0079] like Figure 2 As shown, in one embodiment, the coding area is divided into 8 blocks in total (the number and size of the blocks can be set according to the actual application scenario, and the present disclosure does not impose any restrictions on this), each of which can store up to 12 bytes of data, and the entire freely laid out dot matrix code can store up to 96 bytes of data; since there is a situation where the amount of information is less than 96 bytes, in order to provide a better user experience, in one or more embodiments, the user can independently select a data filling scheme, for example, the user can evenly fill the data into multiple blocks, or only fill it into part of the blocks according to the amount of data; the encoder can customize some areas to fill the data dot matrix. Compared with the traditional QR code, the freely laid out dot matrix code has greatly improved in aesthetics, thereby improving the user experience.
[0080] like Figure 3 As shown, the data module: Figure 3 The four types of 3*3 large rectangles shown in the figure, one 3*3 large rectangle represents 2 bits, each large rectangle has one and only one black small rectangle, the black small rectangle has four possible positions, namely the upper left corner, the upper right corner, the lower left corner, and the lower right corner, and the four different positions represent four combinations of 2 bits; in one or more embodiments, the agreed rule is: the upper left corner represents 00, the upper right corner represents 01, the lower left corner represents 10, and the lower right corner represents 11; the encoding rules can be selected according to actual needs, and the present disclosure does not limit the specific encoding rules.
[0081] A data point is a small black rectangle in a data module; a data dot matrix is a combination of multiple data modules;
[0082] One byte is represented by four data modules. Although the four data modules can be arranged in many ways, we stipulate that there are only two legal representation methods: horizontal representation and vertical representation. Figure 4 As shown, there is a gap of data point width between each two data modules, which can ensure that no two data points are adjacent to each other;
[0083] S4 encodes the byte data to be encoded into a data module and fills it into the encoding area.
[0084] In one embodiment, among the multiple Blocks, one Block is a header information area for storing header information, and the other Blocks are information data areas for storing encoded information data dot matrixes; the header information includes the length of the data information and a number list of Blocks for storing the information data, the first byte of the header information is the data information length, the second byte is the length of the Block sequence number list, and the subsequent bytes are the Block numbers.
[0085] According to the distribution of data area blocks, the following design can be performed:
[0086] 1) Block 0 is the header information area, which only stores header information, and other blocks are information data areas, which are used to store the encoded information data dot matrix;
[0087] 2) Fill the encoded data dot matrix in the order of the numbers in the Block number list;
[0088] 3) The filling order of data dots in different blocks is different. The filling order can be divided into two types: filling order within bytes and filling order outside bytes;
[0089] a) Filling order within a byte: In a freely configurable dot matrix code, a byte is composed of four data modules, and the arrangement of these four data modules is the filling order within the byte;
[0090] b) Byte-out filling order: The four data modules are regarded as a unit representing a byte, and the arrangement of this unit is called the byte-out arrangement;
[0091] The filling order of each block is also different (hereinafter referred to as "in-byte filling order" and "out-byte filling order"):
[0092] a) Block 0: Inside the byte: from left to right, outside the byte: first from top to bottom, then from left to right
[0093] b) Block 1: Inside the byte: from right to left, outside the byte: first from top to bottom, then from right to left
[0094] c) Block 2: Inside the byte: from top to bottom, outside the byte: first from right to left, then from top to bottom
[0095] d) Block 3: Inside the byte: from top to bottom, outside the byte: first from left to right, then from top to bottom
[0096] e) Block 4: Inside the byte: from bottom to top, outside the byte: first from right to left, then from bottom to top
[0097] f) Block 5: Inside the byte: from bottom to top, outside the byte: first from left to right, then from bottom to top
[0098] g) Block 6: Inside the byte: from left to right, outside the byte: first from top to bottom, then from left to right
[0099] h) Block 7: Inside the byte: from right to left, outside the byte: first from top to bottom, then from right to left
[0100] The above method can be used to combine the encoded data dot matrix with the central image, etc. to form a complete dot matrix code that can be freely laid out.
[0101] Block 0 is the header information area, which is only used to store header information. Blocks 1 to 7 are the information data area, which are used to store other information data. The header information consists of two parts: 1) the length of the data information; 2) the number list of the blocks used to store the information data. The data information is calculated based on the information to be encoded, and the number list of the blocks is specified by the user. Before encoding, the encoding system will check for illegal situations such as the mismatch between the number list specified by the user and the length of the data information.
[0102] The header information in the header information encoding is divided into two parts, the data information length and the block sequence number list; the header information contains only non-negative integers, which can be directly represented by binary numbers; it is stipulated that the first byte of the header information is the data information length, the second byte is the length of the block sequence number list, and the subsequent bytes are the block numbers;
[0103] The information data encoding refers to encoding the information, i.e. the input string, into a byte stream according to the "iso-8859-1" encoding specification.
[0104] In one embodiment, the positioning mark, i.e., the positioning area, and the auxiliary correction mark, i.e., the positioning mark in the auxiliary positioning area, are patterns that help the decoding program locate; the positioning mark allows the user to scan from any angle without aligning the dot matrix code, and the decoding program can read the data in the dot matrix code; the design of the positioning mark of the dot matrix code that can be freely arranged refers to the positioning mark of the currently widely used QR Code, but some modifications are made on its basis to facilitate alignment with the data dot matrix, such as Figure 5As shown in the figure, the similarities between the two are: 1) the number of positioning marks is 3; 2) the positioning marks are distributed in the upper left, upper right and lower left corners; the main differences are: in the positioning marks of QRCode, the ratio of "black-white-black-white-black" is 1:1:3:1:1, and in the positioning marks of the freely laid out dot matrix code, the ratio of "black-white-black-white-black" is 2:1:5:1:2;
[0105] The main function of the auxiliary correction mark is to assist in the correction of the dot matrix code during the decoding process. The "black-white-black-white-black" ratio is 2:2:3:2:2. Figure 6 shown.
[0106] Embodiment 2
[0107] like Figure 7 FIG. 1 is a flowchart of a decoding method for the encoding method of the aforementioned data dot code provided in the second embodiment of the present disclosure. The specific steps are as follows:
[0108] S21 identifies the data dot code.
[0109] In one embodiment, dot matrix code photos can be collected at a certain frequency and the photos can be decoded, similar to ordinary code scanning operations, or dot matrix code operations can be recognized through pictures.
[0110] S22 pre-processes the dot matrix code image data.
[0111] In one embodiment, the image preprocessing refers to grayscale, binarization and other processing performed on the image before the freely laid out dot matrix code recognition is performed to speed up the recognition speed and improve the recognition accuracy; the significance of the preprocessing is, on the one hand, to reduce the noise interference in the original image and enhance the representation of effective data, and on the other hand, to simplify the image, facilitate subsequent calculations, and improve the efficiency of subsequent algorithms.
[0112] S23 identifies the data dot code positioning area and the auxiliary positioning area.
[0113] In one embodiment, the dot code positioning may use a finite state machine and a positioning mark recognition algorithm to identify the positioning mark and the auxiliary correction mark.
[0114] In one embodiment, the basic idea of positioning landmark recognition is as follows:
[0115] 1) Scan the binarized image line by line. If a line segment of black-white-black-white-black that meets the pattern of 2:1:5:1:2 is found, the coordinates of the pixel at the midpoint of this line segment are recorded.
[0116] 2) Execute the image labeling algorithm which will be described in detail later. The purpose of this algorithm is to find the area consisting of all connected black pixels;
[0117] 3) Then, based on the coordinates of the midpoints of all qualified line segments (in one embodiment, qualified line segments can be obtained by the finite state machine method described below), find the area consisting of the black pixels connected to them. If it is a legal dot matrix code, three connected areas will be found;
[0118] 4) Calculate the center coordinates of the connected areas formed by the three black pixels respectively, which are the coordinates of the center points of the positioning mark;
[0119] In one embodiment, a finite state machine can be used to find black and white line segments that meet the requirements. First, it is necessary to consider how to convert pixels in a row into several line segments. The pseudo code is as follows:
[0120] 1) Read in a row of pixel array;
[0121] 2) Initialize the counter count = 0; initialize a list L for storing line segments, and insert a line segment with a length of 0 and a color equal to the color of the first pixel in the array;
[0122] 3) Read the count-th pixel point. If the pixel point has the same color as the last line segment in L, increase the length of the line segment by one. If the pixel point has a different color from the last line segment in L, insert a line with a length of 1 and the color of this pixel into L.
[0123] 4) Increment the counter count value by one, and repeat steps 3)-4) until the counter count value equals the number of pixels;
[0124] Executing the above pseudocode will get a list of black and white line segments. Then we need to design a finite state machine suitable for the current problem. Since at least five input line segments are required to finally identify the line segments that meet the conditions, the finite state machine should have 6 states. Figure 8 The state transition diagram for this finite state machine;
[0125] 1) Initially, the state machine is in state 0, i.e., the start state. It is in state 0 when receiving a white line segment, and enters state 1 only when receiving a black line segment. After entering state 1, the unit length needs to be calculated based on the current black line segment, and the unit length = black line segment length / 2.
[0126] 2) When in state 1, the next line segment received must be white. If the length of the white line segment is approximately equal to the unit length, enter state 2, otherwise enter state 0;
[0127] 3) When in state 2, the next line segment received must be black. If the length of the black line segment is approximately equal to 5 times the unit length, enter state 3, otherwise enter state 1 and recalculate the unit length;
[0128] 4) When in state 3, the next line segment received must be white. If the length of the white line segment is approximately equal to the unit length, enter state 4, otherwise enter state 0;
[0129] 5) When in state 4, the next line segment received must be black. If the length of the black line segment is approximately equal to 2 times the unit length, enter state 5, otherwise enter state 1 and recalculate the unit length;
[0130] 6) Arriving at state 5 means successfully finding a black and white line segment that meets the requirements of 2:1:5:1:2, and automatically entering state 0; in state 5, the coordinates of the center point of the line segment that meets the requirements can be recorded;
[0131] The image labeling algorithm may be to label the area consisting of all connected black pixels in the binarized image with a unique label; the algorithm is divided into two parts, the first part assigns a label to each black area, and a black area may have more than one label, and the second part removes the redundant labels in a black area and only retains a unique label;
[0132] The pseudo code for the first part is as follows:
[0133] 1) Initialize some necessary variables: currentLabel, which indicates the current label, and label is an incrementing variable; an empty array Labels, which indicates the minimum value of the label of the black area connected to the black area marked by the current Label in the picture, such as Labels[j] = k, which indicates that the minimum value of the label of the black area connected to the black area marked by Labelj is k;
[0134] 2) Read the pixels in the image row by row, analyzing each pixel from left to right;
[0135] 3) If the current pixel is white, ignore this pixel and continue to analyze the next pixel; if the current pixel is black, go to step 4;
[0136] 4) If the pixel to the left of the current pixel and the pixel directly above the current pixel are both white, then currentLabel is used as the label of the current pixel, and the Labels array also needs to be updated, so that Labels[currentLabel] is equal to currentLabel, and the value of currentLabel is increased by 1;
[0137] 5) Black pixels must have been assigned a label. If only one of the left pixel and the pixel directly above is black, the label value of that pixel is directly used as the current pixel label;
[0138] 6) If the pixel to the left and the pixel directly above the current pixel are all black, the smaller value of the Label of the pixel to the left and the pixel directly above is selected as the Label of the current pixel. At the same time, the information in the Labels array needs to be updated, that is, Labels[larger Label] = smaller Label;
[0139] After the algorithm in the first part, we can basically get a Fig. 9 The intermediate result is, where the black and white rectangles correspond to the black and white pixels in the image, and the number on the black rectangle is the label corresponding to the black pixel; after the first part of the algorithm, there may be multiple labels in the same complete connected area, but at the same time there is a Labels array that has recorded the information of the label connection. Fig. 9 In the results shown, the Labels array should have the following relationship: Labels[2] = 1;
[0140] The second part of the algorithm needs to remove the redundant Labels in the same black connected area based on the results of the first part and the Labels array; the pseudo code is as follows:
[0141]
[0142]
[0143] 11) Traverse the pixels in the image row by row. If the current pixel is black, set its label: label = Labels[label]
[0144] The core idea of the second part of the algorithm is to query forward in a chain based on the Labels array obtained in the first part, and update the current label until the current label is equal to the smallest label in the current black area, and then re-traverse the image to update the pixel label; after these two steps, we can assign a displacement label to each black area in the image;
[0145] In combination with the above description, in one embodiment, the positioning mark recognition algorithm refers to a complete positioning mark algorithm that should also find the center of the positioning mark. Only by finding the center of the positioning mark can a coordinate mapping relationship from the original image captured by the image acquisition device to the standard freely configurable dot matrix code be established;
[0146] After using the positioning landmark recognition algorithm to find the line segment that meets the requirements, we can calculate the coordinates of the midpoint of the line segment. Combined with the image labeling algorithm in the previous section, we can further obtain the label of the point.
[0147] Although the positioning mark recognition algorithm can identify multiple line segments that meet the requirements, many line segments are actually in the same positioning mark, so the labels of their midpoints are the same; under normal circumstances, it can be found that the midpoints of these line segments correspond to three labels in total, and then the average values of the horizontal and vertical coordinates of all the pixels in the black area corresponding to the three labels are calculated to obtain the coordinates of the center point of the positioning mark;
[0148] So far, the center point coordinates of the three positioning marks can be successfully obtained. Using the same method, the center point coordinates of the auxiliary positioning mark can also be obtained;
[0149] S24 corrects the data dot code.
[0150] In actual operation, it is possible that the image captured by the image acquisition device may be distorted in perspective due to problems such as shooting angle. In this case, the distorted image needs to be transformed inversely in order to perform subsequent decoding operations. Fig.10 As shown, in (a), xy is the coordinate system of the distorted image, and in (b), uv is the coordinate system of the standard image. The inverse perspective transformation can establish a mapping relationship from the uv coordinate system to the xy coordinate system. The mapping formula is as follows:
[0151]
[0152]
[0153] Among them, A~H are the parameters to be calculated. These parameters can be solved according to the coordinates of the center points of the three positioning marks and one auxiliary correction mark calculated previously, thus obtaining the mapping relationship from the uv coordinate system to the xy coordinate system.
[0154] S25 decodes the header information in the header information area.
[0155] S26 decodes the information stored in other blocks according to the header information.
[0156] S27 connects the data in the Block storing the data to obtain a bit stream.
[0157] S28 restores the bit stream to original data.
[0158] In one embodiment, Figure 2Taking the standard free layout dot matrix code as an example, the decoding time is analyzed by shooting from six different angles. Although the shooting angles are different, the time spent on decoding a picture is roughly the same, about 465ms. Due to different devices, the time spent on decoding will also vary. The absolute decoding time is not very meaningful, and the relative time spent in each stage is more valuable for reference.
[0159] The time spent in the dot code positioning stage accounts for about 88% of the total time; since both the positioning mark recognition algorithm and the image marking algorithm need to traverse every pixel, in the code implementation, only the image pixels are traversed once and the two algorithms are executed at the same time; the currently designed decoding algorithm can decode the information in the dot code within 0.5 seconds, which is highly efficient.
[0160] In one embodiment, as mentioned above, the freely configurable dot code decoding system uses a finite state machine to identify the positioning mark. The dot code positioning is the basis of the entire decoding system. Only by correctly identifying the positioning mark can the dot code area and the direction of the dot code be located. The freely configurable dot code correction requires the use of an image marking algorithm, a positioning mark recognition algorithm, and an inverse perspective transformation to correct the deformation of the dot code image acquired by the image acquisition device due to the shooting angle and other issues, calculate the coordinates of the key points in the standard dot code image in the dot code image acquired by the image acquisition device, and establish a mapping relationship. In the decoding stage of the freely configurable dot code decoding system, take decoding of 2 bits of information represented by a data module as an example: there are a total of nine small rectangles in the data module, in which data points may appear in the upper left, upper right, lower left, and lower right positions. Therefore, the previously obtained mapping relationship can be used to determine the coordinates of the four positions in the standard dot code graphic in the captured image, and then check whether the coordinates fall within the black connected area. However, this method is not efficient, mainly for the following reasons:
[0161] 1) The four coordinates in the standard graph need to be mapped to the captured image. In the worst case, four checks need to be done to see if they are within the black connected area;
[0162] 2) The algorithm to check whether the point is in the black area is very complex. First, you need to traverse the coordinates of the center points of all black areas to find the black area that is closest to the current point; then you need to traverse one or more black areas to determine whether the point is in the black area;
[0163] The decoding method adopted in the present disclosure is more efficient, the number of coordinate conversions is only 1 / 4 of the above method, and it is also simpler to check whether the four positions are black.
[0164] Embodiment three:
[0165] To achieve the above purpose, this embodiment provides a data dot code encoding device 1100, see Fig.11 Specifically, the apparatus 1100 includes: a first setting module 1101 , a first blocking module 1102 , a first encoding module 1103 , and a filling module 1104 .
[0166] The data dot matrix code includes a coding area, a positioning area, an auxiliary positioning area and a central picture;
[0167] The first setting module 1101 is used to set the three positioning areas and one auxiliary positioning area at the four corners of the dot matrix code respectively;
[0168] The central image is set at the center of the dot matrix code;
[0169] The coding area is arranged at the periphery of the central image and between the positioning areas or between the positioning area and the auxiliary positioning area.
[0170] The first block division module 1102 is used to divide the coding area into a plurality of blocks, each block storing a plurality of bytes of data.
[0171] The first encoding module 1103 is used to encode each of the byte data into four data modules, each of the data modules is a large rectangle composed of 9 small rectangles of 3*3, each of the data modules has one and only one data point, and the data point is represented by a small black rectangle, wherein the small black rectangle is located at four optional positions in the large rectangle, namely, the upper left corner, the upper right corner, the lower left corner, and the lower right corner, and the four different positions represent four combinations of 2 bits, and multiple data points constitute a data dot matrix,
[0172] The filling module 1104 is used to encode the byte data to be encoded into a data module and then fill it into the encoding area.
[0173] Embodiment 4:
[0174] To achieve the above purpose, this embodiment provides a decoding device 1200 for a data dot code. Fig.12 Specifically, the apparatus 1200 includes a first recognition module 1201 , a preprocessing module 1202 , a second recognition module 1203 , a correction module 1204 , a first decoding module 1205 , a second decoding module 1206 , a connection module 1207 , and a restoration module 1208 .
[0175] The first recognition module 1201 is used to recognize the data dot matrix code.
[0176] The preprocessing module 1202 is used to preprocess the dot matrix code image data.
[0177] The second identification module 1203 is used to identify the data dot code positioning area and the auxiliary positioning area.
[0178] The correction module 1204 is used to correct the data dot code.
[0179] The first decoding module 1205 is used to decode the header information in the header information area.
[0180] The second decoding module 1206 is used to decode the information stored in other blocks according to the header information.
[0181] The connection module 1207 is used to connect the data in the Block storing the data to obtain a bit stream.
[0182] The restoration module 1208 is used to restore the bit stream to original data.
[0183] Embodiment five:
[0184] Accordingly, an embodiment of the present application further provides an electronic device, which may be a terminal or a server. Fig.13 As shown, Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0185] The electronic device 1300 includes a processor 1301 having one or more processing cores, a memory 1302 having one or more computer-readable storage media, and a computer program stored in the memory 1302 and executable on the processor. The processor 1301 is electrically connected to the memory 1302. Those skilled in the art will appreciate that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0186] Processor 1301 is the control center of electronic device 1300. It uses various interfaces and lines to connect various parts of the entire electronic device 1300, executes various functions of electronic device 1300 and processes data by running or loading software programs (computer programs) and / or units stored in memory 1302, and calling data stored in memory 1302, thereby monitoring electronic device 1300 as a whole.
[0187] In an embodiment of the present application, the processor 1301 in the electronic device 1300 will load the instructions corresponding to the processes of one or more applications into the memory 1302 in accordance with the method steps of the aforementioned embodiment, and the processor 1301 will run the applications stored in the memory 1302 to implement various functions.
[0188] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0189] Optional, such as Fig.13 As shown, the electronic device 1300 further includes: an encoding module 1303, a decoding module 1307, a communication module 1304, an input unit 1305, and a power supply 1306. The processor 1301 is electrically connected to the encoding module 1303, the decoding module 1307, the communication module 1304, the input unit 1305, and the power supply 1306, respectively. Those skilled in the art will appreciate that Fig.13 The electronic device structure shown in the figure does not constitute a limitation of the electronic device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0190] The encoding module 1303 and the decoding module 1307 can be used to implement the encoding and decoding of the data dot code. The specific implementation of the encoding and decoding operation of the data dot code can refer to the previous embodiment, which will not be repeated here.
[0191] The communication module 1304 may be used to communicate with other devices.
[0192] The input unit 1305 may be used to receive input numbers, character information or user feature information (such as fingerprint, iris, facial information, etc.), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0193] The power supply 1306 is used to supply power to various components of the electronic device 1300. Optionally, the power supply 1306 can be logically connected to the processor 1301 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 1306 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0194] Embodiment six:
[0195] To achieve the above objectives, this embodiment proposes a computer-readable storage medium for storing processor-executable instructions. When the processor-executable instructions stored in the computer-readable storage medium are executed, the processor can implement the method of encoding and decoding the data dot code as described above.
[0196] In the above embodiments, specific embodiments are used to illustrate the principles and implementation methods of the present disclosure. The descriptions of each embodiment have their own focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The descriptions of the above embodiments are only used to help understand the technical solutions and core ideas of the present disclosure; ordinary technicians in this field should understand that they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein with equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A method for encoding a data dot code, characterized in that: The data dot matrix code includes a coding area, a positioning area, an auxiliary positioning area and a central picture; The three positioning areas and one auxiliary positioning area are respectively arranged at the four vertex corners of the dot matrix code; The central image is set at the center of the dot matrix code; The coding area is arranged at the periphery of the central image and between the positioning areas or between the positioning area and the auxiliary positioning area. The coding area is divided into multiple blocks, each block stores multiple bytes of data, and each byte of data is encoded into four data modules. Each of the data modules is a large rectangle composed of 9 small rectangles of 3*3. Each of the data modules has one and only one data point, which is represented by a small black rectangle. The small black rectangle is located at four optional positions in the large rectangle, namely, the upper left corner, the upper right corner, the lower left corner, and the lower right corner. The four different positions represent four combinations of 2 bits. Multiple data points form a data dot matrix. The byte data to be encoded is encoded into a data module and then filled into the encoding area.
2. The method according to claim 1, characterized in that The coding area is equally divided into 8 blocks, and each block stores a maximum of 12 bytes of data.
3. The method according to claim 1, characterized in that The central picture is one or more.
4. The method according to claim 1, characterized in that Among the multiple blocks, one block is a header information area for storing header information, and the other blocks are information data areas for storing encoded information data dot matrixes; the header information includes the length of the data information and a number list of blocks for storing information data, the first byte of the header information is the data information length, the second byte is the length of the Block sequence number list, and the subsequent bytes are the Block numbers.
5. The method according to claim 1, characterized in that Fill the encoded data dot matrix in sequence according to the number order in the Block number list.
6. The method according to claim 5, characterized in that The data dot matrix filling order of different blocks is different. The filling order is subdivided into two types: byte filling order and byte outside filling order; The byte filling order means that in the dot matrix code, one byte is composed of four data modules. The arrangement of these four data modules is the byte filling order. There is a data point width interval between every two data modules in the byte filling. Byte-out filling order means that four data modules are regarded as a unit representing a byte, and the arrangement of this unit is called byte-out arrangement.
7. According to the method of claim 6, the filling order of each Block is different, and the filling order within the byte is from left to right or from top to bottom, and the filling order outside the byte is from top to bottom and / or from left to right.
8. According to the method of claim 1, the ratio of "black-white-black-white-black" line segments in the positioning area is 2:1:5:1:2, and the ratio of "black-white-black-white-black" in the auxiliary positioning area is 2:2:3:2:
2.
9. A decoding method adapted to the data dot code encoding method according to any one of claims 1 to 8, characterized in that: Identify the data dot code, Preprocess the dot code image data. Identify the data dot code positioning area and the auxiliary positioning area, Correcting the data dot code, Decode the header information in the header information area, Decode the information stored in other blocks according to the header information. Connect the data in the Block storing the data to get the bit stream. The bit stream is restored to original data.
10. The method according to claim 9, characterized in that The preprocessing includes grayscale and binarization processing.
11. The method according to claim 9, characterized in that Identify the data dot code positioning area and the auxiliary positioning area, specifically, Scan the binarized image line by line. If a black-white-black-white-black line segment that meets the pattern 2:1:5:1:2 or 2:2:3:2:2 is found, the coordinates of the pixel at the midpoint of the line segment are recorded. Find the area consisting of all connected black pixels; Get the black and white line segments that meet the requirements, and find the area composed of black pixels connected to the black and white line segments according to the coordinates of the midpoints of the black and white line segments that meet the requirements. If it is a legal dot matrix code, three connected areas will be found. The center coordinates of the three connected areas are calculated respectively, that is, the coordinates of the center points of the corresponding positioning areas or auxiliary positioning areas.
12. The method according to claim 11, characterized in that The correction of the data dot code includes mapping the distorted graphic to the standard graphic, specifically including establishing a mapping from an xy coordinate system to a uv coordinate system, wherein the xy coordinate system is the distorted graphic coordinate system, the uv coordinate system is the standard graphic coordinate system, and the mapping formula is: ; Among them, A~H are solved by taking values of x, y, u, and v, and A~H are parameters to be solved. These parameters are solved according to the coordinates of the center point of the corresponding positioning area or auxiliary positioning area.
13. The method according to claim 9, characterized in that The dot code correction further comprises: The distorted image is mapped to the standard image coordinates, specifically, the distorted image is mapped to the standard image through an inverse perspective transformation.
14. A data dot code encoding device, characterized in that: The data dot matrix code includes a coding area, a positioning area, an auxiliary positioning area and a central picture; A first setting module, used for setting the three positioning areas and one auxiliary positioning area at the four vertex corners of the dot matrix code respectively; The central image is set at the center of the dot matrix code; The coding area is arranged at the periphery of the central image and between the positioning areas or between the positioning area and the auxiliary positioning area. The first block division module is used to divide the coding area into multiple blocks, each block stores multiple bytes of data, The first encoding module is used to encode each of the byte data into four data modules, each of the data modules is a large rectangle composed of 9 small rectangles of 3*3, each of the data modules has one and only one data point, and the data point is represented by a small black rectangle, wherein the small black rectangle is located at four optional positions in the large rectangle, namely, the upper left corner, the upper right corner, the lower left corner, and the lower right corner, and the four different positions represent four combinations of 2 bits, and a plurality of the data points constitute a data dot matrix, The filling module is used to encode the byte data to be encoded into a data module and then fill it into the encoding area.
15. A decoding device adapted to the data dot code encoding method according to any one of claims 1 to 8, characterized in that: A first recognition module is used to recognize the data dot matrix code. Preprocessing module, used for preprocessing dot code image data, The second identification module is used to identify the data dot code positioning area and the auxiliary positioning area, A correction module, used for correcting the data dot code, The first decoding module is used to decode the header information in the header information area. The second decoding module is used to decode the information stored in other blocks according to the header information. The connection module is used to connect the data in the Block storing the data to obtain the bit stream. The restoration module is used to restore the bit stream to original data.
16. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 13 are implemented.
17. A computer-readable storage medium for storing processor-executable instructions, wherein the processor-executable instructions stored in the computer-readable storage medium can cause a processor to implement the method according to any one of claims 1 to 13 when being executed.
Citation Information
Patent Citations
Rectangular fixed dot matrix information encoding and decoding method
CN106845593A
Dot-matrix two-dimensional code and coding and identification methods for dot-matrix two-dimensional code
CN108334922A