A kind of Quick Response Code resistant to damage coding/decoding method
Technical field
The present invention relates to field of data recognition, is a kind of Quick Response Code resistant to damage coding/decoding method specifically.
Background technology
At present, the method for Quick Response Code decoding is generally: first obtain a square region be communicated with, then estimation of the order goes out 4 limits of square region, using these 4 limits as the border of Quick Response Code, decodes; Or adopt polygonal approximation to estimate 4 borders of Quick Response Code, decode.There is recognition capability difference in a kind of front method, have a limit to damage the shortcoming just can not decoded, a kind of rear method exists the shortcoming of recognition capability difference equally, and when there is border damage, polygonal approximation is easily made mistakes, and causes and can not decode.
Summary of the invention
Task of the present invention is exactly for above-mentioned technical matters, to provide a kind of recognition capability strong, the Quick Response Code resistant to damage coding/decoding method can decoded to stained, damaged Quick Response Code.
The present invention is realized by following technical proposals:
A kind of Quick Response Code resistant to damage coding/decoding method, is characterized in that: comprise the steps:
S101: start;
S102: obtain image, judge whether there is Quick Response Code in image, if there is Quick Response Code, jump to step S103, if there is not Quick Response Code, then again obtain image;
S103: suppose the first two-dimension code area, decode, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S107;
S104: suppose the second two-dimension code area, decode, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S107;
S106: export decoded result;
S107: terminate;
Wherein step S102 comprises the steps:
S1021: obtain image, and gray processing, binaryzation are carried out to image;
S1022: with the lower left corner of binary image for true origin, horizontal direction is x-axis, and vertical direction is y-axis, sets up plane right-angle coordinate;
S1023: find out the region identical with possible two-dimension code area color, at this region progressive scanning picture, find first marginal point, with this point for starting point, carry out frontier tracing, find out frontier point, if number >=168 of the frontier point be communicated with, then suppose that frontier point that these are communicated with surrounds a possible two-dimension code area, jump to step S103, otherwise jump to S1021; Wherein, during progressive scanning picture, can determine that the color of possible two-dimension code area represents: if when sweep trace scanning starting point, color is black by leucismus, then possible two-dimension code area is that normal Quick Response Code color represents, i.e. black correspondence 1, white corresponding 0, setting possible two-dimension code area color is black; Otherwise for reversion color represents, i.e. white corresponding 1, black correspondence 0, sets possible two-dimension code area color as white;
Step S103 comprises the steps:
S1031: the frontier point found out according to step S1023, matching boundary straight line, and the order of the boundary straight line of matching by boundary tracking is sorted, the end to end line segment that the point of adjacent boundary straight line intersection connects into is boundary sections;
S1032: find out 4 the longest segment boundary line segments, 4 boundary straight line corresponding to these 4 sections of boundary sections the longest are the first boundary line, suppose that the region that 4 the first boundary lines surround is the first two-dimension code area;
S1033: decode to the first two-dimension code area, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S104;
Step S104 comprises the steps:
S1041: suppose the second two-dimension code area position: find out in the boundary straight line of S1031 matching, 3 boundary straight line that the frontier point number of corresponding connection is maximum, these 3 boundary straight line are Second Edge boundary line, these 3 the second boundary straight lines are sorted by the order of boundary tracking, suppose to there is the 4th article of real the second boundary straight line, the region that 4 the second boundary straight lines are surrounded is the second two-dimension code area, and the 4th article of real the second boundary straight line is designated as L4 ';
S1042: determine the 4th article of the second boundary straight line supposed, the 4th article of the second boundary straight line supposed is designated as L4;
S1043: determine the 4th article of real the second boundary straight line;
S1044: decode to the second two-dimension code area, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S107;
Wherein step S1042, comprises the steps:
The intersection point of any two the adjacent straight lines in 3 the second boundary straight lines of S10421: calculation procedure S1041 sequence, if there is the intersection point of a pair adjacent straight line to there is intersection point outside the region identical with view finding graphic color or not, this is designated as L1 and L2 to adjacent straight line according to the order sorted, article 3, that remaining in the second boundary straight line straight line is designated as L3, then L4 is crossing with L1 and L2 respectively, and L4 and L3 is parallel;
S10422: find out on L1, distance L3 frontier point farthest between upper and L1 and L2 of L2, crossing this farthest boundary point and be parallel on the straight line of L1 or L2, with this farthest boundary point for starting point, scan along the direction away from L3, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on L4, determine L4;
Step S1043 comprises the steps:
S10431: the intersection point calculating L4 and L1, L2, is designated as P1, P2 respectively;
S10432: the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate that calculate P1 and P2, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
S10433: on L4 take P1 as starting point, P2 is terminal, every 1-6 point get a point as scan start point, these are pressed its to P1 distance from the close-by examples to those far off, be designated as successively M1, M2 ... to M n; By M1, M2 ... order to M n scans;
S10434: as F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near L3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of L4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near L3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of L4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point
Find out with M1, M2 ... with all real frontier point that M n is scan start point, simulate straight line, this straight line is L4 ';
Wherein the first threshold values is 4-12 pixel;
Quick Response Code is Z-code or Data Matrix code.
Wherein, according to real frontier point, the method for L4 ' described in matching can adopt Hough transform method or least square method.
The further improvement project of the present invention comprises:
Described Quick Response Code resistant to damage coding/decoding method also comprises: carry out step S105 when described step S1044 decodes unsuccessfully;
S105: suppose the 3rd two-dimension code area, decode, if successfully decoded, then jumps to described step S106, if decode unsuccessfully, then jumps to described step S107;
Wherein, step S105 comprises the steps:
S1051: find out in the boundary straight line of described step S1031 matching, 2 boundary straight line that the frontier point of corresponding connection is maximum, and these 2 boundary straight line are sorted by the order of boundary tracking, be designated as W1 and W2, these 2 articles of boundary straight line are the 3rd boundary line, suppose to there is the 3rd, 4 article of the 3rd real boundary straight line, the region that 4 article of the 3rd boundary straight line is surrounded is the 3rd two-dimension code area, and the 3rd, 4 article of the 3rd real boundary straight line is designated as W3 ', W4 ';
S1052: determine the 3rd, 4 article the 3rd of the hypothesis relation between boundary straight line and W1 and W2, the 3rd, 4 article of the 3rd boundary straight line supposed is designated as W3, W4:
Calculate the intersection point of W1 and W2, and judge position of intersecting point: if this intersection point is on the region identical with view finding graphic color, then W3 and W1 is parallel, and W3 and W2 intersects, W4 and W2 is parallel, and W4 and W1 intersects, and jumps to step S1053; If this intersection point exists intersection point outside the region identical with view finding graphic color or not, then W3 with W4 is parallel, and W3 is crossing with W1 and W2 respectively, and W4 is crossing with W1 and W2 respectively, jumps to step S1054;
S1053:W3 and W1 is parallel, and W3 and W2 intersects, and W4 and W2 is parallel, and when W4 and W1 intersects, determines W3 ', W4 ', decode;
S1054:W3 with W4 is parallel, and W3 is crossing with W1 and W2 respectively, when W4 is crossing with W1 and W2 respectively, determines W3 ', W4 ', decodes;
Wherein, step S1053 comprises the steps:
S10531: determine W3 and W4:
Find out in the frontier point corresponding with W1, distance W2 frontier point farthest, crossing this farthest boundary point and be parallel on the straight line of W1, with this farthest boundary point for starting point, scan along away from the direction of W2, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W4, determine W4, the intersection point of W4 and W1 is designated as Q1;
Find out in the frontier point corresponding with W2, distance W1 frontier point farthest, crossing this farthest boundary point and be parallel on the straight line of W2, with this farthest boundary point for starting point, scan along away from the direction of W1, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W3, determine W3, the intersection point of W3 and W2 is designated as Q2;
Calculate the intersection point of W3 and W4, be designated as Q3;
S10532: determine W3 ':
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of Q2 and Q3, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On W3, take Q2 as starting point, Q3 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W2 from the close-by examples to those far off, be designated as successively T1, T2 ... to T n; By T1, T2 ... order to T n scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W1, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W3 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W1, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W3 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with T1, T2 ... with all real frontier point that T n is scan start point, simulate straight line, this straight line is W3 ';
S10533: determine W4 ':
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of Q1 and Q3, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On W4, take Q1 as starting point, Q3 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W1 from the close-by examples to those far off, be designated as successively J1, J2 ... to Jn; By J1, J2 ... order to Jn scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W2, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W2, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with J1, J2 ... with all real frontier point that Jn is scan start point, simulate straight line, this straight line is W4 ';
S10534: the 3rd two-dimension code area is decoded, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jump to step S107;
Wherein, step S1054 comprises the steps:
S10541: find out in the frontier point corresponding with W1, be positioned at two frontier points at W1 bearing of trend two ends, find out in the frontier point corresponding with W2, be positioned at two frontier points at W2 bearing of trend two ends, and four frontier points are designated as G1, G2, G3 to G4 by the order of boundary tracking, G1 and G2 is the point on W1, G3 and G4 is the point on W2;
S10542: suppose G2 and G3, any one group of point in G1 and G4 two groups of points is the point on straight line W3, decodes, if successfully decoded, then jump to step S106, if decode unsuccessfully, then suppose that group point remaining in two groups of points is the point on straight line W3, decode, if successfully decoded, jump to step S106, if decode unsuccessfully, jump to step S107;
Wherein, in step S10542, suppose G2 and the G3 point that to be point on straight line and hypothesis G1 and G4 be on straight line W3, the decoding step of both of these case is identical; With G2 and G3 for the point on straight line W3, decode, comprise the steps:
S105421: determine W3 according to G2 and G3;
S105422: find out on W1, distance W3 frontier point farthest between upper and W1 and W2 of W2, crossing this farthest boundary point and be parallel on the straight line of W1 or W2, with this farthest boundary point for starting point, scan along the direction away from W3, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W4, determine W4, the intersection point of W4 and W1 is designated as E1, and the intersection point of W4 and W2 is designated as E4; In like manner, redefine W3, find out on W1, distance W4 frontier point farthest between upper and W1 and W2 of W2, crossing this farthest boundary point and be parallel on the straight line of W1 or W2, with this farthest boundary point for starting point, scan along the direction away from W4, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W3, cross this point, make the straight line being parallel to W4, namely can redefine W3, the intersection point of W3 and the W1 redefined is designated as E2, and the intersection point of W3 and the W2 redefined is designated as E3;
S105423: determine W3 ', comprises the steps:
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of E2 and E3, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On the W3 redefined, take E2 as starting point, E3 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W1 from the close-by examples to those far off, be designated as successively R1, R2 ... to Rn; By R1, R2 ... order to Rn scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W4, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of the W3 redefined time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W4, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of the W3 redefined time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with R1, R2 ... with all real frontier point that R n is scan start point, simulate straight line, this straight line is W3 ';
S105424: determine W4 ', comprises the steps:
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of E1 and E4, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On W4, take E1 as starting point, E4 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W1 from the close-by examples to those far off, be designated as successively V1, V2 ... to Vn; By V1, V2 ... order to Vn scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with V1, V2 ... with all real frontier point that Vn is scan start point, simulate straight line, this straight line is W4 ';
S105425: the 3rd two-dimension code area is decoded.
Wherein, according to real frontier point, the method for W3 ' described in matching and/or W4 ' can adopt Hough transform method or least square method.
Beneficial effect: beneficial effect: Quick Response Code resistant to damage coding/decoding method recognition capability disclosed by the invention is strong, effectively can identify the image in 2 D code that view finding figure is stained, damaged.
Accompanying drawing explanation
Fig. 1 is one of decoding process figure of Quick Response Code resistant to damage coding/decoding method of the present invention;
Fig. 2 is the decoding process figure bis-of Quick Response Code resistant to damage coding/decoding method of the present invention;
Fig. 3 is the method schematic diagram that step S103 finds out the first two-dimension code area;
Fig. 4 is the method schematic diagram that step S104 finds out the second two-dimension code area;
Fig. 5 is the method schematic diagram that step S1053 finds out the 3rd two-dimension code area;
Fig. 6 is the method schematic diagram that step S1054 finds out the 3rd two-dimension code area.
Embodiment
As shown in Figure 1, a kind of Quick Response Code resistant to damage coding/decoding method, comprises the steps:
S101: start;
S102: obtain image, judge whether there is Quick Response Code in image, if there is Quick Response Code, jump to step S103, if there is not Quick Response Code, then again obtain image;
S103: suppose the first two-dimension code area, decode, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S107;
S104: suppose the second two-dimension code area, decode, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S107;
S106: export decoded result;
S107: terminate;
Wherein the first threshold values is 4-12 pixel;
Step S102 comprises the steps:
S1021: obtain image, and gray processing, binaryzation are carried out to image;
S1022: with the lower left corner of binary image for true origin, horizontal direction is x-axis, and vertical direction is y-axis, sets up plane right-angle coordinate; Can selection level direction to the right be X-axis positive dirction, can selection level direction left be also the positive dirction of X-axis; Direction straight up can be selected to be Y-axis positive dirction, direction straight down also can be selected to be the positive dirction of Y-axis;
S1023: find out the region identical with possible two-dimension code area color, at this region progressive scanning picture, find first marginal point, with this point for starting point, carry out frontier tracing, find out frontier point, if number >=168 of the frontier point be communicated with, then suppose that frontier point that these are communicated with surrounds a possible two-dimension code area, jump to step S103, otherwise jump to S1021; Wherein, during progressive scanning picture, can determine that the color of possible two-dimension code area represents: if when sweep trace scanning starting point, color is black by leucismus, then possible two-dimension code area is that normal Quick Response Code color represents, i.e. black correspondence 1, white corresponding 0, setting possible two-dimension code area color is black; Otherwise for reversion color represents, i.e. white corresponding 1, black correspondence 0, sets possible two-dimension code area color as white;
Step S103 comprises the steps:
S1031: the frontier point found out according to step S1023, matching boundary straight line, and the order of the boundary straight line of matching by boundary tracking is sorted, the end to end line segment that the point of adjacent boundary straight line intersection connects into is boundary sections; Fig. 3 shows the method for step S103, simulates altogether six boundary lines, is respectively A1, A2, A3, A4, A5 and A6;
S1032: find out 4 the longest segment boundary line segments, 4 boundary straight line corresponding to these 4 sections of boundary sections the longest are the first boundary line, suppose that the region that 4 the first boundary lines surround is the first two-dimension code area; A1, A2, A3 and A4 in Fig. 3 are the first boundary line;
S1033: decode to the first two-dimension code area, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S104;
Step S104 comprises the steps:
S1041: suppose the second two-dimension code area position: find out in the boundary straight line of S1031 matching, 3 boundary straight line that the frontier point number of corresponding connection is maximum, these 3 boundary straight line are Second Edge boundary line, these 3 the second boundary straight lines are sorted by the order of boundary tracking, suppose to there is the 4th article of real the second boundary straight line, the region that 4 the second boundary straight lines are surrounded is the second two-dimension code area, and the 4th article of real the second boundary straight line is designated as L4 '; Fig. 4 shows step S104 method.
S1042: determine the 4th article of the second boundary straight line supposed, the 4th article of the second boundary straight line supposed is designated as L4;
S1043: determine the 4th article of real the second boundary straight line;
S1044: decode to the second two-dimension code area, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jumps to step S107;
Wherein step S1042, comprises the steps:
The intersection point of any two the adjacent straight lines in 3 the second boundary straight lines of S10421: calculation procedure S1041 sequence, if there is the intersection point of a pair adjacent straight line to there is intersection point outside the region identical with view finding graphic color or not, this is designated as L1 and L2 to adjacent straight line according to the order sorted, article 3, that remaining in the second boundary straight line straight line is designated as L3, then L4 is crossing with L1 and L2 respectively, and L4 and L3 is parallel;
S10422: find out on L1, distance L3 frontier point farthest between upper and L1 and L2 of L2, crossing this farthest boundary point and be parallel on the straight line of L1 or L2, with this farthest boundary point for starting point, scan along the direction away from L3, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on L4, determine L4;
Step S1043 comprises the steps:
S10431: the intersection point calculating L4 and L1, L2, is designated as P1, P2 respectively;
S10432: the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate that calculate P1 and P2, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
S10433: on L4 take P1 as starting point, P2 is terminal, every 1-6 point get a point as scan start point, these are pressed its to P1 distance from the close-by examples to those far off, be designated as successively M1, M2, M3 ... to M n; By M1, M2, M3 ... order to M n scans;
S10434: as F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near L3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of L4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near L3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of L4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point
Find out with M1, M2, M3 ... with all real frontier point that M n is scan start point, simulate straight line, this straight line is L4 '; According to real frontier point, the method for matching L4 ' can adopt Hough transformation or least square method.
Quick Response Code is Z-code or Data Matrix code.
Embodiment 2
As shown in Figure 2, the present embodiment has carried out following improvement on the basis of embodiment 1:
Step S105 is carried out when the step S1044 of embodiment 1 decodes unsuccessfully;
S105: suppose the 3rd two-dimension code area, decode, if successfully decoded, then jump to step S106, if decode unsuccessfully, then jump to step S107;
Wherein, step S105 comprises the steps:
S1051: find out in the boundary straight line of S1031 matching, 2 boundary straight line that the frontier point of corresponding connection is maximum, and these 2 boundary straight line are sorted by the order of boundary tracking, be designated as W1 and W2, these 2 articles of boundary straight line are the 3rd boundary line, suppose to there is the 3rd, 4 article of the 3rd real boundary straight line, the region that 4 article of the 3rd boundary straight line is surrounded is the 3rd two-dimension code area, and the 3rd, 4 article of the 3rd real boundary straight line is designated as W3 ', W4 ';
S1052: determine the 3rd, 4 article the 3rd of the hypothesis relation between boundary straight line and W1 and W2, the 3rd, 4 article of the 3rd boundary straight line supposed is designated as W3, W4:
Calculate the intersection point of W1 and W2, and judge position of intersecting point: if this intersection point is on the region identical with view finding graphic color, then W3 and W1 is parallel, and W3 and W2 intersects, W4 and W2 is parallel, and W4 and W1 intersects, and jumps to step S1053; If this intersection point exists intersection point outside the region identical with view finding graphic color or not, then W3 with W4 is parallel, and W3 is crossing with W1 and W2 respectively, and W4 is crossing with W1 and W2 respectively, jumps to step S1054;
S1053:W3 and W1 is parallel, and W3 and W2 intersects, and W4 and W2 is parallel, and when W4 and W1 intersects, determines W3 ', W4 ', decode;
S1054:W3 with W4 is parallel, and W3 is crossing with W1 and W2 respectively, when W4 is crossing with W1 and W2 respectively, determines W3 ', W4 ', decodes;
Wherein, step S1053 comprises the steps:
S10531: determine W3 and W4:
Find out in the frontier point corresponding with W1, distance W2 frontier point farthest, crossing this farthest boundary point and be parallel on the straight line of W1, with this farthest boundary point for starting point, scan along away from the direction of W2, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W4, determine W4, the intersection point of W4 and W1 is designated as Q1; Fig. 5 shows the method that step S1053 finds out the 3rd two-dimension code area;
Find out in the frontier point corresponding with W2, distance W1 frontier point farthest, crossing this farthest boundary point and be parallel on the straight line of W2, with this farthest boundary point for starting point, scan along away from the direction of W1, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W3, determine W3, the intersection point of W3 and W2 is designated as Q2;
Calculate the intersection point of W3 and W4, be designated as Q3;
S10532: determine W3 ':
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of Q2 and Q3, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On W3, take Q2 as starting point, Q3 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W2 from the close-by examples to those far off, be designated as successively T1, T2, T3 ... to T n; By T1, T2, T3 ... order to T n scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W1, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W3 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W1, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W3 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with T1, T2, T3 ... with all real frontier point that T n is scan start point, simulate straight line, this straight line is W3 ';
S10533: determine W4 ':
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of Q1 and Q3, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On W4, take Q1 as starting point, Q3 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W1 from the close-by examples to those far off, be designated as successively J1, J2, J3 ... to Jn; By J1, J2, J3 ... order to Jn scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W2, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W2, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with J1, J2, J3 ... with all real frontier point that Jn is scan start point, simulate straight line, this straight line is W4 ';
S10534: the 3rd two-dimension code area is decoded, if successfully decoded, then jumps to step S106, if decode unsuccessfully, then jump to step S107;
Wherein, step S1054 comprises the steps:
S10541: find out in the frontier point corresponding with W1, be positioned at two frontier points at W1 bearing of trend two ends, find out in the frontier point corresponding with W2, be positioned at two frontier points at W2 bearing of trend two ends, and four frontier points are designated as G1, G2, G3 to G4 by the order of boundary tracking, G1 and G2 is the point on W1, G3 and G4 is the point on W2; Fig. 6 shows the method that step S1054 finds out the 3rd two-dimension code area;
S10542: suppose G2 and G3, any one group of point in G1 and G4 two groups of points is the point on straight line W3, decodes, if successfully decoded, then jump to step S106, if decode unsuccessfully, then suppose that group point remaining in two groups of points is the point on straight line W3, decode, if successfully decoded, jump to step S106, if decode unsuccessfully, jump to step S107;
Wherein, in step S10542, suppose G2 and the G3 point that to be point on straight line and hypothesis G1 and G4 be on straight line W3, the decoding step of both of these case is identical; With G2 and G3 for the point on straight line W3, decode, comprise the steps:
S105421:S105421: determine W3 according to G2 and G3;
S105422: find out on W1, distance W3 frontier point farthest between upper and W1 and W2 of W2, crossing this farthest boundary point and be parallel on the straight line of W1 or W2, with this farthest boundary point for starting point, scan along the direction away from W3, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W4, determine W4, the intersection point of W4 and W1 is designated as E1, and the intersection point of W4 and W2 is designated as E4; In like manner, redefine W3, find out on W1, distance W4 frontier point farthest between upper and W1 and W2 of W2, crossing this farthest boundary point and be parallel on the straight line of W1 or W2, with this farthest boundary point for starting point, scan along the direction away from W4, if number >=5 of the point different from view finding graphic color that continuous sweep is arrived, then suppose that this farthest boundary point is the point on W3, cross this point, make the straight line being parallel to W4, namely can redefine W3, the intersection point of W3 and the W1 redefined is designated as E2, and the intersection point of W3 and the W2 redefined is designated as E3;
S105423: determine W3 ', comprises the steps:
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of E2 and E3, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On the W3 redefined, take E2 as starting point, E3 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W1 from the close-by examples to those far off, be designated as successively R1, R2, R3 ... to Rn; By R1, R2, R3 ... order to Rn scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W4, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of the W3 redefined time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W4, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of the W3 redefined time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with R1, R2, R3 ... with all real frontier point that R n is scan start point, simulate straight line, this straight line is W3 ';
S105424: determine W4 ', comprises the steps:
Calculate the absolute value │ Δ y │ of difference of ordinate and the absolute value │ Δ x │ of the difference of horizontal ordinate of E1 and E4, and compare size, comparative result is designated as F, if │ Δ y │≤│ Δ x │, then and F=1, otherwise, F=0;
On W4, take E1 as starting point, E4 be terminal, get a point as scan start point every 1-6 point, these are pressed its distance to W1 from the close-by examples to those far off, be designated as successively V1, V2, V3 ... to Vn; By V1, V2, V3 ... order to Vn scans;
As F=1, crossing a scan start point and be parallel on the straight line of y-axis, from this scan start point towards the enterprising line scanning in direction near W3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
As F=0, crossing a scan start point and be parallel on the straight line of x-axis, from this scan start point towards the enterprising line scanning in direction near W3, when finding identical with a view finding graphic color point or the point of scanning to distance >=the first threshold values of W4 time, stop the scanning on this straight line, the point that this is identical with view finding graphic color is recorded as real frontier point;
Find out with V1, V2, V3 ... with all real frontier point that Vn is scan start point, simulate straight line, this straight line is W4 ';
S105425: the 3rd two-dimension code area is decoded.
Wherein, according to real frontier point, the method for matching W3 ' and/or W4 ' can adopt Hough transform method or least square method.
Quick Response Code resistant to damage coding/decoding method recognition capability of the present invention is strong, can pollute, destroy the environmental applications of Quick Response Code at commute, even if a damaged limit even two limits when, Z-code still can correctly identify, effectively can expand the usable range of Quick Response Code.