CN-116189189-B - Text correction method and device and electronic equipment
Abstract
The application provides a text correction method and device and electronic equipment. When the method is executed, firstly, a picture comprising an irregular text is acquired, then, the largest inscribed rectangle of the target character is determined, two adjacent sides of the largest inscribed rectangle are unequal, a first straight line perpendicular to the horizontal direction is determined in the smallest inscribed rectangle, a second straight line perpendicular to the direction of the short side is determined in the largest inscribed rectangle, the rotation angle of the target character is determined according to the included angle between the first straight line and the second straight line, and finally, the target character is corrected according to the rotation angle of the target character. In this way, the rotation angle of the target character is determined according to the included angle between the first straight line and the second straight line, and the target character is corrected according to the rotation angle of the target character, so that the implementation means for correcting the irregular character gets rid of the dependence on a model, the implementation process is simpler, and the problem of complicated implementation means for correcting the irregular text in the prior art is solved.
Inventors
- LIU YU
- CHEN LIANZHONG
- HU KEYUN
Assignees
- 北京嘉和海森健康科技有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20230224
Claims (9)
- 1. A method of text correction, the method comprising: Acquiring a picture comprising an irregular text, wherein the irregular text comprises target characters; Determining a minimum circumscribed rectangle of the target character in the picture, wherein a group of opposite sides of the minimum circumscribed rectangle are parallel to the horizontal direction; determining an area surrounded by a plurality of vertexes of a target character in the picture, wherein the area surrounded by the plurality of vertexes of the target character is used for determining a maximum inscribed rectangle of the target character; Determining a first straight line perpendicular to the horizontal direction in the minimum circumscribed rectangle, and determining a second straight line perpendicular to the direction in which the short side is located in the maximum inscribed rectangle; Determining the rotation angle of the target character according to the included angle between the first straight line and the second straight line; Correcting the target character according to the rotation angle of the target character; The determining the minimum circumscribed rectangle of the target character in the picture specifically comprises the following steps: The method comprises the steps of determining a left boundary, a right boundary, an upper boundary and a lower boundary of a target character in the picture, wherein the left boundary, the right boundary and the horizontal direction are parallel, the upper boundary, the lower boundary and the horizontal direction are parallel, and the left boundary, the right boundary, the upper boundary and the lower boundary are used for determining the minimum circumscribed rectangle of the target character.
- 2. The method according to claim 1, wherein the method further comprises: Dividing the picture comprising the irregular text by character row units to obtain a plurality of sub-pictures; the determining the left boundary, the right boundary, the upper boundary and the lower boundary of the target character in the picture specifically comprises: determining a left boundary, a right boundary, an upper boundary and a lower boundary of a target character of a target sub-picture in the plurality of sub-pictures; the determining the area surrounded by the plurality of vertexes of the target character in the picture specifically comprises the following steps: and determining an area surrounded by a plurality of vertexes of the target character of the target sub-picture in the plurality of sub-pictures.
- 3. The method according to claim 2, wherein determining the left and right boundaries of the target character of the target sub-picture in the plurality of sub-pictures specifically comprises: Constructing a first matrix, wherein the first matrix is M rows and 1 column, and each element value in the first matrix is 1, wherein M is the same as the pixel row number of the target sub-picture; Multiplying a transposed matrix of a column matrix corresponding to pixel values of each pixel column in the target sub-picture by the first matrix to obtain a plurality of first numerical values; determining a pixel column corresponding to a first value which is not equal to a first preset value as a target pixel column; Determining a pixel column corresponding to a first value, wherein the left side of the target pixel column is equal to a first preset value, as a left boundary of the target character; and determining the pixel column corresponding to the first value, which is equal to the first preset value, on the right side of the target pixel column as the right boundary of the target character.
- 4. A method according to claim 3, wherein determining the upper and lower boundaries of the target character of the target sub-picture in the plurality of sub-pictures specifically comprises: Constructing a second matrix, wherein the second matrix is 1 row and N columns, and each element value in the second matrix is 1, wherein N is the same as the number of columns of pixels between the left boundary and the right boundary of the target character; multiplying a row matrix corresponding to pixel values of each pixel row in the target sub-picture with a transposed matrix of the second matrix to obtain a plurality of second values; determining a pixel row corresponding to a second value which is not equal to the second preset value; And determining the pixel row corresponding to the second numerical value, which is equal to the second preset numerical value, above the target pixel row as the upper boundary of the target character, and determining the pixel row corresponding to the second numerical value, which is equal to the second preset numerical value, below the target pixel row as the lower boundary of the target character.
- 5. The method according to claim 2, wherein after the correcting the target character according to the rotation angle of the target character, the method further comprises: and in the vertical direction, moving the plurality of rotated target characters in the picture to the same horizontal line.
- 6. The method according to claim 5, wherein the moving the rotated target characters in the picture to the same horizontal line specifically comprises: acquiring the ordinate of the middle point of the rotated target character positioned in the same row in the picture comprising the irregular text; Calculating the average value of ordinate coordinates corresponding to the rotated target characters; And moving a plurality of rotated target characters in the picture comprising the irregular text to a horizontal line where the average value is located.
- 7. The method according to any one of claims 1-6, wherein said correcting said target character according to the rotation angle of said target character comprises: And if the rotation angle is larger than a preset angle, correcting the target character according to the rotation angle of the target character.
- 8. The text correction device is characterized by comprising an acquisition module, a determination module and a correction module; the acquisition module is specifically used for acquiring a picture comprising an irregular text, wherein the irregular text comprises target characters; The device comprises a determining module, a first straight line and a second straight line, wherein the determining module is used for determining the minimum circumscribed rectangle of the target character in the picture, a group of opposite edges of the minimum circumscribed rectangle are parallel to the horizontal direction, a region surrounded by a plurality of vertexes of the target character in the picture is determined, the region surrounded by the vertexes is used for determining the maximum inscribed rectangle of the target character, two adjacent edges of the maximum inscribed rectangle are unequal, a first straight line perpendicular to the horizontal direction is determined in the minimum circumscribed rectangle, and a second straight line perpendicular to the direction of the short edge is determined in the maximum inscribed rectangle, and the rotation angle of the target character is determined according to the included angle between the first straight line and the second straight line; The correction module is specifically configured to correct the target character according to the rotation angle of the target character; the determining module is specifically configured to: The method comprises the steps of determining a left boundary, a right boundary, an upper boundary and a lower boundary of a target character in the picture, wherein the left boundary, the right boundary and the horizontal direction are parallel, the upper boundary, the lower boundary and the horizontal direction are parallel, and the left boundary, the right boundary, the upper boundary and the lower boundary are used for determining the minimum circumscribed rectangle of the target character.
- 9. An electronic device is characterized by comprising a memory and a processor; Wherein the memory is used for storing programs; the processor invokes the program and is configured to: Acquiring a picture comprising an irregular text, wherein the irregular text comprises target characters; Determining a minimum circumscribed rectangle of the target character in the picture, wherein a group of opposite sides of the minimum circumscribed rectangle are parallel to the horizontal direction; determining an area surrounded by a plurality of vertexes of a target character in the picture, wherein the area surrounded by the vertexes is used for determining a maximum inscribed rectangle of the target character; Determining a first straight line perpendicular to the horizontal direction in the minimum circumscribed rectangle, and determining a second straight line perpendicular to the direction in which the short side is located in the maximum inscribed rectangle; Determining the rotation angle of the target character according to the included angle between the first straight line and the second straight line; Correcting the target character according to the rotation angle of the target character; The determining the minimum circumscribed rectangle of the target character in the picture specifically comprises the following steps: The method comprises the steps of determining a left boundary, a right boundary, an upper boundary and a lower boundary of a target character in the picture, wherein the left boundary, the right boundary and the horizontal direction are parallel, the upper boundary, the lower boundary and the horizontal direction are parallel, and the left boundary, the right boundary, the upper boundary and the lower boundary are used for determining the minimum circumscribed rectangle of the target character.
Description
Text correction method and device and electronic equipment Technical Field The present application relates to the field of image processing technologies, and in particular, to a text correction method and apparatus, and an electronic device. Background The irregular text generally refers to text which is originally regular due to scanning, photographing angles, photographing modes and the like and is changed into different forms of inclined, curved, askew and the like. Correcting irregular text and facilitating character recognition by optical character recognition technology. Multiple models are commonly used in the art to determine the direction of a character. In the implementation process of determining the character direction, model training is generally performed by using pictures of various deflection angles of a character, and then the deflection angles of the character are determined by using the trained models. In the prior art, if the deflection angles of the characters are to be judged, model training is required to be carried out on the characters with the deflection angles, and the problem that the implementation mode of carrying out irregular text correction is complex exists. Disclosure of Invention In view of the above, the embodiment of the application provides a text correction method, a text correction device and electronic equipment, which aim to solve the problem that the implementation mode for carrying out irregular text correction is complicated in the prior art. In a first aspect, an embodiment of the present application provides a text correction method, where the method includes: Acquiring a picture comprising an irregular text, wherein the irregular text comprises target characters; Determining a minimum circumscribed rectangle of the target character in the picture, wherein a group of opposite sides of the minimum circumscribed rectangle are parallel to the horizontal direction; determining an area surrounded by a plurality of vertexes of a target character in the picture, wherein the area surrounded by the plurality of vertexes of the target character is used for determining a maximum inscribed rectangle of the target character; Determining a first straight line perpendicular to the horizontal direction in the minimum circumscribed rectangle, and determining a second straight line perpendicular to the direction in which the short side is located in the maximum inscribed rectangle; Determining the rotation angle of the target character according to the included angle between the first straight line and the second straight line; and correcting the target character according to the rotation angle of the target character. Optionally, the determining the minimum circumscribed rectangle of the target character in the picture specifically includes: The method comprises the steps of determining a left boundary, a right boundary, an upper boundary and a lower boundary of a target character in the picture, wherein the left boundary, the right boundary and the horizontal direction are parallel, the upper boundary, the lower boundary and the horizontal direction are parallel, and the left boundary, the right boundary, the upper boundary and the lower boundary are used for determining the minimum circumscribed rectangle of the target character. Optionally, the method further comprises: Dividing the picture comprising the irregular text by character row units to obtain a plurality of sub-pictures; the determining the left boundary, the right boundary, the upper boundary and the lower boundary of the target character in the picture specifically comprises: determining a left boundary, a right boundary, an upper boundary and a lower boundary of a target character of a target sub-picture in the plurality of sub-pictures; the determining the area surrounded by the plurality of vertexes of the target character in the picture specifically comprises the following steps: and determining an area surrounded by a plurality of vertexes of the target character of the target sub-picture in the plurality of sub-pictures. Optionally, the determining the left boundary and the right boundary of the target character of the target sub-picture in the plurality of sub-pictures specifically includes: Constructing a first matrix, wherein the first matrix is M rows and 1 column, and each element value in the first matrix is 1, wherein M is the same as the pixel row number of the target sub-picture; Multiplying a transposed matrix of a column matrix corresponding to pixel values of each pixel column in the target sub-picture by the first matrix to obtain a plurality of first numerical values; determining a pixel column corresponding to a first value which is not equal to a first preset value as a target pixel column; Determining a pixel column corresponding to a first value, wherein the left side of the target pixel column is equal to a first preset value, as a left boundary of the target character; and determining t