A two-dimensional code encoding and decoding method and an electronic device
By segmenting the text to be encoded and selecting an encoding mode with a lower bit depth, the problem of insufficient QR code data capacity is solved, enabling the generation of shorter binary strings to store longer text.
Patent Information
- Application Number
- CN202110486582.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-30
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2041-04-30
AI Technical Summary
In existing technologies, when electronic devices encode information to be stored, the length of the generated binary string is too long, exceeding the data capacity of the QR code, thus making it impossible to generate a QR code.
By dividing the text to be encoded into multiple character segments and selecting the target encoding mode for each character segment, a lower bit encoding mode is used for encoding, resulting in a shorter binary string.
This effectively reduces the length of the binary string, allowing the character segment to use only a few pattern indicators, thus enabling the storage of longer text in QR codes.
Smart Images

Figure CN115271013B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of terminal artificial intelligence (AI) and corresponding subfields, the field of information storage, and in particular, to a two-dimensional code encoding and decoding method and an electronic device. BACKGROUND
[0002] Nowadays, two-dimensional codes are widely used in life. Users can see two-dimensional codes everywhere in life. For example, users can use electronic devices to scan two-dimensional codes to realize payment, information acquisition, account login, and the like. Two-dimensional codes can be used to store payment information, account login information, and the like. Common two-dimensional codes include quick response (QR) codes, circular two-dimensional codes, and the like. Different versions of two-dimensional codes have different capacities for storing information.
[0003] An electronic device can encode a binary string from information (referred to as to-be-stored information, for example, a string) that needs to be stored in a two-dimensional code and then generate a two-dimensional code. For to-be-stored information, different encoding methods of an electronic device result in different lengths of binary strings. Since two-dimensional codes have limited capacities, it is desirable for an electronic device to encode to-be-stored information into a binary string that is as short as possible.
[0004] Therefore, how an electronic device encodes to-be-stored information into a binary string that is shorter in length is a problem that needs to be solved. SUMMARY
[0005] The present application provides a two-dimensional code encoding and decoding method and an electronic device. In the two-dimensional code encoding method provided by the present application, an electronic device can encode to-be-encoded text into a binary string that is shorter in length. In the two-dimensional code decoding method provided by the present application, an electronic device can decode a two-dimensional code that is encoded by using the two-dimensional code encoding method of the present application.
[0006] In a first aspect, the present application provides a two-dimensional code encoding method, which can include: an electronic device obtaining to-be-encoded text, the to-be-encoded text containing N characters, N being a positive integer; the electronic device determining a target encoding mode of each character in the N characters from X selectable encoding modes; the electronic device dividing the N characters into M character segments according to the target encoding mode of each character and determining a target encoding mode of each character segment in the M character segments; M is less than or equal to N; the electronic device encoding the M character segments according to the target encoding mode of each character segment to obtain a first binary string; and the electronic device generating a two-dimensional code of a version corresponding to the length of the first binary string from the first binary string.
[0007] By the two-dimensional code encoding method provided in the embodiments of the present application, the electronic device can encode the to-be-encoded text into a shorter binary string. When the character length in the to-be-encoded text is too long, the binary string obtained by the encoding method in the prior art exceeds the data capacity in the two-dimensional code in the prior art, resulting in that the two-dimensional code cannot be generated. By using the two-dimensional code encoding method in the embodiments of the present application, the to-be-encoded text with a longer character length can be encoded, and the two-dimensional code is generated.
[0008] In a possible implementation, the electronic device determines the target encoding mode of each character in the N characters from the X selectable encoding modes, including: the electronic device determines one or more candidate encoding modes of a first character in the N characters from the X selectable encoding modes; and the electronic device selects a candidate encoding mode with the lowest number of encoding bits from the one or more candidate encoding modes as the target encoding mode of the first character.
[0009] In this way, the electronic device can encode each character into a binary string with a lower number of bits. Thus, the electronic device can obtain a shorter binary string by encoding the to-be-encoded text.
[0010] In a possible implementation, the electronic device divides the N characters into M character segments according to the target encoding mode of each character in the N characters, and determines the target encoding mode of each character segment in the M character segments, including: the electronic device divides the characters that are continuously adjacent and have the same target encoding mode in the N characters into a character segment, to obtain the M character segments; and the electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in each character segment.
[0011] In a possible implementation, the M character segments include a first character segment, the first character segment includes a first character and a second character, the target encoding modes of the first character and the second character are the same, and the target encoding mode of the first character segment is the same as the target encoding modes of the first character and the second character.
[0012] In this way, the electronic device divides the N characters into character segments for encoding, which can save the number of binary bits occupied by the mode indicators, and thus a shorter binary string can be obtained.
[0013] In a possible implementation, the electronic device divides the N characters into M character segments according to the target encoding mode of each character in the N characters, and determines the target encoding mode of each character segment in the M character segments, including: the electronic device divides the characters that are continuously adjacent and have the same target encoding mode and are greater than a preset number into a character segment, to obtain the M character segments; and the electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in each character segment.
[0014] In this way, the electronic device can divide the N characters into fewer character segments, and only one mode indicator is needed for each character segment. Compared with one character as one character segment, the electronic device obtains fewer mode indicators in the binary string. In this way, the number of bits of the mode indicators can be saved. Thus, the electronic device can obtain a shorter binary string.
[0015] In a possible implementation, the M character segments include a second character segment, and the number of characters in the second character segment is greater than or equal to the preset number.
[0016] In a possible implementation, the electronic device divides the N characters into M character segments according to the target encoding mode of each of the N characters, and determines the target encoding mode of each of the M character segments, including: the electronic device starts counting from the first character in the N characters; when the (u-1)th character is counted, the electronic device determines that the number of characters is greater than or equal to the preset number, and the target encoding mode of the (u-1)th character is different from that of the u th character, the electronic device divides the first character to the (u-1)th character in the N characters into one character segment, and obtains the M character segments; and the electronic device determines the target encoding mode of each of the M character segments based on the target encoding mode of the characters in each of the M character segments.
[0017] In this way, the electronic device can divide the N characters into fewer character segments, and only one mode indicator is needed for each character segment. Compared with one character as one character segment, the electronic device obtains fewer mode indicators in the binary string. In this way, the number of bits of the mode indicators can be saved. Thus, the electronic device can obtain a shorter binary string.
[0018] In a possible implementation, the M character segments include a first character segment, and the electronic device determines the target encoding mode of each of the M character segments based on the target encoding mode of the characters in each of the character segments, including: the electronic device determines that the target encoding mode of the first character and the second character in the first character segment is the first target encoding mode; and the electronic device takes the first target encoding mode as the target encoding mode of the first character segment.
[0019] In a possible implementation, the M character segments include a first character segment, and the electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the character in each character segment, including: the electronic device determines that the target encoding mode of a first character in the first character segment is a first target encoding mode, and the target encoding mode of a second character in the first character segment is a second target encoding mode, where the number of encoding bits of the first target encoding mode is higher than that of the second target encoding mode, and the first target encoding mode corresponds to an encoding index table that includes the second character, and the first target encoding mode and the second target encoding mode are included in the X optional encoding modes; and the electronic device takes the first target encoding mode as the target encoding mode of the first character segment.
[0020] In a possible implementation, the M character segments include a first character segment, and the electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the character in each character segment, including: the electronic device determines that the target encoding mode of a first character in the first character segment is a first target encoding mode, and the target encoding mode of a second character in the first character segment is a second target encoding mode, where the first target encoding mode is different from the second target encoding mode, the encoding index table corresponding to the first target encoding mode does not include the first character, the encoding index table corresponding to the second target encoding mode does not include the second character, the number of encoding bits corresponding to a third target encoding mode is higher than that of the first target encoding mode and the second target encoding mode, and the first target encoding mode, the second target encoding mode, and the third target encoding mode are included in the X optional encoding modes; and the electronic device takes the third target encoding mode as the target encoding mode of the first character segment.
[0021] In a possible implementation, the first binary string includes a second binary string, the second binary string is obtained by encoding the first character segment, and the second binary character segment includes a mode indicator of the target encoding mode of the first character segment, an indicator of the length of the character in the first character segment, and a binary string obtained by encoding the character in the first string according to the target encoding mode of the first string.
[0022] In a possible implementation, the N characters include one or more of a numeric character, an uppercase letter character, a lowercase letter character, a special character, and an escape character, and the target encoding mode corresponding to the numeric character, the uppercase letter character, the lowercase letter character, the special character, and the escape character has different minimum number of encoding bits.
[0023] In a possible implementation, each of the X selectable encoding modes corresponds to an encoding index table; the encoding index tables include a first encoding index table, a second encoding index table, a third encoding index table, a fourth encoding index table, a fifth encoding index table, a sixth encoding index table, a seventh encoding index table, and an eighth encoding index table; the first encoding index table contains numeric characters; the second encoding index table contains numeric characters and uppercase letter characters; the third encoding index table contains numeric characters and lowercase letter characters; the fourth encoding index table contains uppercase letter characters and special characters; the fifth encoding index table contains lowercase letter characters and special characters; the sixth encoding index table contains numeric characters, uppercase letter characters, and special characters; the seventh encoding index table contains numeric characters, lowercase letter characters, and special characters; and the eighth encoding index table contains numeric characters, uppercase letter characters, lowercase letter characters, and special characters.
[0024] In a possible implementation, the two-dimensional code includes a first version of two-dimensional code, a second version of two-dimensional code, a third version of two-dimensional code, a fourth version of two-dimensional code, a fifth version of two-dimensional code, and a sixth version of two-dimensional code, and the data capacities of the first version of two-dimensional code, the second version of two-dimensional code, the third version of two-dimensional code, the fourth version of two-dimensional code, the fifth version of two-dimensional code, and the sixth version of two-dimensional code are different.
[0025] In a possible implementation, the two-dimensional code is a circular two-dimensional code, the circular two-dimensional code includes an encoding region composed of a plurality of concentric circles, and each of the plurality of concentric circles contains a plurality of code elements on a ring of the concentric circle.
[0026] In a second aspect, a two-dimensional code decoding method is provided, which can include: an electronic device obtaining a two-dimensional code to be decoded, the two-dimensional code to be decoded indicating first information; the electronic device obtaining mode indication information from the two-dimensional code to be decoded; the electronic device determining an encoding mode of the two-dimensional code to be decoded from the mode indication information, the electronic device storing one or more mapping relationship tables, the mapping relationship tables containing the mode indication information and the encoding mode corresponding to the mode indication information; and the electronic device decoding the two-dimensional code to be decoded according to the encoding mode to obtain the first information.
[0027] In this way, through the two-dimensional code decoding method provided in the present application, the electronic device can decode two-dimensional codes of different encoding modes.
[0028] In a possible implementation, the two-dimensional code to be decoded contains an encoding region, and the electronic device determines the mode indication information from the two-dimensional code to be decoded, specifically including: the electronic device obtaining the mode indication information from code elements in the encoding region that store the mode indication information. In this way, the electronic device can obtain the mode indication information.
[0029] In a possible implementation, before the electronic device acquires the mode indication information from the symbol storing the mode indication information in the encoding area, the method further includes: acquiring, by the electronic device, version information of the to-be-decoded two-dimensional code, and determining, by the electronic device, a target version of the to-be-decoded two-dimensional code based on the version information; the target version indicates coordinate information of each storage location in the encoding area of the to-be-decoded two-dimensional code; and determining, by the electronic device, binary values corresponding to storage locations occupied by each of the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the coordinate information of each storage location. In this way, the electronic device can accurately obtain the binary values corresponding to each symbol in the encoding area.
[0030] Optionally, the binary data can be 0 or 1.
[0031] In a possible implementation, the electronic device can determine the version information of the to-be-decoded two-dimensional code according to a distance between any two locators in the to-be-decoded two-dimensional code. Different version information corresponds to different distances between any two locators in the two-dimensional code.
[0032] In a possible implementation, the electronic device decodes the to-be-decoded two-dimensional code according to the encoding mode to obtain the first information, including: decoding, by the electronic device, the binary values corresponding to the storage locations occupied by each of the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the encoding mode to obtain the first information. Different encoding modes correspond to different numbers of encoding bits, so that the electronic device can accurately decode the binary values corresponding to the number of bits to obtain the first information according to the encoding mode.
[0033] In a possible implementation, the electronic device acquires the mode indication information from the to-be-decoded two-dimensional code, including: acquiring, by the electronic device, one mode indication information from the to-be-decoded two-dimensional code, and one or more sub-mode indication information contained in the mode indication information.
[0034] The electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, including: determining, by the electronic device, the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, and determining one or more encoding sub-modes of the to-be-decoded two-dimensional code from the one or more sub-mode indication information.
[0035] The electronic device decodes the binary values corresponding to the storage locations occupied by each of the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the encoding mode to obtain the first information, including: decoding, by the electronic device, the binary values corresponding to the storage locations occupied by each of the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the one or more encoding sub-modes to obtain the first information.
[0036] The first information can be coded into the to-be-decoded two-dimensional code by a plurality of coding sub-modes in one coding mode. In this way, the electronic device can accurately decode the first information from the to-be-decoded two-dimensional code through step-by-step sub-decoding.
[0037] In a possible implementation, the one or more coding sub-modes include a first coding sub-mode and a second coding sub-mode, and the coding region includes a first coding region and a second coding region; the electronic device decodes the binary values corresponding to the storage positions occupied by the plurality of code elements in the coding region of the to-be-decoded two-dimensional code according to the one or more coding sub-modes to obtain the first information, including: the electronic device decodes the binary values corresponding to the storage positions occupied by the plurality of code elements in the first coding region according to the first coding sub-mode, and decodes the binary values corresponding to the storage positions occupied by the plurality of code elements in the second coding region according to the second coding sub-mode to obtain the first information. In this way, the electronic device can accurately decode the first information from the to-be-decoded two-dimensional code through step-by-step sub-decoding.
[0038] In a possible implementation, the mode indication information and the one or more sub-mode indication information are binary characters with a fixed number of bits.
[0039] In a possible implementation, the electronic device determines the coding mode of the to-be-decoded two-dimensional code from the mode indication information, and the electronic device stores one or more mapping relationship tables, and the mapping relationship tables include the mode indication information and the coding mode corresponding to the mode indication information, including: the electronic device queries the coding mode corresponding to the mode indication information and the coding bit number of the coding mode in the mapping relationship table.
[0040] In a possible implementation, the electronic device determines the coding mode of the to-be-decoded two-dimensional code from the mode indication information, and the electronic device stores one or more mapping relationship tables, and the mapping relationship tables include the mode indication information and the coding mode corresponding to the mode indication information, and specifically including: the electronic device queries the coding mode corresponding to the mode indication information and the coding sub-mode corresponding to each sub-mode indication information in the one or more coding sub-modes in the mapping relationship table.
[0041] In a possible implementation, the to-be-decoded two-dimensional code includes one mode indication information and a plurality of sub-mode indication information, the first information includes two or more characters in a digital character, an uppercase letter character, a lowercase letter character, a special character, and an escape character, and the target coding mode corresponding to the digital character, the uppercase letter character, the lowercase letter character, the special character, and the escape character with the lowest coding bit number is different.
[0042] In a possible implementation, one or more encoding sub-modes each corresponds to an encoding index table; the encoding index table includes a first encoding index table, a second encoding index table, a third encoding index table, a fourth encoding index table, a fifth encoding index table, a sixth encoding index table, a seventh encoding index table, and an eighth encoding index table; the first encoding index table includes the digital character; the second encoding index table includes the digital character and the uppercase letter character; the third encoding index table includes the digital character and the lowercase letter character; the fourth encoding index table includes the uppercase letter character and the special character; the fifth encoding index table includes the lowercase letter character and the special character; the sixth encoding index table includes the digital character, the uppercase letter character, and the special character; the seventh encoding index table includes the digital character, the lowercase letter character, and the special character; and the eighth encoding index table includes the digital character, the uppercase letter character, the lowercase letter character, and the special character.
[0043] In a possible implementation, the target version of the to-be-decoded two-dimensional code includes a first version, a second version, a third version, a fourth version, a fifth version, and a sixth version; and the target version of the to-be-decoded two-dimensional code is different, and the data capacity of the to-be-decoded two-dimensional code is different.
[0044] In a third aspect, the present application provides an electronic device, including: one or more processors, one or more memories; the one or more memories are coupled with the one or more processors; the one or more memories are configured to store computer program codes, the computer program codes include computer instructions; when the computer instructions run on the processor, the electronic device is caused to perform: obtaining a to-be-encoded text, the to-be-encoded text includes N characters, N is a positive integer; determining a target encoding mode of each character in the N characters from X selectable encoding modes; dividing the N characters into M character segments according to the target encoding mode of each character, and determining a target encoding mode of each character segment in the M character segments; M is less than or equal to N; encoding the M character segments according to the target encoding mode of each character segment to obtain a first binary string; and generating a two-dimensional code of a version corresponding to the length of the first binary string from the first binary string.
[0045] By using the two-dimensional code encoding method provided in the embodiments of the present application, the electronic device can encode the to-be-encoded text into a shorter binary string. When the length of the character in the to-be-encoded text is too long, the binary string obtained by using the encoding method in the prior art exceeds the data capacity of the two-dimensional code in the prior art, so that the two-dimensional code cannot be generated. However, by using the two-dimensional code encoding method in the embodiments of the present application, the to-be-encoded text with a character length can be encoded, and the two-dimensional code can be generated.
[0046] In a possible implementation, the processor is further configured to: determine one or more candidate encoding modes of a first character in the N characters from the X candidate encoding modes; and select a candidate encoding mode with the least number of encoding bits from the one or more candidate encoding modes as the target encoding mode of the first character.
[0047] In this way, the electronic device can encode each character into a binary string with less number of bits. Thus, the electronic device can obtain a shorter binary string by encoding the text to be encoded.
[0048] In a possible implementation, the processor is further configured to: divide the N characters into M character segments, each of which includes one or more characters with the same target encoding mode; and determine the target encoding mode of each of the M character segments based on the target encoding modes of the characters in the character segment.
[0049] In a possible implementation, the M character segments include a first character segment, the first character segment includes a first character and a second character, the target encoding modes of the first character and the second character are the same, and the target encoding mode of the first character segment is the same as the target encoding modes of the first character and the second character.
[0050] In this way, the electronic device can divide the N characters into character segments for encoding, thereby saving the number of binary bits occupied by the mode indicators, and obtaining a shorter binary string.
[0051] In a possible implementation, the processor is further configured to: divide the N characters into M character segments, each of which includes one or more characters with the same target encoding mode and greater than a preset number; and determine the target encoding mode of each of the M character segments based on the target encoding modes of the characters in the character segment.
[0052] In this way, the electronic device can divide the N characters into fewer character segments, and each character segment only needs one mode indicator. Compared with a character as a character segment, the electronic device obtains fewer mode indicators in the binary string. In this way, the number of mode indicators can be saved. Thus, the electronic device can obtain a shorter binary string.
[0053] In a possible implementation, the M character segments include a second character segment, and the number of characters in the second character segment is greater than or equal to the preset number.
[0054] In a possible implementation, the processor is further configured to perform: counting from the first character in the N characters; when the (u-1)th character is counted, determining that the number of characters is greater than or equal to the preset number, and the target encoding mode of the (u-1)th character is different from that of the u th character, dividing the first character to the (u-1)th character in the N characters into a character segment to obtain M character segments; and determining the target encoding mode of each character segment in the M character segments based on the target encoding mode of the character in each character segment.
[0055] In this way, the electronic device can divide the N characters into fewer character segments, and each character segment only needs one mode indicator. Compared with one character as one character segment, the electronic device obtains fewer mode indicators in the binary string. In addition, the number of encoding bits of the target encoding mode of the character segment can be made lower, so that the electronic device can obtain a shorter binary string.
[0056] In a possible implementation, the processor is further configured to perform: determining that the target encoding modes of the first character and the second character in the first character segment are the first target encoding mode; and taking the first target encoding mode as the target encoding mode of the first character segment.
[0057] In a possible implementation, the processor is further configured to perform: determining that the target encoding mode of the first character in the first character segment is the first target encoding mode, and the target encoding mode of the second character in the first character segment is the second target encoding mode, wherein the number of encoding bits of the first target encoding mode is higher than that of the second target encoding mode, the first target encoding mode includes the second character in the encoding index table corresponding to the first target encoding mode, and the first target encoding mode and the second target encoding mode are included in the X selectable encoding modes; and taking the first target encoding mode as the target encoding mode of the first character segment.
[0058] In a possible implementation, the processor is further configured to perform: determining that the target encoding mode of the first character in the first character segment is the first target encoding mode, and the target encoding mode of the second character in the first character segment is the second target encoding mode, wherein the first target encoding mode is different from the second target encoding mode, the first target encoding mode does not include the first character in the encoding index table corresponding to the first target encoding mode, the second target encoding mode does not include the second character in the encoding index table corresponding to the second target encoding mode, the number of encoding bits of a third target encoding mode is higher than those of the first target encoding mode and the second target encoding mode, and the first target encoding mode, the second target encoding mode, and the third target encoding mode are included in the X selectable encoding modes; and taking the third target encoding mode as the target encoding mode of the first character segment.
[0059] In a possible implementation, the first binary string comprises a second binary string, the second binary string is obtained by encoding the first character segment, and the second binary string comprises a mode indicator of the target encoding mode of the first character segment, an indicator of the character length in the first character segment, and a binary string obtained by encoding the characters in the first string according to the target encoding mode of the first string.
[0060] In a possible implementation, the N characters comprise one or more of a numeric character, an uppercase letter character, a lowercase letter character, a special character, and an escape character, and the target encoding mode corresponding to the numeric character, the uppercase letter character, the lowercase letter character, the special character, and the escape character has the lowest number of encoding bits.
[0061] In a possible implementation, each of the X optional encoding modes corresponds to an encoding index table; the encoding index tables comprise a first encoding index table, a second encoding index table, a third encoding index table, a fourth encoding index table, a fifth encoding index table, a sixth encoding index table, a seventh encoding index table, and an eighth encoding index table; the first encoding index table contains a numeric character; the second encoding index table contains a numeric character and an uppercase letter character; the third encoding index table contains a numeric character and a lowercase letter character; the fourth encoding index table contains an uppercase letter character and a special character; the fifth encoding index table contains a lowercase letter character and a special character; the sixth encoding index table contains a numeric character, an uppercase letter character, and a special character; the seventh encoding index table contains a numeric character, a lowercase letter character, and a special character; and the eighth encoding index table contains a numeric character, an uppercase letter character, a lowercase letter character, and a special character.
[0062] In a possible implementation, the two-dimensional code comprises a first version of a two-dimensional code, a second version of a two-dimensional code, a third version of a two-dimensional code, a fourth version of a two-dimensional code, a fifth version of a two-dimensional code, and a sixth version of a two-dimensional code, and the data capacities of the first version of a two-dimensional code, the second version of a two-dimensional code, the third version of a two-dimensional code, the fourth version of a two-dimensional code, the fifth version of a two-dimensional code, and the sixth version of a two-dimensional code are different.
[0063] In a possible implementation, the two-dimensional code is a circular two-dimensional code, the circular two-dimensional code comprises an encoding region composed of a plurality of concentric circles, and each of the plurality of concentric circles comprises a plurality of code elements on a ring of the concentric circle.
[0064] In a fourth aspect, the present application provides an electronic device, comprising: one or more processors, one or more memories; the one or more memories are coupled to the one or more processors; the one or more memories are configured to store computer program codes, the computer program codes comprising computer instructions; when the computer instructions run on the processors, the electronic device is caused to perform: obtaining a to-be-decoded two-dimensional code, the to-be-decoded two-dimensional code indicating first information; obtaining mode indication information from the to-be-decoded two-dimensional code; determining a coding mode of the to-be-decoded two-dimensional code from the mode indication information, the electronic device storing one or more mapping relationship tables, the mapping relationship tables containing the mode indication information and the coding mode corresponding to the mode indication information; decoding the to-be-decoded two-dimensional code according to the coding mode to obtain the first information.
[0065] In this way, by using the two-dimensional code decoding method provided by the present application, the electronic device can decode two-dimensional codes of different coding modes.
[0066] In a possible implementation, the electronic device is further caused to perform: obtaining the mode indication information from a symbol in the coding area where the mode indication information is stored. In this way, the electronic device can obtain the mode indication information.
[0067] In a possible implementation, the electronic device is further caused to perform: obtaining version information of the to-be-decoded two-dimensional code, determining a target version of the to-be-decoded two-dimensional code based on the version information; the target version indicates coordinate information of each storage location in the coding area of the to-be-decoded two-dimensional code; and determining binary values corresponding to storage locations occupied by each symbol in the plurality of symbols in the coding area of the to-be-decoded two-dimensional code according to the coordinate information of each storage location. In this way, the electronic device can accurately determine the binary values corresponding to each symbol in the coding area.
[0068] Optionally, the binary data can be 0 or 1.
[0069] In a possible implementation, the electronic device can determine the version information of the to-be-decoded two-dimensional code according to the distance between any two locators in the to-be-decoded two-dimensional code. Different version information corresponds to different distances between any two locators in the two-dimensional code.
[0070] In a possible implementation, the electronic device is further caused to perform: decoding the binary values corresponding to the storage locations occupied by each symbol in the plurality of symbols in the coding area of the to-be-decoded two-dimensional code according to the coding mode to obtain the first information. Different coding modes correspond to different numbers of coding bits, so that the electronic device can accurately decode the binary values corresponding to the number of bits to obtain the first information according to the coding mode.
[0071] In a possible implementation, the electronic device is further configured to: obtain a mode indication information and one or more sub-mode indication information from the to-be-encoded two-dimensional code; determine the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, and determine one or more encoding sub-modes of the to-be-decoded two-dimensional code from the one or more sub-mode indication information; and decode the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the encoding region of the to-be-decoded two-dimensional code according to the one or more encoding sub-modes, to obtain the first information.
[0072] The first information can be encoded into the to-be-decoded two-dimensional code by the plurality of encoding sub-modes in the encoding mode. In this way, the electronic device can accurately decode the first information from the to-be-decoded two-dimensional code through step-by-step and subdivided decoding.
[0073] In a possible implementation, the one or more encoding sub-modes include a first encoding sub-mode and a second encoding sub-mode, and the encoding region includes a first encoding region and a second encoding region. The electronic device is further configured to: decode the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the first encoding region according to the first encoding sub-mode, and decode the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the second encoding region according to the second encoding sub-mode, to obtain the first information. In this way, the electronic device can accurately decode the first information from the to-be-decoded two-dimensional code through step-by-step and subdivided decoding.
[0074] In a possible implementation, the mode indication information and the one or more sub-mode indication information are binary characters with a fixed number of bits.
[0075] In a possible implementation, the electronic device is further configured to: query, in the mapping relationship table, the encoding mode corresponding to the mode indication information, and the encoding bit number of the encoding mode.
[0076] In a possible implementation, the electronic device is further configured to: query, in the mapping relationship table, the encoding mode corresponding to the mode indication information, and the encoding sub-mode corresponding to each of the one or more sub-mode indication information.
[0077] In a possible implementation, the to-be-decoded two-dimensional code includes a mode indication information and a plurality of sub-mode indication information, the first information includes two or more of the following characters: a numeric character, an uppercase letter character, a lowercase letter character, a special character, and an escape character, and the target encoding mode corresponding to each of the numeric character, the uppercase letter character, the lowercase letter character, the special character, and the escape character in terms of the lowest encoding bit number is different.
[0078] In a possible implementation, one or more encoding sub-modes each corresponds to an encoding index table; the encoding index table includes a first encoding index table, a second encoding index table, a third encoding index table, a fourth encoding index table, a fifth encoding index table, a sixth encoding index table, a seventh encoding index table, and an eighth encoding index table; the first encoding index table contains the digital character; the second encoding index table contains the digital character and the uppercase letter character; the third encoding index table contains the digital character and the lowercase letter character; the fourth encoding index table contains the uppercase letter character and the special character; the fifth encoding index table contains the lowercase letter character and the special character; the sixth encoding index table contains the digital character, the uppercase letter character, and the special character; the seventh encoding index table contains the digital character, the lowercase letter character, and the special character; and the eighth encoding index table contains the digital character, the uppercase letter character, the lowercase letter character, and the special character.
[0079] In a possible implementation, the target version of the to-be-decoded two-dimensional code includes a first version, a second version, a third version, a fourth version, a fifth version, and a sixth version; and the target version of the to-be-decoded two-dimensional code is different, and the data capacity of the to-be-decoded two-dimensional code is different.
[0080] In a fifth aspect, the present application provides an electronic device, including: one or more processors, one or more memories; the one or more memories are coupled with the one or more processors; the one or more memories are configured to store computer program codes, the computer program codes include computer instructions; when the computer instructions run on the processor, the electronic device executes the two-dimensional code encoding method in any possible implementation of the first aspect and the two-dimensional code decoding method in any possible implementation of the second aspect.
[0081] In a sixth aspect, the present application provides a computer storage medium, including computer instructions, when the computer instructions run on an electronic device, the electronic device executes the two-dimensional code encoding method in any possible implementation of any aspect and the two-dimensional code decoding method in any possible implementation of the second aspect.
[0082] In a seventh aspect, the present application provides a computer program product, when the computer program product runs on a computer, the computer executes the two-dimensional code encoding method in any possible implementation of any aspect and the two-dimensional code decoding method in any possible implementation of the second aspect. BRIEF DESCRIPTION OF DRAWINGS
[0083] Figure 1 is a schematic diagram of a QR code provided by the present application;
[0084] Figure 2is a set of schematic diagrams of two-dimensional codes provided by an embodiment of the present application;
[0085] Figures 3A-3F is a set of schematic diagrams of two-dimensional codes provided by an embodiment of the present application;
[0086] Figure 4 is a schematic diagram of a two-dimensional code encoding method flow provided by an embodiment of the present application;
[0087] Figure 5 is a schematic diagram of dividing a string into a plurality of character segments provided by an embodiment of the present application;
[0088] Figure 6A is a schematic diagram of a character segment encoding result format provided by an embodiment of the present application;
[0089] Figure 6B is a schematic diagram of a string encoding result format provided by an embodiment of the present application;
[0090] Figure 6C is a schematic diagram of another character segment encoding result format provided by an embodiment of the present application;
[0091] Figure 6D is a schematic diagram of another string encoding result format provided by an embodiment of the present application;
[0092] Figure 7 is a schematic diagram of a step of generating a two-dimensional code from an encoding result in a two-dimensional code encoding method provided by an embodiment of the present application;
[0093] Figures 8A-8F is a schematic diagram of a structure of a set of two-dimensional codes provided by an embodiment of the present application;
[0094] Figure 9 is a schematic diagram of a flow of a two-dimensional code decoding method provided by an embodiment of the present application;
[0095] Figure 10 is a schematic diagram of a structure of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0096] The terms used in the following embodiments of the present application are only for the purpose of describing particular embodiments and are not intended to be limiting of the present application. As used in the specification and the appended claims of the present application, the singular forms "a," "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "and / or," as used in the present application, encompasses all possible combinations of one or more of the associated listed items.
[0097] The terms "first", "second", "third", etc. are used herein only to describe different instances, and are not used to denote or imply relative importance or an indicated number of technical features. Thus, features defined with "first", "second", etc. can explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, the meaning of "a plurality of" is two or more, unless otherwise specified. The terms "intermediate", "left", "right", "up", "down", etc. indicate the orientation or positional relationship shown in the drawings, and are only used for the convenience of describing the present application and simplifying the description, and thus cannot be understood as indicating or implying that the indicated device or element must have a particular orientation, be constructed and operated in a particular orientation, and thus cannot be understood as limiting the present application.
[0098] The embodiments of the present application relate to an application of a two-dimensional code encoding method, which can be applied in an electronic device 100. Through the method, first, the electronic device 100 can obtain a text to be encoded, which can contain one or more of numbers, capital letters, small letters, Chinese characters, Japanese characters, etc.; then the electronic device 100 can divide the text to be encoded into multiple fields, then the electronic device 100 encodes each field in the multiple fields by selecting the encoding mode with the lowest number of bits, to obtain a binary string, wherein the electronic device stores N encoding tables, each of which corresponds to an encoding mode; finally, the electronic device 100 can generate a two-dimensional code from the binary string.
[0099] First, some concepts involved in a two-dimensional code encoding method provided by the present application will be described below.
[0100] 1. Encoding mode
[0101] In the embodiments of the present application, there can be multiple encoding modes in the electronic device, each of which is used to convert the text to be encoded into binary characters. However, different encoding modes adopt different conversion methods. When an encoding mode is selected for encoding, the electronic device 100 converts the character in the text to be encoded into the index value corresponding to the character according to the encoding index table corresponding to the encoding mode, and then converts the index value into a binary character according to the encoding mode.
[0102] As shown in Table 1 below, Table 1 exemplarily lists some encoding modes and mode indicators corresponding to the encoding modes.
[0103] Table 1
[0104]
[0105] The encoding modes and the mode indicators corresponding to the encoding modes shown in Table 1 are the encoding modes and the mode indicators provided in the standard protocol of the two-dimensional code. It can be understood that more encoding modes can be provided as the standard protocol of the two-dimensional code develops. The encoding modes involved in the embodiments of the present application can not be limited to the encoding modes provided in Table 1.
[0106] In the embodiments of the present application, the mixed encoding mode Structured_Append can include multiple encoding sub-modes, and each encoding sub-mode corresponds to an encoding index table. The encoding sub-modes of the mixed encoding mode Structured_Append can be shown in Table 2. Eight sub-modes of the mixed encoding mode, i.e., the pure number encoding mode, the uppercase hexadecimal encoding mode, the lowercase hexadecimal encoding mode, the number and uppercase letter mixed encoding mode, the number and lowercase letter mixed encoding mode, the number and uppercase letter and common character mixed encoding mode, the number and lowercase letter and common character mixed encoding mode, and the number and uppercase and lowercase and special character and escape character mixed encoding mode, are shown in Table 2 by way of example.
[0107] Table 2
[0108]
[0109]
[0110] It can be understood that Table 2 is only by way of example, and the encoding sub-modes of the mixed encoding mode Structured_Append can not be limited to the eight encoding sub-modes shown in Table 2. The encoding sub-modes of the mixed encoding mode can further include a Spanish encoding mode, a Portuguese encoding mode, or a Korean encoding mode or a mixed encoding mode of different languages, etc., which are not limited herein.
[0111] In the embodiments of the present application, the numbers "0"-"9" can be referred to as number characters, the uppercase English letters "A"-"Z" can be referred to as uppercase letter characters, and the lowercase English letters "a"-"z" can be referred to as lowercase letter characters. Characters other than the numbers and the uppercase and lowercase English letters in a computer keyboard can be referred to as special characters, such as the question mark "?", the double quotation marks "", the left parenthesis "(", the right parenthesis ")", etc. The escape character refers to a backslash plus other characters, such as "\0", "\a", etc.
[0112] 2. Encoding index table
[0113] The encoding index table is used to specify the index value corresponding to a character. In an embodiment, the electronic device 100 can store an encoding index table corresponding to Base10 mode, an encoding index table corresponding to Base16_U mode, an encoding index table corresponding to Base16_L mode, an encoding index table corresponding to Base32_U mode, an encoding index table corresponding to Base32_L mode, an encoding index table corresponding to Base45_U mode, an encoding index table corresponding to Base45_L mode, and an encoding index table corresponding to Base128 mode.
[0114] For example, the encoding index table corresponding to Base10 mode can be as shown in Table 3.
[0115] Table 3
[0116] character (char) index value (value) character (char) index value (value) 0 0 5 5 1 1 6 6 2 2 7 7 3 3 8 8 4 4 9 9
[0117] As shown in Table 3, Table 3 shows an encoding index table of pure numeric characters. The encoding index table can include numeric characters "0"-"9" and index values corresponding to the numeric characters "0"-"9", respectively. For example, when a character in the text to be encoded is "0", the index value corresponding to the character in the encoding index table shown in Table 3 is "0". The index values shown in Table 3 can be decimal values, i.e., the index values "0"-"9" can be decimal values.
[0118] It can be understood that the encoding index table corresponding to Base10 mode can not be limited to the encoding index table shown in Table 3. The encoding index table corresponding to Base10 mode can change with changes in the two-dimensional code encoding protocol. The specific form and content of the encoding index table corresponding to Base10 mode are not limited herein.
[0119] For example, the encoding index table corresponding to Base16_U mode can be as shown in Table 4.
[0120] Table 4
[0121] character (char) index value (value) character (char) index value (value) 0 0 8 8 1 1 9 9 2 2 A 10 3 3 B 11 4 4 C 12 5 5 D 13 6 6 E 14 7 7 F 15
[0122] As shown in Table 4, Table 4 shows a hexadecimal encoding index table. The encoding index table can include hexadecimal characters (numeric characters "0"-"9" and uppercase letters "A"-"F") and index values corresponding to the hexadecimal characters, respectively. For example, the index value corresponding to the character "0" in Table 4 is "0", and the index value corresponding to the character "A" is "10". The index values shown in Table 4 can be decimal values. That is, the index values "0"-"15" in Table 4 can be decimal values.
[0123] It is understood that the encoding index table corresponding to the Base16_U mode is not limited to the encoding index table shown in Table 4. The encoding index table corresponding to the Base16_U mode can change with the change of the QR code encoding protocol. The specific form and content of the encoding index table corresponding to the Base16_U mode are not limited here.
[0124] For example, the encoding index table corresponding to the Base16_L mode can be shown in Table 5 below.
[0125] Table 5
[0126] character (char) index value (value) character (char) index value (value) 0 0 8 8 1 1 9 9 2 2 a 10 3 3 b 11 4 4 c 12 5 5 d 13 6 6 e 14 7 7 f 15
[0127] As shown in Table 5, this table displays a hexadecimal encoding index. This index can include the index values corresponding to each hexadecimal character (the numeric characters "0"-"9", and the lowercase letters "a"-"f"). For example, the index value corresponding to the character "0" in Table 5 is "0", and the index value corresponding to the character "a" is "10". The index values shown in Table 5 can also be decimal values. That is, index values "0" through "15" in Table 5 can be decimal values.
[0128] It is understood that the encoding index table corresponding to the Base16_L mode is not limited to the encoding index table shown in Table 5. The encoding index table corresponding to the Base16_L mode can change with the change of the QR code encoding protocol. The specific form and content of the encoding index table corresponding to the Base16_L mode are not limited here.
[0129] For example, the encoding index table corresponding to the Base32_U mode can be shown in Table 6 below.
[0130] Table 6
[0131]
[0132] As shown in Table 6, Table 6 presents the encoding index table for uppercase letters and special characters. This encoding index table can include uppercase letters "A"-"Z" and the special character "SP", as well as the index values corresponding to the uppercase letters "A"-"Z" and the index value corresponding to the special character "SP". For example, in Table 6, the index value corresponding to the uppercase character "A" could be "0", and the index value corresponding to the special character "SP" could be "26". The index values shown in Table 6 can be decimal values. That is, the index values "0"-"31" in Table 6 can be decimal values.
[0133] It can be understood that the encoding index table corresponding to the Base32_U mode can not be limited to the encoding index table shown in Table 6. The encoding index table corresponding to the Base32_U mode can change with the change of the two-dimensional code encoding protocol. The specific form and content of the encoding index table corresponding to the Base32_U mode are not limited here.
[0134] Exemplarily, the encoding index table corresponding to the Base32_L mode can be as shown in Table 7.
[0135] Table 7
[0136]
[0137] As shown in Table 7, Table 7 shows the encoding index table of lowercase letters and special characters. The encoding index table can include lowercase letters "a"-"z" and special characters "SP", and the index values corresponding to the lowercase letters "a"-"z" respectively, the index value corresponding to the special character "SP". For example, in Table 7, the index value corresponding to the lowercase letter "a" can be "0", and the index value corresponding to the special character "SP" can be "26". The index values shown in Table 7 can be decimal values. That is, the index values "0"-"31" in Table 7 can be decimal values.
[0138] It can be understood that the encoding index table corresponding to the Base32_L mode can not be limited to the encoding index table shown in Table 7. The encoding index table corresponding to the Base32_L mode can change with the change of the two-dimensional code encoding protocol. The specific form and content of the encoding index table corresponding to the Base32_L mode are not limited here.
[0139] Exemplarily, the encoding index table corresponding to the Base45_U mode can be as shown in Table 8.
[0140] Table 8
[0141]
[0142] As shown in Table 8, Table 8 shows the encoding index table of numbers, uppercase letters and common characters. The encoding index table can include number characters "0"-"9", and uppercase letters "A"-"Z" and special characters (such as "?", "$", "%", etc.), and the index values corresponding to the number characters "0"-"9" respectively, the index values corresponding to the uppercase letters "A"-"Z" respectively, the index values corresponding to the common characters. For example, in Table 8, the index value corresponding to the number character "0" can be "0", the index value corresponding to the uppercase letter "A" can be "10", and the index value corresponding to the special character "?" can be "36". The index values shown in Table 8 can be decimal values. That is, the index values "0"-"44" in Table 8 can be decimal values.
[0143] It can be understood that the encoding index table corresponding to the Base45_U mode can not be limited to the encoding index table shown in Table 8. The encoding index table corresponding to the Base45_U mode can change with the change of the two-dimensional code encoding protocol. The specific form and content of the encoding index table corresponding to the Base45_U mode are not limited here.
[0144] Exemplarily, the encoding index table corresponding to the Base45_L mode can be as shown in Table 9.
[0145] Table 9
[0146]
[0147]
[0148] As shown in Table 9, Table 9 shows the encoding index table of the number, lowercase letter and special character. The encoding index table can include the index values corresponding to the number characters “0”-“9”, the lowercase letters “a”-“z” and the commonly used characters (for example, “?”, “!”, “=” and the like), and the number characters “0”-“9”, respectively. The index values corresponding to the lowercase letters “a”-“z”, respectively, and the index values corresponding to the commonly used characters. For example, in Table 9, the index value corresponding to the number character “0” can be “0”, the index value corresponding to the lowercase letter “a” can be “10”, and the index value corresponding to the commonly used character “?” can be “43”. The index values shown in Table 9 can be decimal values. That is, the index values “0”-“44” in Table 9 can be decimal values.
[0149] It can be understood that the encoding index table corresponding to the Base45_L mode can not be limited to the encoding index table shown in Table 9. The encoding index table corresponding to the Base45_L mode can change with the change of the two-dimensional code encoding protocol. The specific form and content of the encoding index table corresponding to the Base45_L mode are not limited here.
[0150] Exemplarily, the encoding index table corresponding to the Base128 mode can be as shown in Table 10.
[0151] Table 10
[0152]
[0153]
[0154] As shown in Table 10, Table 10 shows an encoding index table of digits, lowercase letters, uppercase letters and common characters, and escape characters. The encoding index table can include digits "0"-"9", and lowercase letters "a"-"z", uppercase letters "A"-"Z" and common characters (for example, "?", "!", "=", and the like), escape characters, and index values corresponding to the digits "0"-"9", respectively, index values corresponding to the lowercase letters "a"-"z", respectively, index values corresponding to the uppercase letters "A"-"Z", respectively, and index values corresponding to the common characters and escape characters, respectively. For example, in Table 10, the index value corresponding to the digit "0" can be "16", the index value corresponding to the lowercase letter "a" can be "65", and the index value corresponding to the common character "?" can be "31". The index values shown in Table 10 can be decimal values. That is, the index values "0"-"127" in Table 10 can be decimal values.
[0155] It can be understood that the encoding index table corresponding to the Base128 mode can not be limited to the encoding index table shown in Table 10. The encoding index table corresponding to the Base128 mode can change with the change of the two-dimensional code encoding protocol. The specific form and content of the encoding index table corresponding to the Base128 mode are not limited here.
[0156] It can be understood that the encoding index table stored by the electronic device 100 in the embodiments of the present application can not be limited to the encoding index tables shown in Tables 3-10. The electronic device 100 can store more encoding index tables, which are not limited here.
[0157] The encoding binary bits and the mode indicators corresponding to the encoding sub-modes (for example, the Base10 mode, the Base16_U mode, the Base16_L mode, the Base32_U mode, the Base32_L mode, the Base45_U mode, the Base45_L mode, and the Base128 mode) of the mixed encoding mode Structured_Append involved in the embodiments of the present application can be as shown in Table 11.
[0158] Table 11
[0159]
[0160]
[0161] As shown in Table 11, Table 11 exemplarily shows the binary bits and the mode indicators corresponding to the Base10 mode, the Base16_U mode, the Base16_L mode, the Base32_U mode, the Base32_L mode, the Base45_U mode, the Base45_L mode, the Base128 mode, and the like, respectively. It can be understood that the encoding sub-modes shown in Table 11, and the binary bits and the mode indicators corresponding to the encoding sub-modes are only for illustration, and the number of the encoding sub-modes and the binary bits and the mode indicators corresponding to each encoding sub-mode are not limited in the embodiments of the present application.
[0162] It can be understood that the encoding index table in the embodiments of the present application can be more, and is not limited to the encoding index tables shown in Tables 3-10.
[0163] The electronic device 100 can select any one of the above encoding modes to encode the text to be encoded into a binary string, and then the electronic device 100 can generate a two-dimensional code corresponding to a version of the two-dimensional code according to the binary string. The two-dimensional code involved in the embodiments of the present application can include different types of two-dimensional codes, and the same type but different versions of two-dimensional codes. For example, Figure 1 the QR (Quick Response) code shown in (a), (b), and (c) of FIG. 1, Figure 2 the two-dimensional codes shown in (a), (b), and (c) of FIG. 2, Figures 3A-3F the circular two-dimensional codes shown in (a), (b), (c), (d), (e), and (f) of FIG. 3. It can be understood that the data capacity that can be stored by different types of two-dimensional codes, and the same type but different versions of two-dimensional codes is generally different. The greater the data capacity that can be stored by a two-dimensional code, the longer the length of the binary string that can be stored by the two-dimensional code.
[0164] Figure 2 The applets shown in (a), (b), and (c) of FIG. 4 are the same type of two-dimensional code, but different versions, and the data capacity that can be stored is also different.
[0165] Figures 3A-3F The circular two-dimensional codes shown in (a), (b), (c), (d), (e), and (f) of FIG. 3 are of the same type, but different versions. Figure 3A the circular two-dimensional code of version one, Figure 3B the circular two-dimensional code of version two, Figure 3C the circular two-dimensional code of version three, Figure 3D the circular two-dimensional code of version four, Figure 3E the circular two-dimensional code of version five, Figure 3F the circular two-dimensional code of version six. Figures 3A-3F The circular two-dimensional code shown in FIG. 3 can be referred to as a Hongmeng two-dimensional code in the embodiments of the present application. It can be understood that the number of the encoding sub-modes, and the binary bits and the mode indicators corresponding to each encoding sub-mode are not limited in the embodiments of the present application. Figures 3A-3FThe name of the illustrated two-dimensional code is not limited.
[0166] It can be understood that, Figure 1 , Figure 2 and Figures 3A-3F The two-dimensional codes shown in the above are only for illustration, and the types of two-dimensional codes and the versions of a certain type of two-dimensional code involved in the embodiments of the present application can be more, not limited to Figure 1 , Figure 2 The two-dimensional codes shown in Figures 3A-3F The two-dimensional codes shown in Figures 3A-3F are taken as examples for illustration.
[0167] Exemplarily, Figures 3A-3F The data capacity of the different versions of two-dimensional codes shown in the above can be as shown in Table 12.
[0168] Table 12
[0169]
[0170]
[0171] As shown in Table 12, Figure 3A The data capacity of the version one two-dimensional code shown in the above is 249 bits, and 19 valid bytes can be stored. Figure 3B The data capacity of the version two two-dimensional code shown in the above is 408 bits, and 34 valid bytes can be stored. Figure 3C The data capacity of the version three two-dimensional code shown in the above is 624 bits, and 55 valid bytes can be stored. Figure 3D The data capacity of the version four two-dimensional code shown in the above is 872 bits, and 80 valid bytes can be stored. Figure 3E The data capacity of the version five two-dimensional code shown in the above is 1152 bits, and 108 valid bytes can be stored. Figure 3F The data capacity of the version six two-dimensional code shown in the above is 1464 bits, and 136 valid bytes can be stored.
[0172] Based on the above explanation of the basic concepts involved in the embodiments of the present application, a two-dimensional code encoding method provided by the embodiments of the present application is introduced below. As shown in Figure 4 , Figure 4 a two-dimensional code encoding method flow provided by the embodiments of the present application is shown, which can include the following steps:
[0173] S101, the electronic device 100 acquires the to-be-encoded text, and the to-be-encoded text can contain N characters.
[0174] The electronic device 100 can obtain a to-be-encoded text, and the N characters of the to-be-encoded text can be one or more of a numeric character, an English uppercase letter, an English lowercase letter, a Chinese character, Japanese, Korean, a general character, a special character, an escape character, and the like. Specifically, the to-be-encoded text can be a string of numbers, a piece of text (Chinese, English, Japanese, Korean, and the like), a link, and the like, such as "12345678", "ABCD", "abcdef", "a kind of two-dimensional code encoding method", "https: / / zh.wikipedia.org / wiki / %E4%BD%8D%E5%85%83", and the like.
[0175] The to-be-encoded text obtained by the electronic device 100 can be input by a user in the electronic device 100, can be generated by the electronic device 100 based on information input by the user, or can be obtained by the electronic device 100 from another electronic device, and the like, which is not limited herein.
[0176] In S102, the electronic device 100 determines one or more candidate encoding modes for each character in the N characters from X available encoding modes, and selects a candidate encoding mode with the lowest number of encoding bits from the one or more candidate encoding modes as a target encoding mode for each character, where X is a positive number.
[0177] The electronic device 100 stores X encoding modes, and each encoding mode has a corresponding number of encoding bits. For example, the eight encoding modes shown in Table 11, Base10 mode, Base16_U mode, Base16_L mode, Base32_U mode, Base32_L mode, Base45_U mode, Base45_L mode, and Base128 mode, and the corresponding number of encoding bits (i.e., the number of bits in the table, also referred to as the number of binary bits) of each encoding mode.
[0178] In the embodiments of the present application, X is a positive number, and X can be equal to 8 or 10, which is not limited herein. Hereinafter, X is equal to 8 is taken as an example for illustration. That is, hereinafter, the electronic device 100 is configured with eight encoding modes as shown in Table 11 is taken as an example for illustration.
[0179] The encoding mode configured in the electronic device 100 can be referred to as an optional encoding mode. The electronic device 100 can determine one or more candidate encoding modes corresponding to each character in the text to be encoded from X encoding modes. When an encoding mode A corresponds to an encoding index table including a character A, the encoding mode A can be referred to as a candidate encoding mode of the character A. For example, for the character "0", the Base10 mode, the Base16_U mode, the Base16_L mode, the Base32_U mode, the Base32_L mode, the Base45_U mode, the Base45_L mode, the Base128 mode, and the like correspond to the encoding index tables including the character "0", and thus the Base10 mode, the Base16_U mode, the Base16_L mode, the Base32_U mode, the Base32_L mode, the Base45_U mode, the Base45_L mode, and the Base128 mode can be referred to as the candidate encoding modes of the character "0".
[0180] As can be seen from Table 11, the Base10 mode has an encoding bit number of 3. The Base16_U mode has an encoding bit number of 4. The Base16_L mode has an encoding bit number of 4. The Base32_U mode has an encoding bit number of 5. The Base32_L mode has an encoding bit number of 5. The Base45_U mode has an encoding bit number of 6. The Base45_L mode has an encoding bit number of 6. The Base128 mode has an encoding bit number of 7. The Base10 mode has the lowest encoding bit number, and thus the electronic device 100 can select the Base10 mode as the target encoding mode of the character "0" from the candidate modes of the character "0".
[0181] The target encoding mode of each character in the N characters of the text to be encoded can be the same or different. For example, when the N characters are "0124FEAabcd" (in this case, N is equal to 11). Referring to the description of the determination of the target encoding mode of the character "0" by the electronic device 100, the electronic device 100 can determine the target encoding mode of the character "0" as the Base10 mode, the target encoding mode of the character "1" as the Base10 mode, the target encoding mode of the character "2" as the Base10 mode, the target encoding mode of the character "4" as the Base10 mode, the target encoding mode of the character "F" as the Base16_U mode, the target encoding mode of the character "E" as the Base16_U mode, the target encoding mode of the character "A" as the Base16_U mode, the target encoding mode of the character "a" as the Base16_L mode, the target encoding mode of the character "b" as the Base16_L mode, the target encoding mode of the character "c" as the Base16_L mode, and the target encoding mode of the character "d" as the Base16_L mode.
[0182] It can be understood that N is an integer greater than 1, and the embodiments of the present application do not limit the specific value of N. For example, N can be equal to 1, and N can also be equal to 11.
[0183] In S103, the electronic device 100 divides the N characters into M character segments according to the target encoding mode of each character in the N characters, and determines the target encoding mode of the M character segments, each of which contains one or more characters.
[0184] The electronic device 100 can divide the N characters into M character segments according to the target encoding mode of each character in the N characters. Each of the M character segments contains one or more characters. M can be less than or equal to N. The electronic device 100 can also determine the target encoding mode of the character segment according to the target encoding mode of each character in the character segment.
[0185] The electronic device 100 can configure M to be equal to N in the system. The electronic device 100 can also configure M to be less than N.
[0186] The electronic device 100 can divide the N character segments into M character segments in various ways. Hereinafter, the electronic device 100 will be taken as an example to specifically illustrate how the electronic device divides the N characters into M character segments according to the target encoding mode of each character in the N characters, and determines the target encoding mode of the M character segments, by taking the N characters "0124FEAabcd" in the above as an example.
[0187] Alternatively, in a possible implementation, the electronic device 100 can divide the character string "0124FEAabcd" composed of 11 characters into 11 character segments, that is, each character segment contains one character. The target encoding mode of each character segment is the target encoding mode of the character contained in the character segment. The target encoding mode of each character in the character string "0124FEAabcd" and the encoding mode of the character segment can be as shown in Table 13.
[0188] Table 13
[0189]
[0190]
[0191] As shown in Table 13, the electronic device 100 can divide the string "0124FEAabcd" into 11 character segments, i.e., character segment "0", character segment "1", character segment "2", character segment "4", character segment "F", character segment "E", character segment "A", character segment "a", character segment "b", character segment "c", and character segment "d". The target encoding mode of the character segment "0" is the Base10 mode. The target encoding mode of the character segment "1" is the Base10 mode. The target encoding mode of the character segment "2" is the Base10 mode. The target encoding mode of the character segment "4" is the Base10 mode. The target encoding mode of the character segment "F" is the Base16_U mode. The target encoding mode of the character segment "E" is the Base16_U mode. The target encoding mode of the character segment "A" is the Base16_U mode. The target encoding mode of the character segment "a" is the Base16_L mode. The target encoding mode of the character segment "b" is the Base16_L mode. The target encoding mode of the character segment "c" is the Base16_L mode. The target encoding mode of the character segment "d" is the Base16_L mode.
[0192] Alternatively, in a possible implementation, the electronic device 100 can divide the characters that are continuous adjacent and have the same target encoding mode in the N characters into one character segment, and finally obtain M character segments. For example, in the string "0124FEAabcd", the characters "0", "1", "2", and "4" are continuous adjacent (i.e., the character "0" is adjacent to the character "1", the character "1" is adjacent to the character "2", and the character "2" is adjacent to the character "4"), and have the same target encoding mode. The electronic device 100 can divide the characters "0", "1", "2", and "4" into one character segment "0124". The target encoding mode of the character segment "0124" is the target encoding mode of the characters "0", "1", "2", and "4", i.e., the Base10 mode. The target encoding mode of each character in the string "0124FEAabcd" and the encoding mode of the character segment can be as shown in Table 14.
[0193] Table 14
[0194]
[0195] As shown in Table 13, the electronic device 100 can divide the string "0124FEAabcd" into 3 character segments, i.e., a character segment "0124", a character segment "FEA", and a character segment "abcd". The character segment "0124" contains 4 characters, and the target encoding mode of each of the 4 characters is the Base10 mode. Therefore, the target encoding mode of the character segment "0124" can also be the Base10 mode. The character segment "FEA" contains 3 characters, and the target encoding mode of each of the 3 characters is the Base16_U mode. Therefore, the target encoding mode of the character segment "FEA" can also be the Base16_U mode. The character segment "abcd" contains 4 characters, and the target encoding mode of each of the 4 characters is the Base16_L mode. Therefore, the target encoding mode of the character segment "abcd" can also be the Base16_L mode.
[0196] Optionally, in a possible implementation, the electronic device 100 can divide the N characters into M character segments, and the number of characters in each of the M character segments is greater than or equal to a preset number.
[0197] Further, the electronic device 100 can divide the character segments in the order of the arrangement of the N characters. The electronic device 100 can divide the characters that are continuously adjacent to each other and have the same target encoding mode into a character segment when the number of the characters is greater than or equal to a preset number. The electronic device 100 can divide the characters that are continuously adjacent to each other but have different target encoding modes into a character segment when the number of the characters is equal to or greater than the preset number. For example, when the preset number is 4, the electronic device 100 can divide the string "0124FEAabcd" into character segments as shown in Table 15.
[0198] Table 15
[0199]
[0200] As shown in Table 15, the characters "0", "1", "2", "4" in the string "0124FEAabcd" are continuous and adjacent, and the target encoding mode is the same, so the electronic device 100 can divide the characters "0", "1", "2", "4" into a character segment "0124". The characters "F", "E", "A" in the string "0124FEAabcd" are continuous and adjacent, and the encoding mode is different, but the three characters "F", "E", "A" do not satisfy the preset number, so the electronic device 100 can divide the characters "a", "b", "c", "d" after the character "A" into a character segment "FEAabcd" together with the characters "F", "E", "A". The target encoding mode of the characters "F", "E", "A" is Base16_U mode, and the target encoding mode of the characters "a", "b", "c", "d" is Base16_L mode. The target encoding mode of the character segment "FEAabcd" can be Base128 mode, which requires both encoding of English uppercase letters and encoding of English lowercase letters.
[0201] Alternatively, the electronic device 100 can divide the string "0124FEAabcd" into character segments "0124", "FEAa", and "bcd", and the target encoding mode of the character segment "0124" is Base10 mode. The target encoding mode of the character segment "FEAa" is Base128 mode. Alternatively, in a possible implementation, the electronic device counts from the 1st character of N characters, and when the number of characters is greater than or equal to the preset number, the target encoding mode of the u-th character is different from the target encoding mode of the (u-1)th character, the electronic device 100 divides the 1st character to the (u-1)th character into a character segment. Then, the electronic device 100 counts from the u-th character again, and when the number of characters is greater than or equal to the preset number, the target encoding mode of the v-th character is different from the target encoding mode of the (v-1)th character, the electronic device 100 divides the u-th character and the (v-1)th character into a character segment. In turn, the electronic device 100 divides the N characters into M character segments.
[0202] Further, in a possible implementation, the electronic device can use two pointers to count and identify different target encoding modes in the string, respectively. For example, Figure 5 The string "10ABCD1234aaaa" shown in Table 15, and the pointer i and the pointer j. The pointer i is used for counting, and the pointer j is a position pointer used to identify a new target encoding mode. Taking the preset number equal to 4 as an example, as shown in Table 15, the electronic device 100 counts from the 1st character of the string "10ABCD1234aaaa" and divides the 1st character to the 4th character into a character segment "10ABCD". The target encoding mode of the character segment "10ABCD" is Base10 mode. Then, the electronic device 100 counts from the 5th character of the string "10ABCD1234aaaa" and divides the 5th character to the 8th character into a character segment "1234". The target encoding mode of the character segment "1234" is Base16_U mode. Then, the electronic device 100 counts from the 9th character of the string "10ABCD1234aaaa" and divides the 9th character to the 12th character into a character segment "aaaa". The target encoding mode of the character segment "aaaa" is Base16_L mode. Figure 5As shown, first, the pointer j is at the position j1, i.e., the first character "1", and the pointer i starts counting from the first character "1" of the string "10ABCD1234aaaa". When the pointer j is at the position j2, i.e., the seventh character "1", the seventh character "1" is different from the target encoding mode of the sixth character "D", the electronic device 100 divides the first six characters into one character segment, i.e., the character segment "10ABCD". The pointer i starts counting again from the seventh character "1", and at j = j3, the electronic device 100 identifies that the target encoding mode of the thirteenth character "a" is different from the target encoding mode of the twelfth character "4", the electronic device 100 divides the seventh character to the eleventh character, i.e., four characters, into one character segment, i.e., the character segment "1234", and the electronic device 100 divides the remaining four characters, i.e., the four adjacent characters "a", into one character segment "aaaa".
[0203] It can be understood that when the electronic device 100 divides the N characters into M-1 character segments according to the above steps, if the number of remaining characters is less than the preset number, the electronic device 100 can also divide the characters less than the preset number into the Mth character segment. That is, the number of characters in the last obtained character segment of the M character segments can be less than the preset number.
[0204] It can be understood that the preset number can be configured by the system of the electronic device 100, and the experience value of the preset number is 4. However, the embodiment of the present application does not limit the specific value of the preset number, and the preset number can be 4, 5 or other values.
[0205] S104, the electronic device 100 encodes the M character segments according to the target encoding of the M character segments to obtain a binary string S.
[0206] When the electronic device 100 divides the N characters into M character segments and determines the target encoding mode of the M character segments, the electronic device 100 can encode each character segment according to the target encoding mode of each character segment, and finally obtain a binary string S.
[0207] In a possible implementation, the format of the binary string obtained by encoding the character segment according to the target encoding mode of the character segment can be as follows Figure 6AAs shown. The binary string 600 obtained by encoding the character segment can include a mode indicator 60a, a data length 60b, and data 60c. The mode indicator 60a is used to identify the encoding mode of the binary string 600. The data length 60b is used to indicate the length of the data 60c in the binary string 600. The data 60c is the binary character data obtained by encoding the characters in the original character segment according to the target mode. The character segment "0124" shown in Table 14 above is used as an example for illustration. The character segment "0124" is encoded according to the target encoding mode, namely Base10 mode, to obtain the binary string S1 as shown in Table 16 below.
[0208] Table 16
[0209]
[0210] As shown in Table 16, the target encoding mode for the character segment "0124" is Base10. The result of encoding "0124" in Base10 mode is "000001010100". After adding the mode indicator and length, the final encoding result of the character segment "0124" is the binary string S1 "001100000001010100". Here, the character "0" corresponds to the decimal value "0" in the Base10 mode encoding index table. Since the Base10 mode encoding has 3 bits, the decimal value "0" can be converted to the three-bit binary character "000". Therefore, the character "0" can be encoded as the binary character "000" according to Base10 mode. Similarly, the character "1" can be encoded as the binary character "001" according to Base10 mode. The character "2" can be encoded as the binary character "010" according to Base10 mode. The character "4" can be encoded as the binary character "100" according to Base10 mode.
[0211] Furthermore, the format of the binary string S resulting from the encoding of N characters in the text to be encoded can be as follows: Figure 6B As shown. Figure 6B As shown, binary string 60 can be composed of the encoding results of multiple character segments (e.g., binary string 60 (including pattern indicator, length, and data), binary string 601 (including pattern indicator, length, and data), binary string 602 (including pattern indicator, length, and data), etc.). The following example illustrates this with the segmentation results of N characters "0124FEAabcd" and N characters "0124FEAabcd" shown in Table 14. The encoding result of N characters "0124FEAabcd", i.e., binary string S, can be shown in Table 17 below.
[0212] Table 17
[0213]
[0214] As shown in Table 17, the N characters "0124FEAabcd" can be divided into the character segment "0124", the character segment "FEA", and the character segment "abcd". The character segment "0124" can be encoded according to the target mode, i.e., the Base10 mode, to obtain the binary string S1 "001100000001010100". The character segment "FEA" can be encoded according to the target mode, i.e., the Base16_U mode, to obtain the binary string S2 "010011111111101010". The character segment "abcd" can be encoded according to the target encoding mode, i.e., the Base16_L mode, to obtain the binary string S3 "001100101010111101". The encoding result of the N characters "0124FEAabcd", i.e., the binary string S, can be composed of the binary string S1, the binary string S2, and the binary string S3. Therefore, the binary string S can be "001100000001010100010011111111101010001100101010111101". The encoding result of each character in the character segment "0124", the character segment "FEA", and the character segment "abcd" can refer to the description of the encoding result of the character "0" in the character segment "0124" in Table 16, and will not be described here.
[0215] It can be understood that, since the Base10 mode, the Base16_U mode, and the Base16_L mode are sub-modes of the Structured_Append mixed encoding mode, the binary string S obtained after final encoding can be prefixed with the mode indicator "0011" of the Structured_Append mixed encoding mode. Optionally, the total length (11 characters in total) of the string can also be indicated after the mode indicator "0011" of the Structured_Append mixed encoding mode. Therefore, the final binary string S can be "00111011001100000001010100010011111111101010001100101010111101".
[0216] Optionally, when the number of characters in the M character segments is fixed, the format of the encoding result of the character segment can also be the encoding format as shown in Table 18. Compared with the encoding format as shown in Table 17, Figure 6C Figure 6A Figure 6C The data length can not be included in the binary string. For example, the character segment shown in Table 13 includes only one character in each character segment, and the format of the encoding result of the character segment, i.e., the format of the binary string obtained after encoding, can be Figure 6C as shown in Table 13. The format of the encoding result of the string shown in Table 13 can be as shown in Figure 6D . Figure 6D The string 70 in the character segment can be composed of a string obtained by encoding a plurality of character segments (for example, string 700 (including a mode indicator and data), string 701 (including a mode indicator and data), string 702 (including a mode indicator and data), and the like). Reference can be made to the description of Figure 6A and Figure 6B above, which will not be repeated here.
[0217] It can be understood that the format of the binary string in the embodiments of the present application is not limited to the formats shown in Figure 6B and Figure 6D . The format of the binary string can have more forms, for example, the format of the binary string can be that the data is after the mode indicator, i.e., the format of "mode indicator 1 mode indicator 2 mode indicator 3 data 1 data 2 data 3", and the like, where mode indicator 1 is an encoding mode indication of data 1, mode indicator 2 is an encoding mode indication of data 2, and mode indicator 3 is an encoding mode indication of data 3, which is not limited here.
[0218] It can be understood that the division result of N characters can be different, and the binary string S obtained after final encoding can be different. For example, the N characters "0124FEAabcd" are divided according to the character segments shown in Table 13 to obtain the encoding result, which can be different from the encoding result of the character segments shown in Table 14.
[0219] It can be understood that the encoding bit number of the character length in the above Tables 16 and 17 is 3, which is only for illustration. When the character length of the character segment and the string is longer, the encoding bit number of the character length is higher. When the encoding bit number is 3, the character segment or the string of up to 7 characters can be represented. When the encoding is 4, the character segment or the string of up to 15 characters can be represented. The encoding bit number of the character length in the embodiments of the present application can be set to a fixed value. That is, the character length of each character segment can be encoded according to the set encoding bit number. The encoding bit number of the character length in the embodiments of the present application is not limited, for example, it can be 3 as shown in Tables 16 and 17, it can be 4, it can be 8, it can be higher, and the like.
[0220] S105, the electronic device 100 generates a target two-dimensional code of a corresponding version according to the length of the binary string S.
[0221] Since the data capacity of different versions of the two-dimensional code is different, the electronic device 100 needs to generate a corresponding version of the two-dimensional code according to the length of the binary string S. The target two-dimensional code corresponding to the length of the binary string S refers to the data capacity of the target two-dimensional code of the version being greater than or equal to the length of the binary string S.
[0222] Optionally, the electronic device can encrypt and compress the binary string S to obtain a binary string S', and the electronic device can generate a corresponding version of the two-dimensional code according to the length of the binary string S'. In this way, the security of the string can be improved, and the storage space of the string can be improved.
[0223] In a possible implementation, as shown in Figure 7 , the electronic device 100 generates a corresponding version of the two-dimensional code according to the length of the binary string S, which can specifically include the following steps:
[0224] S1051, the electronic device 100 can determine the target version of the target two-dimensional code according to the length of the binary string.
[0225] Different versions provide different amounts of stored data. The longer the binary string is, the more data needs to be stored. The electronic device 100 determines the target version of the two-dimensional code to be generated according to the length of the binary string.
[0226] The following describes six versions of the two-dimensional code shown in Figures 3A-3F , and briefly introduces the six versions of the two-dimensional code in Figures 3A-3F . It should be noted that when the following describes the dot-shaped code elements in the six versions of the two-dimensional code, the dot-shaped code elements here are one storage location, and cannot be equated with the code elements in the generated two-dimensional code.
[0227] Version one, the coding area of the two-dimensional code includes four concentric circular areas.
[0228] As shown in Figure 8A , the image area 401 of the two-dimensional code in Figure 8A indicates the brand type (Harmony OS) of the two-dimensional code. It can be seen that in Figure 8A , the image area 401 is circular.
[0229] The center point of the image area 401 is taken as the center of a circle, and the encoding area 402 includes four concentric circular areas, and each of the four concentric circular areas is uniformly arranged with dot code elements. The distance between two adjacent dot code elements in each of the four concentric circular areas (or the arc length formed by the centers of two adjacent dot code elements) is the same. Each dot code element can store information, and the information stored in each dot code element can indicate that, in terms of color, if a dot code element stores first information (for example, 1 in binary), the dot code element is colored in a first color (for example, black), and if a dot code element stores second information (for example, 0 in binary), the dot code element is colored in a second color (for example, white, for example, transparent) or is not colored.
[0230] There is a first interval between the image area 401 and the encoding area 402, and there is a second interval between each of two adjacent concentric circular areas in the encoding area 402. Each of the concentric circular areas is composed of an inner circular ring and an outer circular ring, the width of each of the concentric circular areas is the difference between the radii of the inner circular ring and the outer circular ring, and the second interval is the interval between the outer circular ring of the small concentric circular area and the inner circular ring of the large concentric circular area in the two adjacent concentric circular areas. There is a third interval between two adjacent dot code elements in each of the concentric circular areas. For example, in Figure 8A , if the diameter of a dot code element is 1, the radius of the image area 401 is 10, the interval between the image area 401 and the encoding area 402 is 1, that is, the first interval is 1 or the diameter of a dot code element, the width of each of the concentric circular areas in the encoding area 402 is 1, that is, the diameter of a dot code element, the interval between each of two adjacent concentric circular areas in the encoding area 402 is 1, that is, the second interval is 1 or the diameter of a dot code element, and the interval between two adjacent dot code elements in each of the concentric circular areas can be 0 or a circular arc with the same central angle, that is, the third interval can be 0 or a circular arc with the same central angle.
[0231] In some embodiments, the four concentric circular areas are divided into upper half areas and lower half areas, and there is a fourth interval between the upper half areas and the lower half areas. For example, in Figure 8A , if the diameter of a dot code element is 1, the interval between the upper half areas and the lower half areas is 5.
[0232] The locator area is in the two-dimensional code, for example, in Figure 8A , the locator area includes three main locators 403 and an auxiliary locator 404, the outer contours of the three main locators 403 and the auxiliary locator 404 are all circular, the centers of the three main locators 403 are all in the penultimate concentric circular area in the periphery, and the diameter of a dot code element is 1, so the diameter of the three main locators 403 is 5.
[0233] Version two, the coding area of the two-dimensional code includes five concentric circular areas.
[0234] As shown in Figure 8B , the image area 411 of the two-dimensional code in Figure 8B indicates the brand type (Harmony OS) of the two-dimensional code. With the center point of the image area 411 as the center, the coding area 412 includes five concentric circular areas, and each concentric circular area is uniformly arranged with dot-shaped code elements. The distance between the centers of two adjacent dot-shaped code elements in each concentric circular area (or the arc length formed by the centers of every two adjacent dot-shaped code elements) is the same.
[0235] There is a first interval between the image area 411 and the coding area 412, a second interval between every two adjacent concentric circular areas in the coding area 412, and a third interval between two adjacent dot-shaped code elements in each concentric circular area. For example, in Figure 8B , if the diameter of a dot-shaped code element is 1, the radius of the image area 411 is 10, the interval between the image area 411 and the coding area 412 is 2, that is, the first interval is 2 or the diameter of two dot-shaped code elements; the interval between every two adjacent concentric circular areas in the coding area 412 is 1, that is, the second interval is 1 or the diameter of one dot-shaped code element; and the interval between two adjacent dot-shaped code elements in each concentric circular area can be 0 or a circular arc with the same central angle, that is, the third interval can be 0 or a circular arc with the same central angle.
[0236] In some embodiments, the four concentric circular areas are divided into upper and lower half areas, and there is a fourth interval between the upper and lower half areas. For example, in Figure 8B , if the diameter of a dot-shaped code element is 1, the interval between the upper and lower half areas is 5.
[0237] The locator area is in the two-dimensional code, for example, in Figure 8B , it includes three main locators 413 and one auxiliary locator 414, and the outer contours of the three main locators 413 and the auxiliary locator 414 are all circular. The centers of the main locators 413 are all in the penultimate concentric circular area in the periphery, and the diameter of a dot-shaped code element is 1, so the diameter of the three main locators 413 is 5.
[0238] Version three, the coding area of the two-dimensional code includes eight concentric circular areas.
[0239] As shown in Figure 8C , the image area 411 of the two-dimensional code in Figure 8CThe image area 421 of the two-dimensional code in FIG. 4A indicates the brand type (harmony OS) of the two-dimensional code. The encoding area 422 includes 8 concentric circular areas with the center point of the image area 421 as the center, and each of the concentric circular areas is uniformly arranged with dot code elements. The distance between the centers of two adjacent dot code elements in each of the concentric circular areas (or the arc length formed by the centers of two adjacent dot code elements) is the same.
[0240] There is a first interval between the image area 421 and the encoding area 422, a second interval between each of the two adjacent concentric circular areas in the encoding area 422, and a third interval between each of the two adjacent dot code elements in each of the concentric circular areas. For example, in Figure 8C , if the diameter of a dot code element is 1, the radius of the image area 421 is 10, the interval between the image area 421 and the encoding area 422 is 2, that is, the first interval is 2 or the diameter of two dot code elements; the interval between each of the two adjacent concentric circular areas in the encoding area 422 is less than 1, that is, the second interval can be between 0 and 1; and the interval between each of the two adjacent dot code elements in each of the concentric circular areas can be 0 or a circular arc with the same central angle, that is, the third interval can be 0 or a circular arc with the same central angle.
[0241] In some embodiments, the 8 concentric circular areas are divided into upper half areas and lower half areas, and there is a fourth interval between the upper half areas and the lower half areas. For example, in Figure 8C , if the diameter of a dot code element is 1, the interval between the upper half areas and the lower half areas is 5.
[0242] The locator area is in the two-dimensional code, for example, in Figure 8C , the two-dimensional code includes three main locators 423 and an auxiliary locator 424, and the outer contours of the three main locators 423 and the auxiliary locator 424 are circular. The centers of the main locators 423 are in the penultimate concentric circular area in the periphery, and the diameter of a dot code element is 1. Therefore, the diameter of the three main locators 423 is 5.
[0243] Version four, the encoding area of the two-dimensional code includes 10 concentric circular areas.
[0244] As shown in Figure 8D , Figure 8D The image area 431 of the two-dimensional code in FIG. 4B indicates the brand type (harmony OS) of the two-dimensional code. The encoding area 432 includes 10 concentric circular areas with the center point of the image area 431 as the center, and each of the concentric circular areas is uniformly arranged with dot code elements. The distance between the centers of two adjacent dot code elements in each of the concentric circular areas (or the arc length formed by the centers of two adjacent dot code elements) is the same.
[0245] There is a first interval between the image area 431 and the encoding area 432, a second interval between each two adjacent concentric circular areas in the encoding area 432, and a third interval between two adjacent dot-shaped code elements in each concentric circular area. For example, in Figure 8D , if the diameter of one dot-shaped code element is 1, the radius of the image area 431 is 10, the interval between the image area 431 and the encoding area 432 is 2, that is, the first interval is 2 or the diameter of two dot-shaped code elements; the interval between each two adjacent concentric circular areas in the encoding area 432 is less than 1, that is, the second interval can be between 0 and 1; the interval between two adjacent dot-shaped code elements in each concentric circular area can be 0 or a circular arc with the same central angle, that is, the third interval can be 0 or a circular arc with the same central angle.
[0246] In some embodiments, the four concentric circular areas are divided into upper half areas and lower half areas, and there is a fourth interval between the upper half areas and the lower half areas. For example, in Figure 8D , if the diameter of one dot-shaped code element is 1, the interval between the upper half areas and the lower half areas is 5.
[0247] The locator area is in the two-dimensional code, for example, in Figure 8D , three main locators 433 and one auxiliary locator 434 are included, the outer contours of the three main locators 433 and the auxiliary locator 434 are all circular, the centers of the main locators 433 are all in the penultimate concentric circular area in the periphery, and the diameter of one dot-shaped code element is 1, then the diameter of the three main locators 433 is 5.
[0248] Version five, the encoding area of the two-dimensional code includes 11 concentric circular areas.
[0249] As shown in Figure 8E , the image area 441 of the two-dimensional code in Figure 8E indicates the brand type (Harmony System, harmony OS) of the two-dimensional code. With the center point of the image area 441 as the center, the encoding area 442 includes 11 concentric circular areas, and dot-shaped code elements are uniformly arranged in each concentric circular area, and the distance between the centers of two adjacent dot-shaped code elements in each concentric circular area (or the length of the circular arc formed by the centers of every two adjacent dot-shaped code elements) is the same.
[0250] There is a first interval between the image area 441 and the encoding area 442, a second interval between each two adjacent concentric circular areas in the encoding area 442, and a third interval between two adjacent dot-shaped code elements in each concentric circular area. For example, in Figure 8EIn the image region 441, if the diameter of a dot-shaped symbol is 1, then the radius of the image region 441 is 10, and the interval between the image region 441 and the encoding region 442 is 1. That is, the first interval is 1 or the diameter of a dot-shaped symbol. The interval between any two adjacent concentric circular regions in the encoding region 442 is less than 1, that is, the second interval can be between 0 and 1. The interval between any two adjacent dot-shaped symbols in each concentric circular region can be 0, or it can be an arc with the same central angle. That is, the third interval can be 0, or it can be an arc with the same central angle.
[0251] In some embodiments, the 11 concentric circular regions are each divided into an upper region and a lower region, with a fourth interval between the upper and lower regions, for example, in... Figure 8E In this context, if the diameter of a dot-shaped symbol is 1, the interval between the upper and lower halves of the region is 5.
[0252] The locator area is within the QR code, for example in... Figure 8E It includes three main locators 443 and one auxiliary locator 444. The outer contours of the three main locators 443 and the auxiliary locator 444 are all circular. The center of the main locator 443 is in the second to last concentric circle region. The diameter of a dot-shaped code element is 1, so the diameter of the three main locators 443 is 5.
[0253] Version 6 includes 13 concentric circle areas in the QR code's encoding region.
[0254] like Figure 8F As shown, Figure 8F The image area 451 of the QR code indicates the brand type of the QR code (HarmonyOS). With the center point of the image area 451 as the center, the encoding area 452 includes 13 concentric circle areas. Each concentric circle area has evenly arranged dot-shaped code elements. The distance between the centers of two adjacent dot-shaped code elements in each concentric circle area (or the length of the arc formed by the centers of every two adjacent dot-shaped code elements) is the same.
[0255] There is a first interval between image region 451 and coding region 452, a second interval between every two adjacent concentric circle regions in coding region 452, and a third interval between two adjacent dot-shaped symbols in each concentric circle region. For example, in... Figure 8FIn the image region 451, if the diameter of a dot-shaped symbol is 1, then the radius of the image region 451 is 13, and the interval between the image region 451 and the encoding region 452 is 3. That is, the first interval is 3 or the diameter of three dot-shaped symbols. The interval between any two adjacent concentric circular regions in the encoding region 452 is less than 1, that is, the second interval can be between 0 and 1. The interval between any two adjacent dot-shaped symbols in each concentric circular region can be 0, or it can be an arc with the same central angle. That is, the third interval can be 0, or it can be an arc with the same central angle.
[0256] In some embodiments, the four concentric circular regions are each divided into an upper region and a lower region, with a fourth interval between the upper and lower regions, for example, in... Figure 8F In this context, if the diameter of a dot-shaped symbol is 1, the interval between the upper and lower halves of the region is 7.
[0257] The locator area is within the QR code, for example in... Figure 8F It includes three main locators 453 and one auxiliary locator 454. The outer contours of the three main locators 453 and the auxiliary locator 454 are all circular. The center of the main locator 453 is in the second to last concentric circle region. The diameter of a dot-shaped code element is 1, so the diameter of the three main locators 453 is 5.
[0258] Understandably, the more concentric circle regions and the more dot-shaped code elements there are, the larger the amount of data stored in that version. Not limited to the six versions mentioned above, the number of concentric circle regions and the number of dot-shaped code elements in each concentric circle region can have other configurations, and this application does not impose any restrictions on this.
[0259] S1052, Electronic device 100 can allocate the binary string S to each concentric circle area in the encoding area according to the image area, encoding area and locator position in the target version of the target QR code, and obtain the QR code information.
[0260] The electronic device 100 performs ring-splitting processing on the binary string according to the position of the image region, encoding region, and locator in the structure of the target version of the QR code to be generated. The binary string is then distributed into the dot-shaped code elements of each concentric circle region in the encoding region to obtain the QR code information.
[0261] Specifically, based on the number of concentric circle regions in the encoding area of the QR code structure, and the information capacity of each concentric circle region (positively correlated with the number of dot-shaped code elements), the binary string can be split into substrings corresponding to each concentric circle region, and each substring can be assigned to the dot-shaped code elements in the corresponding concentric circle region for storage.
[0262] The two-dimensional code information includes information stored in each dot-shaped code element. For example, a dot-shaped code element in a first position stores first information, and a dot-shaped code element in a second position stores second information. The first position and the second position indicate the center coordinates and the radius information of the dot-shaped code element. For example, the first information can be 1 in a binary string, and the second information can be 0 in the binary string.
[0263] In some embodiments, the two-dimensional code information can further include a display form corresponding to each dot-shaped code element. For example, a dot-shaped code element storing first information is displayed in a first color, and a dot-shaped code element storing second information is displayed in a second color. For example, the first color can be black, and the second color can be white, transparent, or no color.
[0264] In some embodiments, the electronic device 100 further splits a substring corresponding to a concentric circular region into two substrings stored in the upper half region and the lower half region of the concentric circular region, respectively. The electronic device 100 can further split a substring corresponding to a concentric circular region into four substrings stored in the four quadrants of the concentric circular region, respectively.
[0265] The electronic device 100 fills the binary string into the dot-shaped code elements in the concentric circular regions of the target version of the two-dimensional code. The filling direction can be from the innermost concentric circular region to the outer concentric circular region, or from the outermost concentric circular region to the inner concentric circular region, or from left to right, from top to bottom, and the like. The embodiments of the present application do not limit the filling direction.
[0266] If a reserved region (for example, a region reserving format information or version information) or a functional module region (for example, a locator region, a calibration module region, or a time module region) is encountered, the code element at this position is not filled, and the filling continues until the next idle code element.
[0267] In S1053, the electronic device 100 selects a mask mode of the target two-dimensional code and adds mask information.
[0268] Masking refers to a strategy of changing the value of a code element in the encoding region of a two-dimensional code according to a specific rule. The purpose of using masking is to adjust the display effect of the code elements in the two-dimensional code (for example, to avoid large areas of blank or black blocks in the two-dimensional code, which affects code recognition), so as to facilitate the code reader to read information as easily as possible.
[0269] Masking patterns include, for example, masking all even-numbered concentric circle regions in a QR code; or, for example, masking some dot-shaped code elements within each concentric circle region of a QR code. Electronic device 100 uses masking patterns to overlay QR code information to adjust the layout of the QR code information, making the distribution of code elements in the QR code information more uniform, thereby making the generated QR code more aesthetically pleasing.
[0270] Specifically, masking QR code information can be achieved by performing an XOR operation between the binary string of the QR code information and the mask.
[0271] In some embodiments, the electronic device 100 fills the encoding area with QR code information that includes mask information. The electronic device 100 verifies whether the target version meets the capacity requirements of the QR code to be generated. If it does, version information is added.
[0272] S1054. The electronic device generates the target QR code.
[0273] In this embodiment, the electronic device 100 can encode the QR code encoding area by leaving unusable areas empty. After completing the encoding of the QR code encoding area and obtaining the QR code information, the electronic device 100, based on the QR code information, uses a drawing algorithm to draw the dot-shaped code elements storing the first information in the encoding area as the first color and the dot-shaped code elements storing the second information as the second color, thus completing the drawing of the encoding area. Furthermore, the electronic device 100 fills in the corresponding image area, locator area, and other areas in the target version to obtain a complete QR code image. The unusable areas include the image area, locator area, and blank areas in the encoding area of the target version of the QR code (such as...). Figure 8A (A blank area with a 5-space interval between the upper and lower halves), etc.
[0274] In some embodiments, the electronic device 100 connects and draws dot-shaped code elements that meet preset conditions into arc-shaped code elements. The preset conditions include: if two or more consecutive adjacent dot-shaped code elements in a concentric circular region both store first information, the two or more adjacent dot-shaped code elements are connected and drawn into an arc-shaped code element, which is drawn in a first color. Optionally, the portion of the arc-shaped code element connecting the dot-shaped code elements is also filled with the first color, which can enhance the aesthetics of the QR code. Similarly, if two or more consecutive adjacent dot-shaped code elements in a concentric circular region both store second information, the two or more adjacent dot-shaped code elements are connected and drawn into an arc-shaped code element, which is drawn in a second color.
[0275] The following is an exemplary description of the QR code images generated from the six versions of QR codes mentioned above.
[0276] The target version is version one, the generated exemplary two-dimensional code is as shown in the following figure. Figure 3A Figure 3A The target version is version one, the generated exemplary two-dimensional code is as shown in the following figure.
[0277] The target version is version two, the generated exemplary two-dimensional code is as shown in the following figure. Figure 3B Figure 3B The target version is version two, the generated exemplary two-dimensional code is as shown in the following figure.
[0278] The target version is version three, the generated exemplary two-dimensional code is as shown in the following figure. Figure 3C Figure 3C The target version is version three, the generated exemplary two-dimensional code is as shown in the following figure.
[0279] The target version is version four, the generated exemplary two-dimensional code is as shown in the following figure. Figure 3D Figure 3D The target version is version four, the generated exemplary two-dimensional code is as shown in the following figure.
[0280] The target version is version five, the generated exemplary two-dimensional code is as shown in the following figure. Figure 3E Figure 3E The target version is version five, the generated exemplary two-dimensional code is as shown in the following figure.
[0281] The target version is version six, the generated exemplary two-dimensional code is as shown in the following figure. Figure 3F Figure 3F The target version is version six, the generated exemplary two-dimensional code is as shown in the following figure.
[0282] It can be understood that the two-dimensional code encoding method provided by the embodiment of the present application can be any combination of the above steps S101-S105. Alternatively, the two-dimensional code encoding method provided by the embodiment of the present application can be a two-dimensional code encoding method obtained by combining the steps associated with the above steps S101-S105, or can be a two-dimensional code encoding method obtained by combining the replacement schemes of any one of the above steps S101-S105. For example, the above step S102 can be replaced by the electronic device determining the character type of the N characters and determining the target encoding mode corresponding to each character type.
[0283] The embodiment of the present application provides a two-dimensional code encoding method. Through the method, the electronic device 100 can obtain a to-be-encoded text, and the to-be-encoded text can include N characters. The electronic device 100 determines one or more candidate encoding modes of each character in the N characters from X selectable encoding modes, selects a candidate encoding mode with the lowest number of encoding bits from the one or more candidate encoding modes as the target encoding mode of each character, and X is a positive number. The electronic device 100 divides the N characters into M character segments according to the target encoding mode of each character in the N characters, and determines the target encoding mode of the M character segments, each character segment in the M character segments including one or more characters. The electronic device 100 encodes the M character segments according to the target encoding mode of the M character segments, to obtain a binary string S. The electronic device 100 generates a target two-dimensional code corresponding to a version according to the length of the binary string S. In this way, the electronic device 100 can encode the to-be-encoded text into a binary string with a shorter length, thereby improving the data capacity of the two-dimensional code. Thus, the to-be-encoded text with a longer length can be encoded and a two-dimensional code can be generated.
[0284] For example, the string "0124FEAabcd" can be encoded into a 54-bit binary string "001100000001010100010011111111101010001100101010111101" according to the two-dimensional code encoding method provided in the embodiments of the present application. According to the encoding mode in the prior art, the electronic device 100 directly encodes the string "0124FEAabcd" as a whole, adopts the base128 encoding mode to encode, and obtains an 84-bit binary string. In the base128 encoding mode, the number of encoding bits is 7, and each of the 11 characters in "0124FEAabcd" is encoded into a 7-bit binary character, thereby obtaining a 77-bit binary string, and then 3 bits of mode indicator and 4 bits of length indication are added, and finally an 84-bit binary string is obtained. As can be seen, the binary string obtained by using the two-dimensional code encoding method provided in the embodiments of the present application is shorter. In this way, the electronic device can generate a two-dimensional code for a longer string.
[0285] Based on the two-dimensional code encoding method provided in the above embodiments, the embodiments of the present application further provide a two-dimensional code decoding method. The contents related to the foregoing embodiments are applicable to the present embodiment, and will not be repeated here. As shown in Figure 9 The two-dimensional code decoding method can specifically include the following steps:
[0286] S901, the electronic device 100 acquires a two-dimensional code to be decoded.
[0287] The electronic device 100 can acquire the two-dimensional code to be decoded through a camera, and the electronic device can also acquire the two-dimensional code to be decoded from the gallery of the electronic device. The electronic device 100 can also acquire the two-dimensional code to be decoded through another electronic device 100. That is, the other electronic device sends the two-dimensional code to be decoded to the electronic device 100. The embodiments of the present application do not limit the way in which the electronic device 100 acquires the two-dimensional code to be decoded.
[0288] The two-dimensional code to be decoded can be a QR code as shown in Figure 1 It can also be a two-dimensional code as shown in (a), (b) or (c) of Figure 2 or any version of the two-dimensional code shown in Figures 3A-3F The type of the two-dimensional code is not limited here.
[0289] The two-dimensional code to be decoded can be a two-dimensional code generated according to the steps S101-S105 described above.
[0290] In a possible implementation, before the electronic device 100 acquires the to-be-decoded two-dimensional code, the electronic device 100 acquires a first image containing the to-be-decoded two-dimensional code; and the electronic device 100 determines a region of the to-be-decoded two-dimensional code in the first image by using a locator (for example, the primary locator 403 and the auxiliary locator 404 shown in FIG. 8) in the to-be-decoded two-dimensional code. Figure 8A
[0291] Further, before the electronic device 100 determines the region of the to-be-decoded two-dimensional code in the first image, the electronic device 100 can perform preprocessing on the first image. The preprocessing can include one or more of grayscale processing, denoising processing, binarization processing, dilation processing, and corrosion processing. The specific processes of the grayscale processing, the denoising processing, the binarization processing, the dilation processing, and the corrosion processing can refer to the prior art, and will not be described here.
[0292] S902, the electronic device 100 acquires mode indication information from the to-be-decoded two-dimensional code.
[0293] The electronic device 100 can acquire the mode indication information from a coding region (for example, the coding region 402 shown in FIG. 8) of the to-be-decoded two-dimensional code. The mode indication information can be a binary string. The electronic device 100 can acquire the binary string used to identify the coding mode of the to-be-decoded two-dimensional code. Figure 8A
[0294] Optionally, the electronic device 100 can acquire version information of the to-be-decoded two-dimensional code, and determine the coding region in the to-be-decoded two-dimensional code based on the version information. Then, the electronic device 100 can acquire the mode indication information from the coding region.
[0295] S903, the electronic device 100 determines a coding mode from the mode indication information, and the electronic device 100 stores a mapping relationship table of the mode indication information and the coding mode.
[0296] The electronic device 100 can determine the coding mode of the to-be-decoded two-dimensional code according to the mode indication information, for example, the binary string used to indicate the coding mode. The electronic device 100 can store a mapping relationship table of the mode indication information and the coding mode. The mapping relationship table can be Table 1 in the foregoing, and can also be Table 11 in the foregoing. If the electronic device 100 acquires the mode indication information “0000”, the electronic device 100 can determine that the coding mode of the to-be-decoded two-dimensional code is the Terminator Mode. If the electronic device 100 acquires the mode indication information “0011”, the electronic device 100 can determine that the coding mode of the to-be-decoded two-dimensional code is the hybrid coding mode. The electronic device 100 can also determine the coding sub-mode of the to-be-decoded two-dimensional code from the mode indication information.
[0297] Further, if the electronic device 100 determines that the mode indication information of the encoding sub-mode is included in the part of the characters in the encoding region of the to-be-decoded two-dimensional code, the electronic device 100 can determine the corresponding encoding sub-mode according to the mode indication information of the encoding sub-mode. For example, if the mode indication information is a binary string "000", the electronic device 100 can determine that the encoding sub-mode is a Base10 mode.
[0298] In a possible implementation, the electronic device 100 obtains multiple mode indication information, for example, multiple mode indicators, in the encoding region, and decodes the binary string according to the mode indication information corresponding to the binary string.
[0299] S904, the electronic device 100 decodes the to-be-decoded two-dimensional code according to the determined encoding mode, to obtain the encoding information in the two-dimensional code.
[0300] The electronic device 100 decodes the to-be-decoded two-dimensional code according to the determined encoding mode. If the electronic device 100 obtains the compression indication information from the to-be-decoded two-dimensional code, the electronic device 100 can decompress the to-be-decoded two-dimensional code according to the compression indication information. If the electronic device 100 obtains the encryption indication information, the electronic device 100 can also decrypt the to-be-decoded two-dimensional code according to the encryption indication information. Finally, the electronic device 100 can obtain the encoding information in the to-be-decoded two-dimensional code, for example, "abcd", for example, "I love my family" and the like. In the embodiment of the present application, the encoding information in the two-dimensional code can be referred to as first information.
[0301] In a possible implementation, the electronic device 100 can determine, from the encoding region, how many binary bytes are included in the encoding region, the length of each binary byte, and the encoding mode. The electronic device 100 can encode each byte according to the encoding length corresponding to the byte. For example, the electronic device 100 can determine that the mode indication information is "0011" from the to-be-decoded two-dimensional code. Then the encoding mode of the to-be-decoded two-dimensional code is a hybrid encoding mode. If the byte length in the encoding information is 3, it indicates that the to-be-decoded two-dimensional code is encoded by 3 binary strings. The electronic device can obtain the encoding sub-mode indicators (for example, "001", indicating that the encoding mode is a Base10 mode) and the length indication (for example, "100" indicating that the number of original characters encoded into the binary string is 4) of the 3 binary strings from the encoding region, and finally obtain the specific results of the 3 binary strings, for example, "000001010100". The binary string "000001010100" can be decoded according to the encoding sub-mode to obtain the two-dimensional code encoding information, that is, the numerical character "0124".
[0302] In a possible implementation, the to-be-decoded two-dimensional code contains an encoding area, and the electronic device determines the mode indication information from the to-be-decoded two-dimensional code, specifically including: the electronic device acquires the mode indication information from a symbol in the encoding area in which the mode indication information is stored. In this way, the electronic device can acquire the mode indication information.
[0303] In a possible implementation, before the electronic device acquires the mode indication information from the symbol in the encoding area in which the mode indication information is stored, the method further includes: the electronic device acquires version information of the to-be-decoded two-dimensional code, and determines a target version of the to-be-decoded two-dimensional code based on the version information; the target version indicates coordinate information of each storage location in the encoding area of the to-be-decoded two-dimensional code; and the electronic device determines binary values corresponding to storage locations occupied by each symbol in the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the coordinate information of each storage location. In this way, the electronic device can accurately determine the binary values corresponding to each symbol in the encoding area.
[0304] Optionally, the binary data can be 0 or 1.
[0305] In a possible implementation, the electronic device can determine the version information of the to-be-decoded two-dimensional code according to distances between any two locators in the to-be-decoded two-dimensional code. Different version information corresponds to different distances between any two locators in the two-dimensional code.
[0306] In a possible implementation, the electronic device decodes the to-be-decoded two-dimensional code according to the encoding mode to obtain the first information, including: the electronic device decodes the binary values corresponding to the storage locations occupied by each symbol in the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the encoding mode to obtain the first information. Different encoding modes correspond to different encoding bit numbers, so that the electronic device can accurately decode the binary values corresponding to the bit numbers to obtain the first information according to the encoding mode.
[0307] In a possible implementation, the electronic device acquires the mode indication information from the to-be-decoded two-dimensional code, including: the electronic device acquires one mode indication information from the to-be-decoded two-dimensional code, and one or more sub-mode indication information contained in the mode indication information.
[0308] The electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, including: the electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, and determines one or more encoding sub-modes of the to-be-decoded two-dimensional code from the one or more sub-mode indication information.
[0309] The electronic device decodes the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the encoding region of the to-be-decoded two-dimensional code according to the encoding mode to obtain the first information, including: the electronic device decodes the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the encoding region of the to-be-decoded two-dimensional code according to one or more encoding sub-modes to obtain the first information.
[0310] The first information can be encoded into the to-be-decoded two-dimensional code by a plurality of encoding sub-modes in one encoding mode. In this way, the electronic device can gradually subdivide decoding, and accurately decode the first information from the to-be-decoded two-dimensional code.
[0311] In a possible implementation, the one or more encoding sub-modes include a first encoding sub-mode and a second encoding sub-mode, and the encoding region includes a first encoding region and a second encoding region; the electronic device decodes the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the encoding region of the to-be-decoded two-dimensional code according to the one or more encoding sub-modes to obtain the first information, including: the electronic device decodes the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the first encoding region according to the first encoding sub-mode, and decodes the binary values corresponding to the storage positions occupied by each of the plurality of code elements in the second encoding region according to the second encoding sub-mode to obtain the first information. In this way, the electronic device can gradually subdivide decoding, and accurately decode the first information from the to-be-decoded two-dimensional code.
[0312] In a possible implementation, the mode indication information and the one or more sub-mode indication information are binary characters with a fixed number of bits.
[0313] In a possible implementation, the electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, and the electronic device stores one or more mapping relationship tables, and the mapping relationship tables include the mode indication information and the encoding mode corresponding to the mode indication information, including: the electronic device queries the encoding mode corresponding to the mode indication information and the encoding bit number of the encoding mode in the mapping relationship table.
[0314] In a possible implementation, the electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, and the electronic device stores one or more mapping relationship tables, and the mapping relationship tables include the mode indication information and the encoding mode corresponding to the mode indication information, and specifically including: the electronic device queries the encoding mode corresponding to the mode indication information and the encoding sub-mode corresponding to each of the one or more encoding sub-mode indication information in the mapping relationship table.
[0315] In a possible implementation, the two-dimensional code to be decoded contains one mode indication information and multiple sub-mode indication information, the first information contains two or more characters in the following characters: numeric character, uppercase letter character, lowercase letter character, special character, escape character, and the target encoding mode corresponding to the minimum number of encoding bits of the numeric character, uppercase letter character, lowercase letter character, special character, and escape character is different.
[0316] In a possible implementation, each of the one or more encoding sub-modes corresponds to an encoding index table; the encoding index table includes a first encoding index table, a second encoding index table, a third encoding index table, a fourth encoding index table, a fifth encoding index table, a sixth encoding index table, a seventh encoding index table, and an eighth encoding index table; the first encoding index table contains the numeric character; the second encoding index table contains the numeric character and the uppercase letter character; the third encoding index table contains the numeric character and the lowercase letter character; the fourth encoding index table contains the uppercase letter character and the special character; the fifth encoding index table contains the lowercase letter character and the special character; the sixth encoding index table contains the numeric character, the uppercase letter character, and the special character; the seventh encoding index table contains the numeric character, the lowercase letter character, and the special character; and the eighth encoding index table contains the numeric character, the uppercase letter character, the lowercase letter character, and the special character.
[0317] In a possible implementation, the target version of the two-dimensional code to be decoded includes a first version, a second version, a third version, a fourth version, a fifth version, and a sixth version; and the target version of the two-dimensional code to be decoded is different, and the data capacity of the two-dimensional code to be decoded is different.
[0318] It can be understood that the two-dimensional code decoding method provided by the embodiment of the present application can be obtained by any combination of the above steps S901-S904. Alternatively, the two-dimensional code decoding method provided by the embodiment of the present application can be obtained by combining the steps associated with the above steps S901-S904, or can be obtained by combining the replacement scheme of any one of the above steps S901-S904. The above steps S901-S904 are only for illustration, and do not limit the two-dimensional code decoding method provided by the embodiment of the present application.
[0319] The electronic device 100 obtains a to-be-decoded two-dimensional code, obtains mode indication information from the to-be-decoded two-dimensional code, determines an encoding mode in the mode indication information, and stores a mapping relationship table of the mode indication information and the encoding mode in the electronic device. The electronic device 100 decodes the to-be-decoded two-dimensional code according to the encoding mode, and obtains encoding information in the two-dimensional code. In this way, the electronic device 100 can more accurately decode information in the two-dimensional code. The two-dimensional code decoding method provided in the embodiment of the present application is applied to decoding of a special binary encoding structure with subdivision encoding. The electronic device can use a block decoding manner to restore the subdivision encoding information step by step, so as to obtain an encoding string.
[0320] An example electronic device 100 provided in the embodiment of the present application is introduced below.
[0321] Figure 10 FIG. 1 is a structural schematic diagram of the electronic device 100 provided in the embodiment of the present application.
[0322] The embodiment is specifically described below by taking the electronic device 100 as an example. It should be understood that the electronic device 100 can have more or fewer components than those shown in the figure, can combine two or more components, or can have a different component configuration. The various components shown in the figure can be implemented in hardware, software, or a combination of hardware and software including one or more signal processing and / or application specific integrated circuits.
[0323] The electronic device 100 can include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charge management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a loudspeaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identify module (SIM) card interface 195, etc. The sensor module 180 can include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0324] It can be understood that the structural schematic of the embodiments of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 can include more or fewer components than those shown, or combine certain components, or split certain components, or different arrangement of components. The components shown can be implemented in hardware, software, or a combination of software and hardware.
[0325] The processor 110 can include one or more processing units, for example: the processor 110 can include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices, or can be integrated in one or more processors. The NPU is a neural-network (NN) computing processor, which can quickly process input information by drawing on the structure of biological neural networks, such as drawing on the transmission mode between human brain neurons, and can also constantly self-learn. Through the NPU, the electronic device 100 can realize intelligent cognitive applications such as image recognition, face recognition, speech recognition, text understanding, etc.
[0326] Among them, the controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals to complete the control of instruction fetching and instruction execution.
[0327] In the embodiments of the present application, the processor 110 can be configured to determine a target encoding mode of each character in N characters of the text to be encoded, and divide the N characters into M character segments according to the target encoding mode of each character.
[0328] The memory can also be provided in the processor 110, used to store instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory can save instructions or data that the processor 110 has just used or repeatedly uses. If the processor 110 needs to use the instructions or data again, it can be directly called from the memory. This avoids repeated access and reduces the waiting time of the processor 110, thereby improving the efficiency of the system.
[0329] The charging management module 140 is configured to receive charging input from a charger. The charger can be a wireless charger or a wired charger.
[0330] The power management module 141 is configured to connect the battery 142 and the charging management module 140 to the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160.
[0331] The wireless communication function of the electronic device 100 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor.
[0332] The antenna 1 and the antenna 2 are configured to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be configured to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example, the antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in combination with a tuning switch.
[0333] The mobile communication module 150 can provide a solution for wireless communication including 2G / 3G / 4G / 5G, etc. applied to the electronic device 100. The mobile communication module 150 can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and perform filtering, amplification, etc. on the received electromagnetic waves, and transmit the processed electromagnetic waves to the modem processor for demodulation. The mobile communication module 150 can also amplify signals modulated by the modem processor, and convert the amplified signals into electromagnetic waves to be radiated through the antenna 1. In some embodiments, at least part of the functional modules of the mobile communication module 150 can be disposed in the processor 110. In some embodiments, at least part of the functional modules of the mobile communication module 150 and at least part of the modules of the processor 110 can be disposed in the same device.
[0334] The modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through audio devices (not limited to speaker 170A, receiver 170B, etc.) or displays images or videos through the display screen 194. In some embodiments, the modem processor may be a separate device. In other embodiments, the modem processor may be independent of the processor 110 and may be housed in the same device as the mobile communication module 150 or other functional modules.
[0335] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0336] In some embodiments, the antenna 1 and the mobile communication module 150 of the electronic device 100 are coupled, and the antenna 2 and the wireless communication module 160 are coupled, so that the electronic device 100 can communicate with a network and other devices through wireless communication technology. The wireless communication technology can include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS can include a global positioning system (GPS), a global navigation satellite system (GLONASS), a beidu navigation satellite system (BDS), a quasi-zenith satellite system (QZSS), and / or a satellite based augmentation systems (SBAS).
[0337] The electronic device 100 implements a display function through a GPU, a display screen 194, and an application processor, etc. The GPU is a microprocessor for image processing, which is connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 can include one or more GPUs, which execute program instructions to generate or change display information.
[0338] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device 100 can include 1 or N display screens 194, N being a positive integer greater than 1.
[0339] The electronic device 100 can implement a photographing function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor, etc.
[0340] ISP is used to process the data feedback from the camera 193. For example, when taking a photo, the shutter is opened, the light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and conversion into a visible image. ISP can also optimize the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature, and other parameters of the shooting scene. In some embodiments, ISP can be provided in the camera 193.
[0341] The camera 193 is used to capture still images or videos. Objects generate optical images through lenses and project them onto photosensitive elements. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then transmitted to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into a standard RGB, YUV, or other format image signal. In some embodiments, the electronic device 100 can include one or N cameras 193, where N is a positive integer greater than 1.
[0342] The digital signal processor is used to process digital signals, in addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy, etc.
[0343] The video codec is used to compress or decompress digital video. The electronic device 100 can support one or more video codecs. In this way, the electronic device 100 can play or record videos in multiple encoding formats, such as moving picture experts group (MPEG) 1, MPEG 2, MPEG 3, MPEG 4, etc.
[0344] The internal memory 121 can include one or more random access memories (RAMs) and one or more non-volatile memories (NVMs). The random access memory can be directly read and written by the processor 110, and can be used to store executable programs (such as machine instructions) of operating systems or other programs running, and can also be used to store user and application data, etc. The non-volatile memory can also store executable programs and store user and application data, etc., which can be loaded into the random access memory in advance for direct reading and writing by the processor 110.
[0345] The electronic device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor, etc. For example, music play, recording, etc.
[0346] The audio module 170 is used to convert digital audio information into analog audio signals for output, and also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be disposed in the processor 110, or part of the functions of the audio module 170 can be disposed in the processor 110.
[0347] The speaker 170A, also called "loudspeaker", is used to convert audio electrical signals into sound signals.
[0348] The receiver 170B, also called "earpiece", is used to convert audio electrical signals into sound signals.
[0349] The microphone 170C, also called "microphone", "sound transducer", is used to convert sound signals into electrical signals.
[0350] The earphone interface 170D is used to connect wired earphones.
[0351] The pressure sensor 180A is used to sense pressure signals, and can convert the pressure signals into electrical signals.
[0352] The gyroscope sensor 180B can be used to determine the motion posture of the electronic device 100.
[0353] The barometric sensor 180C is used to measure air pressure.
[0354] The magnetic sensor 180D includes a Hall sensor.
[0355] The acceleration sensor 180E can detect the magnitude of acceleration of the electronic device 100 in each direction (generally three axes). It can also be used to identify the posture of the electronic device, and applied to landscape / portrait screen switching, pedometer, etc.
[0356] The distance sensor 180F is used to measure distance.
[0357] The proximity light sensor 180G can include, for example, a light emitting diode (LED) and a light detector, such as a photodiode.
[0358] The ambient light sensor 180L is used to sense ambient light brightness.
[0359] The fingerprint sensor 180H is used to collect fingerprints. The electric
[0360] The temperature sensor 180J is used to detect temperature.
[0361] Touch sensor 180K, also called "touch panel".
[0362] Keys 190 include: power on / off key, volume key, etc. Keys 190 can be mechanical keys. They can also be touch keys.
[0363] Motor 191 can generate vibration prompt. Motor 191 can be used for incoming call vibration prompt, and also can be used for touch vibration feedback.
[0364] Indicator 192 can be an indicator light, which can be used to indicate charging status, power change, and also can be used to indicate messages, missed calls, notifications, etc.
[0365] SIM card interface 195 is used to connect SIM card.
[0366] The software system of electronic device 100 can adopt layered architecture, event-driven architecture, micro-kernel architecture, micro-service architecture, or cloud architecture. The software architecture of electronic device 100 is not limited in the embodiments of the present application. For example, the software architecture of electronic device 100 can be an Android system with layered architecture.
[0367] The above-described and above-embodied examples are only used to illustrate the technical solutions of the present application, and not to limit the same; even though the foregoing embodiments of the present application have been described in detail, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for some technical features thereof; 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 application.
[0368] In the above-described embodiments, according to the context, the term "when" can be interpreted as meaning "if" or "after" or "in response to determining" or "in response to detecting". Similarly, according to the context, the phrase "upon determining" or "if detecting (the stated condition or event)" can be interpreted as meaning "if determining" or "in response to determining" or "upon detecting (the stated condition or event)" or "in response to detecting (the stated condition or event)".
[0369] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions can be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line) or wireless (such as infrared, wireless, microwave, etc.) mode. The computer readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. integrated with one or more available media. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk) and the like.
[0370] Those of ordinary skill in the art understand that all or part of the processes in the above embodiments can be implemented by a computer program to instruct the relevant hardware, which can be stored in a computer readable storage medium. The program can include the processes of the above method embodiments when executed. The aforementioned storage medium includes ROM or random access memory (RAM), magnetic disk or optical disk, and various media that can store program codes.
Claims
1. A two-dimensional code encoding method characterized by comprising: The method comprises the following steps: An electronic device obtains a text to be encoded, the text to be encoded comprising N characters, N being a positive integer; The electronic device determines a target encoding mode of each character in the N characters from X selectable encoding modes; The electronic device divides the N characters into M character segments according to the target encoding mode of each character, and determines a target encoding mode of each character segment in the M character segments; M is less than or equal to N; The electronic device encodes the M character segments according to the target encoding mode of each character segment, to obtain a first binary string; The electronic device determines a target version of a target two-dimensional code according to the length of the first binary string; The electronic device allocates the first binary string to each concentric circular region in the encoding region according to the positions of the image region, the encoding region and the positioner in the target version, to obtain two-dimensional code information; The electronic device generates the target two-dimensional code based on the two-dimensional code information.
2. The method of claim 1, wherein, The electronic device determines a target encoding mode of each character in the N characters from X selectable encoding modes, comprising: The electronic device determines one or more candidate encoding modes of a first character in the N characters from X selectable encoding modes; The electronic device selects a candidate encoding mode with the lowest number of encoding bits from the one or more candidate encoding modes as the target encoding mode of the first character.
3. The method of claim 2, wherein, The electronic device divides the N characters into M character segments according to the target encoding mode of each character, and determines a target encoding mode of each character segment in the M character segments, comprising: The electronic device divides characters in the N characters that are continuously adjacent and have the same target encoding mode into a character segment, to obtain M character segments; The electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in the character segment.
4. The method of claim 3, wherein, The M character segments comprise a first character segment, the first character segment comprising the first character and a second character, the target encoding modes of the first character and the second character being the same, and the target encoding mode of the first character segment being the same as the target encoding modes of the first character and the second character.
5. The method of claim 2, wherein, The electronic device divides the N characters into M character segments according to the target encoding mode of each character, and determines a target encoding mode of each character segment in the M character segments, comprising: The electronic device divides characters in the N characters that are continuously adjacent and have the same target encoding mode and are greater than a preset number into a character segment, to obtain M character segments; The electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in the character segment.
6. The method of claim 5, wherein, The M character segments comprise a second character segment, the number of characters in the second character segment being greater than or equal to the preset number.
7. The method of claim 2, wherein, The electronic device divides the N characters into M character segments according to the target encoding mode of each character, and determines a target encoding mode of each character segment in the M character segments, comprising: The electronic device starts counting from a first character in the N characters; When counting to an (u-1)th character, the electronic device determines that the number of characters is greater than or equal to a preset number, and a target encoding mode of the (u-1)th character is different from that of a uth character, and divides the first character to the (u-1)th character in the N characters into a character segment to obtain M character segments; The electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in each character segment.
8. The method of claim 3, wherein, The M character segments include a first character segment, and the electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in each character segment, including: The electronic device determines that the target encoding modes of the first character and a second character in the first character segment are a first target encoding mode; The electronic device takes the first target encoding mode as the target encoding mode of the first character segment.
9. The method of claim 3, wherein, The M character segments include a first character segment, and the electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in each character segment, including: The electronic device determines that the target encoding mode of the first character in the first character segment is a first target encoding mode, and the target encoding mode of a second character in the first character segment is a second target encoding mode, wherein the number of encoding bits of the first target encoding mode is higher than that of the second target encoding mode, and the first target encoding mode corresponds to an encoding index table including the second character, and the X selectable encoding modes include the first target encoding mode and the second target encoding mode; The electronic device takes the first target encoding mode as the target encoding mode of the first character segment.
10. The method of claim 3, wherein, The M character segments include a first character segment, and the electronic device determines the target encoding mode of each character segment in the M character segments based on the target encoding mode of the characters in each character segment, including: The electronic device determines that the target encoding mode of the first character in the first character segment is a first target encoding mode, and the target encoding mode of a second character in the first character segment is a second target encoding mode, wherein the first target encoding mode is different from the second target encoding mode, the first target encoding mode does not include the first character in a corresponding encoding index table, the second target encoding mode does not include the second character in a corresponding encoding index table, a third target encoding mode corresponds to a number of encoding bits higher than those of the first target encoding mode and the second target encoding mode, and the X selectable encoding modes include the first target encoding mode, the second target encoding mode, and the third target encoding mode; The electronic device takes the third target encoding mode as the target encoding mode of the first character segment.
11. The method of claim 4, wherein, The first binary string includes a second binary string, the second binary string being encoded by the first character segment, the second binary character segment including a mode indicator of a target encoding mode of the first character segment, an indicator of a character length in the first character segment, and a binary string of characters in the first string encoded according to the target encoding mode of the first string.
12. The method according to any one of claims 1 to 11, characterized in that, The N characters include one or more of a numeric character, an uppercase letter character, a lowercase letter character, a special character, and an escape character, and the target encoding mode corresponding to the numeric character, the uppercase letter character, the lowercase letter character, the special character, and the escape character has different minimum encoding bit numbers.
13. The method of claim 12, wherein, Each of the X selectable encoding modes corresponds to an encoding index table; the encoding index table includes a first encoding index table, a second encoding index table, a third encoding index table, a fourth encoding index table, a fifth encoding index table, a sixth encoding index table, a seventh encoding index table, and an eighth encoding index table. The first encoding index table includes the numeric character; the second encoding index table includes the numeric character and the uppercase letter character; The third encoding index table includes the numeric character and the lowercase letter character; The fourth encoding index table includes the uppercase letter character and the special character; the fifth encoding index table includes the lowercase letter character and the special character; the sixth encoding index table includes the numeric character, the uppercase letter character, and the special character; the seventh encoding index table includes the numeric character, the lowercase letter character, and the special character; and the eighth encoding index table includes the numeric character, the uppercase letter character, the lowercase letter character, and the special character.
14. The method of claim 13, wherein, The two-dimensional code includes a first version of a two-dimensional code, a second version of a two-dimensional code, a third version of a two-dimensional code, a fourth version of a two-dimensional code, a fifth version of a two-dimensional code, and a sixth version of a two-dimensional code, and the data capacities of the first version of a two-dimensional code, the second version of a two-dimensional code, the third version of a two-dimensional code, the fourth version of a two-dimensional code, the fifth version of a two-dimensional code, and the sixth version of a two-dimensional code are different.
15. The method of claim 14, wherein, The two-dimensional code is a circular two-dimensional code, the circular two-dimensional code includes an encoding area composed of a plurality of concentric circles, and each of the plurality of concentric circles includes a plurality of code elements on a ring of the concentric circle.
16. A two-dimensional code decoding method characterized by comprising: The method includes: An electronic device obtains a two-dimensional code to be decoded, the two-dimensional code to be decoded indicating first information; The electronic device determines version information of the two-dimensional code to be decoded according to a distance between a first locator and a second locator in the two-dimensional code to be decoded; The electronic device obtains mode indicator information from the two-dimensional code to be decoded; The electronic device determines an encoding mode of the two-dimensional code to be decoded from the mode indicator information, and the electronic device stores one or more mapping relationship tables, the mapping relationship tables including mode indicator information and an encoding mode corresponding to the mode indicator information; and The electronic device decodes the to-be-decoded two-dimensional code based on the version information and the encoding mode to obtain the first information.
17. The method of claim 16, wherein, The to-be-decoded two-dimensional code contains an encoding area, and the electronic device determines mode indication information from the to-be-decoded two-dimensional code, specifically including: The electronic device obtains the mode indication information from a symbol in the encoding area that stores the mode indication information.
18. The method of claim 17, before the electronic device obtains the mode indication information from a symbol in the encoding area that stores the mode indication information, comprising: determining a target version of the to-be-decoded two-dimensional code based on the version information; the target version indicates coordinate information of each storage location in the encoding area of the to-be-decoded two-dimensional code; the electronic device determines a binary value corresponding to a storage location occupied by each symbol in the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the coordinate information of each storage location.
19. The method of claim 18, wherein, The electronic device decodes the to-be-decoded two-dimensional code based on the version information and the encoding mode to obtain the first information, including: The electronic device decodes the binary value corresponding to the storage location occupied by each symbol in the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the encoding mode to obtain the first information.
20. The method of claim 19, wherein, The electronic device obtains mode indication information from the to-be-decoded two-dimensional code, including: The electronic device obtains one mode indication information and one or more sub-mode indication information contained in the mode indication information from the to-be-decoded two-dimensional code; The electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, including: The electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information and determines one or more encoding sub-modes of the to-be-decoded two-dimensional code from the one or more sub-mode indication information; The electronic device decodes the binary value corresponding to the storage location occupied by each symbol in the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the one or more encoding sub-modes to obtain the first information. The electronic device decodes the binary value corresponding to the storage location occupied by each symbol in the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the one or more encoding sub-modes to obtain the first information.
21. The method of claim 20, wherein, The one or more encoding sub-modes include a first encoding sub-mode and a second encoding sub-mode, and the encoding area includes a first encoding area and a second encoding area; The electronic device decodes the binary value corresponding to the storage location occupied by each symbol in the plurality of symbols in the encoding area of the to-be-decoded two-dimensional code according to the one or more encoding sub-modes to obtain the first information, including: The electronic device decodes the binary value corresponding to the storage location occupied by each symbol in the plurality of symbols in the first encoding area according to the first encoding sub-mode and decodes the binary value corresponding to the storage location occupied by each symbol in the plurality of symbols in the second encoding area according to the second encoding sub-mode to obtain the first information.
22. The method of claim 21, wherein, The mode indication information and the one or more sub-mode indication information are binary characters with fixed bit number.
23. The method of claim 22, wherein, The electronic device determines the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, and a mapping relationship table between the mode indication information and the encoding mode is stored in the electronic device, including: The electronic device queries the encoding mode corresponding to the mode indication information and the encoding bit number of the encoding mode in the mapping relationship table.
24. The method of claim 19, wherein, The electronic device obtains the encoding mode of the to-be-decoded two-dimensional code from the mode indication information, and a mapping relationship table between the mode indication information and the encoding mode is stored in the electronic device, specifically including: The electronic device queries the encoding mode corresponding to the mode indication information and the encoding sub-mode corresponding to each sub-mode indication information in the one or more encoding sub-modes in the mapping relationship table.
25. The method of any one of claims 16-24, wherein, The to-be-decoded two-dimensional code includes one mode indication information and multiple sub-mode indication information, and the first information includes two or more characters of numerical characters, uppercase letter characters, lowercase letter characters, special characters, and escape characters, and the target encoding mode corresponding to the numerical characters, the uppercase letter characters, the lowercase letter characters, the special characters, and the escape characters respectively has different minimum encoding bit number.
26. The method of claim 25, wherein, Each encoding sub-mode of the one or more encoding sub-modes corresponds to an encoding index table; the encoding index table includes a first encoding index table, a second encoding index table, a third encoding index table, a fourth encoding index table, a fifth encoding index table, a sixth encoding index table, a seventh encoding index table, and an eighth encoding index table. The first encoding index table includes the numerical characters; the second encoding index table includes the numerical characters and the uppercase letter characters; The third encoding index table includes the numerical characters and the lowercase letter characters; The fourth encoding index table includes the uppercase letter characters and the special characters; the fifth encoding index table includes the lowercase letter characters and the special characters; the sixth encoding index table includes the numerical characters, the uppercase letter characters, and the special characters; the seventh encoding index table includes the numerical characters, the lowercase letter characters, and the special characters; and the eighth encoding index table includes the numerical characters, the uppercase letter characters, the lowercase letter characters, and the special characters.
27. The method of claim 26, wherein, The target version of the to-be-decoded two-dimensional code includes a first version, a second version, a third version, a fourth version, a fifth version, and a sixth version. The target version of the to-be-decoded two-dimensional code is different, and the data capacity of the to-be-decoded two-dimensional code is different.
28. The method of claim 27, wherein, The to-be-decoded two-dimensional code is a circular two-dimensional code, the circular two-dimensional code includes an encoding area composed of multiple concentric circles, and each concentric circle in the multiple concentric circles includes multiple code elements on the annulus of the concentric circle.
29. An electronic device, comprising: Including: a communication interface, a memory, and a processor; the communication interface, the memory, and the processor are coupled, the memory is configured to store computer program code, the computer program code includes computer instructions, when the processor reads the computer instructions from the memory, so that the electronic device executes the method as claimed in any one of claims 1 to 15 or 16-28.
30. A computer storage medium, comprising, computer instructions, when the computer instructions are run on an electronic device, cause the electronic device to execute the method as claimed in any one of claims 1 to 15 or 16-28.
Citation Information
Patent Citations
Two-dimensional code coding method, two-dimensional code decoding method and two-dimensional code print
CN104143109A
QR code generation method suitable for ink-jet printer
CN110569946A