A text correction method, computer readable storage medium
By acquiring the character edge regions and gradient angle images of text images, performing histogram statistics and smoothing, calculating sub-pixel maxima, and correcting the rotation and tilt of the text images, the problem of missegmentation and misrecognition caused by rotation and tilt in character recognition is solved, thus improving the accuracy of character recognition.
Patent Information
- Application Number
- CN202310995486.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-08
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2043-08-08
AI Technical Summary
Existing character recognition methods are prone to missegmentation and misrecognition of characters when faced with interference from background patterns, font rotation and tilt during printing, etc., which affects the accuracy of character recognition.
By acquiring the character edge regions and gradient amplitude images of the text image, histogram statistics and smoothing are performed, sub-pixel maxima are calculated, and rotation and tilt correction of the text image are carried out.
It effectively reduces the occurrence of character missegmentation and misrecognition caused by font rotation and tilt during printing, and improves the accuracy of character recognition.
Smart Images

Figure CN117237960B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, and particularly relates to a text correction method and a computer readable storage medium. BACKGROUND
[0002] In recent years, visual recognition is applied more and more widely in various industries, and character recognition is one of important scenes. Generally, a character recognition method usually has two stages of character segmentation and character recognition. However, in actual application scenes, there are factors such as background pattern interference, rotation and inclination of font printing, and the general character recognition method often has the problems of character mis-segmentation and mis-recognition when facing the above scenes. Therefore, it is necessary to process the text image for character recognition to improve the accuracy of subsequent character recognition. SUMMARY
[0003] The technical problem solved by the present application is to improve the accuracy of character recognition of a text image.
[0004] According to a first aspect, in an embodiment, a text correction method is provided, comprising:
[0005] obtaining a text image;
[0006] calculating a character block preliminary detection image and a background estimation image according to the text image, and calculating a character block detection image based on image difference according to the character block preliminary detection image and the background estimation image;
[0007] obtaining an initial estimation value of a rotation angle of the text image, and determining a second angle range based on the initial estimation value of the rotation angle;
[0008] forming a target function curve according to a gray scale projection result of a plurality of rotation angle values in the second angle range to obtain a second target function curve; wherein the gray scale projection process of each rotation angle value includes: generating a sampling point array according to the rotation angle value to sample the character block detection image to obtain the gray scale projection result;
[0009] calculating an angle value corresponding to a sub-pixel maximum value point of the second target function curve as an accurate estimation value of the rotation angle;
[0010] rotating and correcting the text image according to the accurate estimation value of the rotation angle;
[0011] taking the text image or the reduced text image as an inclination estimation image, and extracting a character edge region and a gradient amplitude angle image in the inclination estimation image;
[0012] performing histogram statistics on a region in the gradient amplitude angle image corresponding to the character edge region to obtain a gradient amplitude angle histogram, performing smoothing processing on the gradient amplitude angle histogram to obtain a gradient amplitude angle curve, and calculating a sub-pixel maximum value point of the gradient amplitude angle curve as an estimated value of the tilt angle;
[0013] performing tilt correction on the text image according to the estimated value of the tilt angle.
[0014] In one embodiment, the calculating the character block preliminary detection image and the background estimation image from the text image comprises: performing morphological processing on the text image to generate a character block from a character in the text image to obtain the character block preliminary detection image, and obtaining the background estimation image.
[0015] In one embodiment, the performing morphological processing on the text image to generate a character block from a character in the text image to obtain the character block preliminary detection image, and obtaining the background estimation image comprises:
[0016] performing first morphological processing on the text image to generate a character block from a character in the text image to obtain a character block preliminary detection image;
[0017] performing reduction on the character block preliminary detection image to obtain a reduced image;
[0018] performing second morphological processing on the reduced image to obtain the background estimation image;
[0019] the calculating the character block detection image based on image difference comprises: subtracting the background estimation image from the reduced image to obtain the character block detection image.
[0020] In one embodiment, a template width of the grayscale erosion processing is max(3.0, H c / 8.0), and a reduction ratio of the reduction on the character block preliminary detection image is 8.0 / H c , where H c is a preset character pixel height.
[0021] In one embodiment, the first morphological processing is grayscale erosion processing, and the performing second morphological processing on the reduced image to obtain the background estimation image comprises: performing median filtering on the reduced image to obtain a median filtering image, performing grayscale closing operation on the median filtering image to obtain a grayscale closing operation image, and taking the grayscale closing operation image as the background estimation image.
[0022] In one embodiment, a template size of the grayscale closing operation is
[0023] max(5.0, 0.5 x max(3.0, H c / 8.0)) x 2 | 1,
[0024] where H c is a preset character pixel height, and | represents a binary OR operation.
[0025] In one embodiment, the obtaining of the initial estimation of the rotation angle of the text image comprises:
[0026] obtaining a preset first angle range, and forming a target function curve according to gray projection results of a plurality of rotation angle values in the first angle range to obtain a first target function curve; wherein the gray projection process of each rotation angle value comprises: generating a sampling point array according to the rotation angle value to sample the character block detection image to obtain a gray projection result.
[0027] calculating an angle value corresponding to a sub-pixel maximum value point of the first target function curve as the initial estimation of the rotation angle.
[0028] In one embodiment, the plurality of rotation angle values in the first angle range are obtained in the following manner: reading angle values in the first angle range as rotation angle values at a first angle step to obtain the plurality of rotation angle values in the first angle range.
[0029] In one embodiment, the first angle step is determined by the following expression:
[0030]
[0031] where S min and S max respectively represent a lower limit value and an upper limit value of the angle of the first angle range, and round() represents a rounding operation.
[0032] In one embodiment, the plurality of rotation angle values in the second angle range are obtained in the following manner: reading angle values in the second angle range as rotation angle values at a second angle step to obtain the plurality of rotation angle values in the second angle range; wherein the second angle range is smaller than the first angle range, and the second angle step is smaller than the first angle step.
[0033] In one embodiment, the generating of the sampling point array according to the rotation angle value to sample the character block detection image to obtain a gray projection result comprises:
[0034] generating a sampling point on the text image at a first step in a projection direction corresponding to the rotation angle value and at a second step in a traversal direction orthogonal to the projection direction to obtain the sampling point array.
[0035] calculating a gray value of each sampling point;
[0036] performing gray projection on the sampling point array in a projection direction to obtain a gray projection result.
[0037] In one embodiment, the gray value of a sampling point is determined by the following expression:
[0038]
[0039] where w1, w2, w3 and w4 are sampling weight coefficients, (x, y) represents the coordinates of a sampling point, g(x, y) represents the gray value of the sampling point, and respectively represent the gray values of the pixel points with coordinates (x, y) and (x, y) respectively on the text image. and respectively represent the gray values of the pixel points with coordinates (x, y) and (x, y) respectively on the text image.
[0040] In one embodiment, the forming of a target function curve according to the gray projection results of the plurality of rotation angle values in the first angle range obtains a first target function curve, including: for each rotation angle value in the first angle range, calculating the sum of squared differences of the gray projection as the target function value thereof, and forming the first target function curve based on all the rotation angle values in the first angle range and the target function values thereof.
[0041] The forming of a target function curve according to the gray projection results of the plurality of rotation angle values in the second angle range obtains a second target function curve, including: for each rotation angle value in the second angle range, calculating the sum of squared differences of the gray projection as the target function value thereof, and forming the second target function curve based on all the rotation angle values in the second angle range and the target function values thereof.
[0042] In one embodiment, the extracting of the character edge region and the gradient amplitude angle image in the tilt estimation image includes:
[0043] performing mean filtering on the tilt estimation image to obtain a mean filtering image;
[0044] performing processing on the mean filtering image using a first edge extraction filter to obtain a first gradient image and a first gradient amplitude angle image;
[0045] performing binarization on the first gradient image using a first binarization threshold to obtain a first character edge region of the tilt estimation image, where the first character edge region is a region in the tilt estimation image corresponding to a region in the first gradient image with a gray value greater than the first binarization threshold;
[0046] processing the mean filtered image using a second edge extraction filter to obtain a second gradient image and a second gradient amplitude angle image;
[0047] binarizing the second gradient image using a second binarization threshold to obtain a second character edge region of the tilt estimation image, wherein the second character edge region is a region of the tilt estimation image corresponding to a region of the second gradient image having a gray value greater than the second binarization threshold;
[0048] obtaining an intersection of the first character edge region and the second character edge region of the tilt estimation image to obtain a final character edge region of the tilt estimation image;
[0049] using either of the first gradient amplitude angle image and the second gradient amplitude angle image as a gradient amplitude angle image of the tilt estimation image.
[0050] In an embodiment, the filter kernel size of the mean filtering is 1xN, where N is a preset filter kernel width.
[0051] In an embodiment, the first binarization threshold is 1.4xG1, and the second binarization threshold is 1.4xG2, where G1 represents a standard deviation of the first gradient image, and G2 represents a standard deviation of the second gradient image.
[0052] According to a second aspect, an embodiment provides a computer readable storage medium, having stored thereon a program, the program being capable of being executed by a processor to implement the text correction method of any of the above embodiments.
[0053] According to the text correction method in the above embodiments, the rotation angle and tilt angle of the text are estimated, and the text image is corrected based on the estimated angle. This can effectively reduce the missegmentation and misrecognition of characters caused by the rotation and tilt during font printing, and improve the accuracy of character recognition in text images. Furthermore, estimating the tilt angle after rotation correction is beneficial to obtaining a more accurate tilt angle estimate. When estimating the rotation angle, a preliminary character block detection image and a background estimation image are first obtained from the text image. The character block detection image is obtained based on image difference calculation, which makes the character block detection free from the interference of background noise and thus more accurate. Then, the rotation angle is estimated from coarse to fine. In the fine estimation process, a sampling point array is generated based on the rotation angle value to sample the character block detection image and obtain grayscale projection results. The second objective function curve is obtained based on the grayscale projection results of multiple rotation angle values within the second angle range. The angle value corresponding to the sub-pixel maximum point of the second objective function curve is calculated as the precise estimate of the rotation angle, thereby reducing the amount of computation and greatly improving the accuracy of the estimated rotation angle. When estimating the tilt angle, the text image or a scaled-down text image is used as the tilt estimation image. The character edge region and gradient amplitude image are extracted from the tilt estimation image. Histogram statistics are performed on the region corresponding to the character edge region in the gradient amplitude image to obtain the gradient amplitude histogram. The gradient amplitude curve is obtained based on the gradient amplitude histogram. The sub-pixel maxima of the gradient amplitude curve are used as the tilt angle estimate, which greatly improves the accuracy of the tilt angle. Attached Figure Description
[0054] Figure 1 A flowchart of a text correction method according to one embodiment;
[0055] Figure 2 A schematic diagram of text image rotation;
[0056] Figure 3 An illustration of text tilting;
[0057] Figure 4 This is a flowchart illustrating morphological processing of a text image to obtain a preliminary character block detection image and a background estimation image in one embodiment.
[0058] Figure 5 This is a flowchart of obtaining an initial estimate of the rotation angle of a text image in one embodiment;
[0059] Figure 6 This is a flowchart of one embodiment of generating a sampling point array based on a rotation angle value to sample a character block detection image and obtain a grayscale projection result;
[0060] Figure 7A schematic diagram illustrating the process of generating a sampling point array to sample a character block detection image and obtain grayscale projection results;
[0061] Figure 8 This is a flowchart illustrating the extraction of character edge regions and gradient amplitude images from a tilt-estimated image in one embodiment;
[0062] Figure 9 A flowchart illustrating the text line character recognition steps of one embodiment;
[0063] Figure 10 An initial structural diagram model is established for one line of text in one embodiment;
[0064] Figure 11 This is a flowchart illustrating the calculation of the distance threshold T in one embodiment;
[0065] Figure 12 To Figure 10 The subgraph model obtained after partitioning the initial structural graph model shown;
[0066] Figure 13 This is a standard structural diagram model constructed based on text structural information in one embodiment;
[0067] Figure 14 This is a flowchart illustrating the matching of isomorphic graphs of a standard structural graph model within a subgraph model, as described in one embodiment.
[0068] Figure 15 In one embodiment, with One of the connected edges cannot be connected to... The case where we find edges with the same direction among connected edges;
[0069] Figure 16 To and Connected edges and A diagram illustrating the case where connected edges are perfectly matched;
[0070] Figure 17 To and Connected edges and A diagram illustrating a situation where connected edges do not perfectly match. Detailed Implementation
[0071] The application will be described in further detail below with specific reference being made to the drawings. Like elements are referred to with like reference numerals throughout the specification. In the following description, numerous specific details are set forth in order to provide a thorough understanding of the application. However, it will be apparent to one skilled in the art that the application can be practiced without the specific details given. In other instances, well-known methods have not been described in detail in order not to unnecessarily obscure the application. Also, the use of "about" or "approximately" in connection with a recited parameter means plus or minus a tolerance range of less than 5% of the recited parameter.
[0072] In addition, features, operations, or steps described in the specification can be performed in any suitable order unless otherwise specified and any order is meant to be within the scope of the application. Also, any labelling of a particular feature, operation, or step with a given name or term does not limit the scope of the application unless otherwise specified.
[0073] The serial numbers of components in this document, such as "first", "second", etc., are only used to distinguish the described objects, and do not have any sequence or technical meaning. The "connection" and "coupling" in this application include direct and indirect connections (couplings) unless otherwise specified.
[0074] Reference is made to Figure 1 The text correction method in an embodiment of the application includes steps 100-900, which will be described in detail below.
[0075] Step 100: Obtain a text image. It can be understood that the text image contains text composed of characters, which include but are not limited to numbers, Chinese and English characters, and punctuation marks, etc.
[0076] Step 200: Calculate a character block preliminary detection image and a background estimation image according to the text image, and calculate a character block detection image based on image difference according to the character block preliminary detection image and the background estimation image.
[0077] This step mainly generates character blocks based on the characters in the text image. For example, for a character like '日' (sun), a region similar to a square ■ can be generated, thereby obtaining the character block detection image. The character block detection image can retain and highlight the approximate positions of the characters. To more accurately detect character blocks, this application uses the difference method to obtain the character block detection image. Specifically, first, some image processing methods are used to detect character blocks based on the text image, obtaining the preliminary character block detection image and the background estimation image, and then a difference operation is performed, such as subtracting the background estimation image from the preliminary character block detection image to obtain the character block detection image. Here, the background refers to the background of the character block.
[0078] Step 300: Obtain an initial estimated value of the rotation angle of the text image, and determine a second angle range based on the initial estimated value of the rotation angle.
[0079] The rotation angle of the text image refers to the angle by which the text image rotates relative to the normal state. Please refer to Figure 2 , usually, the text is horizontally arranged in the normal state, and after rotating a certain angle, it will be in the Figure 2 state shown in the right figure, and the rotated angle is the rotation angle of the text image. This application estimates the rotation angle of the text image, and after obtaining the rotation angle of the text image, rotation correction can be performed accordingly.
[0080] The initial estimated value of the rotation angle of the text image can be a value preset according to experience, or a rotation angle value estimated by using existing rotation angle estimation methods. The second angle range can be a preset-sized angle range including the initial estimated value of the rotation angle, for example, it can be a neighborhood of the preset size of the initial estimated value of the rotation angle. Since the initial estimated value of the rotation angle is already the result of a preliminary estimate, in order to further make a more accurate estimate, the second angle range can be set to be smaller. [[ID=!14]]
[0081] Step 400: Form a target function curve based on the gray-scale projection results of multiple rotation angle values within the second angle range, and obtain the second target function curve; where the gray-scale projection process for each rotation angle value includes: generating a sampling point array according to the rotation angle value to sample the character block detection image to obtain the gray-scale projection result. <!END]]
[0082] Specifically, first, multiple rotation angle values are arbitrarily selected or selected according to certain rules within the second angle range. For each rotation angle value, gray-scale projection is performed, and the target function value is calculated based on the gray-scale projection result. Based on the target function values of the selected multiple rotation angle values, a target function curve is formed, and the second target function curve is obtained. During the gray-scale projection process, the gray-scale values of the sampling points are obtained by sampling the character block detection image with the sampling point array generated according to the rotation angle value, and the gray-scale projection result is calculated using the gray-scale values of the sampling points, thus reducing the calculation amount.
[0083] In some embodiments, the objective function value represents a degree of gray difference in the orthogonal direction of the gray projection, and can be a sum of squared differences of the gray projection. In this case, a target function curve is formed according to the gray projection results of the plurality of rotation angle values in the second angle range, and a second target function curve is obtained, including: for each rotation angle value in the second angle range, calculating the sum of squared differences of the gray projection thereof as the objective function value thereof, and forming the second target function curve based on all rotation angle values in the second angle range and the objective function values thereof.
[0084] Step 500: calculating an angle value corresponding to a sub-pixel maximum value point of the second target function curve as the rotation angle accurate estimation value.
[0085] In an embodiment, the angle value corresponding to the sub-pixel maximum value point of the second target function curve can be specifically obtained by performing smoothing processing on the second target function curve and then performing interpolation to obtain the sub-pixel maximum value point of the second target function curve, and then obtaining the angle value corresponding to the sub-pixel maximum value point. The smoothing processing can be Gaussian smoothing or mean smoothing, and the interpolation can be parabolic interpolation or Lagrange interpolation.
[0086] The present application first preliminarily estimates the rotation angle to obtain a rotation angle initial estimation value, and then determines a smaller angle range according to the rotation angle initial estimation value to further make a more accurate estimation. Through this coarse-to-fine estimation, the accuracy of the rotation angle estimation is improved.
[0087] Step 600: rotating and correcting the text image according to the rotation angle accurate estimation value.
[0088] Step 700: taking the text image or the reduced text image as a tilt estimation image, and extracting a character edge region and a gradient amplitude angle image in the tilt estimation image.
[0089] The reduced text image is taken as the tilt estimation image in order to reduce the calculation amount. The reduction ratio can be set according to actual needs. In an embodiment, the reduction ratio is 40 / H c Those skilled in the art can understand that the character edge region and the gradient amplitude angle image can be extracted by various edge extraction filters, such as Roberts filter, Canny filter, etc., which will not be described here.
[0090] Step 800: performing histogram statistics on a region corresponding to the character edge region in the gradient amplitude angle image to obtain a gradient amplitude angle histogram, performing smoothing processing on the gradient amplitude angle histogram to obtain a gradient amplitude angle curve, calculating a sub-pixel maximum value point of the gradient amplitude angle curve as a tilt angle estimation value.
[0091] The maximum point here can be a sub-pixel maximum point to improve accuracy, and the sub-pixel maximum point can be obtained by interpolating the gradient amplitude angle curve after smoothing. The smoothing can be Gaussian smoothing or mean smoothing, and the interpolation can be parabolic interpolation or Lagrange interpolation.
[0092] Please refer to Figure 3 , the text presents a state similar to italic when it is inclined, which affects the correct recognition of characters. The inclination angle estimate obtained in this step is an estimate of the text inclination angle, and the inclination correction can be performed according to the obtained text inclination angle.
[0093] Step 900: performing inclination correction on the text image according to the inclination angle estimate.
[0094] The present application estimates the inclination angle after performing rotation correction, which can be understood to make the obtained inclination angle estimate more accurate.
[0095] In some embodiments, the character block preliminary detection image and the background estimate image obtained in step 200 according to the text image can be obtained by performing morphological processing on the text image to generate character blocks according to the characters in the text image to obtain the character block preliminary detection image, and obtaining the background estimate image. The morphological processing refers to gray erosion, gray dilation, gray opening / closing operation, etc. The morphological processing here can include one or more of them. Please refer to Figure 4 In one embodiment, the process of performing morphological processing on the text image to generate character blocks according to the characters in the text image to obtain the character block preliminary detection image, and obtaining the background estimate image includes steps 210-230.
[0096] Step 210: performing first morphological processing on the text image to generate character blocks according to the characters in the text image, thereby obtaining the character block preliminary detection image. In one embodiment, the first morphological processing is gray erosion processing, and the template width of the gray erosion processing can be max(3.0, H c / 8.0), where H c is a preset character pixel height.
[0097] Step 220: reducing the character block preliminary detection image to obtain a reduced image. Here, the calculation amount is reduced by appropriately reducing the character block preliminary detection image, and the reduction ratio when reducing can be 8.0 / H c .
[0098] Step 230: performing second morphological processing on the reduced image to obtain the background estimate image. The purpose of the second morphological processing is to filter out the character blocks in the reduced image and leave the non-character part, i.e. the background part, so as to filter out the interference of non-characters in the later difference.
[0099] In one embodiment, step 230 comprises: performing median filtering on the reduced image to obtain a median filtered image, performing a gray scale closing operation on the median filtered image to obtain a gray scale closing operated image, and taking the gray scale closing operated image as the background estimation image. The size of the median filtering template can be 3x3, and the size of the gray scale closing operation template can be max(5.0, 0.5xmax(3.0, H c The median filtering, the gray scale closing operation, and the like in this embodiment are advantageous in removing noise in the reduced image and obtaining a more accurate background estimation image.
[0100] On the basis of the embodiment shown in Figure 4 In the embodiment shown in
[0101] In some embodiments, in order to obtain a more accurate initial estimation of the rotation angle and reduce the amount of calculation, the initial estimation of the rotation angle in step 300 can also be calculated by a method similar to steps 400-500. Please refer to Figure 5 The process of obtaining the initial estimation of the rotation angle in this embodiment comprises steps 310-320, which are described below.
[0102] Step 310: Obtain a preset first angle range, form a target function curve according to the gray scale projection results of a plurality of rotation angle values in the first angle range, and obtain a first target function curve; wherein the gray scale projection process of each rotation angle value comprises: generating a sampling point array according to the rotation angle value to sample the character block detection image to obtain the gray scale projection result.
[0103] Specifically, first, a plurality of rotation angle values are selected in the first angle range, either randomly or according to certain rules, the gray scale projection is performed for each rotation angle value, the target function value is calculated according to the gray scale projection result, a target function curve is formed based on the target function values of the selected plurality of rotation angle values, and a first target function curve is obtained. In the process of gray scale projection, the gray scale value of the sampling point is obtained by sampling the character block detection image according to the sampling point array generated according to the rotation angle value, and the gray scale projection result is calculated using the gray scale value of the sampling point. The first angle range can be relatively large.
[0104] In some embodiments, the target function value is the sum of squared differences of the gray scale projection, and a target function curve is formed according to the gray scale projection results of the plurality of rotation angle values in the first angle range, to obtain a first target function curve, including: for each rotation angle value in the first angle range, calculating the sum of squared differences of the gray scale projection thereof as the target function value thereof, and forming the first target function curve based on all the rotation angle values in the first angle range and the target function values thereof.
[0105] In some embodiments, the plurality of rotation angle values in the first angle range are obtained by reading angle values in the first angle range as rotation angle values at a first angle step, to obtain the plurality of rotation angle values in the first angle range. For example, the first angle range is [0, 5], and the first angle step is 1, then the plurality of rotation angle values read are 0, 1, 2, 3, 4, and 5. In an embodiment, the first angle step is determined by the following expression:
[0106]
[0107] wherein S min and S max respectively represent the lower limit value and the upper limit value of the angle of the first angle range, and round() represents the rounding operation.
[0108] In an embodiment, the plurality of rotation angle values in the second angle range can also be selected by steps, that is, reading angle values in the second angle range as rotation angle values at a second angle step, to obtain the plurality of rotation angle values in the second angle range. In order to realize the coarse-to-fine rotation angle estimation, the second angle range can be set to be smaller than the first angle range, and the second angle step can be set to be smaller than the first angle step. Assuming that the initial estimation value of the rotation angle is S opt , in an embodiment, the second angle range can be set to be , and the second angle step can be set to be
[0109] Step 320: calculating the angle value corresponding to the sub-pixel maximum value point of the first target function curve as the initial estimation value of the rotation angle.
[0110] In an embodiment, the calculation of the angle value corresponding to the sub-pixel maximum value point of the first target function curve can be specifically: performing smoothing processing on the first target function curve, then performing interpolation to obtain the sub-pixel maximum value point of the first target function curve, and then obtaining the angle value corresponding to the sub-pixel maximum value point. The smoothing processing can adopt Gaussian smoothing or mean smoothing, and the interpolation can adopt parabolic interpolation or Lagrange interpolation method.
[0111] Please refer to Figure 6In some embodiments, the process of generating the sample point array according to the rotation angle value to sample the character block detection image to obtain the gray projection result in step 400 and step 310 includes steps 10-30, which are described in detail below.
[0112] Step 10: A direction corresponding to the rotation angle value is set as the projection direction, and a direction orthogonal to the projection direction is set as the traversal direction. A sample point is generated on the text image in the projection direction with a first step length and in the traversal direction with a second step length, thereby obtaining a sample point array.
[0113] It can be understood that each rotation angle value corresponds to a direction, similar to the hour hand on a clock. When it is rotated by 90 degrees, it is in the horizontal direction, and when it is rotated by 180 degrees, it is in the vertical direction. In an embodiment, the sample point can be determined with the center of the text image as the center point of the sample point array. The first step length and the second step length are set according to actual needs. In an embodiment, the first step length can be set as H c / 8.0, and the second step length can be set as max(1, H c / 60). The generated sample point array is shown in FIG. 10, where the black dots are the sample points. Figure 7
[0114] Step 20: Calculate the gray value of each sample point.
[0115] The gray value of the sample point can be calculated by the gray values of the pixel points near the sample point, such as weighted average, etc. In an embodiment, the gray value of the sample point is determined by the following expression:
[0116]
[0117] where w1, w2, w3, and w4 are sample weight coefficients, inverse distance square weight coefficients are used, and normalized bilinear coefficients or Gaussian weight coefficients, etc. can also be used; (x, y) represents the coordinates of the sample point, g(x, y) represents the gray value of the sample point, and represent the gray values of the pixel points with coordinates and on the text image, respectively.
[0118] Step 30: Perform gray projection on the sample point array in the projection direction to obtain a gray projection result.
[0119] Those skilled in the art can understand that performing gray projection on the sample point array in the projection direction is to calculate the mean value of the gray values of each row of sample points in the projection direction. Therefore, the gray projection result includes the mean value of the gray values of each row of sample points in the projection direction, as shown by the gray projection curve in FIG. 11. Figure 7
[0120] The embodiment of the present application also provides a new method for extracting a character edge region and a gradient amplitude angle image in a tilt estimation image, please refer to Figure 8 The step 700 in the embodiment includes steps 710-770, which are described in detail as follows.
[0121] Step 710: performing mean filtering on the tilt estimation image to obtain a mean filtered image.
[0122] In order to accurately estimate the tilt angle of the text, the edge with the horizontal gradient on the character needs to be highlighted, and the edge with the vertical gradient needs to be blurred. For example, for the character "0", it is expected to be similar to a parenthesis after processing. Therefore, in an embodiment, a long strip filter kernel can be used for mean filtering, that is, the filter kernel size of the mean filtering is 1xN, where N is a preset filter kernel width, and in an embodiment, N=7.
[0123] Step 720: performing processing on the mean filtered image using a first edge extraction filter to obtain a first gradient image and a first gradient amplitude angle image.
[0124] Step 730: performing binarization on the first gradient image using a first binarization threshold to obtain a first character edge region of the tilt estimation image, where the first character edge region is a region in the tilt estimation image corresponding to a region in the first gradient image with a gray value greater than the first binarization threshold.
[0125] After the binarization of the first gradient image, the region with a gray value (indicating a gradient value) greater than the first binarization threshold is obtained, and then the region in the tilt estimation image corresponding to the region is the first character edge region. In an embodiment, the first binarization threshold is 1.4xG1, where G1 represents the standard deviation of the first gradient image, and then the region with a gray value in the range of [1.4xG1, 255] in the first gradient image is obtained after the binarization.
[0126] Step 740: performing processing on the mean filtered image using a second edge extraction filter to obtain a second gradient image and a second gradient amplitude angle image.
[0127] It should be noted that the step 740 and the step 720 can be executed in sequence or simultaneously. In an embodiment, the first edge extraction filter and the second edge extraction filter are a Roberts filter and a Canny filter respectively.
[0128] Step 750: performing binarization on the second gradient image using a second binarization threshold to obtain a second character edge region of the tilt estimation image, where the second character edge region is a region in the tilt estimation image corresponding to a region in the second gradient image with a gray value greater than the second binarization threshold.
[0129] Please refer to step 730 for this step. In one embodiment, the second binarization threshold is 1.4xG2, where G2 represents the standard deviation of the second gradient image, and the region with a gray value range of [1.4xG2, 255] in the second gradient image is obtained after binarization.
[0130] Step 760: Obtain the intersection of the first character edge region and the second character edge region of the tilt estimation image to obtain the final character edge region of the tilt estimation image.
[0131] Step 770: Take either the first gradient amplitude angle image or the second gradient amplitude angle image as the gradient amplitude angle image of the tilt estimation image.
[0132] This embodiment uses two edge extraction filters to extract the character edge region and the gradient amplitude angle image in the tilt estimation image, and combines the results of the two to obtain the final character edge region and the gradient amplitude angle image, making the extracted character edge region and the gradient amplitude angle image more refined and more accurate.
[0133] According to the text correction method of the above embodiment, the rotation angle and the tilt angle of the text are estimated, and the text image is corrected according to the estimated angle, effectively reducing the character mis-segmentation and mis-recognition caused by the rotation and tilt of the font during printing, and improving the accuracy of character segmentation, recognition and structured analysis of the text image when the text in the text image is rotated and tilted.
[0134] When estimating the rotation angle, first, the character block preliminary detection image and the background estimation image are obtained from the text image, and the character block detection image is calculated based on image difference calculation, making the detected character block more accurate; and a coarse-to-fine strategy is used to improve the accuracy of the rotation angle estimation. When estimating the rotation angle value, the gray scale projection result of multiple rotation angle values is used to obtain the target function curve, and the angle value corresponding to the sub-pixel maximum point of the target function curve is calculated as the rotation angle estimation value, greatly improving the accuracy of the estimated rotation angle. When performing gray scale projection, a sampling point array is generated according to the rotation angle value to sample the character block detection image, and the gray scale projection result is obtained according to the sampled gray scale value, reducing the calculation amount.
[0135] When estimating the tilt angle, the text image or the reduced text image is taken as the tilt estimation image, the character edge region and the gradient amplitude angle image in the tilt estimation image are extracted, the region corresponding to the character edge region in the gradient amplitude angle image is histogram counted to obtain the gradient amplitude angle histogram, the gradient amplitude angle curve is obtained according to the gradient amplitude angle histogram, and the sub-pixel maximum point of the gradient amplitude angle curve is taken as the tilt angle estimation value, greatly improving the accuracy of the tilt angle.
[0136] In some embodiments of the present application, after text correction, character recognition is performed on the text image, and a text line character recognition rate optimization method is proposed to improve the character recognition accuracy. After step 900, the text line character recognition step is included in the embodiments, please refer to Figure 9 The text line character recognition step includes steps 1000-5000, which will be described in detail below.
[0137] Step 1000: Perform character segmentation and character recognition on the text image to obtain character recognition data of each character, which at least includes character recognition results.
[0138] Character segmentation and character recognition can be implemented using existing technologies, which will not be described here. Those skilled in the art can understand that character segmentation and character recognition can obtain character recognition results, and in some embodiments, character segmentation regions and character recognition scores can also be obtained. Therefore, in some embodiments, the character recognition data can also include character segmentation regions and character recognition scores, wherein the character recognition score represents the confidence of the character recognition result.
[0139] Step 2000: Construct an initial structure graph model for each text line of the text image, respectively, wherein the steps of constructing the initial structure graph model include: sequentially traversing all characters of the current text line, establishing a node with the current character in the traversal process, recording the character recognition data of the current character in the node, and if there are characters before the current character, establishing an edge between the established node and the node where the preset number of characters before the current character are located. The direction of the edge is from the node where the character before the current character is located to the established node.
[0140] Here, the current text line refers to the text line that is currently constructing the initial structure graph model, and the current character refers to the character that is currently traversed. If there is no other character before the current character in the current text line, no edge establishing operation is needed, and if there is other character, an edge is established between the established node and the node where the preset number of characters before the current character are located. The preset number is set according to the actual situation. In one embodiment, if there is only one character before the current character, an edge is established between the established node and the node where the character is located; if there is more than one character before the current character, an edge is established between the established node and the nodes where the first two characters before the current character are located. Figure 10 An initial structure graph model established for a text line in one embodiment is given.
[0141] In some embodiments, the length of the edge is the distance between the two nodes. When the character recognition data includes the character segmentation region, the distance between the characters is the minimum distance of the circumscribed rectangle of the character segmentation region of the two characters.
[0142] Step 3000: Divide the initial structure graph model of each text line into several subgraph models according to the node where the separator character is located.
[0143] The separator character is preset by the user and can include " / ", "\", "\\", ":", etc. The separator character is significant for dividing text and is used as one of the criteria for subgraph partitioning. Furthermore, if an edge is excessively long, it indicates that the edge may be abnormal. Therefore, in one embodiment, before partitioning the subgraph model based on the node containing the separator character, all edges of the initial structural graph model are traversed, and edges with a length greater than a distance threshold T are deleted. The distance threshold T can be set empirically or obtained through statistical methods. Please refer to [reference needed]. Figure 11 This application provides a method for calculating a distance threshold T in one embodiment, which is described in detail below.
[0144] Step 3100: Exclude delimiters from the text line, sequentially traverse all characters in the text line, calculate the distance between all adjacent characters, and obtain the distance set. Where d i Let N represent the i-th distance value, and N represent the total number of distance values.
[0145] Step 3200: Based on the distance set Histogram for calculating distances between characters Where c represents the total number of groups in the histogram, C j This represents the frequency of the j-th group.
[0146] Step 3300: Smooth the histogram to obtain the distance curve, and calculate the sub-pixel maxima position p of the distance curve. extrem The sub-pixel maxima can be obtained by interpolating the distance curve, and the sub-pixel maxima location p is... extrem This refers to the x-coordinate of the sub-pixel maxima. Smoothing can be achieved using Gaussian smoothing or mean smoothing, while interpolation can be performed using parabolic interpolation or Lagrange interpolation.
[0147] Step 3400: Based on the distance set The minimum value d min Standard deviation d std and sub-pixel maximum position p extrem The distance threshold T is calculated.
[0148] It is understandable that, based on the minimum value d min and sub-pixel maximum position p extrem This allows us to obtain the distance value with the highest probability of occurrence, and its standard deviation d. std This can be used to measure the degree of data deviation. When the distance value with the highest probability of deviation reaches a certain level, it is considered abnormal. Therefore, the minimum value d can be used as a reference. min Standard deviation d stdand sub-pixel maximum position p extrem The distance threshold T is calculated, and the edges with length greater than the distance threshold T are regarded as abnormal edges (i.e. data with too large deviation).
[0149] In one embodiment, step 3200 calculates the distance set The histogram of the distance between characters is calculated, including: calculating the minimum unit distance of quantization of the histogram of the distance between characters where d max and d mean are the maximum value and average value of the distance set respectively; then the total group number is calculated and the histogram is initialized to 0; finally, the distance set is traversed, for each distance value d i , h i = (d i -d min ) / d size is calculated, C hi is added by 1, and after the traversal, the final histogram is obtained. In this embodiment, the distance threshold T is determined by the following formula:
[0150] T = d min +d size ×p extrem +2×d std .
[0151] In one embodiment, the initial structure graph model of each text line is divided into several sub-graph models according to the nodes where the separating characters are located, including: finding the node where the separating character is located in the initial structure graph model, and all nodes connected to the node where the separating character is located where v i represents the i-th node connected to the node where the separating character is located, and V represents the total number of nodes connected to the node where the separating character is located; then deleting all edges connected to the node where the separating character is located, and deleting the longest edge between the nodes, to obtain the divided sub-graph model.
[0152] Taking the initial structure graph model shown in FIG. 1 as an example, the divided sub-graph model is as shown in FIG. 2. Figure 10 Figure 12 For convenience of illustration, the P above is denoted as P1, the P below is denoted as P2, the 2 on the left is denoted as 21, and the 2 on the right is denoted as 22. Among them, the lengths of edges P1-21, P2-21 and P2-3 are greater than the distance threshold T, and thus are deleted; / is a separator character, and the nodes connected thereto are 21, 3, 0 and 22, and thus edges 21- / , 3- / , / -0 and / -22 are deleted, and the edges between nodes 21, 3, 0 and 22 are 21-3, 3-0 and 0-22, among which 3-0 is the longest, and thus is also deleted. Finally, the subgraph model shown in the figure is divided into Figure 12 The three subgraph models shown in the figure.
[0153] Step 4000: receiving input text structure information, and constructing a standard structure graph model according to the text structure information, the text structure information including a number n of characters to be matched and a character type of each character, and the standard structure graph model including n nodes, each node only having edges with left and right adjacent nodes, the direction of the edges being from the left node to the right node, and the i-th node recording the character type of the i-th character, wherein n is a positive integer, and the character type may be, for example, a number, a capital letter, a lowercase letter, etc., and the character type of each character may be a set including various character types allowed for the character.
[0154] The text structure information represents information of a structured text, and the structured text can be matched from a text line using the text structure information. The structured text refers to some text having a fixed format, such as a date "2023 0605". The n nodes of the standard structure graph model correspond to n characters, and the left and right orders of the nodes can be arranged according to the order of the characters in the text to be matched. In some embodiments, the text structure information further includes a lower limit of a character recognition score of each character in the text to be matched, and correspondingly, the i-th node of the standard structure graph model further records the lower limit of the character recognition score of the i-th character. Figure 13 A standard structure graph model constructed according to a text structure information in an embodiment is given, and three nodes are taken as an example in the figure, but it does not mean that there can only be three nodes.
[0155] Step 5000: matching an isomorphic graph of the standard structure graph model in the subgraph model, and taking the characters corresponding to the isomorphic graph as optimal character recognition results matched with the text structure information.
[0156] It should be noted that for a subgraph model having a number of nodes less than that of the standard structure graph model, matching is not needed. When matching the graph models, algorithms such as VF2 can be used. In order to improve the accuracy of matching, the present application further provides a new method for matching an isomorphic graph of a standard structure graph model in a subgraph model, please refer to Figure 14 The flow of matching an isomorphic graph of a standard structure graph model in a subgraph model in an embodiment includes steps 5100-5700, which are described in detail below.
[0157] Step 5100: Establish an mxn matrix M and initialize all elements to 1, where m is the number of nodes of the subgraph model, m≥n.
[0158] Step 5200: Traverse all nodes of the subgraph model and the standard structure model, for any node of the subgraph model and any node of the standard structure model determine and whether the first preset condition and / or the second preset condition are met, and if so, execute step 5300, otherwise execute step 5400.
[0159] wherein the first preset condition means that the character recognition result in is not contained in the character type in , and the second preset condition means that the number of edges connected to is less than the number of edges connected to or one of the edges connected to cannot find an edge with the same direction in the edges connected to , the superscripts i and j represent the indices of the nodes in the subgraph model and the standard structure model respectively, i∈[0,m-1], j∈[0,n-1]. For the case that one of the edges connected to cannot find an edge with the same direction in the edges connected to , please refer to Figure 15 , wherein node B1 is node B4 is There is an edge A4-B4 pointing to node B4 in the edges connected to node B4, while all the edges connected to node B1 are from node B1, so edge A4-B4 cannot find an edge with the same direction in the edges connected to node B1.
[0160] Step 5300: Assign M[i,j] to -1.
[0161] Step 5400: Determine whether the edges connected to and the edges connected to are completely matched, and if so, execute step 5500, otherwise execute step 5600.
[0162] Step 5500: Obtain the matched node pair and Let M[k1,l1]=M[k1,l1]+1, M[k2,l2]=M[k2,l2]+1, wherein and represent the two nodes connected to node , and two nodes connected with node , and match the edge between and , and match the edge between and . Here two edges match means the directions of the two edges are the same.
[0163] the edge connected with and the edge connected with match completely, which can be referred to Figure 16 , where node B1 is node B2 is Since the match is complete, there is only one matched node pair, i.e. {A1, C1} and {A2, C2}, the edge A1-B1 matches the edge A2-B2, and the edge B1-C1 matches the edge B2-C2.
[0164] Step 5600: For each matched case, obtain the matched node pair in this case and According to the length of the edge between and , the length of the edge between and , the length of the edge between and , and calculate the first increase value E1 and the second increase value E2, let M[k x ,l x ] = M[k x ,l x ] + E1, M[k y ,l y ] = M[k y ,l y ] + E2, where and represent two nodes connected with node , and represent two nodes connected with node , and match the edge between and , and match the edge between and match.
[0165] When step 5600 is performed, it is explained that the edge connected with and the edge connected with do not match completely, and there are multiple matching cases. Please refer to Figure 17 , where node B1 is node B3 is There are four matching cases, i.e. four matching node pairs, which are {A1, C1} and {A3, C3}, {A1, C2} and {A3, C3}, {A2, C1} and {A3, C3}, and {A2, C2} and {A3, C3}. For the four matching cases, the first increase value E1 and the second increase value E2 are calculated, and corresponding operations are performed. For the length of the edge, taking the matching node pair {A1, C1} and {A3, C3} as an example, then is the length of edge A1-B1, is the length of edge B1-C1, is the length of edge A3-B3, and is the length of edge B3-C3.
[0166] In an embodiment, the first increase value and the second increase value are determined by the following formula:
[0167]
[0168] Step 5700: After the traversal is completed, nodes corresponding to each node of the standard structure graph model are selected from the subgraph model according to the matrix M, so as to obtain the isomorphic graph; if the traversal is not completed, the traversal is continued.
[0169] For any node of the subgraph model and any node of the standard structure graph model, the larger the element M[i, j] in the matrix is, the greater the possibility of matching is. Based on this, a person skilled in the art can select the node most likely to match in the subgraph model as the corresponding node of the node in the standard structure graph model. The index of the corresponding node of node in the subgraph model is denoted as i(j), and the corresponding node is In an embodiment, the node corresponding to node in the subgraph model is obtained according to the objective function where j p and j q represent two possible values of index j. The meaning of the above objective function is that for each index j, the index i that makes M[i(j), j] maximum is selected, and different indexes j select different indexes i. Finally, the node set is obtained. The resulting graph serves as the isomorphic graph.
[0170] To further improve matching accuracy, the character recognition data can include character recognition scores, and the text structure information can include the lower limit of the character recognition score for each character. Based on this, step 5200 is: traverse all nodes of the subgraph model and the standard structure graph model. For any node of the subgraph model... and any node of the standard structural diagram model judge and If the first preset condition and / or the second preset condition and / or the third preset condition are met, proceed to step 5300; otherwise, proceed to step 5400. The first and second preset conditions are explained in step 5200 above. The third preset condition refers to… The character recognition score is less than The lower limit of character recognition score in [the dataset].
[0171] The text line character recognition steps in the above embodiment first construct an initial structural graph model for each text line of the text image. The nodes of the initial structural graph model record the character recognition data of the characters in the text line. Then, based on the nodes where the separating characters are located, the initial structural graph model of each text line is divided into several sub-graph models. Next, a standard structural graph model is constructed based on the input text structure information. The isomorphic graph of the standard structural graph model is matched in the sub-graph models, and the character corresponding to the isomorphic graph is taken as the optimal character recognition result that matches the input text structure information. Users can input the text structure information of certain texts with fixed structures as a reference for finding such texts in text images. Furthermore, because graph models are used for modeling and isomorphic graph matching, and the character corresponding to the isomorphic graph is taken as the optimal character recognition result that matches the input text structure information, the recognition accuracy of characters or certain fixed-structure texts in complex environments is improved.
[0172] Those skilled in the art can understand that all or part of the functions of various methods in the above embodiments can be realized by hardware or by a computer program. When all or part of the functions in the above embodiments are realized by a computer program, the program can be stored in a computer readable storage medium, which can include a read-only memory, a random access memory, a magnetic disk, an optical disk, a hard disk, and the like. The above functions are realized by executing the program by a computer. For example, the program is stored in a memory of a device, and the above functions are realized by executing the program in the memory by a processor. In addition, when all or part of the functions in the above embodiments are realized by a computer program, the program can also be stored in a storage medium such as a server, another computer, a disk, an optical disk, a flash disk, or a mobile hard disk, and is saved in a memory of a local device by downloading or copying, or the system of the local device is updated, and the above functions are realized by executing the program in the memory by a processor.
[0173] The above application of specific examples to the present application is described, which is only used to help understand the present application and does not limit the present application. For those skilled in the art, according to the idea of the present application, a number of simple deductions, deformations or substitutions can be made.
Claims
1. A text correction method, characterized in that, include: Get text image; A preliminary character block detection image and a background estimation image are calculated based on the text image. A character block detection image is then calculated based on the image difference using the preliminary character block detection image and the background estimation image. Obtain an initial estimate of the rotation angle of the text image, and determine a second angle range based on the initial estimate of the rotation angle; A target function curve is formed based on the grayscale projection results of multiple rotation angle values within the second angle range, thus obtaining the second target function curve; The grayscale projection process for each rotation angle value includes: generating a sampling point array based on the rotation angle value to sample the character block detection image and obtain the grayscale projection result; Calculate the angle value corresponding to the sub-pixel maximum point of the second objective function curve, and use it as an accurate estimate of the rotation angle; The text image is rotated and corrected based on the accurate estimated rotation angle. Using the text image or a scaled-down version of the text image as a tilt estimation image, extract the character edge regions and gradient angle images from the tilt estimation image; Histogram statistics are performed on the regions corresponding to the character edge regions in the gradient angle image to obtain a gradient angle histogram. The gradient angle histogram is smoothed to obtain a gradient angle curve. The sub-pixel maxima of the gradient angle curve are calculated as the tilt angle estimate. The text image is tilted based on the estimated tilt angle.
2. The text correction method as described in claim 1, characterized in that, The step of calculating the preliminary character block detection image and the background estimation image based on the text image includes: performing morphological processing on the text image to generate character blocks based on the characters in the text image to obtain the preliminary character block detection image, and obtaining the background estimation image.
3. The text correction method as described in claim 2, characterized in that, The step of performing morphological processing on the text image to generate character blocks based on the characters in the text image to obtain a preliminary character block detection image, and obtaining the background estimation image, includes: The text image is subjected to a first morphological processing to generate character blocks based on the characters in the text image, thereby obtaining a preliminary character block detection image; The preliminary detection image of the character block is reduced in size to obtain a reduced image; The reduced image is subjected to a second morphological processing to obtain the background estimation image; The method of obtaining the character block detection image based on image difference calculation includes: subtracting the background estimation image from the reduced image to obtain the character block detection image.
4. The text correction method as described in claim 3, characterized in that, The first morphological treatment is grayscale etching. The step of performing a second morphological processing on the reduced image to obtain the background estimation image includes: performing median filtering on the reduced image to obtain a median-filtered image, performing a grayscale closing operation on the median-filtered image to obtain a grayscale closing operation image, and using the grayscale closing operation image as the background estimation image.
5. The text correction method as described in claim 4, characterized in that, The template width for the grayscale etching process is max(3.0, H). c / 8.0), the reduction ratio when reducing the initial detection image of the character block is 8.0 / H. c H c This is the preset character pixel height.
6. The text correction method as described in claim 5, characterized in that, The template size for the grayscale closing operation is max(5.0, 0.5 × max(3.0, H). c / 8.0))×2|1, where H c The preset character pixel height, | represents a binary OR operation.
7. The text correction method as described in claim 1, characterized in that, The process of obtaining the initial estimate of the rotation angle of the text image includes: A preset first angle range is obtained, and a target function curve is formed based on the grayscale projection results of multiple rotation angle values within the first angle range to obtain the first target function curve; wherein the grayscale projection process of each rotation angle value includes: generating a sampling point array based on the rotation angle value to sample the character block detection image to obtain the grayscale projection result; Calculate the angle value corresponding to the sub-pixel maximum point of the first objective function curve, and use it as the initial estimate of the rotation angle.
8. The text correction method as described in claim 7, characterized in that, Multiple rotation angle values within the first angle range are obtained as follows: angle values are read within the first angle range according to a first angle step size as rotation angle values to obtain multiple rotation angle values within the first angle range.
9. The text correction method as described in claim 8, characterized in that, The first angle step size is determined by the following expression: Where S min and S max These represent the lower and upper limits of the first angle range, respectively, and round() represents the rounding operation.
10. The text correction method as described in claim 9, characterized in that, Multiple rotation angle values within the second angle range are obtained as follows: angle values are read within the second angle range according to a second angle step size as rotation angle values to obtain multiple rotation angle values within the second angle range; wherein, the second angle range is smaller than the first angle range, and the second angle step size is smaller than the first angle step size.
11. The text correction method as described in claim 1 or 7, characterized in that, The step of generating a sampling point array based on the rotation angle value to sample the character block detection image and obtain a grayscale projection result includes: Using the direction corresponding to the rotation angle value as the projection direction and the direction orthogonal to the projection direction as the traversal direction, sampling points are generated on the text image with a first step length in the projection direction and a second step length in the traversal direction to obtain the sampling point array. Calculate the grayscale value of each sampling point; The sampling point array is subjected to grayscale projection along the projection direction to obtain the grayscale projection result.
12. The text correction method as described in claim 8, characterized in that, The grayscale value of a sampling point is determined by the following expression: Where w1, w2, w3, and w4 are sampling weight coefficients, (x, y) represents the coordinates of the sampling point, and g(x, y) represents the gray value of the sampling point. and The coordinates on the text image are respectively... and The grayscale value of the pixel.
13. The text correction method as described in claim 7, characterized in that, The step of forming a target function curve based on the grayscale projection results of multiple rotation angle values within the first angle range to obtain the first target function curve includes: for each rotation angle value within the first angle range, calculating the sum of squared differences of its grayscale projection as its target function value, and forming the first target function curve based on all rotation angle values within the first angle range and their target function values; The step of forming a target function curve based on the grayscale projection results of multiple rotation angle values within the second angle range to obtain the second target function curve includes: for each rotation angle value within the second angle range, calculating the sum of squared differences of its grayscale projection as its target function value, and forming the second target function curve based on all rotation angle values within the second angle range and their target function values.
14. The text correction method as described in claim 1, characterized in that, The step of extracting the character edge region and gradient angle image from the tilt estimation image includes: The tilt estimation image is subjected to mean filtering to obtain a mean-filtered image; The mean-filtered image is processed using a first edge extraction filter to obtain a first gradient image and a first gradient amplitude image; The first gradient image is binarized using a first binarization threshold to obtain the first character edge region of the tilted estimation image, wherein the first character edge region is the region in the tilted estimation image that corresponds to the region in the first gradient image whose gray value is greater than the first binarization threshold; The mean-filtered image is processed using a second edge extraction filter to obtain a second gradient image and a second gradient amplitude image; The second gradient image is binarized using a second binarization threshold to obtain the second character edge region of the tilted estimation image, wherein the second character edge region is the region in the tilted estimation image that corresponds to the region in the second gradient image whose gray value is greater than the second binarization threshold; The final character edge regions of the tilted estimated image are obtained by finding the intersection of the first and second character edge regions. Use either the first gradient phase image or the second gradient phase image as the gradient phase image of the tilt estimation image.
15. The text correction method as described in claim 14, characterized in that, The mean filter kernel size is 1×N, where N is the preset kernel width.
16. The text correction method as described in claim 14, characterized in that, The first binarization threshold is 1.4×G1, and the second binarization threshold is 1.4×G2, where G1 represents the standard deviation of the first gradient image and G2 represents the standard deviation of the second gradient image.
17. A computer-readable storage medium, characterized in that, The medium stores a program that can be executed by a processor to implement the text correction method as described in any one of claims 1 to 16.
Citation Information
Patent Citations
Tilt correction method for scanning document image
CN106447615A
Method for accurately identifying characters of inclined text
CN110363196A