A method, system, apparatus and storage medium for scanning document correction
By using LSD algorithm detection and affine transformation correction technology, the problems of tilt and missing boundaries in document images scanned by flatbed scanners are solved, achieving high-quality document image correction that is applicable to various complex boundary and corner missing situations.
Patent Information
- Application Number
- CN202310239525.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-13
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2043-03-13
AI Technical Summary
In existing technologies, document images scanned using flatbed scanners are prone to problems such as tilting, background interference, and missing boundaries, which affect subsequent automated processing, and there is a lack of effective solutions.
The LSD algorithm is used to detect boundary line segments in document images, identify line segment types, select feature line segments for affine transformation correction, handle various boundary and corner missing cases, and use the affine transformation matrix for image correction.
It effectively corrects document images, adapts to various boundary and corner missing situations, avoids introducing additional deformation, and improves image quality.
Smart Images

Figure CN116453128B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of document image processing, and particularly relates to a scanned document correction method, system and device and a storage medium. BACKGROUND
[0002] Scanning by using a flatbed scanner is a common method for digitizing paper documents. Compared with taking pictures by using a mobile camera, the digitized document obtained by using a flatbed scanner usually has high quality and can eliminate the interference of shadows and paper deformation to the greatest extent. However, the document image obtained by using this method still has problems of inclination and background interference, which adversely affect the subsequent automatic processing program of the document. In actual application scenarios, the content of a document is usually complex and diverse: some contain text and images, some contain only text or only images, and some contain horizontal text and some contain vertical text. The boundary of a document is complex: there may be missing corner points (folding at the corner point, and the corner point is outside the imaging range of the scanner), missing or incomplete boundaries (the boundary is incomplete because the boundary is partially outside the imaging range, and the boundary is missing because the boundary is completely outside the imaging range). This makes it very challenging to solve this kind of problem. At present, there is still a lack of solutions to this kind of problem. SUMMARY
[0003] To at least partially solve one of the technical problems existing in the prior art, the purpose of the present application is to provide a scanned document correction method, system, device and storage medium.
[0004] The technical solution adopted by the present application is as follows:
[0005] A scanned document correction method comprises the following steps:
[0006] Obtaining a document image, performing segmentation processing on the document image, and obtaining a segmentation mask image;
[0007] Performing boundary line segment detection on the segmentation mask image to obtain a plurality of boundary line segments;
[0008] Identifying the boundary line segments to obtain the types of the boundary line segments;
[0009] Selecting a feature line segment for each of the four boundaries of the document according to the identified boundary line segments;
[0010] Performing affine transformation correction according to the feature line segments to obtain a corrected document image.
[0011] Further, the boundary line segment detection on the segmentation mask image to obtain a plurality of boundary line segments comprises:
[0012] The line segments at the document boundary of the segmentation mask image are detected by using the LSD algorithm to obtain a plurality of boundary line segments;
[0013] The detected line segments do not include line segments on the intersection line of the document and the imaging boundary; the detection result includes that all boundaries have line segments, one boundary has no line segment, or two boundaries have no line segment.
[0014] Further, the boundary line segments are identified to obtain the type of the boundary line segments, including:
[0015] The boundary line segments are divided into horizontal line segments and vertical line segments according to the inclination angle of the boundary line segments;
[0016] The midpoint coordinate values of the vertical line segments are compared with the midpoint coordinate values of the segmentation mask image, and the vertical line segments are determined as left boundary line segments and right boundary line segments according to the comparison result;
[0017] The midpoint coordinate values of the horizontal line segments are compared with the midpoint coordinate values of the segmentation mask image, and the horizontal line segments are determined as upper boundary line segments and lower boundary line segments according to the comparison result.
[0018] Further, the feature line segment is selected for each of the four boundaries of the document according to the identified boundary line segments, including:
[0019] For the same type of boundary line segment, the average length of the line segment is calculated according to all boundary line segments of the type, and the boundary line segment of the type is removed according to the average length;
[0020] Two different types of boundary line segments are obtained respectively, the included angle between the two types of boundary line segments is calculated, and the corresponding boundary line segment is obtained as the feature line segment according to the included angle.
[0021] Further, if there is a boundary without a feature line segment, the scanning document correction method further includes a step of supplementing a feature line segment, and the step of supplementing a feature line segment includes:
[0022] Let boundary A be a boundary without a feature line segment, if the opposite boundary C of boundary A has a feature line segment: the feature line segment on boundary C is translated to be tangent to the document foreground region, and the translated line segment is used as the feature line segment of boundary A;
[0023] If the opposite boundary C of A has no feature line segment, let any adjacent boundary of boundary A be B, draw a perpendicular line of the feature line segment of boundary B and translate it to be tangent to the document foreground region to obtain two straight lines, and one of the two straight lines is determined as the feature line of boundary A according to the position of boundary A.
[0024] Further, the feature line segment is subjected to affine transformation to obtain a corrected document image, including:
[0025] The four corner points obtained by intersecting the straight lines on which the four characteristic line segments are located are mapped to a rectangle:
[0026] An affine transformation matrix is solved according to the mapping relationship, and the document image is subjected to affine transformation by using the affine transformation matrix, so that a document image after correction and removal of a scanning background is obtained.
[0027] Further, the affine transformation matrix is obtained by the following method:
[0028] Three of the four corner points are selected at random, and the coordinates of the three corner points are denoted as (a1, b1), (a2, b2), (a3, b3), and the coordinates of the points on the rectangle corresponding to the corner points are denoted as (a'1, b'1), (a'2, b'2), (a'3, b'3).
[0029] The affine transformation matrix is:
[0030]
[0031] Let The affine transformation matrix T is obtained by solving the following function:
[0032] min||TA-B|| 2
[0033] Another technical solution adopted by the present application is:
[0034] A scanning document correction system comprises:
[0035] An image segmentation module is configured to acquire a document image, perform segmentation processing on the document image, and obtain a segmentation mask image.
[0036] A line segment detection module is configured to perform boundary line segment detection on the segmentation mask image, and obtain a plurality of boundary line segments.
[0037] A line segment identification module is configured to identify the boundary line segments to obtain the types of the boundary line segments.
[0038] A line segment selection module is configured to select one characteristic line segment for each of the four boundaries of a document according to the identified boundary line segments.
[0039] A feature mapping module is configured to perform affine transformation correction according to the characteristic line segments, and obtain a corrected document image.
[0040] Another technical solution adopted by the present application is:
[0041] A scanning document correction device comprises:
[0042] At least one processor;
[0043] at least one memory for storing at least one program;
[0044] When the at least one program is executed by the at least one processor, the at least one processor implements the above method.
[0045] Another technical solution adopted by the present application is:
[0046] A computer readable storage medium, wherein a processor executable program is stored, the processor executable program is used for executing the above method when executed by a processor.
[0047] The present application has the beneficial effects that: the present application can process various boundaries and missing corner points, and can also process documents with folds at corner points, and has good applicability; in addition, the present application only uses affine transformation for correction, and does not introduce additional deformation. BRIEF DESCRIPTION OF DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following introduces the drawings of the related technical solutions in the embodiments of the present application or the prior art. It should be understood that the drawings in the following introduction are only for the convenience of clearly describing part of the embodiments in the technical solutions of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the premise of the drawings.
[0049] Figure 1 is a step flow chart of a scanning document correction method in an embodiment of the present application;
[0050] Figure 2 is a visualization diagram of part of scanning document samples and output results of each step in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the drawings, wherein the same or similar reference signs represent the same or similar elements or elements with the same or similar functions throughout. The embodiments described below by referring to the drawings are exemplary and are only used to explain the present application, and cannot be understood as a limitation of the present application. For the step numbers in the following embodiments, they are only set for the convenience of explanation and description, and the order between the steps is not limited in any way, and the execution order of each step in the embodiments can be adaptively adjusted according to the understanding of those skilled in the art.
[0052] In the description of the present application, it needs to be understood that the orientation description, such as the orientation or position relationship indicated by the upper, lower, front, rear, left, right and the like, is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present application and simplifying the description, and does not indicate or imply that the device or element indicated must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation on the present application.
[0053] In the description of the present application, one or more is understood as one or more, more than two, greater than, less than, more than and the like are understood as not including the number, above, below, within and the like are understood as including the number. If the first, second is described, it is only for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated or the order of technical features indicated.
[0054] In the description of the present application, unless otherwise explicitly limited, the words such as setting, installing, connecting and the like should be broadly understood, and those skilled in the art can reasonably determine the specific meaning of the above words in the present application in combination with the specific content of the technical scheme.
[0055] As shown in Figure 1 , the embodiment provides a scanning document correction method, comprising the following steps:
[0056] Step S1: foreground segmentation. The foreground area occupied by the document is segmented from the scanning background to obtain a segmentation mask image.
[0057] As an optional implementation, the foreground segmentation adopts a threshold-based method: the scanning background is usually dark, and the document foreground is usually light, so the embodiment separates the document foreground by predefining a threshold. However, due to the influence of dark document content, only the threshold method will cause the document content area to be classified as the scanning background, so after threshold segmentation, a morphological closing operation is used to eliminate the influence of the document content, and finally a complete document foreground segmentation mask image is obtained.
[0058] Step S2: boundary line segment detection.
[0059] The line segments at the document boundary are detected on the segmentation mask image obtained in the step S1, and the line segments do not include the line segments on the intersection line of the document and the imaging boundary.
[0060] As an optional implementation, on the basis of step S1, the line segment detection is performed by using the LSD algorithm, and N line segments [L1, L2,..., LN] (N≥2) are detected. N ](N≥2), L n =[x 1 n ,y 1n ,x 2 n ,y 2 n ,width n ,angle n ,length n ]. (x 1 n ,y 1 n ),(x 2 n ,y 2 n ),width n ,angle n ,length n These represent the coordinates of endpoint 1, endpoint 2, line segment confidence, line segment inclination angle, and line segment length returned by the LSD algorithm for each line segment.
[0061] Step S3: Classify boundary segments.
[0062] First, line segments are divided into horizontal and vertical segments based on their inclination angle: segments with inclination angles between [-45°+k180°, 45°+k180°], k∈Z, are classified as horizontal segments, while those outside this range are classified as vertical segments. Next, based on the comparison between the midpoint coordinates of the line segment and the midpoint coordinates of the image, vertical segments are classified into left and right boundary segments, and horizontal segments are classified into upper and lower boundary segments: for vertical segments, those whose midpoint x-coordinate is to the left of the midpoint x-coordinate are classified as left boundary segments, and those to the right are classified as right boundary segments; for horizontal segments, those whose midpoint y-coordinate is above the midpoint y-coordinate are classified as upper boundary segments, and those below are classified as lower boundary segments. The classification results may be: all boundaries have segments, one boundary has no segments, or two boundaries have no segments. The cases of three boundaries having no segments or all boundaries having no segments are not considered.
[0063] Specifically, first, based on the tilt angle... n Divide all line segments into vertical and horizontal segments. Line segments within the range [-45°+k180°, 45°+k180°], where k ∈ Z, are classified as horizontal segments; otherwise, they are classified as vertical segments. Then, based on the coordinates of the midpoints of the line segments... Coordinates of the midpoint of the image Compare, where W and H are the width and height of the image, respectively. For horizontal line segments, if If it is classified as a lower boundary line segment, then it is classified as an upper boundary line segment; for vertical line segments, if If it is, it is classified as a right boundary segment; otherwise, it is a left boundary segment. Ultimately, we can obtain the segment for each of the four boundaries: Upper boundary: [L] 1上 ,L2上 ..., L N上 ], lower boundary: [L 1下 , L 2下 ..., L N下 ], left boundary: [L 1左 , L 2左 ..., L N左 ], right boundary: [L 1右 , L 2右 ..., L N右 ] N 上 , N 下 , N 左 , N 右 ≥ 0.
[0064] Step S4: boundary feature line segment extraction.
[0065] Step S4 selects one feature line segment for each of the four boundaries of the document, to represent the corresponding boundary, and removes the remaining line segments.
[0066] As an optional implementation, step S4 specifically includes steps S41-S42:
[0067] S41, respectively calculate the average length of the line segments contained in each boundary with line segments, and remove the line segments in each boundary with a length less than the average length of the boundary.
[0068] Calculate the average length of all line segments (take the upper boundary as an example): Remove all line segments in the boundary line segment with a length less than the average line segment length.
[0069] S42, based on the remaining line segments: for the boundary A with line segments, if the parallel boundary C of A exists line segments, calculate the included angle of all line segments on A and all line segments on C, and the line segment of A with the smallest included angle is the feature line segment of A; if the parallel boundary C of A does not exist line segments, calculate the included angle of all line segments on A and all line segments on the vertical boundary of A, and the line segment of A with the included angle closest to 90° is the feature line segment of A.
[0070] In the remaining line segments, for any boundary with a line segment number not equal to zero (take the upper boundary as an example), if the lower boundary exists line segments, calculate the included angle of all line segments on the upper boundary and all line segments on the lower boundary, and the line segment of the upper boundary with the smallest included angle is the feature line segment of the upper boundary; if the lower boundary does not exist line segments, calculate the included angle of all line segments on the upper boundary and all line segments on the left boundary and the right boundary, and the line segment of the upper boundary with the included angle closest to 90° is the feature line segment of the upper boundary. The feature line segments of other boundaries can be obtained in the same way.
[0071] Step S5: missing boundary filling and corner point acquisition.
[0072] Step S5: extending all the characteristic line segments obtained in step S4 to get characteristic straight lines, if there are straight lines in all 4 boundaries, then directly jump to step S6, without executing step S5.
[0073] wherein, step S5 specifically comprises: recording boundary A as a boundary without characteristic straight line, if parallel boundary C of A has characteristic straight line: translating the characteristic straight line on C to the tangent position with the document foreground region, and the translated straight line is taken as the characteristic straight line of A. If parallel boundary C of A has no characteristic straight line: recording any vertical boundary of A as B, drawing the perpendicular line of the characteristic straight line of B and translating it to the tangent position with the document foreground, finally obtaining two straight lines, and determining one of the two straight lines as the characteristic straight line of A according to the position of A, such as: if A is the upper boundary, the straight line located in the upper position of the two straight lines is taken as the characteristic straight line of A; if A is the lower boundary, the straight line located in the lower position of the two straight lines is taken as the characteristic straight line of A; if A is the left boundary, the straight line located in the left position of the two straight lines is taken as the characteristic straight line of A; if A is the right boundary, the straight line located in the right position of the two straight lines is taken as the characteristic straight line of A.
[0074] Specifically, for the boundary without characteristic straight line (taking the upper boundary as an example): if the lower boundary has characteristic straight line, the characteristic straight line of the lower boundary is translated to the tangent position with the document foreground region, and the translated straight line is taken as the characteristic straight line of the upper boundary; if the lower boundary has no characteristic straight line, the perpendicular line of the characteristic straight line of the left boundary or the right boundary is drawn and translated to the tangent position with the document foreground mask, two straight lines can be obtained, and then the straight line with the upper relative position is selected as the characteristic straight line of the upper boundary. The other direction boundaries can be obtained in the same way.
[0075] Step S6: affine transformation correction.
[0076] Step S6: mapping the four corner points obtained by intersecting the four characteristic straight lines in step S4 or S5 to a rectangle: such as mapping the document left upper corner point to the rectangle left upper corner point, mapping the document right upper corner point to the rectangle right upper corner point, such as mapping the document left lower corner point to the rectangle left lower corner point, and mapping the document right lower corner point to the rectangle right lower corner point. The affine transformation matrix is solved according to the mapping relationship, and the affine transformation matrix is used to perform affine transformation on the scanned document image to obtain the document image after the scanned background is corrected and removed.
[0077] Specifically, three of the four corner points are selected at random, and the coordinates of the three corner points are recorded as: (a1, b1), (a2, b2), (a3, b3), the coordinates of the corresponding points on the rectangle are recorded as: (a'1, b'1), (a'2, b'2), (a'3, b'3), and the affine transformation matrix to be solved is denoted as:
[0078]
[0079] Let T is obtained by optimizing the following function:
[0080] min||TA-B|| 2
[0081] Based on the solved T, the scanned document image can be subjected to affine transformation to obtain a corrected image.
[0082] As can be seen from the above, the method of the present application can process various boundaries and missing corner points, including: all four corner points of the document in the imaging range exist, only three corner points of the document in the imaging range exist, only two corner points of the document in the imaging range exist, only one corner point of the document in the imaging range exists, and no corner point of the document in the imaging range exists. The present application can also process the document with folding at the corner points. The present application is aimed at the problem of only containing rotation, scaling and translation of the scanned document, and only uses affine transformation for correction, without introducing additional deformation.
[0083] The embodiment also provides a scanning document correction system, comprising:
[0084] An image segmentation module is configured to acquire a document image, perform segmentation processing on the document image, and obtain a segmentation mask image.
[0085] A line segment detection module is configured to perform boundary line segment detection on the segmentation mask image, and obtain a plurality of boundary line segments.
[0086] A line segment identification module is configured to identify the boundary line segments to obtain the types of the boundary line segments.
[0087] A line segment selection module is configured to select a feature line segment for each of the four boundaries of the document according to the identified boundary line segments.
[0088] A feature mapping module is configured to perform affine transformation correction according to the feature line segments, and obtain a corrected document image.
[0089] The scanning document correction system of the embodiment can execute the scanning document correction method provided by the method embodiment of the present application, can execute the implementation steps of any combination of the method embodiment, and has the corresponding functions and beneficial effects of the method.
[0090] The embodiment also provides a scanning document correction device, comprising:
[0091] At least one processor;
[0092] At least one memory configured to store at least one program;
[0093] When the at least one program is executed by the at least one processor, the at least one processor implements the method. Figure 1 The method.
[0094] The scanning document correction device of the embodiment can execute the scanning document correction method provided by the method embodiment of the application, can execute the implementation steps of any combination of the method embodiment, and has the corresponding functions and beneficial effects of the method.
[0095] The embodiment of the application further discloses a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device can read the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method shown in the embodiment. Figure 1
[0096] The embodiment further provides a storage medium storing instructions or programs that can execute the scanning document correction method provided by the method embodiment of the application. When the instructions or programs are executed, the implementation steps of any combination of the method embodiment can be executed, and the corresponding functions and beneficial effects of the method are possessed.
[0097] In some alternative embodiments, the functions / operations mentioned in the block diagram can not occur in the order mentioned in the operation diagram. For example, depending on the functions / operations involved, two blocks shown in succession can actually be executed substantially simultaneously or the blocks can sometimes be executed in reverse order. In addition, the embodiments presented and described in the flowcharts of the application are provided by way of example, with the purpose of providing a more comprehensive understanding of the technology. The disclosed method is not limited to the operations and logical flows presented herein. Alternative embodiments are contemplated in which the order of various operations is changed and in which sub-operations described as part of larger operations are independently executed.
[0098] In addition, although the application is described in the context of functional modules, it should be understood that, unless otherwise stated to the contrary, one or more of the described functions and / or features can be integrated in a single physical device and / or software module, or one or more functions and / or features can be implemented in separate physical devices or software modules. It can also be understood that a detailed discussion of the actual implementation of each module is unnecessary for an understanding of the application. Rather, given the properties, functions and internal relationships of the various functional modules in the devices disclosed herein, the actual implementation of the module will be within the routine skill of the engineer, given the present disclosure. Thus, a person skilled in the art can implement the application set forth in the claims without undue experimentation using ordinary skill. It can also be understood that the disclosed specific concepts are merely illustrative and are not intended to limit the scope of the application, which is determined by the full scope of the appended claims and their equivalents.
[0099] If the functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the technical solutions that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0100] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a list of executable instructions for implementing logic functions, which can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus or device, such as a computer-based system, a system including a processor or other system that can fetch the instructions from the instruction execution system, apparatus or device and execute the instructions, or in conjunction with these instructions execution systems, apparatus or devices. For the purpose of this specification, the "computer-readable medium" can be any device that can contain, store, communicate, propagate or transport programs for use by or in connection with an instruction execution system, apparatus or device, or in conjunction with these instruction execution systems, apparatus or devices.
[0101] More specific examples (non-exhaustive list) of the computer-readable medium include the following: an electrical connection having one or more wires (electrical devices), a portable computer diskette (magnetic devices), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). In addition, the computer-readable medium can even be paper or other suitable medium on which the program can be printed, because the program can be electronically obtained, for example, by optical scanning of the paper or other medium, followed by editing, interpreting or otherwise processing, if necessary, in other suitable ways, to be electronically obtained and then stored in the computer memory.
[0102] It should be understood that various parts of the present application can be implemented in hardware, software, firmware or a combination thereof. In the above embodiments, various steps or methods can be implemented in software or firmware that is stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any of the following technologies, known in the art, or their equivalents, can be employed for implementation: discrete logic circuitry having logic gates for implementing logic functions upon data signals, application specific integrated circuits having appropriate combinational logic gates, programmable gate arrays (PGA), field programmable gate arrays (FPGA), and the like.
[0103] In the above description of the present specification, the description of the terms "one embodiment / one example", "another embodiment / another example", or "certain embodiments / certain examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiments or examples are included in at least one embodiment or example of the present application. In the present specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Also, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0104] Although the embodiments of the present application have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and variations can be made thereto without departing from the principles and spirit of the present application, the scope of which is defined by the claims and their equivalents.
[0105] The above is a specific description of the preferred embodiments of the present application, but the present application is not limited to the above-described embodiments, and those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present application, and these equivalent modifications or substitutions are included in the scope defined by the claims of the present application.
Claims
1. A method of correcting a scanned document, characterized by, The method comprises the following steps: Obtaining a document image, performing segmentation processing on the document image, and obtaining a segmentation mask image; Performing boundary line segment detection on the segmentation mask image to obtain a plurality of boundary line segments; Identifying the boundary line segments to obtain the types of the boundary line segments; Selecting one characteristic line segment for each of the four boundaries of the document according to the identified boundary line segments; Performing affine transformation correction according to the characteristic line segments to obtain a corrected document image; The boundary line segment detection on the segmentation mask image to obtain a plurality of boundary line segments comprises: Detecting the line segments at the document boundaries of the segmentation mask image by using an LSD algorithm to obtain a plurality of boundary line segments; The detected line segments do not include line segments on the intersection lines of the document and the imaging boundaries; the detection result includes that all boundaries have line segments, one boundary has no line segment, and two boundaries have no line segment; The selection of one characteristic line segment for each of the four boundaries of the document according to the identified boundary line segments comprises: For boundary line segments of the same type, the average length of the line segments is calculated according to all boundary line segments of the type, and the boundary line segments of the type are removed according to the average length; Two types of boundary line segments are obtained respectively, the included angle between the two types of boundary line segments is calculated, and the corresponding boundary line segment is obtained as a characteristic line segment according to the included angle; If there is a boundary without a characteristic line segment, the scanning document correction method further comprises a step of supplementing a characteristic line segment, and the step of supplementing a characteristic line segment comprises: Taking boundary A as the boundary without a characteristic line segment, if the boundary C opposite to the boundary A has a characteristic line segment, the characteristic line segment on the boundary C is translated to be tangent to the document foreground region, and the translated line segment is taken as the characteristic line segment of the boundary A; If the boundary C opposite to the boundary A has no characteristic line segment, taking any adjacent boundary B of the boundary A as the boundary, a perpendicular line of the characteristic line segment of the boundary B is translated to be tangent to the document foreground region, two straight lines are obtained, and one of the two straight lines is determined to be the characteristic straight line of the boundary A according to the position of the boundary A.
2. The method of claim 1, wherein, The identification of the boundary line segments to obtain the types of the boundary line segments comprises: The boundary line segments are divided into horizontal line segments and vertical line segments according to the inclination angles of the boundary line segments; The midpoint coordinate values of the vertical line segments are compared with the midpoint coordinate values of the segmentation mask image, and the vertical line segments are determined to be left boundary line segments and right boundary line segments according to the comparison results; The midpoint coordinate values of the horizontal line segments are compared with the midpoint coordinate values of the segmentation mask image, and the horizontal line segments are determined to be upper boundary line segments and lower boundary line segments according to the comparison results.
3. The method of claim 1, wherein, The affine transformation correction according to the characteristic line segments to obtain a corrected document image comprises: Mapping the four corner points obtained by intersecting the straight lines on which the four characteristic line segments are located to a rectangle: An affine transformation matrix is obtained according to the mapping relationship, and the document image is subjected to affine transformation by using the affine transformation matrix to obtain a document image after correction and removal of the scanning background.
4. The method of claim 3, wherein, The affine transformation matrix is obtained by the following method: Any three of the four corner points are selected, and the coordinates are denoted as: (x1, y1), (x2, y2), (x3, y3), and (x4, y4). The coordinates of the points on the rectangle corresponding to the corner points are denoted as: (x1, y1), (x2, y2), (x3, y3), and (x4, y4). The affine transformation matrix is: Let A = B= The affine transformation matrix T is obtained by optimizing the following function:
5. A system for implementing the method of any one of claims 1 to 4, characterized in that, It comprises: An image segmentation module is configured to obtain a document image, perform segmentation processing on the document image, and obtain a segmentation mask image; a line segment detection module configured to perform boundary line segment detection on the segmentation mask image to obtain a plurality of boundary line segments; a line segment identification module configured to identify the boundary line segments to obtain types of the boundary line segments; a line segment selection module configured to select one feature line segment for each of four boundaries of the document according to the identified boundary line segments; a feature mapping module configured to perform affine transformation correction according to the feature line segments to obtain a corrected document image.
6. A scanning document correction apparatus characterized by comprising: comprising: at least one processor; at least one memory configured to store at least one program; when the at least one program is executed by the at least one processor, the at least one processor is caused to implement the method of any one of claims 1-4.
7. A computer readable storage medium having stored therein a program that is executable by a processor, characterized in that, The program executable by the processor when executed by the processor is configured to perform the method of any one of claims 1-4.
Citation Information
Patent Citations
Method and device for correcting document image
CN106296745A
Rapid paper detection and segmentation method based on spatial constraint condition
CN110097561A
Document image geometric correction method, system and device and medium
CN114418869A