Block decoding method and system for two-dimensional code

10095903 ยท 2018-10-09

Assignee

Inventors

Cpc classification

International classification

Abstract

A block decoding method includes: storing a received two-dimensional code image in an image data backup register; binarizing the received two-dimensional code image; searching for a boundary line of the two-dimensional code image; segmenting each of the regions into bit regions each of which corresponds to one bit data; re-acquiring the received two-dimensional code image stored in the image data backup register; calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region; calculating a gray-scale threshold of each of the bit regions n using the Otsu method; binarizing the bit region so as to obtain a binarized two-dimensional code image; and decoding the binarized two-dimensional code image. A system for a two-dimensional code is also disclosed.

Claims

1. A block decoding method for a two-dimensional code, characterized by comprising: storing a received two-dimensional code image in an image data backup register; binarizing the received two-dimensional code image based on a gray-scale value of a pixel; searching for a boundary line of the two-dimensional code image based on a position detection pattern; searching for a version number and a correction pattern of the two-dimensional code image; segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image, a straight line where a boundary line of the position detection pattern is located and a straight line where a boundary line of the correction pattern is located; calculating the number of bits in each of the regions based on the position detection pattern, the correction pattern and the version number; segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern and deformation amount of the correction pattern; re-acquiring the received two-dimensional code image stored in the image data backup register; calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region; calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method; binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and decoding the binarized two-dimensional code image.

2. The block decoding method for a two-dimensional code according to claim 1, wherein binarizing the received two-dimensional code image based on the gray-scale value of the pixel specifically includes: calculating a gray-scale threshold based on the gray-scale value of the pixel using an average value method; and binarizing the received two-dimensional code image based on the gray-scale threshold.

3. The block decoding method for a two-dimensional code according to claim 1, wherein binarizing the received two-dimensional code image based on the gray-scale value of the pixel specifically includes: calculating a gray-scale threshold based on the gray-scale value of the pixel using the Otsu method; and binarizing the received two-dimensional code image based on the gray-scale threshold.

4. The block decoding method for a two-dimensional code according to claim 1, wherein searching for the boundary line of the two-dimensional code image based on the position detection pattern specifically includes: determining two adjacent boundary lines in the two-dimensional code image based on three position detection patterns; translating the two adjacent boundary lines respectively so that the translated boundary lines pass through corner points of the position detection pattern; searching for black-and-white demarcation points of the received two-dimensional code image in the proximity of the translated boundary lines; and fitting the black-and-white demarcation points of the received two-dimensional code image using the least squares method so as to obtain the boundary lines of the two-dimensional code image.

5. The block decoding method for a two-dimensional code according to claim 1, wherein searching for the version number and the correction pattern of the two-dimensional code image specifically includes: searching for a position where the version number is located in the two-dimensional code image based on the boundary lines of the two-dimensional code image and the position detection pattern; decoding an image corresponding to the position where the version number is located to obtain the version number; determining a position of the correction pattern based on the version number and a shape of the position detection pattern; and searching in the two-dimensional code image for an image corresponding to the position of the correction pattern, and decoding the image to obtain the correction pattern.

6. The block decoding method for a two-dimensional code according to claim 1, wherein segmenting each of the regions into bit regions each of which corresponds to one bit data based on the deformation amount of the position detection pattern and the deformation amount of the correction pattern specifically includes: calculating a ratio of the lengths of two adjacent bits based on the number of bits and the length of bits of the position detection patterns having the same straight-line boundary or of the correction pattern; calculating the length of each bit in each region on the same straight-line boundary based on the ratio of the lengths of the two adjacent bits and the number of bits in each region on the same straight-line boundary; sequentially calculating the length of each bit on the boundaries of all the regions and marking segmenting points; and connecting the segmenting points on two opposite boundaries in each of the regions to segment each region into bit regions each of which corresponds to one bit.

7. A block decoding method for a two-dimensional code, characterized by comprising: storing a received two-dimensional code image in an image data backup register; binarizing the received two-dimensional code image based on a gray-scale value of a pixel; searching for a boundary line of the two-dimensional code image based on a position detection pattern; searching for a version number of the two-dimensional code image; segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image and a straight line where a boundary line of the position detection pattern is located; calculating the number of bits in each of the regions based on the position detection pattern and the version number; segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern; re-acquiring the received two-dimensional code image stored in the image data backup register; calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region; calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method; binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and decoding the binarized two-dimensional code image.

8. The block decoding method for a two-dimensional code according to claim 7, wherein binarizing the received two-dimensional code image based on the gray-scale value of the pixel specifically includes: calculating a gray-scale threshold based on the gray-scale value of the pixel using an average value method; and binarizing the received two-dimensional code image based on the gray-scale threshold.

9. The block decoding method for a two-dimensional code according to claim 7, wherein binarizing the received two-dimensional code image based on the gray-scale value of the pixel specifically includes: calculating a gray-scale threshold based on the gray-scale value of the pixel using the Otsu method; and binarizing the received two-dimensional code image based on the gray-scale threshold.

10. The block decoding method for a two-dimensional code according to claim 7, wherein searching for the boundary line of the two-dimensional code image based on the position detection pattern specifically includes: determining two adjacent boundary lines in the two-dimensional code image based on three position detection patterns; translating the two adjacent boundary lines respectively so that the translated boundary lines pass through corner points of the position detection pattern; searching for black-and-white demarcation points of the received two-dimensional code image in the proximity of the translated boundary lines; and fitting the black-and-white demarcation points of the received two-dimensional code image using the least squares method so as to obtain the boundary lines of the two-dimensional code image.

11. The block decoding method for a two-dimensional code according to claim 7, wherein segmenting each of the regions into bit regions each of which corresponds to one bit data based on the deformation amount of the position detection pattern specifically includes: calculating a ratio of the lengths of two adjacent bits based on the number of bits and the length of bits of the position detection patterns having the same straight-line boundary; calculating the length of each bit in each region on the same straight-line boundary based on the ratio of the lengths of the two adjacent bits and the number of bits in each region on the same straight-line boundary; sequentially calculating the length of each bit on the boundaries of all the regions and marking segmenting points; and connecting the segmenting points on two opposite boundaries in each of the regions to segment each region into bit regions each of which corresponds to one bit.

12. A block decoding system for a two-dimensional code, characterized by comprising: a storage module which is configured for storing a received two-dimensional code image in an image data backup register; a first binarizing module which is configured for binarizing the received two-dimensional code image based on a gray-scale value of a pixel; a first searching module which is configured for searching for a boundary line of the two-dimensional code image based on a position detection pattern; a second searching module which is configured for searching for a version number and a correction pattern of the two-dimensional code image; a first segmenting module which is configured for segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image, a straight line where a boundary line of the position detection pattern is located and a straight line where a boundary line of the correction pattern is located; a first calculating module which is configured for calculating the number of bits in each of the regions based on the position detection pattern, the correction pattern and the version number; a second segmenting module which is configured for segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern and deformation amount of the correction pattern; an acquiring module which is configured for re-acquiring the received two-dimensional code image stored in the image data backup register; a second calculating module which is configured for calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region; a third calculating module which is configured for calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method; a second binarizing module which is configured for binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and a decoding module which is configured for decoding the binarized two-dimensional code image.

13. A block decoding system for a two-dimensional code, characterized by comprising a storage module which is configured for storing a received two-dimensional code image in an image data backup register; a first binarizing module which is configured for binarizing the received two-dimensional code image based on a gray-scale value of a pixel; a first searching module which is configured for searching for a boundary line of the two-dimensional code image based on a position detection pattern; a second searching module which is configured for searching for a version number of the two-dimensional code image; a first segmenting module which is configured for segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image and a straight line where a boundary line of the position detection pattern is located; a first calculating module which is configured for calculating the number of bits in each of the regions based on the position detection pattern and the version number; a second segmenting module which is configured for segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern; an acquiring module which is configured for re-acquiring the received two-dimensional code image stored in the image data backup register; a second calculating module which is configured for calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region; a third calculating module which is configured for calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method; a second binarizing module which is configured for binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and a decoding module which is configured for decoding the binarized two-dimensional code image.

Description

BRIEF DESCRIPTION OF THE ACCOMPANYING DRAWINGS

(1) FIG. 1 is a flowchart of a block decoding method for a two-dimensional code according to a first embodiment of the invention;

(2) FIG. 2 is an original diagram of a Chinese-sensible code according to the first embodiment of the invention;

(3) FIG. 3 is a schematic diagram of segmenting the Chinese-sensible code according to the first embodiment of the invention;

(4) FIG. 4 is a flowchart of a block decoding method of a two-dimensional code according to a second embodiment of the invention;

(5) FIG. 5 is an original diagram of a QR code according to the second embodiment of the invention;

(6) FIG. 6 is a schematic diagram of a boundary line of the QR code according to the second embodiment of the invention; and

(7) FIG. 7 is a schematic diagram of segmenting the QR code according to the second embodiment of the invention.

(8) TABLE-US-00001 Reference numbers 1. first region; 2. second region; 3. third region; 4. fourth region; 5. fifth region; 6. sixth region; 7. seventh region; 8. eighth region; 9. ninth region; 10. position detection pattern; 11. correction pattern; 12. position detection pattern.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

(9) In order to illustrate the technical solutions, the objects and effects of the invention in detail, embodiments are described below in conjunction with the accompanying drawings.

(10) A critical concept of the invention is to segment a two-dimensional code image into regions in consideration of deformation amount of a position detection pattern and deformation amount of a correction pattern of the two-dimensional code image, and to divide the segmented region into bit regions corresponding to bit data, thereby improving segmenting precision; and to re-read the two-dimensional code image after the two-dimensional code image is segmented into bit regions, thereby realizing quick and accurate decoding.

(11) A specific embodiment of the invention is described as follows.

(12) Referring to FIG. 1, a block decoding method for a two-dimensional code includes:

(13) storing a received two-dimensional code image in an image data backup register;

(14) binarizing the received two-dimensional code image based on a gray-scale value of a pixel;

(15) searching for a boundary line of the two-dimensional code image based on a position detection pattern;

(16) searching for a version number and a correction pattern of the two-dimensional code image;

(17) segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image, a straight line where a boundary line of the position detection pattern is located and a straight line where a boundary line of the correction pattern is located;

(18) calculating the number of bits in each of the regions based on the position detection pattern, the correction pattern and the version number;

(19) segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern and deformation amount of the correction pattern;

(20) re-acquiring the received two-dimensional code image stored in the image data backup register;

(21) calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region;

(22) calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method;

(23) binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and

(24) decoding the binarized two-dimensional code image.

(25) Referring to FIG. 4, a block decoding method for a two-dimensional code includes:

(26) storing a received two-dimensional code image in an image data backup register;

(27) binarizing the received two-dimensional code image based on a gray-scale value of a pixel;

(28) searching for a boundary line of the two-dimensional code image based on a position detection pattern;

(29) searching for a version number of the two-dimensional code image;

(30) segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image and a straight line where a boundary line of the position detection pattern is located;

(31) calculating the number of bits in each of the regions based on the position detection pattern and the version number;

(32) segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern;

(33) re-acquiring the received two-dimensional code image stored in the image data backup register;

(34) calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region;

(35) calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method;

(36) binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and

(37) decoding the binarized two-dimensional code image.

(38) Further, binarizing the received two-dimensional code image based on the gray-scale value of the pixel specifically includes:

(39) calculating a gray-scale threshold based on the gray-scale value of the pixel using an average value method; and

(40) binarizing the received two-dimensional code image based on the gray-scale threshold.

(41) It can be known from the above description that in case where the gray-scale threshold of the received two-dimensional code image is calculated using the average value method, such advantages as small data calculation amount and quick calculation process are realized.

(42) Further, binarizing the received two-dimensional code image based on the gray-scale value of the pixel specifically includes:

(43) calculating a gray-scale threshold based on the gray-scale value of the pixel using the Otsu method; and

(44) binarizing the received two-dimensional code image based on the gray-scale threshold.

(45) It can be known from the above description that in case where the gray-scale threshold of the received two-dimensional code image is calculated using the Otsu method, such advantages as reducing the possibility of misclassifying a foreground color from a background color are realized.

(46) Further, searching for the boundary line of the two-dimensional code image based on the position detection pattern specifically includes:

(47) determining two adjacent boundary lines in the two-dimensional code image based on three position detection patterns;

(48) translating the two adjacent boundary lines respectively so that the translated boundary lines pass through corner points of the position detection pattern;

(49) searching for black-and-white demarcation points of the received two-dimensional code image in the proximity of the translated boundary lines; and

(50) fitting the black-and-white demarcation points of the received two-dimensional code image using the least squares method so as to obtain the boundary lines of the two-dimensional code image.

(51) It can be known from the above description that when determining the boundary lines of the two-dimensional code image based on three position detection patterns, two adjacent boundary lines in the two-dimensional code image are determined based on two position detection patterns having the same straight-line boundary, then the two adjacent boundary lines are translated, and then black-and-white demarcation points are searched for in the proximity of the translated boundary lines and the black-and-white demarcation points are fitted using the least squares method so as to obtain the boundary lines of the two-dimensional code image, thus having an advantage of quick and accurate positioning.

(52) Further, searching for the version number and the correction pattern of the two-dimensional code image specifically includes:

(53) searching for a position where the version number is located in the two-dimensional code image based on the boundary lines of the two-dimensional code image and the position detection pattern;

(54) decoding an image corresponding to the position where the version number is located to obtain the version number;

(55) determining a position of the correction pattern based on the version number and a shape of the position detection pattern; and

(56) searching in the two-dimensional code image for an image corresponding to the position of the correction pattern, and decoding the image to obtain the correction pattern.

(57) It can be known from the above description that the version number in the two-dimensional code image may be found out based on the shape and the position of the position detection pattern, and can be decoded. The position of the correction pattern can be determined based on the version number and the position detection pattern. The above process is reasonable.

(58) Further, segmenting each of the regions into bit regions each of which corresponds to one bit data based on the deformation amount of the position detection pattern and the deformation amount of the correction pattern specifically includes:

(59) calculating a ratio of the lengths of two adjacent bits based on the number of bits and the length of bits of the position detection patterns having the same straight-line boundary or of the correction pattern;

(60) calculating the length of each bit in each region on the same straight-line boundary based on the ratio of the lengths of the two adjacent bits and the number of bits in each region on the same straight-line boundary;

(61) sequentially calculating the length of each bit on the boundaries of all the regions and marking segmenting points; and

(62) connecting the segmenting points on two opposite boundaries in each of the regions to segment each region into bit regions each of which corresponds to one bit.

(63) It can be known from the above description that the number of bits in the width direction and the number of bits in the length direction of each region can be calculated based on the number of bits in the length direction and the number of bits in the width direction of the position detection pattern and the correction pattern, and the number of bits in each region is further calculated. The length of bits on the boundary of each region may be calculated based on deformation amount on the boundaries of the position detection pattern and the correction pattern, and each of the regions may be segmented into bit regions each of which corresponds to one bit. The above process is reasonable, thereby preventing decoding precision of the received two-dimensional code image from being affected by the deformation amount of the received two-dimensional code image, and improving decoding precision of the two-dimensional code image.

(64) Further, segmenting each of the regions into bit regions each of which corresponds to one bit data based on the deformation amount of the position detection pattern specifically includes:

(65) calculating a ratio of the lengths of two adjacent bits based on the number of bits and the length of bits of the position detection patterns having the same straight-line boundary;

(66) calculating the length of each bit in each region on the same straight-line boundary based on the ratio of the lengths of the two adjacent bits and the number of bits in each region on the same straight-line boundary;

(67) sequentially calculating the length of each bit on the boundaries of all the regions and marking segmenting points; and

(68) connecting the segmenting points on two opposite boundaries in each of the regions to segment each region into bit regions each of which corresponds to one bit.

(69) It can be known from the above description that the number of bits in the width direction and the number of bits in the length direction of each region can be calculated based on the number of bits in the length direction and the number of bits in the width direction of the position detection pattern, and the number of bits in each region is further calculated. The length of bits on the boundary of each region may be calculated based on deformation amount on the boundary of the position detection pattern, and each of the regions may be segmented into bit regions each of which corresponds to one bit. The above process is reasonable, thereby preventing decoding precision of the received two-dimensional code image from being affected by the deformation amount of the received two-dimensional code image, and improving decoding precision of the two-dimensional code image.

(70) Referring to FIG. 1 to FIG. 3, a first embodiment of the invention is described as follows.

(71) A block decoding method for a two-dimensional code is disclosed.

(72) Referring to FIG. 2, a received two-dimensional code image is stored in an image data backup register. The received two-dimensional code is a Chinese-sensible code. A position detection pattern 10 and a correction pattern 11 of the Chinese-sensible code are shown in FIG. 2.

(73) The received two-dimensional code image is binarized based on a gray-scale value of a pixel.

(74) Specifically, gray-scale threshold is calculated based on the gray-scale value of the pixel using an average value method;

(75) the received two-dimensional code image is binarized based on the gray-scale threshold;

(76) a boundary line of the two-dimensional code image is searched for based on the position detection pattern 10.

(77) The version number and the correction pattern 11 of the two-dimensional code image is searched for.

(78) Specifically, a position where the version number is located in the two-dimensional code image can be found out based on the boundary line and the position detection pattern 10 of the two-dimensional code image;

(79) an image corresponding to the position where the version number is located is decoded to obtain the version number;

(80) a position of the correction pattern 11 is determined based on the version number and a shape of the position detection pattern 10;

(81) an image corresponding to the position of the correction pattern 11 is searched for in the two-dimensional code image, and the image is decoded.

(82) Referring to FIG. 3, the two-dimensional code image is segmented into regions based on the boundary line of the two-dimensional code image, a straight line where a boundary line of the position detection pattern 10 is located and a straight line where a boundary line of the correction pattern 11 is located.

(83) The number of bits in each of the regions is calculated based on the position detection pattern 10, the correction pattern 11 and the version number.

(84) Each of the regions is segmented into bit regions each of which corresponds to one bit data based on deformation amount of the position detection pattern 10 and deformation amount of the correction pattern 11.

(85) Specifically, a ratio of the lengths of two adjacent bits can be calculated based on the number of bits and the length of bits of the position detection patterns 10 having the same straight-line boundary or of the correction pattern 11;

(86) the length of each bit in each region on the same straight-line boundary is calculated based on the ratio of the lengths of the two adjacent bits and the number of bits in each region on the same straight-line boundary;

(87) the length of each bit on the boundaries of all the regions is sequentially calculated and segmenting points are marked;

(88) the segmenting points on two opposite boundaries in each of the regions are connected to segment each region into bit regions each of which corresponds to one bit;

(89) the received two-dimensional code image stored in the image data backup register is re-acquired;

(90) an average gray-scale value of all the pixels in the bit region is calculated as a gray-scale value of the bit region;

(91) a gray-scale threshold of each bit region is calculated based on the gray-scale value of the bit region using the Otsu method;

(92) the bit region is binarized based on the gray-scale threshold so as to obtain a binarized two-dimensional code image;

(93) the binarized two-dimensional code image is decoded.

(94) Referring to FIG. 4 to FIG. 7, a second embodiment of the invention is described as follows.

(95) A block decoding method for a two-dimensional code is disclosed.

(96) Referring to FIG. 5, a received two-dimensional code image is stored in an image data backup register. The received two-dimensional code is a QR code, and a position detection pattern 12 of the QR code is shown in FIG. 5. The QR code in FIG. 5 does not include a correction pattern.

(97) The received two-dimensional code image is binarized based on a gray-scale value of a pixel.

(98) Specifically, a gray-scale threshold is calculated based on the gray-scale value of the pixel using the Otsu method;

(99) the received two-dimensional code image is binarized based on the gray-scale threshold.

(100) Referring to FIG. 6, a boundary line of the two-dimensional code image is searched for based on the position detection pattern 12.

(101) Specifically, two adjacent boundary lines u and 1 in the two-dimensional code image can be determined based on three position detection patterns 12;

(102) the two adjacent boundary lines u and 1 are translated respectively so that the translated boundary lines pass through corner points Q and P of the pattern detection pattern 12;

(103) black-and-white demarcation points of the received two-dimensional code image are searched for in the proximity of the translated boundary lines;

(104) the black-and-white demarcation points of the received two-dimensional code image are fit using the least squares method so as to obtain the boundary lines d and r of the two-dimensional code image;

(105) a version number v of the two-dimensional code image is searched for.

(106) Referring to FIG. 7, the two-dimensional code image is segmented into nine regions based on the boundary lines of the two-dimensional code image and straight lines where boundary lines of the position detection patterns 12 are located. The nine regions are a first region 1, a second region 2, a third region 3, a fourth region 4, a fifth region 5, a sixth region 6, a seventh region 7, an eighth region 8 and a ninth region 9.

(107) The number of bits in each region is calculated based on the position detection pattern 12 and the version number v.

(108) Specifically, the position detection pattern 12 in FIG. 6 includes 49 bit regions, wherein seven bits are arranged in a width direction of the position detection pattern 12, and seven bits are arranged in a length direction of the position direction pattern 12. That is, seven bits are arranged at both sides of each of the first region 1, the second region 2 and the fourth region 4, and seven bits are arranged in each of the width direction and the length direction of the third region 3. Seven bits are arranged in the length direction at one side of each of the fifth region 5, the sixth region 6, the seventh region 7 and the eighth region 8.

(109) Seven bits are arranged in the width direction of the fifth region 5. Assuming the total length of the two-dimensional code in a transverse direction is m, m=4v+17 is obtained based on the version number. The length of bits in the length direction of the fifth region 5 is calculated, m14=4v+3.

(110) The length of the other side of each of the sixth region 6, the seventh region 7 and the eighth region 8 is 4v+3.

(111) Each region is segmented into bit regions each of which corresponds to one bit, based on deformation amount of the position detection pattern 12.

(112) Specifically, a ratio of the lengths of two adjacent bits can be calculated based on the number of bits and the length of bits in each of the position detection patterns 12 having the same straight-line boundary.

(113) Specifically, for example, for an upper length side of the fifth region 5, a straight line where it is located is an upper boundary line of the two-dimensional code image.

(114) Assuming the length of each bit on the upper boundary line of the two-dimensional code image is denoted as t.sub.i from left to right, where i=1, 2, . . . m, and it is known that the length of an upper boundary line of the first region 1 is denoted as d.sub.1, the length of an upper boundary line of the fourth region 4 is denoted as d.sub.4, the total length of the upper boundary line of the two-dimensional code image is denoted as d.sub.0, then the ratio of the lengths of two adjacent bits is represented as

(115) t i + 1 / t 4 = d 4 / d 1 ( m - 7 ) ,

(116) The length of each bit in each region on the same straight-line boundary can be calculated based on the ratio of the lengths of the two adjacent bits and the number of bits in each region on the same straight-line boundary.

(117) The length of each bit on the boundaries of all the regions is sequentially calculated, and segmenting points are marked.

(118) The segmenting points on two opposite boundaries in each of the regions are connected to segment each region into bit regions each of which corresponds to one bit.

(119) The received two-dimensional code image stored in the image data backup register is re-acquired.

(120) An average gray-scale value of all the pixels in the bit region is calculated as a gray-scale value of the bit region.

(121) A gray-scale threshold of each of the bit regions is calculated based on the gray-scale value of the bit region using the Otsu method.

(122) The bit region is binarized based on the gray-scale threshold so as to obtain a binarized two-dimensional code image.

(123) The binarized two-dimensional code image is decoded.

(124) A block decoding system for a two-dimensional code includes:

(125) a storage module which is configured for storing a received two-dimensional code image in an image data backup register;

(126) a first binarizing module which is configured for binarizing the received two-dimensional code image based on a gray-scale value of a pixel;

(127) a first searching module which is configured for searching for a boundary line of the two-dimensional code image based on a position detection pattern;

(128) a second searching module which is configured for searching for a version number and a correction pattern of the two-dimensional code image;

(129) a first segmenting module which is configured for segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image, a straight line where a boundary line of the position detection pattern is located and a straight line where a boundary line of the correction pattern is located;

(130) a first calculating module which is configured for calculating the number of bits in each of the regions based on the position detection pattern, the correction pattern and the version number;

(131) a second segmenting module which is configured for segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern and deformation amount of the correction pattern;

(132) an acquiring module which is configured for re-acquiring the received two-dimensional code image stored in the image data backup register;

(133) a second calculating module which is configured for calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region;

(134) a third calculating module which is configured for calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method;

(135) a second binarizing module which is configured for binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and

(136) a decoding module which is configured for decoding the binarized two-dimensional code image.

(137) A third embodiment of the invention is described as follows.

(138) A block decoding system for a two-dimensional code includes:

(139) a storage module which is configured for storing a received two-dimensional code image in an image data backup register;

(140) a first binarizing module which is configured for binarizing the received two-dimensional code image based on a gray-scale value of a pixel;

(141) a first searching module which is configured for searching for a boundary line of the two-dimensional code image based on a position detection pattern;

(142) a second searching module which is configured for searching for a version number and a correction pattern of the two-dimensional code image;

(143) a first segmenting module which is configured for segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image, a straight line where a boundary line of the position detection pattern is located and a straight line where a boundary line of the correction pattern is located;

(144) a first calculating module which is configured for calculating the number of bits in each of the regions based on the position detection pattern, the correction pattern and the version number;

(145) a second segmenting module which is configured for segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern and deformation amount of the correction pattern;

(146) an acquiring module which is configured for re-acquiring the received two-dimensional code image stored in the image data backup register;

(147) a second calculating module which is configured for calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region;

(148) a third calculating module which is configured for calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method;

(149) a second binarizing module which is configured for binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and

(150) a decoding module which is configured for decoding the binarized two-dimensional code image.

(151) A block decoding system for a two-dimensional code includes:

(152) a storage module which is configured for storing a received two-dimensional code image in an image data backup register;

(153) a first binarizing module which is configured for binarizing the received two-dimensional code image based on a gray-scale value of a pixel;

(154) a first searching module which is configured for searching for a boundary line of the two-dimensional code image based on a position detection pattern;

(155) a second searching module which is configured for searching for a version number of the two-dimensional code image;

(156) a first segmenting module which is configured for segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image and a straight line where a boundary line of the position detection pattern is located;

(157) a first calculating module which is configured for calculating the number of bits in each of the regions based on the position detection pattern and the version number;

(158) a second segmenting module which is configured for segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern;

(159) an acquiring module which is configured for re-acquiring the received two-dimensional code image stored in the image data backup register;

(160) a second calculating module which is configured for calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region;

(161) a third calculating module which is configured for calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method;

(162) a second binarizing module which is configured for binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and

(163) a decoding module which is configured for decoding the binarized two-dimensional code image.

(164) A fourth embodiment of the invention is described as follows.

(165) A block decoding system for a two-dimensional code includes:

(166) a storage module which is configured for storing a received two-dimensional code image in an image data backup register;

(167) a first binarizing module which is configured for binarizing the received two-dimensional code image based on a gray-scale value of a pixel;

(168) a first searching module which is configured for searching for a boundary line of the two-dimensional code image based on a position detection pattern;

(169) a second searching module which is configured for searching for a version number of the two-dimensional code image;

(170) a first segmenting module which is configured for segmenting the two-dimensional code image into regions based on the boundary line of the two-dimensional code image and a straight line where a boundary line of the position detection pattern is located;

(171) a first calculating module which is configured for calculating the number of bits in each of the regions based on the position detection pattern and the version number;

(172) a second segmenting module which is configured for segmenting each of the regions into bit regions each of which corresponds to one bit data, based on deformation amount of the position detection pattern;

(173) an acquiring module which is configured for re-acquiring the received two-dimensional code image stored in the image data backup register;

(174) a second calculating module which is configured for calculating an average gray-scale value of all the pixels in the bit region as a gray-scale value of the bit region;

(175) a third calculating module which is configured for calculating a gray-scale threshold of each of the bit regions based on the gray-scale value of the bit region using the Otsu method;

(176) a second binarizing module which is configured for binarizing the bit region based on the gray-scale threshold so as to obtain a binarized two-dimensional code image; and

(177) a decoding module which is configured for decoding the binarized two-dimensional code image.

(178) To sum up, in the block decoding method and system for a two-dimensional code provided by the invention, a boundary of the two-dimensional code image is determined based on a position detection pattern of the received two-dimensional code image, thereby effecting accurate positioning; the two-dimensional code image is segmented into regions based on the straight lines where the position detection pattern and the correction pattern are located, thereby facilitating decoding and reducing an influence of environmental factor such as lights and angle on the received two-dimensional code image; the region is segmented into bit regions each of which corresponds to one bit based on deformation amount of the position detection pattern and deformation amount of the correction pattern, thereby effecting quick decoding of the two-dimensional code image; the received two-dimensional code image stored in the image data backup register is re-acquired after segmenting the two-dimensional code image into regions, and this is equivalent to re-acquiring the coordinates and gray-scale values of the pixels in the received two-dimensional code image, thereby improving decoding precision of the two-dimensional code. In the system, the two-dimensional code image is segmented precisely, thereby avoiding external interference and realizing accurate decoding.