Text image processing method, device, computer equipment and storage medium

By using a deep learning model to detect the edge coordinates of text images and calculate the rectangular area and tilt angle, it can filter out abnormal text and rotate the image, thus solving the problem of insufficient accuracy in text image recognition and achieving higher correction accuracy and robustness.

CN111353489BActive Publication Date: 2025-09-09SHENZHEN SAIANTE TECH SERVICE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202010123338.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-02-27
Publication Date
2025-09-09
Estimated Expiration
2040-02-27

AI Technical Summary

Technical Problem

Existing text image recognition methods have the problem of insufficient accuracy during the correction process, especially when affected by image noise and text tilt. Traditional methods such as edge detection and Hough line detection have poor robustness.

Method used

The preset text detection model based on deep learning is used to detect the coordinates of text edges, calculate the area and tilt angle of the minimum rectangle, filter out abnormal text, and reversely rotate the image based on the average tilt angle to reduce interference factors and improve correction accuracy.

Benefits of technology

The accuracy of text image correction is improved, the interference of abnormal text is reduced, and the robustness of recognition is enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111353489B_ABST
    Figure CN111353489B_ABST
Patent Text Reader

Abstract

This application relates to a neural network-based text image processing method, apparatus, computer equipment, and storage medium. The method comprises: inputting a text image to be processed into a preset text detection model; using the preset text model to perform edge detection on the characters in the text image to be processed to obtain the edge coordinates of the characters; obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character in the text image to be processed based on the edge coordinates of each character; screening each character based on the rectangular area and tilt angle of each character's minimum rectangle to obtain normal characters; and reversely rotating the text image to be processed based on the average tilt angle of the normal characters to obtain a text image. This method can improve accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an image text method, apparatus, computer equipment, and storage medium. Background Art

[0002] Text image recognition is a key area of ​​office automation, but multiple factors can affect recognition rates. Text tilt in images is a significant factor, and therefore, most current text image recognition applications require correction before recognition.

[0003] Traditional methods for text image correction include edge detection and Hough lines, but they all have significant limitations. For example, because edge detection requires the text in an image to contain connected regions, it is only suitable for inspecting text in complete objects. Hough lines, on the other hand, rely heavily on image quality and have poor robustness. They are easily affected by image noise and can lead to errors, thus reducing correction accuracy. Summary of the Invention

[0004] Based on this, it is necessary to provide a text image processing method, device, computer equipment and storage medium that can accurately solve the above technical problems.

[0005] A text image processing method, the method comprising:

[0006] Inputting the text image to be processed into a preset text detection model, detecting the text in the text image to be processed using the preset text model to obtain the edge coordinates of the text;

[0007] Obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed;

[0008] Screening the characters for abnormality based on the rectangular area and tilt angle of the smallest rectangle of each character to obtain characters without abnormality;

[0009] The text image to be processed is reversely rotated according to the average tilt angle of the normal text to obtain a text image.

[0010] In one embodiment, the obtaining of the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed includes:

[0011] Thinning the edge coordinates of each character in the text image to be processed to obtain thinned edge coordinates;

[0012] Connecting the thinned edge coordinates to obtain a coordinate polygon;

[0013] Traversing to obtain a co-lateral circumscribed rectangle that shares a side with the coordinate polygon;

[0014] A minimum rectangle is determined from the co-lateral circumscribed rectangles, and the rectangular area and tilt angle of the minimum rectangle are obtained.

[0015] In one embodiment, obtaining the tilt angle of the minimum rectangle includes:

[0016] Determine the coordinates of vertices adjacent to the horizontal slanted side of the minimum rectangle;

[0017] The angle between the horizontal plane and the horizontal inclined side is calculated according to the coordinate values ​​of the adjacent vertex coordinates to obtain the inclination angle of the minimum rectangle.

[0018] In one embodiment, the filtering of the characters based on the rectangular area and tilt angle of the smallest rectangle of each character to obtain normal characters includes:

[0019] Calculating an average tilt angle of each of the characters according to the tilt angle;

[0020] Based on the average tilt angle, eliminate the text whose tilt angle does not meet the angle requirement;

[0021] According to the rectangular area of ​​the minimum rectangle of each character, a preset number of characters are selected from the characters that meet the angle requirements as normal characters.

[0022] In one embodiment, removing characters whose tilt angles do not meet the angle requirement based on the average tilt angle includes:

[0023] Calculating the deviation between the average tilt angle and the tilt angle of each character respectively;

[0024] Acquire and eliminate text with a deviation value greater than a threshold.

[0025] In one embodiment, the step of reversely rotating the text image to be processed according to the average tilt angle of the non-abnormal text to obtain the text image includes:

[0026] Determine the average tilt angle and tilt direction of the normal text;

[0027] The text to be processed is rotated in the opposite direction of the tilt direction by an angle equal to the average tilt angle to obtain a text image.

[0028] In one embodiment, rotating the to-be-processed text in a direction opposite to the tilt direction by an angle equal to the average tilt angle to obtain a text image includes:

[0029] Obtaining the coordinates of each pixel in the text image to be processed;

[0030] The coordinates of each pixel point are mapped and transformed based on the tilt direction and the average tilt angle, and an image composed of the pixel points after the coordinate mapping transformation is obtained to obtain a text image.

[0031] A text image processing device, comprising:

[0032] A detection module, configured to input a text image to be processed into a preset text detection model, and perform edge detection on the text in the text image to be processed using the preset text model to obtain edge coordinates of the text;

[0033] An acquisition module, configured to acquire the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed;

[0034] A screening module, configured to screen the characters based on the rectangular area and tilt angle of the smallest rectangle of each character to obtain characters without abnormalities;

[0035] The rotation module is used to reversely rotate the text image to be processed according to the average tilt angle of the non-abnormal text to obtain a text image.

[0036] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the above-mentioned text image processing methods when executing the computer program.

[0037] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of any one of the above-mentioned text image processing methods.

[0038] The above-mentioned text image processing method, device, computer equipment and storage medium perform edge detection on the text image to be processed through a preset text detection model based on deep learning to obtain the edge coordinates of the text, thereby improving the accuracy of obtaining edge information, and then screen the text to obtain normal text based on the rectangular area and tilt angle of the minimum rectangle obtained from the edge coordinates of the text, and perform rotation correction on the text image to be processed based on the tilt angle of the normal text, thereby reducing the interference factors of abnormal text elimination and improving the accuracy of correction. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 This is an application scenario diagram of a text image processing method in one embodiment;

[0040] Figure 2 1 is a flow chart of a text image processing method according to an embodiment;

[0041] Figure 3 A schematic flow chart of a step of obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in a text image to be processed in one embodiment;

[0042] Figure 4 is a schematic diagram of a coordinate polygon in one embodiment;

[0043] Figure 5 is a schematic diagram of a co-lateral circumscribed rectangle in one embodiment;

[0044] Figure 6 is a schematic diagram of a minimum rectangle in one embodiment;

[0045] Figure 7 is a structural block diagram of a text image processing device in one embodiment;

[0046] Figure 8 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0047] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0048] The text image processing method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. Specifically, after the terminal 102 receives the text image to be processed, the above-mentioned text image processing method can be implemented independently. The terminal 102 can also send the text image to be processed to the server 104, and the server 104 can implement the above-mentioned text image processing method independently. For example, the terminal 102 or the server 104 inputs the text image to be processed into a preset text detection model, and uses the preset text model to perform edge detection on the text in the text image to be processed to obtain the edge coordinates of the text; the terminal 102 or the server 104 obtains the rectangular area and tilt angle of the minimum rectangle corresponding to each text according to the edge coordinates of each text in the text image to be processed; the terminal 102 or the server 104 performs abnormal screening on each text based on the rectangular area and tilt angle of the minimum rectangle of each text to obtain non-abnormal text; the terminal 102 or the server 104 reversely rotates the text image to be processed according to the average tilt angle of the non-abnormal text to obtain the text image. The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices, and the server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.

[0049] In one embodiment, Figure 2 As shown, a text image processing method is provided, which is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:

[0050] In step S202 , the text image to be processed is input into a preset text detection model, and the text in the text image to be processed is detected using the preset text model to obtain edge coordinates of the text.

[0051] The text image to be processed refers to the text image that needs to be processed. The detection model is the pre-trained AdvancedEast (Advanced Efficient and Accuracy Scene Text) algorithm model. The edge coordinates refer to the coordinates of the area in the text image that can contain text. Figure 2 The edge coordinates can be understood as all the coordinates on the four edges: 0-1 edge, 1-2 edge, 2-3 edge, and 3-0 edge.

[0052] Specifically, after the server receives the text image to be processed sent by the terminal, it calls the trained AdvancedEast algorithm model. The text image to be processed is input into the AdvancedEast algorithm model, and the AdvancedEast algorithm model detects and obtains the edge coordinates of each character in the text image to be processed. It should be understood that when the AdvancedEast algorithm model detects the text image to be processed, it detects continuous text segments in units of lines, and obtains the edge coordinates of each line of text. For example, when a line of text contains only a single character, the edge coordinates are the edge coordinates of this character. When a line of text contains two or more continuous text segments, the edge coordinates are the edge coordinates of these continuous text segments.

[0053] Step S204 , obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed.

[0054] The minimum rectangle is the smallest enclosing rectangle that encloses the text, and the rectangular area is the area of ​​the minimum rectangle. The tilt angle refers to the angle at which the text is tilted relative to the horizontal plane, which can be understood as the angle between the text and the horizontal plane.

[0055] Specifically, after obtaining the edge coordinates of each line of text in the text image to be processed, an image processing tool, such as OpenCV or MATLAB, can be used to obtain the minimum rectangle for each line of text based on the edge coordinates of each character. The area of ​​the minimum rectangle and its angle with the horizontal plane are then calculated to obtain the minimum rectangle area and tilt angle.

[0056] In step S206 , each character is screened for abnormalities based on the rectangular area and tilt angle of the smallest rectangle of each character to obtain normal characters.

[0057] Since the text in real-world text images is complex and contains certain interference factors, such as watermarks and stamps, removing interference factors by using the rectangular area and tilt angle of the minimum rectangle corresponding to the text can improve the accuracy of subsequent processing.

[0058] In one embodiment, step S206, each character is screened for abnormalities based on the rectangular area and tilt angle of the minimum rectangle of each character to obtain normal characters, specifically including: calculating the average tilt angle of each character based on the tilt angle; based on the average tilt angle, eliminating characters whose tilt angles do not meet the angle requirements; based on the rectangular area of ​​the minimum rectangle of each character, selecting a preset number of characters from the characters that meet the angle requirements as normal characters.

[0059] Specifically, the average tilt angle is the average of the tilt angles of each line of text in the text to be processed. After obtaining the tilt angle of the minimum rectangle of each text, the average tilt angle of each text is calculated based on the number of texts. For example, there are 3 lines of text, and the tilt angles of each line of text are A, B, and C, then the average tilt angle J = (A+B+C) / 3. Then, the average tilt angle is compared with the tilt angle of each text, and the result of the size comparison is used to determine whether the tilt angle meets the angle requirement. The text whose tilt angle does not meet the angle requirement is eliminated, and the text whose tilt angle meets the angle requirement is selected.

[0060] After obtaining text that meets the angle requirements, a preset number of text lines are selected, ranked from largest to smallest, based on the area of ​​the smallest rectangle containing each character, to identify the non-anomalous text lines. For example, if the preset number is 10, then the top 10 text lines that meet the angle requirements are selected based on their area as the non-anomalous text lines. In this implementation, selecting longer text lines by area further eliminates interference factors such as watermarks and stamps that may include shorter text lines.

[0061] In one embodiment, based on the average tilt angle, characters whose tilt angles do not meet the angle requirements are eliminated, including: calculating the deviation value between the average tilt angle and the tilt angle of each character; obtaining and eliminating characters whose deviation value is greater than a threshold.

[0062] Specifically, by calculating the difference between the average tilt angle and the tilt angle of each character, a deviation value between the tilt angle and the average tilt angle is obtained. Then, the deviation value is compared with a preset threshold value, and the deviation value greater than the threshold value is determined, and the characters corresponding to the deviation value are eliminated. The threshold value can be a fixed value set according to the type of text image actually processed. In this embodiment, the threshold value is preferably 30% of the average tilt angle, and the characters to be eliminated are those whose corresponding deviation values ​​are greater than 30% of the average tilt angle.

[0063] Step S208 : reversely rotating the text image to be processed according to the average tilt angle of the text without abnormalities to obtain a text image.

[0064] Specifically, reverse rotation is a rotation in a direction opposite to the average tilt angle. After obtaining the normal text, the average tilt angle and tilt direction of the normal text are first calculated and determined. Then, the text to be processed is rotated in the opposite direction of the tilt direction by the same angle as the average tilt angle to obtain a text image. For example, if the average tilt angle of the normal text is 20 degrees to the left, reverse rotation means rotating the text image to be processed 20 degrees to the right.

[0065] In one embodiment, rotating the text to be processed in the opposite direction of the tilt direction by an angle equal to the average tilt angle to obtain a text image specifically includes: obtaining the coordinates of each pixel point in the text image to be processed; mapping and transforming the coordinates of each pixel point based on the tilt direction and the average tilt angle, obtaining an image composed of the pixel points after the coordinate mapping transformation, and obtaining a text image.

[0066] Specifically, the coordinates of each pixel in the text image to be processed are first obtained. The rotation direction is determined based on the tilt direction, and the rotation angle is determined based on the average tilt angle. The coordinates of each pixel are then remapped based on the rotation direction and rotation angle to obtain new, rotated coordinates for each pixel. The positions of each pixel are adjusted based on the positions of the new, rotated coordinates. The image formed by the adjusted pixels is the rotated text image.

[0067] The above-mentioned text image processing method performs edge detection on the text image to be processed through a preset text detection model based on deep learning to obtain the edge coordinates of the text, thereby improving the accuracy of obtaining edge information, and then screens the text to obtain normal text based on the rectangular area and tilt angle of the minimum rectangle obtained from the edge coordinates of the text, and performs rotation correction on the text image to be processed based on the tilt angle of the normal text, thereby reducing the interference factors of abnormal text elimination and improving the accuracy of correction.

[0068] In one embodiment, Figure 3As shown, obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed includes the following steps:

[0069] Step S302 , thinning the edge coordinates of each character in the text image to be processed to obtain thinned edge coordinates.

[0070] Thinning is the process of applying rules to minimize the number of data points while preserving the shape of the vector curve. Specifically, the obtained edge coordinates are thinned out, and the remaining edge coordinates are the resulting thinned edge coordinates. For example, if there are 100 edge coordinates in total, after thinning, only 50 thinned edge coordinates may remain.

[0071] Step S304: Connect the thinned edge coordinates to obtain a coordinate polygon.

[0072] Specifically, in the order of thinning edge coordinates, each thinned edge coordinate is connected in sequence to obtain a coordinate polygon. Figure 4 As shown, a schematic diagram of a coordinate polygon is provided. Figure 4 , Figure 4 The coordinate polygon shown is a polygon obtained by connecting the six edge coordinates in sequence.

[0073] Step S306: traverse to obtain the co-lateral circumscribed rectangle that shares the same side with the coordinate polygon.

[0074] Step S308 : determining a minimum rectangle from the co-lateral circumscribed rectangles, and obtaining the rectangular area and tilt angle of the minimum rectangle.

[0075] A co-enclosing rectangle is one where one side of the coordinate polygon's circumscribed rectangle coincides with a side of the coordinate polygon. This means that one side of the co-enclosing rectangle is also a side of the coordinate polygon. Therefore, the minimum enclosing rectangle of the coordinate polygon is the desired minimum rectangle.

[0076] Specifically, after obtaining the coordinate polygon, traverse and select each edge in the coordinate polygon, and draw the circumscribed rectangle of the coordinate polygon based on the selected edges. Then, select the rectangle with the smallest area from all the circumscribed rectangles as the minimum rectangle. For example, Figure 4 The hexagon shown has 6 sides, and 6 corresponding co-side circumscribed rectangles can be obtained. From these 6, the circumscribed rectangle with the smallest area is selected as the minimum rectangle. Figure 5 As shown in the figure, a schematic diagram of a co-lateral circumscribed rectangle is provided. Figure 5 , the shape drawn by the solid line is Figure 4 The coordinate polygon shown is drawn with dotted lines. Figure 4The colateral circumscribed rectangle is drawn with the bottom edge of the coordinate polygon shown as the colateral edge.

[0077] Once the minimum rectangle is obtained, the area and tilt angle of the minimum rectangle can be obtained. The area of ​​the minimum rectangle is calculated using the area formula after determining the length and width based on the coordinates of the four vertices of the minimum rectangle.

[0078] In one embodiment, obtaining the tilt angle of the minimum rectangle specifically includes: determining the vertex coordinates adjacent to the horizontal tilt side of the minimum rectangle; calculating the angle between the horizontal plane and the horizontal tilt side based on the coordinate values ​​of the adjacent vertex coordinates to obtain the tilt angle of the minimum rectangle.

[0079] The horizontal inclined edge is the edge of the minimum rectangle that is inclined relative to the horizontal plane. The coordinates of the vertices adjacent to the horizontal inclined edge of the minimum rectangle are the vertices located on the horizontal inclined edge. Figure 6 As shown, a minimum rectangle diagram is provided. Figure 6 , the 0-3 side and the 1-2 side are horizontally inclined sides. The coordinates 0 and 3 on the 0-3 side are the coordinates of the adjacent vertices. The coordinates 1 and 2 on the 1-2 side are the coordinates of the adjacent vertices. Figure 5 Taking the 0-3 side as an example, the calculation formula for the tilt angle θ is as follows:

[0080] θ=arctan((y0-y3) / (x3-x0))

[0081] in addition, Figure 5 The 0-3 side shown is when the position of coordinate 0 is lower than the position of coordinate 3. When the position is reversed, that is, when the position of coordinate 0 is above coordinate 3, the calculation formula of the tilt angle θ is as follows:

[0082] θ=90-(arctan((y0-y3) / (x3-x0)))

[0083] In this embodiment, after thinning the coordinates, the minimum rectangle is determined, which not only removes duplicate coordinates to reduce processing time, but also accurately obtains the minimum rectangle.

[0084] It should be understood that although Figure 2-3 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. In addition, Figure 2-3At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0085] In one embodiment, Figure 7 As shown, a text image processing device is provided, including: a detection module 702, an acquisition module 704, a screening module 706 and a rotation module 708, wherein:

[0086] The detection module 702 is used to input the text image to be processed into a preset text detection model, perform edge detection on the text in the text image to be processed using the preset text model, and obtain edge coordinates of the text.

[0087] The acquisition module 704 is configured to acquire the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed.

[0088] The screening module 706 is used to screen each character based on the rectangular area and tilt angle of the smallest rectangle of each character to obtain normal characters.

[0089] The rotation module 708 is configured to reversely rotate the text image to be processed according to the average tilt angle of the non-abnormal text to obtain a text image.

[0090] In one embodiment, the acquisition module 704 is also used to thin out the edge coordinates of each character in the text image to be processed to obtain thinned edge coordinates; connect the thinned edge coordinates to obtain a coordinate polygon; traverse to obtain a co-lateral circumscribed rectangle that shares a common edge with the coordinate polygon; determine the minimum rectangle from the co-lateral circumscribed rectangles, and obtain the rectangular area and tilt angle of the minimum rectangle.

[0091] In one embodiment, the acquisition module 704 is further configured to determine the coordinates of vertices adjacent to the horizontal slanted side of the minimum rectangle; and calculate the angle between the horizontal plane and the horizontal slanted side according to the coordinate values ​​of the adjacent vertex coordinates to obtain the slant angle of the minimum rectangle.

[0092] In one embodiment, the screening module 706 is also used to calculate the average tilt angle of each character based on the tilt angle; based on the average tilt angle, eliminate the characters whose tilt angles do not meet the angle requirements; based on the rectangular area of ​​the minimum rectangle of each character, select a preset number of characters from the characters that meet the angle requirements as normal characters.

[0093] In one embodiment, the screening module 706 is further configured to respectively calculate the deviation between the average tilt angle and the tilt angle of each character; and obtain and eliminate characters with a deviation value greater than a threshold.

[0094] In one embodiment, the rotation module 708 is further configured to determine the average tilt angle and tilt direction of normal text; and rotate the text to be processed in the opposite direction of the tilt direction by the same angle as the average tilt angle to obtain a text image.

[0095] In one embodiment, the rotation module 708 is also used to obtain the coordinates of each pixel point in the text image to be processed; the coordinates of each pixel point are mapped and transformed based on the tilt direction and the average tilt angle, and an image composed of pixel points after the coordinate mapping transformation is obtained to obtain a text image.

[0096] The specific definition of the text image processing device can be found in the definition of the text image processing method above and will not be repeated here. The various modules in the above-mentioned text image processing device can be implemented in whole or in part through software, hardware, or a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the corresponding operations of the above modules.

[0097] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 8 The computer device includes a processor, a memory, a network interface, and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store relevant data. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a text image processing method is implemented.

[0098] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0099] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0100] Input the text image to be processed into a preset text detection model, use the preset text model to perform edge detection on the text in the text image to be processed, and obtain the edge coordinates of the text;

[0101] Obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed;

[0102] Screen each character based on the rectangular area and tilt angle of the smallest rectangle of each character to obtain normal characters;

[0103] The text image to be processed is reversely rotated according to the average tilt angle of the normal text to obtain a text image.

[0104] In one embodiment, when the processor executes the computer program, the following steps are also implemented: thinning the edge coordinates of each character in the text image to be processed to obtain thinned edge coordinates; connecting the thinned edge coordinates to obtain a coordinate polygon; traversing to obtain a co-lateral circumscribed rectangle that shares a common edge with the coordinate polygon; determining a minimum rectangle from the co-lateral circumscribed rectangles, and obtaining the rectangular area and tilt angle of the minimum rectangle.

[0105] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0106] Determine the coordinates of vertices adjacent to the horizontal slanted side of the minimum rectangle; calculate the angle between the horizontal plane and the horizontal slanted side according to the coordinate values ​​of the adjacent vertex coordinates to obtain the slant angle of the minimum rectangle.

[0107] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0108] The average tilt angle of each character is calculated according to the tilt angle; based on the average tilt angle, characters whose tilt angles do not meet the angle requirements are eliminated; based on the rectangular area of ​​the minimum rectangle of each character, a preset number of characters are selected from the characters that meet the angle requirements as normal characters.

[0109] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0110] Calculate the deviation between the average tilt angle and the tilt angle of each character respectively; obtain and eliminate characters with a deviation value greater than a threshold.

[0111] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0112] Determine the average tilt angle and tilt direction of normal text; rotate the text to be processed in the opposite direction of the tilt direction by the same angle as the average tilt angle to obtain a text image.

[0113] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0114] The coordinates of each pixel in the text image to be processed are obtained; the coordinates of each pixel are mapped and transformed based on the tilt direction and the average tilt angle, and an image composed of the pixel points after the coordinate mapping transformation is obtained to obtain the text image.

[0115] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0116] The text image to be processed is input into a preset text detection model, and the preset text model is used to perform edge detection on the text in the text image to be processed to obtain the edge coordinates of the text.

[0117] Obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed;

[0118] Screen each character based on the rectangular area and tilt angle of the smallest rectangle of each character to obtain normal characters;

[0119] The text image to be processed is reversely rotated according to the average tilt angle of the normal text to obtain a text image.

[0120] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: thinning the edge coordinates of each character in the text image to be processed to obtain thinned edge coordinates; connecting the thinned edge coordinates to obtain a coordinate polygon; traversing to obtain a co-lateral circumscribed rectangle that shares a common edge with the coordinate polygon; determining a minimum rectangle from the co-lateral circumscribed rectangles, and obtaining the rectangular area and tilt angle of the minimum rectangle.

[0121] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: determining the coordinates of vertices adjacent to the horizontal inclined side of the minimum rectangle; calculating the angle between the horizontal plane and the horizontal inclined side based on the coordinate values ​​of the adjacent vertex coordinates to obtain the inclination angle of the minimum rectangle.

[0122] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: calculating the average tilt angle of each character based on the tilt angle; based on the average tilt angle, eliminating characters whose tilt angles do not meet the angle requirements; and selecting a preset number of characters from the characters that meet the angle requirements as normal characters based on the rectangular area of ​​the minimum rectangle of each character.

[0123] In one embodiment, when the computer program is executed by the processor, the following steps are further implemented: respectively calculating the deviation value between the average tilt angle and the tilt angle of each character; obtaining and eliminating characters with a deviation value greater than a threshold.

[0124] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0125] Determine the average tilt angle and tilt direction of normal text; rotate the text to be processed in the opposite direction of the tilt direction by the same angle as the average tilt angle to obtain a text image.

[0126] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0127] The coordinates of each pixel in the text image to be processed are obtained; the coordinates of each pixel are mapped and transformed based on the tilt direction and the average tilt angle, and an image composed of the pixel points after the coordinate mapping transformation is obtained to obtain the text image.

[0128] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0129] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0130] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.

Claims

1. A text image processing method, the method comprising: Inputting the text image to be processed into a preset text detection model, detecting the text in the text image to be processed using the preset text detection model to obtain the edge coordinates of the text; Obtaining the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed; Calculating an average tilt angle of each of the characters according to the tilt angle; Based on the average tilt angle, eliminate the text whose tilt angle does not meet the angle requirement; Selecting a preset number of characters as normal characters from the characters that meet the angle requirement according to the order of the rectangular areas of the minimum rectangles of the characters; Determine the average tilt angle and tilt direction of the normal text; Determine the rotation direction according to the tilt direction of the normal text, and determine the rotation angle according to the average tilt angle of the normal text; Obtaining the coordinates of each pixel in the text image to be processed; The coordinates of each pixel point are mapped and transformed based on the rotation angle and the rotation direction, and an image composed of the pixel points after the coordinate mapping transformation is obtained to obtain a text image.

2. The method according to claim 1, characterized in that The obtaining of the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed includes: Thinning the edge coordinates of each character in the text image to be processed to obtain thinned edge coordinates; Connecting the thinned edge coordinates to obtain a coordinate polygon; Traversing to obtain a co-lateral circumscribed rectangle that shares a side with the coordinate polygon; A minimum rectangle is determined from the co-lateral circumscribed rectangles, and the rectangular area and tilt angle of the minimum rectangle are obtained.

3. The method according to claim 1 or 2, characterized in that The obtaining of the tilt angle of the minimum rectangle includes: Determining coordinates of vertices adjacent to the horizontally inclined side of the minimum rectangle; The angle between the horizontal plane and the horizontal inclined side is calculated according to the coordinate values ​​of the adjacent vertex coordinates to obtain the inclination angle of the minimum rectangle.

4. The method according to claim 1, wherein Eliminating characters whose inclination angles do not meet the angle requirement based on the average inclination angle includes: Calculating the deviation between the average tilt angle and the tilt angle of each character respectively; Acquire and eliminate text with a deviation value greater than a threshold.

5. A text image processing device, characterized in that: The device comprises: A detection module is used to input the text image to be processed into a preset text detection model, and use the preset text detection model to perform edge detection on the text in the text image to be processed to obtain the edge coordinates of the text; An acquisition module, configured to acquire the rectangular area and tilt angle of the minimum rectangle corresponding to each character according to the edge coordinates of each character in the text image to be processed; a screening module, configured to calculate an average tilt angle of each of the characters based on the tilt angle, calculate a deviation between the average tilt angle and the tilt angle of each character, remove characters having a deviation value greater than a threshold value from the characters, and select a preset number of characters from the characters that meet the angle requirement as normal characters based on the order of the rectangular areas of the smallest rectangles of the characters; A rotation module is used to determine the average tilt angle and tilt direction of the normal text, determine the rotation direction according to the tilt direction of the normal text, determine the rotation angle according to the average tilt angle of the normal text, obtain the coordinates of each pixel point in the text image to be processed, map and transform the coordinates of each pixel point based on the rotation angle and the rotation direction, obtain an image composed of the pixel points after the coordinate mapping transformation, and obtain a text image.

6. The device according to claim 5, characterized in that The acquisition module is further used to thin out the edge coordinates of each character in the text image to be processed to obtain thinned edge coordinates; connect the thinned edge coordinates to obtain a coordinate polygon; traverse to obtain a co-edge circumscribed rectangle that shares a common edge with the coordinate polygon; determine a minimum rectangle from the co-edge circumscribed rectangles, and obtain the rectangular area and tilt angle of the minimum rectangle.

7. The device according to claim 5, characterized in that The acquisition module is further configured to determine the coordinates of vertices adjacent to the horizontal inclined side of the minimum rectangle; and calculate the angle between the horizontal plane and the horizontal inclined side according to the coordinate values ​​of the adjacent vertex coordinates to obtain the inclination angle of the minimum rectangle.

8. The device according to claim 5, characterized in that The screening module is further configured to respectively calculate the deviation between the average tilt angle and the tilt angle of each of the characters; and obtain and eliminate characters whose deviation values ​​are greater than a threshold.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Method and apparatus for tag identification

    CN107016387A

  • Method and device for correcting inclined text image, medium and electronic equipment

    CN110427939A

  • Text direction correction method and device, computer device and storage medium

    CN110490198A

  • Identification method and device for character area of OSD and storage medium

    CN110717489A