Two-dimensional code generation and analysis method, electronic equipment and storage medium
By combining stroke patterns with QR code base maps to generate diverse QR codes, the problems of single format of traditional QR codes and low payment security are solved, and high recognition and security are improved.
Patent Information
- Application Number
- CN202510037360.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-09
- Publication Date
- 2025-05-13
AI Technical Summary
Traditional QR codes have a single form in terms of visual effects, and it is difficult to detect tampering, resulting in damage to payment security.
By combining the stroke pattern with the blank QR code base map, a QR code composed of the stroke pattern is generated, and the spatial position parameters of each stroke pattern in the QR code are obtained to generate encoding information.
The generated QR codes are highly diverse and highly recognizable, and it is difficult for criminals to generate similar QR codes, which improves the security of QR codes.
Smart Images

Figure CN119990171A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of Internet technology, and in particular, to a method for generating and parsing a two-dimensional code, an electronic device, and a storage medium. Background Art
[0002] As an efficient tool for information transmission and storage, QR code has been widely used in all walks of life.
[0003] However, traditional QR codes generally have the problem of being monotonous in form and lacking personalized elements. Even if the QR code is tampered with, it is difficult to detect. Taking the physical QR code as an example, it is not uncommon for criminals to paste their own QR codes on the QR codes of merchants. Due to the monotonous form of traditional QR codes, it is difficult for customers and merchants to detect that the QR code has been tampered with, so that the money paid by customers by scanning the code is transferred to the accounts of criminals. Summary of the invention
[0004] In view of this, one or more embodiments of this specification provide a method for generating and parsing a two-dimensional code, an electronic device, and a storage medium, so as to provide a novel method for generating a two-dimensional code.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of an embodiment of this specification, a method for generating a two-dimensional code is provided, the method comprising:
[0007] Obtaining a stroke pattern selected from a preset pattern;
[0008] Combining the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern;
[0009] The spatial position parameters of each stroke pattern in the two-dimensional code are obtained, and encoding information consisting of the spatial position parameters is generated.
[0010] Optionally, combining the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern includes:
[0011] Get a blank QR code base image;
[0012] In the areas where any three of the four corners of the two-dimensional code base map are located, positioning points are respectively set;
[0013] According to a preset placement rule, the stroke pattern is placed on the two-dimensional code base map to generate a two-dimensional code composed of the stroke pattern.
[0014] Optionally, placing the stroke pattern on the two-dimensional code base map according to a preset placement rule includes:
[0015] For each selected stroke pattern, perform the following steps in sequence:
[0016] Initialize a random number, and generate the position coordinates and rotation angle of a stroke pattern according to the random number;
[0017] The stroke pattern is placed on the two-dimensional code base map according to the position coordinates, and the stroke pattern is rotated clockwise or counterclockwise at the rotation angle.
[0018] Optionally, the initializing random number and generating the position coordinates and rotation angle of the stroke pattern placed in the two-dimensional code base map according to the random number include:
[0019] Initialize horizontal random number, vertical random number and rotation random number;
[0020] Multiply the horizontal random number by the pixel value of the width of the two-dimensional code base image, and round down to obtain the horizontal coordinate;
[0021] Multiply the vertical random number by the pixel value of the height of the two-dimensional code base map; and round down to obtain the vertical coordinate;
[0022] The rotation random number is multiplied by 360 and rounded down to obtain the rotation angle of the stroke pattern.
[0023] Optionally, placing the stroke pattern on the two-dimensional code base map according to the position coordinates, and rotating the stroke pattern clockwise or counterclockwise by the rotation angle includes:
[0024] The coordinates of the center point of the stroke pattern are set as the horizontal coordinates and the vertical coordinates to place the stroke pattern on the two-dimensional code base map, and further rotate the stroke pattern clockwise or counterclockwise at the rotation angle based on the center point.
[0025] Optionally, after rotating the stroke pattern clockwise or counterclockwise by the rotation angle, the method further includes:
[0026] Checking whether the rotated stroke pattern is abnormal;
[0027] If there is an exception, re-execute the step of initializing the random number;
[0028] If there are no exceptions, the next stroke pattern is executed.
[0029] Optionally, the checking whether the rotated stroke pattern is abnormal includes:
[0030] Determine whether the rotated stroke pattern exceeds the range of the two-dimensional code base map;
[0031] Determining whether the rotated stroke pattern overlaps with the positioning point;
[0032] If the rotated stroke pattern exceeds the range of the two-dimensional code base map, or overlaps with any positioning point, it is determined that an abnormality exists;
[0033] If the rotated stroke pattern does not exceed the range of the two-dimensional code base map and does not overlap with any positioning point, it is determined that there is no abnormality.
[0034] According to a second aspect of the embodiments of this specification, a method for parsing a two-dimensional code is provided, the method comprising:
[0035] Obtain a QR code consisting of a stroke pattern to be parsed;
[0036] Parsing the two-dimensional code to determine the spatial position parameters of the stroke pattern constituting the two-dimensional code;
[0037] Generate encoding information consisting of the spatial position parameters.
[0038] Optionally, the parsing of the two-dimensional code to determine the spatial position parameters of the stroke pattern constituting the two-dimensional code includes:
[0039] Using an image detection algorithm, the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern are detected;
[0040] The position coordinates of each stroke pattern and the rotation angle of the stroke pattern are determined as the spatial position parameters of the stroke pattern.
[0041] Optionally, before using an image detection algorithm to detect the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern, the method further includes:
[0042] Detecting a preset pattern in a middle area of the QR code;
[0043] Obtaining a stroke pattern selected from the preset pattern during the generation of the QR code and using it as a verification pattern;
[0044] The method of using an image detection algorithm to detect the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern includes:
[0045] An image detection algorithm is used to detect the stroke patterns in the two-dimensional code that match the verification pattern, and the position coordinates of each stroke pattern and the rotation angle of the stroke pattern are calculated.
[0046] According to a third aspect of the embodiments of this specification, a device for generating a two-dimensional code is provided, the device comprising:
[0047] An acquisition unit, which acquires a stroke pattern selected from a preset pattern;
[0048] A generating unit, combining the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern;
[0049] The encoding unit obtains the spatial position parameters of each stroke pattern in the two-dimensional code and generates encoding information composed of the spatial position parameters.
[0050] Optionally, the generating unit may further include:
[0051] Get the subunit and get the blank QR code base image;
[0052] Setting a subunit to respectively set positioning points in the areas where any three of the four corners of the two-dimensional code base map are located;
[0053] The placement subunit places the stroke pattern on the two-dimensional code base map according to a preset placement rule to generate a two-dimensional code composed of the stroke pattern.
[0054] Optionally, the placement subunit may further include:
[0055] For each selected stroke pattern, execute the following sub-units in sequence:
[0056] The calculation subunit initializes a random number, and generates the position coordinates and rotation angle of the stroke pattern placed in the two-dimensional code base map according to the random number;
[0057] The generating subunit places the stroke pattern on the two-dimensional code base map according to the position coordinates, and performs clockwise or counterclockwise rotation on the stroke pattern at the rotation angle.
[0058] Optionally, the calculation subunit is further used to initialize horizontal random numbers, vertical random numbers and rotation random numbers; multiply the horizontal random number by the pixel value of the width of the two-dimensional code base image, and round down to obtain the horizontal coordinate; multiply the vertical random number by the pixel value of the height of the two-dimensional code base image; and round down to obtain the vertical coordinate; multiply the rotation random number by 360, and round down to obtain the rotation angle of the stroke pattern.
[0059] Optionally, the generating subunit is further used to set the coordinates of the center point of the stroke pattern as the horizontal coordinate and the vertical coordinate, so as to place the stroke pattern on the QR code base map, and further rotate the stroke pattern clockwise or counterclockwise at the rotation angle based on the center point.
[0060] Optionally, after generating the subunit, it also includes:
[0061] The checking subunit checks whether the rotated stroke pattern is abnormal; if there is an abnormality, the initial subunit is re-executed; if there is no abnormality, the initial subunit is executed for the next stroke pattern.
[0062] According to a fourth aspect of the embodiments of this specification, a two-dimensional code parsing device is provided, the device comprising:
[0063] An acquisition unit, which acquires a two-dimensional code composed of a stroke pattern to be parsed;
[0064] A parsing unit, which parses the two-dimensional code to determine the spatial position parameters of the stroke pattern constituting the two-dimensional code;
[0065] The encoding unit generates encoding information consisting of the spatial position parameters.
[0066] Optionally, the parsing unit may further include:
[0067] A detection subunit detects the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern using an image detection algorithm;
[0068] The determination subunit determines the position coordinates of each stroke pattern and the rotation angle of the stroke pattern as the spatial position parameters of the stroke pattern.
[0069] Optionally, before detecting the subunit, it also includes:
[0070] A verification subunit detects a preset pattern in the middle area of the two-dimensional code; obtains a stroke pattern selected from the preset pattern during the generation of the two-dimensional code and uses it as a verification pattern;
[0071] The detection subunit is further used to detect the stroke pattern matching the verification pattern in the two-dimensional code by using an image detection algorithm, and calculate the position coordinates of each stroke pattern and the rotation angle of the stroke pattern.
[0072] According to a fifth aspect of the embodiments of this specification, an electronic device is provided, including:
[0073] processor;
[0074] a memory for storing processor-executable instructions;
[0075] The processor executes the executable instructions to implement the method for generating or parsing a two-dimensional code as described in any embodiment of this specification.
[0076] According to the sixth aspect of the embodiments of this specification, a computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the method for generating or parsing a two-dimensional code described in any embodiment of this specification is implemented.
[0077] According to the seventh aspect of the embodiments of this specification, a computer program product is provided, including a computer program, which, when executed by a processor, implements the method for generating or parsing a two-dimensional code as described in any embodiment of this specification.
[0078] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0079] By integrating the stroke pattern into the QR code, a QR code with high diversity is generated, which breaks the problem of the single form of the traditional QR code; and the QR code composed of the stroke pattern has a high degree of recognition, and it is difficult for criminals to legally generate a similar QR code. Even if the QR code is tampered with, it can be easily discovered, thereby improving the security of the QR code.
[0080] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present specification. BRIEF DESCRIPTION OF THE DRAWINGS
[0081] Figure 1 It is a flowchart of a method for generating a two-dimensional code provided by an exemplary embodiment;
[0082] Figure 2 is a schematic diagram of a preset pattern provided by an exemplary embodiment;
[0083] Figure 3a is a schematic diagram of a positioning point provided by an exemplary embodiment;
[0084] Figure 3b is a schematic diagram of a QR code provided by an exemplary embodiment;
[0085] Figure 3c is a schematic diagram of abnormal placement of a stroke pattern provided by an exemplary embodiment;
[0086] Figure 3d is a schematic diagram of a QR code with a preset pattern added provided by an exemplary embodiment;
[0087] Figure 4It is a schematic diagram of a process of generating a QR code for multi-party interaction provided by an exemplary embodiment;
[0088] Figure 5 It is a flowchart of a method for parsing a two-dimensional code provided by an exemplary embodiment;
[0089] Figure 6 It is a schematic diagram of a parsing process of a QR code for multi-party interaction provided by an exemplary embodiment;
[0090] Figure 7 It is a structural schematic diagram of a device for generating a two-dimensional code provided by an exemplary embodiment;
[0091] Figure 8 It is a structural schematic diagram of a two-dimensional code parsing device provided by an exemplary embodiment;
[0092] Fig. 9 It is a schematic structural diagram of an electronic device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0093] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0094] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0095] The embodiments of this specification provide a method for generating and parsing a two-dimensional code, which is divided into a two-dimensional code generation process and a two-dimensional code scanning process.
[0096] [Generate a QR code]
[0097] As described above, traditional QR codes generally have the problem of a single form in terms of visual effects, lacking personalized elements, and it is difficult to detect even if the QR code is tampered with. Taking physical QR codes as an example, it is not uncommon for criminals to paste the QR codes they applied for onto the merchant's QR codes. Due to the single form of traditional QR codes, it is difficult for both customers and merchants to detect that the QR code has been tampered with, resulting in the transfer of the amount paid by the customer through scanning the code into the criminal's account.
[0098] To address the above problems, the QR code generation solution provided in this specification integrates stroke patterns into the QR code to generate QR codes with high diversity, breaking the problem of the single form of traditional QR codes; and the QR code composed of the stroke patterns has high辨识度, and it is difficult for criminals to legally generate similar QR codes. Even if the QR code is tampered with, it can be easily detected, thus improving the security of the QR code.
[0099] Please refer to Figure 1 The flowchart of a method for generating a QR code provided by an exemplary embodiment. The method of this embodiment will be described from the perspective of the server to describe how to generate a QR code composed of stroke patterns.
[0100] As Figure 1 shown, the method may include the following processes:
[0101] Step 110, obtain the stroke pattern selected from the preset pattern.
[0102] The server may respond to the QR code generation request initiated by the client and obtain the preset pattern carried in the request, or the preset pattern specified by the request and saved in a third party or locally on the server.
[0103] The client may be a program installed in the user terminal to provide services for the user. Among them, the program includes but is not limited to APPs, web pages, mini programs, etc., and the user terminal includes but is not limited to smart phones, personal digital assistants, tablet computers, personal computers, laptop computers, etc.
[0104] The preset pattern includes a logo pattern, and the stroke pattern includes a pattern related to the stroke obtained by splitting the logo pattern.
[0105] As Figure 2 an example, for the upper logo "Xiaohongshu", several stroke patterns can be split from it. For example, the vertical hook stroke of the character "小" in the lower part, the dot stroke of the character "书", the twisted silk side stroke of the character "红", and the撇 stroke of the character "小".
[0106] By selecting stroke patterns from the logo pattern and integrating the stroke patterns into the QR code, you can improve the recognition of the QR code and enhance the popularity of the brand logo.
[0107] Step 120, combining the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern.
[0108] In this step, after obtaining the stroke pattern selected from the preset pattern, the stroke pattern can be combined with a blank two-dimensional code base image to generate a two-dimensional code composed of the stroke pattern.
[0109] In an exemplary embodiment, step 120 may include:
[0110] Get a blank QR code base image;
[0111] In the areas where any three of the four corners of the two-dimensional code base map are located, positioning points are respectively set;
[0112] According to a preset placement rule, the stroke pattern is placed on the two-dimensional code base map to generate a two-dimensional code composed of the stroke pattern.
[0113] In this step, the positioning point is used to determine the direction of the QR code. Usually, the QR code base is a regular rectangle (such as a rectangle or a square), and such a QR code base may have four corners. Since it involves the encoding and decoding of the QR code, the direction of the QR code can be determined by setting a unified positioning point, and then the encoding and subsequent decoding can be carried out in an orderly manner according to the direction of the QR code.
[0114] like Figure 3a For example, in this example, a red free circle is used as a positioning point, and a positioning point is set at the upper left corner, upper right corner, and lower left corner of the QR code base map.
[0115] For example, it is assumed that the pixel value of the width (W) of the blank two-dimensional code background image is A pixel value, and the pixel value of the height (H) is also B pixel value. A may be equal to B, or may not be equal to B.
[0116] like Figure 2 As shown, a red hollow circle is placed at a distance of a1 pixels horizontally and b1 pixels vertically from the border at the upper left corner, upper right corner and lower left corner of the QR code base image, and the inner diameter of the red hollow circle is c1 pixels and the outer diameter is c2 pixels. Among them, a1 is less than A, b1 is less than B; c1 is less than c2.
[0117] By setting Figure 3a These three positioning points can clarify the direction of the QR code base map (and can also clarify the QR code generated subsequently).
[0118] It should be noted that Figure 3a The red free circle shown in the figure is only an example of a positioning point. In actual application, positioning points of any color and shape can be used, and this specification does not limit this.
[0119] After setting the positioning points, the selected stroke patterns can be placed in the QR code base map in sequence, and each stroke pattern is based on the same placement rules. For example, for each selected stroke pattern, the stroke pattern can be placed in the QR code base map in sequence according to the placement rules shown below:
[0120] Initialize a random number, and generate the position coordinates and rotation angle of the stroke pattern placed in the two-dimensional code base map according to the random number;
[0121] The stroke pattern is placed on the two-dimensional code base map according to the position coordinates, and the stroke pattern is rotated clockwise or counterclockwise at the rotation angle.
[0122] In this embodiment, by introducing random numbers, different position coordinates and rotation angles can be generated for each stroke pattern. Even if the same stroke pattern is selected from the same preset pattern, the QR code generated each time can be different, thereby improving the diversity of the QR code composed of stroke patterns.
[0123] In an exemplary implementation, the initializing random number and generating the position coordinates and rotation angle of the stroke pattern placed in the two-dimensional code base map according to the random number may include:
[0124] Initialize horizontal random number, vertical random number and rotation random number;
[0125] Multiply the horizontal random number by the pixel value of the width of the two-dimensional code base image, and round down to obtain the horizontal coordinate;
[0126] Multiply the vertical random number by the pixel value of the height of the two-dimensional code base map; and round down to obtain the vertical coordinate;
[0127] The rotation random number is multiplied by 360 and rounded down to obtain the rotation angle of the stroke pattern.
[0128] In this example, considering that the QR code is a two-dimensional plane graphic, when determining the position coordinates of the stroke pattern, the pixel values of the horizontal width and the vertical height of the QR code base image can be referred to, and the horizontal and vertical coordinates relative to the QR code base image can be generated according to random numbers. The generated horizontal and vertical coordinates are used as the position coordinates of the stroke pattern.
[0129] It is worth mentioning that in order to limit the horizontal and vertical coordinates within the QR code base map, the value range of the above-mentioned horizontal random numbers, vertical random numbers and rotation random numbers can be limited to the interval [0,1], that is, the horizontal random numbers, vertical random numbers and rotation random numbers in the interval [0,1] can be initialized.
[0130] In this embodiment, by setting the horizontal random number and the vertical random number, the stroke pattern can be randomly placed in the QR code base map. In addition, by setting the rotation random number, even the same stroke pattern can have different placement angles, thereby further increasing diversity.
[0131] It should be noted that the purpose of rounding down is to ensure that the stroke pattern after placement is within the QR code base as much as possible. If rounding up, it is easier to make the stroke pattern after placement exceed the QR code base.
[0132] In an exemplary implementation, placing the stroke pattern on the two-dimensional code base map according to the position coordinates and rotating the stroke pattern clockwise or counterclockwise by the rotation angle may include:
[0133] The coordinates of the center point of the stroke pattern are set as the horizontal coordinates and the vertical coordinates to place the stroke pattern on the two-dimensional code base map, and further rotate the stroke pattern clockwise or counterclockwise at the rotation angle based on the center point.
[0134] In this embodiment, considering that the stroke pattern is a two-dimensional plane image, and the horizontal coordinates and vertical coordinates contained in the position coordinates are only a point, when placing the stroke pattern according to the position coordinates, the center point of the stroke pattern can be aligned with the position coordinates, that is, the coordinates of the center point are set to the horizontal coordinates and the vertical coordinates, so that the stroke pattern can be placed on the QR code base according to the position coordinates, and then the stroke pattern can be rotated.
[0135] Still Figure 2 Take the four stroke patterns shown as an example, these four stroke patterns are replaced by letters ABCD respectively. The images are placed in the order of A->B->C->D. The placement process is as follows:
[0136] First, three initial random numbers in the interval [0,1] (horizontal random number xi, vertical random number yi and rotation random number ri);
[0137] Next, multiply the horizontal random number xi by the pixel value A of the width of the QR code base image, and round it down to get the horizontal coordinate X; multiply the vertical random number yi by the pixel value B of the height of the QR code base image, and round it down to get the vertical coordinate Y; multiply the rotation random number ri by 360 and round it down to get the rotation schedule R.
[0138] Among them, the obtained (X, Y) represents a pixel position in the QR code background image, and this pixel position will be used as the center point for placing the stroke pattern. The obtained R represents the angle value by which the stroke pattern needs to be rotated.
[0139] Finally, set the center point of the image stroke to (X, Y), so as to place the stroke pattern in the QR code background image, and rotate the placed QR code background image by R angles with the center point as the rotation center. The rotation direction here can be predefined, either clockwise or counterclockwise, and each stroke pattern is rotated in the same direction.
[0140] By the above method, successively Figure 2 After placing the 4 stroke patterns shown in the QR code background image with positioning points set, a QR code composed of stroke patterns as shown in Figure 3b can be generated. It should be noted that due to the limited space of the QR code background image, overlap between stroke patterns is allowed, and the previously placed stroke pattern can be partially covered by the subsequently placed stroke pattern. As Figure 3b shown, the vertical hook stroke part of the character "小" placed later covers the left-falling stroke of the character "小" placed earlier; similarly, the dot stroke of the character "书" placed last partially covers the left-falling stroke of the character "小" placed earlier and the twisted silk radical stroke of the character "红" placed earlier at the same time.
[0141] In practical applications, since the calculated (X, Y) coincides with the center point of the stroke pattern, and the stroke pattern itself has a certain size, abnormal situations such as the placed stroke pattern exceeding the QR code background image or other abnormalities may occur.
[0142] In view of this, in an exemplary embodiment, after the clockwise or counterclockwise rotation of the rotation angle of the stroke pattern, it may further include:
[0143] Verify whether the rotated stroke pattern is abnormal;
[0144] If there is an abnormality, re - execute the step of initializing the horizontal random number, vertical random number, and rotation random number in the interval [0, 1];
[0145] If there is no abnormality, execute the next stroke pattern.
[0146] In this embodiment, after each stroke pattern is placed, an abnormality check can also be performed to determine whether there is an abnormality of the placed stroke pattern relative to the QR code background image. If there is an abnormality, the stroke pattern is re - placed, and if there is no abnormality, the next stroke pattern can be continued to be placed.
[0147] In an exemplary embodiment, the above-mentioned checking whether the rotated stroke pattern is abnormal may further include:
[0148] Determine whether the rotated stroke pattern exceeds the range of the two-dimensional code base map;
[0149] Alternatively, determining whether the rotated stroke pattern overlaps with the positioning point;
[0150] If the rotated stroke pattern exceeds the range of the two-dimensional code base map, or overlaps with any positioning point, it is determined that an abnormality exists;
[0151] If the rotated stroke pattern does not exceed the range of the two-dimensional code base map and does not overlap with any positioning point, it is determined that there is no abnormality.
[0152] like Figure 3c As shown, although the center point of the stroke pattern is located within the QR code base, not all of the stroke patterns are within the QR code base, and some of the stroke patterns are located outside the QR code base. Therefore, the stroke pattern arranged in this way is incomplete and needs to be rearranged.
[0153] In addition, if the stroke pattern overlaps with the positioning point set in the QR code base map, it will affect the function of the positioning point. When parsing the QR code, it will not be able to identify the effective positioning point and determine the direction of the QR code, resulting in parsing failure. Therefore, the stroke pattern that overlaps with the positioning point is also an abnormality and needs to be rearranged.
[0154] The above-mentioned abnormality check can avoid in advance the problem that the generated QR code cannot be parsed normally due to abnormal placement of stroke patterns.
[0155] In an exemplary embodiment, the method further comprises:
[0156] Scaling the preset pattern to a preset size;
[0157] The scaled preset pattern is placed in the central area of the two-dimensional code base map; wherein the center point of the scaled preset pattern coincides with the center point of the two-dimensional code base map.
[0158] like Figure 3d As shown, on the basis of generating the two-dimensional code composed of the stroke pattern, a preset pattern can be further added, so that the recognition of the two-dimensional code can be further improved.
[0159] Step 130, obtaining the spatial position parameters of each stroke pattern in the two-dimensional code, and generating coding information composed of the spatial position parameters.
[0160] In this embodiment, with the help of the above-mentioned step 120, when placing the stroke pattern, it is necessary to calculate the horizontal coordinates, vertical coordinates and rotation angle of the stroke pattern in the QR code base image. The horizontal coordinates, vertical coordinates and rotation angle of the stroke pattern can be used as spatial position parameters.
[0161] Furthermore, the coding information composed of the spatial position parameters can be generated by sequentially splicing the horizontal coordinates, vertical coordinates and rotation angles of each stroke pattern according to the arrangement order of the stroke patterns, thereby obtaining the coding information of the generated two-dimensional code.
[0162] by Figure 3b Taking the two-dimensional code shown as an example, assuming that the spatial position parameters of the four stroke patterns are calculated in the order of ABCD, they are: A stroke pattern (x0, y0, r0), B stroke pattern (x1, y1, r1), C stroke pattern (x2, y2, r2), D stroke pattern (x3, y3, r3);
[0163] After splicing, we can get a 12-dimensional vector V = [x0, y0, r0, x1, y1, r1, x2, y2, r2, x3, y3, r3], and this vector V can be used as the encoding information of the QR code.
[0164] The method for generating a two-dimensional code in this embodiment integrates the stroke pattern into the two-dimensional code to generate a two-dimensional code with high diversity, breaking the problem of the single form of the traditional two-dimensional code. On the one hand, the two-dimensional code composed of the stroke pattern has a high degree of recognition, and it is difficult for criminals to legally generate a similar two-dimensional code. Even if the two-dimensional code is tampered with, it can be easily discovered, thereby improving the security of the two-dimensional code.
[0165] On the other hand, for the stroke patterns of Chinese characters, incorporating Chinese character strokes into QR codes can give QR codes unique cultural connotations and artistic life, and enhance the aesthetic value of QR codes. Higher aesthetic value can also bring users a pleasant visual experience and enhance users' participation and interest in scanning QR codes.
[0166] On the other hand, through horizontal random numbers, vertical random numbers and rotational random numbers, the stroke patterns are highly diverse. Even the same stroke pattern can have different encoding information, thus meeting the demand for the number of QR codes for a large number of different businesses.
[0167] Since the QR code provided in this manual is different from the traditional QR code, it is not a black and white square QR code generated based on the encoding of the business address; instead, the stroke pattern is directly placed on the QR code base to generate a highly recognizable and diverse QR code; therefore, the QR code generated at this time does not have a business address that can be parsed, and it can be considered that the QR code generated at this time is just a recognizable pattern, rather than a valid QR code that can be scanned and used.
[0168] Therefore, it is necessary to add a business address for executing related business to the generated two-dimensional code composed of stroke patterns. However, since the two-dimensional code has been generated at this time, and the stroke pattern itself cannot carry the business address information, it is impossible to directly add the business address to the generated two-dimensional code.
[0169] In view of this, after generating the coding information composed of the spatial position parameters in step 130, a mapping relationship between the coding information and the business address corresponding to the two-dimensional code can also be established.
[0170] By utilizing the inherent characteristics of the stroke pattern added to the QR code, i.e., the spatial position parameters of the stroke pattern in the QR code, the spatial position parameters of each stroke pattern are used as the encoding information of the QR code to uniquely bind the QR code (i.e., the QR code and the encoding information have a unique corresponding relationship). Furthermore, after determining the encoding information of the uniquely bound QR code, the corresponding business address can also be associated with the encoding information, i.e., a mapping relationship between the encoding information and the business address is established, so that the corresponding relationship between the QR code and the business address can be realized, thereby giving the ability to execute related businesses by scanning the QR code.
[0171] In this specification, a mapping relationship between the encoding information and the business address of the target business can be established based on business requirements or the target business specified in the QR code generation request initiated by the aforementioned client, so that the QR code (composed of stroke patterns) generated by the above embodiment can execute the target business after successful scanning.
[0172] The target business may be various, for example, it may include payment-related business (such as collection, payment, transfer, etc.), and the corresponding QR code composed of stroke patterns may be called collection code, payment code, transfer code, etc. For another example, the target business may be social-related business (such as following, forwarding, adding friends, transferring files, lottery, etc.), and the corresponding QR code composed of stroke patterns may be called following code, sharing code, lottery code, etc. In short, any application scenario involving QR code may adopt the QR code generation solution provided in this specification, and this specification does not limit the specific application scenario of QR code.
[0173] The following is a detailed explanation of the solution in this manual using the payment code in daily life as an example.
[0174] If a merchant wants to apply to generate a payment code, the merchant can upload the store's logo pattern and payment account, and the server can perform the method of the aforementioned steps 110 to 130, disassemble the text pattern in the logo pattern according to the stroke order, and select at least one stroke pattern from the disassembly result; then combine the stroke pattern with a blank QR code base map to generate a QR code composed of stroke patterns, and determine the spatial position parameters of each stroke pattern in the QR code, and encode the spatial position parameters into the encoding information of the QR code. Finally, the server obtains the payment address corresponding to the payment account (usually an address in the form of a URL) based on the payment account provided by the user, and then establishes a mapping relationship between the encoding information of the QR code and the payment address, which can be stored on the server.
[0175] In this way, when the customer scans the QR code composed of stroke patterns, the client used by the customer parses the encoding information of the stroke pattern in the QR code (the process of parsing the QR code will be introduced in subsequent embodiments), and then sends the encoding information to the server. The server queries the payment address mapped to the encoding information from all the mapping relationships maintained, and then returns the payment address to the client, so that the client can jump to the payment interface corresponding to the payment address to make payment.
[0176] After introducing the embodiment of the method for generating a two-dimensional code with the server as the execution subject, the following introduces the embodiment of the method for generating a two-dimensional code under multi-party interaction in combination with the client and the server. Figure 4 As shown, it may include:
[0177] Step 410: The client sends a request for generating a QR code to the server.
[0178] The preset pattern that can be carried in the generation request sent by the client can refer to a logo pattern or other patterns composed of strokes.
[0179] Step 420: The server obtains a stroke pattern selected from preset patterns.
[0180] The server side responds to the generation request by selecting a stroke pattern from the preset patterns carried in the generation request. The number of the stroke patterns is at least one.
[0181] In step 430, the server combines the stroke pattern with a blank QR code base image to generate a QR code consisting of the stroke pattern.
[0182] The server sets positioning points in the areas where any three of the four corners of the two-dimensional code base map are located, and places the stroke pattern in the two-dimensional code base map according to a preset placement rule, thereby generating a two-dimensional code composed of the stroke pattern. The placement rule here can refer to the above embodiment and will not be repeated here.
[0183] In step 440, the server obtains the spatial position parameters of each stroke pattern in the two-dimensional code, and generates coding information composed of the spatial position parameters.
[0184] Since the QR code provided in this manual is different from the traditional QR code, it is not a black and white square QR code based on coding information; instead, the stroke pattern is directly placed on the QR code base to generate a highly recognizable and diverse QR code; therefore, the QR code generated at this time does not have coding information.
[0185] To this end, the server may use the horizontal coordinates, vertical coordinates and rotation angle of the stroke pattern as spatial position parameters, and concatenate the spatial position parameters of each stroke pattern, thereby obtaining the encoding information composed of the spatial position parameters.
[0186] Step 450: The server establishes a mapping relationship between the encoding information and the business address corresponding to the QR code.
[0187] After encoding to obtain the encoding information, the server can establish a mapping relationship between the encoding information and the business address of the target business according to business requirements or the target business specified in the QR code generation request initiated by the client.
[0188] Step 460: The server returns the generated QR code to the client.
[0189] It is worth mentioning that, in addition to returning the QR code to the client after step 450 , the server may also return the QR code to the client after generating the QR code in step 430 .
[0190] After receiving the QR code, the client can scan it by itself, transmit it over the network, or print or create a physical QR code to display the QR code and have other users scan it. After successfully scanning the code, the coding information of the stroke pattern in the QR code can be parsed to obtain the business address mapped to the coding information, so that the client can jump to the business address to execute the relevant business process.
[0191] [Analysis of QR code]
[0192] After the QR code is generated, it can be transmitted over the network and displayed through electronic devices, or printed as a physical QR code for display. Other users can use the client to scan the displayed QR code to perform the QR code parsing process.
[0193] See below Figure 5 An exemplary embodiment provides a flowchart of a method for generating a QR code. The method description of this embodiment will describe how to parse a QR code composed of stroke patterns from the perspective of a client. It should be noted that the client that parses the QR code may be different from the client that requests to generate the QR code.
[0194] Step 510, obtaining a two-dimensional code composed of stroke patterns to be parsed.
[0195] The user can use the client to scan the QR code composed of the stroke pattern, thereby obtaining the QR code composed of the stroke pattern to be parsed. Wherein, the QR code composed of the stroke pattern is generated by the embodiment of the QR code generation method described above.
[0196] Step 520, parse the two-dimensional code to determine the spatial position parameters of the stroke pattern constituting the two-dimensional code.
[0197] Parsing of QR codes can be divided into positioning point detection and stroke image detection.
[0198] The process of positioning point detection requires preprocessing of the image of the two-dimensional code such as smoothing filtering and binarization to obtain a clearer two-dimensional code, and then further contour detection of the two-dimensional code to detect the positioning points in the two-dimensional code.
[0199] The contour detection can be performed by extracting the contour features of each graphic in the two-dimensional code and matching them with the standard contour features of the positioning point to be detected. The graphic corresponding to the successfully matched contour feature is the detected positioning point.
[0200] Below Figure 3d Taking the red hollow circle as an example, it is necessary to first determine the significant difference between the positioning point and the stroke pattern, so as to define the standard contour features of the positioning point based on the difference. Figure 3d In the figure, it can be found that the positioning points are hollow circles, while the stroke patterns can also have circular shapes (not shown in the figure), but the stroke patterns are all solid. Therefore, it can be defined that the standard contour feature of the positioning point is composed of two circular sub-contours (inner circle and outer circle) features. In this way, when performing contour detection, three positioning points at the upper corner, upper right corner and lower left corner can be screened out.
[0201] Of course, if no positioning points are detected, or the number of detected positioning points does not meet 3, an error is returned and the QR code is retrieved again, for example, prompting the user to re-scan the QR code to obtain a clearer and more accurate QR code.
[0202] After the positioning points are detected, stroke image detection can be further performed.
[0203] Exemplarily, an image detection algorithm may be used to detect the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern;
[0204] The position coordinates of each stroke pattern and the rotation angle of the stroke pattern are determined as the spatial position parameters of the stroke pattern.
[0205] In this embodiment, the stroke pattern in the QR code can be detected in sequence according to the positional relationship between the three detected positioning points. The detection order is consistent with the order of placing the stroke pattern during the QR code generation process. The stroke pattern can be detected from the upper left corner to the upper right corner of the QR code in the order of the upper left corner positioning point, the upper right corner positioning point and the lower left corner positioning point, and then the stroke pattern is detected from the lower left corner to the lower right corner.
[0206] If the generation embodiment of a QR code places the stroke pattern on the QR code base by setting the coordinates of the center point of the stroke pattern as horizontal coordinates and vertical coordinates; then correspondingly, the image detection image in this embodiment can detect the horizontal coordinates and vertical coordinates of the center point of each stroke pattern in the QR code.
[0207] The horizontal coordinates and vertical coordinates are also the same as those in the aforementioned QR code generation embodiment. The pixel values of the horizontal width and the vertical height of the QR code base image are used as the reference system, and the horizontal coordinates and vertical coordinates of the center point of the stroke pattern relative to the QR code base image are detected.
[0208] It should be noted that since the angle at which the user scans the QR code is random, it is difficult to directly obtain the QR code image in the front view. Therefore, after detecting the positioning point, the QR code image can also be affine transformed to obtain the corrected QR code image in the front view. In this way, based on the QR code image in the front view, the spatial position parameters of the stroke pattern can be detected more accurately.
[0209] In this specification, the image detection algorithm may include but is not limited to SIFT (Scale-invariant feature transform), SURF (Speeded Up Robust Features), ORB (Oriented FAST and Rotated BRIEF) algorithm, etc.
[0210] In order to clarify which stroke patterns are in the QR code, a preset pattern added to the QR code can be used. The preset pattern is an original pattern that provides a stroke pattern as shown in the previous embodiment. For example, the preset pattern may include a logo pattern, and the stroke pattern may include a stroke-related pattern obtained by splitting the logo pattern.
[0211] Specifically, a preset pattern in the middle area of the QR code may be detected;
[0212] Obtaining a stroke pattern selected from the preset pattern during the generation of the QR code and using it as a verification pattern;
[0213] Then, an image detection algorithm is used to detect the stroke patterns in the two-dimensional code that match the verification pattern, and the position coordinates of each stroke pattern and the rotation angle of the stroke pattern are calculated.
[0214] In this embodiment, after the client detects the preset pattern, it can obtain the stroke patterns used by the server to generate the QR code corresponding to the preset pattern from the server, and use these stroke patterns as verification patterns to verify whether the stroke patterns detected by the image detection algorithm are the stroke patterns split from the preset pattern and used to generate the QR code.
[0215] Through the image detection algorithm, the stroke pattern matching the verification pattern in the QR code can be detected, and the position coordinates of each stroke pattern and the rotation angle of the stroke pattern can be obtained; then the position coordinates and the rotation angle of the stroke pattern are used as the spatial position parameters of the stroke pattern.
[0216] Step 530: Generate coding information consisting of the spatial position parameters.
[0217] As shown above, the order of detecting stroke patterns is consistent with the order of placing stroke patterns. Therefore, when each stroke pattern is detected correctly, the order of spatial position parameters of each stroke pattern detected based on the detection order will also be consistent with the order of spatial position parameters of the coding information generated in step 130 during the QR code generation process.
[0218] In this way, by splicing the horizontal coordinates, vertical coordinates of the center point of each stroke pattern and the rotation angle of the stroke pattern in the order of the detected stroke patterns, the encoding information corresponding to the two-dimensional code can be obtained.
[0219] The two-dimensional code parsing method of this embodiment is based on the aforementioned two-dimensional code generation method, and is used to parse the two-dimensional code composed of stroke patterns generated by the aforementioned two-dimensional code generation method.
[0220] By analyzing the inherent features of the stroke pattern added in the QR code, that is, the spatial position parameters of the stroke pattern in the QR code, the same encoding method as the aforementioned QR code generation method is adopted, and the spatial position parameters of each stroke pattern are used as encoding information.
[0221] Since the aforementioned QR code generation method uses random numbers to make the stroke pattern added in the QR code highly diverse, even the same stroke pattern can have different encoding information, so the encoding information of each QR code can be considered unique. Based on this, if the encoding information generated in step 530 is consistent with the encoding information generated in step 130 in the aforementioned QR code generation method, it means that the parsing of the QR code is successful. On the contrary, if they are inconsistent, it means that the parsing of the QR code has failed.
[0222] In an exemplary embodiment, as described in the previous QR code generation embodiment, after generating the QR code, the server will establish a mapping relationship between the encoding information of the QR code and the corresponding business address; and the server can store the mapping relationship.
[0223] Correspondingly, after step 530, the following may further be included: searching for a business address that has a mapping relationship with the coding information, and jumping to the business address to execute a related business process.
[0224] After parsing and generating the coding information of the QR code, the client can send the coding information generated in step 530 to the server to query the server for a business address that has a mapping relationship with the coding information; if the server queries the business address mapped by the coding information, the server can return the queried business address to the client; and then the client can jump to the business address returned by the server to execute related business processes.
[0225] Of course, if the server fails to find the business address corresponding to the coded information, it can also return a query failure to the client; the client rescans and parses the query failure according to the server. For example, the user is prompted to rescan the QR code to obtain a clearer and more accurate QR code. Alternatively, after multiple failed queries for the same coded information, the client prompts the user that the QR code is incorrect.
[0226] After introducing the embodiment of the two-dimensional code parsing method with the client as the execution subject, the following introduces the embodiment of the two-dimensional code parsing method under multi-party interaction in combination with the client and the server. Figure 6 As shown, it may include:
[0227] Step 610: The client sends a QR code consisting of a stroke pattern to the server.
[0228] The client scans the QR code composed of the stroke pattern to send the QR code composed of the stroke pattern to the server.
[0229] Step 620: The server parses the QR code to determine the spatial position parameters of the stroke pattern constituting the QR code.
[0230] The server parses the QR code to obtain the spatial position parameters of each stroke pattern.
[0231] If the client scans the QR code and then parses the QR code locally, step 610 may be omitted and the process may start directly from step 620 , in which the client parses the QR code to determine the spatial position parameters of the stroke pattern constituting the QR code.
[0232] Step 630: The server generates coding information consisting of the spatial position parameters.
[0233] The server concatenates the horizontal coordinates, vertical coordinates, and rotation angles of the center points of each stroke pattern in the order of the detected stroke patterns, and can obtain the encoding information corresponding to the QR code.
[0234] If step 620 is performed by the client, step 630 may be performed in the client, and after generating the encoding information, the client also needs to send the encoding information to the server.
[0235] Step 640: The server searches for a business address that has a mapping relationship with the coding information.
[0236] Step 650: The server returns the service address to the client.
[0237] If the server finds a business address that has a mapping relationship with the coding information, it returns the business address to the client; if it does not find a business address that has a mapping relationship with the coding information, it returns a resolution failure prompt to the client.
[0238] Step 660: The client jumps to the business address to execute related business processes.
[0239] The client responds to the business address returned by the server and jumps to the business address to execute the relevant business process.
[0240] The QR code parsing method provided in this specification utilizes the spatial position parameters of the QR code stroke pattern to construct coding information, and establishes a mapping relationship between the coding information and the business address, thereby ensuring the recognition efficiency of the QR code while achieving QR code diversity, high recognition and security.
[0241] Figure 7 The structural block diagram of a two-dimensional code generation device is illustrated, and the two-dimensional code generation device corresponds to the aforementioned Figure 1 The embodiment of the method for generating a two-dimensional code is shown. Specifically, the device for generating a two-dimensional code may include: an acquisition unit 710, a generation unit 720, an encoding unit 730 and a mapping unit 740, specifically:
[0242] An acquisition unit 710 acquires a stroke pattern selected from a preset pattern;
[0243] A generating unit 720 combines the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern;
[0244] The encoding unit 730 obtains the spatial position parameters of each stroke pattern in the two-dimensional code and generates encoding information composed of the spatial position parameters.
[0245] In an exemplary embodiment, it also includes:
[0246] A mapping unit is used to establish a mapping relationship between the encoding information and the business address corresponding to the two-dimensional code.
[0247] In an exemplary embodiment, the generating unit 720 may further include:
[0248] Get the subunit and get the blank QR code base image;
[0249] Setting a subunit to respectively set positioning points in the areas where any three of the four corners of the two-dimensional code base map are located;
[0250] The placement subunit places the stroke pattern on the two-dimensional code base map according to a preset placement rule to generate a two-dimensional code composed of the stroke pattern.
[0251] In an exemplary embodiment, the placement subunit may further include:
[0252] For each selected stroke pattern, execute the following sub-units in sequence:
[0253] The calculation subunit initializes a random number, and generates the position coordinates and rotation angle of the stroke pattern placed in the two-dimensional code base map according to the random number;
[0254] The generating subunit places the stroke pattern on the two-dimensional code base map according to the position coordinates, and performs clockwise or counterclockwise rotation on the stroke pattern at the rotation angle.
[0255] In an exemplary embodiment, the calculation subunit is further used to initialize a horizontal random number, a vertical random number and a rotation random number; multiply the horizontal random number by the pixel value of the width of the two-dimensional code base image, and round down to obtain the horizontal coordinate; multiply the vertical random number by the pixel value of the height of the two-dimensional code base image; and round down to obtain the vertical coordinate; multiply the rotation random number by 360, and round down to obtain the rotation angle of the stroke pattern.
[0256] In an exemplary embodiment, the generating subunit is further used to set the coordinates of the center point of the stroke pattern as the horizontal coordinate and the vertical coordinate to place the stroke pattern on the QR code base map, and further rotate the stroke pattern clockwise or counterclockwise at the rotation angle based on the center point.
[0257] In an exemplary embodiment, the spatial position parameters include a horizontal coordinate, a vertical coordinate, and a rotation angle of the stroke pattern.
[0258] In an exemplary embodiment, after generating the subunit, the method further includes:
[0259] The checking subunit checks whether the rotated stroke pattern is abnormal; if there is an abnormality, the initial subunit is re-executed; if there is no abnormality, the initial subunit is executed for the next stroke pattern.
[0260] In an exemplary embodiment, the check subunit may further include:
[0261] Determine whether the rotated stroke pattern exceeds the range of the two-dimensional code base map; determine whether the rotated stroke pattern overlaps with the positioning point; if the rotated stroke pattern exceeds the range of the two-dimensional code base map, or overlaps with any positioning point, determine that an abnormality exists; if the rotated stroke pattern does not exceed the range of the two-dimensional code base map and does not overlap with any positioning point, determine that no abnormality exists.
[0262] In an exemplary embodiment, the generating unit 720 further includes: scaling the preset pattern to a preset size; placing the scaled preset pattern in the central area of the QR code base; wherein the center point of the scaled preset pattern coincides with the center point of the QR code base.
[0263] In an exemplary embodiment, the preset pattern includes a logo pattern, and the stroke pattern includes a stroke-related pattern obtained by splitting the logo pattern.
[0264] Figure 8 A structural block diagram of a two-dimensional code analysis device is illustrated, and the two-dimensional code analysis device corresponds to the aforementioned Figure 4 The embodiment of the method for parsing a two-dimensional code is shown. Specifically, the device for parsing a two-dimensional code may include: an acquisition unit 810 , a parsing unit 820 , an encoding unit 830 and a query unit 840 .
[0265] An acquisition unit 810 acquires a two-dimensional code composed of a stroke pattern to be parsed;
[0266] A parsing unit 820 is configured to parse the two-dimensional code and determine spatial position parameters of a stroke pattern constituting the two-dimensional code;
[0267] The encoding unit 830 generates encoding information consisting of the spatial position parameters.
[0268] In an exemplary embodiment, it also includes:
[0269] The query unit queries the business address that has a mapping relationship with the coding information, and jumps to the business address to execute related business processes.
[0270] In an exemplary embodiment, the parsing unit 820 may further include:
[0271] A detection subunit detects the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern using an image detection algorithm;
[0272] The determination subunit determines the position coordinates of each stroke pattern and the rotation angle of the stroke pattern as the spatial position parameters of the stroke pattern.
[0273] In an exemplary embodiment, before the detection subunit, the method further includes:
[0274] Detecting a preset pattern in a middle area of the QR code;
[0275] Obtaining a stroke pattern selected from the preset pattern during the generation of the QR code and using it as a verification pattern;
[0276] The detection subunit is further used to detect the stroke pattern matching the verification pattern in the two-dimensional code by using an image detection algorithm, and calculate the horizontal coordinate, vertical coordinate and rotation angle of the center point of each stroke pattern.
[0277] In an exemplary embodiment, when the detection subunit detects a stroke pattern in the QR code that matches the verification pattern, it is further used to perform contour detection on the QR code and detect positioning points in the QR code; and detect the stroke patterns in the QR code in sequence according to the positional relationship between the three detected positioning points.
[0278] In an exemplary embodiment, the encoding unit 830 is further used to splice the horizontal coordinates, vertical coordinates and rotation angle of the center point of each stroke pattern from front to back in the order of the detected stroke patterns to obtain encoding information.
[0279] In an exemplary embodiment, the preset pattern includes a logo pattern, and the stroke pattern includes a stroke-related pattern obtained by splitting the logo pattern.
[0280] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.
[0281] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.
[0282] like Fig. 9 As shown, Fig. 9 The hardware structure diagram of an electronic device according to an embodiment of the present specification is shown, and the device may include: a processor 1710, a memory 1720, an input / output interface 1730, a communication interface 1740, and a bus 1750. The processor 1710, the memory 1720, the input / output interface 1730, and the communication interface 1740 are connected to each other in communication within the device through the bus 1750.
[0283] The processor 1710 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification. The processor implements the above method by running executable instructions.
[0284] The memory 1720 for storing processor executable instructions can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1720 can store operating systems and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1720.
[0285] The input / output interface 1730 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0286] The communication interface 1740 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).
[0287] The bus 1750 includes a path that transmits information between the various components of the device (eg, the processor 1710, the memory 1720, the input / output interface 1730, and the communication interface 1740).
[0288] It should be noted that, although the above device only shows the processor 1710, the memory 1720, the input / output interface 1730, the communication interface 1740 and the bus 1750, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.
[0289] The embodiments of this specification also provide a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method for generating a two-dimensional code of any of the above embodiments is implemented.
[0290] Computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0291] The embodiments of this specification also provide a computer program product, which, when executed by a processor, is used to implement the method for generating a two-dimensional code described in any embodiment of this specification.
[0292] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0293] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0294] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0295] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A method for generating a two-dimensional code, characterized in that: The method comprises: Obtaining a stroke pattern selected from a preset pattern; Combining the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern; The spatial position parameters of each stroke pattern in the two-dimensional code are obtained, and coding information consisting of the spatial position parameters is generated.
2. The method according to claim 1, characterized in that The step of combining the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern comprises: Get a blank QR code base image; In the areas where any three of the four corners of the two-dimensional code base map are located, positioning points are respectively set; According to a preset placement rule, the stroke pattern is placed on the two-dimensional code base map to generate a two-dimensional code composed of the stroke pattern.
3. The method according to claim 2, characterized in that Placing the stroke pattern on the two-dimensional code base map according to a preset placement rule includes: For each selected stroke pattern, perform the following steps in sequence: Initialize a random number, and generate the position coordinates and rotation angle of the stroke pattern placed in the two-dimensional code base map according to the random number; The stroke pattern is placed on the two-dimensional code base map according to the position coordinates, and the stroke pattern is rotated clockwise or counterclockwise at the rotation angle.
4. The method according to claim 3, characterized in that The initialization of the random number and the generation of the position coordinates and rotation angle of the stroke pattern placed in the two-dimensional code base map according to the random number include: Initialize horizontal random number, vertical random number and rotation random number; Multiply the horizontal random number by the pixel value of the width of the two-dimensional code base image, and round down to obtain the horizontal coordinate; Multiply the vertical random number by the pixel value of the height of the two-dimensional code base map; and round down to obtain the vertical coordinate; The rotation random number is multiplied by 360 and rounded down to obtain the rotation angle of the stroke pattern.
5. The method according to claim 4, characterized in that Placing the stroke pattern on the two-dimensional code base map according to the position coordinates, and rotating the stroke pattern clockwise or counterclockwise at the rotation angle, includes: The coordinates of the center point of the stroke pattern are set as the horizontal coordinates and the vertical coordinates to place the stroke pattern on the two-dimensional code base map, and further rotate the stroke pattern clockwise or counterclockwise at the rotation angle based on the center point.
6. The method according to claim 3, characterized in that After rotating the stroke pattern clockwise or counterclockwise by the rotation angle, the method further includes: Checking whether the rotated stroke pattern is abnormal; If there is an exception, re-execute the step of initializing the random number; If there are no exceptions, the next stroke pattern is executed.
7. The method according to claim 6, characterized in that The checking whether the rotated stroke pattern is abnormal includes: Determine whether the rotated stroke pattern exceeds the range of the two-dimensional code base map; Determining whether the rotated stroke pattern overlaps with the positioning point; If the rotated stroke pattern exceeds the range of the two-dimensional code base map, or overlaps with any positioning point, it is determined that an abnormality exists; If the rotated stroke pattern does not exceed the range of the two-dimensional code base map and does not overlap with any positioning point, it is determined that there is no abnormality.
8. A method for parsing a two-dimensional code, characterized in that: The method comprises: Obtain a QR code consisting of a stroke pattern to be parsed; Parsing the two-dimensional code to determine the spatial position parameters of the stroke pattern constituting the two-dimensional code; Generate encoding information consisting of the spatial position parameters.
9. The method according to claim 8, characterized in that The step of parsing the two-dimensional code to determine the spatial position parameters of the stroke pattern constituting the two-dimensional code includes: Using an image detection algorithm, the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern are detected; The position coordinates of each stroke pattern and the rotation angle of the stroke pattern are determined as the spatial position parameters of the stroke pattern.
10. The method according to claim 9, characterized in that Before using the image detection algorithm to detect the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern, the method further includes: Detecting a preset pattern in a middle area of the QR code; Obtaining a stroke pattern selected from the preset pattern during the generation of the QR code and using it as a verification pattern; The method of using an image detection algorithm to detect the position coordinates of each stroke pattern in the two-dimensional code and the rotation angle of the stroke pattern includes: An image detection algorithm is used to detect the stroke patterns in the two-dimensional code that match the verification pattern, and the position coordinates of each stroke pattern and the rotation angle of the stroke pattern are calculated.
11. A device for generating a two-dimensional code, characterized in that: The device comprises: An acquisition unit, which acquires a stroke pattern selected from a preset pattern; A generating unit, combining the stroke pattern with a blank two-dimensional code base image to generate a two-dimensional code consisting of the stroke pattern; The encoding unit obtains the spatial position parameters of each stroke pattern in the two-dimensional code and generates encoding information composed of the spatial position parameters.
12. A two-dimensional code analysis device, characterized in that: The device comprises: An acquisition unit, which acquires a two-dimensional code composed of a stroke pattern to be parsed; A parsing unit, which parses the two-dimensional code to determine the spatial position parameters of the stroke pattern constituting the two-dimensional code; The encoding unit generates encoding information consisting of the spatial position parameters.
13. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 10 by running the executable instructions.
14. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the method as described in any one of claims 1 to 10 is implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.