CN112163443A - Code scanning method, code scanning device and mobile terminal - Google Patents

Code scanning method, code scanning device and mobile terminal Download PDF

Info

Publication number
CN112163443A
CN112163443A CN202011125549.5A CN202011125549A CN112163443A CN 112163443 A CN112163443 A CN 112163443A CN 202011125549 A CN202011125549 A CN 202011125549A CN 112163443 A CN112163443 A CN 112163443A
Authority
CN
China
Prior art keywords
dimensional code
image
code
gray
scanning
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.)
Withdrawn
Application number
CN202011125549.5A
Other languages
Chinese (zh)
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.)
Individual
Original Assignee
Individual
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 Individual filed Critical Individual
Priority to CN202011125549.5A priority Critical patent/CN112163443A/en
Publication of CN112163443A publication Critical patent/CN112163443A/en
Withdrawn legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/14Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation using light without selection of wavelength, e.g. sensing reflected white light
    • G06K7/1404Methods for optical code recognition
    • G06K7/146Methods for optical code recognition the method including quality enhancement steps
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/14Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation using light without selection of wavelength, e.g. sensing reflected white light
    • G06K7/1404Methods for optical code recognition
    • G06K7/1439Methods for optical code recognition including a method step for retrieval of the optical code
    • G06K7/1443Methods for optical code recognition including a method step for retrieval of the optical code locating of the code in an image

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Electromagnetism (AREA)
  • General Health & Medical Sciences (AREA)
  • Toxicology (AREA)
  • Artificial Intelligence (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Image Processing (AREA)

Abstract

The invention relates to the technical field of two-dimensional code scanning, and discloses a code scanning method, which comprises the following steps: acquiring a two-dimensional code image containing a two-dimensional code, and graying the two-dimensional code image by using a weighted average method to obtain a two-dimensional code grayscale image; performing noise reduction processing on the two-dimensional code gray image by using a bilateral filtering algorithm to obtain a noise-reduced two-dimensional code gray image; carrying out binarization processing on the two-dimensional code gray level image subjected to noise reduction by using an improved binarization algorithm to obtain a binarization image of the two-dimensional code; positioning the two-dimensional code by using a dynamic two-dimensional code positioning algorithm to obtain the area of the two-dimensional code; and decoding the two-dimensional code by using a two-dimensional code decoding method according to the area of the two-dimensional code to obtain a code scanning result of the two-dimensional code. The invention also provides a code scanning device and a mobile terminal. The invention realizes the scanning of the two-dimensional code.

Description

Code scanning method, code scanning device and mobile terminal
Technical Field
The invention relates to the technical field of two-dimensional code scanning, in particular to a code scanning method, a code scanning device and a mobile terminal.
Background
With the rapid development of computer technology and the gradual popularization of intelligent devices, two-dimensional code recognition technology comes to the fore as a medium for information transmission, two-dimensional codes are applied to aspects of production and life such as market supermarkets, industrial production lines, postal express and the like, and scanning and recognition of two-dimensional codes become hot topics in the current research field.
For the identification of the two-dimensional code, an image type identification device provided with a camera is usually adopted, and the two-dimensional code is matched with appropriate identification software to be identified. In ordinary life, this kind of equipment simple structure, the low price, need guarantee the relative stillness of identification equipment and two-dimensional code just can discern the two-dimensional code with higher rate of accuracy. However, in industrial production, in order to ensure that the two-dimensional code image acquired by the device is clear and stable, a high-speed camera is often used as an image acquisition module of the device, and the method can identify the two-dimensional code with high accuracy, but the device is expensive and is difficult to popularize.
Meanwhile, in the actual use process, the collected two-dimensional code image often has the problems of uneven illumination, inclination, distortion and the like, which brings great challenges to the identification of the two-dimensional code.
In view of this, how to more efficiently scan and identify the two-dimensional code becomes an urgent problem to be solved by those skilled in the art.
Disclosure of Invention
The invention provides a code scanning method, which improves the traditional image binarization processing method, ensures the detail information of a two-dimensional code image after binarization processing, and utilizes a dynamic two-dimensional code positioning method to position a dynamic two-dimensional code, thereby decoding the two-dimensional code according to the positioning result of the two-dimensional code.
In order to achieve the above object, the present invention provides a code scanning method, including:
acquiring a two-dimensional code image containing a two-dimensional code, and graying the two-dimensional code image by using a weighted average method to obtain a two-dimensional code grayscale image;
performing noise reduction processing on the two-dimensional code gray image by using a bilateral filtering algorithm to obtain a noise-reduced two-dimensional code gray image;
carrying out binarization processing on the two-dimensional code gray level image subjected to noise reduction by using an improved binarization algorithm to obtain a binarization image of the two-dimensional code;
positioning the two-dimensional code by using a dynamic two-dimensional code positioning algorithm to obtain the area of the two-dimensional code;
and decoding the two-dimensional code by using a two-dimensional code decoding method according to the area of the two-dimensional code to obtain a code scanning result of the two-dimensional code.
Optionally, the graying the two-dimensional code image by using the weighted average method includes:
graying the two-dimensional code image by using a weighted average method, wherein the formula of the weighted average method is as follows:
Gray(i,j)=R(i,j)×0.299+G(i,j)×0.587+B(i,j)×0.114
wherein:
R(i,j),G(i,j),B(i,j)the pixel values of the two-dimensional code image pixel (i, j) on the three color channels of R, G and B are obtained;
Gray(i,j)is the gray value of the two-dimensional code image pixel (i, j).
Optionally, the performing noise reduction processing on the two-dimensional code grayscale image by using a bilateral filtering algorithm includes:
the bilateral filtered image g (x, y) may be represented as:
Figure BDA0002733505880000021
W(x,y,m,n)=Gd(x,y,m,n)×Gr(x,y,m,n)
Figure BDA0002733505880000022
Figure BDA0002733505880000023
wherein:
f (x, y) is a two-dimensional code gray image with the pixel point (x, y) as the center;
(m, n) is a neighborhood pixel with (x, y) as a center pixel point, and the set of the neighborhood pixels is S;
w (x, y, m, n) is the weight coefficient of each point of the filter;
Gd(x, y, m, n) is spatial similarity;
Gr(x, y, m, n) is the gray scale similarity;
σd,σrrespectively, distance and standard deviation of gray scale based on gaussian kernel function.
Optionally, the binarizing processing the two-dimensional code grayscale image after noise reduction by using an improved binarizing algorithm includes:
1) traversing all gray values of the two-dimensional code gray image, and recording the gray value which enables the inter-class variance target function value to be maximum as a global threshold T1
2) Let T equal 0.5 × (T)1+128), where f (x, y) is the gray value of the current pixel (x, y), and the average value T of the maximum gray value M and the minimum gray value N in all gray values in the window with the pixel size of (2w +1) × (2w +1) and the current pixel as the center is calculated2The invention sets w to 1;
3) calculating the average value of all gray values in the window
Figure BDA0002733505880000033
And mean square error C:
Figure BDA0002733505880000031
Figure BDA0002733505880000032
4) let T be aT1+bT2And b is greater than or equal to 0, a is greater than or equal to 1, b is greater than or equal to 0, and the two-dimensional code gray level image pixels are subjected to point-by-point binarization processing according to the processing rule:
if C is greater than or equal to S, when T is1T ≧ T, f (x, y) ═ 255, when T1<T,f(x,y)=0;
If C is less than S, when T2T ≧ T, f (x, y) ═ 255, when T2<T,f(x,y)=0;
Wherein:
s is a threshold parameter set by the invention, and the value of S is 15;
c is the mean square error of all gray values in the window;
f (x, y) is the gray value of the current pixel (x, y).
Optionally, the positioning the two-dimensional code by using a dynamic two-dimensional code positioning algorithm includes:
1) carrying out convolution operation on the binary image by utilizing 5 convolution cores with the size of 3 multiplied by 3 pixels, and carrying out down-sampling operation after each convolution operation to obtain a sampling characteristic diagram of the binary image;
2) using convolution cores with different expansion rates to carry out cavity convolution on the sampling characteristic diagram to obtain a cavity convolution characteristic diagram, wherein the distribution of the expansion rates follows the combination form of sawtooth waves, and a plurality of layers with increased expansion rates are combined together;
3) performing convolution operation on the cavity convolution characteristic graph by using a convolution kernel with dimensions of 3 multiplied by 1024; then expanding the channel number by using a convolution kernel with the convolution kernel size of 1 multiplied by 5070 dimensionality; then, carrying out average pooling operation to obtain a tensor with dimensions of 1 multiplied by 5070; and finally, outputting the feature map with the tensor transformation dimensionality of 13 multiplied by 30 dimensionality, wherein the finally output feature map is the feature map of the area where the two-dimensional code is located.
Optionally, the decoding the two-dimensional code by using the two-dimensional code decoding method includes:
1) according to the structure of the two-dimensional code, the upper right corner of the two-dimensional code contains the version information of the two-dimensional code, the lower left corner of the two-dimensional code is a two-dimensional code position detection image, and a sampling network of the two-dimensional code version information is obtained by intercepting the upper right corner area of the two-dimensional code;
2) determining the grade of the two-dimensional code version according to a sampling network of the two-dimensional code version information, and correcting the error version information module, wherein the error correction mechanism is based on an RS error correction principle;
3) establishing a sampling grid on a two-dimensional code area image, wherein a plurality of cross points are arranged in the sampling grid, the points are sampled, the dark color is represented by binary number '1', and the light color is represented by binary number '0', so that a brand-new bitmap is generated, namely a two-dimensional code symbol is represented by a matrix;
4) eliminating the mask, namely performing exclusive-or operation on the coding region of the two-dimensional code and the mask graph to obtain a data code word and an error correction code word, and then rearranging the data code word and the error correction code word;
5) error checking is carried out on the code words, and substitution errors, read rejection errors and the like are corrected;
6) and reassembling the sequence of the error-corrected code words to form a bit stream which is the same as the data coding so as to realize the decoding operation.
In addition, to achieve the above object, the present invention further provides a code scanning apparatus, including:
the two-dimensional code acquisition device is used for acquiring a two-dimensional code image and carrying out gray processing on the two-dimensional code image;
the two-dimensional code processor is used for carrying out noise reduction processing on the two-dimensional code image by utilizing a bilateral filtering algorithm and carrying out binarization processing on the two-dimensional code image subjected to noise reduction by utilizing an improved binarization algorithm to obtain a binarization image of the two-dimensional code;
and the code scanning device is used for positioning the two-dimensional code by utilizing a dynamic two-dimensional code positioning algorithm to obtain the area where the two-dimensional code is located, and decoding the two-dimensional code by utilizing a two-dimensional code decoding method to obtain the code scanning result of the two-dimensional code.
In addition, to achieve the above object, the present invention also provides a mobile terminal, including:
the mobile terminal antenna is used for transmitting the two-dimensional code image to the code scanning device and receiving a code scanning result;
the mobile terminal camera is used for acquiring a two-dimensional code image;
the mobile terminal rear cover is used for accommodating a circuit main board of the mobile terminal, a mobile terminal antenna and a mobile terminal camera.
In addition, to achieve the above object, the present invention further provides a computer readable storage medium, which stores code scanning program instructions, where the code scanning program instructions are executable by one or more processors to implement the steps of the code scanning implementation method as described above.
Compared with the prior art, the invention provides a code scanning method, which has the following advantages:
firstly, most of the traditional image binarization methods are Otsu algorithms, the methods are simple and efficient, are not sensitive to noise, but have a large number of burr phenomena, and even all (1) white or all (0) black can occur in an area with over-strong or over-weak illumination, so that details of a part of the area are lost. Therefore, the invention improves the traditional image binarization method, introduces a global threshold value into a local threshold value method, associates information in each window with the whole image information, introduces the mean square error of all gray values in the window into an algorithm, and performs point-by-point binarization processing on pixels of the two-dimensional code gray image by setting a processing rule, wherein the processing rule is as follows:
if C is greater than or equal to S, when T is1T ≧ T, f (x, y) ═ 255, when T1<T,f(x,y)=0;
If C is less than S, when T2T ≧ T, f (x, y) ═ 255, when T2<T,f(x,y)=0;
Wherein: s is a threshold parameter set by the invention, and the value of S is 15; c is the mean square error of all gray values in the window; f (x, y) is the gray value of the current pixel (x, y); t is1Is a global threshold, T2The average value of the maximum gray value M and the minimum gray value N in the gray values in the local window is obtained. When C is larger than or equal to S, the gray value in the window is wider, the pixel is in a foreground and background crossing region, and at the moment, the global threshold value is taken as the threshold value, so that the edge is smoother; when C is less than S, the gray value in the window is more concentrated, the pixel is in the foreground or background area, and T is used2As a threshold value to prevent misclassification and avoid white spots or black spots. Therefore, the algorithm of the invention is more reasonable than using a single threshold value by selecting a proper weight value to binarize the gray level image, so that the obtained two-dimensional code binarized image is more complete and has less noise, and the method is beneficial to subsequent two-dimensional code scanning and decoding processing.
The conventional convolution network structure of the target detection model is based on convolution-pooling-convolution-pooling design, but as the network structure deepens, although the receptive field of the following feature map continuously increases, the resolution of the picture is indeed gradually reduced, so that the network structure has poor effect on the detection of small targets. Therefore, the invention improves the traditional target detection model, provides a dynamic two-dimensional code positioning algorithm, enlarges the receptive field of the characteristic diagram by setting different expansion rates to the convolution kernel, realizes the cavity convolution, and compared with the traditional convolution, the cavity convolution can enlarge the receptive field of the network and increase the resolution of the image under the condition of not increasing the number of model parameters so as to gather more overall information and reduce the maximum pooling layer used by the model. However, as the sparsity of the hole convolution increases, the high-level feature map can be sparsely sampled, that is, the input image information is lost when the hole convolution is used, so the present invention proposes a hole convolution mixing scheme, after the down sampling is used, the same expansion rate is not used for all layers, but different expansion rates are used for different layers, wherein the expansion rate of the 0 th layer is 1, which is equivalent to the common convolution, and the distribution of the expansion rates follows the combination form of sawtooth waves, so that the information incoherence or mutual interference caused by the large change of the expansion rates is avoided, the expansion rates of the 1 st layer to the 3 rd layer are 1.2 times of the expansion rate of the previous layer, and the expansion rates of the 4 th layer to the 6 th layer are 0.7 times of the previous layer, when the expansion rates increase, the perception field of the feature map also increases, thereby effectively capturing the whole information of the two-dimensional code, however, the characteristic diagram is gridded due to the overlarge expansion rate, and 75% of local information is lost when the expansion rate is 2, so that the expansion rate is gradually reduced from the 4 th layer to the 6 th layer, the local information of the two-dimensional code is captured, the information loss is avoided, and the accuracy of the two-dimensional code region identification is improved.
Drawings
Fig. 1 is a schematic flowchart of a code scanning method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a code scanning apparatus according to an embodiment of the present invention;
the implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The method has the advantages that the traditional image binarization processing method is improved, the detail information of the two-dimensional code image after binarization processing is guaranteed, a dynamic two-dimensional code positioning method is used for positioning the dynamic two-dimensional code, and therefore decoding processing of the two-dimensional code is carried out according to the positioning result of the two-dimensional code. Fig. 1 is a schematic diagram of a code scanning method according to an embodiment of the present invention.
In this embodiment, the code scanning method includes:
and S1, acquiring a two-dimensional code image containing the two-dimensional code, and graying the two-dimensional code image by using a weighted average method to obtain a two-dimensional code grayscale image.
Firstly, the invention obtains a two-dimensional code image containing a two-dimensional code, and grays the two-dimensional code image by using a weighted average method, wherein the formula of the weighted average method is as follows:
Gray(i,j)=R(i,j)×0.299+G(i,j)×0.587+B(i,j)×0.114
wherein:
R(i,j),G(i,j),B(i,j)the pixel values of the two-dimensional code image pixel (i, j) on the three color channels of R, G and B are obtained;
Gray(i,j)is the gray value of the two-dimensional code image pixel (i, j).
And S2, performing noise reduction processing on the two-dimensional code gray image by using a bilateral filtering algorithm to obtain the two-dimensional code gray image subjected to noise reduction.
Further, the invention utilizes bilateral filtering algorithm to perform noise reduction processing on the two-dimensional code gray image to obtain the two-dimensional code gray image after noise reduction, and the image g (x, y) subjected to bilateral filtering can be expressed as:
Figure BDA0002733505880000071
W(x,y,m,n)=Gd(x,y,m,n)×Gr(x,y,m,n)
Figure BDA0002733505880000072
Figure BDA0002733505880000073
wherein:
f (x, y) is a two-dimensional code gray image with the pixel point (x, y) as the center;
(m, n) is a neighborhood pixel with (x, y) as a center pixel point, and the set of the neighborhood pixels is S;
w (x, y, m, n) is the weight coefficient of each point of the filter;
Gd(x, y, m, n) is spatial similarity;
Gr(x, y, m, n) is the gray scale similarity;
σd,σrrespectively, distance and standard deviation of gray scale based on gaussian kernel function.
At the position where the gray scale of the image pixel is not changed much, the gray scale value of each point is not different much, G r1, which in this case corresponds to gaussian filtering. G is at the position of the image gray value mutation, such as the corner point and the edge of the two-dimensional code, when the central pixel point and the neighborhood point are at the same side of the edgerTrend to 1; when the two sides of the edge are in the same gray value difference, GrTo 0; only neighborhood points with similar gray values are used to calculate the weights. Therefore, the bilateral filtering method can filter noise and protect edge information from loss.
And S3, carrying out binarization processing on the two-dimensional code gray level image subjected to noise reduction by using an improved binarization algorithm to obtain a binarization image of the two-dimensional code.
Further, the invention performs binarization processing on the two-dimensional code gray level image after noise reduction by using an improved binarization algorithm to obtain a binarization image of the two-dimensional code, wherein the process of performing binarization processing on the two-dimensional code gray level image after noise reduction by using the improved binarization algorithm comprises the following steps:
1) traversing all gray values of the two-dimensional code gray image, and recording the gray value which enables the inter-class variance target function value to be maximum as a global threshold T1
2) Let T equal 0.5 × (T)1+128), where f (x, y) is the gray value of the current pixel (x, y), and the average value T of the maximum gray value M and the minimum gray value N in all gray values in the window with the pixel size of (2w +1) × (2w +1) and the current pixel as the center is calculated2The invention sets w to 1;
3) calculating the average value of all gray values in the window
Figure BDA0002733505880000076
And mean square error C:
Figure BDA0002733505880000074
Figure BDA0002733505880000075
4) let T be aT1+bT2And b is greater than or equal to 0, a is greater than or equal to 1, b is greater than or equal to 0, and the two-dimensional code gray level image pixels are subjected to point-by-point binarization processing according to the processing rule:
if C is greater than or equal to S, when T is1T ≧ T, f (x, y) ═ 255, when T1<T,f(x,y)=0;
If C is less than S, when T2T ≧ T, f (x, y) ═ 255, when T2<T,f(x,y)=0;
Wherein:
s is a threshold parameter set by the invention, and the value of S is 15;
c is the mean square error of all gray values in the window;
f (x, y) is the gray value of the current pixel (x, y).
And S4, positioning the two-dimensional code by using a dynamic two-dimensional code positioning algorithm to obtain the area of the two-dimensional code.
Furthermore, the invention positions the two-dimensional code by using a dynamic two-dimensional code positioning algorithm, wherein the process of positioning the two-dimensional code by using the dynamic two-dimensional code positioning algorithm comprises the following steps:
1) carrying out convolution operation on the binary image by utilizing 5 convolution cores with the size of 3 multiplied by 3 pixels, and carrying out down-sampling operation after each convolution operation to obtain a sampling characteristic diagram of the binary image;
2) using convolution cores with different expansion rates to carry out cavity convolution on the sampling characteristic diagram to obtain a cavity convolution characteristic diagram, wherein the distribution of the expansion rates follows the combination form of sawtooth waves, and a plurality of layers with increased expansion rates are combined together; in a specific embodiment of the invention, the expansion ratio of the 0 th layer is 1, which is equivalent to a common convolution, and the expansion ratio distribution follows a sawtooth wave combination form, so that the situation that information is irrelevant or interfered with each other due to large change of the expansion ratio is avoided, the expansion ratio from the 1 st layer to the 3 rd layer is 1.2 times of the expansion ratio of the previous layer, and the expansion ratio from the 4 th layer to the 6 th layer is 0.7 times of the previous layer, when the expansion ratio is increased, the sensitivity field of the characteristic diagram is also increased, so that the overall information of the two-dimensional code is effectively captured, but as the characteristic diagram is gridded due to the excessive expansion ratio, and 75% of local information is lost when the expansion ratio is 2, the expansion ratio is gradually reduced from the 4 th layer to the 6 th layer, so that the local information of the two-dimensional code is captured;
3) performing convolution operation on the cavity convolution characteristic graph by using a convolution kernel with dimensions of 3 multiplied by 1024; then expanding the channel number by using a convolution kernel with the convolution kernel size of 1 multiplied by 5070 dimensionality; then, carrying out average pooling operation to obtain a tensor with dimensions of 1 multiplied by 5070; and finally, outputting the feature map with the tensor transformation dimensionality of 13 multiplied by 30 dimensionality, wherein the finally output feature map is the feature map of the area where the two-dimensional code is located.
And S5, decoding the two-dimensional code by using a two-dimensional code decoding method according to the area of the two-dimensional code to obtain a code scanning result of the two-dimensional code.
Further, according to the area of the two-dimensional code, the two-dimensional code is decoded by a two-dimensional code decoding method to obtain a code scanning result of the two-dimensional code, and the two-dimensional code decoding method comprises the following steps:
1) according to the structure of the two-dimensional code, the upper right corner of the two-dimensional code contains the version information of the two-dimensional code, the lower left corner of the two-dimensional code is a two-dimensional code position detection image, and a sampling network of the two-dimensional code version information is obtained by intercepting the upper right corner area of the two-dimensional code;
2) determining the grade of the two-dimensional code version according to a sampling network of the two-dimensional code version information, and correcting the error version information module, wherein the error correction mechanism is based on an RS error correction principle;
3) establishing a sampling grid on a two-dimensional code area image, wherein a plurality of cross points are arranged in the sampling grid, the points are sampled, the dark color is represented by binary number '1', and the light color is represented by binary number '0', so that a brand-new bitmap is generated, namely a two-dimensional code symbol is represented by a matrix;
4) eliminating the mask, namely performing exclusive-or operation on the coding region of the two-dimensional code and the mask graph to obtain a data code word and an error correction code word, and then rearranging the data code word and the error correction code word;
5) error checking is carried out on the code words, and substitution errors, read rejection errors and the like are corrected;
6) and reassembling the sequence of the error-corrected code words to form a bit stream which is the same as the data coding so as to realize the decoding operation.
The following describes embodiments of the present invention through an algorithmic experiment and tests of the inventive treatment method. The hardware test environment of the algorithm of the invention is as follows: the processor is Intercore i5-44603.2GHz, the memory is 32G, the programming language is python3.7, and the computing framework is Tensorflow; the comparison method is a code scanning method based on YOLOv2, a code scanning method based on Fast-RCNN and a code scanning method based on R-CNN.
In the algorithm experiment, the data set is a plurality of collected two-dimensional code images. In the experiment, the two-dimension code image is input into the algorithm model, and the accuracy of code scanning of the two-dimension code is used as an index for evaluating the algorithm model.
According to the experimental result, the code scanning accuracy of the code scanning method based on YOLOv2 is 89.32%, the code scanning accuracy of the code scanning method based on Fast-RCNN is 90.32%, the code scanning accuracy of the code scanning method based on R-CNN is 87.68%, the code scanning accuracy of the algorithm is 92.21%, and compared with a comparison algorithm, the code scanning method provided by the invention has higher code scanning accuracy.
The invention also provides a code scanning device. Fig. 2 is a schematic diagram of an internal structure of a code scanning apparatus according to an embodiment of the present invention.
In this embodiment, the code scanning device 1 at least includes a two-dimensional code acquisition device 11, a two-dimensional code processor 12, a code scanning device 13, a communication bus 14, and a network interface 15.
The two-dimensional code acquisition device 11 may be a PC (Personal Computer), a terminal device such as a smart phone, a tablet Computer, and a portable Computer, or a server.
The two-dimensional code processor 12 includes at least one type of readable storage medium including flash memory, hard disk, multi-media card, card type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, and the like. The two-dimensional code processor 12 may in some embodiments be an internal storage unit of the code-scanning apparatus 1, such as a hard disk of the code-scanning apparatus 1. The two-dimensional code processor 12 may be an external storage device of the code scanner 1 in other embodiments, such as a plug-in hard disk provided on the code scanner 1, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Further, the two-dimensional code processor 12 may also include both an internal storage unit of the code-scanning apparatus 1 and an external storage device. The two-dimensional code processor 12 can be used not only to store application software and various types of data installed in the code scanning apparatus 1, but also to temporarily store data that has been output or is to be output.
The code scanning device 13 may be a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor or other data Processing chip in some embodiments, and is used for executing program codes stored in the two-dimensional code processor 12 or Processing data, such as code scanning program instructions.
The communication bus 14 is used to enable connection communication between these components.
The network interface 15 may optionally comprise a standard wired interface, a wireless interface (e.g. WI-FI interface), typically used for establishing a communication connection between the apparatus 1 and other electronic devices.
Optionally, the apparatus 1 may further comprise a user interface, which may comprise a Display (Display), an input unit such as a Keyboard (Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the code scanning apparatus 1 and for displaying a visual user interface.
While figure 2 only shows the device 1 with the components 11-15 and the code scanning device, it will be understood by those skilled in the art that the structure shown in figure 1 does not constitute a limitation of the code scanning device 1, and may include fewer or more components than shown, or some components in combination, or a different arrangement of components.
In the embodiment of the apparatus 1 shown in fig. 2, the two-dimensional code processor 12 stores therein code scanning program instructions; the steps of the code scanning device 13 executing the code scanning program instructions stored in the two-dimensional code processor 12 are the same as the implementation method of the code scanning method, and are not described here.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, where code scanning program instructions are stored on the computer-readable storage medium and executable by one or more processors to implement the following operations:
acquiring a two-dimensional code image containing a two-dimensional code, and graying the two-dimensional code image by using a weighted average method to obtain a two-dimensional code grayscale image;
performing noise reduction processing on the two-dimensional code gray image by using a bilateral filtering algorithm to obtain a noise-reduced two-dimensional code gray image;
carrying out binarization processing on the two-dimensional code gray level image subjected to noise reduction by using an improved binarization algorithm to obtain a binarization image of the two-dimensional code;
positioning the two-dimensional code by using a dynamic two-dimensional code positioning algorithm to obtain the area of the two-dimensional code;
and decoding the two-dimensional code by using a two-dimensional code decoding method according to the area of the two-dimensional code to obtain a code scanning result of the two-dimensional code.
It should be noted that the above-mentioned numbers of the embodiments of the present invention are merely for description, and do not represent the merits of the embodiments. And the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, apparatus, article, or method that includes the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (9)

1. A method for scanning codes, the method comprising:
acquiring a two-dimensional code image containing a two-dimensional code, and graying the two-dimensional code image by using a weighted average method to obtain a two-dimensional code grayscale image;
performing noise reduction processing on the two-dimensional code gray image by using a bilateral filtering algorithm to obtain a noise-reduced two-dimensional code gray image;
carrying out binarization processing on the two-dimensional code gray level image subjected to noise reduction by using an improved binarization algorithm to obtain a binarization image of the two-dimensional code;
positioning the two-dimensional code by using a dynamic two-dimensional code positioning algorithm to obtain the area of the two-dimensional code;
and decoding the two-dimensional code by using a two-dimensional code decoding method according to the area of the two-dimensional code to obtain a code scanning result of the two-dimensional code.
2. The code scanning method of claim 1, wherein the graying of the two-dimensional code image by the weighted average method comprises:
graying the two-dimensional code image by using a weighted average method, wherein the formula of the weighted average method is as follows:
Gray(i,j)=R(i,j)×0.299+G(i,j)×0.587+B(i,j)×0.114
wherein:
R(i,j),G(i,j),B(i,j)the pixel values of the two-dimensional code image pixel (i, j) on the three color channels of R, G and B are obtained;
Gray(i,j)is the gray value of the two-dimensional code image pixel (i, j).
3. The code scanning method of claim 2, wherein the performing noise reduction on the two-dimensional code gray image by using the bilateral filtering algorithm comprises:
the bilateral filtered image g (x, y) may be represented as:
Figure FDA0002733505870000011
W(x,y,m,n)=Gd(x,y,m,n)×Gr(x,y,m,n)
Figure FDA0002733505870000012
Figure FDA0002733505870000013
wherein:
f (x, y) is a two-dimensional code gray image with the pixel point (x, y) as the center;
(m, n) is a neighborhood pixel with (x, y) as a center pixel point, and the set of the neighborhood pixels is S;
w (x, y, m, n) is the weight coefficient of each point of the filter;
Gd(x, y, m, n) is spatial similarity;
Gr(x, y, m, n) is the gray scale similarity;
σd,σrrespectively, distance and standard deviation of gray scale based on gaussian kernel function.
4. The code scanning method as claimed in claim 3, wherein the binarizing processing on the two-dimensional code gray image after noise reduction by using the improved binarizing algorithm comprises:
1) go through twoAll gray values of the dimension code gray image are recorded as a global threshold value T, wherein the gray value which enables the inter-class variance objective function value to be maximum1
2) Let T equal 0.5 × (T)1+128), where f (x, y) is the gray value of the current pixel (x, y), and the average value T of the maximum gray value M and the minimum gray value N in all gray values in the window with the pixel size of (2w +1) × (2w +1) and the current pixel as the center is calculated2The invention sets w to 1;
3) calculating the average value of all gray values in the window
Figure FDA0002733505870000021
And mean square error C:
Figure FDA0002733505870000022
Figure FDA0002733505870000023
4) let T be aT1+bT2And b is greater than or equal to 0, a is greater than or equal to 1, b is greater than or equal to 0, and the two-dimensional code gray level image pixels are subjected to point-by-point binarization processing according to the processing rule:
if C is greater than or equal to S, when T is1T ≧ T, f (x, y) ═ 255, when T1<T,f(x,y)=0;
If C is less than S, when T2T ≧ T, f (x, y) ═ 255, when T2<T,f(x,y)=0;
Wherein:
s is a threshold parameter set by the invention, and the value of S is 15;
c is the mean square error of all gray values in the window;
f (x, y) is the gray value of the current pixel (x, y).
5. The code scanning method of claim 4, wherein the positioning the two-dimensional code by using the dynamic two-dimensional code positioning algorithm comprises:
1) carrying out convolution operation on the binary image by utilizing 5 convolution cores with the size of 3 multiplied by 3 pixels, and carrying out down-sampling operation after each convolution operation to obtain a sampling characteristic diagram of the binary image;
2) performing cavity convolution on the sampling characteristic diagram by using convolution cores with different expansion rates to obtain a cavity convolution characteristic diagram, wherein the expansion rate distribution follows the combination form of sawtooth waves, and a plurality of layers with increased expansion rates are combined together;
3) performing convolution operation on the cavity convolution characteristic graph by using a convolution kernel with dimensions of 3 multiplied by 1024; then expanding the channel number by using a convolution kernel with the convolution kernel size of 1 multiplied by 5070 dimensionality; then, carrying out average pooling operation to obtain a tensor with dimensions of 1 multiplied by 5070; and finally, outputting the feature map with the tensor transformation dimensionality of 13 multiplied by 30 dimensionality, wherein the finally output feature map is the feature map of the area where the two-dimensional code is located.
6. The code scanning method of claim 5, wherein the decoding the two-dimensional code by using the two-dimensional code decoding method comprises:
1) according to the structure of the two-dimensional code, the upper right corner of the two-dimensional code contains the version information of the two-dimensional code, the lower left corner of the two-dimensional code is a two-dimensional code position detection image, and a sampling network of the two-dimensional code version information is obtained by intercepting the upper right corner area of the two-dimensional code;
2) determining the grade of the two-dimensional code version according to a sampling network of the two-dimensional code version information, and correcting the error version information module, wherein the error correction mechanism is based on an RS error correction principle;
3) establishing a sampling grid on a two-dimensional code area image, wherein a plurality of cross points are arranged in the sampling grid, the points are sampled, the dark color is represented by binary number '1', and the light color is represented by binary number '0', so that a brand-new bitmap is generated, namely a two-dimensional code symbol is represented by a matrix;
4) eliminating the mask, namely performing exclusive-or operation on the coding region of the two-dimensional code and the mask graph to obtain a data code word and an error correction code word, and then rearranging the data code word and the error correction code word;
5) error checking is carried out on the code words, and substitution errors, read rejection errors and the like are corrected;
6) and reassembling the sequence of the error-corrected code words to form a bit stream which is the same as the data coding so as to realize the decoding operation.
7. An apparatus for scanning a code, the apparatus comprising:
the two-dimensional code acquisition device is used for acquiring a two-dimensional code image and carrying out gray processing on the two-dimensional code image;
the two-dimensional code processor is used for carrying out noise reduction processing on the two-dimensional code image by utilizing a bilateral filtering algorithm and carrying out binarization processing on the two-dimensional code image subjected to noise reduction by utilizing an improved binarization algorithm to obtain a binarization image of the two-dimensional code;
and the code scanning device is used for positioning the two-dimensional code by utilizing a dynamic two-dimensional code positioning algorithm to obtain the area where the two-dimensional code is located, and decoding the two-dimensional code by utilizing a two-dimensional code decoding method to obtain the code scanning result of the two-dimensional code.
8. A mobile terminal, characterized in that the mobile terminal comprises:
the mobile terminal antenna is used for transmitting the two-dimensional code image to the code scanning device and receiving a code scanning result;
the mobile terminal camera is used for acquiring a two-dimensional code image;
the mobile terminal rear cover is used for accommodating a circuit main board of the mobile terminal, a mobile terminal antenna and a mobile terminal camera.
9. A computer-readable storage medium having code scanning program instructions stored thereon, the code scanning program instructions being executable by one or more processors to implement the steps of a code scanning implementation method according to any one of claims 1 to 6.
CN202011125549.5A 2020-10-20 2020-10-20 Code scanning method, code scanning device and mobile terminal Withdrawn CN112163443A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011125549.5A CN112163443A (en) 2020-10-20 2020-10-20 Code scanning method, code scanning device and mobile terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011125549.5A CN112163443A (en) 2020-10-20 2020-10-20 Code scanning method, code scanning device and mobile terminal

Publications (1)

Publication Number Publication Date
CN112163443A true CN112163443A (en) 2021-01-01

Family

ID=73867607

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011125549.5A Withdrawn CN112163443A (en) 2020-10-20 2020-10-20 Code scanning method, code scanning device and mobile terminal

Country Status (1)

Country Link
CN (1) CN112163443A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112926351A (en) * 2021-03-17 2021-06-08 北京金朗维科技有限公司 Method and device for identifying graphic code and code scanning equipment
CN113362319A (en) * 2021-06-30 2021-09-07 深圳市创想三维科技股份有限公司 Laser printing method and device based on image processing, laser printer and computer readable storage medium
CN117787309A (en) * 2023-12-13 2024-03-29 佛山鑫码电子科技有限公司 Code scanning method and device based on double-color light source irradiation
CN117829175A (en) * 2023-12-06 2024-04-05 佛山鑫码电子科技有限公司 Code scanning method and system based on light compensation of bicolor light source

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112926351A (en) * 2021-03-17 2021-06-08 北京金朗维科技有限公司 Method and device for identifying graphic code and code scanning equipment
CN113362319A (en) * 2021-06-30 2021-09-07 深圳市创想三维科技股份有限公司 Laser printing method and device based on image processing, laser printer and computer readable storage medium
CN117829175A (en) * 2023-12-06 2024-04-05 佛山鑫码电子科技有限公司 Code scanning method and system based on light compensation of bicolor light source
CN117787309A (en) * 2023-12-13 2024-03-29 佛山鑫码电子科技有限公司 Code scanning method and device based on double-color light source irradiation

Similar Documents

Publication Publication Date Title
US11676238B2 (en) Detecting conflicts between multiple different signals within imagery
CN112163443A (en) Code scanning method, code scanning device and mobile terminal
US8523075B2 (en) Barcode recognition using data-driven classifier
CN110348264B (en) QR two-dimensional code image correction method and system
WO2014160433A2 (en) Systems and methods for classifying objects in digital images captured using mobile devices
CN109117846B (en) Image processing method and device, electronic equipment and computer readable medium
US20120018518A1 (en) Barcode processing
CN110717497B (en) Image similarity matching method, device and computer readable storage medium
CN110738203A (en) Method and device for outputting field structuralization and computer readable storage medium
WO2005020140A2 (en) Group average filter algorithm for digital image processing
US20200302135A1 (en) Method and apparatus for localization of one-dimensional barcodes
CN111291761B (en) Method and device for recognizing text
CN111899270A (en) Card frame detection method, device and equipment and readable storage medium
CN111080665A (en) Image frame identification method, device and equipment and computer storage medium
CN108960246B (en) Binarization processing device and method for image recognition
CN104346596A (en) Identification method and identification device for QR (Quick Response) code
Joshi et al. First steps toward CNN based source classification of document images shared over messaging app
CN116976372A (en) Picture identification method, device, equipment and medium based on square reference code
WO2009148409A1 (en) Method and system for extracting a barcode from a captured image
Tong et al. QR code detection based on local features
CN113727050B (en) Video super-resolution processing method and device for mobile equipment and storage medium
CN111753573B (en) Two-dimensional code image recognition method and device, electronic equipment and readable storage medium
CN113780278A (en) Method and device for identifying license plate content, electronic equipment and storage medium
CN111612714A (en) Image restoration method and device and electronic equipment
Hu et al. Application of computational verb image processing to 1-D barcode localization

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
WW01 Invention patent application withdrawn after publication
WW01 Invention patent application withdrawn after publication

Application publication date: 20210101