Method, system and related device for generating encrypted two-dimensional code
By dividing the QR code into encryption modules, hollowing out the encryption and adjusting the grayscale value, and combining cryptographic algorithms and image feature analysis, the problem of easy copying of QR codes is solved, and efficient product authenticity identification is achieved.
Patent Information
- Application Number
- CN202510785563.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-10-10
AI Technical Summary
Existing QR codes are easy to copy, resulting in the proliferation of counterfeit QR codes, making it difficult to accurately identify the authenticity of goods, and affecting anti-counterfeiting work.
By dividing the initial QR code into a positioning area and a data area, and using a cryptographic algorithm to generate a hash function value for hollow encryption and grayscale value adjustment, a unique physical feature that depends on a specific algorithm is formed, and the recognition threshold is optimized by combining image feature analysis and machine learning.
The anti-copying ability and verification efficiency of the QR code have been improved, enabling consumers to accurately identify the authenticity of goods and enhancing anti-counterfeiting performance.
Smart Images

Figure CN120764569A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of two-dimensional codes, in particular to a method and system for generating encrypted two-dimensional codes and related devices. BACKGROUND
[0002] With the rapid development of information technology and the wide popularity of intelligent devices, two-dimensional codes, as a convenient data storage and transmission carrier, have been widely used in many fields such as product anti-counterfeiting, information tracing, and payment authentication. From daily consumer product labels to various types of information identification, two-dimensional codes have become an important bridge connecting the physical world and the digital world due to their simple encoding, large information storage capacity, and convenient reading.
[0003] In the prior art, the information to be stored, such as URLs, text, numbers, etc., is usually converted into a specific black and white matrix pattern using public encoding rules, i.e., ordinary two-dimensional codes. The generation process of these ordinary two-dimensional codes is relatively simple and does not require complex encryption processing. The data is stored in plaintext form in the pattern structure of the two-dimensional code. When the information needs to be read, the two-dimensional code image is identified and decoded by a scanning device to obtain the public encoded information contained therein. This implementation method is widely used due to its simplicity.
[0004] However, the current two-dimensional codes have the defect of being easy to copy, leading to a proliferation of counterfeit two-dimensional codes in the market. Since these two-dimensional codes contain public encoded information, attackers can easily obtain the content of these two-dimensional codes through simple methods such as scanning or taking pictures and copy them, or even generate two-dimensional codes that look exactly the same and point to malicious links or fake content. This copying and counterfeiting behavior can seriously endanger social safety and make it difficult for consumers to accurately identify the authenticity of products through two-dimensional codes, posing a significant challenge to anti-counterfeiting efforts. SUMMARY
[0005] To solve the above technical problems, the present application provides a method and system for generating encrypted two-dimensional codes and related devices.
[0006] The technical solutions provided in the present application are described as follows: The first aspect of the present application provides a method for generating encrypted two-dimensional codes, comprising: generating an initial two-dimensional code based on user text requirements, the initial two-dimensional code including a positioning area and a data area; dividing the initial two-dimensional code into multiple modules and identifying the modules that include the data area and do not include the positioning area as encryption modules; generating a first hash function value using a preset cryptographic algorithm and performing hollow encryption processing on the corresponding black pixel points in the encryption modules according to the first hash function value; identify the black pixel points in a preset range around the black pixel points after the hollow encryption processing as a print sensitive area; generate a second hash function value using the preset cryptographic algorithm, and change the gray value of the black pixel points of the print sensitive area according to the second hash function value to obtain an encrypted two-dimensional code.
[0007] Optionally, after obtaining the encrypted two-dimensional code, the method further comprises: setting an initial threshold based on the encrypted two-dimensional code, and optimizing the initial threshold using a preset classification model to obtain a target recognition threshold, so as to realize high-precision recognition of the encrypted two-dimensional code.
[0008] Optionally, the step of setting an initial threshold based on the encrypted two-dimensional code, and optimizing the initial threshold using a preset classification model to obtain a target recognition threshold comprises: analyzing the image characteristics of the encrypted two-dimensional code, and determining a verification index according to the image characteristics; obtaining test images of the encrypted two-dimensional code under multiple scenarios, the test images comprising an encrypted two-dimensional code printed image, an encrypted two-dimensional code photographed image, and an encrypted two-dimensional code scanned image; calculating the test images based on the verification index to obtain index data of the test images; setting an initial threshold of the verification index according to the index data, and inputting the test images into a preset classification model for training to obtain a target classification model; optimizing the initial threshold of the target classification model to obtain a target recognition threshold.
[0009] Optionally, the initial threshold of the verification index comprises a hollow pixel loss rate, a black pixel inconsistency rate, a print sensitive feature gray scale distribution, and a high frequency noise proportion.
[0010] Optionally, the step of calculating the test images based on the verification index to obtain index data of the test images comprises: calculating index data of the encrypted two-dimensional code printed image, the encrypted two-dimensional code photographed image, and the encrypted two-dimensional code scanned image based on the verification index, the index data comprising a print index, a photographed index, and a scanned index; wherein the print index comprises the hollow pixel loss rate, the black pixel inconsistency rate, the print sensitive feature gray scale mean value, the print sensitive feature gray scale standard deviation, and the high frequency noise proportion of the encrypted two-dimensional code printed image; The photographing indicators are the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray mean value, the printing sensitive feature gray standard deviation, and the high-frequency noise proportion of the encrypted two-dimensional code photographing image. The scanning indicators are the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray mean value, the printing sensitive feature gray standard deviation, and the high-frequency noise proportion of the encrypted two-dimensional code scanning image.
[0011] Optionally, the initial threshold of the verification indicator is set according to the indicator data, and the test image is input into a preset classification model for training to obtain a target classification model, including: A preset visualization library is introduced, and an indicator distribution map is generated according to the printing indicators, the photographing indicators, and the scanning indicators. The feature differences of the printing indicators, the photographing indicators, and the scanning indicators are analyzed through the indicator distribution map, and the initial threshold of the verification indicator is set according to the feature differences. The test image is divided into a training image set and a verification image set, and the training image set is input into a preset classification model for training. The threshold of the verification image set is obtained by using the trained preset classification model to perform threshold prediction on the verification image set. The false recognition rate and the missed recognition rate of the threshold of the verification data set are calculated using a preset loss function, and the trained preset classification model is optimized according to the false recognition rate and the missed recognition rate to obtain a target classification model.
[0012] Optionally, the encrypted module includes at most one black pixel point processed by hollow encryption.
[0013] The second aspect of the present application provides a system for generating an encrypted two-dimensional code, the system comprising: A generation unit configured to generate an initial two-dimensional code based on a user text requirement, the initial two-dimensional code including a positioning area and a data area; A first identification unit configured to divide the initial two-dimensional code into a plurality of modules and identify the modules including the data area and excluding the positioning area as encrypted modules; A processing unit configured to generate a first hash function value using a preset cryptographic algorithm and perform hollow encryption processing on corresponding black pixel points in the encrypted modules according to the first hash function value; A second identification unit configured to identify the black pixel points within a preset range around the hollow-encrypted black pixel points as printing sensitive areas; The changing unit is configured to generate a second hash function value by using the preset cryptographic algorithm, and change the gray value of the black pixel point of the print-sensitive area according to the second hash function value to obtain an encrypted two-dimensional code.
[0014] Optionally, the method further comprises an optimization unit, which is specifically configured to: setting an initial threshold based on the encrypted two-dimensional code, and optimizing the initial threshold by using a preset classification model to obtain a target recognition threshold, so as to realize high-precision recognition of the encrypted two-dimensional code.
[0015] Optionally, the optimization unit is specifically configured to: analyze image characteristics of the encrypted two-dimensional code, and determine a verification index according to the image characteristics; obtain test images of the encrypted two-dimensional code in multiple scenes, wherein the test images include an encrypted two-dimensional code printing image, an encrypted two-dimensional code photographing image, and an encrypted two-dimensional code scanning image; calculate the test images based on the verification index to obtain index data of the test images; set an initial threshold of the verification index according to the index data, and input the test images into a preset classification model for training to obtain a target classification model; optimize the initial threshold by using the target classification model to obtain a target recognition threshold.
[0016] Optionally, the initial threshold of the verification index includes a hollow pixel loss rate, a black pixel inconsistency rate, a print-sensitive feature gray value distribution, and a high-frequency noise proportion.
[0017] Optionally, the optimization unit is specifically configured to: calculate index data of the encrypted two-dimensional code printing image, the encrypted two-dimensional code photographing image, and the encrypted two-dimensional code scanning image based on the verification index, wherein the index data includes a printing index, a photographing index, and a scanning index; wherein the printing index is the hollow pixel loss rate, the black pixel inconsistency rate, a print-sensitive feature gray value mean, a print-sensitive feature gray value standard deviation, and the high-frequency noise proportion of the encrypted two-dimensional code printing image; wherein the photographing index is the hollow pixel loss rate, the black pixel inconsistency rate, the print-sensitive feature gray value mean, the print-sensitive feature gray value standard deviation, and the high-frequency noise proportion of the encrypted two-dimensional code photographing image; wherein the scanning index is the hollow pixel loss rate, the black pixel inconsistency rate, the print-sensitive feature gray value mean, the print-sensitive feature gray value standard deviation, and the high-frequency noise proportion of the encrypted two-dimensional code scanning image.
[0018] Optionally, the optimization unit is specifically configured to: introducing a preset visualization library and generating an index distribution map according to the printing index, the photographing index and the scanning index; analyzing feature differences between the printing index and the photographing index and the scanning index through the index distribution map, and setting an initial threshold value of the verification index according to the feature differences; dividing the test image into a training image set and a verification image set, and inputting the training image set into a preset classification model for training; using the trained preset classification model to perform threshold prediction on the verification image set to obtain a threshold value of the verification data set; using a preset loss function to calculate a false recognition rate and a missed recognition rate of the threshold value of the verification data set, and optimizing the trained preset classification model according to the false recognition rate and the missed recognition rate to obtain a target classification model.
[0019] Optionally, the encryption module includes at most one hollowed-out encrypted black pixel point.
[0020] The third aspect of the present application provides a device for generating an encrypted two-dimensional code, the device comprising: a processor, a memory, an input-output unit and a bus; the processor is connected with the memory, the input-output unit and the bus; the memory stores a program, and the processor calls the program to execute the first aspect and any optional method for generating an encrypted two-dimensional code in the first aspect.
[0021] The fourth aspect of the present application provides a computer-readable storage medium, the computer-readable storage medium stores a program, and the program executes the first aspect and any optional method for generating an encrypted two-dimensional code in the first aspect when executed on a computer.
[0022] As can be seen from the above technical solutions, the embodiments of the present application have the following advantages: The application realizes the improvement of the encryption and anti-counterfeiting performance of the two-dimensional code by performing encryption module division, hollow encryption and gray value adjustment on the data area of the initial two-dimensional code. First, the initial two-dimensional code is divided into a positioning area and a data area, and only the encryption modules of the data area are processed, which not only ensures the basic identification function of the two-dimensional code, but also encrypts the key information area, so that the attacker cannot directly obtain the plaintext data in the two-dimensional code. Subsequently, a first hash function value is generated using a preset cryptographic algorithm, the black pixel points of the encryption module are hollowed and encrypted by the first hash function value, and a second hash function value is generated using a preset cryptographic algorithm, and the gray value of the printing sensitive area around the hollowed pixel is modified by the second hash function value. This combination of cryptographic algorithms and physical feature modification can make the encrypted two-dimensional code form a unique physical feature that depends on a specific algorithm, and the copy will be difficult to accurately restore the hollow precision and gray distribution of the encrypted two-dimensional code, and will be identified as a counterfeit two-dimensional code when scanning due to the mismatch of the features.
[0023] The entire encryption process binds the data encryption and the physical features through the hash function, avoids the easy copying problem of ordinary two-dimensional codes, improves the anti-copying capability and verification efficiency of the two-dimensional code in the anti-counterfeiting scene, and enables consumers to accurately distinguish the authenticity of the goods through the encrypted two-dimensional code. BRIEF DESCRIPTION OF DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0025] Figure 1 An embodiment flowchart of the method for generating an encrypted two-dimensional code provided by the present application is shown in the figure. Figure 2 Another embodiment flowchart of the method for generating an encrypted two-dimensional code provided by the present application is shown in the figure. Figure 3 An embodiment structure diagram of the system for generating an encrypted two-dimensional code provided by the present application is shown in the figure. Figure 4 An embodiment structure diagram of the device for generating an encrypted two-dimensional code provided by the present application is shown in the figure. DETAILED DESCRIPTION
[0026] The present application provides a method for generating an encrypted two-dimensional code, which can improve the anti-counterfeiting effect of the two-dimensional code. It should be noted that the method for generating an encrypted two-dimensional code of the present application is applied to a terminal.
[0027] It should be noted that the method, device and related device for generating an encrypted two-dimensional code provided in the present application can be applied to a terminal and can also be applied to a system, and can also be applied to a server. For example, the terminal can be a smart phone or a computer, a tablet computer, a smart television, a smart watch, a portable computer terminal, or a fixed terminal such as a desktop computer. For the convenience of description, the terminal is taken as an execution subject for illustration in the present application.
[0028] Please refer to Figure 1 The present application first provides an embodiment of a method for generating an encrypted two-dimensional code, which comprises the following steps: S101, generating an initial two-dimensional code based on a user text requirement, the initial two-dimensional code comprising a positioning area and a data area; In this embodiment, the initial two-dimensional code is generated based on the user text requirement. First, the user text is processed, and then the QrCode library for generating two-dimensional codes is used to configure the parameters for outputting a black-and-white image. The QrCode library is a cross-language tool library for generating two-dimensional codes. Subsequently, error correction codes are generated by Reed-Solomon (error correction coding based on algebraic geometry and finite field theory) to ensure that the initial two-dimensional code has high error correction capability, and at the same time, the user's text requirement is converted into binary and laid out according to the standard, including positioning patterns and format information, etc., so as to generate an initial two-dimensional code containing a positioning area and a data area.
[0029] It should be noted that the generation process of the initial two-dimensional code follows the standard generation rules of two-dimensional codes, so that the generated initial two-dimensional code can accurately store user text information and has a certain anti-interference capability, providing a basis for subsequent encryption processing.
[0030] S102, dividing the initial two-dimensional code into a plurality of modules, and identifying a module comprising a data area and not comprising a positioning area as an encryption module; In this embodiment, the generated initial two-dimensional code is divided into a plurality of modules, and the module division is according to the 21x21 module division rule. After the division is completed, each module is identified, and modules that include a data area but do not include a positioning area are selected as encryption modules.
[0031] Specifically, the identification of the module comprising the data area and not comprising the positioning area is based on the structure of the initial two-dimensional code. The positioning area is mainly used for positioning and identification of the two-dimensional code, and needs to maintain the stability and integrity of the two-dimensional code, while the data area is the key part for storing user text information and needs to be encrypted and protected.
[0032] S103, generating a first hash function value using a preset cryptographic algorithm, and performing hollow encryption processing on the corresponding black pixel points in the encryption module according to the first hash function value; In this embodiment, a preset cryptographic algorithm is used to generate the first hash function value. The preset cryptographic algorithm in the first hash function value is SHA-256 hash algorithm. The seed of the generated first hash function value is calculated based on the text, the encryption key, the constraint condition, and the date. The encryption key, the constraint condition, and the date are determined by actual needs, which are not limited here.
[0033] The first hash function value is represented by the following formula: ; wherein, represents the seed, represents the text, represents the encryption key, represents the constraint condition, represents the date.
[0034] After the first hash function value is generated, the corresponding black pixel points in the encryption module are hollowed out and encrypted. In the processing process, the black pixel points are located by the Python numpy (image processing) library, and the key areas such as the positioning area are further excluded. Then, the random selection algorithm of random.sample is used to determine the black pixel points that need to be hollowed out, and these black pixel points are set to white, thereby forming the encryption feature.
[0035] The random selection algorithm of random.sample is an algorithm for randomly selecting elements without repetition from a specified sequence. It ensures that each element has an equal probability of being selected and does not repeat the selection of the same element. It is commonly used in scenarios that require random sampling and require unique samples, such as random number generation in cryptography, data sampling, etc.
[0036] Specifically, the hollowing-out processing utilizes the irreversibility and randomness of the cryptographic algorithm to control the selection and distribution of the hollowed-out pixel points through the first hash function value, so that the two-dimensional code after hollowing-out and encryption processing has unique encryption features and is difficult to be easily copied and forged.
[0037] In S104, the black pixel points within a preset range around the black pixel points after hollowing-out and encryption processing are identified as the print-sensitive area. In this embodiment, after the black pixel points in the encryption module are hollowed out and encrypted, the black pixel points within a preset range around these black pixel points after hollowing-out and encryption processing are identified, and the black pixel points within the preset range are determined as the print-sensitive area. The preset range is a specific pixel distance, such as a certain range around the hollowed-out pixel point as the center.
[0038] In the identification process, the position of the hollowed-out pixel points is determined by the numpy library, and based on the position of the hollowed-out pixel points, a predetermined range of the periphery is delimited, and the black pixel points within the range are identified as the printing sensitive area.
[0039] S105, using a preset cryptographic algorithm to generate a second hash function value, and changing the gray value of the black pixel points in the printing sensitive area according to the second hash function value to obtain an encrypted two-dimensional code.
[0040] In this embodiment, a second hash function value is generated using a preset cryptographic algorithm, and then the gray value of the black pixel points in the printing sensitive area is changed according to the generated second hash function value, thereby obtaining an encrypted two-dimensional code.
[0041] In the process of changing the gray value, the numpy library is used to locate the black pixel points in the printing sensitive area, and then these black pixel points are changed to a small gray value, wherein the gray value ranges from 10 to 15, for example, the gray value of these black pixel points is 0, and the gray value of these black pixel points after changing is 15. At the same time, it is necessary to ensure that the changed gray value does not cover the white area in the two-dimensional code.
[0042] Specifically, the change operation mainly utilizes the randomness and uniqueness of the cryptographic algorithm, and controls the change mode and distribution of the gray value of the black pixel points in the printing sensitive area through the second hash function value, to form unique printing sensitive features. These features, combined with the hollowed-out encryption features, further enhance the encryption and anti-counterfeiting performance of the two-dimensional code.
[0043] This embodiment realizes the improvement of two-dimensional code encryption and anti-counterfeiting performance by encrypting the data area of the initial two-dimensional code, dividing the encryption module, hollowing out the encryption, and adjusting the gray value. First, the initial two-dimensional code is divided into a positioning area and a data area, and only the encryption module of the data area is processed, which not only ensures the basic identification function of the two-dimensional code, but also encrypts the key information area specifically, so that attackers cannot directly obtain the plaintext data in the two-dimensional code. Subsequently, a first hash function value is generated using a preset cryptographic algorithm, the black pixel points of the encryption module are hollowed out by the first hash function value, and a second hash function value is generated using a preset cryptographic algorithm, the gray value of the printing sensitive area around the hollowed-out pixel is modified by the second hash function value. This combination of cryptographic algorithms and physical feature modification can make the encrypted two-dimensional code form a unique physical feature that depends on a specific algorithm, and the copy will be difficult to accurately restore the encryption accuracy and gray distribution of the hollowed-out, and will be identified as a counterfeit two-dimensional code when scanning due to the mismatch of the features.
[0044] The entire encryption process binds the data encryption with the physical characteristics through the hash function, avoids the easy copying problem of the ordinary two-dimensional code, improves the anti-copying capability and verification efficiency of the two-dimensional code in the anti-counterfeiting scene, and enables the consumer to accurately identify the authenticity of the product through the encrypted two-dimensional code.
[0045] Please refer to Figure 2 The application also provides another embodiment of a method for generating an encrypted two-dimensional code, which comprises the following steps: S201, generating an initial two-dimensional code based on a user text requirement, the initial two-dimensional code comprising a positioning area and a data area; S202, dividing the initial two-dimensional code into a plurality of modules, and identifying a module comprising the data area and not comprising the positioning area as an encryption module; S203, generating a first hash function value using a preset cryptographic algorithm, and performing hollow encryption processing on the corresponding black pixel points in the encryption module according to the first hash function value; S204, identifying the black pixel points within a preset range around the black pixel points after the hollow encryption processing as a printing sensitive area; S205, generating a second hash function value using a preset cryptographic algorithm, and changing the gray value of the black pixel points in the printing sensitive area according to the second hash function value to obtain an encrypted two-dimensional code.
[0046] In the embodiment, steps S201 to S205 are similar to steps S101 to S105 of the foregoing embodiment, and will not be described here again.
[0047] S206, analyzing the image characteristics of the encrypted two-dimensional code, and determining a verification index according to the image characteristics; In the embodiment, the analysis of the image characteristics in the encrypted two-dimensional code is mainly performed through the numpy library and the scipy.fftpack library, and then the verification index is calculated according to the image characteristics, wherein the verification index comprises a hollow pixel loss rate, a black pixel inconsistency rate, a printing sensitive feature gray mean value, a printing sensitive feature gray standard deviation, and a high-frequency noise proportion.
[0048] Specifically, the scipy.fftpack library is a tool library for fast Fourier transform in Python, which can convert time domain signals into frequency domain representation and is used for analyzing the frequency components of signals. The scipy.fftpack library provides an efficient Fourier transform algorithm in the embodiment, which can process one-dimensional, two-dimensional and multi-dimensional data, and is widely used in the fields of image processing, signal analysis and noise filtering, and quickly extracts the image characteristics in the encrypted two-dimensional code.
[0049] Specifically, the hollow pixel loss rate is the proportion of hollow pixel points in the encrypted two-dimensional code lost in the copying or identification process, used to measure the integrity of the encryption features of the two-dimensional code, and a high hollow pixel loss rate indicates that the two-dimensional code is a copy or is damaged; the black pixel inconsistency rate refers to the difference between the actual distribution of black pixel points in the encrypted two-dimensional code and the original standard distribution, reflecting the consistency of the black pixel points; the printing sensitive feature gray mean value and the printing sensitive feature gray standard deviation represent the average level of the gray value of the encrypted two-dimensional code and the dispersion degree of the gray value of the encrypted two-dimensional code, respectively, used to judge the stability of the gray feature of the printing sensitive area; and the high-frequency noise ratio is the proportion of high-frequency noise in the encrypted two-dimensional code image, and high-frequency noise is mostly introduced by copying methods such as photographing and scanning, so a high high-frequency noise ratio indicates that the two-dimensional code is most likely a copy rather than an original printed product.
[0050] By analyzing the characteristics of the encrypted two-dimensional code image to determine the verification index, a scientific anti-counterfeiting verification system is constructed. The verification index covers the core physical features of the encrypted two-dimensional code, so that the authenticity verification is upgraded from simple data decoding to multi-dimensional feature detection, improving the accuracy and reliability of the anti-counterfeiting verification, and effectively solving the defect that the original and the copy cannot be distinguished in the prior art.
[0051] S207, acquiring test images of the encrypted two-dimensional code in multiple scenes, the test images including encrypted two-dimensional code printing images, encrypted two-dimensional code photographing images, and encrypted two-dimensional code scanning images; In this embodiment, test images of the encrypted two-dimensional code in multiple scenes are acquired, wherein the test images of the encrypted two-dimensional code include printing images generated using actual printing equipment, photographing images taken by different light, angle or equipment, and scanning images obtained by different resolution scanners.
[0052] Specifically, data acquisition technology is used to simulate actual application scenarios using multiple devices, collect image data in different scenarios, and label the image source and basic information. The images in different scenarios contain actual interference factors such as light changes, device differences, and physical wear, for example, encrypted two-dimensional code photographing images can reflect the performance of the two-dimensional code when scanned by a mobile device, and encrypted two-dimensional code scanning images can reflect the identification in an industrial scenario. In this way, the verification bias caused by a single test scene can be avoided, the threshold setting is more universal, and the identification robustness and anti-counterfeiting reliability of the encrypted two-dimensional code in complex environments are improved.
[0053] S208, calculating index data of the encrypted two-dimensional code printing images, the encrypted two-dimensional code photographing images, and the encrypted two-dimensional code scanning images based on the verification index, the index data including printing indexes, photographing indexes, and scanning indexes; In this embodiment, based on the determined verification indicators, the indicator data of the encrypted two-dimensional code printed image, the encrypted two-dimensional code photographed image and the encrypted two-dimensional code scanned image are calculated respectively. The encrypted two-dimensional code printed image, the encrypted two-dimensional code photographed image and the encrypted two-dimensional code scanned image are analyzed and calculated by the numpy library to obtain the indicator data, which includes the printing indicator, the photographing indicator and the scanning indicator.
[0054] Specifically, the image characteristics are mainly converted into comparable numerical type indicator data by using quantitative calculation method, and the source authenticity of the encrypted two-dimensional code printed image, the encrypted two-dimensional code photographed image and the encrypted two-dimensional code scanned image is distinguished by the differences of different scene indicators.
[0055] Further, the printing indicator is the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray mean value, the printing sensitive feature gray standard deviation and the high frequency noise proportion of the encrypted two-dimensional code printed image; the photographing indicator is the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray mean value, the printing sensitive feature gray standard deviation and the high frequency noise proportion of the encrypted two-dimensional code photographed image; and the scanning indicator is the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray mean value, the printing sensitive feature gray standard deviation and the high frequency noise proportion of the encrypted two-dimensional code scanned image.
[0056] The printing indicator of the encrypted two-dimensional code printed image will be used as a typical value to provide a data comparison basis for the subsequent feature difference analysis of the encrypted two-dimensional code printed image, the encrypted two-dimensional code photographed image and the encrypted two-dimensional code scanned image. The typical value of the hollow pixel loss rate is usually less than 0.2, the typical value of the black pixel inconsistency rate is usually less than 0.2, the printing sensitive feature gray mean value is usually in the interval of 10 to 30, the printing sensitive feature gray standard deviation is usually less than 10, and the high frequency noise proportion is usually less than 0.5.
[0057] S209, introducing a preset visualization library and generating an indicator distribution map according to the printing indicator, the photographing indicator and the scanning indicator; In this embodiment, the abstract indicator data is converted into intuitive graphics by using data visualization technology, so that the distribution differences and overlapping areas of different scene indicators can be observed, and the visualization basis for subsequent threshold analysis is provided. First, a preset visualization library is introduced, which can be a matplotlib library. The obtained printing indicator, photographing indicator and scanning indicator are visualized by the preset visualization library to generate an indicator distribution map. The indicator distribution map can be a histogram, a box plot or a line chart which can display the distribution range, mean value and standard deviation characteristics of various indicators.
[0058] The visualization chart can clearly present the index distribution difference between the encrypted two-dimensional code printed image and the encrypted two-dimensional code photographed image and the encrypted two-dimensional code scanned image, and can quickly locate the feature difference points of the encrypted two-dimensional code photographed image and the encrypted two-dimensional code scanned image.
[0059] In S210, the feature differences between the printing index, the photographing index and the scanning index are analyzed through the index distribution chart, and the initial threshold of the verification index is set according to the feature differences. In the embodiment, the threshold optimization method in statistical analysis and machine learning is mainly used to establish a distinguishing boundary based on the index distribution feature differences, so as to realize the quantitative judgment of the two-dimensional code authenticity. Specifically, the feature differences between the printing index, the photographing index and the scanning index are compared and analyzed through the index distribution chart generated by the above steps. According to these feature differences, the initial threshold of the verification index that can maximize the distinction between the original and the copy is determined by combining the ROC curve or the recall rate curve.
[0060] The ROC curve or the recall rate curve is a curve that draws the relationship between the true positive rate and the false positive rate (ROC) or the accuracy and the recall rate, which can help to determine the optimal threshold and balance the misrecognition rate and the missed recognition rate.
[0061] In S211, the test image is divided into a training image set and a verification image set, and the training image set is input into a preset classification model for training. In the embodiment, the test images of multiple scenes obtained are divided into a training image set and a verification image set, and the division method follows the machine learning data processing specification, for example, randomly allocated according to a 7:3 ratio. Then, the training image set is input into a preset classification model, and the preset classification model is trained based on the verification index of the image.
[0062] During the training, the preset classification model learns the index feature differences between the encrypted two-dimensional code printed image and the non-printed image, and establishes a classification decision boundary. The trained preset classification model can automatically learn the feature rules of different scene images, avoiding the subjectivity of manual threshold setting.
[0063] In S212, the trained preset classification model is used to predict the threshold of the verification image set, and the threshold of the verification data set is obtained. In the embodiment, the feature mapping ability of the trained preset classification model to the verification image set is mainly used to realize the automatic derivation from the index data to the threshold judgment, further avoiding the artificial experience deviation.
[0064] First, the trained preset classification model is used to process the verification image set, and after processing, the preset classification model calculates the output prediction threshold based on the verification index data of the verification image set. The threshold predicted by the trained preset classification model can dynamically adapt to the distribution of the verification set data, for example, when the noise proportion in the verification set is generally high, the preset classification model will automatically adjust the noise proportion threshold to improve the recognition accuracy. This data-driven threshold prediction method is more flexible and adaptable than fixed threshold.
[0065] S213, calculate the false recognition rate and the missed recognition rate of the threshold value of the verification data set using the preset loss function, and optimize the trained preset classification model according to the false recognition rate and the missed recognition rate to obtain a target classification model.
[0066] In this embodiment, a preset loss function, such as a cross-entropy loss function, a mean square error function, etc., is introduced to calculate the false recognition rate and the missed recognition rate of the threshold value of the verification data set. The trained preset classification model is optimized according to the false recognition rate and the missed recognition rate, and the parameters of the trained preset classification model are adjusted by gradient descent algorithm to reduce the loss function value, so as to minimize the false recognition rate and the missed recognition rate of the preset classification model, thereby obtaining a target classification model.
[0067] The preset classification model optimization process takes the false recognition rate and the missed recognition rate as the core target, and can specifically solve the difficulties of "false scanning of counterfeit codes" and "missing detection of real codes" in the prior art. For example, when the false recognition rate of the preset classification model for the photographed image is too high, the optimization will enhance the sensitivity of the preset classification model to the high-frequency noise proportion; if the missed recognition rate is high, the tolerance of the preset classification model to the printing sensitive features will be adjusted. This quantitative optimization makes the target classification model more accurate in distinguishing true and false, provides a high-reliability model basis for the generation of subsequent target recognition threshold, and further improves the practical value of the encrypted two-dimensional code anti-counterfeiting.
[0068] S214, the target recognition threshold is obtained by optimizing the initial threshold value of the target classification model to realize high-precision recognition of the encrypted two-dimensional code.
[0069] In this embodiment, the initial threshold value is iteratively optimized using the optimized target classification model. The target classification model finds the threshold point that minimizes the false recognition rate and the missed recognition rate near the initial threshold value based on the mapping relationship between the verification index and the image true and false label, and obtains the target recognition threshold. For example, the target classification model optimizes the hollow loss rate threshold in the initial threshold value from 0.2 to 0.18 to balance the true and false recognition accuracy.
[0070] The initial threshold value is optimized by the target classification model to obtain a target recognition threshold value, so that high-precision recognition of the encrypted two-dimensional code is realized. The target recognition threshold value has better data adaptability than the initial threshold value, can accurately distinguish between original printed matter and copies, can maintain low false recognition rate and missed recognition rate in different scenes, improves the reliability of user judgment of the two-dimensional code, and effectively blocks the circulation risk of counterfeit two-dimensional codes.
[0071] The system for generating an encrypted two-dimensional code provided in the present application will be described in detail below. Please refer to Figure 3 , Figure 3 An embodiment of the system for generating an encrypted two-dimensional code provided in the present application includes: The generating unit 301 is configured to generate an initial two-dimensional code based on user text requirements, and the initial two-dimensional code includes a positioning area and a data area. The first identification unit 302 is configured to divide the initial two-dimensional code into a plurality of modules, and identify a module including the data area and not including the positioning area as an encryption module. The processing unit 303 is configured to generate a first hash function value using a preset cryptographic algorithm, and perform hollow encryption processing on corresponding black pixel points in the encryption module according to the first hash function value. The second identification unit 304 is configured to identify black pixel points within a preset range around the black pixel points after the hollow encryption processing as a printing sensitive area. The changing unit 305 is configured to generate a second hash function value using a preset cryptographic algorithm, and change the gray value of the black pixel points in the printing sensitive area according to the second hash function value to obtain an encrypted two-dimensional code.
[0072] Optionally, the system further includes an optimization unit 306, which is specifically configured to: Set an initial threshold value based on the encrypted two-dimensional code, and optimize the initial threshold value using a preset classification model to obtain a target recognition threshold value, so as to realize high-precision recognition of the encrypted two-dimensional code.
[0073] Optionally, the optimization unit 306 is specifically configured to: Analyze the image characteristics of the encrypted two-dimensional code, and determine a verification index according to the image characteristics. Obtain test images of the encrypted two-dimensional code in multiple scenes, and the test images include encrypted two-dimensional code printed images, encrypted two-dimensional code photographed images, and encrypted two-dimensional code scanned images. Calculate the test images based on the verification index to obtain index data of the test images. Set an initial threshold value of the verification index according to the index data, and input the test images into a preset classification model for training to obtain a target classification model. Optimize the initial threshold value by the target classification model to obtain a target recognition threshold value.
[0074] Optionally, the initial threshold of the verification index includes the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray scale distribution, and the high frequency noise proportion.
[0075] Optionally, the optimization unit 306 is specifically configured to: based on the verification index, calculate index data of the encrypted two-dimensional code printing image, the encrypted two-dimensional code photographed image, and the encrypted two-dimensional code scanned image, the index data including printing indexes, photographed indexes, and scanned indexes; The printing indexes are the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray scale mean value, the printing sensitive feature gray scale standard deviation, and the high frequency noise proportion of the encrypted two-dimensional code printing image. The photographed indexes are the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray scale mean value, the printing sensitive feature gray scale standard deviation, and the high frequency noise proportion of the encrypted two-dimensional code photographed image. The scanned indexes are the hollow pixel loss rate, the black pixel inconsistency rate, the printing sensitive feature gray scale mean value, the printing sensitive feature gray scale standard deviation, and the high frequency noise proportion of the encrypted two-dimensional code scanned image.
[0076] Optionally, the optimization unit 306 is specifically configured to: introduce a preset visualization library and generate an index distribution map according to the printing indexes, the photographed indexes, and the scanned indexes; analyze the feature differences between the printing indexes and the photographed indexes and the scanned indexes through the index distribution map, and set the initial threshold of the verification index according to the feature differences; divide the test image into a training image set and a verification image set, and input the training image set into a preset classification model for training; use the trained preset classification model to perform threshold prediction on the verification image set to obtain the threshold of the verification data set; use a preset loss function to calculate the false recognition rate and the missed recognition rate of the threshold of the verification data set, optimize the trained preset classification model according to the false recognition rate and the missed recognition rate, and obtain a target classification model.
[0077] Optionally, the encryption module includes at most one hollow-encrypted black pixel point. For specific implementation manners, refer to Figure 1 - Figure 2 Embodiment, this time do not repeat.
[0078] The application also provides a device for generating an encrypted two-dimensional code. Please refer to Figure 4 , Figure 4 An embodiment of the device for generating an encrypted two-dimensional code provided by the application includes: a processor 401, a memory 402, an input / output unit 403, and a bus 404; The processor 401 is connected with the memory 402, the input and output unit 403 and the bus 404; The memory 402 stores a program, and the processor 401 invokes the program to execute any one of the above methods for generating an encrypted two-dimensional code.
[0079] The application also relates to a computer readable storage medium, and the computer readable storage medium stores a program, and the program is characterized in that when the program runs on a computer, the program causes the computer to execute any one of the above methods for generating an encrypted two-dimensional code.
[0080] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, and will not be described here.
[0081] In the several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic. The division of the units is only a logical function division. There can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between the units can be indirect couplings or communication connections through some interfaces, devices or units, and can be electrical, mechanical or in other forms.
[0082] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, can be located in one place, or can be distributed on a plurality of network units. According to actual needs, some or all of the units can be selected to achieve the purpose of the embodiment.
[0083] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0084] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
Claims
1. A method for generating an encrypted QR code, characterized in that: include: Generate an initial QR code based on the user's text requirements, the initial QR code including a positioning area and a data area; Divide the initial QR code into multiple modules, and identify the module including the data area and excluding the positioning area as an encryption module; Generate a first Hash function value using a preset cryptographic algorithm, and perform hollow encryption processing on corresponding black pixels in the encryption module according to the first Hash function value; Identify the black pixel points within a preset range around the black pixel points after hollowing out and encryption as printing sensitive areas; A second hash function value is generated using the preset cryptographic algorithm, and the grayscale value of the black pixel point in the printing sensitive area is changed according to the second hash function value to obtain an encrypted two-dimensional code.
2. The method according to claim 1, characterized in that After obtaining the encrypted QR code, the method further includes: An initial threshold is set based on the encrypted two-dimensional code, and the initial threshold is optimized using a preset classification model to obtain a target recognition threshold, so as to achieve high-precision recognition of the encrypted two-dimensional code.
3. The method according to claim 2, characterized in that The initial threshold is set based on the encrypted QR code, and the initial threshold is optimized using a preset classification model to obtain a target recognition threshold, including: Analyzing image characteristics of the encrypted QR code and determining a verification indicator based on the image characteristics; Acquire test images of the encrypted QR code in multiple scenarios, the test images including a printed image of the encrypted QR code, a photographed image of the encrypted QR code, and a scanned image of the encrypted QR code; Calculating the test image based on the verification index to obtain index data of the test image; Setting an initial threshold value of the verification indicator according to the indicator data, and inputting the test image into a preset classification model for training to obtain a target classification model; The target classification model is optimized by optimizing the initial threshold to obtain a target recognition threshold.
4. The method according to claim 3, characterized in that The initial thresholds of the verification indicators include hollow pixel loss rate, black pixel inconsistency rate, printing sensitive feature grayscale distribution and high-frequency noise ratio.
5. The method according to claim 4, characterized in that The calculating the test image based on the verification index to obtain index data of the test image includes: Calculate index data of the encrypted QR code printed image, the encrypted QR code photographed image, and the encrypted QR code scanned image based on the verification index, wherein the index data includes a printing index, a photographing index, and a scanning index; The printing indicators include the hollow pixel loss rate, the black pixel inconsistency rate, the grayscale mean value of the printing sensitive feature, the grayscale standard deviation of the printing sensitive feature, and the high-frequency noise ratio of the encrypted two-dimensional code printed image; The photographic indicators include the hollow pixel loss rate, the black pixel inconsistency rate, the grayscale mean value of the printing sensitive feature, the grayscale standard deviation of the printing sensitive feature, and the high-frequency noise ratio of the encrypted QR code photographic image; Among them, the scanning indicators are the hollow pixel loss rate, the black pixel inconsistency rate, the grayscale mean of the printing sensitive feature, the grayscale standard deviation of the printing sensitive feature and the high-frequency noise ratio of the encrypted two-dimensional code scan image.
6. The method according to claim 5, characterized in that The initial threshold of the verification indicator is set according to the indicator data, and the test image is input into a preset classification model for training to obtain a target classification model, including: Introducing a preset visualization library and generating an indicator distribution map according to the printing indicator, the photographing indicator, and the scanning indicator; Analyzing the characteristic differences between the printing indicator, the photographing indicator, and the scanning indicator through the indicator distribution map, and setting the initial threshold value of the verification indicator according to the characteristic differences; Dividing the test image into a training image set and a verification image set, and inputting the training image set into a preset classification model for training; Using the trained preset classification model to perform threshold prediction on the verification image set to obtain the threshold of the verification data set; The preset loss function is used to calculate the false recognition rate and missed recognition rate of the threshold of the verification data set, and the trained preset classification model is optimized according to the false recognition rate and missed recognition rate to obtain the target classification model.
7. The method according to any one of claims 1 to 6, characterized in that The encryption module includes at most one black pixel point after the hollowing out encryption process.
8. A device for generating an encrypted QR code, characterized in that: include: A generating unit, configured to generate an initial QR code based on a user text requirement, wherein the initial QR code includes a positioning area and a data area; a first identification unit, configured to divide the initial two-dimensional code into a plurality of modules, and identify the module including the data area and excluding the positioning area as an encryption module; a processing unit, configured to generate a first hash function value using a preset cryptographic algorithm, and perform hollow encryption processing on corresponding black pixels in the encryption module according to the first hash function value; A second recognition unit is used to recognize that the black pixel points within a preset range around the black pixel points after the hollowing and encryption processing are printing sensitive areas; The changing unit is configured to generate a second hash function value using the preset cryptographic algorithm, and change the grayscale value of the black pixel in the printing sensitive area according to the second hash function value to obtain an encrypted two-dimensional code.
9. A system for generating an encrypted QR code, characterized in that: include: processor, memory, input and output units, and buses; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a program stored thereon, wherein the program, when executed on a computer, performs the method according to any one of claims 1 to 7.
Citation Information
Cited By
Two-dimensional code anti-counterfeiting image processing method and system for anti-counterfeiting verification
CN120997537A