Tilted text correction method and device, terminal equipment and readable storage medium
By determining and filtering out the target strokes within the stroke height range of handwritten text for tilt correction, the problem of center of gravity shift caused by user writing habits is solved, and the accuracy and efficiency of handwritten text recognition is improved.
Patent Information
- Application Number
- CN202410068195.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-16
- Publication Date
- 2025-07-18
AI Technical Summary
In the prior art, in handwritten text recognition, excessive strokes caused by user's personal writing habits affect poor correction of text tilt, especially the problem of center of gravity shift has not been effectively solved.
By determining the current text line height of the text line to be corrected, the stroke height range is cut off, irregular strokes are removed, and only the target text strokes within the height range are corrected, and the target strokes are used for tilt correction.
It improves the effect of text tilt correction, prevents excessively long strokes from affecting correction, and improves the accuracy and efficiency of correction.
Smart Images

Figure CN120340035A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and particularly to a method, apparatus, terminal device and readable storage medium for correcting oblique text. Background Art
[0002] In the process of handwritten text recognition, the correction of the inclination of the handwritten text trajectory is a very important part, which directly affects the accuracy of text recognition. The correction of the inclination of the handwritten text trajectory not only needs to consider different writing scenarios, but also takes into account the overall operation efficiency of the algorithm.
[0003] In the prior art, when correcting oblique text, due to different personal writing habits of users, for example, some strokes are too long, resulting in a change in the center of gravity of the text. And the change in the center of gravity of the text will cause that in the process of correcting the text inclination, it is easy to be affected by the user's writing habits and the correction effect is not good. Therefore, it is necessary to improve the correction effect of text inclination. Summary of the Invention
[0004] This application provides a method for correcting oblique text. By screening out some irregular strokes, it is not necessary to refer to irregular strokes during correction, avoiding the influence of irregular strokes on the correction of oblique text.
[0005] In a first aspect, this application provides a method for correcting oblique text, the method includes:
[0006] Obtain the text line to be corrected;
[0007] Determine the current text line height of the text line to be corrected;
[0008] Based on the current text line height, determine the stroke truncation height range;
[0009] Determine the text strokes within the stroke truncation height range of the text line to be corrected as target text strokes;
[0010] Perform oblique correction according to the target text strokes to obtain the text line after oblique correction.
[0011] In some embodiments of this application, the determining the current text line height of the text line to be corrected includes:
[0012] Perform trajectory point sampling on the strokes of each character in the text line to be corrected to obtain a plurality of sampled trajectory points;
[0013] Determine the current text line height of the text line to be corrected according to each of the sampled trajectory points.
[0014] In some embodiments of this application, the determining the current text line height of the text line to be corrected according to each of the sampled trajectory points includes:
[0015] Determine the distance between adjacent sampling trajectory points among the respective sampling trajectory points;
[0016] If there are target adjacent sampling trajectory points where the distance is less than a preset distance threshold, integrate the target adjacent sampling trajectory points into sampling trajectory points to obtain the sampling trajectory points after completion of filtering;
[0017] Determine the current text line height of the text line to be corrected according to the sampling trajectory points after completion of filtering.
[0018] In some embodiments of the present application, the determining that the text strokes within the stroke truncation height range of the text line to be corrected are target text strokes includes:
[0019] Determine the ordinate of each of the sampling trajectory points;
[0020] According to the ordinate of each of the sampling trajectory points, determine the target sampling trajectory points within the stroke truncation height range;
[0021] Determine that the text strokes corresponding to the target sampling trajectory points are the target text strokes.
[0022] In some embodiments of the present application, the performing skew correction according to the target text strokes to obtain the text line after skew correction includes:
[0023] Determine the abscissa of each of the target sampling trajectory points corresponding to the target text strokes;
[0024] Determine that the target sampling trajectory points with the same abscissa are a sequence of trajectory points to obtain a plurality of sequences of trajectory points;
[0025] Taking any one sequence of trajectory points as the target sequence of trajectory points, if there is a target sequence of trajectory points in which the ordinate value of one target sequence of trajectory points is greater than the ordinate value of any one sequence of trajectory points in the adjacent sequence of trajectory points of the target sequence of trajectory points, then obtain the target sequence of trajectory points;
[0026] Perform skew correction on the text line to be corrected according to the target sequence of trajectory points to obtain the text line after skew correction.
[0027] In some embodiments of the present application, the performing skew correction on the text line to be corrected according to the target sequence of trajectory points includes:
[0028] Determine the offset value corresponding to each of the target sequences of trajectory points;
[0029] Perform skew correction on the text line to be corrected according to the offset value corresponding to each of the target sequences of trajectory points.
[0030] In some embodiments of the present application, determining the offset values corresponding to each of the target trajectory point sequences includes:
[0031] Performing fitting based on the abscissas of each of the target trajectory point sequences to obtain the fitting values of each of the trajectory point sequences;
[0032] Determining the differences between the fitting values of each of the trajectory point sequences and the mid-ordinate values of the ordinates sampled by each of the trajectory points to obtain the differences corresponding to each of the trajectory point sequences, and the differences corresponding to each of the trajectory point sequences are the offset values corresponding to each of the target trajectory point sequences.
[0033] In a second aspect, the present application further provides an inclined text correction device, and the device includes:
[0034] An acquisition module, configured to acquire a text line to be corrected;
[0035] A first determination module, configured to determine the current text line height of the text line to be corrected;
[0036] A second determination module, configured to determine a stroke truncation height range based on the current text line height;
[0037] A third determination module, configured to determine the text strokes within the stroke truncation height range of the text line to be corrected as target text strokes;
[0038] A correction module, configured to perform inclined correction based on the target text strokes to obtain an inclined-corrected text line.
[0039] In some embodiments of the present application, the first determination module is specifically configured to:
[0040] Performing trajectory point sampling on the strokes of each character in the text line to be corrected to obtain a plurality of sampled trajectory points;
[0041] Determining the current text line height of the text line to be corrected according to each of the sampled trajectory points.
[0042] In some embodiments of the present application, the first determination module is further specifically configured to:
[0043] Determining the distances between adjacent sampled trajectory points among each of the sampled trajectory points;
[0044] If there are target adjacent sampled trajectory points with the distances less than a preset distance threshold, integrating the target adjacent sampled trajectory points into sampled trajectory points to obtain the sampled trajectory points after filtering is completed;
[0045] Determining the current text line height of the text line to be corrected according to the sampled trajectory points after filtering is completed.
[0046] In some embodiments of the present application, the third determination module is specifically configured to:
[0047] Determine the ordinate of each of the sampled trajectory points;
[0048] According to the ordinates of each of the sampled trajectory points, determine the target sampled trajectory points within the stroke truncation height range;
[0049] Determine that the text stroke corresponding to the target sampled trajectory point is the target text stroke.
[0050] In some embodiments of the present application, the correction module is specifically configured to:
[0051] Determine the abscissa of each of the target sampled trajectory points corresponding to the target text stroke;
[0052] Determine that the target sampled trajectory points with the same abscissa are a sequence of trajectory points to obtain multiple sequences of trajectory points;
[0053] Taking any one of the sequences of trajectory points as the target sequence of trajectory points, if there is a target sequence of trajectory points in the target sequence of trajectory points whose ordinate value is greater than the ordinate value of any one of the sequence of trajectory points in the adjacent sequence of trajectory points of the target sequence of trajectory points, then obtain the target sequence of trajectory points;
[0054] According to the target sequence of trajectory points, perform skew correction on the text line to be corrected to obtain a text line after skew correction.
[0055] In some embodiments of the present application, the correction module is specifically further configured to:
[0056] Determine the offset value corresponding to each of the target sequences of trajectory points;
[0057] According to the offset value corresponding to each of the target sequences of trajectory points, perform skew correction on the text line to be corrected.
[0058] In some embodiments of the present application, the correction module is specifically further configured to:
[0059] Perform fitting according to the abscissas of each of the target sequences of trajectory points to obtain the fitting value of each of the sequences of trajectory points;
[0060] Determine the difference between the fitting value of each of the sequences of trajectory points and the midpoint ordinate value of the ordinate of each of the trajectory point samplings to obtain the difference corresponding to each of the sequences of trajectory points, and the difference corresponding to each of the sequences of trajectory points is the offset value corresponding to each of the target sequences of trajectory points.
[0061] In a third aspect, the present application further provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the steps in any one of the above-mentioned inclined text correction methods.
[0062] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored. The computer program is executed by a processor to implement the steps in any one of the above-mentioned inclined text correction methods.
[0063] For the inclined text correction method provided by the present application, by determining the current text line height of the text line to be corrected, it is possible to determine, based on the current text line height of the text line to be corrected, the text strokes within the height threshold range of the text line to be corrected as the target text strokes. This solution can, when some users write some strokes irregularly, crop or filter the strokes with overly long writing strokes to obtain the target text strokes, preventing the overly long writing strokes from affecting the correction of text inclination and resulting in poor correction effects. In other words, when the present application performs text inclination correction after cropping or filtering the overly long writing strokes, the correction effect can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] To more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the accompanying drawings required for the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those skilled in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0065] Figure 1 is a schematic diagram of the scenario of the inclined text correction system provided in the embodiment of the present application;
[0066] Figure 2 is a schematic flowchart of an embodiment of the inclined text correction method in the embodiment of the present application;
[0067] Figure 3 is a schematic diagram of a functional module of the inclined text correction device in the embodiment of the present application;
[0068] Figure 4 is a schematic diagram of the structure of the terminal device in the embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0069] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0070] In the description of the present application, it should be understood that the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the present application, "a plurality of" means two or more, unless otherwise specifically defined.
[0071] In the present application, the term "exemplary" is used to mean "serving as an example, illustration, or explanation". Any embodiment described as "exemplary" in the present application is not necessarily to be construed as more preferred or more advantageous than other embodiments. At the same time, it can be understood that in the specific implementation manners of the present application, when it comes to relevant data such as user information and user data, when the above embodiments of the present application are applied to specific products or technologies, user permission or consent needs to be obtained, and the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of the relevant countries and regions.
[0072] In order for any person skilled in the art to implement and use the present application, the following description is given. In the following description, details are set forth for the purpose of explanation. It should be understood that those of ordinary skill in the art can recognize that the present application can be implemented without using these specific details. In other instances, well-known structures and processes are not elaborated in detail to avoid obscuring the description of the present application with unnecessary details. Therefore, the present application is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed in the present application.
[0073] First, more and more devices support the function of writing text. When a user uses the text writing function on a device, the text line may be inclined. When there is an inclined text line, the device will correct the inclined text line. In the prior art, the commonly used text correction methods include: methods mainly based on deep learning, such as manually collecting and annotating a large number of handwritten inclined texts at different angles, building a deep neural network for training, and using the large amount of annotated data to train an identification model for the inclination angle of the text. Or, the inclination angle of the inclined text is solved by means of linear regression: specifically, according to the stroke information of the writing, such as coordinates (x, y), stroke order, etc., appropriate coordinate points can be selected to fit the text inclination line, and the inclination angle is solved based on the inclination line and corrected. Or, correction is performed by means of projection: a certain angle range is preset, the text trajectory is continuously rotated, and the vertical direction projection value closest to the target value is solved, and then this angle is the optimal inclination angle. However, when some users write text, some vertical strokes will be written longer, which will cause the center of gravity of the text to shift. When the center of gravity of the text with longer strokes shifts, it will not be on the same horizontal line as the centers of gravity of other normal texts. At this time, when correcting the inclined text line, there will be a problem of poor correction effect. Therefore, to solve this problem, the present application provides a method, device, equipment and storage medium for correcting inclined text, which can eliminate the problem of center of gravity shift caused by overly long strokes, and the following will be described in detail respectively.
[0074] Please refer to Figure 1 , Figure 1 which is a schematic diagram of the scenario of the inclined text correction system provided by an embodiment of the present application. The inclined text correction system may include a terminal device 100 and a storage device 200, and the storage device 200 may transmit data to the terminal device 100. As Figure 1 the terminal device 100 in
[0075] can obtain the inclined text stored in the storage device 200 to execute the inclined text correction method in the present application.
[0076] In an embodiment of the present application, the terminal device 100 and the storage device 200 can communicate through any communication means, including but not limited to, mobile communication based on the 3rd Generation Partnership Project (3GPP), Long Term Evolution (LTE), Worldwide Interoperability for Microwave Access (WiMAX), or computer network communication based on the TCP / IP Protocol Suite (TCP / IP), User Datagram Protocol (UDP), etc.
[0077] It should be noted that Figure 1 The schematic diagram of the scenario of the inclined text correction system shown is only an example. The inclined text correction system and scenario described in the embodiments of the present application are for more clearly illustrating the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those of ordinary skill in the art know that with the evolution of the inclined text correction system and the emergence of new service scenarios, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.
[0078] As Figure 2 shown, Figure 2 It is a schematic flowchart of an embodiment of the inclined text correction method in the embodiments of the present application. The inclined text correction method may include the following steps 201 to 205:
[0079] 201. Obtain the text line to be corrected.
[0080] In an embodiment of the present application, determining whether the text line is inclined is not within the scope of discussion in the embodiments of the present application. Therefore, how to identify the inclination of the text line is not elaborated in the present application. When it is determined through relevant text line inclination determination techniques that the text line is inclined, the inclined text line, that is, the text line to be corrected, can be sent to the device for correcting the inclined text line to obtain the text line to be corrected, or the inclined text line can also be sent to a preset storage device for storage so that the device for correcting the inclined text line can obtain it. Specifically, the present application embodiments do not limit the manner of obtaining the text line to be corrected.
[0081] 202. Determine the current text line height of the text line to be corrected.
[0082] Normally, when users write text, such as "p", "f", "叫" and other similar characters, the vertical strokes will be written longer. Writing longer strokes will affect the correction of the tilted text line. The specific reason is that longer numerical strokes will be used as the judgment of the overall text line height, especially the beginning and end of a text line. The longer strokes will affect the calculation of the correction parameters, resulting in inaccurate correction. Therefore, in order to avoid this situation, it is necessary to remove the longer vertical strokes in the writing strokes, so that when calculating the correction parameters, it will not be affected by the longer vertical strokes. Therefore, in the embodiment of the present application, the purpose of determining the height of the text line to be corrected is this.
[0083] Specifically, in the embodiment of the present application, the current text line height of the text line to be corrected can be determined in the following manner. For example, the tilted text correction device can convert the text line to be corrected into an image, and calculate the vertical coordinate of the pixel value of each stroke in the text to be corrected. Then, according to the difference in the vertical coordinates of each pixel point, a maximum vertical coordinate difference value is determined as the current text line height.
[0084] 203. Determine a stroke interception height range based on the current text line height.
[0085] Normally, when a user writes text, the size of the text will be within a normal range. Therefore, the height of the text will also be within a normal range. If a text line is not tilted, theoretically, the height of the text line is approximately equal to the height of a normal text. Conversely, if the text line is in a tilted state, the height of the tilted text line will be greater than the normal height of a text. At the same time, when the user is writing text, the degree of tilt is usually not very large. The specific reason is that if the tilt is large, the user will find that the text line he wrote is tilted during the writing process, and will adjust it by himself. Therefore, if the height of the text line to be corrected is too high, it represents a situation that the user did not find that his writing was tilted, but the longer vertical strokes caused the text line to be too high. Therefore, in the embodiment of the present application, if the current text line to be corrected is too high, it means that a longer vertical stroke has appeared, and the height of the text line needs to be reduced. Therefore, in the embodiment of the present application, the excessively high text line can be reduced to a height range of a regular text tilt. For example, if the conventional tilted text is half a centimeter, the strokes of the text line to be corrected that is too high can be clipped, including determining the height midpoint of the entire text line to be corrected, and obtaining a half-centimeter height range based on the height midpoint. Of course, there are other ways to determine the stroke clipping height range of the text line to be corrected, which is not limited by the specific embodiments of the present application.
[0086] 204. Determine text strokes within a stroke interception height range of the text line to be corrected as target text strokes.
[0087] After determining the stroke truncation height range, the strokes within the stroke truncation height range can be used for subsequent skew correction calculations. It should be noted that in the embodiments of the present application, the purpose of determining the text strokes within the stroke truncation height range as the target text strokes is not to delete the strokes exceeding the stroke truncation height range, but to ignore the partial strokes exceeding the stroke truncation height range, so that in the subsequent calculation process of correction, the partial strokes exceeding the stroke truncation height range are not referred to. For example, assume that a vertical stroke A is not entirely included within the stroke truncation height range, with a part of the vertical stroke A within the stroke truncation height range and another part outside the stroke truncation height range. In this case, only the vertical part outside the stroke truncation height range needs to be ignored. Among them, in the embodiments of the present application, an ignore mark can be made for the ignored part of the strokes, so that in the subsequent correction calculation process, when calculating the correction parameters in combination with each stroke, if an ignore mark exists for the obtained relevant pixel point positions, that pixel point is not referred to.
[0088] 205. Perform skew correction on the target text strokes to obtain a text line after skew correction.
[0089] According to the actual situation, when users write text, they usually write from left to right. And based on the collected skewed text, the general skew direction of the text lines written by users is upper right or lower right. In other words, the more to the left a text line is, the less likely it is to be skewed. Furthermore, in the embodiments of the present application, after determining the target text strokes, the target strokes belonging to the first character in the target text strokes can be referred to, and then the midpoint of the first character can be obtained based on the target strokes of the first character. Specifically, the vertical coordinates of each pixel point in the target strokes of the first character can be determined, and then the median value can be obtained based on the vertical coordinates of each pixel point in the target strokes of the first character. At this time, the midpoint coordinates of the first character can be obtained. By analogy, the midpoint vertical coordinates of each character other than the first character in the text line to be corrected can be obtained, and then the difference is calculated between the midpoint vertical coordinates of other characters and the midpoint vertical coordinates of the first character. At this time, if the midpoint vertical coordinate of a character is higher than that of the first character, the entire character is translated downward until the midpoint vertical coordinate of the translated character is the same as that of the first character, and thus the skew correction of each character can be completed.
[0090] The inclined text correction method provided by this application determines the current text line height of the text line to be corrected. Thus, according to the current text line height of the text line to be corrected, the text strokes within the height threshold range of the text line to be corrected can be determined as the target text strokes. This solution can, when some users write some strokes irregularly, crop or filter the strokes with overly long writing strokes to obtain the target text strokes, preventing the overly long writing strokes from affecting the correction of text inclination and resulting in poor correction effects. In other words, when this application performs text inclination correction after cropping or filtering the overly long writing strokes, the correction effect can be improved.
[0091] In order to better implement the embodiments of this application, in one embodiment of this application, determining the current text line height of the text line to be corrected includes:
[0092] Performing trajectory point sampling on the strokes of each character in the text line to be corrected to obtain a plurality of sampled trajectory points; determining the current text line height of the text line to be corrected according to the sampled trajectory points.
[0093] In the above embodiment, the method for determining the current text line height provides a solution for determining based on the vertical coordinates of the pixel points of each stroke. However, the number of pixel points on each stroke is too large, and the computational load is large when calculating the difference in the vertical coordinates of the pixel points. Therefore, in order to reduce the computational burden, in the embodiments of this application, the pixel points corresponding to each character stroke can be sampled to obtain the sampled trajectory points of each stroke. Then, calculate the difference in the vertical coordinates of the sampled trajectory points, and select the largest difference in the vertical coordinates of a sampled trajectory point as the current text line height.
[0094] Among them, in the embodiments of this application, when performing trajectory point sampling on each character stroke, sampling can be performed according to a preset sampling frequency. For example: using a sampling frequency of 200HZ to sample the pixel points of each stroke in the text to be corrected to obtain a plurality of sampled trajectory points.
[0095] In order to better implement the embodiments of this application, in one embodiment of this application, determining the current text line height of the text line to be corrected according to the sampled trajectory points includes:
[0096] Determining the distance between adjacent sampled trajectory points among the sampled trajectory points; if there are target adjacent sampled trajectory points with a distance less than a preset distance threshold, integrating the target adjacent sampled trajectory points into sampled trajectory points to obtain the sampled trajectory points after completion of filtering; determining the current text line height of the text line to be corrected according to the sampled trajectory points after completion of filtering.
[0097] However, in actual situations, there are intersecting parts in the strokes. When sampling at a certain sampling frequency, the sampling points are too close to each other at the intersecting parts of the strokes. Therefore, in order to further reduce the computational burden, the too-close sampling points can be filtered, some of the relatively close sampling points can be deleted, and only one sampling point needs to be retained. For example: the sampling trajectory points of all strokes of this line of text are [(x1,y1),(x2,y2),...(x n ,y n )]. When the distance between two points is less than a certain threshold (such as 2 pixel distances), they are regarded as similar points, and only one trajectory point needs to be retained at this position. After that, the filtered sampling trajectory points can be obtained. Next, according to the above method of calculating coordinates, the current text line height of the text line to be corrected can be determined. The specific details will not be elaborated here.
[0098] In order to better implement the embodiments of the present application, in one embodiment of the present application, determining the text strokes within the stroke intercept height range of the text line to be corrected as the target text strokes includes:
[0099] Determining the vertical coordinates of each sampling trajectory point; according to the vertical coordinates of each sampling trajectory point, determining the target sampling trajectory points within the stroke intercept height range; determining the text strokes corresponding to the target sampling trajectory points as the target text strokes.
[0100] The above embodiments provide a solution for determining the stroke intercept height range according to the vertical coordinates of pixel points, and the text strokes within the stroke intercept height range as the target text strokes. Since it can be obtained from the description of the above embodiments that the computational burden according to pixel points is relatively heavy. Therefore, when determining the target text strokes, they can be determined according to the sampling trajectory points. Specifically, according to the vertical coordinates of the sampling trajectory points, the stroke intercept height range of the text line to be corrected can be determined. The specific determination method is the same as the above embodiment of determining the stroke intercept height range according to the vertical coordinates of pixel points. The specific details will not be elaborated here. After that, when the stroke intercept height range is obtained according to the sampling trajectory points, the text strokes within the stroke intercept height range can be used as the target text strokes.
[0101] Among them, obtaining the y coordinate information Y = [y1,y2,,...,y of all filtered sampling trajectory points n, respectively obtain the y - values corresponding to the quantile percentages of 20%, 50%, and 80%, i.e., y_down = y_20, y_medium = y_50, y_up = y_80. Among them, y_medium is used as the reference baseline height of this line of text, and y_corpus_h = y_up - y_down is used as the main character stroke height of this line of text. The values of y_up and y_down can be adjusted according to the actual situation. After that, for the trajectory points whose y - coordinates are not within the range of [y_50 - y_corpus_h, y_50 + y_corpus_h], just filter them out.
[0102] To better implement the embodiments of the present application, in one embodiment of the present application, according to the strokes of the target text, tilt correction is performed to obtain the text line after tilt correction, including:
[0103] Determine the abscissas of each target sampling trajectory point corresponding to the strokes of the target text; determine the target sampling trajectory points with the same abscissa as a trajectory point sequence to obtain multiple trajectory point sequences; take any one of the trajectory point sequences as the target trajectory point sequence. If there is a target trajectory point sequence in which the ordinate value of a target trajectory point sequence is greater than the ordinate value of any sequence trajectory point in the adjacent trajectory point sequence of the target trajectory point sequence, then obtain the target trajectory point sequence; according to the target trajectory point sequence, perform tilt correction on the text line to be corrected to obtain the text line after tilt correction.
[0104] The above - mentioned embodiment provides a solution for determining the correction of the mid - point of each character in the text line to be corrected compared with the mid - point of the first character according to the ordinates of the strokes of each character. However, in the above - mentioned solution, character recognition needs to be performed to determine the target strokes corresponding to each character. Therefore, in the embodiments of the present application, the target sampling trajectory points with the same abscissa among the target sampling trajectory points corresponding to each target text stroke are used as a trajectory point sequence. Among them, when there is a value of the ordinate in a target trajectory point sequence that is greater than the ordinates of any other trajectory point sequence, the target trajectory points in this target trajectory point sequence are used as the trajectory points for calculating the correction parameters in the follow - up. For example: except for the first and last column sequences, compare whether the value of col(x i ) satisfies col(x i )>col(x i-1 ) and col(x i )>col(x i+1) If this condition is met, this point is added as a candidate point to the set set_1 of trajectory points to be fitted. Among them, the reason for selecting a target trajectory point sequence with the vertical coordinate value of one vertical coordinate greater than that of any other trajectory point sequence is that for a line of text, what can reflect the inclination of the overall trajectory stroke is often several strokes of each character. At the same time, reducing redundant data can improve the calculation efficiency.
[0105] After obtaining the target trajectory point sequence for tilt correction calculation, since for a line of text, what can reflect the inclination of the overall trajectory stroke is often several strokes of each character, and the target trajectory points represent the specific target strokes that can better reflect the overall inclination. Therefore, it is possible to determine the offset of each trajectory point in the target trajectory point sequence relative to the first character in the text line to be corrected. For example: Calculate the vertical coordinate distance of each trajectory point in the target trajectory point sequence relative to the midpoint of the first character, so as to calculate an average vertical coordinate distance. Then, regard this average vertical coordinate distance as a translation parameter, and translate the text involved in each target trajectory point sequence upward or downward according to this average vertical coordinate distance. For example: If this average vertical coordinate distance is positive, translate the average vertical coordinate value downward; conversely, if this average vertical coordinate distance is negative, translate the average vertical coordinate value upward. Although this correction method does not correct all the characters in the text line to be corrected, only processes the characters with a large offset degree, the final actual visual effect has a very small difference from the visual effect of adjusting all the characters. Among them, the implementation method of determining the midpoint of the first character is the same as the method of determining the midpoint of the first character in the above embodiment, and will not be elaborated here specifically.
[0106] To better implement the embodiments of the present application, in one embodiment of the present application, tilt correction of the text line to be corrected according to the target trajectory point sequence includes:
[0107] Determine the offset values corresponding to each target trajectory point sequence; perform tilt correction on the text line to be corrected according to the offset values corresponding to each target trajectory point sequence.
[0108] In the above embodiment, an implementation method is provided in which the average difference between the vertical coordinates of each trajectory point in the target trajectory point sequence and the vertical coordinate of the midpoint of the first character is used as the translation value. However, the embodiments of the present application also provide a method for determining the offset value and an implementation method for performing tilt correction on the text line to be corrected.
[0109] Specifically, after obtaining the target trajectory point sequence for skew correction calculation, the ordinate of the midpoint in the target trajectory point sequence can be determined. Then, the average difference of the ordinate of the midpoint of the trajectory point sequence with the smallest abscissa is calculated, and this average difference can be determined as the offset value. After that, for this offset value, the text line to be corrected can be corrected. For example, when the offset value is positive, it is offset downward according to this offset value; if the offset value is negative, it is offset upward according to this offset value. The advantage of this method is that there is no need to perform character recognition on the text line to be corrected to identify the first character, and thus there is no need to calculate the ordinate of the midpoint of the first character either.
[0110] To better implement the embodiments of the present application, in one embodiment of the present application, determining the offset value corresponding to each target trajectory point sequence includes:
[0111] Fitting according to the abscissas of each target trajectory point sequence to obtain the fitting values of each trajectory point sequence; determining the difference between the fitting value of each trajectory point sequence and the ordinate value of the midpoint of the ordinate of each trajectory point sampling to obtain the difference corresponding to each trajectory point sequence, and the difference corresponding to each trajectory point sequence is the offset value corresponding to each target trajectory point sequence.
[0112] The above embodiment provides a solution for calculating the average difference between the ordinate of each trajectory point in the target trajectory point sequence and the ordinate of the midpoint of the trajectory point sequence with the smallest abscissa as the offset value. However, the embodiments of the present application also provide a method for calculating the offset value. Specifically, the least squares method can be used to fit the target trajectory point sequence, and the fitting function can adopt a linear function (y = ax + b) or a quadratic function (y = ax 2 + bx + c) to obtain the parameters of the fitting function. It should be noted that the coefficients a, b, and c of the fitting function in the embodiments of the present application can be determined according to the actual situation, and the embodiments of the present application do not make any limitations. Based on this, since the abscissas of each trajectory point in the target trajectory point sequence are the same, the abscissas of all trajectory points in each target trajectory point sequence can be brought in to obtain the corresponding fitted y coordinate value y_curved_list. Then, the difference y_diff = y_curved_list - y_medium between y_curved_list and the ordinate value of the midpoint of the ordinate of each trajectory point sampling can be calculated, so as to obtain the offset value corresponding to each target sequence trajectory point. Furthermore, when y_diff < 0, the y coordinate value of the corresponding column is translated downward. When y_diff > 0, the y coordinate value of the corresponding column is translated upward. The translated trajectory point sequence is the required trajectory sequence after correction, and the correction operation can be completed.
[0113] To better implement the inclined text correction method in the embodiments of the present application, on top of the inclined text correction method, the embodiments of the present application also provide an inclined text correction device, as Figure 3 shown. The device 300 includes:
[0114] An acquisition module 301, configured to acquire a text line to be corrected;
[0115] A first determination module 302, configured to determine the current text line height of the text line to be corrected;
[0116] A second determination module 303, configured to determine a stroke intercept height range based on the current text line height;
[0117] A third determination module 304, configured to determine that the text strokes of the text line to be corrected within the stroke intercept height range are target text strokes;
[0118] A correction module 305, configured to perform inclined correction according to the target text strokes to obtain an inclined-corrected text line.
[0119] For the inclined text correction device provided by the present application, after the acquisition module 301 acquires the text line to be corrected, the first determination module 302 determines the current text line height of the text line to be corrected, so that according to the current text line height of the text line to be corrected, the second determination module 303 further determines that the text strokes of the text line to be corrected within the height threshold range are target text strokes. This solution can, when some users write some strokes irregularly, crop or filter the strokes with too long writing strokes through the third determination module 304 to obtain the target text strokes, and finally perform the correction of the inclined text through the correction module 305, preventing the problem that the too long writing strokes affect the correction of the text inclination and resulting in poor correction effect. In other words, when the present application performs text inclination correction after cropping or filtering the too long writing strokes, the correction effect can be improved.
[0120] In some embodiments of the present application, the first determination module 302 is specifically configured to:
[0121] Perform trajectory point sampling on the strokes of each character in the text line to be corrected to obtain a plurality of sampled trajectory points;
[0122] Determine the current text line height of the text line to be corrected according to the sampled trajectory points.
[0123] In some embodiments of the present application, the first determination module 302 is further specifically configured to:
[0124] Determine the distance between adjacent sampled trajectory points among the sampled trajectory points;
[0125] If there are target adjacent sampled trajectory points with a distance less than a preset distance threshold, integrate the target adjacent sampled trajectory points into sampled trajectory points to obtain the sampled trajectory points after filtering is completed;
[0126] According to the sampled trajectory points after filtering is completed, determine the current text line height of the text line to be corrected.
[0127] In some embodiments of the present application, the third determination module 304 is specifically configured to:
[0128] Determine the vertical coordinates of each sampled trajectory point;
[0129] According to the vertical coordinates of each sampled trajectory point, determine the target sampled trajectory points within the stroke truncation height range;
[0130] Determine that the text stroke corresponding to the target sampled trajectory point is the target text stroke.
[0131] In some embodiments of the present application, the correction module 305 is specifically configured to:
[0132] Determine the horizontal coordinates of each target sampled trajectory point corresponding to the target text stroke;
[0133] Determine that the target sampled trajectory points with the same horizontal coordinate are a sequence of trajectory points to obtain multiple sequences of trajectory points;
[0134] Taking any one sequence of trajectory points as the target sequence of trajectory points, if there is a vertical coordinate value of a target sequence of trajectory points in the target sequence of trajectory points that is greater than the vertical coordinate value of any one sequence of trajectory points in the adjacent sequence of trajectory points of the target sequence of trajectory points, then obtain the target sequence of trajectory points;
[0135] According to the target sequence of trajectory points, perform skew correction on the text line to be corrected to obtain the text line after skew correction.
[0136] In some embodiments of the present application, the correction module 305 is specifically further configured to:
[0137] Determine the offset value corresponding to each target sequence of trajectory points;
[0138] According to the offset value corresponding to each target sequence of trajectory points, perform skew correction on the text line to be corrected.
[0139] In some embodiments of the present application, the correction module 305 is specifically further configured to:
[0140] Perform fitting according to the horizontal coordinates of each target sequence of trajectory points to obtain the fitting value of each sequence of trajectory points;
[0141] Determine the difference between the fitting value of each trajectory point sequence and the mid-ordinate value of the ordinate of each trajectory point sample, to obtain the difference corresponding to each trajectory point sequence, and the difference corresponding to each trajectory point sequence is the offset value corresponding to each target trajectory point sequence.
[0142] The embodiment of the present application also provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the steps in any one of the skew text correction methods in the embodiments of the present application. Among them, this terminal device integrates any one of the skew text correction methods provided by the embodiments of the present application. As Figure 4 shown, it shows a schematic structural diagram of the terminal device involved in the embodiment of the present application. Specifically:
[0143] This terminal device may include a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, an input unit 404, and other components. Those skilled in the art can understand that Figure 4 the structure of the terminal device shown in does not constitute a limitation on the terminal device, and it may include more or fewer components than shown, or combine certain components, or have different component arrangements. Among them:
[0144] The processor 401 is the control center of this terminal device, connecting various parts of the entire terminal device through various interfaces and lines. By running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, it executes various functions of the terminal device and processes data, thereby monitoring the terminal device as a whole. Optionally, the processor 401 may include one or more processing cores; the processor 401 may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or the processor may also be any conventional processor, etc. Preferably, the processor 401 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 401.
[0145] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the terminal device. In addition, the memory 402 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices. Correspondingly, the memory 402 can also include a memory controller to provide the processor 401 with access to the memory 402.
[0146] The terminal device further includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to implement functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, a recharge system, a power failure detection circuit, a power converter or inverter, and a power status indicator.
[0147] The terminal device may further include an input unit 404, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.
[0148] Although not shown, the terminal device may further include a display unit, etc., which will not be elaborated here. Specifically, in this embodiment, the processor 401 in the terminal device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402 to implement various functions, such as:
[0149] Obtain the text line to be corrected;
[0150] Determine the current text line height of the text line to be corrected;
[0151] Based on the current text line height, determine the stroke truncation height range;
[0152] Determine the text strokes of the text line to be corrected within the stroke truncation height range as the target text strokes;
[0153] Perform skew correction according to the target text strokes to obtain the text line after skew correction.
[0154] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by controlling relevant hardware through instructions. The instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0155] For this reason, an embodiment of the present application provides a computer-readable storage medium, which may include: read-only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), a magnetic disk or an optical disc, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any one of the skew text correction methods provided by the embodiments of the present application. For example, when the computer program is loaded by the processor, the following steps can be executed:
[0156] Obtain the text line to be corrected;
[0157] Determine the current text line height of the text line to be corrected;
[0158] Based on the current text line height, determine the stroke truncation height range;
[0159] Determine that the text strokes of the text line to be corrected within the stroke truncation height range are target text strokes;
[0160] Perform skew correction according to the target text strokes to obtain a text line after skew correction.
[0161] In the above embodiments, the descriptions of the respective embodiments have their own emphases. For parts not detailed in a certain embodiment, reference can be made to the detailed descriptions of other embodiments above, and details will not be repeated here.
[0162] In specific implementation, the above-mentioned various units or structures can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above-mentioned various units or structures can refer to the method embodiments above, and details will not be repeated here.
[0163] The specific implementation of each of the above operations can refer to the foregoing embodiments, and details will not be repeated here.
[0164] The above has introduced in detail a skew text correction method and device provided by an embodiment of the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present application.
Claims
1. An inclined text correction method, characterized in that The method includes: Obtaining a text line to be corrected; Determining the current text line height of the text line to be corrected; Based on the current text line height, determining a stroke truncation height range; Determining the text strokes of the text line to be corrected within the stroke truncation height range as target text strokes; Performing skew correction according to the target text strokes to obtain a text line after skew correction.
2. The inclined text correction method according to claim 1, wherein The determining the current text line height of the text line to be corrected includes: Performing trajectory point sampling on the strokes of each character in the text line to be corrected to obtain a plurality of sampled trajectory points; Determining the current text line height of the text line to be corrected according to each of the sampled trajectory points.
3. The inclined text correction method according to claim 2, characterized in that The determining the current text line height of the text line to be corrected according to each of the sampled trajectory points includes: Determining the distance between adjacent sampled trajectory points among each of the sampled trajectory points; If there are target adjacent sampled trajectory points with the distance less than a preset distance threshold, integrating the target adjacent sampled trajectory points into sampled trajectory points to obtain filtered sampled trajectory points; Determining the current text line height of the text line to be corrected according to the filtered sampled trajectory points.
4. The inclined text correction method according to claim 2, wherein The determining the text strokes of the text line to be corrected within the stroke truncation height range as target text strokes includes: Determining the ordinate of each of the sampled trajectory points; Determining target sampled trajectory points within the stroke truncation height range according to the ordinates of each of the sampled trajectory points; Determining the text strokes corresponding to the target sampled trajectory points as the target text strokes.
5. The skew text correction method according to claim 4, wherein The performing skew correction according to the target text strokes to obtain a text line after skew correction includes: Determining the abscissa of each of the target sampled trajectory points corresponding to the target text strokes; Determining the target sampled trajectory points with the same abscissa as a trajectory point sequence to obtain a plurality of trajectory point sequences; Taking any one of the trajectory point sequences as a target trajectory point sequence, if there is a target trajectory point sequence in the target trajectory point sequence whose ordinate value is greater than the ordinate value of any one of the sequence trajectory points in the adjacent trajectory point sequence of the target trajectory point sequence, then obtaining the target trajectory point sequence; Performing skew correction on the text line to be corrected according to the target trajectory point sequence to obtain a text line after skew correction.
6. The inclined text correction method according to claim 5, wherein The performing skew correction on the text line to be corrected according to the target trajectory point sequence includes: Determining the offset value corresponding to each of the target trajectory point sequences; Performing skew correction on the text line to be corrected according to the offset value corresponding to each of the target trajectory point sequences.
7. The inclined text correction method according to claim 6, wherein The determining the offset value corresponding to each of the target trajectory point sequences includes: Performing fitting according to the abscissa of each of the target trajectory point sequences to obtain the fitting value of each of the trajectory point sequences; Determining the difference between the fitting value of each of the trajectory point sequences and the mid-ordinate value of the ordinates of each of the trajectory point samplings to obtain the difference corresponding to each of the trajectory point sequences, and the difference corresponding to each of the trajectory point sequences is the offset value corresponding to each of the target trajectory point sequences.
8. An inclined text correction device, characterized in that, The apparatus includes: An obtaining module, configured to obtain a text line to be corrected; The first determination module is configured to determine the current text line height of the text line to be corrected; The second determination module is configured to determine a stroke truncation height range based on the current text line height; The third determination module is configured to determine the text strokes within the stroke truncation height range of the text line to be corrected as target text strokes; The correction module is configured to perform skew correction according to the target text strokes to obtain a text line after skew correction.
9. A terminal device, characterized in that, The terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the steps in the skew text correction method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and the computer program is executed by the processor to implement the steps in the skew text correction method according to any one of claims 1 to 7.