A document image tilt correction method

Through pre -processing and straight -line detection of document images, combined with straight -line -based tilt -angle detection methods, the efficient and accurate tilt correction of the document image is realized, and the problem of inaccurate detection in the existing technologies is solved.

CN118941451BActive Publication Date: 2025-01-28SHANGHAI ZHIYU INFORMATION TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411383212.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2025-01-28
Estimated Expiration
2044-09-30

AI Technical Summary

Technical Problem

In the prior art, when processing document images containing noise or interference lines, it is difficult to accurately detect the inclination angle, and the generalization ability of the model is not strong, making universality and accuracy difficult to ensure.

Method used

A document image tilt correction method is proposed to obtain the inclined angle through document image pre -processing, linear detection and stitching, and straight -line -based tilting angle detection method, and rotate correction.

Benefits of technology

The efficient and accurate correction of tilting document images is achieved, and the accurate acquisition of the tilt angle is ensured. It is suitable for different types of document images, which improves the accuracy and efficiency of processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118941451B_ABST
    Figure CN118941451B_ABST
Patent Text Reader

Abstract

The present invention discloses a document image tilt correction method, comprising the following steps: step S1: reading a tilted document image, graying, binarizing and morphologically processing the tilted document image, and extracting the main features of the tilted document image; step S2: extracting straight line segments in the tilted document image by a straight line detection algorithm, and obtaining the tilt angle; if no straight line segment is detected, firstly using text contour analysis to roughly estimate the tilt angle of the tilted document image, and then using a rank decomposition method to obtain a fine tilt angle; step S3: performing rotation correction on the tilted document image according to the detected tilt angle. The present invention combines straight line and text features to achieve high-precision detection of the tilt angle of the document image, and can effectively correct the tilted document image, is suitable for processing various tilted document images, and improves the accuracy and efficiency of document image processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of document image processing, and in particular relates to a document image tilt correction method. Background Art

[0002] With the popularization of office automation and the widespread application of scanning technology, a large number of paper documents are converted into digital images for storage, transmission and processing. However, in actual operation, due to factors such as the instability of scanning equipment and the deviation of the paper placement angle, the document image often tilts to varying degrees. This tilt phenomenon not only affects the overall appearance of the document, but also causes difficulties in subsequent digital processing processes such as image recognition, text extraction, and layout analysis, reducing the accuracy and efficiency of the processing.

[0003] There is a patent document named "A document image tilt correction method and device based on projection variance minimization" (publication number: CN114202650A), which uses a projection method to select the tilt angle by calculating the projection variance, and then performs rotation correction. However, when there is a large amount of noise and interference lines in the image, the projection method cannot accurately detect the tilt angle of the image. Another example is a patent document named "A complex archival image tilt correction method based on convolutional neural network" (publication number: CN110211048B), which constructs a text line positioning model, segments the text lines and calculates the tilt angle, and performs overall tilt correction on the document body according to the tilt angle. However, the generalization ability of the model is not strong, and it is difficult to guarantee universality and accuracy.

[0004] Therefore, it is particularly important to develop a new method that can accurately correct the tilt of document images while taking into account adaptability and robustness. This patented technology came into being in this context, aiming to achieve efficient and accurate correction of document image tilt problems through innovative image processing algorithms and strategies. Summary of the invention

[0005] In order to solve the above technical problems, the present invention proposes a document image tilt correction method, which can detect the tilt angle of a tilted document image and correct the tilted document image efficiently.

[0006] The technical solution adopted by the present invention is as follows: a document image tilt correction method, comprising the following steps:

[0007] Step S1: Document image preprocessing: Read document image I, grayscale and binarize document image I to obtain a second image I g , for the second image I g Perform morphological processing to obtain the third image I p ;

[0008] Step S2: Tilt angle detection: For the second image I g Perform straight line detection. If a straight line segment is detected, store the detected straight line segment in a straight line segment set L, divide the straight line segment set L into a first horizontal line segment set Lh1 and a first vertical line segment set Lv1, splice adjacent horizontal line segments in the first horizontal line segment set Lh1 to obtain a second horizontal line segment set Lh2, and splice adjacent vertical line segments in the first vertical line segment set Lv1 to obtain a second vertical line segment set Lv2; according to the second horizontal line segment set Lh2 and the second vertical line segment set Lv2, use the inclination angle detection method based on straight line processing to obtain the first inclination angle Angle_s, and assign the first inclination angle Angle_s to the correction inclination angle Angle; if no straight line segment is detected, first perform a third image I p A rough tilt angle is estimated to obtain a rough tilt angle Angle_r, and then a fine tilt angle detection method is used to obtain a second tilt angle Angle_e according to the rough tilt angle Angle_r, and the second tilt angle Angle_e is assigned to the correction tilt angle Angle;

[0009] Step S3: Rotation correction: According to the correction angle Angle, the document image I is subjected to rotation correction to obtain the corrected document image I c .

[0010] Furthermore, in step S2, the straight line segment set L is divided into a first horizontal line segment set Lh1 and a first vertical line segment set Lv1, and the specific steps are as follows:

[0011] Step S211, traverse all straight line segments in the straight line set L, let l represent the straight line segment currently being judged, let y start and x start Respectively represent the y coordinate and x coordinate of the starting point of the line segment l currently being judged. Let y end and x end They respectively represent the y-coordinate and x-coordinate of the end point of the straight line segment l currently being judged;

[0012] Step S212, if x end =x start , then the straight line segment l currently being judged is determined to be a vertical line segment, and the straight line segment l currently being judged is added to the first vertical line segment set Lv1; if y end =y start , then the straight line segment l currently being judged is determined to be a horizontal line segment, and the straight line segment l currently being judged is added to the first horizontal line segment set Lh1;

[0013] Otherwise, the slope kl of the straight line segment l currently being judged is calculated using formula (1);

[0014] kl = (y2-y1) / (x2-x1)(1);

[0015] Where kl is the slope, let x1 represent the x-coordinate of the left endpoint of a line segment, let y1 represent the y-coordinate of the left endpoint of a line segment, let x2 represent the x-coordinate of the right endpoint of a line segment, and let y2 represent the y-coordinate of the right endpoint of a line segment;

[0016] Step S213, if |kl|>1, determine that the straight line segment l currently being judged is a vertical line segment, and add the straight line segment l currently being judged to the first vertical line segment set Lv1; otherwise, determine that the straight line segment l currently being judged is a horizontal line segment, and add the straight line segment l currently being judged to the first horizontal line segment set Lh1.

[0017] Furthermore, in step S2, adjacent horizontal line segments in the first horizontal line segment set Lh1 are spliced ​​to obtain a second horizontal line segment set Lh2. The specific steps are as follows:

[0018] Step S2201, sorting all horizontal line segments in the first horizontal line segment set Lh1 in ascending order according to the y coordinates of the left endpoints of the horizontal line segments;

[0019] Step S2202, set the first distance threshold Td1, set the second distance threshold Td2, let lh i represents the i-th horizontal line segment of the first horizontal line segment set Lh1, i=1,2,…,ni, ni is the number of horizontal line segments in the first horizontal line segment set Lh1;

[0020] Step S2203, define a horizontal line segment splicing mark set Fh containing n splicing mark variables, the i-th variable fh in the horizontal line segment splicing mark set Fh i represents the splicing mark of the i-th horizontal line segment in the first horizontal line segment set, and the splicing mark fh of the i-th horizontal line segment in the first horizontal line segment set i The initial value is set to 0; the first variable k and the second variable j are set; the initial value of the first variable k is set to 0;

[0021] Step S2204: increase the value of the first variable k by 1. If k>ni-1, jump to step S2212;

[0022] Step S2205, if fh k =1, where fh k represents the splicing mark of the kth horizontal line segment in the first horizontal line segment set, jump to step S2204, otherwise, set the value of the second variable j to the first variable k;

[0023] Step S2206, increase the value of the second variable j by 1, if j>n, jump to step S2204;

[0024] Step S2207, if fh j = 1, where fh j represents the splicing mark of the j-th horizontal line segment in the first set of horizontal line segments, then jump to Step S2206;

[0025] Step S2208, if x k right < x j left , where x k right represents the x coordinate of the right endpoint of the k-th horizontal line segment in the first set of horizontal line segments Lh1, and x j left represents the x coordinate of the left endpoint of the j-th horizontal line segment in the first set of horizontal line segments Lh1, then determine that the k-th horizontal line segment lh k in the first set of horizontal line segments is located to the left of the j-th horizontal line segment lh j in the first set of horizontal line segments; if x j right < x k left , where x j right represents the x coordinate of the right endpoint of the j-th horizontal line segment in the first set of horizontal line segments Lh1, and x k left represents the x coordinate of the left endpoint of the k-th horizontal line segment in the first set of horizontal line segments Lh1, then determine that the j-th horizontal line segment lh j in the first set of horizontal line segments is located to the left of the k-th horizontal line segment lh k in the first set of horizontal line segments Lh1;

[0026] Step S2209, if the k-th horizontal line segment lh k in the first set of horizontal line segments Lh1 is located to the left of the j-th horizontal line segment lh j in the first set of horizontal line segments, |x k right - x j left | < Td1, and |y k right - y j left | < Td1, then connect the left endpoint of the k-th horizontal line segment lh k in the first set of horizontal line segments Lh1 to the right endpoint of the j-th horizontal line segment lh j in the first set of horizontal line segments to obtain the horizontal splicing line segment lc k,j ; otherwise, if the j-th horizontal line segment lh jThe k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k On the left, |x j right -x k left | < Td1, and |y j right -y k left | < Td1, then connect the left endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments to the right endpoint of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 to obtain the horizontal splicing line segment lc j ; Otherwise, jump to step S2206; k ; Otherwise, jump to step S2206; k,j ; Otherwise, jump to step S2206;

[0027] Step S2210, when the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k Is on the left of the j-th horizontal line segment lh in the first set of horizontal line segments j , calculate the vertical distance dh from the right endpoint of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k To the horizontal splicing line segment lc k,j And the vertical distance dh from the left endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments k,2 To the horizontal splicing line segment lc j ; When the j-th horizontal line segment lh in the first set of horizontal line segments k,j Is on the left of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 j,3 , calculate the vertical distance dh from the left endpoint of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 j To the horizontal splicing line segment lc k And the vertical distance dh from the right endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments k To the horizontal splicing line segment lc k,j ; k,1 ; j To the horizontal splicing line segment lc k,j ; j,4 ;

[0028] The specific method for calculating the vertical distance d1 from a point po to a line segment is:

[0029] Let x0 represent the x coordinate of the point po, and let y0 represent the y coordinate of the point po; use formula (2) to calculate the vertical distance d1 from the point po to the line segment:

[0030] (2);

[0031] Step S2211, if dh k,1 < Td2 and dh j,4<Td2, dh k,2 <Td2 and dh j,3 <Td2, then set the splicing flag fh of the k-th horizontal line segment in the first set of horizontal line segments k and the splicing flag fh of the j-th horizontal line segment in the first set of horizontal line segments j both to 1, and add the horizontal splicing line segment lc k,j to the second set of horizontal line segments Lh2; jump to step S2204;

[0032] Step S2212, traverse each splicing flag in the set of horizontal line segment splicing flags Fh. If the i-th variable fh in the set of horizontal line segment splicing flags Fh i is 0, then add the i-th horizontal line segment lh in the first set of horizontal line segments Lh1 i to the second set of horizontal line segments Lh2.

[0033] Furthermore, in step S2, splice adjacent vertical line segments in the first set of vertical line segments Lv1 to obtain the second set of vertical line segments Lv2. The specific steps are as follows:

[0034] Step S2301, sort each vertical line segment in the first set of vertical line segments Lv1 in ascending order according to the x coordinate of the upper endpoint of the vertical line segment;

[0035] Step S2302, let lv j represent the j-th vertical line segment in the first set of vertical line segments Lv1, j = 1, 2,..., nj, where nj is the number of vertical line segments in the first set of vertical line segments Lv1;

[0036] Step S2303, define a set of vertical line segment splicing flags Fv containing m splicing flag variables. The j-th variable fv in the set of vertical line segment splicing flags Fv j represents the splicing flag of the j-th vertical line segment in the first set of vertical line segments. The splicing flag fv of the j-th vertical line segment in the first set of vertical line segments j is initially set to 0; set the third variable u and the fourth variable s; the initial value of the third variable u is set to 0;

[0037] Step S2304, increase the value of the third variable u by 1. If u > nj - 1, then jump to step S2312;

[0038] Step S2305, if fv u = 1, where fv u represents the splicing flag of the u-th vertical line segment in the first set of vertical line segments, then jump to step S2304, otherwise, set the value of the fourth variable s to u;

[0039] Step S2306, increment the value of the fourth variable s by 1. If s > nj, jump to step S2304;

[0040] Step S2307, if fv j = 1, where fv j represents the splicing flag of the j-th vertical line segment in the first set of vertical line segments, then jump to step S2306;

[0041] Step S2308, if y s down < y u up where y s down represents the y-coordinate of the lower endpoint of the s-th vertical line segment in the first set of vertical line segments Lv1, and y u up represents the y-coordinate of the upper endpoint of the u-th vertical line segment in the first set of vertical line segments Lv1, then determine that the s-th vertical line segment lv s in the first set of vertical line segments Lv1 is located above the u-th vertical line segment lv u in the first set of vertical line segments Lv1; if y u down < y s up where y u down represents the y-coordinate of the lower endpoint of the u-th vertical line segment in the first set of vertical line segments Lv1, and y s up represents the y-coordinate of the upper endpoint of the s-th vertical line segment in the first set of vertical line segments Lv1, then determine that the u-th vertical line segment lv u in the first set of vertical line segments Lv1 is located above the s-th vertical line segment lv s in the first set of vertical line segments Lv1;

[0042] Step S2309, if the u-th vertical line segment lv u in the first set of vertical line segments Lv1 is located above the s-th vertical line segment lv s in the first set of vertical line segments Lv1, |x u down - x s up | < Td1, and |y u down - y s up | < Td1, then connect the upper endpoint of the u-th vertical line segment lv u in the first set of vertical line segments Lv1 to the lower endpoint of the s-th vertical line segment lv s in the first set of vertical line segments Lv1 to obtain the vertical splicing line segment lcu,s ; Otherwise, if the sth vertical line segment lv in the first set of vertical line segments Lv1 s is above the uth vertical line segment lv in the first set of vertical line segments Lv1 u and |x s down - x u up | < Td1 and |y s down - y u up | < Td1, then connect the upper endpoint of the sth vertical line segment lv in the first set of vertical line segments Lv1 s to the lower endpoint of the uth vertical line segment lv in the first set of vertical line segments Lv1 u to obtain the vertical splicing line segment lc u,s ; Otherwise, jump to step S2306;

[0043] Step S2310, calculate the vertical distance dv from the upper endpoint of the uth vertical line segment lv in the first set of vertical line segments Lv1 u to the vertical splicing line segment lc u,s , the vertical distance dv from the lower endpoint of the uth vertical line segment lv in the first set of vertical line segments Lv1 u,1 to the vertical splicing line segment lc u , the vertical distance dv from the upper endpoint of the sth vertical line segment lv in the first set of vertical line segments Lv1 u,s to the vertical splicing line segment lc u,2 and the vertical distance dv from the lower endpoint of the sth vertical line segment lv in the first set of vertical line segments Lv1 s to the vertical splicing line segment lc u,s using formula (2); s,3 and the vertical distance dv from the lower endpoint of the sth vertical line segment lv in the first set of vertical line segments Lv1 s to the vertical splicing line segment lc u,s ; s,4 ;

[0044] Step S2311, if dv u,1 < Td2, dv u,2 < Td2, dv s,3 < Td2, dv s,4 < Td2, then set the splicing marks fv of the uth vertical line segment and the sth vertical line segment in the set of vertical line segments to 1, and add the vertical splicing line segment lc u to the second set of vertical line segments Lv2; jump to step S2304; s ; u,s ;

[0045] Step S2312, traverse each splicing mark in the vertical line segment splicing mark set Fv, if the j-th variable fv in the vertical line segment splicing mark set Fv j is 0, then the jth vertical line segment lv in the first vertical line segment set Lv1 j Add the second vertical line segment set Lv2.

[0046] Further, in step S2, according to the second horizontal line segment set Lh2 and the second vertical line segment set Lv2, the first inclination angle Angle_s is obtained by using the inclination angle detection method based on straight line processing, and the specific steps are as follows:

[0047] Step S241, setting a third horizontal line segment set Lh3, traversing each vertical line segment in the second vertical line segment set Lv2, rotating each vertical line segment 90 degrees clockwise around the center point of the vertical line segment, and adding the vertical line segment to the third horizontal line segment set Lh3;

[0048] Step S242, merging the second horizontal line segment set Lh2 and the third horizontal line segment set Lh3 to generate a fourth horizontal line segment set Lh4;

[0049] Step S243, setting a fifth horizontal line segment set Lh5, setting a line segment length threshold Tc, and traversing all horizontal line segments in the fourth horizontal line segment set Lh4;

[0050] Step S2431, let la v represents the vth horizontal line segment currently traversed, v=1,2,…,nv, nv is the number of line segments in the fourth horizontal line segment set Lh4;

[0051] Step S2432, let x c left Indicates the vth horizontal line segment la currently traversed v The x coordinate of the left endpoint of c right Indicates the vth horizontal line segment la currently traversed v The x coordinate of the right endpoint of c left Indicates the vth horizontal line segment la currently traversed v The y coordinate of the left endpoint, let y c right Indicates the vth horizontal line segment la currently traversed v Calculate the y coordinate of the right endpoint of the currently traversed vth horizontal line segment la v The calculation formula of the line segment length len is shown in formula (3):

[0052] (3);

[0053] Step S2433, if len>Tc, then the currently traversed vth horizontal line segment la v Add the fifth horizontal line segment set Lh5;

[0054] Step S244, setting a first slope set K1, and traversing all horizontal line segments in the fifth horizontal line segment set Lh5;

[0055] Step S245, let lb e represents the e-th horizontal line segment currently traversed, e=1,2,…,ne, ne is the number of line segments in the fifth horizontal line segment set Lh5;

[0056] Formula (1) is used to calculate the e-th horizontal line segment lb currently traversed e The slope of the line segment kc e , the line segment slope kc e Add the first slope set K1;

[0057] Step S246, using the median absolute deviation method to remove outliers from the first slope set K1 to obtain a second slope set K2;

[0058] Step S247: according to each slope k in the second slope set K2 r , calculate the average slope ave_k of the second slope set K2, where r=1,2,…,nr, nr is the number of slopes in the second slope set K2, and the calculation formula of the average slope of the second slope set K2 is shown in formula (4):

[0059] (4);

[0060] Step S248, convert the average slope ave_k of the second slope set K2 into an angle to obtain a first inclination angle Angle_s. The angle conversion formula is shown in formula (5):

[0061] (5);

[0062] Here, arctan represents the inverse tangent function.

[0063] Furthermore, in step S2, the third image I p Perform a rough tilt angle estimation to obtain a rough tilt angle Angle_r. The specific steps are as follows:

[0064] Step S251: for the third image I p Perform contour detection, and add the detected text line contour to the first text line contour set C1;

[0065] Step S252, for each text line contour in the first text line contour set C1, a maximum circumscribed rectangle of the text line contour is calculated, and the text line contours in the first text line contour set C1 are sorted in descending order according to the width of the maximum circumscribed rectangle of the text line contour to obtain a sorted second text line contour set C2;

[0066] Step S253, setting a first text line slope set KD1, and traversing all text line contours in the second text line contour set C2;

[0067] Step S254, using the median absolute deviation method to remove outliers from the first text line slope set KD1, to obtain the second text line slope set KD2;

[0068] Step S255: according to each slope k in the second text line slope set KD2 t , calculate the average slope ave_k of the second text line slope set KD2 D , where t=1,2,…, nt, nt is the number of slopes in the second text line slope set KD2, and the average slope calculation formula of the second text line slope set KD2 is shown in formula (6):

[0069] (6);

[0070] Step S256: The average slope ave_k of the second text line slope set KD2 is D Convert to angle to get the rough tilt angle Angle_r. The angle conversion formula is shown in formula (7):

[0071] (7).

[0072] Further, in step S253, a first text line slope set KD1 is set, and all text line contours in the second text line contour set C2 are traversed; specifically:

[0073] Step S2531, let c g represents the g-th text line contour currently traversed, where g=1,2,...,ng, and ng is the total number of text line contours in the second text line contour set C2;

[0074] Step S2532, let hc g and wc g Represent the text line contour c g The height and width of the maximum enclosing rectangle generate a rectangle with a height of hc g , width is wc g And the text line contour mask matrix Mc with all values ​​0 g , the text line contour mask matrix Mcg Perform masking, specifically:

[0075] Step S25321, traverse the text line contour c g All the text line contour points in p c g,w Represents the text line contour c g The w-th text line contour point, w=1,2,...,nw, nw represents the text line contour c g The total number of text line contour points, let x c g,w Represents the text line contour point p c g,w The x coordinate of c g,w Represents the text line contour point p c g,w The y coordinate of

[0076] Step S25322: transform the text line contour mask matrix Mc g The coordinates of the point (x c g,w, y c g,w ) is set to 1;

[0077] Step S2533, set the first mask center point set Dm1, traverse the text line contour mask matrix Mc g All columns of

[0078] Step S25331, let col z Represents the contour mask matrix Mc of the currently traversed text line g Columns, where z=1,2,...,nz, nz is the text line contour mask matrix Mc g The total number of columns;

[0079] Step S25332, obtain the contour mask matrix Mc of the text line currently traversed g col z The y coordinate of the first pixel whose value is 1 z start , get the contour mask matrix Mc of the currently traversed text line g col z The y coordinate of the last pixel whose value is 1 z end , calculate the contour mask matrix Mc of the currently traversed text line g col z The y coordinate of the center point y z , the calculation formula is shown in formula (8):

[0080] y z =(y z start +y z end ) / 2 (8);

[0081] Step S25333: transform the contour mask matrix Mc of the currently traversed text line into g col z The center point (z,y z ) add the first mask center point set Dm1;

[0082] Step S2534, using the median absolute deviation method to remove outliers from the first mask center point set Dm1 to obtain the second mask center point set Dm2;

[0083] Step S2535, set the first mask parameter a, set the second mask parameter b, and set N m represents the total number of mask center points in the second mask center point set Dm2. From the second mask center point set Dm2, select The mask center point is selected as the first mask center point, and the The mask center point is used as the second mask center point, where is the round-up symbol, is the rounding down symbol; connect the first mask center point and the second mask center point into a straight line segment to obtain the text line contour mask matrix Mc g Center line lm g ;

[0084] Step S2536, using formula (1) to calculate the text line contour mask matrix Mc g Center line lm g The slope kc g , the slope kc g Add the first text line slope set KD1.

[0085] Furthermore, in step S2, according to the rough tilt angle Angle_r, a fine tilt angle detection method is used to obtain a second tilt angle Angle_e, and the specific steps are as follows:

[0086] Step S2601, set the first rank value set TR1, set the first angle set TA1, set the rotation angle threshold H, set the rotation step step; let angle represent the current rotation angle, initialize the current rotation angle angle to Angle_r-H; let angle_end represent the maximum rotation angle, initialize the maximum rotation angle angle_end to Angle_r+H;

[0087] Step S2602: for the second image I g Rotate the current rotation angle angle around the origin to obtain the rotated image I r ;

[0088] Step S2603, setting a redundant marker set DE, and traversing all rank values ​​in the first rank value set TR1;

[0089] Step S2604, traverse all redundant tags in the redundant tag set DE;

[0090] Step S2605, setting a second rank value set TR2, setting a second angle set TA2, setting a search flag Find, and initializing the value of the search flag Find to 0;

[0091] Step S2606, obtaining the index number of the minimum rank value in the first rank value set TR1 by finding the minimum value point, and obtaining the minimum rank value index number set DI;

[0092] Step S2607: if the minimum rank value index number set DI is empty, the value of the search flag Find is set to 1, the minimum rank value Rtr1 in the first rank value set TR1 is obtained, and the process jumps to step S2611;

[0093] Step S2608, setting the value of the search flag Find to 2, searching the first angle and the first rank value set TR1 in the first angle set TA1 according to the minimum rank value index number in the minimum rank value index number set DI, and generating the second angle set TA2 and the second rank value set TR2;

[0094] Step S2609, obtaining the minimum rank value Rtr2 in the second rank value set TR2;

[0095] Step S2610, according to the index number index1 of the minimum rank value Rtr2 in the second rank value set TR2, find the angle value Ar2 with the index number index1 in the second angle set TA2, and assign the angle value Ar2 to the second inclination angle Angle_e;

[0096] Step S2611, if Find=1, then according to the index number index2 of the minimum rank value Rtr1 in the first rank value set TR1, find the angle value Ar1 with the index number index2 in the first angle set TA1, and assign the angle value Ar1 to the second inclination angle Angle_e.

[0097] Further, in step S2602, the second image I g Rotate the current rotation angle angle around the origin to obtain the rotated image I r ; Specifically:

[0098] Step S26021, the rotated image I r Convert to the rotation image matrix M r , the singular value decomposition method is used to rotate the image matrix M r Process and obtain the rotation image rank value R r ;

[0099] Step S26022, add the current rotation angle angle to the first angle set TA1, and set the rotation image rank value R r Add the first rank value set TR1;

[0100] Step S26023, increase the value of the current rotation angle angle by step, if angle≤angle_end, jump to step S2602;

[0101] Step S2603, set a redundant marker set DE, and traverse all rank values ​​in the first rank value set TR1; specifically:

[0102] Step S26031, let r m Represents the mth rank value currently traversed, let r m+1 Indicates the m+1th rank value currently traversed, let a m represents the mth angle value in the first angle set TA1, let a m+1 represents the m+1th angle value in the first angle set TA1, where m=1, 2, ..., nm-1, and nm is the total number of rank values ​​in the first rank value set TR1;

[0103] Step S26032, if r m =r m+1 , then the mth angle value a in the first angle set TA1 m The value is set to (a m +a m+1 ) / 2, add m+1 to the redundant marker set DE;

[0104] Step S2604, traverse all redundant tags in the redundant tag set DE; specifically:

[0105] Step S26041, let de s represents the sth redundant marker currently traversed, where s=1,2,...,ns, and ns is the total number of redundant markers in the redundant marker set DE;

[0106] Step S26042: Delete the first angle set TA1 with index number de s content;

[0107] Step S26043: Delete the index number de in the first rank value set TR1. s content;

[0108] Step S2608, set the value of the search flag Find to 2, search the first angle and the first rank value set TR1 in the first angle set TA1 according to the minimum rank value index number in the minimum rank value index number set DI, and generate the second angle set TA2 and the second rank value set TR2. The specific steps are as follows:

[0109] Step S26081, traverse the index numbers of all the minimum rank values ​​in the minimum rank value index number set DI, let d q represents the index number of the qth minimum rank value in the minimum rank value index number set DI, q=1, 2, ..., nq, and nq represents the total number of index numbers of the minimum rank values ​​in the minimum rank value index number set DI;

[0110] Step S26082: set the index number d in the first angle set TA1 q The content is added to the second angle set TA2;

[0111] Step S26083: set the index number d in the first rank value set TR1 q The content of is added to the second rank value set TR2.

[0112] The beneficial effects of the present invention are as follows: the present invention provides a document image tilt correction method, which effectively utilizes the text line features and straight line features in the tilted document image to ensure the accurate acquisition of the tilt angle, is suitable for tilt angle detection and rotation correction of tilted document images, and can achieve a high-precision tilt correction effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0113] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0114] Figure 1 is a flow chart of the method of Embodiment 1 and Embodiment 2 of the present invention;

[0115] Figure 2 is the original image of Example 1 of the present invention;

[0116] Figure 3 is a schematic diagram of the text line contour centerline obtained in step S2 of embodiment 1 of the present invention;

[0117] Figure 4 is a tilt correction result diagram obtained in step S3 of embodiment 1 of the present invention;

[0118] Figure 5 is the original image of Example 2 of the present invention;

[0119] Figure 6 is a schematic diagram of straight line processing obtained in step S2 of embodiment 2 of the present invention;

[0120] Figure 7 This is a diagram of the tilt correction result obtained in step S3 of embodiment 2 of the present invention. DETAILED DESCRIPTION

[0121] The specific implementation of the present invention will be further described in detail below in conjunction with the accompanying drawings in the embodiments of the present invention. It should be noted that the specific embodiment of the document image tilt correction method according to the present invention is only used as an example and is not intended to limit the present invention.

[0122] This embodiment takes two types of document images, namely, a document image without straight line segments and a document image with straight line segments as examples, respectively as Embodiment 1 and Embodiment 2, to illustrate a document image tilt correction method proposed by the present invention.

[0123] Embodiment 1, as Figure 1 As shown, the present invention adopts the following steps to correct the tilted document image:

[0124] Step S1: document image preprocessing; reading document image I, such as Figure 2 As shown, the document image I is grayed and binarized to obtain a second image I g , for the second image I g Perform morphological processing to obtain the third image I p ;

[0125] The image binarization algorithm in the above steps is a common method for image binarization. For details, see Lv Junzhe. Research on Image Binarization Algorithm and Its Implementation [J]. Library and Information Guide, 2004, 14(12): 266-267.

[0126] The morphological processing algorithm in the above steps is a common method for image morphological processing. For details, see Wu Ying. Application of Morphological Image Processing [J]. Computers and Modernization, 2013(5):5.DOI:10.3969 / j.issn.1006-2475.2013.05.021;

[0127] Step S2: Tilt angle detection: For the second image I g Perform straight line detection. If no straight line segment is detected, first perform the third image I p A rough tilt angle is estimated to obtain a rough tilt angle Angle_r, and then a fine tilt angle detection method is used to obtain a second tilt angle Angle_e according to the rough tilt angle Angle_r, and the second tilt angle Angle_e is assigned to the correction tilt angle Angle;

[0128] The line detection algorithm in the above steps is a common method for line detection in images. For details, see Chen Gaikai. Line detection based on Hough transform [J]. Journal of Xi'an Aeronautical University, 2007, 25(3):34-36. DOI:10.3969 / j.issn.1008-9233.2007.03.012;

[0129] Step S3: Rotation correction: According to the correction angle Angle, the document image I is subjected to rotation correction to obtain the corrected document image I c ,like Figure 4 shown.

[0130] Furthermore, in step S2, the third image I p The rough tilt angle is estimated to obtain the rough tilt angle Angle_r. The specific steps are as follows:

[0131] Step S251: for the third image I p Perform contour detection, and add the detected text line contour to the first text line contour set C1;

[0132] The contour detection algorithm in the above steps is a common method for contour detection in images. For details, see Zhang Yi, Kuang Yi, Wang Mei, et al. Human contour detection algorithm based on OpenCV[J]. Computer Technology and Development, 2020, 30(8):5. DOI:10.3969 / j.issn.1673-629X.2020.08.013;

[0133] Step S252, for each text line contour in the first text line contour set C1, a maximum circumscribed rectangle of the text line contour is calculated, and the text line contours in the first text line contour set C1 are sorted in descending order according to the width of the maximum circumscribed rectangle of the text line contour to obtain a sorted second text line contour set C2;

[0134] Step S253, setting a first text line slope set KD1, and traversing all text line contours in the second text line contour set C2;

[0135] Step S2531, let c g represents the g-th text line contour currently traversed, where g=1,2,...,ng, and ng is the total number of text line contours in the second text line contour set C2;

[0136] Step S2532, let hc g and wc g Represent the text line contour c gThe height and width of the maximum enclosing rectangle generate a rectangle with a height of hc g , width is wc g And the text line contour mask matrix Mc with all values ​​0 g , the text line contour mask matrix Mc g Perform masking, specifically:

[0137] Step S25321, traverse the text line contour c g All the text line contour points in p c g,w Represents the text line contour c g The w-th text line contour point, w=1,2,...,nw, nw represents the text line contour c g The total number of text line contour points, let x c g,w Represents the text line contour point p c g,w The x coordinate of c g,w Represents the text line contour point p c g,w The y coordinate of

[0138] Step S25322: transform the text line contour mask matrix Mc g The coordinates of the point (x c g,w, y c g,w ) is set to 1;

[0139] Step S2533, set the first mask center point set Dm1, traverse the text line contour mask matrix Mc g All columns of

[0140] Step S25331, let col z Represents the contour mask matrix Mc of the currently traversed text line g Columns, where z=1,2,...,nz, nz is the text line contour mask matrix Mc g The total number of columns;

[0141] Step S25332, obtain the contour mask matrix Mc of the text line currently traversed g col z The y coordinate of the first pixel whose value is 1 z start , get the contour mask matrix Mc of the currently traversed text line g col z The y coordinate of the last pixel whose value is 1 z end, calculate the contour mask matrix Mc of the currently traversed text line g col z The y coordinate of the center point y z , the calculation formula is shown in formula (8):

[0142] y z =(y z start +y z end ) / 2(8);

[0143] Step S25333: transform the contour mask matrix Mc of the currently traversed text line into g col z The center point (z,y z ) add the first mask center point set Dm1;

[0144] Step S2534, using the median absolute deviation method to remove outliers from the first mask center point set Dm1 to obtain the second mask center point set Dm2;

[0145] The median absolute deviation algorithm in the above steps is a common method for calculating outliers. For details, see Gong Xunqiang, Zhang Fangze, Lu Tieding, et al. Abnormal training sample detection method based on median absolute deviation[J]. Laser & Optoelectronics Progress, 2020, 57(23):6.DOI:10.3788 / LOP57.231202;

[0146] Step S2535, set the first mask parameter a=0.25, set the second mask parameter b=0.75, and set N m represents the total number of mask center points in the second mask center point set Dm2. From the second mask center point set Dm2, select The mask center point is selected as the first mask center point, and the The mask center point is used as the second mask center point, where is the round-up symbol, is the rounding down symbol; connect the first mask center point and the second mask center point into a straight line segment to obtain the text line contour mask matrix Mc g Center line lm g ,like Figure 3 As shown;

[0147] Step S2536, using formula (1) to calculate the text line contour mask matrix Mc g Center line lm g The slope kc g , the slope kc g Add the first text line slope set KD1;

[0148] Step S254, using the median absolute deviation method to remove outliers from the first text line slope set KD1, to obtain the second text line slope set KD2;

[0149] The median absolute deviation algorithm in the above steps is a common method for calculating outliers. For details, see Gong Xunqiang, Zhang Fangze, Lu Tieding, et al. Abnormal training sample detection method based on median absolute deviation[J]. Laser & Optoelectronics Progress, 2020, 57(23):6.DOI:10.3788 / LOP57.231202;

[0150] Step S255: according to each slope k in the second text line slope set KD2 t , calculate the average slope ave_k of the second text line slope set KD2 D , where t=1,2,…, nt, nt is the number of slopes in the second text line slope set KD2, and the average slope calculation formula of the second text line slope set KD2 is shown in formula (6):

[0151] (6);

[0152] Step S256: The average slope ave_k of the second text line slope set KD2 is D Convert to angle to get the rough tilt angle Angle_r. The angle conversion formula is shown in formula (7):

[0153] (7).

[0154] Further, in step S2, according to the rough tilt angle Angle_r, a fine tilt angle detection method is used to obtain a second tilt angle Angle_e, and the specific steps are as follows:

[0155] Step S2601, set the first rank value set TR1, set the first angle set TA1, set the rotation angle threshold H=1.5, set the rotation step step=0.1; let angle represent the current rotation angle, initialize the current rotation angle angle to Angle_r-H; let angle_end represent the maximum rotation angle, initialize the maximum rotation angle angle_end to Angle_r+H;

[0156] Step S2602: for the second image I g Rotate the current rotation angle angle around the origin to obtain the rotated image I r ;

[0157] Step S26021, the rotated image Ir Convert to the rotation image matrix M r , the singular value decomposition method is used to rotate the image matrix M r Process and obtain the rotation image rank value R r ;

[0158] The singular value decomposition method in the above steps is a common method for solving the rank of a matrix. For details, see Zhao Feng, Huang Qingming, Gao Wen. An image matching algorithm based on singular value decomposition [J]. Computer Research and Development, 2010(01):25-34.DOI:CNKI:SUN:JFYZ.0.2010-01-005;

[0159] Step S26022, add the current rotation angle angle to the first angle set TA1, and set the rotation image rank value R r Add the first rank value set TR1;

[0160] Step S26023, increase the value of the current rotation angle angle by step, if angle≤angle_end, jump to step S2602;

[0161] Step S2603, setting a redundant marker set DE, and traversing all rank values ​​in the first rank value set TR1;

[0162] Step S26031, let r m Represents the mth rank value currently traversed, let r m+1 Indicates the m+1th rank value currently traversed, let a m represents the mth angle value in the first angle set TA1, let a m+1 represents the m+1th angle value in the first angle set TA1, where m=1, 2, ..., nm-1, and nm is the total number of rank values ​​in the first rank value set TR1;

[0163] Step S26032, if r m =r m+1 , then the mth angle value a in the first angle set TA1 m The value is set to (a m +a m+1 ) / 2, add m+1 to the redundant marker set DE;

[0164] Step S2604, traverse all redundant tags in the redundant tag set DE;

[0165] Step S26041, let de s represents the sth redundant marker currently traversed, where s=1,2,...,ns, and ns is the total number of redundant markers in the redundant marker set DE;

[0166] Step S26042: Delete the first angle set TA1 with index number de s content;

[0167] Step S26043: Delete the index number de in the first rank value set TR1. s content;

[0168] Step S2605, setting a second rank value set TR2, setting a second angle set TA2, setting a search flag Find, and initializing the value of the search flag Find to 0;

[0169] Step S2606, obtaining the index number of the minimum rank value in the first rank value set TR1 by finding the minimum value point, and obtaining the minimum rank value index number set DI;

[0170] Step S2607, if the minimum rank value index sequence number set DI is empty, the value of the search flag Find is set to 1, the minimum rank value Rtr1 in the first rank value set TR1 is obtained, and the process jumps to step S2611;

[0171] Step S2608, set the value of the search flag Find to 2, search the first angle and the first rank value set TR1 in the first angle set TA1 according to the minimum rank value index number in the minimum rank value index number set DI, and generate the second angle set TA2 and the second rank value set TR2. The specific steps are as follows:

[0172] Step S26081, traverse the index numbers of all the minimum rank values ​​in the minimum rank value index number set DI, let d q represents the index number of the qth minimum rank value in the minimum rank value index number set DI, q=1, 2, ..., nq, and nq represents the total number of index numbers of the minimum rank values ​​in the minimum rank value index number set DI;

[0173] Step S26082: set the index number d in the first angle set TA1 q The content is added to the second angle set TA2;

[0174] Step S26083: set the index number d in the first rank value set TR1 q The content of is added to the second rank value set TR2;

[0175] Step S2609, obtaining the minimum rank value Rtr2 in the second rank value set TR2;

[0176] Step S2610, according to the index number index1 of the minimum rank value Rtr2 in the second rank value set TR2, find the angle value Ar2 with the index number index1 in the second angle set TA2, and assign the angle value Ar2 to the second inclination angle Angle_e;

[0177] Step S2611, if Find=1, then according to the index number index2 of the minimum rank value Rtr1 in the first rank value set TR1, find the angle value Ar1 with the index number index2 in the first angle set TA1, and assign the angle value Ar1 to the second inclination angle Angle_e.

[0178] Embodiment 2, as Figure 1 As shown, the present invention adopts the following steps to correct the tilted document image:

[0179] Step S1: document image preprocessing; reading document image I, such as Figure 5 As shown, the document image I is grayed and binarized to obtain a second image I g , for the second image I g Perform morphological processing to obtain the third image I p ;

[0180] The image binarization algorithm in the above steps is a common method for image binarization. For details, see Lv Junzhe. Research on Image Binarization Algorithm and Its Implementation [J]. Library and Information Guide, 2004, 14(12): 266-267.

[0181] The morphological processing algorithm in the above steps is a common method for image morphological processing. For details, see Wu Ying. Application of Morphological Image Processing [J]. Computers and Modernization, 2013(5):5.DOI:10.3969 / j.issn.1006-2475.2013.05.021;

[0182] Step S2: Tilt angle detection: For the second image I g Perform straight line detection and detect straight line segments, such as Figure 6 As shown, the detected straight line segments are stored in a straight line segment set L, and the straight line segment set L is divided into a first horizontal line segment set Lh1 and a first vertical line segment set Lv1, adjacent horizontal line segments in the first horizontal line segment set Lh1 are spliced ​​to obtain a second horizontal line segment set Lh2, and adjacent vertical line segments in the first vertical line segment set Lv1 are spliced ​​to obtain a second vertical line segment set Lv2, and according to the second horizontal line segment set Lh2 and the second vertical line segment set Lv2, a first inclination angle Angle_s is obtained by using an inclination angle detection method based on straight line processing, and the first inclination angle Angle_s is assigned to the correction inclination angle Angle;

[0183] The line detection algorithm in the above steps is a common method for line detection in images. For details, see Chen Gaikai. Line detection based on Hough transform [J]. Journal of Xi'an Aeronautical University, 2007, 25(3):34-36. DOI:10.3969 / j.issn.1008-9233.2007.03.012;

[0184] Step S3: Rotation correction: According to the correction angle Angle, the document image I is subjected to rotation correction to obtain the corrected document image I c ,like Figure 7 As shown;

[0185] Furthermore, in step S2, the straight line segment set L is divided into a first horizontal line segment set Lh1 and a first vertical line segment set Lv1, and the specific steps are as follows:

[0186] Step S211, traverse all straight line segments in the straight line set L, let l represent the straight line segment currently being judged, let y start and x start Respectively represent the y coordinate and x coordinate of the starting point of the line segment l currently being judged. Let y end and x end They respectively represent the y-coordinate and x-coordinate of the end point of the straight line segment l currently being judged;

[0187] Step S212, if x end =x start , then the straight line segment l currently being judged is determined to be a vertical line segment, and the straight line segment l currently being judged is added to the first vertical line segment set Lv1; if y end =y start , then the straight line segment l currently being judged is determined to be a horizontal line segment, and the straight line segment l currently being judged is added to the first horizontal line segment set Lh1;

[0188] Otherwise, the slope kl of the straight line segment l currently being judged is calculated using formula (1);

[0189] kl = (y2-y1) / (x2-x1)(1);

[0190] Where kl is the slope, let x1 represent the x-coordinate of the left endpoint of a line segment, let y1 represent the y-coordinate of the left endpoint of a line segment, let x2 represent the x-coordinate of the right endpoint of a line segment, and let y2 represent the y-coordinate of the right endpoint of a line segment;

[0191] Step S213, if |kl|>1, determine that the straight line segment l currently being judged is a vertical line segment, and add the straight line segment l currently being judged to the first vertical line segment set Lv1; otherwise, determine that the straight line segment l currently being judged is a horizontal line segment, and add the straight line segment l currently being judged to the first horizontal line segment set Lh1.

[0192] Furthermore, in step S2, adjacent horizontal line segments in the first horizontal line segment set Lh1 are spliced ​​to obtain a second horizontal line segment set Lh2, and the specific steps are as follows:

[0193] Step S2201, sorting all horizontal line segments in the first horizontal line segment set Lh1 in ascending order according to the y coordinates of the left endpoints of the horizontal line segments;

[0194] Step S2202, set the first distance threshold Td1=5, set the second distance threshold Td2=5, let lh i represents the i-th horizontal line segment of the first horizontal line segment set Lh1, i=1,2,…,ni, ni is the number of horizontal line segments in the first horizontal line segment set Lh1;

[0195] Step S2203, define a horizontal line segment splicing mark set Fh containing n splicing mark variables, the i-th variable fh in the horizontal line segment splicing mark set Fh i represents the splicing mark of the i-th horizontal line segment in the first horizontal line segment set, and the splicing mark fh of the i-th horizontal line segment in the first horizontal line segment set i The initial value is set to 0; the first variable k and the second variable j are set; the initial value of the first variable k is set to 0;

[0196] Step S2204: increase the value of the first variable k by 1. If k>ni-1, jump to step S2212;

[0197] Step S2205, if fh k =1, where fh k represents the splicing mark of the kth horizontal line segment in the first horizontal line segment set, jump to step S2204, otherwise, set the value of the second variable j to the first variable k;

[0198] Step S2206, increase the value of the second variable j by 1, if j>n, jump to step S2204;

[0199] Step S2207, if fh j =1, where fh j represents the splicing mark of the j-th horizontal line segment in the first horizontal line segment set, then jumps to step S2206;

[0200] Step S2208, if x kright <x j left , where x k right represents the x-coordinate of the right endpoint of the k-th horizontal line segment in the first set of horizontal line segments Lh1, and x j left represents the x-coordinate of the left endpoint of the j-th horizontal line segment in the first set of horizontal line segments Lh1, then it is determined that the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k is located to the left of the j-th horizontal line segment lh in the first set of horizontal line segments j ; if x j right <x k left , where x j right represents the x-coordinate of the right endpoint of the j-th horizontal line segment in the first set of horizontal line segments Lh1, and x k left represents the x-coordinate of the left endpoint of the k-th horizontal line segment in the first set of horizontal line segments Lh1, then it is determined that the j-th horizontal line segment lh in the first set of horizontal line segments j is located to the left of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k ;

[0201] Step S2209, if the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k is located to the left of the j-th horizontal line segment lh in the first set of horizontal line segments j , |x k right - x j left | < Td1, and |y k right - y j left | < Td1, then connect the left endpoint of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k to the right endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments j to obtain the horizontal splicing line segment lc k,j ; otherwise, if the j-th horizontal line segment lh in the first set of horizontal line segments j is located to the left of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k , |x j right - x k left | < Td1, and |y j right - y k left|<Td1, then connect the left endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments to the right endpoint of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 to obtain the horizontal splicing line segment lc j ; otherwise, jump to step S2206; k ; k,j ;

[0202] Step S2210, when the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 k is to the left of the j-th horizontal line segment lh in the first set of horizontal line segments, calculate the vertical distance dh j from the right endpoint of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 to the horizontal splicing line segment lc k and the vertical distance dh k,j from the left endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments to the horizontal splicing line segment lc k,2 ; when the j-th horizontal line segment lh in the first set of horizontal line segments j is to the left of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1, calculate the vertical distance dh k,j from the left endpoint of the k-th horizontal line segment lh in the first set of horizontal line segments Lh1 to the horizontal splicing line segment lc j,3 and the vertical distance dh j from the right endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments to the horizontal splicing line segment lc k ; k ; k,j ; k,1 ; j ; k,j ; j,4 ;

[0203] The specific method for calculating the vertical distance d1 from a point po to a line segment is:

[0204] Let x0 represent the x coordinate of the point po, and let y0 represent the y coordinate of the point po; calculate the vertical distance d1 from the point po to the line segment using formula (2):

[0205] (2);

[0206] Step S2211, if dh k,1 <Td2 and dh j,4 <Td2, dh k,2 <Td2 and dh j,3 <Td2, then set the splicing flags fh k of the k-th horizontal line segment in the first set of horizontal line segments and the splicing flag fh j of the j-th horizontal line segment in the first set of horizontal line segments to 1, and set the horizontal splicing line segment lc k,jAdd the second horizontal line segment set Lh2; jump to step S2204;

[0207] Step S2212, traverse each splicing mark in the horizontal line segment splicing mark set Fh, if the i-th variable fh in the horizontal line segment splicing mark set Fh i is 0, then the i-th horizontal line segment lh in the first horizontal line segment set Lh1 i Add the second horizontal line segment set Lh2.

[0208] Furthermore, in step S2, adjacent vertical line segments in the first vertical line segment set Lv1 are concatenated to obtain a second vertical line segment set Lv2. The specific steps are as follows:

[0209] Step S2301, sorting each vertical line segment in the first vertical line segment set Lv1 in ascending order according to the x coordinate of the upper endpoint of the vertical line segment;

[0210] Step S2302, let lv j represents the j-th vertical line segment of the first vertical line segment set Lv1, j=1,2,…,nj, nj is the number of vertical line segments in the first vertical line segment set Lv1;

[0211] Step S2303: define a vertical line segment splicing mark set Fv containing m splicing mark variables. The jth variable fv in the vertical line segment splicing mark set Fv is j represents the splicing mark of the j-th vertical line segment in the first vertical line segment set, and the splicing mark fv of the j-th vertical line segment in the first vertical line segment set j The initial value is set to 0; the third variable u and the fourth variable s are set; the initial value of the third variable u is set to 0;

[0212] Step S2304, increase the value of the third variable u by 1, if u>nj-1, jump to step S2312;

[0213] Step S2305, if fv u =1, where fv u represents the splicing mark of the u-th vertical line segment in the first vertical line segment set, then jump to step S2304; otherwise, set the value of the fourth variable s to u;

[0214] Step S2306, increase the value of the fourth variable s by 1, if s>nj, jump to step S2304;

[0215] Step S2307, if fv j =1, where fv j represents the splicing mark of the j-th vertical line segment in the first vertical line segment set, then jumps to step S2306;

[0216] Step S2308, if y s down < y u up , where y s down represents the y - coordinate of the lower - endpoint of the s - th vertical line segment in the first set of vertical line segments Lv1, and y u up represents the y - coordinate of the upper - endpoint of the u - th vertical line segment in the first set of vertical line segments Lv1, then it is determined that the s - th vertical line segment lv in the first set of vertical line segments Lv1 s is above the u - th vertical line segment lv in the first set of vertical line segments Lv1 u ; if y u down < y s up , where y u down represents the y - coordinate of the lower - endpoint of the u - th vertical line segment in the first set of vertical line segments Lv1, and y s up represents the y - coordinate of the upper - endpoint of the s - th vertical line segment in the first set of vertical line segments Lv1, then it is determined that the u - th vertical line segment lv in the first set of vertical line segments Lv1 u is above the s - th vertical line segment lv in the first set of vertical line segments Lv1 s ;

[0217] Step S2309, if the u - th vertical line segment lv in the first set of vertical line segments Lv1 u is above the s - th vertical line segment lv in the first set of vertical line segments Lv1 s |x u down - x s up | < Td1, and |y u down - y s up | < Td1, then connect the upper - endpoint of the u - th vertical line segment lv in the first set of vertical line segments Lv1 u to the lower - endpoint of the s - th vertical line segment lv in the first set of vertical line segments Lv1 s to obtain the vertical splicing line segment lc u,s ; otherwise, if the s - th vertical line segment lv in the first set of vertical line segments Lv1 s is above the u - th vertical line segment lv in the first set of vertical line segments Lv1 u |x s down - x u up | < Td1 and |y sdown -y u up | If Td1, then connect the upper endpoint of the s-th vertical line segment lv in the first set of vertical line segments Lv1 to the lower endpoint of the u-th vertical line segment lv in the first set of vertical line segments Lv1 to obtain the vertical splicing line segment lc s ; Otherwise, jump to step S2306; u ; u,s ; Otherwise, jump to step S2306;

[0218] Step S2310, calculate the vertical distance dv from the upper endpoint of the u-th vertical line segment lv in the first set of vertical line segments Lv1 to the vertical splicing line segment lc u using formula (2), the vertical distance dv from the lower endpoint of the u-th vertical line segment lv in the first set of vertical line segments Lv1 to the vertical splicing line segment lc u,s , the vertical distance dv from the upper endpoint of the s-th vertical line segment lv in the first set of vertical line segments Lv1 to the vertical splicing line segment lc u,1 , and the vertical distance dv from the lower endpoint of the s-th vertical line segment lv in the first set of vertical line segments Lv1 to the vertical splicing line segment lc u ; u,s ; u,2 ; s ; u,s ; s,3 ; s ; u,s ; s,4 ;

[0219] Step S2311, if dv u,1 <Td2, dv u,2 <Td2, dv s,3 <Td2, dv s,4 <Td2, then set the splicing marks fv of the u-th vertical line segment and the s-th vertical line segment in a set of vertical line segments to 1, and add the vertical splicing line segment lc u to the second set of vertical line segments Lv2; jump to step S2304; s ; u,s ;

[0220] Step S2312, traverse each splicing mark in the set of vertical line segment splicing marks Fv. If the j-th variable fv in the set of vertical line segment splicing marks Fv j is 0, then add the j-th vertical line segment lv in the first set of vertical line segments Lv1 j to the second set of vertical line segments Lv2.

[0221] Further, in step S2, according to the second horizontal line segment set Lh2 and the second vertical line segment set Lv2, the first inclination angle Angle_s is obtained by using the inclination angle detection method based on straight line processing, and the specific steps are as follows:

[0222] Step S241, setting a third horizontal line segment set Lh3, traversing each vertical line segment in the second vertical line segment set Lv2, rotating each vertical line segment 90 degrees clockwise around the center point of the vertical line segment, and adding the vertical line segment to the third horizontal line segment set Lh3;

[0223] Step S242, merging the second horizontal line segment set Lh2 and the third horizontal line segment set Lh3 to generate a fourth horizontal line segment set Lh4;

[0224] Step S243, setting a fifth horizontal line segment set Lh5, setting a line segment length threshold Tc=50, and traversing all horizontal line segments in the fourth horizontal line segment set Lh4;

[0225] Step S2431, let la v represents the vth horizontal line segment currently traversed, v=1,2,…,nv, nv is the number of line segments in the fourth horizontal line segment set Lh4;

[0226] Step S2432, let x c left Indicates the vth horizontal line segment la currently traversed v The x coordinate of the left endpoint of c right Indicates the vth horizontal line segment la currently traversed v The x coordinate of the right endpoint of c left Indicates the vth horizontal line segment la currently traversed v The y coordinate of the left endpoint, let y c right Indicates the vth horizontal line segment la currently traversed v Calculate the y coordinate of the right endpoint of the currently traversed vth horizontal line segment la v The calculation formula of the line segment length len is shown in formula (3):

[0227] (3);

[0228] Step S2433, if len>Tc, then the currently traversed vth horizontal line segment la v Add the fifth horizontal line segment set Lh5;

[0229] Step S244, setting a first slope set K1, and traversing all horizontal line segments in the fifth horizontal line segment set Lh5;

[0230] Step S245, let lbe represents the e-th horizontal line segment currently traversed, e=1,2,…,ne, ne is the number of line segments in the fifth horizontal line segment set Lh5;

[0231] Step S2451, using formula (1) to calculate the e-th horizontal line segment lb currently traversed e The slope of the line segment kc e , the line segment slope kc e Add the first slope set K1;

[0232] Step S246, using the median absolute deviation method to remove outliers from the first slope set K1 to obtain a second slope set K2;

[0233] The median absolute deviation algorithm in the above steps is a common method for calculating outliers. For details, see Gong Xunqiang, Zhang Fangze, Lu Tieding, et al. Abnormal training sample detection method based on median absolute deviation[J]. Laser & Optoelectronics Progress, 2020, 57(23):6.DOI:10.3788 / LOP57.231202;

[0234] Step S247: according to each slope k in the second slope set K2 r , calculate the average slope ave_k of the second slope set K2, where r=1,2,…,nr, nr is the number of slopes in the second slope set K2, and the calculation formula of the average slope of the second slope set K2 is shown in formula (4):

[0235] (4);

[0236] Step S248, convert the average slope ave_k of the second slope set K2 into an angle to obtain a first inclination angle Angle_s. The angle conversion formula is shown in formula (5):

[0237] (5);

[0238] Here, arctan represents the inverse tangent function.

[0239] The beneficial effects of the present invention are as follows: the present invention provides a document image tilt correction method, the present invention effectively utilizes the text line features and straight line features in the tilted document image to ensure the accurate acquisition of the tilt angle, the present invention is suitable for tilt angle detection and rotation correction of tilted document images, and can achieve a high-precision tilt correction effect.

[0240] The above description is a preferred embodiment of the present invention and is not intended to limit the present invention. Any equivalent or modification that does not deviate from the spirit disclosed in the present invention should be included in the scope of protection of the present invention.

Claims

1. A document image tilt correction method, characterized in that: The following steps are involved: Step S1: Document image preprocessing: Read document image I, grayscale and binarize document image I to obtain a second image I g , for the second image I g Perform morphological processing to obtain the third image I p ; Step S2: Tilt angle detection: For the second image I g Perform straight line detection. If a straight line segment is detected, store the detected straight line segment in a straight line segment set L, divide the straight line segment set L into a first horizontal line segment set Lh1 and a first vertical line segment set Lv1, splice adjacent horizontal line segments in the first horizontal line segment set Lh1 to obtain a second horizontal line segment set Lh2, and splice adjacent vertical line segments in the first vertical line segment set Lv1 to obtain a second vertical line segment set Lv2; according to the second horizontal line segment set Lh2 and the second vertical line segment set Lv2, use the inclination angle detection method based on straight line processing to obtain the first inclination angle Angle_s, and assign the first inclination angle Angle_s to the correction inclination angle Angle; if no straight line segment is detected, first perform a third image I p A rough tilt angle is estimated to obtain a rough tilt angle Angle_r, and then a fine tilt angle detection method is used to obtain a second tilt angle Angle_e according to the rough tilt angle Angle_r, and the second tilt angle Angle_e is assigned to the correction tilt angle Angle; Step S3: Rotation correction: According to the correction angle Angle, the document image I is subjected to rotation correction to obtain the corrected document image I c ; In step S2, the straight line segment set L is divided into a first horizontal line segment set Lh1 and a first vertical line segment set Lv1. The specific steps are as follows: Step S211, traverse all straight line segments in the straight line set L, let l represent the straight line segment currently being judged, let y start and x start Respectively represent the y coordinate and x coordinate of the starting point of the line segment l currently being judged. Let y end and x end They respectively represent the y-coordinate and x-coordinate of the end point of the straight line segment l currently being judged; Step S212, if x end =x start , then the straight line segment l currently being judged is determined to be a vertical line segment, and the straight line segment l currently being judged is added to the first vertical line segment set Lv1; if y end =y start , then the straight line segment l currently being judged is determined to be a horizontal line segment, and the straight line segment l currently being judged is added to the first horizontal line segment set Lh1; Otherwise, the slope kl of the straight line segment l currently being judged is calculated using formula (1); kl = (y2-y1) / (x2-x1)(1); Where kl is the slope, let x1 represent the x-coordinate of the left endpoint of a line segment, let y1 represent the y-coordinate of the left endpoint of a line segment, let x2 represent the x-coordinate of the right endpoint of a line segment, and let y2 represent the y-coordinate of the right endpoint of a line segment; Step S213, if |kl|>1, it is determined that the straight line segment l currently being determined is a vertical line segment, and the straight line segment l currently being determined is added to the first vertical line segment set Lv1; otherwise, it is determined that the straight line segment l currently being determined is a horizontal line segment, and the straight line segment l currently being determined is added to the first horizontal line segment set Lh1; In step S2, according to the second horizontal line segment set Lh2 and the second vertical line segment set Lv2, the first inclination angle Angle_s is obtained by using the inclination angle detection method based on straight line processing. The specific steps are as follows: Step S241, setting a third horizontal line segment set Lh3, traversing each vertical line segment in the second vertical line segment set Lv2, rotating each vertical line segment 90 degrees clockwise around the center point of the vertical line segment, and adding the vertical line segment to the third horizontal line segment set Lh3; Step S242, merging the second horizontal line segment set Lh2 and the third horizontal line segment set Lh3 to generate a fourth horizontal line segment set Lh4; Step S243, setting a fifth horizontal line segment set Lh5, setting a line segment length threshold Tc, and traversing all horizontal line segments in the fourth horizontal line segment set Lh4; Step S2431, let la v represents the vth horizontal line segment currently traversed, v=1,2,…,nv, nv is the number of line segments in the fourth horizontal line segment set Lh4; Step S2432, let x c left Indicates the vth horizontal line segment la currently traversed v The x coordinate of the left endpoint of c right Indicates the vth horizontal line segment la currently traversed v The x coordinate of the right endpoint of c left Indicates the vth horizontal line segment la currently traversed v The y coordinate of the left endpoint, let y c right Indicates the vth horizontal line segment la currently traversed v Calculate the y coordinate of the right endpoint of the currently traversed vth horizontal line segment la v The calculation formula of the line segment length len is shown in formula (3): (3); Step S2433, if len>Tc, then the currently traversed vth horizontal line segment la v Add the fifth horizontal line segment set Lh5; Step S244, setting a first slope set K1, and traversing all horizontal line segments in the fifth horizontal line segment set Lh5; Step S245, let lb e represents the e-th horizontal line segment currently traversed, e=1,2,…,ne, ne is the number of line segments in the fifth horizontal line segment set Lh5; Formula (1) is used to calculate the e-th horizontal line segment lb currently traversed e The slope of the line segment kc e , the line segment slope kc e Add the first slope set K1; Step S246, using the median absolute deviation method to remove outliers from the first slope set K1 to obtain a second slope set K2; Step S247: according to each slope k in the second slope set K2 r , calculate the average slope ave_k of the second slope set K2, where r=1,2,…,nr, nr is the number of slopes in the second slope set K2, and the calculation formula of the average slope of the second slope set K2 is shown in formula (4): (4); Step S248, convert the average slope ave_k of the second slope set K2 into an angle to obtain a first inclination angle Angle_s. The angle conversion formula is shown in formula (5): (5); Among them, arctan represents the inverse tangent function; In step S2, the third image I p Perform a rough tilt angle estimation to obtain a rough tilt angle Angle_r. The specific steps are as follows: Step S251: for the third image I p Perform contour detection, and add the detected text line contour to the first text line contour set C1; Step S252, for each text line contour in the first text line contour set C1, a maximum circumscribed rectangle of the text line contour is calculated, and the text line contours in the first text line contour set C1 are sorted in descending order according to the width of the maximum circumscribed rectangle of the text line contour to obtain a sorted second text line contour set C2; Step S253, setting a first text line slope set KD1, and traversing all text line contours in the second text line contour set C2; Step S254, using the median absolute deviation method to remove outliers from the first text line slope set KD1, to obtain the second text line slope set KD2; Step S255: according to each slope k in the second text line slope set KD2 t , calculate the average slope ave_k of the second text line slope set KD2 D , where t=1,2,…, nt, nt is the number of slopes in the second text line slope set KD2, and the average slope calculation formula of the second text line slope set KD2 is shown in formula (6): (6); Step S256: The average slope ave_k of the second text line slope set KD2 is D Convert to angle to get the rough tilt angle Angle_r. The angle conversion formula is shown in formula (7): (7); In step S2, according to the rough tilt angle Angle_r, a fine tilt angle detection method is used to obtain a second tilt angle Angle_e, and the specific steps are as follows: Step S2601, set the first rank value set TR1, set the first angle set TA1, set the rotation angle threshold H, set the rotation step step; let angle represent the current rotation angle, initialize the current rotation angle angle to Angle_r-H; let angle_end represent the maximum rotation angle, initialize the maximum rotation angle angle_end to Angle_r+H; Step S2602: for the second image I g Rotate the current rotation angle angle around the origin to obtain the rotated image I r ; Step S2603, setting a redundant marker set DE, and traversing all rank values ​​in the first rank value set TR1; Step S2604, traverse all redundant tags in the redundant tag set DE; Step S2605, setting a second rank value set TR2, setting a second angle set TA2, setting a search flag Find, and initializing the value of the search flag Find to 0; Step S2606, obtaining the index number of the minimum rank value in the first rank value set TR1 by finding the minimum value point, and obtaining the minimum rank value index number set DI; Step S2607, if the minimum rank value index sequence number set DI is empty, the value of the search flag Find is set to 1, the minimum rank value Rtr1 in the first rank value set TR1 is obtained, and the process jumps to step S2611; Step S2608, setting the value of the search flag Find to 2, searching the first angle and the first rank value set TR1 in the first angle set TA1 according to the minimum rank value index number in the minimum rank value index number set DI, and generating the second angle set TA2 and the second rank value set TR2; Step S2609, obtaining the minimum rank value Rtr2 in the second rank value set TR2; Step S2610, according to the index number index1 of the minimum rank value Rtr2 in the second rank value set TR2, find the angle value Ar2 with the index number index1 in the second angle set TA2, and assign the angle value Ar2 to the second inclination angle Angle_e; Step S2611, if Find=1, then find the angle value Ar1 with the index number index2 in the first angle set TA1 according to the index number index2 of the minimum rank value Rtr1 in the first rank value set TR1, and assign the angle value Ar1 to the second inclination angle Angle_e; Step S253, setting the first text line slope set KD1, traversing all text line contours in the second text line contour set C2; specifically: Step S2531, let c g represents the g-th text line contour currently traversed, where g=1,2,...,ng, and ng is the total number of text line contours in the second text line contour set C2; Step S2532, let hc g and wc g Represent the text line contour c g The height and width of the maximum enclosing rectangle generate a rectangle with a height of hc g , width is wc g And the text line contour mask matrix Mc with all values ​​0 g , the text line contour mask matrix Mc g Perform masking, specifically: Step S25321, traverse the text line contour c g All the text line contour points in p c g,w Represents the text line contour c g The w-th text line contour point, w=1,2,...,nw, nw represents the text line contour c g The total number of text line contour points, let x c g,w Represents the text line contour point p c g,w The x coordinate of c g,w Represents the text line contour point p c g,w The y coordinate of Step S25322: transform the text line contour mask matrix Mc g The coordinates of the point (x c g,w, y c g,w ) is set to 1; Step S2533, set the first mask center point set Dm1, traverse the text line contour mask matrix Mc g All columns of Step S25331, let col z Represents the contour mask matrix Mc of the currently traversed text line g Columns, where z=1,2,...,nz, nz is the text line contour mask matrix Mc g The total number of columns; Step S25332, obtain the contour mask matrix Mc of the text line currently traversed g col z The y coordinate of the first pixel whose value is 1 z start , get the contour mask matrix Mc of the currently traversed text line g col z The y coordinate of the last pixel whose value is 1 z end , calculate the contour mask matrix Mc of the currently traversed text line g col z The y coordinate of the center point y z , the calculation formula is shown in formula (8): and z =(and z start +y z end ) / 2(8); Step S25333: transform the contour mask matrix Mc of the currently traversed text line into g col z The center point (z,y z ) add the first mask center point set Dm1; Step S2534, using the median absolute deviation method to remove outliers from the first mask center point set Dm1 to obtain the second mask center point set Dm2; Step S2535, set the first mask parameter a, set the second mask parameter b, and set N m represents the total number of mask center points in the second mask center point set Dm2. From the second mask center point set Dm2, select the ⌈Nth m ×a⌉ mask center point as the first mask center point, select the ⌊Nth m ×b⌋ mask center points are used as the second mask center points, where ⌈⌉ is the rounding symbol and ⌊⌋ is the rounding symbol; connect the first mask center point and the second mask center point into a straight line segment to obtain the text line contour mask matrix Mc g Center line lm g ; Step S2536, using formula (1) to calculate the text line contour mask matrix Mc g Center line lm g The slope kc g , the slope kc g Add the first text line slope set KD1; Step S2602: for the second image I g Rotate the current rotation angle angle around the origin to obtain the rotated image I r ; Specifically: Step S26021, the rotated image I r Convert to the rotation image matrix M r , the singular value decomposition method is used to rotate the image matrix M r Process and obtain the rotation image rank value R r ; Step S26022, add the current rotation angle angle to the first angle set TA1, and set the rotation image rank value R r Add the first rank value set TR1; Step S26023, increase the value of the current rotation angle angle by step, if angle≤angle_end, jump to step S2602; Step S2603, set a redundant marker set DE, and traverse all rank values ​​in the first rank value set TR1; specifically: Step S26031, let r m Represents the mth rank value currently traversed, let r m+1 Indicates the m+1th rank value currently traversed, let a m represents the mth angle value in the first angle set TA1, let a m+1 represents the m+1th angle value in the first angle set TA1, where m=1, 2, ..., nm-1, and nm is the total number of rank values ​​in the first rank value set TR1; Step S26032, if r m =r m+1 , then the mth angle value a in the first angle set TA1 m The value is set to (a m +a m+1 ) / 2, add m+1 to the redundant marker set DE; Step S2604, traverse all redundant tags in the redundant tag set DE; specifically: Step S26041, let de s represents the sth redundant marker currently traversed, where s=1,2,...,ns, and ns is the total number of redundant markers in the redundant marker set DE; Step S26042: Delete the first angle set TA1 with index number de s content; Step S26043: Delete the index number de in the first rank value set TR1. s content; Step S2608, set the value of the search flag Find to 2, search the first angle and the first rank value set TR1 in the first angle set TA1 according to the minimum rank value index number in the minimum rank value index number set DI, and generate the second angle set TA2 and the second rank value set TR2. The specific steps are as follows: Step S26081, traverse the index numbers of all the minimum rank values ​​in the minimum rank value index number set DI, let d q represents the index number of the qth minimum rank value in the minimum rank value index number set DI, q=1, 2, ..., nq, and nq represents the total number of index numbers of the minimum rank values ​​in the minimum rank value index number set DI; Step S26082: set the index number d in the first angle set TA1 q The content is added to the second angle set TA2; Step S26083: set the index number d in the first rank value set TR1 q The content of is added to the second rank value set TR2.

2. A document image tilt correction method according to claim 1, characterized in that: In step S2, adjacent horizontal line segments in the first horizontal line segment set Lh1 are spliced ​​to obtain a second horizontal line segment set Lh2. The specific steps are as follows: Step S2201, sorting all horizontal line segments in the first horizontal line segment set Lh1 in ascending order according to the y coordinates of the left endpoints of the horizontal line segments; Step S2202, set the first distance threshold Td1, set the second distance threshold Td2, let lh i represents the i-th horizontal line segment of the first horizontal line segment set Lh1, i=1,2,…,ni, ni is the number of horizontal line segments in the first horizontal line segment set Lh1; Step S2203, define a horizontal line segment splicing mark set Fh containing n splicing mark variables, the i-th variable fh in the horizontal line segment splicing mark set Fh i represents the splicing mark of the i-th horizontal line segment in the first horizontal line segment set, and the splicing mark fh of the i-th horizontal line segment in the first horizontal line segment set i The initial value is set to 0; the first variable k and the second variable j are set; the initial value of the first variable k is set to 0; Step S2204: increase the value of the first variable k by 1. If k>ni-1, jump to step S2212; Step S2205, if fh k =1, where fh k represents the splicing mark of the kth horizontal line segment in the first horizontal line segment set, jump to step S2204, otherwise, set the value of the second variable j to the first variable k; Step S2206, increase the value of the second variable j by 1, if j>n, jump to step S2204; Step S2207, if fh j =1, where fh j represents the splicing mark of the j-th horizontal line segment in the first horizontal line segment set, then jumps to step S2206; Step S2208, if x k right <x j left , where x k right represents the x coordinate of the right endpoint of the kth horizontal line segment of the first horizontal line segment set Lh1, x j left represents the x coordinate of the left endpoint of the jth horizontal line segment of the first horizontal line segment set Lh1, then the kth horizontal line segment lh of the first horizontal line segment set Lh1 is determined. k The jth horizontal line segment lh in the first horizontal line segment set j Left side; if x j right <x k left , where x j right represents the x coordinate of the right endpoint of the jth horizontal line segment of the first horizontal line segment set Lh1, x k left represents the x coordinate of the left endpoint of the kth horizontal line segment of the first horizontal line segment set Lh1, then the jth horizontal line segment lh in the first horizontal line segment set is determined j The kth horizontal line segment lh located in the first horizontal line segment set Lh1 k left; Step S2209, if the k-th horizontal line segment lh of the first set of horizontal line segments Lh1 k is located to the left of the j-th horizontal line segment lh in the first set of horizontal line segments j and |x k right -x j left | < Td1, and |y k right -y j left | < Td1, then connect the left endpoint of the k-th horizontal line segment lh of the first set of horizontal line segments Lh1 k to the right endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments j to obtain a horizontal splicing line segment lc k,j ; otherwise, if the j-th horizontal line segment lh in the first set of horizontal line segments j is located to the left of the k-th horizontal line segment lh of the first set of horizontal line segments Lh1 k and |x j right -x k left | < Td1, and |y j right -y k left | < Td1, then connect the left endpoint of the j-th horizontal line segment lh in the first set of horizontal line segments j to the right endpoint of the k-th horizontal line segment lh of the first set of horizontal line segments Lh1 k to obtain a horizontal splicing line segment lc k,j ; otherwise, jump to step S2206; Step S2210, when the kth horizontal line segment lh of the first horizontal line segment set Lh1 k The jth horizontal line segment lh in the first horizontal line segment set j On the left, calculate the kth horizontal line segment lh of the first horizontal line segment set Lh1 k The right end point to the horizontal connection segment lc k,j The vertical distance dh k,2 and the jth horizontal line segment lh in the first horizontal line segment set j The left end point to the horizontal connection segment lc k,j The vertical distance dh j,3 , when the jth horizontal line segment lh in the first horizontal line segment set j The kth horizontal line segment lh located in the first horizontal line segment set Lh1 k On the left, calculate the kth horizontal line segment lh of the first horizontal line segment set Lh1 k The left end point to the horizontal connection segment lc k,j The vertical distance dh k,1 and the jth horizontal line segment lh in the first horizontal line segment set j The right end point to the horizontal connection segment lc k,j The vertical distance dh j,4 ; The specific method to calculate the vertical distance d1 from a point po to a line segment is: Let x0 represent the x coordinate of point po, and let y0 represent the y coordinate of point po; use formula (2) to calculate the vertical distance d1 from point po to the line segment: (2); Step S2211, if dh k,1 <Td2 and dh j,4 <Td2, or dh k,2 <Td2 and dh j,3 <Td2, then set the splicing flag fh k of the k-th horizontal line segment in the first set of horizontal line segments and the splicing flag fh j of the j-th horizontal line segment in the first set of horizontal line segments to 1, and add the horizontal splicing line segment lc k,j to the second set of horizontal line segments Lh2; jump to step S2204; Step S2212, traverse each splicing mark in the horizontal line segment splicing mark set Fh, if the i-th variable fh in the horizontal line segment splicing mark set Fh i is 0, then the i-th horizontal line segment lh in the first horizontal line segment set Lh1 i Add the second horizontal line segment set Lh2.

3. A document image tilt correction method according to claim 2, characterized in that: In step S2, adjacent vertical line segments in the first vertical line segment set Lv1 are concatenated to obtain a second vertical line segment set Lv2. The specific steps are as follows: Step S2301, sorting each vertical line segment in the first vertical line segment set Lv1 in ascending order according to the x coordinate of the upper endpoint of the vertical line segment; Step S2302, let lv j represents the j-th vertical line segment of the first vertical line segment set Lv1, j=1,2,…,nj, where nj is the number of vertical line segments in the first vertical line segment set Lv1; Step S2303: define a vertical line segment splicing mark set Fv containing m splicing mark variables. The jth variable fv in the vertical line segment splicing mark set Fv is j represents the splicing mark of the j-th vertical line segment in the first vertical line segment set, and the splicing mark fv of the j-th vertical line segment in the first vertical line segment set j The initial value is set to 0; Set the third variable u and the fourth variable s; the initial value of the third variable u is set to 0; Step S2304, increase the value of the third variable u by 1, if u>nj-1, jump to step S2312; Step S2305, if fv u =1, where fv u represents the splicing mark of the u-th vertical line segment in the first vertical line segment set, then jump to step S2304; otherwise, set the value of the fourth variable s to u; Step S2306, increase the value of the fourth variable s by 1, if s>nj, jump to step S2304; Step S2307, if fv j =1, where fv j represents the splicing mark of the j-th vertical line segment in the first vertical line segment set, then jumps to step S2306; Step S2308, if y s down <y u up , where y s down represents the y coordinate of the lower endpoint of the sth vertical line segment in the first vertical line segment set Lv1, y u up represents the y coordinate of the upper endpoint of the uth vertical line segment in the first vertical line segment set Lv1, then the sth vertical line segment lv in the first vertical line segment set Lv1 is determined. s The uth vertical line segment lv in the first vertical line segment set Lv1 u Above; if y u down <y s up , where y u down represents the y coordinate of the lower endpoint of the uth vertical line segment in the first vertical line segment set Lv1, y s up represents the y coordinate of the upper endpoint of the sth vertical line segment in the first vertical line segment set Lv1, then the uth vertical line segment lv in the first vertical line segment set Lv1 is determined. u The sth vertical line segment lv in the first vertical line segment set Lv1 s above; Step S2309, if the $u$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$ u is above the $s$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$, $|x$ s u down $-x$ s up $| \lt Td1$, and $|y$ u down $-y$ s up $| \lt Td1$, then connect the upper endpoint of the $u$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$ u to the lower endpoint of the $s$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$ s to obtain the vertical splicing line segment $lc$ u,s ; otherwise, if the $s$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$ s is above the $u$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$, $|x$ u s down $-x$ u up $| \lt Td1$ and $|y$ s down $-y$ u up $| \lt Td1$, then connect the upper endpoint of the $s$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$ s to the lower endpoint of the $u$-th vertical line segment $lv$ in the first set of vertical line segments $Lv1$ u to obtain the vertical splicing line segment $lc$ u,s ; otherwise, jump to step S2306;​​ Step S2310, using formula (2) to calculate the uth vertical line segment lv in the first vertical line segment set Lv1 u From the upper end point to the vertical splicing line segment lc u,s The vertical distance dv u,1 , the uth vertical line segment lv in the first vertical line segment set Lv1 u From the lower end point to the vertical splicing line segment lc u,s The vertical distance dv u,2 , the sth vertical line segment lv in the first vertical line segment set Lv1 s From the upper end point to the vertical splicing line segment lc u,s The vertical distance dv s,3 and the sth vertical line segment lv in the first vertical line segment set Lv1 s From the lower end point to the vertical splicing line segment lc u,s The vertical distance dv s,4 ; Step S2311, if dv u,1 <Td2, dv u,2 <Td2, dv s,3 <Td2, dv s,4 <Td2, then set the splicing flag fv of the u-th vertical line segment in a set of vertical line segments u and the splicing flag fv of the s-th vertical line segment in a set of vertical line segments s to 1, and add the vertical splicing line segment lc u,s to the second set of vertical line segments Lv2; jump to step S2304; Step S2312, traverse each splicing mark in the vertical line segment splicing mark set Fv, if the j-th variable fv in the vertical line segment splicing mark set Fv j is 0, then the jth vertical line segment lv in the first vertical line segment set Lv1 j Add the second vertical line segment set Lv2.

Citation Information

Patent Citations

  • A method for tilt correction of complex archival images based on convolutional neural networks

    CN110211048B

  • Document image tilt correction method and device based on projection variance minimization

    CN114202650A

  • Scanning document image tilt correction method based on segmented projection

    CN115601757A

  • Self-adaptive scanning document image inclination angle detection method

    CN115619845A