Two-dimensional code anti-counterfeiting image processing method and system for anti-counterfeiting verification
By acquiring multiple frames of images and dividing them into color blocks, an anti-counterfeiting grayscale matrix and an enhanced anti-counterfeiting binary matrix are established, solving the problem of the imbalance between robustness and accuracy in QR code anti-counterfeiting verification and achieving efficient anti-counterfeiting verification.
Patent Information
- Application Number
- CN202511506569.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-21
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2045-10-21
AI Technical Summary
In existing QR code anti-counterfeiting verification, image quality is unstable due to factors such as ambient lighting, shooting angle, and camera resolution, resulting in insufficient robustness or low accuracy, making it difficult to balance robustness and accuracy.
By acquiring multiple frames of images, dividing them into color blocks, obtaining anti-counterfeiting pixels, establishing an anti-counterfeiting grayscale matrix and an enhanced anti-counterfeiting binary matrix, and combining grayscale relationships to determine the authenticity of the QR code, the accuracy of anti-counterfeiting verification is improved by utilizing the stable geometric and physical properties of the QR code itself for illumination correction.
It improves the authentication success rate in real-world scenarios, ensures the accuracy and robustness of anti-counterfeiting verification, and reduces the negative impact of external factors.
Smart Images

Figure CN120997537A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology. More specifically, this invention relates to a QR code anti-counterfeiting image processing method and system for anti-counterfeiting verification. Background Technology
[0002] QR codes are a two-dimensional encoding method that uses alternating black and white patterns to record data. They are widely used and promoted due to their low cost and ability to form various smart applications when combined with smartphones. A common application of QR codes is product anti-counterfeiting and traceability, linking product information to the QR code so that users can learn about the product and verify its authenticity by scanning the code when purchasing. However, due to the replicability of QR codes, they often require encryption and image processing to ensure their uniqueness and meet the requirements of anti-counterfeiting applications.
[0003] To ensure the uniqueness of QR codes, the microscopic physical texture of the paper on which the QR code is printed is often used as an anti-counterfeiting feature, enriching the verification content of the QR code. For example, Chinese patent document CN103279731B discloses a QR code anti-counterfeiting method and its verification method, which utilizes the difficult-to-copy random image details generated during the printing of QR codes as an anti-counterfeiting feature, giving the QR code a high level of anti-counterfeiting capability.
[0004] However, during the process of users scanning QR codes for verification, there is an issue of unstable image quality. Ambient lighting, shooting angle, and camera clarity can all affect the recognition of random image details. Therefore, when the extraction accuracy of random image details is high, the robustness is insufficient, which may lead to the failure of anti-counterfeiting verification. On the other hand, if the extraction accuracy of random image details is low, it will result in the failure to meet the accuracy requirements of anti-counterfeiting verification. Summary of the Invention
[0005] To address the aforementioned technical problem of balancing the robustness and accuracy of QR code anti-counterfeiting image processing, this invention provides solutions in the following aspects.
[0006] In a first aspect, the present invention provides a QR code anti-counterfeiting image processing method for anti-counterfeiting verification, comprising: Multiple images of the QR code to be tested are acquired using a mobile terminal. The grayscale processing and distortion correction results of these images are recorded as the test image. A standard image and a set of standard images of the QR code to be tested are obtained. Each standard image is divided into several color blocks, and anti-counterfeiting pixels are obtained on a block-by-block basis. An anti-counterfeiting grayscale matrix for any standard image is established based on the grayscale of the anti-counterfeiting pixels. The anti-counterfeiting pixels are extracted based on the uniformity of grayscale distribution within each color block. Any standard image is recorded as the target image. The sharpness of any test image is obtained by combining the edge gradient and grayscale distribution types of the test image. Based on the sharpness of the test image and the occurrence of anti-counterfeiting pixels in test images of different sharpnesses, an enhanced anti-counterfeiting binary matrix of the QR code to be tested is established. Based on the enhanced anti-counterfeiting binary matrix and the grayscale relationship of pixels in all test images, an enhanced anti-counterfeiting grayscale matrix of the QR code to be tested is established. Based on the enhanced anti-counterfeiting grayscale matrix of the QR code to be tested and the non-zero value of the corresponding standard image's anti-counterfeiting grayscale matrix... The authenticity of a QR code is determined by the degree of grayscale similarity of its elements.
[0007] This invention effectively suppresses the negative effects of hand tremors, motion blur, and transient lighting changes by acquiring multiple frames of images and calculating the feature stability of each anti-counterfeiting pixel. It extracts the most reliable physical features from the unstable data stream, significantly improving the authentication success rate in real-world scenarios. This invention utilizes the anti-counterfeiting pixels of the QR code itself, which possess stable geometric and physical properties, as local lighting references, achieving precise lighting correction for these pixels. This self-reference mechanism requires no additional hardware and is more accurate than global correction, ensuring the authenticity of the material fingerprint features.
[0008] Preferably, dividing each standard image into several color blocks includes: Edge detection is performed on the target image to obtain several edges; a sliding window is established, the initial size of which is... The sliding window is moved in an S-shape from the top left corner to the bottom right corner of the target image, with a step size of 1 pixel. Any pixel in the target image is recorded as... ,Include The window is denoted as Set up a sliding window and determine the size of the color blocks based on the distribution of colors within the window's edges; Set the size of the color blocks in the target image to the final sliding window size, obtain the monochrome windows of all pixels in the target image, take the union of the sets, and obtain the color block set of the target image.
[0009] This invention divides the image to be tested into color blocks, making full use of the characteristics of QR codes, which makes the acquisition of anti-counterfeiting pixels more detailed and accurate.
[0010] Preferably, determining the size of the color block includes: right Any window of the target image that does not contain pixels at any edge of the target image is denoted as _____. A monochrome window; if the window contains edge pixels of the target image and is adjacent to edge pixels of the target image contained in a neighboring window, then the window is denoted as... The noisy window; if all pixels of the target image have a monochrome window, the sliding window is increased in increments of 1 pixel; when Increase to At that time, all pixels of the target image have a monochrome window, and Increase to When none of the pixels in the target image contain a monochrome window, The size of the corresponding sliding window is denoted as the size of the color block in the target image.
[0011] Preferably, the step of obtaining anti-counterfeiting pixels in units of color blocks includes: Any color block in the target image is designated as the target color block, and the pixels belonging to each gray level of the target color block are obtained. Based on the uniformity of the gray level distribution of the pixels in the target color block, the gray level stability of any pixel in the target color block is calculated. Combining the gray level stability of the pixels in the target color block with that of their neighboring pixels, the anti-counterfeiting stability of any pixel in the target color block is obtained. Based on the gray level stability, stable pixels of the target color block are selected, and these stable pixels are clustered based on their anti-counterfeiting stability to obtain several anti-counterfeiting pixel clusters. An anti-counterfeiting gray level matrix of the target image is established, and the gray levels of all anti-counterfeiting pixels are included in the corresponding elements of the anti-counterfeiting gray level matrix. The values of the remaining elements are denoted as... , It is a preset value outside the grayscale value range.
[0012] This invention uses grayscale distribution to screen anti-counterfeiting pixels, which can greatly reflect the texture characteristics of QR codes on different printing material backgrounds, so that the anti-counterfeiting pixels have the effect of anti-counterfeiting verification.
[0013] Preferably, the calculation of the arbitrary grayscale stability of the target color patch includes: Divide the target color block into several sub-color blocks and obtain the number of pixels with gray level q in all sub-color blocks of the target color block; The grayscale stability of the target color block with grayscale value q satisfies the expression: ; In the formula, This indicates the grayscale stability of the target color block with a grayscale value of q. This indicates the number of pixels with a gray level of q in the target color block; Indicates the number of pixels in the target color block; Indicates the number of sub-color blocks of a color block; , This represents the number of pixels belonging to the a-th and b-th sub-color blocks among the pixels with grayscale value q in the target color block; Represents the absolute value function; This represents the natural exponential function.
[0014] Preferably, the anti-counterfeiting stability of any pixel in the target color block satisfies the expression: ; In the formula, This indicates the anti-counterfeiting stability of the i-th pixel of the target color block; This represents the grayscale stability corresponding to the grayscale value of the i-th pixel in the target color block. This represents the number of neighboring pixels of a pixel. This represents the grayscale stability corresponding to the grayscale of the r-th neighboring pixel of the i-th pixel in the target color block. This represents the natural exponential function.
[0015] The present invention improves the robustness of QR code anti-counterfeiting verification by acquiring the anti-counterfeiting stability of pixels, and avoids the influence of factors such as lighting and clarity on the judgment of the authenticity of goods.
[0016] Preferably, obtaining the sharpness of any image to be tested includes: Based on the edge detection algorithm, several edges of any image to be tested are obtained. Several pixels are obtained at equal pixel distances on any edge of the image to be tested, and are denoted as edge feature pixels of the image to be tested. The gradient vector of the edge feature pixels is obtained. The sharpness of any image under test satisfies the expression: In the formula, This represents the sharpness of the k-th image to be tested; This represents the number of edge feature pixels in the k-th image to be tested; This represents the gradient vector of the t-th edge feature pixel in the k-th image to be tested; This represents the grayscale class of the k-th pixel in the image to be tested; Represents the absolute value function; Represents the normalization function; It is a local minimum.
[0017] The image clarity obtained by this invention ensures that even in cases of low clarity, there are enough anti-counterfeiting pixels for verification, guaranteeing the accuracy of anti-counterfeiting QR code detection.
[0018] Preferably, the step of establishing the enhanced anti-counterfeiting binary matrix of the QR code to be tested includes: Obtain the anti-counterfeiting grayscale matrix of all images to be tested, and construct the anti-counterfeiting frequency matrix of the QR code to be tested. The value of any element in the anti-counterfeiting frequency matrix is equal to the frequency of the corresponding position belonging to the anti-counterfeiting pixel in all images to be tested. Change the values of elements in the anti-counterfeiting frequency matrix whose frequency is less than the second threshold to... Then all non- Change the values of the elements to 1, and record the resulting matrix as the enhanced anti-counterfeiting binary matrix of the QR code to be tested.
[0019] Preferably, establishing the enhanced anti-counterfeiting grayscale matrix of the QR code to be tested includes: Based on the grayscale mean range, the set of color patches in each image to be tested is divided into two types of color patches; the v-th color patch of any image to be tested is denoted as... , obtain Similar color blocks in the neighborhood will The average grayscale value of all stable pixels is denoted as Background grayscale, when If the difference between the background grayscale and the average background grayscale of all similar color blocks is less than or equal to the third threshold, then... The stable color blocks are denoted as stable color blocks. The stable color blocks in the v-th color block of all the images to be tested are collectively referred to as the stable color blocks of the v-th region of the QR code to be tested. The average gray value of the anti-counterfeiting pixels with the same coordinates of all stable color blocks in the v-th region of the QR code to be tested is calculated to obtain the preliminary enhanced anti-counterfeiting gray matrix of the QR code to be tested. The matrix is multiplied bit by bit with the enhanced anti-counterfeiting binary matrix to obtain the enhanced anti-counterfeiting gray matrix of the QR code to be tested.
[0020] Secondly, the present invention provides a QR code anti-counterfeiting image processing system for anti-counterfeiting verification, including a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the above-mentioned QR code anti-counterfeiting image processing method for anti-counterfeiting verification is implemented.
[0021] By adopting the above technical solution, the QR code anti-counterfeiting image processing method used for anti-counterfeiting verification is generated into a computer program and stored in a memory so that it can be loaded and executed by a processor. In this way, a terminal device can be made based on the memory and the processor for convenient use.
[0022] The beneficial effects of this invention are as follows: (1) This invention extracts anti-counterfeiting pixels by dividing a standard image into color blocks and analyzing the uniformity of gray distribution within the color blocks, which can directly and accurately locate the texture-rich area of the QR code background. (2) The present invention compares the grayscale relationship and anti-counterfeiting stability of pixels in the QR code to be tested and the standard image. Compared with the comparison of grayscale values alone, it can improve the robustness of QR code anti-counterfeiting verification and improve the accuracy of anti-counterfeiting verification.
[0023] (3) The present invention ensures the accuracy requirement of anti-counterfeiting verification while extracting details of QR code images with high precision, and improves the processing effect of QR code anti-counterfeiting images used for anti-counterfeiting verification. Attached Figure Description
[0024] Figure 1 This is a flowchart illustrating the QR code anti-counterfeiting image processing method used for anti-counterfeiting verification in this invention; Figure 2 It is an illustrative representation of the contents. A schematic diagram of the window. Detailed Implementation
[0025] This invention discloses a QR code anti-counterfeiting image processing method for anti-counterfeiting verification, as described in the embodiments of the present invention. Figure 1 This includes steps S1-S4: S1: Collect multiple images of the QR code to be tested through a mobile terminal, and record the grayscale processing and distortion correction results of the images as the images to be tested; obtain the standard image of the QR code to be tested and the standard image set.
[0026] It should be noted that QR code verification is often required when users need to confirm the authenticity of goods during the purchase process or upon receipt. Therefore, the terminal used to scan the QR code is usually a mobile device, and users will move their hands to ensure the mobile device's camera can clearly capture the QR code. During this process, angles and lighting conditions change. Therefore, to improve the accuracy of QR code scanning and anti-counterfeiting verification, this invention captures the QR code image multiple times during camera movement and combines multiple QR code images for anti-counterfeiting verification, thereby avoiding verification failures caused by external factors such as angle and lighting. Simultaneously, to ensure the QR code verification has a source, it is also necessary to obtain all unverified QR codes of the product stored in the verification center.
[0027] Specifically, when a user clicks the QR code scanning module on the mobile terminal, the camera starts operating and captures images of the QR codes at a preset frequency, obtaining a preset number of images of the QR codes to be tested. It should be noted that the preset frequency and preset number are set by the implementers according to the actual implementation situation; for example, the preset frequency can be set to 0.1 seconds per image, and the preset number can be set to 10 images.
[0028] All images of the QR code to be tested are converted to grayscale. Then, the boundaries of the QR code in all images are obtained through Hough line detection. The pixels of the boundaries and the regions within the boundaries are extracted, and distortion correction is performed through affine transformation to obtain several images of the QR code to be tested. It should be noted that the grayscale conversion, Hough line detection, and affine transformation are all existing technologies and will not be described in detail here.
[0029] The QR code decoder identifies and decodes all images to be tested, redirecting the user to the verification link of the QR code. The standard image of the QR code for the product contained in the verification link is then obtained. All standard images of the same product's QR codes are then collected and denoted as the standard image set. It should be noted that the QR code decoder is existing technology and therefore will not be described in detail.
[0030] At this point, several images to be tested, as well as corresponding standard images and standard image sets, have been obtained.
[0031] S2: Divide each standard image into several color blocks, obtain anti-counterfeiting pixels in units of color blocks, and combine the grayscale of the anti-counterfeiting pixels to establish an anti-counterfeiting grayscale matrix for any standard image.
[0032] It should be noted that a QR code is composed of several black and white squares, representing the values 1 and 0. Due to the influence of paper, the QR code image is often not a binary image during real-time capture. It contains the microscopic structure of the paper, causing the grayscale levels within the black and white squares to be inconsistent, thus forming the unique identifier of each QR code. Therefore, this invention first divides the standard image, treating each black and white square as a color block. The pixels within each color block with unique grayscale representations are used as anti-counterfeiting features for subsequent anti-counterfeiting verification.
[0033] Specifically, each standard image is divided into several color blocks, and anti-counterfeiting pixels are obtained on a per-color-block basis. Combining the grayscale values of these anti-counterfeiting pixels, an anti-counterfeiting grayscale matrix is established for any standard image, including: Let any standard image be designated as the target image. Edge detection is then performed on the target image to obtain several edges. It should be noted that the edge detection described is an existing technique, and the edges of the image can be obtained using the Canny operator or the Sobel operator.
[0034] Create a sliding window, the initial size of which is... The sliding window is moved in an "S" shape across the target image, starting from the top left corner and moving to the bottom right corner, with a step size of 1 pixel. Any pixel in the target image is then recorded as... ,Include The window is denoted as ,like Figure 2 For inclusion A schematic diagram of the window, in which , , , Each contains The four windows. To avoid analyzing the unit size of incorrect color blocks, the initial size of the sliding window can be set to a small value, such as 4.
[0035] It should be noted that, if If any window has edges that connect to the edges of neighboring windows, it indicates that the window is not a single color block. Therefore, if If there is a window that does not contain edges connected to neighboring windows, it means that P belongs to a color block. If all pixels belong to a color block, it means that the sliding window can still be increased. Therefore, the sliding window should be increased to contain the complete color block.
[0036] right Any window of the target image that does not contain pixels at any edge of the target image is denoted as _____. A monochrome window; if the window contains edge pixels of the target image and is adjacent to edge pixels of the target image contained in a neighboring window, then the window is denoted as... The noisy window; if all pixels of the target image have a monochrome window, the sliding window is increased in increments of 1 pixel; when Increase to At that time, all pixels of the target image have a monochrome window, and Increase to When none of the pixels in the target image contain a monochrome window, The size of the corresponding sliding window is denoted as the size of the color block in the target image.
[0037] Set the size of the color blocks in the target image to the final sliding window size, obtain the monochrome windows of all pixels in the target image, take the union of the sets, and obtain the color block set of the target image.
[0038] It should be noted that, due to factors such as paper texture, the grayscale distribution in each color block is uneven. Therefore, by extracting the uneven grayscale in the color block, the anti-counterfeiting pixels in the color block can be obtained.
[0039] Record any color block in the target image as the target color block, and obtain the pixels of the target color block belonging to each gray level.
[0040] It should be noted that the more pixels of any gray level a target color block has, and the more uniformly they are distributed, the more stable those pixels are within the target color block. Therefore, the stability of the color block at any gray level is calculated based on the uniformity of the gray level distribution of the pixels within the color block.
[0041] Divide the target color block into several equal sub-color blocks and obtain the number of pixels with grayscale value q in all sub-color blocks. It should be noted that the number of equal divisions of the target color block is set by the implementer based on the actual implementation situation; for example, if the color block size is... The size of the sub-color block can then be set to .
[0042] The grayscale stability of the target color block with grayscale value q satisfies the expression: ; In the formula, This indicates the grayscale stability of the target color block with a grayscale value of q. This indicates the number of pixels with a gray level of q in the target color block; Indicates the number of pixels in the target color block; Indicates the number of sub-color blocks of a color block; , This represents the number of pixels belonging to the a-th and b-th sub-color blocks among the pixels with grayscale value q in the target color block; Represents the absolute value function; This represents the natural exponential function.
[0043] In the formula, This represents the proportion of pixels with gray level q in the target color block. The larger this value is, the more common gray level q is in the target color block, and therefore the higher the gray level stability of gray level q. This represents the sum of the differences in the number of pixels with gray level q in all different sub-color blocks within the target color block. This value indicates the uniformity of the distribution of pixels with gray level q in the target color block. The larger the value, the more uneven the distribution of pixels with gray level q in the target color block, and the lower the gray level stability of pixels with gray level q in the target color block. and In summary, the larger this value is, the more pixels with grayscale q in the target color block there are, and the more evenly they are distributed. In this case, the grayscale stability of the target color block with grayscale q is higher.
[0044] It should be noted that pixels with higher grayscale stability have weaker representation of color block features. Therefore, pixels with lower grayscale stability are more suitable as anti-counterfeiting pixels to characterize the microstructural features of color blocks. On the other hand, if anti-counterfeiting pixels are not clustered, they may fail to be captured due to instability in camera sharpness, lighting, and orientation. Therefore, further analysis of pixel clustering is necessary. The more clustered the anti-counterfeiting pixels, the stronger their feature representation and stability, making them more suitable as anti-counterfeiting pixels. The anti-counterfeiting stability of a pixel is obtained by combining the grayscale stability of the pixel within the color block with that of its neighboring pixels.
[0045] The anti-counterfeiting stability of any pixel in the target color block satisfies the expression: ; In the formula, This indicates the anti-counterfeiting stability of the i-th pixel of the target color block; This represents the grayscale stability corresponding to the grayscale value of the i-th pixel in the target color block. This represents the number of neighboring pixels of a pixel. This represents the grayscale stability corresponding to the grayscale of the r-th neighboring pixel of the i-th pixel in the target color block. This represents the natural exponential function. It should be noted that the neighboring pixels are preset values and can be set to... The neighborhood has 24 pixels.
[0046] Pixels with the highest grayscale stability (N) are designated as stable pixels. Pixels of the target color block are used as growth seeds in descending order of anti-counterfeiting stability. Region growth is performed sequentially, with the growth condition being the presence of unstable pixels in the neighboring pixels of the growth region. Growth stops when all neighboring pixels of the growth region are stable pixels. Region growth stops when the number of regions that have completed growth exceeds a first threshold or when the growth regions of the growth seeds overlap. Each growth region is designated as an anti-counterfeiting pixel cluster, resulting in several anti-counterfeiting pixel clusters for the target color block.
[0047] Obtain the anti-counterfeiting pixel clusters of all color blocks in the target image, establish an anti-counterfeiting grayscale matrix for the target image, the anti-counterfeiting grayscale matrix being the same size as the target image, and include the grayscale values of all anti-counterfeiting pixels in the corresponding elements of the anti-counterfeiting grayscale matrix, with the values of the remaining elements denoted as... It should be noted that the aforementioned It is a preset value for a non-grayscale value range, which can be set to 256 or other characters can be used instead.
[0048] Thus, the anti-spoofing grayscale matrix of any image to be tested is obtained.
[0049] S3: Combine the edge gradient and grayscale distribution of the image under test to obtain the sharpness of any image under test; based on the sharpness of the image under test and the occurrence of anti-counterfeiting pixels in images under test with different sharpness, establish an enhanced anti-counterfeiting binary matrix for the QR code under test; based on the enhanced anti-counterfeiting binary matrix, combine the grayscale relationship of pixels in all images under test to establish an enhanced anti-counterfeiting grayscale matrix for the QR code under test.
[0050] It should be noted that the acquisition scenario of the standard image is relatively idealized, while the image under test is limited by the clarity of the mobile terminal's camera and the influence of external factors, which will cause some changes in the anti-counterfeiting grayscale matrix. For example, the position and grayscale of the anti-counterfeiting pixels will change, so the anti-counterfeiting grayscale matrix of the image under test cannot be completely matched with the anti-counterfeiting grayscale matrix of the corresponding standard image. However, by combining the anti-counterfeiting grayscale matrices of all the images under test of the QR code, the anti-counterfeiting grayscale matrix of the corresponding standard image can be restored to the greatest extent. Therefore, this invention combines the anti-counterfeiting grayscale matrices of all the images under test to obtain the enhanced anti-counterfeiting grayscale matrix of the QR code under test.
[0051] It should be further noted that when the image under test has low resolution, the obtained anti-counterfeiting grayscale matrix may be deviated, and the number of anti-counterfeiting pixels may be small. However, the positional structure of the anti-counterfeiting pixels can still demonstrate the anti-counterfeiting features of the QR code. When the color of the image under test changes, there may be a deviation in grayscale values in the overall or partial aspects of the image. However, the grayscale relationship of the anti-counterfeiting pixels can still demonstrate the anti-counterfeiting features of the QR code. Therefore, this invention combines the positional structure of the anti-counterfeiting pixels and the grayscale relationship of the anti-counterfeiting grayscale matrix of all images under test to establish an enhanced anti-counterfeiting grayscale matrix for the QR code under test.
[0052] It should be noted that the higher the resolution of the image under test, the more distinct the boundaries of the image and the more dispersed the grayscale distribution of the pixels, thus enabling details to be presented.
[0053] Specifically, by combining the edge gradient and grayscale distribution types of the image under test, the sharpness of any image under test is obtained, including: Edge detection is performed on any image to be tested to obtain several edges of the image. Several pixels are then obtained at equal pixel distances along any edge of the image, denoted as edge feature pixels. The gradient vector of these edge feature pixels is then obtained. It should be noted that the equal pixel distance can be set according to the actual implementation. For example, obtaining four pixels at equal pixel distances may not accurately reflect sharpness if the number is too small, while a large number will increase irrelevant computational load. This edge detection is an existing technology and can be performed using the Sobel operator or the Canny operator.
[0054] The sharpness of any image under test satisfies the expression: ; In the formula, This represents the sharpness of the k-th image to be tested; This represents the number of edge feature pixels in the k-th image to be tested; This represents the gradient vector of the t-th edge feature pixel in the k-th image to be tested; This represents the grayscale class of the k-th pixel in the image to be tested; Represents the absolute value function; Represents the normalization function; To find the minimum value and avoid a denominator of 0, for example, .
[0055] In the formula, This represents the magnitude of the gradient vector of the t-th edge feature pixel in the k-th test image. This value reflects the degree of gray-level change in the neighborhood of the t-th edge feature pixel in the k-th test image. The larger the value, the higher the degree of gray-level change in the neighborhood of the t-th edge feature pixel in the k-th test image, the more details are preserved, and therefore the higher the clarity of the k-th test image. This represents the average sharpness of the neighborhood of all edge feature pixels in the k-th test image. A larger value indicates higher sharpness of the k-th test image. Based on this, the grayscale values of the pixels in the k-th test image are... The larger the value, the richer the grayscale of the k-th test image, the fewer the blurred pixels in the k-th test image, and the higher the clarity of the k-th test image.
[0056] It should be noted that the lower the resolution of the image under test, the fewer anti-counterfeiting pixels can be extracted. However, if these anti-counterfeiting pixels are located in the corresponding positions of the high-resolution image under test, then these anti-counterfeiting pixels have a higher anti-counterfeiting capability and can still correctly prevent counterfeiting even with significant image loss. Therefore, the positions of anti-counterfeiting pixels in all images under test are statistically analyzed and filtered to obtain the enhanced anti-counterfeiting binary matrix of the QR code under test.
[0057] Preferably, the anti-counterfeiting grayscale matrix of all images to be tested is obtained, and the anti-counterfeiting frequency matrix of the QR code to be tested is constructed. The value of any element in the anti-counterfeiting frequency matrix is equal to the frequency of the corresponding position belonging to the anti-counterfeiting pixel in all images to be tested. The values of elements in the anti-counterfeiting frequency matrix whose frequency is less than the second threshold are changed to... Then all non- The values of the elements are changed to 1, and the resulting matrix is recorded as the enhanced anti-counterfeiting binary matrix of the QR code to be tested. It should be noted that the second threshold can be set according to the actual implementation; for example, when the number of images to be tested is 10, the second threshold can be set to 5. The enhanced anti-counterfeiting binary matrix reflects the positions of anti-counterfeiting pixels with strong anti-counterfeiting capabilities obtained from all the images to be tested. It is a preset value for a non-grayscale value range, which can be set to 256 or other characters can be used instead.
[0058] It should be noted that, unlike the coordinates of anti-counterfeiting pixels, the grayscale value of the corresponding position of the anti-counterfeiting pixel in the enhanced anti-counterfeiting grayscale matrix cannot be obtained simply by accumulation. This is because the overall grayscale of different test images is different. For example, the overall grayscale of the test image with insufficient light is lower, while the overall grayscale of the test image with strong light is higher. However, the grayscale relationship between pixels does not change. Under uniform illumination, the grayscale relationship between two adjacent pixels is stable. Therefore, further analysis and quantification of the grayscale relationship of the pixels in the enhanced anti-counterfeiting binary matrix are performed to obtain the enhanced anti-counterfeiting grayscale matrix.
[0059] Preferably, based on the enhanced anti-counterfeiting binary matrix and combining the grayscale relationships of pixels in all images to be tested, an enhanced anti-counterfeiting grayscale matrix is established for the QR code to be tested, including: For each set of color patches in the image to be tested, color patches with a grayscale mean greater than the grayscale mean of the corresponding image to be tested are denoted as Class I color patches of the corresponding image to be tested, and color patches with a grayscale mean less than the grayscale mean of the corresponding image to be tested are denoted as Class II color patches of the corresponding image to be tested.
[0060] Let the v-th color patch of the k-th image be denoted as... ,by For example, to obtain Get the same color blocks in the neighborhood. The average grayscale value of all stable pixels is denoted as . The background grayscale is obtained by acquiring the background grayscale of the same type of color blocks. If the difference between the background grayscale value and the average background grayscale value of all the same type of color blocks is greater than the third threshold, then... This is denoted as an unstable color block. If the difference between the background grayscale and the average background grayscale of all the same type of color blocks is less than or equal to the third threshold, then... These are designated as stable color blocks. It should be noted that, considering the instability of light positions, the grayscale relationship of a color block may change when its position is within a region of abrupt changes in light position or grayscale. Therefore, color blocks are screened, and only stable color blocks are used for grayscale relationship analysis. The third threshold is set by the implementer based on the actual implementation situation; for example, the third threshold can be set to 8.
[0061] The v-th color block of the image to be tested is denoted as the v-th region of the QR code to be tested. The v-th color blocks of all images to be tested are obtained, and the stable color blocks among them are collectively referred to as the stable color blocks of the v-th region of the QR code to be tested. The average grayscale values of the anti-counterfeiting pixels with the same coordinates of all stable color blocks in the v-th region of the QR code to be tested are calculated to obtain the preliminary enhanced anti-counterfeiting grayscale matrix of the QR code to be tested. The preliminary enhanced anti-counterfeiting grayscale matrix is multiplied bit-by-bit by the enhanced anti-counterfeiting binary matrix of the QR code to be tested to obtain the enhanced anti-counterfeiting grayscale matrix of the QR code to be tested. It should be noted that the elements with a value of 1 in the enhanced anti-counterfeiting binary matrix represent the positions of the pixels in the enhanced anti-counterfeiting grayscale matrix that can enhance anti-counterfeiting. By filling the grayscale values of the preliminary enhanced anti-counterfeiting grayscale matrix, the enhanced anti-counterfeiting pixels are made more specific, providing a more accurate basis for anti-counterfeiting verification.
[0062] At this point, the enhanced anti-counterfeiting grayscale matrix of the QR code to be tested has been obtained.
[0063] S4: The non-standard anti-counterfeiting grayscale matrix based on the QR code under test and the corresponding standard image. The authenticity of a QR code is determined by the degree of grayscale similarity of its elements.
[0064] It should be noted that the enhanced anti-counterfeiting grayscale matrix of the QR code under test is a matrix of pixel coordinates and grayscale values after filtering and grayscale recombination. It is not completely consistent with the anti-counterfeiting grayscale matrix of the standard image of the corresponding product. However, the key pixels, that is, the pixels that can enhance anti-counterfeiting, can be well matched in the anti-counterfeiting grayscale matrix of the standard image, which means that the product corresponding to the QR code under test is genuine.
[0065] Specifically, the values in the enhanced anti-counterfeiting grayscale matrix of the QR code to be tested and the corresponding standard image's anti-counterfeiting grayscale matrix are all non-zero. The elements are denoted as the temporary anti-counterfeiting elements of the QR code to be tested and the temporary anti-counterfeiting elements of the standard image, respectively.
[0066] It should be noted that the grayscale relationships of elements at the same position and their neighbors in the temporary anti-counterfeiting elements of the QR code under test and the temporary anti-counterfeiting elements of the standard image should be consistent. For example, in the standard image, the position... Temporary anti-counterfeiting elements and locations If the grayscale difference of the temporary anti-counterfeiting elements is 10, then the closer the grayscale difference in the QR code to be tested is to 10, the more consistent the two temporary anti-counterfeiting elements are with the genuine product's QR code. Therefore, by combining the grayscale differences of the same neighborhood relationships of the temporary anti-counterfeiting elements of the QR code to be tested and the standard image, the authenticity of the QR code to be tested can be obtained.
[0067] The authenticity of the QR code under test satisfies the expression: ; In the formula, Indicates the authenticity of the QR code being tested; Indicates the number of temporary anti-counterfeiting elements in the QR code to be tested; This represents the grayscale difference between the s-th and z-th temporary anti-counterfeiting elements of the QR code to be tested; This represents the grayscale difference between the s-th and z-th temporary anti-counterfeiting elements in the standard image; Indicates shared ownership Two-by-two combinations of temporary anti-counterfeiting elements; Represents the absolute value function; Represents the natural exponential function; This is a minimum value used to avoid a denominator of 0, for example... .
[0068] In the formula, This represents the difference in grayscale values between the s-th and z-th temporary anti-counterfeiting elements in the QR code under test and the standard image; This represents the sum of the differences in grayscale values between all different pairwise combinations of temporary anti-counterfeiting elements between the QR code under test and the standard image; This represents the average of the sum of the differences in grayscale values between all different pairwise combinations of temporary anti-counterfeiting elements in the QR code under test and the standard image. This value reflects the overall difference between the temporary anti-counterfeiting elements in the QR code under test and the standard image. The larger this value is, the less the grayscale relationship of the anti-counterfeiting pixels of the QR code under test conforms to the standard image, thus indicating that the authenticity of the QR code under test is lower.
[0069] At this point, the authenticity of the QR code under test has been determined.
[0070] A fourth threshold is set. If the authenticity of the QR code being tested is greater than the fourth threshold, the product corresponding to the QR code is considered genuine. It should be noted that the fourth threshold can be set by simulating the authenticity of QR codes in a real environment. For example, it can be set to 0.7. Setting it higher will detect genuine QR codes as counterfeit products, while setting it lower will allow counterfeit QR codes to be identified as genuine products.
[0071] This completes the processing and verification of the QR code anti-counterfeiting image.
[0072] This invention also discloses a QR code anti-counterfeiting image processing system for anti-counterfeiting verification, including a processor and a memory. The memory stores computer program instructions, and when the computer program instructions are executed by the processor, the QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to the present invention is implemented.
[0073] The system also includes other components well known to those skilled in the art, such as communication buses and communication interfaces, the settings and functions of which are known in the art and will not be described in detail here.
[0074] While this specification has shown and described numerous embodiments of the invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Many modifications, alterations, and alternatives will occur to those skilled in the art without departing from the spirit and essence of the invention. It should be understood that various alternatives to the embodiments of the invention described herein may be employed in the practice of this invention.
Claims
1. A QR code anti-counterfeiting image processing method for anti-counterfeiting verification, characterized in that, include: Multiple images of the QR code to be tested are acquired using a mobile terminal, and the grayscale processing and distortion correction results of the images are recorded as the images to be tested; a standard image of the QR code to be tested and a standard image set are obtained. Each standard image is divided into several color blocks, and anti-counterfeiting pixels are obtained on a unit basis. Combining the grayscale of the anti-counterfeiting pixels, an anti-counterfeiting grayscale matrix is established for any standard image. The anti-counterfeiting pixels are extracted based on the uniformity of grayscale distribution within each color block. Any standard image is denoted as the target image. By combining the edge gradient and grayscale distribution of the image under test, the sharpness of any image under test is obtained; based on the sharpness of the image under test and the occurrence of anti-counterfeiting pixels in images under test with different sharpness, an enhanced anti-counterfeiting binary matrix of the QR code under test is established; based on the enhanced anti-counterfeiting binary matrix, combined with the grayscale relationship of pixels in all images under test, an enhanced anti-counterfeiting grayscale matrix of the QR code under test is established. The enhanced anti-counterfeiting grayscale matrix based on the QR code under test and the non-anti-counterfeiting grayscale matrix of the corresponding standard image. The grayscale similarity of elements is used to determine the authenticity of the QR code being tested. It is a preset value outside the grayscale value range.
2. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 1, characterized in that, The process of dividing each standard image into several color blocks includes: Edge detection is performed on the target image to obtain several edges; a sliding window is established, the initial size of which is... The sliding window is moved in an S-shape from the top left corner to the bottom right corner of the target image, with a step size of 1 pixel. Any pixel in the target image is recorded as... ,Include The window is denoted as Set up a sliding window and determine the size of the color blocks based on the distribution of colors within the window's edges; Set the size of the color blocks in the target image to the final sliding window size, obtain the monochrome windows of all pixels in the target image, take the union of the sets, and obtain the color block set of the target image.
3. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 2, characterized in that, Determining the size of the color block includes: right Any window of the target image that does not contain pixels at any edge of the target image is denoted as _____. A monochrome window; if the window contains edge pixels of the target image and is adjacent to edge pixels of the target image contained in a neighboring window, then the window is denoted as... The noisy window; if all pixels of the target image have a monochrome window, the sliding window is increased in increments of 1 pixel; when Increase to At that time, all pixels of the target image have a monochrome window, and Increase to When none of the pixels in the target image contain a monochrome window, The size of the corresponding sliding window is denoted as the size of the color block in the target image.
4. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 1, characterized in that, The method of obtaining anti-counterfeiting pixels in units of color blocks includes: Any color block in the target image is designated as the target color block, and the pixels belonging to each gray level of the target color block are obtained. Based on the uniformity of the gray level distribution of the pixels in the target color block, the gray level stability of any pixel in the target color block is calculated. Combining the gray level stability of the pixels in the target color block with that of their neighboring pixels, the anti-counterfeiting stability of any pixel in the target color block is obtained. Based on the gray level stability, stable pixels of the target color block are selected, and these stable pixels are clustered based on their anti-counterfeiting stability to obtain several anti-counterfeiting pixel clusters. An anti-counterfeiting gray level matrix of the target image is established, and the gray levels of all anti-counterfeiting pixels are included in the corresponding elements of the anti-counterfeiting gray level matrix. The values of the remaining elements are denoted as... .
5. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 4, characterized in that, The calculation of the arbitrary grayscale stability of the target color patch includes: Divide the target color block into several sub-color blocks and obtain the number of pixels with gray level q in all sub-color blocks of the target color block; The grayscale stability of the target color block with grayscale value q satisfies the expression: ; In the formula, This indicates the grayscale stability of the target color block with a grayscale value of q. This indicates the number of pixels with a gray level of q in the target color block; Indicates the number of pixels in the target color block; Indicates the number of sub-color blocks of a color block; , This represents the number of pixels belonging to the a-th and b-th sub-color blocks among the pixels with grayscale value q in the target color block; Represents the absolute value function; This represents the natural exponential function.
6. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 4, characterized in that, The anti-counterfeiting stability of obtaining any pixel point of the target color block satisfies the expression: ; In the formula, This indicates the anti-counterfeiting stability of the i-th pixel of the target color block; This represents the grayscale stability corresponding to the grayscale value of the i-th pixel in the target color block. This represents the number of neighboring pixels of a pixel. This represents the grayscale stability corresponding to the grayscale of the r-th neighboring pixel of the i-th pixel in the target color block. This represents the natural exponential function.
7. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 1, characterized in that, The process of obtaining the sharpness of any image to be tested includes: Based on the edge detection algorithm, several edges of any image to be tested are obtained. Several pixels are obtained at equal pixel distances on any edge of the image to be tested, and are denoted as edge feature pixels of the image to be tested. The gradient vector of the edge feature pixels is obtained. The sharpness of any image under test satisfies the expression: In the formula, This represents the sharpness of the k-th image to be tested; This represents the number of edge feature pixels in the k-th image to be tested; This represents the gradient vector of the t-th edge feature pixel in the k-th image to be tested; This represents the grayscale class of the k-th pixel in the image to be tested; Represents the absolute value function; Represents the normalization function; It is a local minimum.
8. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 1, characterized in that, The process of establishing an enhanced anti-counterfeiting binary matrix for the QR code to be tested includes: Obtain the anti-counterfeiting grayscale matrix of all images to be tested, and construct the anti-counterfeiting frequency matrix of the QR code to be tested. The value of any element in the anti-counterfeiting frequency matrix is equal to the frequency of the corresponding position belonging to the anti-counterfeiting pixel in all images to be tested. Change the values of elements in the anti-counterfeiting frequency matrix whose frequency is less than the second threshold to... Then all non- Change the values of the elements to 1, and record the resulting matrix as the enhanced anti-counterfeiting binary matrix of the QR code to be tested.
9. The QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to claim 1, characterized in that, The process of establishing an enhanced anti-counterfeiting grayscale matrix for the QR code to be tested includes: Based on the grayscale mean range, the set of color patches in each image to be tested is divided into two types of color patches; the v-th color patch of any image to be tested is denoted as... , obtain Similar color blocks in the neighborhood will The average grayscale value of all stable pixels is denoted as Background grayscale, when If the difference between the background grayscale and the average background grayscale of all similar color blocks is less than or equal to the third threshold, then... The stable color blocks are denoted as stable color blocks. The stable color blocks in the v-th color block of all the images to be tested are collectively referred to as the stable color blocks of the v-th region of the QR code to be tested. The average gray value of the anti-counterfeiting pixels with the same coordinates of all stable color blocks in the v-th region of the QR code to be tested is calculated to obtain the preliminary enhanced anti-counterfeiting gray matrix of the QR code to be tested. The matrix is multiplied bit by bit with the enhanced anti-counterfeiting binary matrix to obtain the enhanced anti-counterfeiting gray matrix of the QR code to be tested.
10. A QR code anti-counterfeiting image processing system for anti-counterfeiting verification, characterized in that, include: The processor and memory, wherein the memory stores computer program instructions that, when executed by the processor, implement the QR code anti-counterfeiting image processing method for anti-counterfeiting verification according to any one of claims 1-9.
Citation Information
Patent Citations
Two-dimension code anti-counterfeit method and its anti-counterfeit verification method
CN103279731B
Production method of anti-counterfeiting embossed metal picture
CN117173142A
Double-layer anti-counterfeit label system and method based on artificial intelligence
CN119992072A
Method, system and related device for generating encrypted two-dimensional code
CN120764569A
Tint Block Image Generation Program and Tint Block Image Generation Device
US20090059254A1