Text image correction method and device
By determining N+1 sets of reference points for the main outline in the text image for correction, the problem of low accuracy in recognizing curved text lines is solved, and the recognition effect is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHUHAI KINGSOFT OFFICE SOFTWARE
- Filing Date
- 2022-06-09
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, the accuracy of recognizing curved text lines is low, which affects the reading experience.
By extracting the text line outline from the original text image, determining the main outline, and setting N+1 sets of first reference points, and then determining N+1 sets of second reference points for the corrected text image based on these reference points, the text line image is corrected to obtain the corrected text image.
It improves the accuracy of curved text recognition and enhances the reading experience.
Smart Images

Figure CN117252767B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a method and apparatus for text image correction. Background Technology
[0002] With the development of image processing technology, people often need to perform text recognition on photos and images containing text to meet diverse usage needs, such as recognizing and extracting text from photos.
[0003] In related technologies, text recognition of photos, images, etc., usually requires text detection first, and then the detected text is directly fed into a text recognition model for text recognition.
[0004] However, in practical applications, many photos and images contain curved text lines. When text recognition models attempt to identify curved text lines, the accuracy of the recognition results is significantly reduced, impacting the reading experience. Therefore, how to correct curved text lines in images is a pressing issue that needs to be addressed. Summary of the Invention
[0005] To address the problems existing in the prior art, embodiments of the present invention provide a text image correction method and apparatus.
[0006] This invention provides a text image correction method, comprising:
[0007] Extract at least one text line outline from the original text image, and determine the main outline from the text line outline;
[0008] When the main contour is a curved contour, N+1 sets of first reference points are determined for the main contour; N is a positive integer.
[0009] Based on the N+1 sets of first reference points, determine N+1 sets of second reference points for the corrected text image; each set of first reference points corresponds to a set of second reference points.
[0010] Based on the N+1 sets of first reference points and the N+1 sets of second reference points, the text line image corresponding to the main contour is corrected to obtain the corrected text image.
[0011] Optionally, determining the N+1 sets of first reference points for the main contour includes:
[0012] The main contour is divided into N sub-contour units;
[0013] Determine the N+1 sets of first reference points corresponding to the N sub-contour units;
[0014] The N sub-contour units include one first sub-contour unit, one second sub-contour unit, and N-2 third sub-contour units; the first sub-contour unit and the second sub-contour unit are located at both ends of the main contour; each third sub-contour unit corresponds to two equal dividing lines; two adjacent third sub-contour units share a set of first reference points; N is greater than or equal to 3.
[0015] The N+1 group of first reference points includes the first reference point corresponding to the third sub-contour unit, the first reference point corresponding to the first sub-contour unit, and the first reference point corresponding to the second sub-contour unit.
[0016] Optionally, determining the N+1 sets of first reference points corresponding to the N sub-contour units includes:
[0017] Two equal dividing lines corresponding to the third sub-contour unit are determined, and two sets of first reference points corresponding to the two equal dividing lines are determined, wherein each set of first reference points includes an upper reference point and a lower reference point.
[0018] The two sets of first reference points corresponding to the two equal dividing lines are determined as the two sets of first reference points corresponding to the third sub-contour unit.
[0019] Based on the vertices of the minimum bounding rectangle of the first sub-contour unit, a set of first reference points corresponding to the first sub-contour unit is determined.
[0020] Based on the vertices of the minimum bounding rectangle of the second sub-contour unit, a set of first reference points corresponding to the second sub-contour unit is determined.
[0021] Optionally, determining the two sets of first reference points corresponding to the two equal dividing lines includes:
[0022] For each of the equal dividing lines, starting from the upper vertex of the equal dividing line, query downwards the pixel value of each pixel in the text line image corresponding to the third sub-contour unit, and determine the pixel point with the pixel value of the preset value as the upper bound reference point corresponding to the third sub-contour unit; and starting from the lower vertex of the equal dividing line, query upwards the pixel value of each pixel in the text line image corresponding to the third sub-contour unit, and determine the pixel point with the pixel value of the preset value as the lower bound reference point corresponding to the third sub-contour unit.
[0023] Optionally, determining the N+1 sets of second reference points for the corrected text image based on the N+1 sets of first reference points includes:
[0024] The width of the corrected text image is determined based on the difference between the coordinates of the upper and lower bound reference points of each group of first reference points.
[0025] The length of the corrected text image is determined based on the distance between adjacent reference points in the N+1 groups of first reference points;
[0026] Based on the width and the length, the corrected text image is divided into N equal image regions. Based on the vertices of each image region, N+1 sets of second reference points are determined for the corrected text image.
[0027] Optionally, the step of correcting the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain the corrected text image includes:
[0028] Based on the coordinates of the N+1 sets of first reference points, a first matrix is determined; the first matrix includes: the coordinates of the N+1 sets of first reference points and the coordinates of pixels in the text line image corresponding to the main contour.
[0029] Based on the coordinates of the N+1 sets of second reference points, a second matrix is determined; the second matrix includes: the coordinates of the N+1 sets of second reference points and the coordinates of the pixels corresponding to the corrected text image;
[0030] The coordinates of the pixels in the text line image corresponding to the main outline are interpolated to the coordinates of the pixels in the corrected text image to obtain the corrected text image.
[0031] Optionally, the step of extracting at least one text line outline from the original text image and determining the main outline from the text line outline includes:
[0032] Detect at least one text segmentation binary image in the original text image, and extract the text line outlines corresponding to each text segmentation binary image;
[0033] Calculate the area of each text line contour, and determine the text line contour with the largest area as the main contour.
[0034] Optionally, detecting at least one text segmentation binary image in the original text image and extracting the text line contours corresponding to each text segmentation binary image includes:
[0035] The original text image is subjected to text detection processing to obtain a text segmentation binary image and a text detection box;
[0036] Contour lookup is performed on the text segmentation binary image within each text detection box to obtain the text line contours corresponding to each text segmentation binary image.
[0037] Optionally, after determining the main contour from the text line contour, the method further includes:
[0038] Determine the area of the main contour and the area of the text detection box corresponding to the main contour;
[0039] Determine the ratio of the area of the main contour to the area of the text detection box;
[0040] If the ratio is less than a preset threshold, the main contour is determined to be a curved contour.
[0041] The present invention also provides a text image correction device, comprising:
[0042] An extraction module is used to extract at least one text line outline from the original text image and determine the main outline from the text line outline.
[0043] The first reference point determination module is used to determine N+1 sets of first reference points for the main contour when the main contour is a curved contour; N is a positive integer.
[0044] The second reference point determination module is used to determine N+1 sets of second reference points for the corrected text image based on the N+1 sets of first reference points; each set of first reference points corresponds to a set of second reference points.
[0045] The correction module is used to correct the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain the corrected text image.
[0046] Optionally, the first reference point determination module is further used for:
[0047] Divide the main contour into N sub-contour units;
[0048] Determine the N+1 sets of first reference points corresponding to the N sub-contour units;
[0049] The N sub-contour units include one first sub-contour unit, one second sub-contour unit, and N-2 third sub-contour units; the first and second sub-contour units are located at both ends of the main contour; each third sub-contour unit corresponds to two equal dividing lines; two adjacent third sub-contour units share a set of first reference points; N is greater than or equal to 3.
[0050] The first reference point of group N+1 includes the first reference point corresponding to the third sub-contour unit, the first reference point corresponding to the first sub-contour unit, and the first reference point corresponding to the second sub-contour unit.
[0051] Optionally, the first reference point determination module is further used for:
[0052] Determine the two equal dividing lines corresponding to the third sub-contour unit, and determine the two sets of first reference points corresponding to the two equal dividing lines. Each set of first reference points includes an upper reference point and a lower reference point.
[0053] The two sets of first reference points corresponding to the two equal dividing lines are determined as the two sets of first reference points corresponding to the third sub-contour unit.
[0054] Based on the vertices of the minimum bounding rectangle of the first sub-contour unit, determine a set of first reference points corresponding to the first sub-contour unit;
[0055] Based on the vertices of the minimum bounding rectangle of the second sub-contour unit, a set of first reference points corresponding to the second sub-contour unit is determined.
[0056] Optionally, the first reference point determination module is further used for:
[0057] For each equal dividing line, starting from the upper vertex of the equal dividing line, query the pixel value of each pixel in the text line image corresponding to the third sub-contour unit downwards, and determine the pixel value of the pixel with the preset value as the upper bound reference point corresponding to the third sub-contour unit; and starting from the lower vertex of the equal dividing line, query the pixel value of each pixel in the text line image corresponding to the third sub-contour unit upwards, and determine the pixel value of the pixel with the preset value as the lower bound reference point corresponding to the third sub-contour unit.
[0058] Optionally, the second reference point determination module is further used for:
[0059] The width of the corrected text image is determined based on the difference between the coordinates of the upper and lower bound reference points of each group of first reference points.
[0060] The length of the corrected text image is determined based on the distance between adjacent reference points in the first reference point group N+1.
[0061] Based on the width and length, the corrected text image is divided into N equal image regions. Based on the vertices of each image region, N+1 sets of second reference points are determined for the corrected text image.
[0062] Optionally, the correction module is further used for:
[0063] Based on the coordinates of the N+1 sets of first reference points, a first matrix is determined; the first matrix includes: the coordinates of the N+1 sets of first reference points and the coordinates of the pixels in the text line image corresponding to the main contour.
[0064] Based on the coordinates of the N+1 sets of second reference points, a second matrix is determined; the second matrix includes: the coordinates of the N+1 sets of second reference points and the coordinates of the pixels corresponding to the corrected text image.
[0065] The coordinates of the pixels in the text line image corresponding to the main outline are interpolated to the coordinates of the corresponding pixels in the corrected text image to obtain the corrected text image.
[0066] Optionally, the extraction module is further used for:
[0067] Detect at least one text segmentation binary image in the original text image and extract the text line outlines corresponding to each text segmentation binary image;
[0068] Calculate the area of each text line outline and determine the text line outline with the largest area as the main outline.
[0069] Optionally, the extraction module is further used for:
[0070] Text detection processing is performed on the original text image to obtain a text segmentation binary image and a text detection box;
[0071] Contour lookup is performed on the text segmentation binary image within each text detection box to obtain the text line contours corresponding to each text segmentation binary image.
[0072] Optionally, the device further includes:
[0073] The first determining module is used to determine the area of the main contour and the area of the text detection box corresponding to the main contour.
[0074] The second determining module is used to determine the ratio of the contour area of the main contour to the area of the text detection box;
[0075] The third determining module is used to determine that the main contour is a curved contour when the ratio is less than a preset threshold.
[0076] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the text image correction method as described above.
[0077] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the text image correction method as described above.
[0078] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the text image correction method as described above.
[0079] The text image correction method and apparatus provided by this invention extracts at least one text line contour from the original text image and determines the main contour from the text line contour. If the main contour is curved, N+1 sets of first reference points are determined, thereby accurately determining the position of the text line image corresponding to the main contour in the original text image. Then, based on the N+1 sets of first reference points, N+1 sets of second reference points are determined for the corrected text image. Based on the N+1 sets of first and second reference points, the text line image corresponding to the main contour is corrected, resulting in a corrected text image. By performing text recognition on the corrected text image, the accuracy of curved text recognition can be improved. Attached Figure Description
[0080] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0081] Figure 1 This is a flowchart illustrating the text-image correction method provided by the present invention;
[0082] Figure 2 This is a schematic diagram of the N+1 group of first reference points provided by the present invention;
[0083] Figure 3 This is a schematic diagram of the text line outline provided by the present invention;
[0084] Figure 4 This is a schematic diagram of the text detection box coordinate system provided by the present invention;
[0085] Figure 5 This is a schematic diagram of the text image correction method provided by the present invention;
[0086] Figure 6 This is a schematic diagram of the original text image provided by the present invention;
[0087] Figure 7 This is a schematic diagram of the N+1 group of second reference points provided by the present invention;
[0088] Figure 8 This is a schematic diagram of the text and image correction device provided by the present invention;
[0089] Figure 9 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0090] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0091] With the development of image processing technology, people often need to perform text recognition on photos and images containing text to meet diverse usage needs, such as recognizing and extracting text from photos.
[0092] Currently, Optical Character Recognition (OCR) technology is generally used to recognize text images such as photos and pictures. The general OCR recognition process is to first perform text detection on the text image, then map the detection boxes back to the original image, crop the text lines, and then directly feed them into the text recognition model.
[0093] However, in practical applications, many photos and images contain curved text lines. When text recognition models recognize curved text lines, the accuracy of the recognition results will be greatly reduced, affecting people's reading experience.
[0094] In view of the above-mentioned problems, the present invention provides a text image correction method and apparatus, thereby correcting curved text lines in text images and improving the accuracy of curved text recognition when performing text recognition on text images.
[0095] The following is combined with Figures 1-7 This invention describes a text image correction method.
[0096] See Figure 1 , Figure 1 This is a flowchart illustrating the text image correction method provided by the present invention, specifically including steps 101-104:
[0097] Step 101: Extract at least one text line outline from the original text image, and determine the main outline from the text line outline.
[0098] It should be noted that the subject of this invention can be any electronic device with text and image correction function, such as any kind of smartphone, smartwatch, desktop computer, laptop, etc.
[0099] Specifically, in this embodiment, it is first necessary to obtain the original text image. In practical applications, the original text image can be in various formats, such as jpg, png, tif, or pdf. This invention does not limit the format of the original text image.
[0100] After obtaining the original text image, it is necessary to extract at least one text line outline from the original text image, wherein the text line outline contains the text lines in the original text image.
[0101] There are several ways to extract text line outlines from an original text image. For example, you can directly extract the text line outlines from the original text image; or you can convert the original text image into a binary image and then extract the text line outlines based on the binary image.
[0102] After extracting at least one text line outline, it is necessary to determine the main outline from the text line outline. It should be noted that the main outline is the outline corresponding to the text line image that needs to be corrected in each text line outline.
[0103] Step 102: When the main profile is a curved profile, determine the N+1 groups of first reference points of the main profile; N is a positive integer.
[0104] Specifically, in this embodiment, when determining the main contour from the text line contour and confirming that the main contour is a curved contour, it is necessary to determine N+1 sets of first reference points for the main contour. These first reference points are used to determine the position of the text line image corresponding to the main contour within the original text image. For example... Figure 2 As shown, Figure 2 This is a schematic diagram of the N+1 group of first reference points provided by the present invention. Figure 2 In the original text image, there are three text lines: "X", "Y", and "Z". The outline of the text line corresponding to "Y" in the original text image is determined as the main outline. Then, N+1 sets of first reference points are determined within this main outline. These N+1 sets of first reference points include reference point 1 to reference point 22. For example, reference point 1 and reference point 2 form a set of first reference points.
[0105] In practical applications, N can be set to 10, meaning that when the main contour is curved, 11 sets of first reference points are determined for the main contour. It should be noted that N is set to 10 because, based on dataset evaluation, setting N to 10 results in the highest accuracy for text recognition of the corrected text image after correcting it using the 11 sets of first reference points.
[0106] Step 103: Based on the N+1 sets of first reference points, determine the N+1 sets of second reference points for the corrected text image; each set of first reference points corresponds to a set of second reference points.
[0107] Specifically, in this embodiment, after determining the N+1 sets of first reference points for the main outline, it is necessary to determine the N+1 sets of second reference points for the corrected text image based on the N+1 sets of first reference points, with each set of first reference points corresponding to a set of second reference points. The second reference points are used to determine the position of text lines in the corrected text image, which is a rectangle.
[0108] In other words, each group of second reference points is determined based on each group of first reference points. Therefore, each group of first reference points corresponds to a group of second reference points.
[0109] Step 104: Based on the N+1 sets of first reference points and N+1 sets of second reference points, correct the text line image corresponding to the main outline to obtain the corrected text image.
[0110] Specifically, in this embodiment, after determining the N+1 sets of first reference points of the main contour and the N+1 sets of second reference points of the corrected text image, the text line image corresponding to the main contour is corrected based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain the corrected text image. The text line image can be all or part of the original text image, and the text lines in the corrected text image are non-curved text lines.
[0111] The text image correction method provided by this invention extracts at least one text line contour from the original text image and determines the main contour from the text line contour. If the main contour is curved, N+1 sets of first reference points are determined, thereby accurately determining the position of the text line image corresponding to the main contour in the original text image. Then, based on the N+1 sets of first reference points, N+1 sets of second reference points are determined for the corrected text image. Based on the N+1 sets of first and second reference points, the text line image corresponding to the main contour is corrected, resulting in a corrected text image. By performing text recognition on the corrected text image, the accuracy of curved text recognition can be improved.
[0112] The specific implementation of the text image correction method provided by this invention will be described in detail below.
[0113] Optionally, in one possible implementation of this invention, at least one text line outline is extracted from the original text image, and the main outline is determined from the text line outline. This can be achieved through the following steps, specifically including steps 1)-2):
[0114] Step 1) Detect at least one text segmentation binary image in the original text image and extract the text line outlines corresponding to each text segmentation binary image;
[0115] Step 2) Calculate the area of each text line outline and determine the text line outline with the largest area as the main outline.
[0116] Specifically, in this embodiment, it is first necessary to detect at least one text segmentation binary image in the original text image and extract the text line outlines corresponding to each text segmentation binary image.
[0117] In other words, the original text image first needs to be converted into a binary image, where a binary image is an image in which each pixel has only two possible values or grayscale levels.
[0118] In practical applications, there are several ways to convert original text images into binary images. For example, a pixel threshold can be set, setting pixels exceeding the threshold to black and pixels within the threshold to white, thus converting the original text image into a binary image. Alternatively, the original text image can be input into a trained neural network model, which will then convert it into a binary image.
[0119] After converting the original text image into a binary image, the binary image is segmented to obtain at least one segmented binary image as the text segmentation binary image. Then, at least one text segmentation binary image is detected, and the text line contours corresponding to each text segmentation binary image are extracted.
[0120] After extracting the text line contours corresponding to each text segmentation binary image, the area of each text line contour is calculated. Based on prior knowledge, the text line contour with the largest area is determined as the main contour. It should be noted that the reason for determining the text line contour with the largest area as the main contour is that, under normal circumstances, the text line image corresponding to the text line contour with the largest area in the original text image is the text line image that is expected to be text-corrected. Therefore, determining the text line contour with the largest area as the main contour and correcting the text line image corresponding to the main contour can avoid correcting the text line images that do not need correction, thereby improving the efficiency of text correction.
[0121] In the above implementation, by detecting at least one text segmentation binary image in the original text image and extracting the text line contours corresponding to each text segmentation binary image, and then calculating the area of each text line contour, the contours corresponding to the text line images that need to be corrected, i.e., the main contours, can be determined. Correcting the text line images corresponding to the main contours can avoid correcting the text line images that do not need to be corrected, thereby improving the efficiency of text correction.
[0122] Optionally, in one possible implementation of the embodiments of this specification, detecting at least one text segmentation binary image in the original text image and extracting the text line contours corresponding to each text segmentation binary image can be achieved through the following steps, specifically including steps 1.1)-1.2):
[0123] Step 1.1) Perform text detection processing on the original text image to obtain a text segmentation binary image and a text detection box;
[0124] Step 1.2) Perform contour query on the text segmentation binary image within each text detection box to obtain the text line contour corresponding to each text segmentation binary image.
[0125] In this embodiment, the original text image can be input into a trained text detection model, which is used to detect text lines in the original image. Specifically, there are various types of text detection models, such as pixel link models, differentiable binarization (DB) models, etc. This invention does not specifically limit the type of text detection model.
[0126] After inputting the original text image into the text detection model, a text segmentation binary image and a text detection box are obtained. The text segmentation binary image is obtained by segmenting the binary image output by the text detection model using the text detection boxes.
[0127] After obtaining the text segmentation binary image and the text detection box, it is necessary to perform contour query on the text segmentation position image within each text detection box to obtain the text line contour corresponding to each text segmentation binary image.
[0128] In other words, after segmenting the binary image output by the text detection model using the text detection box to obtain at least one text segmentation binary image, it is necessary to perform contour query on each text segmentation binary image to obtain the text line contour corresponding to each text segmentation binary image.
[0129] Contour querying of each text segmentation binary image refers to the process of extracting text contours by ignoring the influence of texture and noise interference within the background and text lines in the text segmentation binary image containing text lines and background, and using certain techniques and methods.
[0130] In practical applications, contour queries for each text segmentation binary image can be achieved in the following way: classify the pixels of each text segmentation binary image, determine whether the pixels belong to the text line, obtain the probability map of the text line region in the text segmentation binary image, and then perform post-processing on the probability map to obtain the enclosing curve of the text line region, that is, the text line contour corresponding to each text segmentation binary image.
[0131] For details on the text line outline, please refer to Figure 3 As shown, Figure 3 This is a schematic diagram of the text line outline provided by the present invention. Figure 3 In the image, the white area represents the text line outline, the black area represents the background of the text segmentation binary image, and the bounding rectangle corresponding to the text line outline is the text detection box.
[0132] In the above implementation, text detection processing is performed on the original text image to obtain a text segmentation binary image and a text detection box; then, contour query is performed on the text segmentation binary image in each text detection box to accurately obtain the text line contour corresponding to each text segmentation binary image, and thus the main contour can be accurately determined from each text line contour to achieve correction of the text line image corresponding to the main contour.
[0133] Optionally, in one possible implementation of this invention, after determining the main contour from the text line contour, it is also necessary to determine whether the main contour is a curved contour. If the main contour is a curved contour, the text line image corresponding to the main contour is then corrected.
[0134] Specifically, determining whether the main contour is a curved contour can be achieved through the following steps, including steps (1) to (3):
[0135] Step (1): Determine the outline area of the main outline and the area of the text detection box corresponding to the main outline;
[0136] Step (2): Determine the ratio of the area of the main outline to the area of the text detection box;
[0137] Step (3): If the ratio is less than the preset threshold, the main contour is determined to be a curved contour.
[0138] Specifically, in this embodiment, when determining whether the main contour is a curved contour, it is necessary to determine the contour area of the main contour and the area of the text detection box corresponding to the main contour; then calculate the ratio of the contour area of the main contour to the area of the text detection box, and if the ratio is less than a preset threshold, the main contour is determined to be a curved contour.
[0139] Under normal circumstances, the text detection box is a regular rectangle. If the main outline is a non-curved outline, the ratio of the area of the main outline to the area of the text detection box is close to 1. Conversely, if the main outline is a curved outline, the ratio of the area of the main outline to the area of the text detection box is less than 1.
[0140] Therefore, a preset threshold needs to be set. For example, if the preset threshold is 0.7, the ratio of the contour area of the main contour to the area of the text detection box is calculated. If the ratio is greater than 0.7, the main contour is determined to be a non-curved contour; if the ratio is less than 0.7, the main contour is determined to be a curved contour.
[0141] In the above implementation, after determining the main outline from the text line outline, the ratio of the outline area of the main outline to the area of the text detection box is determined to determine whether the main outline is a curved outline. If the main outline is a curved outline, the text line image corresponding to the main outline is corrected. By using the above method, it is possible to determine whether the main outline is a curved outline, thereby avoiding the need to correct text line images corresponding to non-curved outlines, and thus improving the efficiency of text correction.
[0142] Optionally, in one possible implementation of this invention, determining the N+1 sets of first reference points of the main contour can be achieved through the following steps, specifically including steps (a)-(b):
[0143] Step (a): Divide the main contour into N sub-contour units;
[0144] Step (b): Determine the N+1 sets of first reference points corresponding to the N sub-contour units;
[0145] The N sub-contour units include one first sub-contour unit, one second sub-contour unit, and N-2 third sub-contour units; the first and second sub-contour units are located at both ends of the main contour; each third sub-contour unit corresponds to two equal dividing lines; two adjacent third sub-contour units share a set of first reference points; N is greater than or equal to 3.
[0146] The first reference point of group N+1 includes the first reference point corresponding to the third sub-contour unit, the first reference point corresponding to the first sub-contour unit, and the first reference point corresponding to the second sub-contour unit.
[0147] Specifically, in this embodiment, taking N equal to 10 as an example, when the main contour is a curved contour, the main contour first needs to be divided into 10 contour units. In practical applications, the main contour can be divided horizontally or in any direction.
[0148] In this embodiment, taking the horizontal division of the main contour as an example, the main contour is horizontally divided into 10 contour units. These 10 contour units include one first sub-contour unit and one second sub-contour unit located at both ends of the main contour, and eight third sub-contour units excluding the first and second sub-contour units. Each third sub-contour unit corresponds to two dividing lines; adjacent third sub-contour units share a set of first reference points; N is greater than or equal to 3.
[0149] It should be noted that since the main outline is divided into N equal outline units horizontally, a text detection box coordinate system can be established based on the text detection box corresponding to the main outline, and the main outline can be divided into N equal outline units horizontally based on this text detection box coordinate system.
[0150] See details Figure 4 As shown, Figure 4 This is a schematic diagram of the coordinate system of the text detection box provided by the present invention. Figure 4 In this model, the edge r of the text detection box is used as the X-axis of the text detection box coordinate system, and the height h of the text detection box is used as the Y-axis. Based on the X-axis of this text detection box coordinate system, the main contour is horizontally divided into N contour units.
[0151] Furthermore, after dividing the main contour horizontally into N equal contour units, N+1 sets of first reference points corresponding to the N sub-contour units are determined. In the above embodiment, by dividing the main contour into N equal contour units and determining N+1 sets of first reference points corresponding to the N sub-contour units, the position of the text line image corresponding to the main contour in the original text image can be accurately determined based on the N+1 sets of first reference points. Correction of the text line image corresponding to the main contour based on these first reference points can improve the accuracy of curved text recognition.
[0152] Optionally, N+1 sets of first reference points corresponding to N sub-contour units are determined, which can be achieved through the following steps, specifically including steps (b1) to (b4):
[0153] Step (b1): Determine the two equal dividing lines corresponding to the third sub-contour unit, and determine the two sets of first reference points corresponding to the two equal dividing lines, wherein each set of first reference points includes an upper reference point and a lower reference point.
[0154] Step (b2): Determine the two sets of first reference points corresponding to the two equal dividing lines as the two sets of first reference points corresponding to the third sub-contour unit;
[0155] Step (b3): Based on the vertices of the minimum bounding rectangle of the first sub-contour unit, determine a set of first reference points corresponding to the first sub-contour unit;
[0156] Step (b4): Based on the vertices of the minimum bounding rectangle of the second sub-contour unit, determine a set of first reference points corresponding to the second sub-contour unit.
[0157] Specifically, in this embodiment, since the contour unit of the main contour is determined based on the X-axis of the text detection box coordinate system, each third sub-contour unit corresponds to two equally divided lines in the vertical direction, and the X-axis coordinate of the equally divided line can be known from the X-axis.
[0158] Furthermore, based on the two equal dividing lines corresponding to the third sub-contour unit, two sets of first reference points corresponding to the two equal dividing lines in the third sub-contour unit can be determined, wherein each set of first reference points includes an upper bound reference point and a lower bound reference point. Then, the two sets of first reference points corresponding to the two equal dividing lines are determined as the two sets of first reference points corresponding to the third sub-contour unit.
[0159] Optionally, the two sets of first reference points corresponding to the two equal dividing lines can be determined through the following steps (b1.1):
[0160] Step (b1.1): For each equal dividing line, starting from the upper vertex of the equal dividing line, query the pixel value of each pixel in the text line image corresponding to the third sub-contour unit downwards, and determine the pixel value of the pixel with the preset value as the upper bound reference point corresponding to the third sub-contour unit; and starting from the lower vertex of the equal dividing line, query the pixel value of each pixel in the text line image corresponding to the third sub-contour unit upwards, and determine the pixel value of the pixel with the preset value as the lower bound reference point corresponding to the third sub-contour unit.
[0161] Specifically, in this embodiment, since the X-axis coordinates of the vertical dividing lines corresponding to each third sub-contour unit can be known based on the X-axis of the text detection box coordinate system, and the text line image in the text detection box exists in the form of a segmented binary image, the two sets of first reference points corresponding to the two dividing lines in the third sub-contour unit can be determined in the following way:
[0162] For each equal dividing line, starting from the upper vertex of each equal dividing line (i.e., starting from the coordinates (x, y = 0), we start by querying the pixel values of each pixel in the text line image corresponding to the third sub-contour unit along the Y-axis of the text detection box coordinate system. The pixel points with preset values (e.g., white pixels with a preset value of 255) are determined as the upper bound reference points corresponding to the third sub-contour unit.
[0163] Similarly, the lower bound reference point corresponding to the third sub-contour element can be determined in the following way:
[0164] For each equal dividing line, starting from the lower vertex of each equal dividing line (i.e., starting from the coordinates (x, y = h), we search upwards along the Y-axis of the text detection box coordinate system for the pixel values of each pixel in the text line image corresponding to the third sub-contour unit. The pixel with a preset value (e.g., a white pixel with a preset value of 255) is determined as the lower bound reference point corresponding to the third sub-contour unit.
[0165] In the above implementation, by querying the pixel values of each pixel from the upper and lower vertices of the equal dividing line, the upper and lower bound reference points corresponding to the third sub-contour unit can be accurately determined. The upper and lower bound reference points together constitute a set of first reference points. Based on the first reference points, the position of the text line image corresponding to the third sub-contour unit in the original text image can be accurately determined.
[0166] In this embodiment, while determining the first reference point corresponding to the third sub-contour unit, it is also necessary to determine a set of first reference points corresponding to the first sub-contour unit based on the vertices of the smallest bounding rectangle of the first sub-contour unit; and to determine a set of first reference points corresponding to the second sub-contour unit based on the vertices of the smallest bounding rectangle of the second sub-contour unit.
[0167] It is understandable that a set of reference points corresponding to the first sub-contour unit and a set of reference points corresponding to the second sub-contour unit are determined based on the vertices of the smallest bounding rectangle of the first sub-contour unit and the smallest bounding rectangle of the second sub-contour unit, because the first and second sub-contour units are located at the two ends of the main contour, and their contour shapes are usually irregular, so the reference points cannot be directly determined by the equal dividing lines.
[0168] Therefore, based on the coordinate system of the text detection box, the vertex coordinates of the smallest bounding rectangle of the first sub-contour unit and the vertex coordinates of the smallest bounding rectangle of the second sub-contour unit can be determined as a set of reference points corresponding to the first sub-contour unit and a set of reference points corresponding to the second sub-contour unit, respectively, thereby improving the accuracy of the first reference point positioning.
[0169] In the above implementation, the irregular shape of the two ends of the main contour is fully considered. The first reference point corresponding to the third sub-contour unit is determined by the equal dividing line corresponding to the third sub-contour unit, and the first reference point of the first sub-contour unit and the second sub-contour unit is determined by the vertex of the smallest bounding rectangle. Thus, the position of the text line image corresponding to the main contour in the original text image can be accurately determined based on N+1 sets of first reference points. When the main contour is a curved contour, the N+1 sets of second reference points of the corrected text image can be accurately determined based on the N+1 sets of first reference points of the main contour, thereby correcting the text line image corresponding to the main contour and improving the accuracy of curved text recognition.
[0170] Optionally, in one possible implementation of this invention, N+1 sets of second reference points for the corrected text image are determined based on N+1 sets of first reference points. This can be achieved through the following steps, specifically including steps [a]-[c]:
[0171] Step [a]: Determine the width of the corrected text image based on the difference between the coordinates of the upper and lower bound reference points of each group of first reference points;
[0172] Step [b]: Determine the length of the corrected text image based on the distance between adjacent reference points in the N+1 group of first reference points;
[0173] Step [c]: Based on the width and length, divide the corrected text image into N equal image regions. Based on the vertices of each image region, determine the N+1 groups of second reference points for the corrected text image.
[0174] Specifically, in this embodiment, when determining the N+1 groups of first reference points, the specific coordinates of each group of first reference points can be determined based on the X-axis and Y-axis in the text detection box coordinate system.
[0175] Therefore, when determining the N+1 sets of second reference points for the corrected text image based on the N+1 sets of first reference points, it is necessary to determine the width of the corrected text image based on the difference between the coordinates of the upper and lower bound reference points of each set of first reference points.
[0176] In practical applications, for example, the average difference between the upper and lower bound Y-axis coordinates of each group of first reference points can be calculated to obtain the average difference between the N+1 groups of first reference points, and this average difference can be used as the width of the corrected text image.
[0177] Then, based on the X-axis coordinates of the first reference points in the N+1 groups in the text detection box coordinate system, the distances between adjacent first reference points are accumulated to calculate the length of the corrected text image.
[0178] After determining the width and length of the corrected text image, divide it into N equal regions. Based on the vertices of each region, determine N+1 sets of second reference points for the corrected text image. It should be noted that when dividing the corrected text image, it can be divided horizontally or in any direction; however, the direction of division must be consistent with the direction of division of the main contour.
[0179] In the above implementation, the width and length of the corrected text image can be determined by the first reference point. Then, the corrected text image is divided into N equal parts horizontally, thereby determining N+1 sets of second reference points for the corrected text image. Based on the N+1 sets of first reference points and N+1 sets of second reference points, the text line image corresponding to the main contour can be corrected, thereby improving the accuracy of curved text recognition.
[0180] Optionally, in one possible implementation of the present invention, the text line image corresponding to the main contour is corrected based on N+1 sets of first reference points and N+1 sets of second reference points to obtain a corrected text image. This can be achieved through the following steps, specifically including steps [1]-[3]:
[0181] Step [1]: Determine the first matrix based on the coordinates of the N+1 sets of first reference points; the first matrix includes: the coordinates of the N+1 sets of first reference points and the coordinates of the pixels in the text line image corresponding to the main contour;
[0182] Step [2]: Determine the second matrix based on the coordinates of the N+1 sets of second reference points; the second matrix includes: the coordinates of the N+1 sets of second reference points and the coordinates of the pixels corresponding to the corrected text image;
[0183] Step [3]: Interpolate the coordinates of the pixels in the text line image corresponding to the main outline to the coordinates of the pixels in the corrected text image to obtain the corrected text image.
[0184] Specifically, in this embodiment, the text line image corresponding to the main outline can be corrected using the moving least squares method based on the coordinates of the N+1 sets of first reference points and the N+1 sets of second reference points to obtain a corrected text image.
[0185] Specifically, the image deformation algorithm using moving least squares refers to an algorithm that modifies the positions of some reference points by controlling them and changes the positions of surrounding pixels according to a deformation function, thereby producing a deformation effect on the image.
[0186] For example, in practical applications, assuming the text line image corresponding to the main outline has pixels of h*w, first select N+1 sets of first reference points on the image, and then construct the first matrix. The first matrix includes the coordinates of the N+1 sets of first reference points and the coordinates of the pixels in the text line image corresponding to the main outline.
[0187] Based on the first matrix, a series of intermediate variables can be pre-calculated. Then, based on the coordinates of N+1 sets of second reference points, a second matrix is calculated. The second matrix includes the coordinates of N+1 sets of second reference points and the coordinates of pixels in the corrected text image. Each element in the second matrix corresponds to an element in the first matrix.
[0188] Finally, the pixels in the text line image corresponding to the main outline are interpolated one by one to the coordinates of the pixels in the corrected text image, thus completing the image deformation and obtaining the corrected text image.
[0189] Generally, in practical applications, based on N+1 sets of first reference points and N+1 sets of second reference points, affine transformation, similarity transformation or rigid transformation in the moving least squares method can be used to correct the text line image corresponding to the main contour, thus obtaining the corrected text image.
[0190] In the above implementation, based on N+1 sets of first reference points and N+1 sets of second reference points, the moving least squares method is used to correct the text line image corresponding to the main contour. This can accurately correct the text line image corresponding to the main contour, thereby obtaining a corrected text image with non-curved text behavior. Text recognition is then performed on this corrected text image, thereby improving the accuracy of curved text recognition.
[0191] Optionally, in one possible implementation of the present invention, the text line image corresponding to the main contour is corrected based on N+1 sets of first reference points and N+1 sets of second reference points to obtain a corrected text image. Then, OCR technology is used to perform text recognition on the corrected text image to obtain the text recognition result.
[0192] Specifically, in this embodiment, after obtaining the corrected text image, OCR technology is also required to perform text recognition on the corrected text image.
[0193] For example, for correcting text images, OCR technology is used to identify the text region, then the text region is divided into rectangular segments to break it down into different characters, and then the characters are classified to identify the text recognition result.
[0194] Through the above implementation methods, text recognition based on corrected text images using OCR technology can effectively improve the accuracy of text recognition.
[0195] The following combination Figure 5 Taking the text image correction method provided by this invention as an example of its application in correcting original text images, the text image correction method will be further explained. Figure 5 This is a schematic diagram of the text image correction method provided by the present invention.
[0196] The text image correction method provided by this invention includes the following correction process:
[0197] Step 1: Obtain the original text image.
[0198] Specifically, in this embodiment, the original text image is as follows: Figure 6 As shown, Figure 6 This is a schematic diagram of the original text image provided by the present invention. Figure 6 In the original text image, there are three text lines: “X”, “Y”, and “Z”.
[0199] Step 2: Input the original text image into the text detection model to obtain the text segmentation binary image and text detection box.
[0200] Step 3: Perform contour query on the text segmentation binary image within each text detection box to obtain the text line contour corresponding to each text segmentation binary image, and extract the main contour from the text line contour.
[0201] Specifically, in this embodiment, the main contour is as follows: Figure 3 As shown.
[0202] Step 4: Determine whether the main contour is a curved contour. If the main contour is a curved contour, proceed to Step 5; if the main contour is a non-curved contour, proceed to Step 8.
[0203] Step 5: Query the original map reference points.
[0204] Specifically, the original image reference point lookup refers to the N+1 sets of first reference points mentioned above used to determine the main outline. The first reference points are detailed below. Figure 2 As shown.
[0205] See Figure 2 The text line outline corresponding to the text line "Y" in the original text image is determined as the main outline, and then N+1 sets of first reference points are determined within this main outline. Specifically, in Figure 2 In this context, N takes the value 10, that is... Figure 2 The first set of reference points for the main outline is 11.
[0206] Step 6: Target map benchmark query.
[0207] Specifically, the original image reference point query refers to the determination of the N+1 sets of second reference points for the text image to be corrected, as mentioned above. The second reference points are detailed below. Figure 7 As shown, Figure 7 This is a schematic diagram of the N+1 group of second reference points provided by the present invention.
[0208] In this embodiment, N is 10, that is Figure 7 The second reference point consists of 11 groups, and each group of first reference points corresponds to a group of second reference points.
[0209] Step 7: Correct the text line image corresponding to the main outline using the moving least squares method.
[0210] Step 8: Based on the corrected text image or the original text image whose main outline is a non-curved outline, obtain a single-line text image.
[0211] Step 9: Input the single-line text image into the text recognition model for text recognition.
[0212] Specifically, in this embodiment, a single-line text image is input into a text recognition model for text recognition, that is, optical character recognition (OCR) technology is used to perform text recognition on the corrected text image or the original text image whose main outline is a non-curved outline.
[0213] Step 10: Obtain the text recognition result from the text recognition model.
[0214] The text image correction method provided by this invention extracts at least one text line contour from the original text image and determines the main contour from the text line contour. If the main contour is curved, N+1 sets of first reference points are determined, thereby accurately determining the position of the text line image corresponding to the main contour in the original text image. Then, based on the N+1 sets of first reference points, N+1 sets of second reference points are determined for the corrected text image. Based on the N+1 sets of first and second reference points, the text line image corresponding to the main contour is corrected, resulting in a corrected text image. By performing text recognition on the corrected text image, the accuracy of curved text recognition can be improved.
[0215] The text image correction device provided by this invention will be described below. The text image correction device described below can be referred to in correspondence with the text image correction method described above. See also Figure 8 , Figure 8 This is a schematic diagram of the structure of the text and image correction device 800 provided by the present invention.
[0216] Extraction module 801 is used to extract at least one text line outline from the original text image and determine the main outline from the text line outline.
[0217] The first reference point determination module 802 is used to determine N+1 sets of first reference points for the main profile when the main profile is a curved profile; N is a positive integer.
[0218] The second reference point determination module 803 is used to determine N+1 sets of second reference points for the corrected text image based on N+1 sets of first reference points; each set of first reference points corresponds to a set of second reference points.
[0219] The correction module 804 is used to correct the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain the corrected text image.
[0220] The text image correction device provided by this invention extracts at least one text line outline from the original text image and determines the main outline from the text line outline. If the main outline is curved, it determines N+1 sets of first reference points for the main outline, thereby accurately determining the position of the text line image corresponding to the main outline in the original text image. Then, based on the N+1 sets of first reference points, it determines N+1 sets of second reference points for the corrected text image. Based on the N+1 sets of first and second reference points, it corrects the text line image corresponding to the main outline, thereby obtaining a corrected text image. By performing text recognition on the corrected text image, the accuracy of curved text recognition can be improved.
[0221] Optionally, the first reference point determination module 802 is further configured to:
[0222] Divide the main contour into N sub-contour units;
[0223] Determine the N+1 sets of first reference points corresponding to the N sub-contour units;
[0224] The N sub-contour units include one first sub-contour unit, one second sub-contour unit, and N-2 third sub-contour units; the first and second sub-contour units are located at both ends of the main contour; each third sub-contour unit corresponds to two equal dividing lines; two adjacent third sub-contour units share a set of first reference points; N is greater than or equal to 3.
[0225] The first reference point of group N+1 includes the first reference point corresponding to the third sub-contour unit, the first reference point corresponding to the first sub-contour unit, and the first reference point corresponding to the second sub-contour unit.
[0226] Optionally, the first reference point determination module 802 is further configured to:
[0227] Determine the two equal dividing lines corresponding to the third sub-contour unit, and determine the two sets of first reference points corresponding to the two equal dividing lines. Each set of first reference points includes an upper reference point and a lower reference point.
[0228] The two sets of first reference points corresponding to the two equal dividing lines are determined as the two sets of first reference points corresponding to the third sub-contour unit.
[0229] Based on the vertices of the minimum bounding rectangle of the first sub-contour unit, determine a set of first reference points corresponding to the first sub-contour unit;
[0230] Based on the vertices of the minimum bounding rectangle of the second sub-contour unit, a set of first reference points corresponding to the second sub-contour unit is determined.
[0231] Optionally, the first reference point determination module 802 is further configured to:
[0232] For each equal dividing line, starting from the upper vertex of the equal dividing line, query the pixel value of each pixel in the text line image corresponding to the third sub-contour unit downwards, and determine the pixel value of the pixel with the preset value as the upper bound reference point corresponding to the third sub-contour unit; and starting from the lower vertex of the equal dividing line, query the pixel value of each pixel in the text line image corresponding to the third sub-contour unit upwards, and determine the pixel value of the pixel with the preset value as the lower bound reference point corresponding to the third sub-contour unit.
[0233] Optionally, the second reference point determination module 803 is further used for:
[0234] The width of the corrected text image is determined based on the difference between the coordinates of the upper and lower bound reference points of each group of first reference points.
[0235] The length of the corrected text image is determined based on the distance between adjacent reference points in the first reference point group N+1.
[0236] Based on the width and length, the corrected text image is divided into N equal image regions. Based on the vertices of each image region, N+1 sets of second reference points are determined for the corrected text image.
[0237] Optionally, the correction module 804 is further used for:
[0238] Based on the coordinates of the N+1 sets of first reference points, a first matrix is determined; the first matrix includes: the coordinates of the N+1 sets of first reference points and the coordinates of the pixels in the text line image corresponding to the main contour.
[0239] Based on the coordinates of the N+1 sets of second reference points, a second matrix is determined; the second matrix includes: the coordinates of the N+1 sets of second reference points and the coordinates of the pixels corresponding to the corrected text image.
[0240] The coordinates of the pixels in the text line image corresponding to the main outline are interpolated to the coordinates of the corresponding pixels in the corrected text image to obtain the corrected text image.
[0241] Optionally, the extraction module 801 is further used for:
[0242] Detect at least one text segmentation binary image in the original text image and extract the text line outlines corresponding to each text segmentation binary image;
[0243] Calculate the area of each text line outline and determine the text line outline with the largest area as the main outline.
[0244] Optionally, the extraction module 801 is further used for:
[0245] Text detection processing is performed on the original text image to obtain a text segmentation binary image and a text detection box;
[0246] Contour lookup is performed on the text segmentation binary image within each text detection box to obtain the text line contours corresponding to each text segmentation binary image.
[0247] Optionally, the device further includes:
[0248] The first determining module is used to determine the area of the main contour and the area of the text detection box corresponding to the main contour.
[0249] The second determining module is used to determine the ratio of the contour area of the main contour to the area of the text detection box;
[0250] The third determining module is used to determine that the main contour is a curved contour when the ratio is less than a preset threshold.
[0251] Figure 9 This is a structural schematic diagram of the electronic device 900 provided by the present invention, as shown below. Figure 9 As shown, the electronic device may include a processor 910, a communications interface 920, a memory 930, and a communication bus 940, wherein the processor 910, the communications interface 920, and the memory 930 communicate with each other via the communication bus 940. The processor 910 can call logical instructions in the memory 930 to execute a text image correction method. This method includes: extracting at least one text line contour from the original text image; determining a main contour from the text line contour; if the main contour is a curved contour, determining N+1 sets of first reference points for the main contour; N being a positive integer; determining N+1 sets of second reference points for the corrected text image based on the N+1 sets of first reference points; each set of first reference points corresponds to a set of second reference points; and correcting the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain a corrected text image.
[0252] Furthermore, the logical instructions in the aforementioned memory 930 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0253] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the above-described text image correction method. The method includes: extracting at least one text line contour from the original text image; determining a main contour from the text line contour; determining N+1 sets of first reference points for the main contour when the main contour is a curved contour; N being a positive integer; determining N+1 sets of second reference points for the corrected text image based on the N+1 sets of first reference points; each set of first reference points corresponding to a set of second reference points; and correcting the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain a corrected text image.
[0254] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is implemented to perform the above-described text image correction method. The method includes: extracting at least one text line contour from the original text image; determining a main contour from the text line contour; if the main contour is a curved contour, determining N+1 sets of first reference points for the main contour; where N is a positive integer; determining N+1 sets of second reference points for the corrected text image based on the N+1 sets of first reference points; each set of first reference points corresponds to a set of second reference points; and correcting the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain a corrected text image.
[0255] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0256] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0257] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A text picture correction method, characterized by, include: Extract at least one text line outline from the original text image, and determine the main outline from the text line outline; When the main contour is a curved contour, the main contour is divided into N equal sub-contour units; N+1 sets of first reference points are determined for each of the N sub-contour units; wherein, the N sub-contour units include one first sub-contour unit, one second sub-contour unit, and N-2 third sub-contour units; the first sub-contour unit and the second sub-contour unit are located at both ends of the main contour; each third sub-contour unit corresponds to two equal dividing lines; two adjacent third sub-contour units share a set of first reference points; N is an integer greater than or equal to 3; the N+1 sets of first reference points include the first reference point corresponding to the third sub-contour unit, the first reference point corresponding to the first sub-contour unit, and the first reference point corresponding to the second sub-contour unit; The width of the corrected text image is determined based on the difference in coordinates between the upper and lower bound reference points of each group of first reference points; the length of the corrected text image is determined based on the distance between adjacent reference points in the N+1 groups of first reference points; based on the width and the length, the corrected text image is divided into N equal image regions, and N+1 groups of second reference points are determined based on the vertices of each image region; each group of first reference points corresponds to a group of second reference points. Based on the N+1 sets of first reference points and the N+1 sets of second reference points, the text line image corresponding to the main contour is corrected to obtain the corrected text image.
2. The text-image correction method according to claim 1, characterized in that, The step of determining the N+1 sets of first reference points corresponding to the N sub-contour units includes: determining two equal dividing lines corresponding to the third sub-contour unit, and determining two sets of first reference points corresponding to the two equal dividing lines, wherein each set of first reference points includes an upper bound reference point and a lower bound reference point. The two sets of first reference points corresponding to the two equal dividing lines are determined as the two sets of first reference points corresponding to the third sub-contour unit. Based on the vertices of the minimum bounding rectangle of the first sub-contour unit, a set of first reference points corresponding to the first sub-contour unit is determined. Based on the vertices of the minimum bounding rectangle of the second sub-contour unit, a set of first reference points corresponding to the second sub-contour unit is determined.
3. The text picture correction method according to claim 2, characterized in that, The determination of the two sets of first reference points corresponding to the two equal dividing lines includes: For each of the equal dividing lines, starting from the upper vertex of the equal dividing line, query downwards the pixel value of each pixel in the text line image corresponding to the third sub-contour unit, and determine the pixel point with the pixel value of the preset value as the upper bound reference point corresponding to the third sub-contour unit; and starting from the lower vertex of the equal dividing line, query upwards the pixel value of each pixel in the text line image corresponding to the third sub-contour unit, and determine the pixel point with the pixel value of the preset value as the lower bound reference point corresponding to the third sub-contour unit.
4. The text picture correction method of claim 1, wherein, The step of correcting the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain the corrected text image includes: Based on the coordinates of the N+1 sets of first reference points, a first matrix is determined; the first matrix includes: the coordinates of the N+1 sets of first reference points and the coordinates of pixels in the text line image corresponding to the main contour. Based on the coordinates of the N+1 sets of second reference points, a second matrix is determined; the second matrix includes: the coordinates of the N+1 sets of second reference points and the coordinates of the pixels corresponding to the corrected text image; The coordinates of the pixels in the text line image corresponding to the main outline are interpolated to the coordinates of the pixels in the corrected text image to obtain the corrected text image.
5. The text picture correction method according to claim 1, characterized in that, The step of extracting at least one text line outline from the original text image and determining the main outline from the text line outline includes: Detect at least one text segmentation binary image in the original text image, and extract the text line outlines corresponding to each text segmentation binary image; Calculate the area of each text line contour, and determine the text line contour with the largest area as the main contour.
6. The text picture correction method according to claim 5, characterized in that, The step of detecting at least one text segmentation binary image in the original text image and extracting the text line contours corresponding to each text segmentation binary image includes: The original text image is subjected to text detection processing to obtain a text segmentation binary image and a text detection box; Contour lookup is performed on the text segmentation binary image within each text detection box to obtain the text line contours corresponding to each text segmentation binary image.
7. The text picture correction method according to claim 1, characterized by, After determining the main contour from the text line contour, the method further includes: Determine the area of the main contour and the area of the text detection box corresponding to the main contour; Determine the ratio of the area of the main contour to the area of the text detection box; If the ratio is less than a preset threshold, the main contour is determined to be a curved contour.
8. A text picture correction apparatus characterized by comprising: include: An extraction module is used to extract at least one text line outline from the original text image and determine the main outline from the text line outline. The first reference point determination module is used to divide the main contour into N equal sub-contour units when the main contour is a curved contour; and to determine N+1 sets of first reference points corresponding to the N sub-contour units; wherein, the N sub-contour units include one first sub-contour unit, one second sub-contour unit, and N-2 third sub-contour units; the first sub-contour unit and the second sub-contour unit are located at both ends of the main contour; each third sub-contour unit corresponds to two equal dividing lines; two adjacent third sub-contour units share a set of first reference points; N is an integer greater than or equal to 3; the N+1 sets of first reference points include the first reference point corresponding to the third sub-contour unit, the first reference point corresponding to the first sub-contour unit, and the first reference point corresponding to the second sub-contour unit; The second reference point determination module is used to determine the width of the corrected text image by the difference in coordinates between the upper and lower bound reference points of each group of first reference points; to determine the length of the corrected text image based on the distance between adjacent groups of reference points in the N+1 groups of first reference points; to divide the corrected text image into N equal image regions based on the width and the length; and to determine N+1 groups of second reference points for the corrected text image based on the vertices of each image region; each group of first reference points corresponds to a group of second reference points. The correction module is used to correct the text line image corresponding to the main contour based on the N+1 sets of first reference points and the N+1 sets of second reference points to obtain the corrected text image.
Citation Information
Patent Citations
Text correction method and device, electronic equipment and storage medium
CN111695554A