Text recognition enhancement method, device and equipment
The reference edge is determined through edge recognition and curve fitting, and the stretching ratio is calculated to correct the text image, which solves the problem of being unable to accurately correct curved and tilted text in the existing technology and improves the accuracy of text recognition.
Patent Information
- Application Number
- CN202410742325.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-08-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing text correction methods cannot accurately correct the bending and tilt problems in text images, which affects the accuracy of text recognition.
Determine the edge pixels and edges of the text image through edge recognition, calculate the curvature by fitting the curve function, determine the reference edge according to the curvature, calculate the stretching ratio to stretch the pixels, obtain a quadrilateral text image, and perform affine transformation to restore to a rectangle.
It effectively solves the problem of bending and tilt in text images, improves the accuracy of text recognition, and ensures the standardization of text images.
Smart Images

Figure CN118570108A
Abstract
Description
Background Art
[0002] During the text recognition process, curved and tilted text will interfere with the recognition accuracy. In reality, there is a certain probability that document images will be curved and tilted. The current text correction method is generally based on the text recognition point and the reference point to stretch the text. This method solves the text correction problem to a certain extent, but cannot accurately correct curved and tilted text.
[0003] The text correction method of the corresponding technology also includes identifying the positioning field in the original image based on the pre-trained text model; performing perspective correction processing on the invoice image according to the positioning field to generate a corrected image; identifying the field to be identified in the corrected image based on the text model, generating and displaying the recognition result. The above method requires separate training of the text model, and the correction result is affected by the accuracy of the model.
[0004] Therefore, it is necessary to construct an enhancement method that can restore document images to improve the accuracy of text recognition. Summary of the invention
[0005] The purpose of the present application is to provide a text recognition enhancement method, device and apparatus, which are used to solve the problem that the existing text correction method cannot accurately correct the bending and tilting of text in the text image.
[0006] In a first aspect, an embodiment of the present application provides a text recognition enhancement method, the method comprising:
[0007] Perform edge recognition on the text image to determine the edge pixels and the edges where each edge pixel is located;
[0008] Fitting a curve function of each edge using at least a portion of edge pixel points of each edge, and determining the curvature of each edge according to the curve function of each edge;
[0009] According to whether the curvature of any edge is less than a set threshold, determining that the edge is used as a reference edge, or calculating the straight line function corresponding to the edge, and determining the edge expressed by the straight line function as the reference edge;
[0010] Determine the stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge according to the opposite edge and the corresponding reference edge;
[0011] Based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge, the position of each pixel point is stretched to obtain a text image corrected into a quadrilateral.
[0012] In some possible embodiments, the text image is an image taken when a commodity inspection station intelligently inspects commodities, or the text image is an image taken when a certificate is verified at a supervision location.
[0013] In some possible embodiments, edge recognition is performed on a text image to determine edge pixels and edges where each edge pixel is located, including:
[0014] Perform edge recognition on the text image to obtain edge pixels;
[0015] Filter out four edge pixel points belonging to the endpoints from all edge pixel points, and calculate the coordinates of the center point O according to the coordinates of the four edge pixel points;
[0016] For any edge pixel M, the following method is used to determine whether it is on any side AB, where A and B are two adjacent edge pixels belonging to the endpoints:
[0017] Take the center point O as the starting point and M, A, and B as the end points to construct vectors OM, OE, and OF, and determine the linear relationship between OM and OE, OF as OM=aOE+bOF;
[0018] If a is greater than 0 and b is greater than 0, it is determined that the edge pixel point M is on the edge EF; otherwise, it is determined that it is not on the edge EF.
[0019] In some possible embodiments, determining to use any edge as a reference edge or calculating a straight line function corresponding to the edge according to whether the curvature of any edge is less than a set threshold value includes:
[0020] For any set of opposite edges, if the curvature of each edge in the set of opposite edges is less than the set threshold, it is determined that both edges in the set of opposite edges are reference edges;
[0021] For any set of comparisons, if the curvature of any side in the set of opposite sides is not less than a set threshold, the corresponding straight line function is determined according to the curve function of each side in the set of opposite sides.
[0022] In some possible embodiments, determining the stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge includes:
[0023] Determine a first distance between two edge pixel points of the opposite side and a second distance between two edge pixel points of the corresponding reference side in the same row or column direction perpendicular to the corresponding reference side;
[0024] The ratio of the first distance to the second distance is determined as a stretching ratio in the same row or column direction perpendicular to the corresponding reference edge.
[0025] In some possible embodiments, based on the determined stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge, stretching the position of each pixel includes:
[0026] In the determined direction of the same row or the same column perpendicular to the corresponding reference edge, two edge pixel points of the opposite edges in the direction are stretched to the corresponding reference edge respectively;
[0027] Determine any other pixel point in the direction, if the stretching ratio is less than 1, based on the distance s from the pixel point to the farther side of the opposite side before stretching, the distance from the pixel point to the reference side corresponding to the side after stretching is s / p, determine the position of the pixel point after stretching, and p is the stretching ratio;
[0028] If the stretching ratio is greater than 1, based on the distance s between the pixel point and the closer side of the opposite sides before stretching, the distance between the pixel point and the reference side corresponding to the side after stretching is s / p, and the position of the pixel point after stretching is determined;
[0029] After it is determined that the stretching of all the pixels in this direction is completed, the coordinates of the corresponding new pixels are calculated according to the positions of the stretched pixels through the neighboring point interpolation algorithm.
[0030] In some possible embodiments, after obtaining the text image corrected into a quadrilateral, the method further includes:
[0031] An affine transformation is performed on the text image corrected into a quadrilateral to restore the text image into a rectangle.
[0032] In a second aspect, an embodiment of the present application provides a text recognition enhancement device, the device comprising:
[0033] The edge recognition module is used to perform edge recognition on the text image and determine the edge pixels and the edges where the edge pixels are located;
[0034] A curvature determination module, configured to fit a curve function of each edge using at least a portion of edge pixels of each edge, and determine the curvature of each edge according to the curve function of each edge;
[0035] A reference edge determination module, used to determine whether the curvature of any edge is less than a set threshold value, to take the edge as the reference edge, or to calculate the straight line function corresponding to the edge, and determine the edge expressed by the straight line function as the reference edge;
[0036] A stretching ratio determination module, used to determine the stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge according to the opposite edge and the corresponding reference edge respectively;
[0037] The image stretching module is used to stretch the position of each pixel point based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge to obtain a text image corrected into a quadrilateral.
[0038] In the third aspect, another embodiment of the present application also provides a text recognition enhancement device, comprising at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method provided in the first aspect above.
[0039] In a fourth aspect, another embodiment of the present application further provides a computer storage medium, wherein the computer storage medium stores a computer program, and the computer program is used to enable a computer to execute any text recognition enhancement method provided in the embodiments of the present application.
[0040] The text recognition enhancement method, device and apparatus provided in the embodiments of the present application identify edges and determine the curvature of each edge, determine the contrast that needs to be stretched based on the curvature, stretch the pixels in the corresponding direction according to the corresponding stretching ratio, and obtain a quadrilateral text image. This solves the problem that the existing text correction method cannot accurately correct text images due to placement steps or curling.
[0041] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. Obviously, the drawings introduced below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0043] Figure 1 is a schematic diagram of an application environment according to an embodiment of the present application;
[0044] Figure 2 A schematic diagram of a text image of a curved and tilted document captured according to an embodiment of the present application;
[0045] Figure 3 is a flow chart of a text recognition enhancement method according to an embodiment of the present application;
[0046] Figure 4 A schematic diagram of a process for determining a reference edge according to an embodiment of the present application;
[0047] Figure 5 A schematic diagram of a process for determining the edge corresponding to each edge pixel point according to an embodiment of the present application;
[0048] Figure 6 This is a schematic diagram of a document with four endpoints identified, taken according to an embodiment of the present application;
[0049] Figure 7 A schematic diagram of a process for determining whether any edge pixel is on any side according to an embodiment of the present application;
[0050] Figure 8 is a schematic diagram of a vector constructed with the center point O as the starting point according to an embodiment of the present application;
[0051] Fig. 9 A schematic diagram of whether to correct an edge according to a curvature according to an embodiment of the present application;
[0052] Fig.10 A schematic diagram of corresponding reference edges determined for two curved edges according to an embodiment of the present application;
[0053] Fig.11 A schematic diagram of a process for determining a stretching ratio for stretching pixels in the same row or column according to an embodiment of the present application;
[0054] Fig.12 It is a schematic diagram of a process of stretching pixels in the same row or column according to a stretching ratio according to an embodiment of the present application;
[0055] Fig.13 A schematic diagram of a process of performing pixel interpolation after stretching according to an embodiment of the present application;
[0056] Fig.14 A schematic diagram of performing affine transformation on a text image according to an embodiment of the present application;
[0057] Fig.15 is a schematic diagram of an enhanced text image according to an example of an embodiment of the present application;
[0058] Fig.16 is a structural schematic diagram of a text recognition enhancement device according to an embodiment of the present application;
[0059] Fig.17 Schematic diagram of the structure of a text recognition enhancement device according to an embodiment of the present application. DETAILED DESCRIPTION
[0060] To further illustrate the technical solution provided by the embodiment of the present application, this is described in detail below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiment of the present application provides the method operation steps as shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiment of the present application. The method can be executed in the order of the method shown in the embodiment or drawings or in parallel during the actual processing process or when the control device is executed.
[0061] In view of the fact that the text correction method in the related art cannot accurately correct the problem of bending and tilting of text in the text image, the present application proposes a text recognition enhancement method, device and equipment that simultaneously solves the tilt and bending problems to improve the accuracy of document recognition.
[0062] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings.
[0063] The text recognition enhancement method in the embodiment of the present application is described in detail below with reference to the accompanying drawings.
[0064] See also Figure 1 , is a schematic diagram of an application environment according to an embodiment of the present application.
[0065] like Figure 1 As shown, the application environment may include, for example, text 10, a photographing device 20, and a text recognition enhancement device 30, wherein:
[0066] The photographing device 20 is used to photograph the text 10 to obtain a text image containing the text, and the text recognition enhancement device 30 is used to enhance the text image to solve the problem of irregular text due to bending or tilting of the text during shooting and inaccurate subsequent text recognition results.
[0067] The above text can be various document files or ID photos, etc. As long as it is a rectangular object with four straight sides, it can be regarded as text. The embodiment of the present application does not limit the form of the text.
[0068] like Figure 2 The figure shows a text image taken with the text as a document file as an example. It can be seen from the figure that the document file in the captured text image has bending and tilting problems due to the bending of the text, and the text correction method in the related art cannot accurately correct the bending and tilting problems of the text in the text image.
[0069] Figure 3 A flowchart of a text recognition enhancement method provided by an embodiment of the present application is shown, including:
[0070] Step 301, edge recognition is performed on the text image to determine edge pixels and the edges where the edge pixels are located;
[0071] The text image in the embodiment of the present application is a text image obtained by photographing a rectangular text. By performing edge recognition on the text image, edge pixel points of the text in the text image can be identified.
[0072] In the embodiment of the present application, for all edge pixel points identified, it is necessary to determine the edge to which each edge pixel point belongs, thereby obtaining edge pixel points on four edges.
[0073] Step 302, fitting a curve function of each edge using at least part of edge pixels of each edge, and determining the curvature of each edge according to the curve function of each edge;
[0074] After obtaining the edge pixel points of each side, the embodiment of the present application can select some edge pixel points from the edge pixel points of the side for curve fitting. The edge pixel points at different positions can be selected in a uniform selection manner. Specifically, the least square method can be used for curve fitting to determine the corresponding curve function. For the horizontal side, the expression of the curve function is y=mx 2 +nx+l; for the longitudinal edge, the curve function is expressed as x=my 2 +ny+l, where x represents the horizontal coordinate of the pixel, y represents the vertical coordinate of the pixel, m, n, and l are constants determined by curve fitting, and the larger the |m|, the higher the curvature of the edge.
[0075] Step 303, according to whether the curvature of any edge is less than a set threshold, determine that the edge is used as a reference edge, or calculate the straight line function corresponding to the edge, and determine the edge expressed by the straight line function as the reference edge;
[0076] If the curvature of an edge is not less than the set threshold, it means that the curvature of the edge is high and meets the correction requirements. It is necessary to calculate the straight line function first and determine the edge expressed by the straight line function as the reference edge. During the correction process, the correction is performed with the goal of correcting the curved edge to the reference edge. If the curvature of an edge is less than the set threshold, it means that the edge is close to the straight line edge and can be directly used as the reference edge without correction.
[0077] like Figure 4 As shown, the process of determining the reference edge of each edge based on the curvature of each edge in the embodiment of the present application includes:
[0078] Step 401, determine whether the curvature of any side is less than a set threshold, if it is less than the set threshold, execute step 402, otherwise execute step 403;
[0079] The above threshold value can be determined according to the requirements and can be set to 0 or a value close to zero.
[0080] Step 402, determining the edge as the corresponding reference edge;
[0081] Step 403: Calculate the straight line function corresponding to the edge, and determine that the edge expressed by the straight line function is the corresponding reference edge.
[0082] When it is determined according to the curve function of the text that the curvature is greater than the set threshold, as a possible implementation method, a curve fitting method can be used to fit the expression of the straight line function. Specifically, for the horizontal curve edge, the expression of the straight line function of y=kx+j is fitted, and for the vertical edge, the expression of the straight line function of x=ky+j is fitted; as another possible implementation method, the edge pixel points at the two end points of the horizontal edge can be used to solve the expression of the straight line function of y=kx+j, and the edge pixel points at the two end points of the vertical edge can be used to solve the expression of the straight line function of x=ky+j, wherein x represents the horizontal coordinate of the pixel point, y represents the vertical coordinate of the pixel point, and k and j are constants.
[0083] Step 304, determining the stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge according to the opposite edge and the corresponding reference edge;
[0084] The above stretching ratio is used to achieve stretching of pixels in the same column direction perpendicular to the corresponding reference edge, such as for the horizontal edge, and for the vertical edge, to achieve stretching of pixels in the same row direction, thereby achieving overall stretching.
[0085] Step 305 , based on the determined stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge, stretch the position of each pixel to obtain a text image corrected into a quadrilateral.
[0086] The text recognition enhancement method, device and apparatus provided in the embodiments of the present application recognize edges and determine the curvature of each edge, determine the stretching ratio required based on the curvature, stretch the pixels in the corresponding direction according to the corresponding stretching ratio, and obtain a text image with four straight edges. This solves the problem that the existing text correction method cannot accurately correct text images due to placement steps or curling.
[0087] In the embodiment of the present application, the above-mentioned text image is an image taken when the commodity inspection station intelligently inspects the commodity, or the text image is an image taken when the certificate is verified at the supervision location. Of course, it can also be a text image taken in other scenes.
[0088] like Figure 5 As shown, the embodiment of the present application performs edge recognition on a text image to determine edge pixels and the edges where each edge pixel is located, including:
[0089] Step 501, performing edge recognition on the text image to obtain edge pixels;
[0090] Step 502, selecting four edge pixel points belonging to the end points from all edge pixel points, and calculating the coordinates of the center point O according to the coordinates of the four edge pixel points;
[0091] The present application embodiment takes the text as a document file as an example. Figure 6 The figure shows a schematic diagram of a document file in a corresponding text image after edge recognition determines the edge to which each edge pixel belongs, wherein the four endpoints are edge pixel A, edge pixel B, edge pixel C, and edge pixel D. Specifically, the following method can be used to select the four edge pixel points belonging to the endpoints from all edge pixels:
[0092] Determine that the coordinates of edge pixel point A satisfy max(-x+y), that is, the edge pixel point with the smallest horizontal coordinate x and the largest vertical coordinate y among all edge pixel points;
[0093] Determine that the coordinates of edge pixel point B satisfy max(x+y), that is, the edge pixel point with the largest horizontal coordinate x and the largest vertical coordinate y among all edge pixel points;
[0094] Determine the edge pixel point C whose coordinates satisfy max(xy), that is, the edge pixel point with the largest horizontal coordinate x and the smallest vertical coordinate y among all edge pixel points;
[0095] It is determined that the coordinates of the edge pixel point D satisfy max(-xy), that is, the edge pixel point with the smallest horizontal coordinate x and the smallest vertical coordinate y among all edge pixel points.
[0096] After obtaining the coordinates of edge pixel points A, B, C, and D, the coordinates of the center point O are calculated as follows (X o , Y o ):
[0097] X o =(x a +x b +x c +x d ) / 4;
[0098] Y o =(y a +y b +y c +y d ) / 4.
[0099] Among them, x a 、x b 、x c 、x d are the horizontal coordinates of edge pixel point A, edge pixel point B, edge pixel point C, and edge pixel point D, respectively. a ,y b ,y c ,y d They are the ordinates of edge pixel point A, edge pixel point B, edge pixel point C, and edge pixel point D respectively.
[0100] Step 503: corresponding to any edge pixel point M, determine whether the edge pixel point is on any edge EF, where E and F are two adjacent edge pixel points belonging to endpoints.
[0101] EF is any side of the text, and according to the above example, it may be side AB, side DC, side AD, or side BC.
[0102] like Figure 7 As shown, in the embodiment of the present application, corresponding to any edge pixel point M, determining whether the edge pixel point is on any edge EF includes:
[0103] Step 701, constructing vectors OM, OE, and OF with the center point O as the starting point and M, E, and F as the end points, and determining the linear relationship between OM and OE, OF as OM=aOE+bOF;
[0104] According to the above example, taking edge AB as an example, firstly, take O as the starting point, and take any edge pixel point M, edge pixel point A, and edge pixel point B as the end points to construct three vectors. The constructed vectors OA, OM, and OB are as follows: Figure 8 As shown:
[0105] OA=(x a -x o ,y a -y o )=(x 1 ,y 1 )
[0106] OB=(x b -x o ,y b -y o )=(x 2 ,y 2 )
[0107] OM=(x m -x o ,y m -y o )=(x 3 ,y 3 )
[0108] Construct the linear relationship between OM and OA, OB: OM = aOM + bOB;
[0109] That is: ax 1 +bx 2 =x 3 ,ay 1 +by 2 =y 3
[0110] According to the above equation, a and b can be calculated.
[0111] Step 702, determine whether a is greater than 0 and b is greater than 0, if so, execute step 703, otherwise execute step 704;
[0112] Step 703: if a is greater than 0 and b is greater than 0, determine that the edge pixel point M is on the edge EF;
[0113] Step 704: determine whether the edge pixel point M is not on the edge EF.
[0114] According to the above example, if a>0, b>0, the edge pixel point M is on the edge AB, otherwise it is not. Similarly, the relationship between all edge pixels and the four edges can be determined, so that all edge pixels can be grouped according to the four edges.
[0115] In the embodiment of the present application, after all edge pixels are grouped into four sides, at least part of the edge pixels of each side are used to fit the curve function of the edge, and the curvature of each side is determined according to the curve function of each side. According to the above example, taking the side AB as an example, the following quadratic function fitting is performed: y=mx 2 +nx+l.
[0116] Specifically, in addition to edge pixel points A and edge pixel point B, several edge pixel points can be uniformly selected on edge AB, and each edge pixel point can be substituted into the above formula to form an equation:
[0117] x i 2 m+x i n+l=y i
[0118] Multiple equations form a system of equations. The least square method can be used to calculate m and n, thereby obtaining the fitting function of edge AB. Similarly, the functions of the other three edges can be fitted, but the expressions of BC and DA need to swap the coordinates x and y:
[0119] x=my 2 +ny+l.
[0120] After determining the curvature of the four edges, the embodiment of the present application can determine whether each edge needs to be corrected according to the curvature of each edge, that is, determine the edge expressed by the straight line function of the edge as the reference edge. Generally, for text, there is a group of contrasts with a large change in curvature due to bending and tilting, and another group of contrasts has almost zero curvature or slight curvature, such as Fig. 9 As shown, the embodiment of the present application determines the edge that needs to be corrected based on the curvature in the following manner, including:
[0121] Step 901, for any set of opposite sides, determine whether the curvature of each side in the set of opposite sides is less than a set threshold, if so, execute step 902, otherwise execute step 903;
[0122] Step 902, if the curvature of each side in the set of opposite sides is less than a set threshold, it is determined that both sides in the set of opposite sides are reference sides;
[0123] That is, for a set of opposite sides with a smaller curvature, you can choose not to make corrections.
[0124] Step 903: if the curvature of any side in the set of opposite sides is not less than a set threshold, determine the corresponding straight line function according to the curve function of each side in the set of opposite sides.
[0125] In the above manner, a group of opposite sides with a larger curvature can be screened out. In the case where there is usually only one set of contrast bends, only the set of contrast with a larger curvature is corrected. Of course, the curvatures of the four sides can also be directly compared, and a group of opposite sides with the largest curvature is selected for correction, while the other group of opposite sides is not corrected.
[0126] like Fig.10 As shown, the curvature of the side AB and the side DC is relatively small, close to a straight line side, while the side AD and the side BC belong to a group of opposite sides with a larger curvature. The larger the |m|, the higher the curvature of the side. Therefore, the embodiment of the present application compares the four |m|s, selects the smaller group of opposite sides as the straight line sides, and the other group of opposite sides as the curved sides that need to be corrected.
[0127] After the edge to be corrected is determined in the embodiment of the present application, the stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge is determined, such as Fig.11 As shown, including:
[0128] Step 1101, determining a first distance between two edge pixel points of the opposite side and a second distance between two edge pixel points of the corresponding reference side in the same row or column direction perpendicular to the corresponding reference side;
[0129] Step 1102: determine the ratio of the first distance to the second distance as a stretching ratio in the same row or column direction perpendicular to the corresponding reference edge.
[0130] The above stretching ratio represents the ratio of the distance between two pixels before and after stretching. For the same row or column, the higher the inward curvature, the smaller the stretching ratio, and the higher the outward curvature, the larger the stretching ratio.
[0131] Based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge, the position of each pixel point is stretched, such as Fig.12 As shown, including:
[0132] Step 1201, in the same row or column direction perpendicular to the corresponding reference edge, two edge pixel points on opposite sides in the direction are respectively stretched to the corresponding reference edge;
[0133] For the horizontal reference edge, the two edge pixels in the same column are stretched column by column, and they are stretched to the reference edge where the edge pixels are close to each other in the column; for the vertical reference edge, the two edge pixels in the same row are stretched row by row, and they are stretched to the reference edge where the edge pixels are close to each other in the row, so as to realize the correction of the edge pixels.
[0134] Step 1202, for any other pixel point in the direction, if the stretching ratio is less than 1, based on the distance s from the pixel point to the farther side of the opposite sides before stretching, and the distance from the pixel point to the reference side corresponding to the side after stretching being s / p, determine the position of the pixel point after stretching;
[0135] Step 1203, if the stretching ratio is greater than 1, based on the distance s between the pixel point and the closer side of the opposite sides before stretching, the distance between the pixel point and the reference side corresponding to the side after stretching is s / p, and the position of the pixel point after stretching is determined, where p is the stretching ratio.
[0136] by Figure 6In the example shown, since both sides AB and DC are reference sides, there is no need to perform stretching in the column direction, only stretching in the same row direction. For any row, calculate the distance between the edge pixels on both sides of this row, and the distance between the intersection of this row and the straight reference side corresponding to side BC and the straight reference side corresponding to side DA, and use the two distance ratios p as the stretching ratio of the pixel. Specifically, select all the pixels in any row, stretch the two edge pixels to the reference side they are close to, and for any pixel in the middle, if the pixel is close to side BC, let the distance from the left edge point before stretching be s, and the distance from the intersection of this row and the straight reference side be s' after stretching, then the relationship between the two is: s / s'=p. Thus, the position of the pixel after stretching can be determined.
[0137] After all pixels are stretched, in order to meet the resolution requirements, the coordinates of the corresponding new pixels are calculated by the neighboring point interpolation algorithm. Fig.13 As shown, the method also includes:
[0138] Step 1301, determine whether stretching of all pixels in the same row or column is completed;
[0139] Step 1302, using a neighboring point interpolation algorithm, calculate the coordinates of the corresponding new pixel point according to the position of the stretched pixel point.
[0140] After the above processing, a quadrilateral with straight edges can be obtained. In order to further restore the text, Fig.14 As shown, the method of the embodiment of the present application also includes:
[0141] Step 1401, determining to obtain a text image corrected into a quadrilateral;
[0142] Step 1402: Perform affine transformation on the text image corrected into a quadrilateral, and restore the text image into a rectangle.
[0143] like Fig.15 As shown, the text recognition enhancement method provided by the embodiment of the present application is Figure 2 The text image shown is the text image effect after correction.
[0144] Based on the same inventive concept, the present application also provides a text recognition enhancement device, such as Fig.16 As shown, the device comprises:
[0145] The edge recognition module 1601 is used to perform edge recognition on the text image and determine edge pixels and the edges where the edge pixels are located;
[0146] A curvature determination module 1602 is used to fit a curve function of each edge using at least part of edge pixels of each edge, and determine the curvature of each edge according to the curve function of each edge;
[0147] The reference edge determination module 1603 is used to determine whether the curvature of any edge is less than a set threshold value, determine that the edge is used as the reference edge, or calculate the straight line function corresponding to the edge, and determine that the edge expressed by the straight line function is the reference edge;
[0148] The stretching ratio determination module 1604 is used to determine the stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge according to the opposite edge and the corresponding reference edge respectively;
[0149] The image stretching module 1605 is used to stretch the position of each pixel point based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge, so as to obtain a text image corrected into a quadrilateral.
[0150] In some possible embodiments, the text image is an image taken when a commodity inspection station intelligently inspects commodities, or the text image is an image taken when a certificate is verified at a supervision location.
[0151] In some possible embodiments, the edge recognition module performs edge recognition on the text image to determine edge pixels and edges where the edge pixels are located, including:
[0152] Perform edge recognition on the text image to obtain edge pixels;
[0153] Filter out four edge pixel points belonging to the endpoints from all edge pixel points, and calculate the coordinates of the center point O according to the coordinates of the four edge pixel points;
[0154] For any edge pixel M, the following method is used to determine whether it is on any side AB, where A and B are two adjacent edge pixels belonging to the endpoints:
[0155] Take the center point O as the starting point and M, A, B as the end points to construct vectors OM, OE, OF, and determine the linear relationship between OM and OA, OB as OM = aOE + bOF;
[0156] If a is greater than 0 and b is greater than 0, it is determined that the edge pixel point M is on the edge EF; otherwise, it is determined that it is not on the edge EF.
[0157] In some possible embodiments, the reference edge determination module determines whether the curvature of any edge is less than a set threshold value, and determines whether the edge is used as the reference edge, or calculates the straight line function corresponding to the edge, including:
[0158] For any set of opposite edges, if the curvature of each edge in the set of opposite edges is less than the set threshold, it is determined that both edges in the set of opposite edges are reference edges;
[0159] For any set of comparisons, if the curvature of any side in the set of opposite sides is not less than a set threshold, the corresponding straight line function is determined according to the curve function of each side in the set of opposite sides.
[0160] In some possible embodiments, the stretching ratio determination module determines the stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge, including:
[0161] Determine a first distance between two edge pixel points of the opposite side and a second distance between two edge pixel points of the corresponding reference side in the same row or column direction perpendicular to the corresponding reference side;
[0162] The ratio of the first distance to the second distance is determined as a stretching ratio in the same row or column direction perpendicular to the corresponding reference edge.
[0163] In some possible embodiments, the image stretching module stretches the position of each pixel point based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge, including:
[0164] In the determined direction of the same row or the same column perpendicular to the corresponding reference edge, two edge pixel points of the opposite edges in the direction are stretched to the corresponding reference edge respectively;
[0165] Determine any other pixel point in the direction, if the stretching ratio is less than 1, based on the distance s from the pixel point to the farther side of the opposite side before stretching, the distance from the pixel point to the reference side corresponding to the side after stretching is s / p, determine the position of the pixel point after stretching, and p is the stretching ratio;
[0166] If the stretching ratio is greater than 1, based on the distance s between the pixel point and the closer side of the opposite sides before stretching, the distance between the pixel point and the reference side corresponding to the side after stretching is s / p, and the position of the pixel point after stretching is determined;
[0167] After it is determined that the stretching of all the pixels in this direction is completed, the coordinates of the corresponding new pixels are calculated according to the positions of the stretched pixels through the neighboring point interpolation algorithm.
[0168] In some possible embodiments, after obtaining the text image corrected into a quadrilateral, the image stretching module is further used to:
[0169] An affine transformation is performed on the text image corrected into a quadrilateral to restore the text image into a rectangle.
[0170] After introducing the text recognition enhancement method and apparatus according to the exemplary embodiment of the present application, next, a text recognition enhancement device according to another exemplary embodiment of the present application is introduced.
[0171] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.
[0172] In some possible implementations, the text recognition enhancement device according to the present application may include at least one processor and at least one memory. The memory stores program code, and when the program code is executed by the processor, the processor executes the steps of the text recognition enhancement method according to various exemplary implementations of the present application described above in this specification.
[0173] Refer to the following Fig.17 The text recognition enhancement device 170 according to this embodiment of the present application is described below. Fig.17 The displayed text recognition enhancement device 170 is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0174] like Fig.17 As shown, the text recognition enhancement device 170 is in the form of a general electronic device. The components of the text recognition enhancement device 170 may include but are not limited to: at least one processor 171, at least one memory 172, and a bus 173 connecting different system components (including the memory 172 and the processor 171).
[0175] Bus 173 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, or a local bus using any of a variety of bus architectures.
[0176] The memory 172 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 1721 and / or a cache memory 1722 , and may further include a read-only memory (ROM) 1723 .
[0177] Memory 172 may also include a program / utility 1725 having a set (at least one) of program modules 1724, such program modules 1724 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0178] The text recognition enhancement device 170 may also communicate with one or more external devices 174 (e.g., keyboards, pointing devices, etc.), one or more devices that enable a user to interact with the text recognition enhancement device 170, and / or any device that enables the text recognition enhancement device 170 to communicate with one or more other electronic devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 175. In addition, the text recognition enhancement device 170 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 176. As shown, the network adapter 176 communicates with other modules for the text recognition enhancement device 170 via a bus 173. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the text recognition enhancement device 170, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0179] In some possible implementations, various aspects of a text recognition enhancement method provided by the present application may also be implemented in the form of a program product, which includes program code. When the program product is run on a computer device, the program code is used to enable the computer device to execute the steps of a text recognition enhancement method according to various exemplary implementations of the present application described above in this specification.
[0180] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0181] The program product for monitoring of the embodiment of the present application can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on an electronic device. However, the program product of the present application is not limited to this. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, an apparatus or a device or used in combination with it.
[0182] The readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein the readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0183] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0184] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and also conventional procedural programming languages such as "C" language or similar programming languages. The program code can be executed entirely on the user electronic device, partially on the user device, as an independent software package, partially on the user electronic device and partially on the remote electronic device, or entirely on the remote electronic device or server. In the case of a remote electronic device, the remote electronic device can be connected to the user electronic device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external electronic device (for example, using an Internet service provider to connect through the Internet).
[0185] It should be noted that, although several units or subunits of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided into multiple units to be embodied.
[0186] In addition, although the operations of the method of the present application are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0187] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0188] The present application is described with reference to the flowcharts and block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and block diagram, as well as the combination of the processes and boxes in the flowchart and block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and block diagram. Figure 1 Process or multiple processes and boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0189] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 Process or multiple processes and boxes Figure 1 A function specified in one or more boxes.
[0190] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 Process or multiple processes and boxes Figure 1 A step that specifies a function in one or more boxes.
[0191] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0192] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A text recognition enhancement method, characterized in that: The method comprises: Perform edge recognition on the text image to determine the edge pixels and the edges where each edge pixel is located; Fitting a curve function of each edge using at least a portion of edge pixel points of each edge, and determining the curvature of each edge according to the curve function of each edge; According to whether the curvature of any edge is less than a set threshold, determining that the edge is used as a reference edge, or calculating the straight line function corresponding to the edge, and determining the edge expressed by the straight line function as the reference edge; Determine the stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge according to the opposite edge and the corresponding reference edge; Based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge, the position of each pixel point is stretched to obtain a text image corrected into a quadrilateral.
2. The method according to claim 1, characterized in that The text image is an image taken when the commodity inspection station intelligently inspects the commodity, or the text image is an image taken when the certificate is verified at the supervision location.
3. The method according to claim 1, characterized in that: Perform edge recognition on text images to determine edge pixels and the edges where each edge pixel is located, including: Perform edge recognition on the text image to obtain edge pixels; Filter out four edge pixel points belonging to the endpoints from all edge pixel points, and calculate the coordinates of the center point O according to the coordinates of the four edge pixel points; For any edge pixel M, the following method is used to determine whether it is on any edge EF, where A and B are two adjacent edge pixels belonging to the endpoints: Take the center point O as the starting point and M, A, and B as the end points to construct vectors OM, OE, and OF, and determine the linear relationship between OM and OE, OF as OM=aOE+bOF; If a is greater than 0 and b is greater than 0, it is determined that the edge pixel point M is on the edge EF; otherwise, it is determined that it is not on the edge EF.
4. The method according to claim 1, characterized in that: According to whether the curvature of any edge is less than a set threshold, the edge is determined to be used as a reference edge, or the straight line function corresponding to the edge is calculated, including: For any set of opposite edges, if the curvature of each edge in the set of opposite edges is less than the set threshold, it is determined that both edges in the set of opposite edges are reference edges; For any set of comparisons, if the curvature of any side in the set of opposite sides is not less than a set threshold, the corresponding straight line function is determined according to the curve function of each side in the set of opposite sides.
5. The method according to claim 1, characterized in that Determine the stretching ratio of each pixel in the same row or column direction perpendicular to the corresponding reference edge, including: Determine a first distance between two edge pixel points of the opposite side and a second distance between two edge pixel points of the corresponding reference side in the same row or column direction perpendicular to the corresponding reference side; The ratio of the first distance to the second distance is determined as a stretching ratio in the same row or column direction perpendicular to the corresponding reference edge.
6. The method according to claim 1, characterized in that Based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge, the position of each pixel point is stretched, including: In the determined direction of the same row or the same column perpendicular to the corresponding reference edge, two edge pixel points of the opposite edges in the direction are stretched to the corresponding reference edge respectively; Determine any other pixel point in the direction, if the stretching ratio is less than 1, based on the distance s from the pixel point to the farther side of the opposite side before stretching, the distance from the pixel point to the reference side corresponding to the side after stretching is s / p, determine the position of the pixel point after stretching, and p is the stretching ratio; If the stretching ratio is greater than 1, based on the distance s between the pixel point and the closer side of the opposite sides before stretching, the distance between the pixel point and the reference side corresponding to the side after stretching is s / p, and the position of the pixel point after stretching is determined; After it is determined that the stretching of all the pixels in this direction is completed, the coordinates of the corresponding new pixels are calculated according to the positions of the stretched pixels through the neighboring point interpolation algorithm.
7. The method according to claim 1, characterized in that After obtaining the text image corrected to a quadrilateral, the following steps are also included: An affine transformation is performed on the text image corrected into a quadrilateral to restore the text image into a rectangle.
8. A text recognition enhancement device, characterized in that: The device comprises: The edge recognition module is used to perform edge recognition on the text image and determine the edge pixels and the edges where the edge pixels are located; A curvature determination module, configured to fit a curve function of each edge using at least a portion of edge pixels of each edge, and determine the curvature of each edge according to the curve function of each edge; A reference edge determination module, used to determine whether the curvature of any edge is less than a set threshold value, to take the edge as the reference edge, or to calculate the straight line function corresponding to the edge, and determine the edge expressed by the straight line function as the reference edge; A stretching ratio determination module, used to determine the stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge according to the opposite edge and the corresponding reference edge respectively; The image stretching module is used to stretch the position of each pixel point based on the determined stretching ratio of each pixel point in the same row or column direction perpendicular to the corresponding reference edge to obtain a text image corrected into a quadrilateral.
9. A text recognition enhancement device, characterized in that: It comprises at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described in any one of claims 1-7.
10. A computer storage medium, characterized in that: The computer storage medium stores a computer program, and the computer program is used to enable a computer to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image text correction method and device, equipment and storage medium
CN113449724A
Text correction method, electronic equipment and storage medium
CN116229478A
Inclination correction device for document image
JP2014230119A
