A three-dimensional code and dynamic code generation method, medium and device
By differentiating odd and even frames in video files and combining foreground region segmentation and saliency image processing, the problems of large computational load and poor real-time code generation in existing technologies are solved, and high-quality 3D codes are generated efficiently.
Patent Information
- Application Number
- CN202310164967.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-24
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2043-02-24
AI Technical Summary
Existing technologies involve large computational loads and poor real-time performance when generating 3D codes, especially when generating video 3D codes, making it difficult to efficiently generate high-quality dynamic 3D codes.
Different methods are used to generate corresponding code images for odd and even frames in video files. The QR code is directly fused for odd frames, while the similarity between the QR code and the dynamic code for even frames is calculated to reduce the amount of computation. Furthermore, the generation efficiency is improved through foreground region segmentation and saliency image processing.
It enables the rapid generation of 3D codes with high similarity to background images, improving generation efficiency and visual effects, reducing computational load, and enhancing code generation quality.
Smart Images

Figure CN116306750B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to a three-dimensional code and a dynamic code generation method, medium and device, and belongs to the dynamic code field. BACKGROUND
[0002] A two-dimensional code is a symbol for representing information in a black-and-white pattern in the horizontal and vertical directions of a plane. A three-dimensional code is a product of fusing a background picture on the basis of a two-dimensional code, and the background picture can be an enterprise logo, a trademark logo, a product logo, a face, an application scenario, etc. The three-dimensional code can provide corresponding data information and visual information. A dynamic display scheme of the three-dimensional code adopts GIF animation or video two-stream media display modes, and the essence of both modes is the sequential playing of a series of static pictures, so that the continuous playing and image effect are generated by using the visual retention principle of the human eye. However, there are certain differences between the two modes. The GIF animation contains a small number of picture frames, and the number of picture frames is less than 100 in the normal case, and the number of pictures played per second (frame rate) is low, so that a certain visual effect is achieved by cyclic playing. The number of picture frames played per second in the video is usually 24 frames, so that a short video of only a few seconds contains a large number of picture frames (generally more than 100 frames), and the background in the video is usually complex, so that the calculation amount is large if the corresponding code picture is generated by processing each frame, and the real-time performance of the dynamic code generation is poor.
[0003] The patent with the publication number CN109934322B discloses a dynamic three-dimensional code generation method, generation device, identification method and identification device, which discloses the following steps: d1. preloading the animation picture; d2. acquiring all image frames of the animation picture; d3. adding a watermark of the picture of the three-dimensional code to each single-frame image to obtain the fused three-dimensional code; and d4. storing the fused three-dimensional code in the gif format. The method has a large calculation amount and poor real-time performance of code generation.
[0004] The patent with the publication number CN106778995B discloses an artistic two-dimensional code generation method and device fused with an image, which discloses the following steps: combining operation codes by using the Gauss Jordan elimination method and the exclusive or operation between the operation codes, adjusting the operation code set, moving the controllable modules of part of the operation codes to the check data area, and preferentially constructing the operation codes for controlling the areas with higher significance; adjusting the encoding data of the two-dimensional code by using the operation code set; and performing the exclusive or operation between the operation code and the encoding data of the two-dimensional code to change the values at the specified positions, so that the color values of the two-dimensional code at the positions correspond to the colors of the corresponding positions of the image binary result Ib. However, the optimization process of the technical solution is complicated, the calculation amount is large, and the real-time performance of code generation is poor. SUMMARY
[0005] In order to overcome the problems in the prior art, the application designs a three-dimensional code and a dynamic code generation method, considering that adjacent frames in a video have a certain similarity, different methods are used to generate corresponding code images for odd frames and even frames in a video file: for odd frames, the similarity is not calculated and the two-dimensional code and the odd frame are directly fused; for even frames, the dynamic code odd frame is taken as an input initial state, and the similarity of the two-dimensional code and the dynamic code odd frame is calculated; without calculating the similarity of each frame of the video file, the calculation amount is reduced, the code generation efficiency is high, and the code generation effect is good.
[0006] In order to achieve the above-mentioned purpose, the application adopts the following technical scheme:
[0007] Technical scheme one
[0008] A three-dimensional code generation method, comprising the following steps:
[0009] Obtaining a video file;
[0010] Taking the first frame of the video file as a first background image;
[0011] Obtaining encoding information; according to the encoding information, generating a first two-dimensional code image;
[0012] Cutting the code points in the first two-dimensional code image into several blocks;
[0013] For each code point in the first two-dimensional code image, setting the color of a block in the code point to be consistent with the color of the code point and randomly setting the colors of other blocks, and repeating the step to obtain a plurality of different second two-dimensional code images;
[0014] Calculating the similarity of the first background image and the plurality of second two-dimensional code images, and outputting the second two-dimensional code image with the highest similarity;
[0015] Fusing the background image and the second two-dimensional code image with the highest similarity to obtain a three-dimensional code.
[0016] Further, it further comprises:
[0017] Extracting a foreground region of the background image; extracting a saliency image of the foreground region; calculating the similarity of the saliency image and the plurality of second two-dimensional code images; fusing the saliency image and the second two-dimensional code image with the highest similarity to obtain a three-dimensional code.
[0018] Further, it further comprises:
[0019] Fusing the second two-dimensional code image and the background image or fusing the second two-dimensional code image and the saliency image to obtain a three-dimensional code.
[0020] Further, the extracting of the saliency image of the foreground region comprises the following specific steps:
[0021] using different Gaussian kernels and convolving the foreground region to obtain a Gaussian smoothing image and the Gaussian smoothing image ; subtracting the Gaussian smoothing image from the Gaussian smoothing image to obtain the saliency image.
[0022] Further, the saliency image and the two-dimensional code image are calculated for similarity, and the specific steps are as follows:
[0023] The saliency image is divided into N windows, and the variance of each window is calculated: according to the window variance, the variance of the saliency image is calculated;
[0024] The two-dimensional code image is divided into N windows, and the variance of each window is calculated: according to the window variance, the variance of the two-dimensional code image is calculated;
[0025] According to the mean of the saliency image and the second two-dimensional code image, the covariance of the second two-dimensional code image and the saliency image is calculated;
[0026] According to the variance and covariance of the saliency image and the second two-dimensional code image, the similarity of the saliency image and the second two-dimensional code image is calculated.
[0027] Further, the variance and covariance of the saliency image and the second two-dimensional code image are calculated for the similarity of the saliency image and the two-dimensional code image, which is expressed in the formula as:
[0028]
[0029] In the formula, represents the covariance of the two-dimensional code image and the saliency image; represents the variance of the saliency image; represents the variance of the two-dimensional code image; represents a constant.
[0030] Technical solution two
[0031] A three-dimensional code generation method, comprising the following steps:
[0032] Obtaining a video file;
[0033] Taking the odd frames of the video file as a first background image;
[0034] Obtaining encoding information; according to the encoding information, generating a first two-dimensional code image;
[0035] Extracting the foreground region of the first background image; extracting the saliency image of the foreground region;
[0036] Fuse the first two-dimensional code image and the saliency image, and output the fusion result.
[0037] Technical solution three
[0038] A three-dimensional code generation method, comprising the following steps:
[0039] Obtaining a video file;
[0040] Taking even frames of the video file as a first background image;
[0041] According to the method of technical solution two, a plurality of fusion results obtained from a plurality of odd frames are obtained.
[0042] Extracting the foreground region of the first background image; extracting the saliency image of the foreground region;
[0043] Calculating the similarity of the saliency image and the plurality of fusion results; outputting the fusion result with the highest similarity.
[0044] Technical solution four
[0045] A dynamic code generation method, comprising the following steps
[0046] S1, obtaining a video file;
[0047] S2, obtaining encoding information; generating a two-dimensional code image according to the encoding information;
[0048] S3, taking the first frame of the video file as a first background image; cutting the code points in the two-dimensional code image into several blocks; setting the color of a certain block in the code point to be consistent with the color of the code point and randomly setting the colors of other blocks, repeating the step to obtain a plurality of different two-dimensional code images; calculating the similarity of the background image and the plurality of two-dimensional code images; outputting the two-dimensional code image with the highest similarity as the first frame of the dynamic code.
[0049] S4, taking the odd frames other than the first frame in the video file as a second background image; extracting the foreground region of the second background image; extracting the saliency image of the foreground region; fusing the two-dimensional code image and the saliency image, and outputting the fusion result as the odd frame of the dynamic code;
[0050] S5, taking the even frames of the video file as a third background image; taking a plurality of fusion results obtained from a plurality of odd frames according to the step S4; extracting the foreground region of the third background image; extracting the saliency image of the foreground region; calculating the similarity of the saliency image and the plurality of fusion results; outputting the fusion result with the highest similarity as the even frame of the dynamic code;
[0051] Combining the first frame of the dynamic code, the odd frame of the dynamic code and the even frame of the dynamic code to obtain the dynamic code.
[0052] Compared with the prior art, the present application has the following characteristics and beneficial effects:
[0053] (1) The present application cuts the code points in the two-dimensional code and fills in colors randomly to obtain multiple two-dimensional codes, and takes the one most similar to the background image in the multiple two-dimensional codes to fuse to obtain a three-dimensional code, which can quickly obtain a code image most similar to the original image, improve the visual effect of the code image, and has small calculation amount.
[0054] (2) The present application performs foreground and background segmentation on the background image, extracts a saliency image of the foreground region by using a DOG algorithm, and can obtain a code image having the most similar structural features to the background image as a three-dimensional code generation result through similarity calculation, thereby improving the artisticity of the code image.
[0055] (3) The present application considers that adjacent frames in a video have certain similarity, and generates corresponding code images by different methods for odd frames and even frames in the video file: for the odd frames, the similarity is not calculated and the two-dimensional code and the odd frame are directly fused; for the even frames, the dynamic code odd frame is taken as an input initial state, and the similarity between the two-dimensional code and the dynamic code odd frame is calculated; without calculating the similarity for each frame of the video file, the calculation amount is reduced, the code generation efficiency is high, and the code generation effect is good. BRIEF DESCRIPTION OF DRAWINGS
[0056] Figure 1 is a flowchart of the present application;
[0057] Figure 2 is a code point cutting schematic diagram;
[0058] Figure 3 is a dynamic code schematic diagram;
[0059] Figure 4 is a three-dimensional code generation flowchart. DETAILED DESCRIPTION
[0060] The present application will be described in more detail below in combination with embodiments.
[0061] Embodiment One
[0062] Considering that the code points and the background image in the three-dimensional code will inevitably affect each other, the fusion effect is relatively harsh. The present embodiment provides a three-dimensional code generation method with better fusion effect, as shown in Figure 4 , which comprises the following steps:
[0063] Obtaining encoding information. According to the encoding information, a two-dimensional code image is generated.
[0064] A background image is acquired. The code points in the two-dimensional code image are cut into several blocks. For each code point in the two-dimensional code image, the color of a block at a certain position in the code point is fixedly set to be consistent with the color of the code point, and the colors of other blocks are randomly set, and the step is repeated to obtain a plurality of different two-dimensional code images. When identifying the two-dimensional code, the color of the block at the fixed position is determined as the color of the code point.
[0065] As shown in Figure 2 , for the four code points representing 0110, each code point is cut into a 3x3 grid; the color of the grid at the central position is set to be consistent with the color of the code point, and the colors of other blocks are randomly set to be black or white.
[0066] The similarity of the background image and the plurality of two-dimensional code images is calculated; and the two-dimensional code image with the highest similarity is output. The background image and the second two-dimensional code image with the highest similarity are fused to obtain a three-dimensional code.
[0067] Embodiment Two
[0068] A three-dimensional code generation method, comprising the following steps:
[0069] A background image is acquired.
[0070] The foreground region of the background image is extracted.
[0071] The saliency image of the foreground region is extracted:
[0072] (1) Different Gaussian kernels and are used to convolve the foreground region to obtain Gaussian smoothing images and In this embodiment, it is set that .
[0073]
[0074]
[0075] In the formula, I(x,y) represents the value of the image at point (x,y); , , respectively represent Gaussian kernels and Gaussian convolution functions.
[0076] (2) Subtracting from to obtain a saliency image with removed high-frequency noise and enhanced edges:
[0077]
[0078]
[0079]
[0080]
[0081] Obtaining encoding information. According to the encoding information, a two-dimensional code image is generated.
[0082] The code points in the two-dimensional code image are divided into several blocks. For each code point in the two-dimensional code image, the color of the block at a certain position in the code point is fixedly set to be consistent with the color of the code point, and the colors of other blocks are randomly set, and the step is repeated to obtain a plurality of different two-dimensional code images.
[0083] The similarity of the saliency image and the plurality of different two-dimensional code images is calculated; the saliency image and the second two-dimensional code image with the highest similarity are fused to obtain a three-dimensional code.
[0084] Embodiment three
[0085] The similarity of the saliency image and the two-dimensional code image is calculated, and the specific steps are as follows:
[0086] (1) The saliency image is divided into N windows by using a sliding window, and the mean and variance of each window are calculated:
[0087]
[0088]
[0089] In the formula, represents the weight corresponding to the pixel value of the pixel point (i, j); represents the pixel value of the pixel point (i, j); represents the window height; represents the window width.
[0090] (2) The variance of the saliency image is calculated:
[0091]
[0092] In the formula, represents the variance of the sliding window; N represents the number of sliding windows.
[0093] (3) Similarly, the two-dimensional code image is divided into N windows by using a sliding window, and the mean and variance of each window are calculated; the variance of the two-dimensional code image is calculated;
[0094] (4) The covariance of the two-dimensional code image and the saliency image is calculated:
[0095] )
[0096] S95, calculate structural similarity of two images:
[0097]
[0098] wherein, denotes covariance of the two-dimensional code image and the saliency image; denotes variance of the saliency image; denotes variance of the two-dimensional code image; denotes a constant.
[0099] Embodiment four
[0100] The present application provides a dynamic code generation method, as shown in the following steps: Figures 1-3
[0101] S1, obtaining a video file;
[0102] S2, obtaining encoding information; generating a two-dimensional code image according to the encoding information;
[0103] S3, taking the first frame of the video file as a first background image; dividing the code points in the two-dimensional code image into several blocks; setting the color of a block in a code point to be consistent with the color of the code point and randomly setting the colors of other blocks, repeating the step to obtain a plurality of different two-dimensional code images; calculating the similarity of the background image and the plurality of different two-dimensional code images; outputting the two-dimensional code image with the highest similarity as the first frame of the dynamic code.
[0104] S4, taking the odd frames other than the first frame in the video file as a second background image; extracting the foreground region of the second background image; extracting the saliency image of the foreground region; fusing the two-dimensional code image and the saliency image, and outputting the fusion result as the odd frame of the dynamic code;
[0105] S5, taking the even frames of the video file as a third background image; taking a plurality of fusion results obtained from a plurality of odd frames according to the step S4; extracting the foreground region of the third background image; extracting the saliency image of the foreground region; calculating the similarity of the saliency image and the plurality of fusion results; outputting the fusion result with the highest similarity as the even frame of the dynamic code.
[0106] S6, combining the first frame of the dynamic code, the odd frame of the dynamic code and the even frame of the dynamic code to obtain the dynamic code.
[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and are not limited to the scope of protection of the present application. Although the present application has been described in detail with reference to the preferred embodiments, those skilled in the art should analyze that the technical solutions of the present application can be modified or replaced by equivalents without departing from the essence and scope of the technical solutions of the present application.
Claims
1. A dynamic code generation method, characterized by, The method comprises the following steps: acquiring a video file; acquiring encoding information; generating a first two-dimensional code image according to the encoding information; dividing code points in the first two-dimensional code image into a plurality of blocks; setting the color of a block in a code point to be consistent with the color of the code point and randomly setting the colors of other blocks, repeating the step to obtain a plurality of different second two-dimensional code images; taking the first frame of the video file as a first background image; calculating the similarity between the first background image and the plurality of second two-dimensional code images; outputting the second two-dimensional code image with the highest similarity as the first frame of the dynamic code; taking the odd frames other than the first frame in the video file as second background images; fusing the second background images and the second two-dimensional code images, and outputting the fusion results as the odd frames of the dynamic code; taking the even frames of the video file as third background images; taking a plurality of fusion results obtained from a plurality of odd frames; calculating the similarity between the third background images and the plurality of fusion results; outputting the fusion result with the highest similarity as the even frame of the dynamic code; combining the first frame of the dynamic code, the odd frames of the dynamic code, and the even frames of the dynamic code to obtain the dynamic code.
2. The dynamic code generation method of claim 1, wherein, Further comprising: extracting the foreground region of the first background image; extracting the saliency image of the foreground region; calculating the similarity between the saliency image and the plurality of second two-dimensional code images; outputting the second two-dimensional code image with the highest similarity to the saliency image as the first frame of the dynamic code.
3. The dynamic code generation method of claim 2, wherein, The specific steps of calculating the similarity between the saliency image and the second two-dimensional code image are as follows: dividing the saliency image into N windows, calculating the variance of each window; calculating the variance of the saliency image according to the window variance; dividing the second two-dimensional code image into N windows, calculating the variance of each window; calculating the variance of the second two-dimensional code image according to the window variance; calculating the covariance between the second two-dimensional code image and the saliency image according to the mean values of the saliency image and the second two-dimensional code image; calculating the similarity between the saliency image and the second two-dimensional code image according to the variances and covariance of the saliency image and the second two-dimensional code image.
Citation Information
Patent Citations
An artistic QR code generation method and device that integrates with images
CN106778995B
Methods, apparatus for generating dynamic 3D codes, methods and apparatus for recognizing them.
CN109934322B
Two dimensional code and method of creating same
CN104346640A