CN109492735B - Two-dimensional code generation method and computer-readable storage medium - Google Patents

Two-dimensional code generation method and computer-readable storage medium Download PDF

Info

Publication number
CN109492735B
CN109492735B CN201811409345.7A CN201811409345A CN109492735B CN 109492735 B CN109492735 B CN 109492735B CN 201811409345 A CN201811409345 A CN 201811409345A CN 109492735 B CN109492735 B CN 109492735B
Authority
CN
China
Prior art keywords
dimensional code
image
code image
original image
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811409345.7A
Other languages
Chinese (zh)
Other versions
CN109492735A (en
Inventor
吴桐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tsinghua University
Original Assignee
Tsinghua University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tsinghua University filed Critical Tsinghua University
Priority to CN201811409345.7A priority Critical patent/CN109492735B/en
Publication of CN109492735A publication Critical patent/CN109492735A/en
Application granted granted Critical
Publication of CN109492735B publication Critical patent/CN109492735B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K19/00Record carriers for use with machines and with at least a part designed to carry digital markings
    • G06K19/06Record carriers for use with machines and with at least a part designed to carry digital markings characterised by the kind of the digital marking, e.g. shape, nature, code
    • G06K19/06009Record carriers for use with machines and with at least a part designed to carry digital markings characterised by the kind of the digital marking, e.g. shape, nature, code with optically detectable marking
    • G06K19/06037Record carriers for use with machines and with at least a part designed to carry digital markings characterised by the kind of the digital marking, e.g. shape, nature, code with optically detectable marking multi-dimensional coding

Abstract

Disclosed are a two-dimensional code generation method and a computer-readable storage medium. Generating a reference two-dimensional code image according to an original image and two-dimensional code data, performing style migration on the reference two-dimensional code image according to the original image to generate a first middle two-dimensional code image, combining the first middle two-dimensional code image and a binary image of the original image to obtain a second middle two-dimensional code image, and rendering the second middle two-dimensional code image according to a gray scale image of the original image and the original image to obtain a target two-dimensional code image. Thus, a two-dimensional code image with better visual effect can be obtained.

Description

Two-dimensional code generation method and computer-readable storage medium
Technical Field
The invention relates to the field of image processing, in particular to a two-dimensional code generation method and a computer readable storage medium.
Background
The two-dimensional code is an information transmission medium, is convenient for plane printing and scanning, is suitable for wide spread, has the characteristics of large storage capacity, high confidentiality, low cost and the like, and has wide application such as electronic coupons, train tickets, code scanning payment, billboards and the like due to the characteristics.
The traditional two-dimensional code is basically formed by black and white modules, and from the perspective of a user, the content of the two-dimensional code is monotonous, and the visual experience is poor. In the two-dimension code beautifying method in the prior art, technologies such as combination and embedding of pictures are generally utilized to generate a beautifying two-dimension code with images or colors so as to enhance visual experience.
However, the beautification two-dimensional code generated by the prior art has more dark color and light color noise modules, and some of the beautification two-dimensional code cannot see the background clearly, so that the visual effect is poor.
Disclosure of Invention
In view of this, the present invention provides a two-dimensional code generating method and a computer readable storage medium to generate a two-dimensional code image with better visual effect, so that the two-dimensional code image can be combined with different background images while ensuring the recognition rate.
In a first aspect, an embodiment of the present invention provides a two-dimensional code generation method, where the method includes:
generating a reference two-dimensional code image according to the original image and the two-dimensional code data;
performing style migration on the reference two-dimensional code image according to the original image to generate a first middle two-dimensional code image;
combining the first intermediate two-dimensional code image and the binary image of the original image to obtain a second intermediate two-dimensional code image; and
and rendering the second intermediate two-dimensional code image according to the gray-scale image of the original image and the original image to obtain a target two-dimensional code image.
Preferably, the generating of the reference two-dimensional code image from the original image and the two-dimensional code data includes:
generating a first weight matrix according to the original image, wherein the first weight matrix represents the importance degree of different positions of the original image; and
and generating the reference two-dimensional code image through the first weight matrix according to the original image and the two-dimensional code data.
Preferably, performing style migration on the reference two-dimensional code image according to the original image to generate a first intermediate two-dimensional code image includes:
extracting a preset area of each module of the reference two-dimensional code image to generate a black and white dot image, combining the black and white dot image and the original image to generate an accuracy image, and calculating accuracy loss according to the accuracy image;
obtaining a style characteristic image through a convolution neural network according to the original image, and calculating style loss according to the style characteristic image;
obtaining a content characteristic image through a convolutional neural network according to the reference two-dimensional code image, and calculating the internal capacitive loss according to the content characteristic image; and
and reconstructing the reference two-dimensional code image according to the accuracy loss, the stylistic loss and the capacitive loss to generate the first middle two-dimensional code image.
Preferably, combining the first intermediate two-dimensional code image and the binarized image of the original image to obtain a second intermediate two-dimensional code image comprises:
obtaining a noise matrix according to the binarized image of the original image and the reference two-dimensional code image, wherein the noise matrix represents the difference between the binarized image of the original image and the reference two-dimensional code image;
obtaining a second weight matrix through weighted summation of the noise matrix and the first weight matrix; and
and combining and binarizing the binarized image of the original image and the first intermediate two-dimensional code image according to the second weight matrix to generate a second intermediate two-dimensional code image.
Preferably, the method further comprises:
and pre-correcting the second middle two-dimensional code image according to the reference two-dimensional code image so as to enable the color of the central scanning point of each module of the second middle two-dimensional code image to be consistent with the reference two-dimensional code image.
Preferably, rendering the second intermediate two-dimensional code image according to the gray scale map of the original image and the original image to obtain a target two-dimensional code image comprises:
combining the gray scale image of the original image and the second intermediate two-dimensional code image according to a third weight matrix to obtain a target two-dimensional code image in the form of a gray scale image; and
and rendering the target two-dimensional code image in the form of the gray scale graph to generate a target two-dimensional code image in the form of a color graph.
Preferably, the method further comprises:
and performing loop iteration adjustment on the target two-dimensional code image to improve the recognition rate.
Preferably, the performing loop iteration adjustment on the target two-dimensional code image to improve the recognition rate includes:
in response to the accuracy loss being greater than an accuracy loss threshold and the content loss being greater than a content loss threshold, calculating an error value characterizing a degree of difference between a target two-dimensional code image in the form of a gray scale pattern and the reference two-dimensional code image;
updating the third weight matrix based on the accuracy loss, the content loss, and the error value; and
and updating the target two-dimensional code image according to the third weight matrix so as to improve the recognition rate of the target two-dimensional code image.
Preferably, the calculating the error value comprises:
acquiring the pixel gray level average value of a preset area of each module of the target two-dimensional code image in the gray level graph form;
acquiring a pixel gray level average value of a preset area of each module of the reference two-dimensional code image; and
and calculating an error value according to the pixel gray level average value of a preset area of each module of the target two-dimensional code image in the form of the gray level graph and the reference two-dimensional code image.
In a second aspect, embodiments of the present invention provide a computer-readable storage medium on which computer program instructions are stored, which when executed by a processor implement the method according to the first aspect.
According to the technical scheme of the embodiment of the invention, a reference two-dimensional code image is generated according to an original image and two-dimensional code data, a first intermediate two-dimensional code image is generated by performing style migration on the reference two-dimensional code image according to the original image, a second intermediate two-dimensional code image is obtained by combining the first intermediate two-dimensional code image and a binary image of the original image, and finally the second intermediate two-dimensional code image is rendered according to a gray scale image of the original image and the original image to obtain a target two-dimensional code image. Thus, a two-dimensional code image with better visual effect can be obtained.
Drawings
The above and other objects, features and advantages of the present invention will become more apparent from the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
fig. 1 is a flowchart of a two-dimensional code generation method according to an embodiment of the present invention;
FIG. 2 is a flow chart of an embodiment of the present invention for generating a reference two-dimensional code image;
FIG. 3 is a schematic diagram of generating a reference two-dimensional code image according to an embodiment of the invention;
FIG. 4 is a flow chart of generating a first intermediate two-dimensional code image according to an embodiment of the invention;
FIG. 5 is a schematic diagram illustrating a style migration performed on the reference two-dimensional code image according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of generating a first intermediate two-dimensional code image according to an embodiment of the invention;
FIG. 7 is a flow chart of an embodiment of the present invention for generating a second intermediate two-dimensional code image;
FIG. 8 is a diagram illustrating an exemplary process of generating a second weight matrix according to an embodiment of the invention;
FIG. 9 is a schematic diagram of generating a second intermediate two-dimensional code image according to an embodiment of the invention;
FIG. 10 is a flow chart of generating a target two-dimensional code image according to an embodiment of the invention;
FIG. 11 is a schematic diagram of generating a target two-dimensional code image according to an embodiment of the invention;
FIG. 12 is a flowchart illustrating a loop iteration adjustment of a target two-dimensional code according to an embodiment of the present invention;
FIG. 13 is a flow chart of calculating an error value according to an embodiment of the present invention;
fig. 14 is a schematic diagram of an electronic device of an embodiment of the invention.
Detailed Description
The present invention will be described below based on examples, but the present invention is not limited to only these examples. In the following detailed description of the present invention, certain specific details are set forth. It will be apparent to one skilled in the art that the present invention may be practiced without these specific details. Well-known methods, procedures, components and circuits have not been described in detail so as not to obscure the present invention.
Further, those of ordinary skill in the art will appreciate that the drawings provided herein are for illustrative purposes and are not necessarily drawn to scale.
Unless the context clearly requires otherwise, throughout the description and the claims, the words "comprise", "comprising", and the like are to be construed in an inclusive sense as opposed to an exclusive or exhaustive sense; that is, what is meant is "including, but not limited to".
In the description of the present invention, it is to be understood that the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. In addition, in the description of the present invention, "a plurality" means two or more unless otherwise specified.
The two-dimensional code uses the concept of binary bit stream in coding, uses a plurality of geometric shapes corresponding to binary to represent literal numerical information, and enables a machine (computer) to identify the coded content. According to the coding form, the two-dimensional code can be divided into a stack type/row type two-dimensional code and a matrix type two-dimensional code. The stacking/row-type two-dimensional code is also called a stacking type two-dimensional code or a row-type two-dimensional code, and the encoding principle is based on a one-dimensional bar code and is stacked into two or more rows according to the requirement. The existing stack/row two-dimensional code includes: code 16K Code, Code 49 Code, PDF417 Code, micro PDF417 Code, etc. The matrix type two-dimensional code is coded in a rectangular space through different distribution of black and white pixels. At the corresponding element position of the matrix, "1" is represented by the presence of a dot (square, circular, or other shape), and "0" is represented by the absence of a dot. The existing matrix type two-dimensional code comprises: QR code (quick response code), Maxi code (Maxicode), data matrix code (DataMatrix).
Fig. 1 is a schematic flow chart of a two-dimensional code generation method according to an embodiment of the present invention. As shown in fig. 1, a two-dimensional code generation method according to an embodiment of the present invention includes:
and S100, generating a reference two-dimensional code image according to the original image and the two-dimensional code data.
And S200, performing style migration on the reference two-dimensional code image according to the original image to generate a first middle two-dimensional code image.
And S300, combining the first intermediate two-dimensional code image and the binary image of the original image to obtain a second intermediate two-dimensional code image.
S400, rendering the second intermediate two-dimensional code image according to the gray-scale image of the original image and the original image to obtain a target two-dimensional code image.
According to the method and the device, a reference two-dimensional code image is generated according to an original image and two-dimensional code data, the reference two-dimensional code image is subjected to style migration according to the original image to generate a first intermediate two-dimensional code image, the first intermediate two-dimensional code image and a binary image of the original image are combined to obtain a second intermediate two-dimensional code image, and finally the second intermediate two-dimensional code image is rendered according to a gray scale image of the original image and the original image to obtain a target two-dimensional code image. Thus, a two-dimensional code image with better visual effect can be obtained.
Fig. 2 is a flowchart of generating a reference two-dimensional code image according to an embodiment of the present invention, and fig. 3 is a schematic diagram of generating a reference two-dimensional code image according to an embodiment of the present invention. As shown in fig. 2 and 3, the generating of the reference two-dimensional code image according to the embodiment of the present invention includes:
and S110, generating a first weight matrix according to the original image, wherein the first weight matrix represents the importance degree of different positions of the original image.
In this embodiment, a comparison function is defined as a location selection policy, and the comparison function may generate a first weight matrix according to the contrast of the original image L, where the first weight matrix represents the importance degree of any location of the original image. Specifically, the user can customize a mask, and areas with darker colors in the mask represent areas with higher importance (regions of interest), and are given higher weight, so that the module controlling the areas is prioritized to keep the original appearance. The lighter colored areas of the mask are given a lower weight.
And S120, generating the reference two-dimensional code image through the first weight matrix according to the original image and the two-dimensional code data.
In the present embodiment, the reference two-dimensional code image Lb is generated based on the RS (Reed-solomon) encoding principle, and is encoded using an RS error correction code, so that the generated two-dimensional code is a QR code, and the QR scanner does not need to correctly see each pixel when scanning the contents of the two-dimensional code, and thus a certain degree of error correction capability and identifiability can be ensured for a limited error code. Furthermore, the specific property of the RS error correction enables some bits in the code stream to be controlled, and the arrangement of the controllable bits can be controlled, so that the generated reference two-dimensional code image can present a shape similar to the original image L. Specifically, bits of the two-dimensional code data are contained in the RS code, each bit corresponds to one pixel in the two-dimensional code, and the pixels are changed by changing the bits of the data, thereby forming a two-dimensional code image having a certain shape.
Specifically, the embodiment of the invention generates a reference two-dimensional code image through a first weight matrix Wm according to an original image L and two-dimensional code data info, wherein the two-dimensional code image is composed of a plurality of black/white lattices, and each black/white lattice is a module. The importance degree of each module is measured through the first weight matrix Wm, the higher the weight is, the higher the priority is, the controllable bits are made, and the arrangement of the controllable bits is controlled, so that the reference two-dimensional code image Lb can present a shape similar to the original image L in the interested area. This may allow for a more natural effect in the subsequent fusion process.
Preferably, the generating of the reference two-dimensional code image Lb from the original image L and the two-dimensional code data info further includes: and preprocessing the original image.
The preprocessing of the original image is to adjust the contrast of different areas of the original image L to different degrees: the contrast of the interesting region is increased, the contrast of the non-interesting region is reduced, the brightness degree of the non-interesting region is polarized, and the interference of the brightness distribution of the original image to the subsequent process is reduced. The formula for image pre-processing is as follows:
CH(x,y)=L(x,y)*αH+βH
CL(x,y)=L(x,y)*αL+βL
L′(x,y)=Wm(x,y)*CH(x,y)+[1-Wm(x,y)]*CL(x,y)
where L (x, y) is the original image luminance value, α H and β H are the adjustment parameters of the region of interest, α L and β L are the adjustment parameters of the non-region of interest, Wm is the first weight matrix, and L' (x, y) is the luminance value of the image after being preprocessed.
Fig. 4 is a flowchart of generating a first intermediate two-dimensional code image according to an embodiment of the present invention, fig. 5 is a schematic diagram of performing style migration on the reference two-dimensional code image according to an embodiment of the present invention, and fig. 6 is a schematic diagram of generating a first intermediate two-dimensional code image according to an embodiment of the present invention. As shown in fig. 4, 5, and 6, performing style migration on the reference two-dimensional code image according to the original image to generate a first intermediate two-dimensional code image includes:
s210, extracting a preset area of each module of the reference two-dimensional code image to generate a black and white dot image, combining the black and white dot image and the original image to generate an accuracy image, and calculating accuracy loss according to the accuracy image;
in this embodiment, the selected predetermined area of each module is the central scanning point of each module, that is, about one third of the area of the center of each module, and when scanning a two-dimensional code, the system only focuses on about one third of the area of the center of each module. And extracting the central scanning point of each module of the reference two-dimensional code Lb to form a black and white dot image, wherein the black and white dot image retains black and white information of the reference two-dimensional code Lb, so that the information of the two-dimensional code can be completely read during scanning. And combining the black and white point image and the original image L to generate an accuracy image La, and calculating accuracy loss according to the accuracy image La, wherein the accuracy loss is calculated by performing mean square error on the content image and the accuracy image La before the content image passes through all the convolution layers, so that convergence can be realized after fewer iteration times in subsequent network calculation.
S220, obtaining a style characteristic image through a convolution neural network according to the original image, and calculating style loss according to the style characteristic image.
And S230, obtaining a content characteristic image through a convolutional neural network according to the reference two-dimensional code image, and calculating the internal capacitive loss according to the content characteristic image.
S240, reconstructing the reference two-dimensional code image according to the accuracy loss, the stylistic loss and the capacitive loss to generate the first middle two-dimensional code image.
In particular, the vgg (visual Geometry group) network is a deep convolutional neural network developed by oxford university computer vision group together with google deep mind (deep thinking) corporation. The VGG network explores the relationship between the depth of the convolutional neural network and its performance, and by repeatedly stacking 3 × 3 small convolutional kernels and 2 × 2 maximum pooling layers, the VGG network successfully constructed 16 to 19 layers of the convolutional neural network. The method comprises the steps of extracting a style characteristic image and a content characteristic image from a calculation layer of a neural network by adopting a pre-trained VGG-16 model, calculating style loss and content loss according to the style characteristic image and the content characteristic image, and reconstructing the content image according to the style loss, the content loss and the accuracy loss to obtain a first middle two-dimensional code image. In the present embodiment, the reference two-dimensional code image Lb is taken as a content image, and the original image L is taken as a genre image. The content feature extraction, reconstruction and loss calculation layer is a fourth convolution layer, the content feature images extracted by the fourth convolution layer are used for calculating the internal capacitive loss, and experiments show that the content feature images of other layers or the arrangement combination of the content feature images have little influence on the result. The style characteristic extraction, reconstruction and loss calculation layers are first, second, third, fourth and fifth convolution layers, style loss is calculated by extracting the style characteristic image through the convolution layers, and because the characteristic image extracted from the depth can keep certain texture of the original image, the shape of the content image is not modified too much, and the readability of the content image is not damaged. As shown in fig. 6, the reference two-dimensional code image is reconstructed from the accuracy loss, the stylistic loss, and the capacitive loss to generate the first intermediate two-dimensional code image Lt.
According to the embodiment of the invention, the style of the reference two-dimensional code image is transferred through the original image, so that the generated first intermediate two-dimensional code image can keep the texture of the original image and the information of the reference two-dimensional code image, and the first intermediate two-dimensional code image with better visual effect is generated.
Fig. 7 is a flowchart of generating a second intermediate two-dimensional code image according to an embodiment of the present invention, fig. 8 is a schematic diagram illustrating a process of generating a second weight matrix according to an embodiment of the present invention, and fig. 9 is a schematic diagram illustrating a process of generating a second intermediate two-dimensional code image according to an embodiment of the present invention. As shown in fig. 7, 8, and 9, combining the first intermediate two-dimensional code image and the binarized image of the original image to obtain a second intermediate two-dimensional code image includes:
and S310, obtaining a noise matrix according to the binarization image of the original image and the reference two-dimensional code image.
Specifically, a binarized image Lp of the original image is acquired, a pixel average value of each module of the binarized image Lp of the original image is calculated, and an absolute value is obtained by subtracting the pixel average value of each module of the binarized image Lp of the original image from the pixel value of each module of the reference two-dimensional code image, so that a noise matrix Wn is obtained. And the noise matrix Wn represents the difference degree between the binarized image of the original image and the reference two-dimensional code image. For each module cell in Wn, a higher brightness indicates a greater degree of difference between the two. The calculation formula of the noise matrix is as follows:
Figure BDA0001878118230000091
where i, j are the subscripts of the blocks, Wn is the noise matrix,
Figure BDA0001878118230000092
being the pixel average value of the binarized image Lp of the original image, Lb (i, j) is the pixel value of each block of the reference two-dimensional code.
And S320, obtaining a second weight matrix through the weighted summation of the noise matrix and the first weight matrix.
Specifically, the noise matrix and the first weight matrix are added by a certain proportion to obtain a second weight matrix. Adding the first weight matrix Wm to the noise matrix Wn may participate in adjusting the weights to a certain extent, so that the weights of the binarized image Lp of the original image are adjusted higher in the region of interest, thus making the combined image closer to the original image. The second weight matrix Ws is calculated as follows:
Ws(i,j)=γ*Wm(i,j)+(1-γ)*Wn(i,j)。
wherein i, j is the subscript of the module, γ is the weight parameter, Ws is the second weight matrix, Wm is the first weight matrix, and Wn is the noise matrix.
S330, combining and binarizing the binarized image of the original image and the first intermediate two-dimensional code image according to the second weight matrix to generate a second intermediate two-dimensional code image.
Specifically, the binarized image Lp of the original image and the first intermediate two-dimensional code image Lt are combined through a second weight matrix Ws and binarized to generate a second intermediate two-dimensional code image Ls.
Although the modules of the second intermediate two-dimensional code image Ls and the reference two-dimensional code image Lb are matched to a large extent, the black and white of the central scanning point at the corresponding position of each module in the second intermediate two-dimensional code image Ls and the reference two-dimensional code image Lb are not completely consistent, and therefore, the method of the embodiment of the invention further comprises the step of pre-correcting the second intermediate two-dimensional code image. Since the system only focuses on about one third of the area in the center of each module when scanning a two-dimensional code, based on this, the second intermediate two-dimensional code image Ls can be pre-corrected by the following method: the center area of each block of the reference two-dimensional code image is sampled by a mask L2 as shown in fig. 9, and the corresponding position in the second intermediate two-dimensional code image Ls is corrected by a mask L1 in accordance with the sample value of the reference two-dimensional code image Lb. And finally obtaining the corrected binary image Lc.
According to the embodiment of the invention, the second middle two-dimensional code image is pre-corrected through the reference two-dimensional code image, so that the black and white of the central scanning point of each position of the second middle two-dimensional code image and the reference two-dimensional code image can be kept completely consistent, and the recognition rate can be improved.
The second intermediate two-dimensional code image mean value is an image Lc after being pre-corrected, which is described below, and it should be understood that the second intermediate two-dimensional code image Lc may be replaced by the image Ls hereinafter.
Fig. 10 is a flowchart of generating a target two-dimensional code image according to an embodiment of the present invention, and fig. 11 is a schematic diagram of generating a target two-dimensional code image according to an embodiment of the present invention. As shown in fig. 9 and 10, the obtaining of the target two-dimensional code image by rendering the second intermediate two-dimensional code image according to the gray scale map of the original image and the original image includes:
s410, combining the gray scale image of the original image and the second intermediate two-dimensional code image according to a third weight matrix to obtain a target two-dimensional code image in the form of a gray scale image.
And weighting and summing the gray scale map Li of the original image and the second intermediate two-dimensional code image Lc according to a third weight matrix Wa to obtain a target two-dimensional code image Lr in a gray scale map form. In the present embodiment, the third weight matrix Wa is equal to the first weight matrix Wm. It should be understood that the third weight matrix Wa may be other weight matrices. The formula for Lr is as follows:
Lr(x,y)=Wa(x,y)*Li(x,y)+[1-Wa(x,y)]*Lc(x,y),
where Lr (x, y) is a pixel value of the target two-dimensional code image, Li (x, y) is a luminance value of the gray scale map of the original image, Lc (x, y) is a pixel value of the second intermediate two-dimensional code image, and Wa is a third weight matrix.
And S420, rendering the target two-dimensional code image in the gray scale pattern form according to the original image to generate a target two-dimensional code image in the color pattern form.
The target two-dimensional code image Lr in the form of a gray pattern is used as L-channel information of the LAB color space, and is combined with the a/B channel separated from the LAB color space of the original image and converted into RGB format, so that the target two-dimensional code image Lr in the form of a color pattern (not shown in the figure) is obtained.
According to the method and the device, a reference two-dimensional code image is generated according to an original image and two-dimensional code data, the reference two-dimensional code image is subjected to style migration according to the original image to generate a first intermediate two-dimensional code image, the first intermediate two-dimensional code image and a binary image of the original image are combined to obtain a second intermediate two-dimensional code image, and finally the second intermediate two-dimensional code image is rendered according to a gray scale image of the original image and the original image to obtain a target two-dimensional code image. Thus, a two-dimensional code image with better visual effect can be obtained.
The recognizable beautified two-dimensional code image can be obtained by the method, and in order to further improve the recognition rate of the obtained target two-dimensional code image, the method of the embodiment of the invention further comprises the following steps:
and S500, performing loop iteration adjustment on the target two-dimensional code image to improve the recognition rate.
Fig. 12 is a flowchart of performing loop iteration adjustment on a target two-dimensional code according to an embodiment of the present invention. As shown in fig. 12, the performing loop iteration adjustment on the target two-dimensional code includes:
and S510, when the accuracy loss is greater than the accuracy loss threshold value and the content loss is greater than the content loss threshold value, calculating an error value, wherein the error value represents the difference degree between the target two-dimensional code image in the form of a gray graph and the reference two-dimensional code image.
Accuracy loss and content loss are introduced in the process of carrying out style migration on the reference two-dimensional code image, and the content loss calculation formula is as follows:
Md(x,y)=abs[Lr(x,y)-Li(x,y)]*Wm(x,y),
LOSSc=∑x,yMd(x,y),
where Lr (x, y) is a pixel value of the target two-dimensional code image Lr in the form of a gray scale map, Li (x, y) is a pixel value of the gray scale map of the original image, Wm is a first weight matrix, and LOSSc is a content loss.
The accuracy loss calculation formula is as follows:
LOSSa=∑i,jMe(i,j)
where LOSSa is the loss of accuracy and Me (i, j) is the error value.
FIG. 13 is a flow chart of calculating an error value according to an embodiment of the present invention. As shown in fig. 13, calculating the error value includes:
and S521, acquiring the pixel gray level average value of each module partial area of the target two-dimensional code image in the form of the gray level graph.
And S522, acquiring the pixel gray level average value of each module partial area of the reference two-dimensional code image.
And S533, calculating an error value according to the pixel gray level average value of each module partial area of the target two-dimensional code image in the form of the gray level graph and the reference two-dimensional code image.
And acquiring the average value of each module pixel of the target two-dimensional code image in the form of gray graph, normalizing, and taking the absolute value of the normalized value and the reference two-dimensional code image to obtain an error value. The error value calculation formula is as follows:
Figure BDA0001878118230000121
Me(i,j)=abs[QLr(i,j)-QLb(i,j)],
where QLr (i, j) is the normalized value and Me (i, j) is the error value.
The accuracy loss calculation formula is as follows:
LOSSa=∑i,jMe(i,j)
among these, LOSSa is a loss of accuracy.
S520, updating the third weight matrix according to the accuracy loss, the content loss and the error value.
The update formula of the third weight matrix is:
Wa(x,y)-=step*{α*LOSSa*Me(x,y)-βLOSSc*[1-Me(x,y)]}。
s530, updating the target two-dimensional code image according to the third weight matrix so as to improve the recognition rate of the target two-dimensional code image.
The method for updating the target two-dimensional code image is the same as the step S410, that is:
and weighting and summing the gray scale map Li of the original image and the second intermediate two-dimensional code image Lc according to the updated third weight matrix Wa to obtain a target two-dimensional code image Lr in the form of a gray scale map.
This can improve the recognition rate of the obtained target two-dimensional code image.
According to the method and the device, a reference two-dimensional code image is generated according to an original image and two-dimensional code data, the reference two-dimensional code image is subjected to style migration according to the original image to generate a first intermediate two-dimensional code image, the first intermediate two-dimensional code image and a binary image of the original image are combined to obtain a second intermediate two-dimensional code image, and finally the second intermediate two-dimensional code image is rendered according to a gray scale image of the original image and the original image to obtain a target two-dimensional code image. Thus, a two-dimensional code image with better visual effect can be obtained.
Fig. 14 is a schematic diagram of an electronic device of an embodiment of the invention. The electronic device shown in fig. 14 is a general-purpose data processing apparatus comprising a general-purpose computer hardware structure including at least a processor 11 and a memory 12. The processor 11 and the memory 12 are connected by a bus 13. The memory 12 is adapted to store instructions or programs executable by the processor 11. The processor 11 may be a stand-alone microprocessor or may be a collection of one or more microprocessors. Thus, processor 11 implements the processing of data and the control of other devices by executing instructions stored by memory 12 to perform the method flows of embodiments of the present invention as described above. The bus 13 connects the above components together, and also connects the above components to a display controller 14 and a display device and an input/output (I/O) device 15. Input/output (I/O) devices 15 may be a mouse, keyboard, modem, network interface, touch input device, motion sensing input device, printer, and other devices known in the art. Typically, the input/output device 15 is connected to the system through an input/output (I/O) controller 16.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus (device) or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-readable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations of methods, apparatus (devices) and computer program products according to embodiments of the application. It will be understood that each flow in the flow diagrams can be implemented by computer program instructions.
These computer program instructions may be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows.
These computer program instructions may also be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
The project is subsidized by independent scientific research plan of Qinghua university.

Claims (9)

1. A two-dimensional code generation method is characterized by comprising the following steps:
generating a reference two-dimensional code image according to the original image and the two-dimensional code data;
performing style migration on the reference two-dimensional code image according to the original image to generate a first middle two-dimensional code image;
combining the first intermediate two-dimensional code image and the binary image of the original image to obtain a second intermediate two-dimensional code image; and
rendering the second intermediate two-dimensional code image according to the gray-scale image of the original image and the original image to obtain a target two-dimensional code image;
wherein combining the first intermediate two-dimensional code image and the binarized image of the original image to obtain a second intermediate two-dimensional code image comprises:
obtaining a noise matrix according to the binarized image of the original image and the reference two-dimensional code image, wherein the noise matrix represents the difference between the binarized image of the original image and the reference two-dimensional code image;
obtaining a second weight matrix through weighted summation of the noise matrix and the first weight matrix; and
and combining and binarizing the binarized image of the original image and the first intermediate two-dimensional code image according to the second weight matrix to generate a second intermediate two-dimensional code image.
2. The two-dimensional code generation method according to claim 1, wherein generating the reference two-dimensional code image from the original image and the two-dimensional code data includes:
generating a first weight matrix according to the original image, wherein the first weight matrix represents the importance degree of different positions of the original image; and
and generating the reference two-dimensional code image through the first weight matrix according to the original image and the two-dimensional code data.
3. The two-dimensional code generation method according to claim 1, wherein performing style migration on the reference two-dimensional code image from the original image to generate a first intermediate two-dimensional code image comprises:
extracting a preset area of each module of the reference two-dimensional code image to generate a black and white dot image, combining the black and white dot image and the original image to generate an accuracy image, and calculating accuracy loss according to the accuracy image;
obtaining a style characteristic image through a convolution neural network according to the original image, and calculating style loss according to the style characteristic image;
obtaining a content characteristic image through a convolutional neural network according to the reference two-dimensional code image, and calculating the internal capacitive loss according to the content characteristic image; and
and reconstructing the reference two-dimensional code image according to the accuracy loss, the stylistic loss and the capacitive loss to generate the first middle two-dimensional code image.
4. The two-dimensional code generation method according to claim 1, further comprising:
and pre-correcting the second middle two-dimensional code image according to the reference two-dimensional code image so as to enable the color of the central scanning point of each module of the second middle two-dimensional code image to be consistent with the reference two-dimensional code image.
5. The two-dimensional code generation method according to claim 1, wherein the obtaining of the target two-dimensional code image from the gray-scale map of the original image and the rendering of the second intermediate two-dimensional code image by the original image comprises:
combining the gray scale image of the original image and the second intermediate two-dimensional code image according to a third weight matrix to obtain a target two-dimensional code image in the form of a gray scale image; and
and rendering the target two-dimensional code image in the form of the gray scale graph according to the original image to generate a target two-dimensional code image in the form of a color graph.
6. The two-dimensional code generation method according to claim 5, further comprising:
and performing loop iteration adjustment on the target two-dimensional code image to improve the recognition rate.
7. The two-dimensional code generation method according to claim 6, wherein performing loop iteration adjustment on the target two-dimensional code image to improve the recognition rate comprises:
in response to the accuracy loss being greater than an accuracy loss threshold and the content loss being greater than a content loss threshold, calculating an error value characterizing a degree of difference between a target two-dimensional code image in the form of a gray scale pattern and the reference two-dimensional code image;
updating the third weight matrix based on the accuracy loss, the content loss, and the error value; and
and updating the target two-dimensional code image according to the third weight matrix so as to improve the recognition rate of the target two-dimensional code image.
8. The two-dimensional code generation method according to claim 7, wherein the calculating the error value includes:
acquiring the pixel gray level average value of a preset area of each module of the target two-dimensional code image in the gray level graph form;
acquiring a pixel gray level average value of a preset area of each module of the reference two-dimensional code image; and
and calculating an error value according to the pixel gray level average value of a preset area of each module of the target two-dimensional code image in the form of the gray level graph and the reference two-dimensional code image.
9. A computer-readable storage medium on which computer program instructions are stored, which, when executed by a processor, implement the method of any one of claims 1-8.
CN201811409345.7A 2018-11-23 2018-11-23 Two-dimensional code generation method and computer-readable storage medium Active CN109492735B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811409345.7A CN109492735B (en) 2018-11-23 2018-11-23 Two-dimensional code generation method and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811409345.7A CN109492735B (en) 2018-11-23 2018-11-23 Two-dimensional code generation method and computer-readable storage medium

Publications (2)

Publication Number Publication Date
CN109492735A CN109492735A (en) 2019-03-19
CN109492735B true CN109492735B (en) 2020-06-09

Family

ID=65696629

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811409345.7A Active CN109492735B (en) 2018-11-23 2018-11-23 Two-dimensional code generation method and computer-readable storage medium

Country Status (1)

Country Link
CN (1) CN109492735B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110751251B (en) * 2019-10-16 2023-10-24 上海掌门科技有限公司 Method and device for generating and transforming two-dimensional code image matrix
CN112241744A (en) * 2020-10-20 2021-01-19 北京字跳网络技术有限公司 Image color migration method, device, equipment and computer readable medium
CN117611953A (en) * 2024-01-18 2024-02-27 深圳思谋信息科技有限公司 Graphic code generation method, graphic code generation device, computer equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103854298A (en) * 2014-02-13 2014-06-11 腾讯科技(深圳)有限公司 Method for integrating pictures with two-dimension codes and terminal
CN108491747A (en) * 2018-02-06 2018-09-04 南京风力舰信息技术有限公司 Beautify the method for QR codes after a kind of blending image
CN108491913A (en) * 2018-02-06 2018-09-04 南京风力舰信息技术有限公司 A method of containing close beautification QR code authentications

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3507773A1 (en) * 2016-09-02 2019-07-10 Artomatix Ltd. Systems and methods for providing convolutional neural network based image synthesis using stable and controllable parametric models, a multiscale synthesis framework and novel network architectures
CN108537776A (en) * 2018-03-12 2018-09-14 维沃移动通信有限公司 A kind of image Style Transfer model generating method and mobile terminal

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103854298A (en) * 2014-02-13 2014-06-11 腾讯科技(深圳)有限公司 Method for integrating pictures with two-dimension codes and terminal
CN108491747A (en) * 2018-02-06 2018-09-04 南京风力舰信息技术有限公司 Beautify the method for QR codes after a kind of blending image
CN108491913A (en) * 2018-02-06 2018-09-04 南京风力舰信息技术有限公司 A method of containing close beautification QR code authentications

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
二维码太丑?用风格迁移生成个性二维码了解一下;机器之心Pro;《百度》;20180309;1-9 *

Also Published As

Publication number Publication date
CN109492735A (en) 2019-03-19

Similar Documents

Publication Publication Date Title
US11704765B2 (en) Artwork generated to convey digital messages, and methods/apparatuses for generating such artwork
CN109376830B (en) Two-dimensional code generation method and device
CN112052839B (en) Image data processing method, apparatus, device and medium
CN109492735B (en) Two-dimensional code generation method and computer-readable storage medium
CN112950661B (en) Attention-based generation method for generating network face cartoon
CN110516201A (en) Image processing method, device, electronic equipment and storage medium
CN110796080A (en) Multi-pose pedestrian image synthesis algorithm based on generation of countermeasure network
JP7303844B2 (en) DATA EXTENSION SYSTEM, DATA EXTENSION METHOD, AND PROGRAM
KR101700818B1 (en) Method and apparatus for estimating age or gender using face image
Fu et al. The secure steganography for hiding images via GAN
EP3809335A1 (en) Image processing device and operation method therefor
CN116416342B (en) Image processing method, apparatus, computer device, and computer-readable storage medium
CN104899629A (en) Two-dimensional code image generation method based on radial basis function
CN116822548B (en) Method for generating high recognition rate AI two-dimensional code and computer readable storage medium
JP2023082065A (en) Method of discriminating objet in image having biometric characteristics of user to verify id of the user by separating portion of image with biometric characteristic from other portion
CN115205624A (en) Cross-dimension attention-convergence cloud and snow identification method and equipment and storage medium
CN114549698A (en) Text synthesis method and device and electronic equipment
Mittal Generating visually appealing QR codes using colour image embedding
CN112861884A (en) Clothing image appearance attribute modification method based on deep learning
CN113205102A (en) Vehicle mark identification method based on memristor neural network
CN117131896B (en) AI two-dimension code generation method and computer readable storage medium
CN117131895B (en) Method for batch generation of unified vision AI two-dimension code and computer readable storage medium
Zhangjie et al. The secure steganography for hiding images via GAN
US20230306550A1 (en) Method for embedding information in a decorative label
CN114332267A (en) Generation method and device of ink-wash painting image, computer equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CB03 Change of inventor or designer information

Inventor after: Wu Tong

Inventor after: Chen Jiansheng

Inventor before: Wu Tong

CB03 Change of inventor or designer information