Method and device for determining line size in text recognition
By using optical character recognition and feature value updates, the problem of inconsistent text line sizes in OCR text recognition has been solved, achieving uniformity in text line sizes and improving the layout effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING SINOVOICE TECH CO LTD
- Filing Date
- 2023-05-30
- Publication Date
- 2026-04-17
AI Technical Summary
In existing OCR text recognition technologies, when calculating the text line font size based on layout analysis, it is impossible to completely match the font, resulting in inconsistent calculated text line font sizes and affecting the layout restoration effect.
The original line information of the text is obtained by optical character recognition, the line height feature value of the sample text is extracted, and the average value and standard deviation are used for updating. The line height is adjusted to determine a uniform line font size.
This achieves uniformity in text line font size, improving the visual effect and consistency of page layout.
Smart Images

Figure CN116704525B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of text recognition technology, and more specifically, to a method and apparatus for determining the line size in text recognition. Background Technology
[0002] In OCR text recognition scenarios, OCR needs to return a relative font size based on the image size to facilitate product layout reconstruction at the application layer. However, in OCR text recognition, this font size information is often limited to the font size representing that line of text. If this font size information is used directly, due to small errors in calculating the line font size during layout reconstruction, the reconstructed content may have some lines higher and some lower, resulting in inconsistent visual effects.
[0003] The text recognition technologies mentioned above are mostly based on layout analysis, which identifies the text line area and then attempts to scale and fill the area to approximate the relative font size based on the width of the text line area and the width of the font size. However, the text line area in layout analysis cannot completely fit the font. As a result, the calculated text line font size varies and is inconsistent. There is currently no effective solution to this problem. Summary of the Invention
[0004] This invention provides a method and apparatus for determining the font size of a line in text recognition, which at least solves the technical problem that text recognition in related technologies is basically based on layout analysis, identifies the area of the text line, and then attempts to scale and fill to approximate the relative font size based on the width of the text line area and the width of the font size. However, the text line area in layout analysis cannot completely fit the font, which affects the calculation of the text line font size, resulting in inconsistencies.
[0005] According to one aspect of the present invention, a method for determining line size in text recognition is provided, comprising: performing text recognition on target text using optical character recognition to obtain a text recognition result, wherein the target text is the text to be recognized; obtaining all original line information in the target text from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least: line height; extracting a predetermined number of lines of text from each of the original line information as sample text; determining feature values of the line height of each of the sample texts, wherein the feature values include at least: mean and standard deviation; updating the line height in the original line information according to the feature values to obtain the updated line height; and determining the line size of the text recognition result according to the updated line height.
[0006] Optionally, text recognition of the target text is performed using optical character recognition (OCR) to obtain a text recognition result, including: scanning the target text to obtain an initial text image corresponding to the target text; preprocessing the initial text image to obtain a preprocessed initial text image, wherein the preprocessing includes at least one of the following operations: binarization, denoising, and tilt correction; and recognizing the initial text image using the OCR to obtain the text recognition result.
[0007] Optionally, the initial text image is recognized using the optical character recognition method to obtain the text recognition result, including: analyzing the initial text image using a layout analysis algorithm to segment and line-divide the initial text image to obtain a layout analysis image; performing character segmentation on the layout analysis image to obtain a character-segmented layout analysis image; and performing character recognition on the character-segmented layout analysis image to obtain the text recognition result.
[0008] Optionally, character recognition is performed on the page layout analysis image after character segmentation to obtain the text recognition result, including: determining the pixel information of the page layout analysis image; obtaining the frame region of a single character in the page layout analysis image based on the pixel information; determining the frame region as the single character region feature of the single character; and obtaining the text recognition result based on the single character region feature.
[0009] Optionally, obtaining the text recognition result based on the single-character region features includes: determining the feature vector of each single character based on the single-character region features; matching the feature vector with a feature template library to obtain the text recognition result, wherein the feature template library includes multiple mapping relationships between single-character region features and feature vectors.
[0010] Optionally, updating the row height in the original row information based on the feature value to obtain the updated row height includes: determining the coefficient of variation based on the feature value, wherein the coefficient of variation is obtained by a predetermined formula, the predetermined formula being: CV = (SD / Mean) * 100%, where CV represents the coefficient of variation, SD represents the standard deviation of the feature value, and Mean represents the average value of the feature value; when it is determined that the coefficient of variation is greater than a predetermined threshold, updating the row height in the original row information using the average value to obtain the updated row height.
[0011] Optionally, after determining the line size of the text recognition result based on the updated line height, the method for determining the line size in the text recognition further includes: smoothing the characters in the text recognition result that need to be adjusted in size based on the line size, to obtain the smoothed text recognition result.
[0012] Optionally, the method for determining the line size in text recognition further includes: restoring the layout of the target text based on the smoothed text recognition result.
[0013] According to another aspect of the present invention, a device for determining line size in text recognition is also provided, comprising: a recognition unit, configured to perform text recognition on target text using optical character recognition to obtain a text recognition result, wherein the target text is the text to be recognized; an acquisition unit, configured to acquire all original line information in the target text from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least: line height; an extraction unit, configured to extract a predetermined number of lines of text from each of the original line information as sample text; a first determination unit, configured to determine the feature value of the line height of each of the sample texts, wherein the feature value includes at least: mean and standard deviation; an update unit, configured to update the line height in the original line information according to the feature value to obtain the updated line height; and a second determination unit, configured to determine the line size of the text recognition result according to the updated line height.
[0014] Optionally, the recognition unit includes: a scanning subunit for scanning the target text to obtain an initial text image corresponding to the target text; a preprocessing subunit for preprocessing the initial text image to obtain a preprocessed initial text image, wherein the preprocessing includes at least one of the following operations: binarization, denoising, and tilt correction; and a recognition subunit for recognizing the initial text image using the optical character recognition method to obtain the text recognition result.
[0015] Optionally, the recognition subunit includes: an analysis module, used to analyze the initial text image using a layout analysis algorithm to segment and line-divide the initial text image to obtain a layout analysis image; a cutting module, used to perform character cutting processing on the layout analysis image to obtain a character-cut layout analysis image; and a recognition module, used to perform character recognition on the character-cut layout analysis image to obtain the text recognition result.
[0016] Optionally, the recognition module includes: a first determining submodule, used to determine the pixel information of the layout analysis image; an acquiring submodule, used to acquire the frame region of a single character in the layout analysis image based on the pixel information; a second determining submodule, used to determine that the frame region is the single character region feature of the single character; and an acquiring submodule, used to obtain the text recognition result based on the single character region feature.
[0017] Optionally, the acquisition submodule includes: a third determining submodule, used to determine the feature vector of each of the single characters based on the single character region features; and a matching submodule, used to match the feature vectors with a feature template library to obtain the text recognition result, wherein the feature template library includes multiple mapping relationships between single character region features and feature vectors.
[0018] Optionally, the update unit includes: a determining subunit, configured to determine the coefficient of variation based on the feature value, wherein the coefficient of variation is obtained by a predetermined formula, the predetermined formula being: CV = (SD / Mean) * 100%, where CV represents the coefficient of variation, SD represents the standard deviation of the feature value, and Mean represents the average value of the feature value; and an update subunit, configured to update the row height in the original row information using the average value when the coefficient of variation is determined to be greater than a predetermined threshold, thereby obtaining the updated row height.
[0019] Optionally, the device for determining the line size in the text recognition further includes a smoothing processing unit, which, after determining the line size of the text recognition result based on the updated line height, performs smoothing processing on the characters in the text recognition result that need to be adjusted in size based on the line size, to obtain the smoothed text recognition result.
[0020] Optionally, the device for determining the line size in text recognition further includes: a restoration unit, used to restore the layout of the target text based on the smoothed text recognition result.
[0021] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein the program executes the method for determining the line size of text recognition as described in any of the above embodiments.
[0022] According to another aspect of the present invention, a processor is also provided, the processor being configured to run a program, wherein the program, when running, executes the method for determining the line size in text recognition as described in any of the above embodiments.
[0023] In this embodiment of the invention, optical character recognition is used to perform text recognition on the target text to obtain a text recognition result, wherein the target text is the text to be recognized; all original line information in the target text is obtained from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least: line height; a predetermined number of lines of text are extracted from each original line information as sample text; the feature value of the line height of each sample text is determined, wherein the feature value includes at least: mean and standard deviation; the line height in the original line information is updated according to the feature value to obtain the updated line height; the line number of the text recognition result is determined according to the updated line height. The technical solution provided by this invention achieves the goal of determining the line font size of the area requiring font size processing based on the feature value of the line height in the original line information of the text recognition result. This makes the line font size of all text more uniform, thereby solving the technical problem that in related technologies, text recognition is basically based on layout analysis, which identifies the area of the text line and then attempts to scale and fill to approximate the relative font size based on the width of the text line area and the width of the font size. However, the text line area of the layout analysis cannot completely fit the font, which affects the calculation of the text line font size, resulting in inconsistencies. Attached Figure Description
[0024] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0025] Figure 1 This is a hardware structure block diagram of a mobile terminal for a method of determining the line size in text recognition according to an embodiment of the present invention.
[0026] Figure 2 This is a flowchart of a method for determining the line size in text recognition according to an embodiment of the present invention;
[0027] Figure 3 This is a schematic diagram of a text recognition device for determining the line size according to an embodiment of the present invention. Detailed Implementation
[0028] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0030] As described in the background section, in OCR text recognition scenarios, OCR recognition needs to return a relative font size based on the image size to facilitate product layout restoration at the application layer. Existing OCR recognition methods are basically based on layout analysis, identifying the text line regions, and then attempting to scale and fill to approximate the relative font size based on the width of the text line region and the font size. However, this method can lead to inaccurate font size estimation in the following two scenarios, thus affecting the layout restoration results: 1) The document may use distributed alignment, or the text characters may contain spaces, tabs, or other whitespace characters, resulting in a larger estimated font size than the original font size; 2) The text line region analyzed in the layout analysis may not completely fit the font, causing the calculated text line font size to vary. To address these shortcomings, embodiments of the present invention provide a method and apparatus for determining line font size in text recognition, a computer-readable storage medium, and a processor.
[0031] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0032] The methods and embodiments provided in this invention can be executed on a mobile terminal, a computer terminal, or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a method of determining the line size in text recognition according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0033] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the method for determining line size in text recognition in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0034] According to an embodiment of the present invention, a method embodiment for determining the font size of a line in text recognition is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0035] Figure 2 This is a flowchart of a method for determining the line size in text recognition according to an embodiment of the present invention, as shown below. Figure 2 As shown, the method includes the following steps:
[0036] Step S202: Use optical character recognition to perform text recognition on the target text to obtain the text recognition result, wherein the target text is the text to be recognized.
[0037] The aforementioned Optical Character Recognition (OCR) refers to the process by which electronic devices (such as scanners or digital cameras) examine characters printed on paper, determine their shapes by detecting dark and light patterns, and then translate the shapes into computer text using character recognition methods.
[0038] Step S204: Obtain all the original line information in the target text from the text recognition result. The original line information is the actual line information of the target text, and the line information includes at least the line height.
[0039] In this embodiment, the original line information of each line in the target text can be obtained from the text recognition results described above. For example, the line height of each line in the target text can be calculated. Since the document may use distributed alignment, or there may be spaces, tabs, or other whitespace characters in the text, the estimated font size will be larger than the original font size. Furthermore, the text line area analyzed by the layout analysis cannot completely fit the font, resulting in variations in the calculated font size. Therefore, further processing is required to ensure that the font size of each line remains consistent, providing a better visual experience for the user.
[0040] Step S206: Extract a predetermined number of lines of text from each original line of information as sample text.
[0041] In this embodiment, a predetermined number of lines of text can be extracted as sample text. For example, a sliding window size can be set, and the predetermined number of lines of text can be extracted from the original line information as sample text through this sliding window.
[0042] Step S208: Determine the feature values of the line height of each sample text, wherein the feature values include at least the mean and standard deviation.
[0043] In this embodiment, the average or standard deviation of the line height of each sample text can be calculated.
[0044] Step S210: Update the row height in the original row information according to the feature value to obtain the updated row height.
[0045] Step S212: Determine the line number of the text recognition result based on the updated line height.
[0046] In this embodiment, the line number of the text recognition result can be determined based on the newly determined line height, and the line number can be used as the line number or the paragraph number.
[0047] As can be seen from the above, in this embodiment of the invention, optical character recognition can be used to perform text recognition on the target text to obtain the text recognition result. The target text is the text to be recognized. All original line information in the target text is obtained from the text recognition result. The original line information is the actual line information of the target text, and the line information includes at least the line height. A predetermined number of lines of text are extracted from each original line information as sample text. The feature value of the line height of each sample text is determined. The feature value includes at least the mean and standard deviation. The line height in the original line information is updated according to the feature value to obtain the updated line height. The line font size of the text recognition result is determined according to the updated line height. This achieves the purpose of determining the line font size of the area that needs to be processed based on the feature value of the line height of the area that needs to be processed in the original line information of the recognized text, thereby making the line font size of all texts more uniform.
[0048] Therefore, the technical solution provided by this invention solves the problem that text recognition in related technologies is basically based on layout analysis, which identifies the area of text lines and then attempts to scale and fill the text line area and the font size to calculate the relative font size. However, the text line area of layout analysis cannot completely fit the font, which causes the calculated text line font size to be inconsistent.
[0049] According to the above embodiments of the present invention, text recognition of target text using optical character recognition (OCR) to obtain text recognition results includes: scanning the target text to obtain an initial text image corresponding to the target text; preprocessing the initial text image to obtain a preprocessed initial text image, wherein the preprocessing includes at least one of the following operations: binarization, denoising, and tilt correction; and recognizing the initial text image using OCR to obtain text recognition results.
[0050] In this embodiment, after the target text is input into the processing system, the processing system can use algorithms to read different image format files, such as scanning the target text with a scanner to obtain the initial text image of the target text. Then, the initial text image can be preprocessed, such as image binarization, noise removal, tilt correction, etc., so that the preprocessed text image is easier to process in subsequent processing and improves the efficiency of determining line size.
[0051] According to the above embodiments of the present invention, recognizing an initial text image using optical character recognition to obtain a text recognition result may include: analyzing the initial text image using a layout analysis algorithm to segment and line-divide the initial text image to obtain a layout analysis image; performing character segmentation processing on the layout analysis image to obtain a character-segmented layout analysis image; and performing character recognition on the character-segmented layout analysis image to obtain a text recognition result.
[0052] In this embodiment, a layout analysis algorithm can be used to analyze the initial text image to segment and line-break the initial text image, thereby obtaining a segmented and line-broken layout analysis image.
[0053] The aforementioned layout analysis algorithm is an algorithm that divides document images into paragraphs and lines. This algorithm can find the framed areas containing valid text information lines within an image; these are denoted as text line region features, or simply line features.
[0054] Next, character segmentation can be performed on the layout analysis image. This mainly addresses the problem of characters being difficult to segment due to character adhesion or broken strokes.
[0055] According to the above embodiments of the present invention, character recognition is performed on the layout analysis image after character segmentation to obtain text recognition results, including: determining the pixel information of the layout analysis image; obtaining the frame region of a single character in the layout analysis image based on the pixel information; determining the single character region feature of the frame region as a single character; and obtaining the text recognition result based on the single character region feature.
[0056] In this embodiment, character feature extraction can be performed by directly obtaining the frame region of a single character based on the image pixel information, which is denoted as single character region feature, or simply character feature.
[0057] According to the above embodiments of the present invention, obtaining text recognition results based on single-character region features includes: determining the feature vector of each single character based on the single-character region features; matching the feature vector with a feature template library to obtain text recognition results, wherein the feature template library includes multiple mapping relationships between single-character region features and feature vectors.
[0058] In this embodiment, the feature vector extracted from the current character can be compared with the feature template library for coarse template classification and fine template matching to identify the character.
[0059] In this embodiment of the invention, the single-character regions contained within a line region can be found using a region overlap algorithm. Since the height of a text line and the height of a single character are usually the same, it is only necessary to calculate the height of the characters within the line using a smoothing algorithm, which can then be used as the height of the text line, and the corresponding line features and character features of that line can be corrected. Based on the height of the corrected character features, the relative font size is calculated by attempting to scale and fill the space using the font size height.
[0060] According to the above embodiments of the present invention, updating the row height in the original row information based on the feature value to obtain the updated row height includes: determining the coefficient of variation based on the feature value, wherein the coefficient of variation is obtained by a predetermined formula, the predetermined formula being: CV = (SD / Mean) * 100%, where CV represents the coefficient of variation, SD represents the standard deviation of the feature value, and Mean represents the average value of the feature value; when it is determined that the coefficient of variation is greater than a predetermined threshold, the average value is used to update the row height in the original row information to obtain the updated row height.
[0061] Since the line heights in the line information of all the obtained OCR recognition results may vary, in this embodiment, a sliding window size N, a coefficient of variation X, and an iteration round M can be set: The first round of smoothing calculation begins by extracting N lines of data from all the line information, calculating the mean font size (Mean) and standard deviation (SD) of the N lines of text, and then calculating the coefficient of variation of the text font size within this sliding window. Specifically, the coefficient of variation can be determined using the aforementioned predetermined formula.
[0062] The larger the coefficient of variation (CV), the greater the difference in font size between the N lines of information in the window, which often occurs when there are both headings and body text within the window. Conversely, a smaller CV indicates that the font sizes in the N lines of text are not significantly different and can be smoothed out. In this case, the height of all N lines can be changed to the calculated average (Mean), which often occurs in pure body text. The first round of smoothing calculation is complete. Repeat the above smoothing process M times for a complete smoothing process. This processing method, due to the use of coefficient of variation detection, can eliminate factors that affect the calculation of the average, ensuring that the large font size of the headings is not averaged out. The multi-round iterative approach is equivalent to enlarging the processing window, making the line numbers of all text more uniform.
[0063] According to the above embodiments of the present invention, after determining the line size of the text recognition result based on the updated line height, the method for determining the line size in the text recognition may further include: smoothing the characters in the text recognition result that need to be adjusted in size based on the line size, so as to obtain the smoothed text recognition result.
[0064] The above smoothing process can make all text line numbers more consistent.
[0065] According to the above embodiments of the present invention, the method for determining the line size in text recognition may further include: restoring the layout of the target text based on the text recognition result after smoothing.
[0066] The technical solution provided by the above embodiments of the present invention utilizes character features to smoothly calculate line height and uses a font size height filling approximation method to calculate relative font size, making all text line numbers more uniform.
[0067] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0068] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, 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 is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0069] According to embodiments of the present invention, a device for determining the line size in text recognition is also provided for implementing the above-described method for determining the line size in text recognition. Figure 3 This is a schematic diagram of a text recognition device for determining line size according to an embodiment of the present invention, as shown below. Figure 3 As shown, the device includes: a recognition unit 301, an acquisition unit 303, an extraction unit 305, a first determination unit 307, an update unit 309, and a second determination unit 311. The device for determining the line size in text recognition will be described below.
[0070] The recognition unit 301 is used to perform text recognition on the target text using optical character recognition to obtain the text recognition result, wherein the target text is the text to be recognized.
[0071] The acquisition unit 303 is used to acquire all the original line information in the target text from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least the line height.
[0072] Extraction unit 305 is used to extract a predetermined number of lines of text from each original line of information as sample text.
[0073] The first determining unit 307 is used to determine the feature value of the line height of each sample text, wherein the feature value includes at least the mean and the standard deviation.
[0074] The update unit 309 is used to update the row height in the original row information according to the feature value to obtain the updated row height.
[0075] The second determining unit 311 is used to determine the line number of the text recognition result based on the updated line height.
[0076] It should be noted that the identification unit 301, acquisition unit 303, extraction unit 305, first determination unit 307 and second determination unit 311 mentioned above correspond to steps S202 to S212 in the above embodiments. The six units and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments.
[0077] As can be seen from the above, in the scheme described in the above embodiments of the present invention, the recognition unit can use optical character recognition to perform text recognition on the target text to obtain the text recognition result, wherein the target text is the text to be recognized; then, the acquisition unit uses the acquisition unit to obtain all the original line information in the target text from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least: line height; then, the extraction unit uses the extraction unit to extract a predetermined number of lines of text from each original line information as sample text; then, the first determination unit uses the first determination unit to determine the feature value of the line height of each sample text, wherein the feature value includes at least: mean and standard deviation; and the update unit uses the update unit to update the line height in the original line information according to the feature value to obtain the updated line height; the second determination unit is used to determine the line font size of the text recognition result according to the updated line height, thereby realizing the purpose of determining the line font size of the area that needs to be processed based on the feature value of the line height of the area that needs to be processed in the original line information of the recognized text, thereby making the line font size of all texts more uniform.
[0078] Therefore, the technical solution provided by this invention solves the problem that text recognition in related technologies is basically based on layout analysis, which identifies the area of text lines and then attempts to scale and fill the text line area and the font size to calculate the relative font size. However, the text line area of layout analysis cannot completely fit the font, which causes the calculated text line font size to be inconsistent.
[0079] Optionally, the recognition unit includes: a scanning subunit for scanning the target text to obtain an initial text image corresponding to the target text; a preprocessing subunit for preprocessing the initial text image to obtain a preprocessed initial text image, wherein the preprocessing includes at least one of the following operations: binarization, denoising, and tilt correction; and a recognition subunit for recognizing the initial text image using optical character recognition to obtain a text recognition result.
[0080] Optionally, the recognition subunit includes: an analysis module, used to analyze the initial text image using a layout analysis algorithm to segment and line-divide the initial text image to obtain a layout analysis image; a segmentation module, used to segment the layout analysis image into characters to obtain a segmented layout analysis image; and a recognition module, used to recognize characters in the segmented layout analysis image to obtain a text recognition result.
[0081] Optionally, the recognition module includes: a first determining submodule for determining pixel information of the layout analysis image; an acquisition submodule for acquiring the frame region of a single character in the layout analysis image based on the pixel information; a second determining submodule for determining the single character region features of the frame region; and an acquisition submodule for obtaining the text recognition result based on the single character region features.
[0082] Optionally, the acquisition submodule includes: a third determination submodule, used to determine the feature vector of each character based on the single-character region features; and a matching submodule, used to match the feature vector with the feature template library to obtain the text recognition result, wherein the feature template library includes multiple mapping relationships between single-character region features and feature vectors.
[0083] Optionally, the update unit includes: a determination subunit, used to determine the coefficient of variation based on the feature values, wherein the coefficient of variation is obtained by a predetermined formula, the predetermined formula being: CV = (SD / Mean) * 100%, where CV represents the coefficient of variation, SD represents the standard deviation of the feature values, and Mean represents the average value of the feature values; and an update subunit, used to update the row height in the original row information using the average value when the coefficient of variation is determined to be greater than a predetermined threshold, to obtain the updated row height.
[0084] Optionally, the device for determining the line size in the text recognition further includes a smoothing unit, which, after determining the line size of the text recognition result based on the updated line height, performs smoothing processing on the characters in the text recognition result that need to be adjusted in size based on the line size, to obtain the smoothed text recognition result.
[0085] Optionally, the device for determining the line size in text recognition further includes a restoration unit, used to restore the layout of the target text based on the smoothed text recognition result.
[0086] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein the program executes the method for determining the line size of text recognition as described above.
[0087] Optionally, in this embodiment, the computer-readable storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any communication device in a group of communication devices.
[0088] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: performing text recognition on the target text using optical character recognition to obtain a text recognition result, wherein the target text is the text to be recognized; obtaining all the original line information in the target text from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least: line height; extracting a predetermined number of lines of text from each original line information as sample text; determining the feature value of the line height of each sample text, wherein the feature value includes at least: mean and standard deviation; updating the line height in the original line information according to the feature value to obtain the updated line height; and determining the line number of the text recognition result according to the updated line height.
[0089] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: scanning the target text to obtain an initial text image corresponding to the target text; preprocessing the initial text image to obtain a preprocessed initial text image, wherein the preprocessing includes at least one of the following operations: binarization, denoising, and tilt correction; and recognizing the initial text image using optical character recognition to obtain a text recognition result.
[0090] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: analyzing the initial text image using a layout analysis algorithm to segment and line-divide the initial text image to obtain a layout analysis image; performing character segmentation on the layout analysis image to obtain a character-segmented layout analysis image; and performing character recognition on the character-segmented layout analysis image to obtain a text recognition result.
[0091] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: determining pixel information of a layout analysis image; obtaining the frame region of a single character in the layout analysis image based on the pixel information; determining the frame region as a single character region feature; and obtaining a text recognition result based on the single character region feature.
[0092] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: determining the feature vector of each character based on the single-character region features; matching the feature vector with a feature template library to obtain the text recognition result, wherein the feature template library includes multiple mapping relationships between single-character region features and feature vectors.
[0093] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: determining the coefficient of variation based on the feature values, wherein the coefficient of variation is obtained by a predetermined formula, the predetermined formula being: CV = (SD / Mean) * 100%, where CV represents the coefficient of variation, SD represents the standard deviation of the feature values, and Mean represents the average value of the feature values; when it is determined that the coefficient of variation is greater than a predetermined threshold, updating the row height in the original row information using the average value to obtain the updated row height.
[0094] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: smoothing the characters in the text recognition result that need to be adjusted in size according to the line font size, so as to obtain the smoothed text recognition result.
[0095] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: restoring the layout of the target text based on the smoothed text recognition result.
[0096] According to another aspect of the present invention, a processor is also provided, which is used to run a program, wherein the program executes the method for determining the line size of text recognition as described above.
[0097] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0098] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0099] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0100] 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 units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0101] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0102] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or 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, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0103] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for determining the size of the characters in a line of text, characterized in that, include: The target text is the text to be recognized by optical character recognition. Obtain all original line information of the target text from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least: line height; Extract a predetermined number of lines of text from each of the original line information as sample text; Determine the feature values of the line height of each of the sample texts, wherein the feature values include at least: mean and standard deviation; The row height in the original row information is updated based on the feature value to obtain the updated row height; The line number of the text recognition result is determined based on the updated line height; The step of updating the row height in the original row information according to the feature value to obtain the updated row height includes: The coefficient of variation is determined based on the eigenvalues, wherein the coefficient of variation is obtained by a predetermined formula, the predetermined formula being: CV = (SD / Mean) * 100%, where CV represents the coefficient of variation, SD represents the standard deviation of the eigenvalues, and Mean represents the average value of the eigenvalues; When the coefficient of variation is determined to be greater than a predetermined threshold, the row height in the original row information is updated using the average value to obtain the updated row height; After determining the line number of the text recognition result based on the updated line height, the method further includes: Based on the line size, the characters in the text recognition result that require font size adjustment are smoothed to obtain the smoothed text recognition result.
2. The method for determining the line size in text recognition according to claim 1, characterized in that, The target text is recognized using optical character recognition (OCR), and the text recognition results include: The target text is scanned to obtain an initial text image corresponding to the target text; The initial text image is preprocessed to obtain the preprocessed initial text image, wherein the preprocessing includes at least one of the following operations: binarization, denoising, and tilt correction. The initial text image is recognized using the optical character recognition method to obtain the text recognition result.
3. The method for determining the line size in text recognition according to claim 2, characterized in that, The initial text image is recognized using the optical character recognition method to obtain the text recognition result, including: The initial text image is analyzed using a layout analysis algorithm to segment and line-divide the initial text image, thereby obtaining a layout analysis image. The layout analysis image is subjected to character segmentation processing to obtain the layout analysis image after character segmentation; The text recognition result is obtained by performing character recognition on the page analysis image after character segmentation.
4. The method for determining the line size in text recognition according to claim 3, characterized in that, The text recognition result is obtained by performing character recognition on the page analysis image after character segmentation, including: Determine the pixel information of the layout analysis image; The frame area of a single character in the layout analysis image is obtained based on the pixel information; The frame region is determined to be a single-character region feature of the single character; The text recognition result is obtained based on the single-character region features.
5. The method for determining the line size in text recognition according to claim 4, characterized in that, The text recognition result is obtained based on the single-character region features, including: The feature vector of each character is determined based on the characteristics of the character region. The feature vector is matched with the feature template library to obtain the text recognition result, wherein the feature template library includes the mapping relationship between multiple single-character region features and feature vectors.
6. The method for determining line size in text recognition according to claim 1, characterized in that, Also includes: The layout of the target text is restored based on the text recognition results after smoothing.
7. A device for determining the line size in text recognition, characterized in that, include: The recognition unit is used to perform text recognition on the target text using optical character recognition to obtain the text recognition result, wherein the target text is the text to be recognized; The acquisition unit is used to acquire all the original line information in the target text from the text recognition result, wherein the original line information is the actual line information of the target text, and the line information includes at least: line height; An extraction unit is used to extract a predetermined number of lines of text from each of the original line information as sample text; The first determining unit is used to determine the feature value of the line height of each of the sample texts, wherein the feature value includes at least: mean and standard deviation; An update unit is used to update the row height in the original row information according to the feature value to obtain the updated row height; The second determining unit is used to determine the line number of the text recognition result based on the updated line height; The update unit includes: A sub-unit is defined for determining the coefficient of variation based on the feature values, wherein the coefficient of variation is obtained by a predetermined formula, the predetermined formula being: CV = (SD / Mean) * 100%, where CV represents the coefficient of variation, SD represents the standard deviation of the feature values, and Mean represents the average value of the feature values; An update subunit is used to update the row height in the original row information using the average value when the coefficient of variation is determined to be greater than a predetermined threshold, so as to obtain the updated row height. The device for determining line size in the text recognition also includes: A smoothing processing unit is used to smooth the characters in the text recognition result that need to be adjusted in size according to the line number after the line number of the text recognition result is determined according to the updated line height, so as to obtain the smoothed text recognition result.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program executes the method for determining the line size of text recognition as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Document word size identification method and device, computer equipment and storage medium
CN115131803A