Text correction method, device, computer equipment and storage medium
By segmenting and perspective transforming the text line outline image, a corrected text image is generated, which solves the problem of recognition errors caused by curved text lines and improves the text recognition accuracy of the OCR system.
Patent Information
- Application Number
- CN202110182043.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-09
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-02-09
AI Technical Summary
When the existing OCR system processes curved text lines, the recognition algorithm causes misrecognition and cannot effectively recognize characters.
By obtaining the text line image and text line outline image to be corrected, determining the segmentation number value to segment the text line outline image, and obtaining a set of control points. Based on these control points, the perspective transformation of the text line image to be corrected is performed to generate a corrected text image.
It effectively avoids the interference of curved text lines on recognition, improves the accuracy of text recognition, and obtains more accurate character recognition results.
Smart Images

Figure CN114943973B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of image processing technology, and in particular to a text correction method, device, computer equipment and storage medium. Background Art
[0002] In recent years, optical character recognition (OCR) technology has been applied to various industries, such as ID card recognition, invoice recognition, etc. A general OCR system usually contains two modules, text detection and text recognition, among which text detection is one of the core modules, and its main purpose is to obtain the image of each text line from the input image.
[0003] At present, the mainstream method of text detection is to use a deep learning algorithm to obtain a text line image, send the image to be detected into a convolutional neural network, then predict the score of the text area, get the score of each pixel belonging to the text, binarize the score map, get the mask of the text, take the outline of the text mask as the text outline, and cut out a small image of the text area according to the circumscribed rectangle.
[0004] However, in the above method, when the text in the image to be detected is curved, the text in the small image of the cut-out text area is curved. Directly inputting this detection result into the recognition algorithm is likely to cause misrecognition. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a text correction method, apparatus, computer device and storage medium to solve the problem in the prior art that the text lines in the text line image cut out from the image to be recognized are curved, resulting in the recognition algorithm being unable to effectively recognize the characters.
[0006] In a first aspect, an embodiment of the present invention provides a text correction method, comprising:
[0007] Acquire a text line image to be corrected and a text line contour image, wherein the text line contour image is a binary image corresponding to the text line image to be corrected;
[0008] Determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine a control point set corresponding to the text line contour image after each segmentation operation;
[0009] The text images to be corrected are perspective transformed according to the control point sets to obtain corresponding corrected text images.
[0010] In a second aspect, an embodiment of the present invention further provides a text correction device, comprising:
[0011] An acquisition module, used for acquiring a text line image to be corrected and a text line contour image, wherein the text line contour image is a binary image corresponding to the text line image to be corrected;
[0012] A determination module, used to determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine a control point set corresponding to the text line contour image after each segmentation operation;
[0013] The correction module is used to perform perspective transformation on the text image to be corrected according to each control point set to obtain corresponding corrected text images.
[0014] In a third aspect, an embodiment of the present invention further provides a computer device, wherein the computer device
[0015] comprising: one or more processors;
[0016] A memory for storing one or more programs;
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the text correction method provided in the first aspect.
[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the text correction method provided in the first aspect.
[0019] The above-mentioned text correction method, device, computer equipment and storage medium include: obtaining a text line image to be corrected and a text line contour image, wherein the text line contour image is a binary image corresponding to the text line image to be corrected; determining at least one segmentation quantity value, and segmenting the text line contour image according to each segmentation quantity value, and determining the control point set corresponding to the text line contour image after each segmentation operation; and perspective transforming the text image to be corrected according to each control point set to obtain the corresponding corrected text images. In the text correction method, the text line contour image is segmented according to each segmentation quantity value to obtain a control point set, and then perspective transforming the text image to be corrected according to the control point set to obtain each corrected text image. Compared with the related art, the corrected text image obtained in this embodiment is a non-curved text image, and character recognition based on each corrected text image can obtain a more accurate character recognition effect, thereby improving the accuracy of image text recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 A flowchart of a text correction method provided in Embodiment 1 of the present invention;
[0021] Figure 2 A flowchart of a text correction method provided in Embodiment 2 of the present invention;
[0022] Figure 3 This is a schematic diagram of an example flow of a text correction method provided in Embodiment 2 of the present invention;
[0023] Figure 4 A schematic diagram of a flow chart of determining a set of control points in a text correction method provided in Embodiment 2 of the present invention;
[0024] Figure 5 A schematic diagram of a flow chart of determining a corrected text image in a text correction method provided in Embodiment 2 of the present invention;
[0025] Figure 6 A schematic diagram of a flow chart of obtaining a text recognition result in a text correction method provided in Embodiment 2 of the present invention;
[0026] Figure 7 This is an example diagram of a process of obtaining a text line image to be corrected in a text correction method provided in Embodiment 2 of the present invention;
[0027] Figure 8 A schematic diagram of the structure of a text correction device provided in Embodiment 3 of the present invention;
[0028] Fig. 9 A schematic diagram of the structure of a computer device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION
[0029] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0030] Embodiment 1
[0031] Figure 1 A flowchart of a text correction method provided in Embodiment 1 of the present invention is provided. The method can be applied to the case of correcting curved text lines in text images. The method can be executed by a text correction device, wherein the text correction device can be implemented by software and / or hardware, and the text correction device can be integrated on a computer device.
[0032] like Figure 1 As shown, a text correction method provided by Embodiment 1 of the present invention includes the following steps:
[0033] Step 101: Acquire a text line image to be corrected and a text line contour image.
[0034] The text line contour image is a binary image corresponding to the text line image to be corrected.
[0035] The text line in the text line image to be corrected in this embodiment is a curved text line. The text line image to be corrected can be obtained from an original image. The original image can be any image including a text line. The text line can be a line of characters composed of words or symbols.
[0036] The text line contour image in this embodiment is a binary image corresponding to the corrected text line image. The text line contour image can also be understood as a binary image cropped out from the binary image of the original image according to the minimum bounding rectangle, wherein the minimum bounding rectangle can be the minimum bounding rectangle corresponding to the text line in the original image.
[0037] Specifically, the method of obtaining the text line image to be corrected can be: inputting the original image into a preset neural network model to obtain a text score map of the original image; binarizing the text score map to obtain a mask of the text line, and the contour of the text line in the original image can be calculated through the mask; the minimum bounding rectangle of the text line can be obtained according to the coordinates of the contour of the text line; the text line image can be correspondingly cropped from the original image according to the minimum bounding rectangle, and the text line image is the text line image to be corrected. Among them, the text score map can include the probability score of each pixel point in the original image being a text line.
[0038] Step 102: determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine the control point set corresponding to the text line contour image after each segmentation operation.
[0039] Among them, a segmentation number value can be understood as the number of segmentation lines determined on the text line contour image. After segmenting the text line contour image according to a segmentation number value, the text line contour image can be segmented into a sub-image area of the segmentation number value plus 1. In this step, after determining a segmentation number value, the text line contour image can be further segmented according to the segmentation number value so as to obtain the corresponding control point set later.
[0040] In this embodiment, after obtaining the text line contour image from the text line image to be corrected, at least one segmentation quantity value can be determined in the text line contour image, and the segmentation quantity value can be determined according to the contour angle of the text line contour. After determining a segmentation quantity value, the remaining segmentation quantity values can be obtained based on the segmentation quantity value. For example, after first determining a segmentation quantity value according to the contour angle of the text line contour, the segmentation quantity value can be added by 1 to obtain a second segmentation quantity value, and the segmentation quantity value can be subtracted by 1 to obtain a third segmentation quantity value. Among them, the number of segmentation quantity values obtained is not specifically limited here, and can be selected according to actual conditions.
[0041] Exemplarily, segmenting the text line contour image according to each segmentation quantity value can be: first segmenting the text line contour image according to the first segmentation quantity value, then segmenting the text line contour image according to the second segmentation quantity value, and finally segmenting the text line contour image according to the third segmentation quantity value.
[0042] Specifically, the method of segmenting the text line contour image according to a segmentation number value among the segmentation number values can be: segmentation is performed on the long border of the text line contour image to obtain segmentation lines of the segmentation number value, and the text line contour image can be segmented into the segmentation number value+1 segment.
[0043] In this embodiment, the control point set may be a set of control points on the text line contour image, and the control point set may be obtained after performing a segmentation operation on the text line contour image. It is understandable that each control point set may include a control point set corresponding to each segmentation operation, and illustratively, each control point set may include a control point set corresponding to the text line contour image after the first segmentation, a control point set corresponding to the text line contour image after the second segmentation, and a control point set corresponding to the text line contour image after the third segmentation.
[0044] Specifically, determining the control point set corresponding to the text line contour image after the first segmentation operation may include: determining the intersection of the segmentation line and the text line contour on the text line contour image, determining the height between the two intersection points on each segmentation line, taking the average of all heights as the height of the text line, and determining the control point set based on the intersection points on each segmentation line and the height of the text line.
[0045] Step 103: Perspective transform the text images to be corrected according to the control point sets to obtain corresponding corrected text images.
[0046] In this embodiment, perspective transformation can be understood as mapping characters in a text line on an image to another blank image according to a mapping relationship. The corrected text image can be an image obtained after the image to be corrected is corrected, and the text line in the corrected text image has a smaller curvature or no curvature than the curvature of the text line in the image to be corrected.
[0047] In this step, a corresponding number of control point sets can be obtained according to the number of segmentation quantity values, and a corresponding number of corrected text images can be obtained through perspective transformation according to each control point set. It can be understood that the number of corrected text images can be determined by the number of segmentation quantity values.
[0048] Furthermore, the method of obtaining a corrected text image by implementing perspective transformation according to a set of control points is described. Specifically, corresponding points are found on the text line image to be corrected according to the quantity information and distribution characteristics of each control point in the control point set, and a blank image of the same size as the text line image to be corrected is added, and control points are evenly set on the blank image according to the quantity information and distribution characteristics of the corresponding points; finally, according to the corresponding points on the text line image to be corrected and the control points on the blank image, the text on the text line image to be corrected can be accurately mapped to the blank image through perspective transformation to obtain the corrected text image.
[0049] In this embodiment, the principle of mapping the text on the text line image to be corrected to the blank image to obtain the corrected text image through perspective transformation is that any four adjacent corresponding points that can form a rectangular frame among the corresponding points on the text line image to be corrected can determine a text, and the text is mapped to the rectangular frame formed by the four control points corresponding to the four corresponding points on the blank image, thereby realizing the mapping of the text on the text line image to be corrected to the blank image to obtain the corrected text image. The above operation can be applied to each character in the text line image to be corrected. Since the distribution of control points on the blank image is more uniform than the distribution of corresponding points on the text line image to be corrected, the curvature of the text obtained after mapping the text line image to be corrected to the blank image can be greatly improved. Therefore, the above text correction method can effectively avoid the interference of text line curvature in the text line image to be corrected on text recognition.
[0050] Optionally, after step 103, a text correction method provided by the present embodiment may further include the following steps: inputting each corrected text image into a text recognition model to obtain recognition results of characters in the text lines of each corrected text image, and according to the recognition results, determining the average recognition rate of the text line in each corrected text image, and taking the corrected text image corresponding to the maximum average recognition rate as the final segmentation result.
[0051] The above process can also be understood as that a corrected text image with the best segmentation effect can be determined in each corrected text image by the above method, and the character recognition accuracy obtained after the corrected text image is input into the text recognition model is high. It can be seen that according to the method corresponding to the corrected text image, the text image to be corrected can be effectively corrected, and the curvature of the text line in the corrected text image can be greatly improved. Therefore, after the above corrected text image is input into the text recognition model, the text recognition model can accurately recognize the text line in the corrected text image.
[0052] The technical solution provided in the first embodiment of the present invention first obtains the text line image to be corrected and the text line contour image; then determines at least one segmentation quantity value, and segments the text line contour image according to each segmentation quantity value, and determines the control point set corresponding to the text line contour image after each segmentation operation; finally, perspective transforms the text image to be corrected according to each control point set, and obtains the corresponding corrected text images. In this text correction method, the text line contour image is segmented according to each segmentation quantity value to obtain a control point set, and then perspective transforms the text image to be corrected according to the control point set to obtain each corrected text image. Compared with the related art, the corrected text image obtained in this embodiment is a non-curved text image, and character recognition based on each corrected text image can obtain a more accurate character recognition effect, thereby improving the accuracy of image text recognition.
[0053] Embodiment 2
[0054] Figure 2 This is a flow chart of a text correction method provided in Embodiment 2 of the present invention. Embodiment 2 is optimized based on the above embodiments.
[0055] like Figure 2 As shown, a text correction method provided by Embodiment 2 of the present invention includes the following steps:
[0056] Step 201: Obtain a text line image to be corrected and a text line contour image.
[0057] The text line contour image is a binary image corresponding to the text line image to be corrected.
[0058] In this embodiment, Figure 3 This is a schematic diagram of an example flow chart of a text correction method provided in the second embodiment of the present invention. To better understand the execution of the method provided in this embodiment, the following is further provided: Figure 3 To describe the implementation process in the form of effect presentation, specifically, Figure 3The steps a to j in the text correction are detailed. The step a is a text line outline image, and the white area in the step a is the text line outline.
[0059] Step 202, determine at least one segmentation quantity value, for each segmentation quantity value, vertically segment along the long border of the text line contour image, obtain segmentation line segments formed by the segmentation quantity value intersecting with the text line contour, and determine the segment length of each segmentation line segment.
[0060] In this embodiment, determining at least one segmentation quantity value may be performed by calculating the contour angle of the text line contour according to the coordinates of the text line contour points in the text line contour image, and further determining the segmentation quantity value according to the size of the contour angle. The contour point coordinates may be the coordinate values corresponding to each contour point.
[0061] Optionally, determining at least one segmentation quantity value may include: determining the contour angle of the text line contour by the least squares method based on the contour point coordinate information of the text line contour in the text line contour image; searching a preset data association table to determine a benchmark value corresponding to the contour angle; and recording the benchmark value, the benchmark value plus 1, and the benchmark value minus 1 as the segmentation quantity values, respectively.
[0062] It should be noted that calculating the contour angle by the least square method is a prior art and will not be described in detail here.
[0063] The text line contour may be the outer contour of the text line in the text line contour image, and if a text line is tilted, the text line contour has a certain tilt angle. The preset data association table may be a pre-set association table, and the relationship between the contour angle and the reference value may be recorded in the data association table, that is, one contour angle corresponds to one reference value; the reference value may be the segmentation quantity value used when the first correction image is obtained by performing the first correction.
[0064] Specifically, after determining the contour angle, the preset data association table can be searched, and the corresponding reference value can be determined according to the contour angle in the table, and then each segmentation quantity value can be determined according to the reference value. Among them, the method of determining each segmentation quantity value according to the reference value can be to use the reference value as a segmentation quantity value, add 1 to the reference value as a segmentation quantity value, and subtract 1 from the reference value as a segmentation quantity value. Exemplarily, if the reference value is N, N-1, N, and N+1 can be used as three segmentation quantity values.
[0065] Furthermore, segmenting the text line contour image according to each of the segmentation quantity values may include: for each segmentation quantity value, vertically segmenting along the long border of the text line contour image, obtaining segmentation line segments formed by the segmentation quantity value intersecting with the text line contour, and determining the segment length of each of the segmentation line segments.
[0066] Among them, vertical segmentation along the upper and lower long borders on the text line contour image can obtain segmentation quantity value line segments, and the intersection of each line segment and the text line contour is used as the segmentation line segment. It should be noted that this step is to segment the text line contour image for each segmentation quantity value, that is, after segmentation, multiple segmented text line contour images can be obtained.
[0067] For example, for a split number value N, refer to Figure 3 From step b to step d in the text line contour map, as shown in step b, N segmentation positions are uniformly selected on the text line contour map; then, as shown in step c, the pixel points in the horizontal direction of the N segmentation positions are traversed on the text line contour map to find the intersection of the segmentation line and the text line contour, and the line segment between the two intersections is the segmentation line segment; then, as shown in step d, the distance between the two intersections on each segmentation line is taken as the segment length of the segmentation line segment to obtain N segment lengths.
[0068] Step 203: Determine the control point set corresponding to the text line contour image after the segmentation operation according to the endpoint coordinate information of each segmentation line segment and the corresponding line segment length.
[0069] In this embodiment, the endpoint coordinate information of each segmented line segment may include the endpoint coordinate information of all segmented line segments obtained after three segmentations.
[0070] Figure 4 The flowchart of determining a control point set in a text correction method provided in the second embodiment of the present invention is as follows. Here, the control point set corresponding to the text line contour image after the first segmentation operation is determined based on the endpoint coordinate information of the segmented line segment obtained after the first segmentation and the corresponding line segment length, such as Figure 4 As shown, step 203 may include the following steps:
[0071] Step 2031: determine the average value of the lengths of each line segment as the text height, and determine the midpoint of each segmented line segment based on the endpoint coordinate information of each segmented line segment.
[0072] In this step, after obtaining the length of each line segment, the average value of the line segment length can be calculated, and the average value is used as the height of the characters in the text line. The midpoint of each segmentation line segment can be further calculated based on the coordinate information of the upper and lower endpoints of each segmentation line segment.
[0073] Here, the calculation of the midpoint of a segment is taken as an example to illustrate, the average value of the horizontal coordinates in the upper endpoint coordinates and the horizontal coordinates in the lower endpoint coordinates of the segment is calculated as the horizontal coordinate of the midpoint of the segment, and the average value of the vertical coordinates in the upper endpoint coordinates and the vertical coordinates in the lower endpoint coordinates of the segment is calculated as the vertical coordinate of the midpoint of the segment, and the position information of the midpoint can be determined according to the horizontal and vertical coordinates of the midpoint. According to the above process, the midpoint of each segment can be calculated.
[0074] For example, Figure 3 As shown in step e in , the average length of each line segment can be calculated as the text height through the formula.
[0075] Step 2032: sequentially connect the midpoints and extend the line segments corresponding to the first and last midpoints until they intersect with the text line outline to form a first number of midpoint line segments.
[0076] The first number is the segmentation number value plus 1. For example, if the current segmentation number is N, the first number is N+1.
[0077] In this step, each midpoint is connected in sequence to obtain a horizontal line segment. The first midpoint on the horizontal line segment is extended to the left until it intersects with the text line outline, and the last midpoint on the horizontal line segment is extended to the right until it intersects with the text line outline. At this point, multiple midpoint connecting segments can be determined on the formed horizontal line segment.
[0078] For example, Figure 3 As shown in step f, take the midpoint of the two intersection points on the segment line, connect the midpoints and extend them to the left and right directions to intersect with the text line contour to obtain the intersection points at both ends of the text line, take the two intersection points and all the midpoints as endpoints, and the line segment between every two endpoints is the midpoint connecting line segment.
[0079] Step 2033: Taking the starting endpoints of the midpoint line segments as target points, determine the vertical lines passing through the target points and perpendicular to the midpoint line segments where the corresponding target points are located.
[0080] In this step, the leftmost starting endpoint of each midpoint line segment is taken as the target point, and a vertical line is drawn through the target point and perpendicular to the midpoint line segment where the target point is located, and the segmentation quantity value plus 2 vertical lines can be obtained.
[0081] For example, Figure 3 As shown in step g in , draw vertical lines at each endpoint. The 10 vertical lines in the figure are vertical lines.
[0082] Step 2034: for each vertical line, determine a pair of coordinate points whose distance from the target point included in the vertical line is half the height of the text.
[0083] In this step, on each vertical line, two coordinate points are taken at the upper and lower ends of the target point to form a coordinate point pair, with the target point as the center, and multiple coordinate point pairs can be obtained. Among them, the distance between the two coordinate points included in a coordinate point pair and the target point is half the height of the text.
[0084] For example, Figure 3 As shown in step h in , a coordinate point pair is taken on each vertical line, and the distance between each coordinate in the coordinate point pair and the target point is h / 2.
[0085] Step 2035: record each pair of coordinate points as a control point pair to form a control point set corresponding to the text line contour image after the segmentation operation.
[0086] In this step, the coordinate point pairs obtained according to the above steps are recorded as control point pairs, and all control point pairs on the text line contour image are combined into a corresponding control point set after the segmentation operation.
[0087] For example, if the text line contour image is segmented three times according to different segmentation quantity values, three control point sets can be obtained, and each segmentation operation can obtain multiple control point pairs.
[0088] Step 204: For each control point set, sequentially associate each control point pair included in the control point set with the text image to be corrected.
[0089] In this step, each control point pair included in the three control point sets obtained after the three segmentation operations needs to be associated with the text image to be corrected in sequence. Taking a control point set as an example, all control points included in the control point set are associated with the text image to be corrected according to the coordinates of all control points included in the control point set.
[0090] For example, Figure 3 The image on the left in step i in is the text image to be corrected, and all the points on the image are the points obtained by associating the control point set on the text image to be corrected.
[0091] Step 205: Generate a blank image with the same height as the text image to be corrected, and evenly add a second number of reference points on the two long borders of the blank image, and determine two reference points with the same horizontal coordinate as a reference point pair.
[0092] The second number is the same as the number of control points included in the control point set.
[0093] In this embodiment, this step is performed on the three text images to be corrected with different control point sets obtained in step 204 .
[0094] In this step, a text image to be corrected with a set of control points is described. First, a blank image with the same size as the text image to be corrected is generated. Then, reference points with the same number as the control points in the set of control points can be evenly selected on the two long borders of the blank image, such as Figure 3 This is shown in the image on the right in step i.
[0095] Among them, two reference points with the same horizontal coordinates can be determined as a reference point pair, such as Figure 3 As shown in step i, 10 reference point pairs can be obtained.
[0096] Step 206: Determine the corrected text image corresponding to the control point set according to each control point pair and the reference point pair.
[0097] Similarly, the corrected text image obtained in this step may include three corrected text images obtained by performing three perspective transformations respectively after three segmentation operations with different segmentation quantity values.
[0098] Figure 5 The following is a flow chart of determining a corrected text image in a text correction method provided in Embodiment 2 of the present invention. The following is an example of obtaining a corrected text image. Figure 5 As shown, step 206 may include the following steps:
[0099] Step 2061: Use two adjacent control point pairs in the control point set in sequence to form a source perspective transformation point group.
[0100] In this step, two adjacent control point pairs are sequentially obtained in the text line contour image to form a source perspective transformation point group, such as Figure 3 The left image in step i includes 9 source perspective transformation point groups.
[0101] Step 2062: For each source perspective transformation point group, two adjacent reference point pairs in the same order on the blank image are used to form a corresponding target perspective transformation point group, and the source text corresponding to the source perspective transformation point group on the image to be corrected is determined.
[0102] In this step, according to each source perspective transformation point group, adjacent reference point pairs are formed into multiple target perspective transformation point groups on the blank image. Figure 3 In step i, the right image includes 9 target perspective transformation point groups.
[0103] Wherein, determining the source text corresponding to the source perspective transformation point group on the text image to be corrected can be understood as a source perspective transformation point group can form a rectangular frame, and the rectangular frame can correspond to the text, such as Figure 3As shown in step i, the text corresponding to the rectangle formed by the two adjacent control point pairs on the left side of the left image in step i, that is, a source perspective transformation point group, is "I".
[0104] According to the above method, all characters in the text line of the text image to be corrected can be matched through the source perspective transformation point group.
[0105] Step 2063: Map the source text onto the blank image by performing perspective transformation on the source perspective transformation point group and the target perspective transformation point group.
[0106] In this step, the source characters in the text line in the text image to be corrected corresponding to each source perspective transformation point group are mapped into the rectangular frame formed by each target perspective transformation point group on the blank image.
[0107] Step 2064: determine the blank image containing each source text in the image to be corrected as the corrected text image corresponding to the control point set.
[0108] In this step, the corrected text image can be an image obtained by mapping the source text on a blank image. It should be noted that each control point set can correspond to a corrected text image. Figure 3 As shown in step j, step j is to obtain a corrected text image based on a set of control points.
[0109] Step 207: Filter the target text image from the corrected text images, and obtain the text recognition result corresponding to the target text image.
[0110] In this embodiment, three corrected text images can be obtained after executing the above steps. Furthermore, it is necessary to determine a corrected image with the most accurate text recognition result among the three corrected text images as the target text image.
[0111] Figure 6 The following is a flow chart of obtaining text recognition results in a text correction method provided in Embodiment 2 of the present invention. Figure 6 As shown, step 207 may include the following steps:
[0112] Step 2071: For each corrected text image, input the corrected text image into a preset text recognition model to obtain the text contained in the corrected text image and the corresponding prediction probability.
[0113] In this step, the preset text recognition model can be any pre-set model with a text recognition function. For example, the text recognition model can be a fully convolutional neural network (FCN) and a recognition network CRNN.
[0114] The three text correction images are input into the preset text recognition model, and the predicted probability of all the texts and each character included in each correction text image can be output.
[0115] Step 2072: Count the number of characters in the text, and determine the average prediction probability of the corrected text image based on the prediction probability of each character and the number of characters.
[0116] In this step, the number of words included in the three corrected text images is counted respectively, and the prediction probability of the words corresponding to the three corrected text images is calculated. The words may include characters.
[0117] Exemplarily, taking the calculation of the text prediction probability corresponding to a corrected text image as an example, if the text line of the corrected text image includes 4 characters, and the prediction probability of each character is 0.3, 0.7, 0.9 and 0.5 respectively, then (0.3+0.7+0.8+0.6) / 4=0.6 can be calculated, and 0.6 is taken as the average prediction probability of the text corrected image.
[0118] Step 2073: Use the corrected text image corresponding to the maximum predicted probability average value as the target text image, and use the text contained in the target text image as the text recognition result.
[0119] In this step, the maximum prediction probability average value can be determined according to the prediction probability average values corresponding to the three corrected images, and the corrected text image corresponding to the maximum prediction probability average value is the target text image.
[0120] The following is a specific example to illustrate the above steps 201 to 207. Figure 3 As shown, it mainly includes the following steps:
[0121] Step a: cutting out a text line contour image from the binary image according to the minimum bounding rectangle of the text line in the text line image to be corrected.
[0122] Step b: Calculate the contour angle of the text line contour by using the least square method according to the coordinates of each contour point in the text line contour image; and evenly select N segmentation positions in the text line contour image.
[0123] Step c: traverse the pixel points in the horizontal direction of the segmentation position on the text line contour image to find the intersection of the segmentation line, that is, the segmentation line segment and the text line contour.
[0124] Step d: Take the distance between the two intersection points on each segment line to obtain N distances, i.e., the length of the line segment.
[0125] Step e: take the average value of the N distances as the height h of the text.
[0126] Step f, take the midpoint of the two intersection points on each segmentation line, that is, the midpoint of the segmentation line segment, connect the midpoints to obtain the central skeleton of the text line, that is, sequentially connect the midpoints and the connecting line segments corresponding to the first and last midpoints respectively; extend the central skeleton to the left and right sides to obtain the intersection points of the central skeleton and the left and right boundaries of the text line contour image, and use these two intersection points as the intersection points of the two ends of the text line, and use the obtained midpoint and the two intersection points as endpoints on the central skeleton. The lines between the endpoints, that is, the midpoint connecting line segments, constitute the endpoint connecting lines.
[0127] Step g, draw perpendicular lines on each end point of the central skeleton, i.e., take the starting end point of each midpoint line segment as the target point, and determine each perpendicular line passing through each target point and perpendicular to the midpoint line segment where the corresponding target point is located.
[0128] Step h: select two control points, i.e., coordinate point pairs, on each vertical line. The two control points are located above and below the endpoint, respectively, and the distance from the endpoint is h / 2.
[0129] Step i, determine the corresponding control points on the text line image to be corrected, that is, associate each control point pair included in the control point set with the text line image to be corrected in sequence, generate a blank image of the same size as the text line image to be corrected, and evenly select points on the blank image, the number of points is the same as the control points, and a second number of reference points are evenly added as corresponding points of the control points.
[0130] Step j: every four adjacent control points are a group of perspective transformation control points, namely, a source perspective transformation point group, and N+1 perspective transformations are performed to map the text line image to be corrected onto a blank image to obtain a corrected image.
[0131] Step k, set N to N-1 and re-execute steps 3 to 11 to obtain a new corrected text image; set N to N+1 and re-execute steps 3 to 11 to obtain another new corrected text image, that is, a total of three corrected text images can be obtained; input the three corrected text images into the text recognition model to obtain three recognition results.
[0132] Finally, the average prediction probability of all characters in each corrected text image is calculated, and the corrected text image corresponding to the maximum average prediction probability is taken as the final segmentation result.
[0133] Furthermore, the text correction method may also include the following contents: inputting the original image as input data into a preset neural network model to obtain a text score map of the original image; determining the text line image to be corrected in the original image and the text line contour image of the text line image to be corrected by binarizing and clipping the text score map.
[0134] Among them, the preset neural network model can be a convolutional neural network, and the convolutional neural network can include networks such as a fully convolutional network and a U-net; the text score map can include the probability score of each pixel in the original image that a text line is missing, and the text score map can be exactly the same size as the original image; the original image can be an image including text lines that has not been processed in any way.
[0135] The process of determining the text line image to be corrected is described below with a specific example. Figure 7 This is an example diagram of a process of obtaining a text line image to be corrected in a text correction method provided in Embodiment 2 of the present invention, such as Figure 7 As shown, the process of obtaining the text line image to be corrected may include the following steps:
[0136] Step 1: Input the original image into the convolutional neural network to obtain the text score map.
[0137] Step 2: Binarize the text score map. Set a threshold according to the application scenario, determine the pixels in the original image with a score greater than the threshold as text, and determine the pixels with a score less than the threshold as background. A binary image of the same size as the original image can be obtained.
[0138] Step 3: Get the text line from the binary image, connect the adjacent points at the top, bottom, left, right, upper left, lower left, upper right and lower right of the text line into an area to get the connected domain of the text line, and extract and process the coordinates of the edge of the connected domain to get the coordinates of the text line contour.
[0139] Step 4: Determine the minimum bounding rectangle of the text line based on the text line contour coordinates.
[0140] Step 5: The text line image to be corrected can be cropped from the original image according to the coordinates of the minimum circumscribed rectangle.
[0141] Step 6: Cut out the text line contour image from the binary image according to the coordinates of the minimum circumscribed rectangle.
[0142] A text correction method provided in the second embodiment of the present invention is further refined on the basis of the scheme provided in the first embodiment, and further obtains a text recognition result after obtaining the corresponding corrected text images. In this method, the text line image to be corrected is segmented and the control point set is determined to accurately determine the text in the text line in the image to be corrected, and the text in the text line image to be corrected is perspectively transformed according to the source perspective transformation point group and the target perspective transformation point group to map it to a blank image, and the curvature of the text line in the corrected text image is greatly improved, and a more accurate text recognition rate can be obtained by inputting the corrected text image into a text recognition model, which greatly improves the accuracy of text recognition.
[0143] Embodiment 3
[0144] Figure 8 This is a structural schematic diagram of a text correction device provided in Example 3 of the present invention, which can be used to correct curved text lines in text images, wherein the text correction device can be implemented by software and / or hardware and is generally integrated on a computer device.
[0145] like Figure 8 As shown, the device includes the following modules: an acquisition module 81 , a determination module 82 and a correction module 83 .
[0146] The acquisition module 81 is used to acquire the text line image to be corrected and the text line contour image.
[0147] Optionally, the acquisition module 81 is specifically used to input the original image as input data into a preset neural network model to obtain a text score map of the original image; by binarizing and clipping the text score map, the text line image to be corrected in the original image and the text line contour image of the text line image to be corrected are determined.
[0148] The determination module 82 is used to determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine the control point set corresponding to the text line contour image after each segmentation operation.
[0149] Optionally, the determination module 82 includes a first determination module for determining at least one segmentation quantity value. The first determination module is specifically used to determine the contour angle of the text line contour by the least square method according to the contour point coordinate information of the text line contour in the text line contour image; search the preset data association table to determine the reference value corresponding to the contour angle; and record the reference value, the reference value plus 1, and the reference value minus 1 as the segmentation quantity values.
[0150] Optionally, the determination module 82 includes a first determination unit, which is used to determine a set of control points corresponding to the text line contour image after each segmentation operation.
[0151] The first determination unit is specifically used for: for each segmentation quantity value, vertically segmenting along the long border of the text line contour image, obtaining segmentation line segments formed by the segmentation quantity value intersecting with the text line contour, and determining the segment length of each segmentation line segment; according to the endpoint coordinate information of each segmentation line segment and the corresponding segment length, determining the control point set corresponding to the text line contour image after the segmentation operation.
[0152] Furthermore, the first determining unit further includes a first subunit, which is used to determine a set of control points corresponding to the text line contour image after the segmentation operation according to the endpoint coordinate information of each segmentation line segment and the corresponding line segment length.
[0153] The first subunit is specifically used for: determining the average value of the length of each line segment as the text height, and determining the midpoint of each segmentation line segment according to the endpoint coordinate information of each segmentation line segment; sequentially connecting the midpoints and extending the line segments corresponding to the first and last midpoints until they intersect with the text line contour to form a first number of midpoint line segments, where the first number is the segmentation number value plus 1; taking the starting endpoint of each midpoint line segment as the target point, determining each vertical line passing through each target point and perpendicular to the midpoint line segment where the corresponding target point is located; for each vertical line, determining a coordinate point pair whose distance value from the target point included in the vertical line is half the text height; recording each coordinate point pair as a control point pair to form a control point set corresponding to the text line contour image after the segmentation operation.
[0154] The correction module 83 is used to perform perspective transformation on the text images to be corrected according to each set of control points to obtain corresponding corrected text images.
[0155] Optionally, the correction module 83 is specifically used to: for each control point set, sequentially associate each control point pair included in the control point set with the text image to be corrected; generate a blank image with the same height as the text image to be corrected, and evenly add a second number of reference points on the two long borders of the blank image, and determine two reference points with the same horizontal coordinate as a reference point pair, and the second number is the same as the number of control points included in the control point set; determine the corrected text image corresponding to the control point set based on each control point pair and the reference point pair.
[0156] Optionally, the correction module 83 includes a correction unit, which is used to determine a corrected text image corresponding to the control point set according to each control point pair and the reference point pair.
[0157] The correction unit is specifically used for: sequentially using two adjacent control point pairs in the control point set to form a source perspective transformation point group; for each source perspective transformation point group, using two adjacent reference point pairs in the same order on a blank image to form a corresponding target perspective transformation point group, and determining the source text corresponding to the source perspective transformation point group on the image to be corrected; mapping the source text to the blank image by performing perspective transformation on the source perspective transformation point group and the target perspective transformation point group; and determining the blank image containing each source text in the image to be corrected as the corrected text image corresponding to the control point set.
[0158] Optionally, the text correction device further includes a screening module for screening a target text image from each correction text image and obtaining a text recognition result corresponding to the target text image.
[0159] Specifically, the screening module is used to: for each corrected text image, input the corrected text image into a preset text recognition model to obtain the text contained in the corrected text image and the corresponding prediction probability; count the number of characters contained in the text, and determine the average prediction probability of the corrected text image based on the prediction probability of each character and the number of characters; use the corrected text image corresponding to the maximum prediction probability average as the target text image, and use the text contained in the target text image as the text recognition result.
[0160] The above-mentioned text correction device can execute the text correction method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0161] Embodiment 4
[0162] Fig. 9 This is a schematic diagram of the structure of a computer device provided in Embodiment 4 of the present invention. Fig. 9 As shown, the computer device provided by the fourth embodiment of the present invention includes: one or more processors 91 and a memory 92; the number of the processors 91 in the computer device can be one or more, Fig. 9 A processor 91 is taken as an example; the processor 91 and the memory 92 of the computer device can be connected by a bus or other means. Fig. 9 The example of connecting through bus is taken in the following.
[0163] The memory 92 is a computer-readable storage medium that can be used to store one or more programs, which can be software programs, computer executable programs and modules, such as program instructions and modules corresponding to the text correction method provided in the embodiment of the present invention (for example, the modules in the text correction device include: acquisition module 81, determination module 82 and correction module 83). The processor 91 executes various functional applications and data processing of the computer device by running the software programs, instructions and modules stored in the storage device 92, that is, realizing the text correction method in the above method embodiment.
[0164] The memory 92 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 92 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 92 may further include a memory remotely arranged relative to the processor 91, and these remote memories may be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0165] Furthermore, when one or more programs included in the above-mentioned computer device are executed by the one or more processors 91, the program performs the following operations:
[0166] Acquire a text line image to be corrected and a text line contour image, wherein the text line contour image is a binary image corresponding to the text line image to be corrected;
[0167] Determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine a control point set corresponding to the text line contour image after each segmentation operation;
[0168] The text images to be corrected are perspective transformed according to the control point sets to obtain corresponding corrected text images.
[0169] Embodiment 5
[0170] Embodiment 5 of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it is used to perform a text correction method. The method includes:
[0171] Acquire a text line image to be corrected and a text line contour image, wherein the text line contour image is a binary image corresponding to the text line image to be corrected;
[0172] Determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine a control point set corresponding to the text line contour image after each segmentation operation;
[0173] The text images to be corrected are perspective transformed according to the control point sets to obtain corresponding corrected text images.
[0174] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the operations of the method described above, and can also execute related operations in the text correction method provided by any embodiment of the present invention.
[0175] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0176] It is worth noting that in the embodiment of the above-mentioned text correction device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0177] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A text correction method, characterized in that: include: Acquire a text line image to be corrected and a text line contour image, wherein the text line contour image is a binary image corresponding to the text line image to be corrected; Determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine a control point set corresponding to the text line contour image after each segmentation operation; Perspectively transform the text line images to be corrected according to the control point sets to obtain corresponding corrected text images; The determining of at least one segmentation quantity value comprises: Determining the contour angle of the text line contour by a least square method according to the contour point coordinate information of the text line contour in the text line contour image; Searching a preset data association table to determine a reference value corresponding to the contour angle; The reference value, the reference value plus 1, and the reference value minus 1 are recorded as the division quantity values respectively.
2. The method according to claim 1, characterized in that The step of segmenting the text line contour image according to each segmentation quantity value and determining a set of control points corresponding to the text line contour image after each segmentation operation includes: For each segmentation quantity value, segmentation is performed vertically along the long border of the text line contour image to obtain segmentation line segments formed by the segmentation quantity value intersecting with the text line contour, and the segment length of each segmentation line segment is determined; According to the endpoint coordinate information of each segmented line segment and the corresponding line segment length, a set of control points corresponding to the text line contour image after the segmentation operation is determined.
3. The method according to claim 2, characterized in that Determining a set of control points corresponding to the text line contour image after the segmentation operation according to the endpoint coordinate information of each segmentation line segment and the corresponding line segment length, including: Determine the average value of the lengths of each segment as the text height, and determine the midpoint of each segment according to the endpoint coordinate information of each segment; Sequentially connect the midpoints and extend the line segments corresponding to the first and last midpoints until they intersect with the text line outline to form a first number of midpoint line segments, where the first number is the segmentation number value plus 1; Taking the starting endpoints of the midpoint line segments as target points, respectively determine the vertical lines passing through the target points and being perpendicular to the midpoint line segments where the corresponding target points are located; For each vertical line, determine a pair of coordinate points whose distance from a target point included in the vertical line is half the height of the text; Each of the coordinate point pairs is recorded as a control point pair to form a control point set corresponding to the text line contour image after the segmentation operation.
4. The method according to claim 1, characterized in that: The perspective transformation of the to-be-corrected text line images according to the control point sets to obtain corresponding corrected text images comprises: For each control point set, sequentially associating each control point pair included in the control point set to the text line image to be corrected; Generate a blank image with the same height as the text line image to be corrected, and evenly add a second number of reference points on two long borders of the blank image, and determine two reference points with the same horizontal coordinate as a reference point pair, wherein the second number is the same as the number of control points included in the control point set; According to each of the control point pairs and the reference point pairs, a corrected text image corresponding to the control point set is determined.
5. The method according to claim 4, characterized in that Determining, according to each of the control point pairs and the reference point pairs, a corrected text image corresponding to the control point set, comprising: Sequentially using two adjacent control point pairs in the control point set to form a source perspective transformation point group; For each source perspective transformation point group, two adjacent reference point pairs in the same order on the blank image are used to form a corresponding target perspective transformation point group, and the source text corresponding to the source perspective transformation point group on the text line image to be corrected is determined; Mapping the source text onto the blank image by performing perspective transformation on the source perspective transformation point group and the target perspective transformation point group; A blank image containing each source character in the to-be-corrected text line image is determined as a corrected text image corresponding to the control point set.
6. The method according to claim 1, characterized in that After the perspective transformation of the text line images to be corrected is performed according to the control point sets to obtain the corresponding corrected text images, the method further includes: A target text image is selected from each of the corrected text images, and a text recognition result corresponding to the target text image is obtained.
7. The method according to claim 6, characterized in that The step of selecting a target text image from each of the corrected text images and obtaining a text recognition result corresponding to the target text image includes: For each corrected text image, the corrected text image is input into a preset text recognition model to obtain the text contained in the corrected text image and the corresponding prediction probability; Counting the number of characters in the included characters, and determining an average prediction probability of the corrected text image according to the prediction probability of each character and the number of characters; The corrected text image corresponding to the maximum predicted probability average value is used as the target text image, and the text contained in the target text image is used as the text recognition result.
8. The method according to any one of claims 1 to 7, characterized in that: Also includes: Inputting the original image as input data into a preset neural network model to obtain a text score map of the original image; The text line image to be corrected and the text line contour image of the text line image to be corrected in the original image are determined by binarization and cutout processing of the text score image.
9. A text correction device, characterized in that: include: An acquisition module, used for acquiring a text line image to be corrected and a text line contour image, wherein the text line contour image is a binary image corresponding to the text line image to be corrected; A determination module, used to determine at least one segmentation quantity value, and segment the text line contour image according to each segmentation quantity value, and determine a control point set corresponding to the text line contour image after each segmentation operation; A correction module, used for perspective transforming the text line images to be corrected according to the control point sets to obtain corresponding corrected text images; The determination module includes a first determination module, which is used to determine at least one segmentation quantity value; the first determination module is specifically used to determine the contour angle of the text line contour by the least squares method based on the contour point coordinate information of the text line contour in the text line contour image; search the preset data association table to determine the benchmark value corresponding to the contour angle; and record the benchmark value, the benchmark value plus 1, and the benchmark value minus 1 as the segmentation quantity values respectively.
10. A computer device, characterized in that: The computer device comprises: one or more processors; A memory for storing one or more programs; The one or more programs are executed by the one or more processors, so that the one or more processors implement the text correction method according to any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the text correction method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Character image labeling method and device and computer readable storage medium
CN109685059A
Nameplate text detection method and device, computer equipment and storage medium
CN110796082A
Text image tilt correction method, system and device and storage medium
CN111553344A
Text line character segmentation method and device based on projection
CN111967474A
Image data input processing method and its device
JP1997091376A
