Character height recognition method and device for table picture, storage medium and equipment
By dynamically adjusting the grayscale threshold and adjacent height range in the table image, the time consumption and deviation problems of the sliding window recognition method are solved, achieving more efficient and accurate character height recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- IFLYTEK CO LTD
- Filing Date
- 2022-12-16
- Publication Date
- 2026-07-24
AI Technical Summary
Existing methods for character height recognition in table images based on sliding windows suffer from high time costs, large result deviations, and difficulty in determining the initial height of the sliding window when dealing with table images with too many elements or moiré patterns, leading to inaccurate character height recognition.
By acquiring a grayscale table image, setting a grayscale threshold to convert it to a black and white image, extracting contour points and filtering bounding boxes, dynamically adjusting the grayscale threshold to obtain more bounding boxes, and determining the character height by using adjacent height ranges, the time consumption and deviation of sliding windows are avoided.
It improves the accuracy and efficiency of character height recognition in table images, is suitable for character height recognition in complex scenarios, reduces time consumption and lowers result deviation.
Smart Images

Figure CN115937884B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, specifically to a method, apparatus, computer-readable storage medium, and computer device for recognizing the character height of a table image. Background Technology
[0002] Optical character recognition (OCR) is an important field in deep learning, commonly used to extract text and structure from images, especially tables. The size of characters and the presence of moiré patterns in table images often pose significant challenges to OCR recognition.
[0003] Currently, the method for recognizing character height in table images is usually based on sliding windows. For example, for a table image, several sliding windows with fixed heights are first set from top to bottom. All bounding boxes are found in each sliding window, some abnormal bounding boxes are filtered out, and then the sum and number of bounding box heights are counted. Finally, the ratio between them is taken as the character height recognition result.
[0004] While the current solution can roughly estimate the character height in a table image, it has a large deviation in character height recognition for table images with too many elements, especially those with moiré patterns, resulting in inaccurate character height recognition results. Summary of the Invention
[0005] This application provides a method, apparatus, computer-readable storage medium, and computer device for recognizing the character height in a table image, which can improve the accuracy of character height recognition in a table image.
[0006] This application provides a method for recognizing the character height of a table image, including:
[0007] Obtain the grayscale image of the table and the set grayscale threshold;
[0008] Convert the table image into a black and white image based on the grayscale threshold.
[0009] Extract the contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0010] If the number of remaining bounding boxes is less than the preset number of bounding boxes, the grayscale threshold is updated according to the preset grayscale value to obtain the updated grayscale threshold, and then the step of converting the table image into a black and white image according to the grayscale threshold is performed.
[0011] If the number of remaining bounding boxes is not less than the preset number of bounding boxes, the character height of the table image is determined based on the height of the remaining bounding boxes.
[0012] This application also provides a method for recognizing the character height of a table image, including:
[0013] Obtain the grayscale image of the table and the set grayscale threshold;
[0014] Convert the table image into a black and white image based on the grayscale threshold.
[0015] Extract the contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0016] Multiple adjacent height ranges are determined based on the height of the remaining bounding box;
[0017] The character height of the table image is determined based on the stated height and the plurality of adjacent height ranges.
[0018] This application embodiment also provides a character height recognition device for table images, including:
[0019] The acquisition module is used to acquire a grayscale table image and obtain the set grayscale threshold.
[0020] The conversion module is used to convert the table image into a black and white image based on the grayscale threshold.
[0021] The extraction and filtering module is used to extract contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0022] An update module is used to update the grayscale threshold according to a preset grayscale value if the number of remaining bounding boxes is less than the preset number of bounding boxes, so as to obtain the updated grayscale threshold, and then trigger the conversion module.
[0023] A height recognition module is used to determine the character height of the table image based on the height of the remaining bounding boxes if the number of remaining bounding boxes is not less than the preset number of bounding boxes.
[0024] This application embodiment also provides a character height recognition device for table images, including:
[0025] The acquisition module is used to acquire a grayscale table image and obtain the set grayscale threshold.
[0026] The conversion module is used to convert the table image into a black and white image based on the grayscale threshold.
[0027] The extraction and filtering module is used to extract contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0028] A height recognition module is used to determine multiple adjacent height intervals based on the height of the remaining bounding box; and to determine the character height of the table image based on the height and the multiple adjacent height intervals.
[0029] This application also provides a computer-readable storage medium storing a computer program adapted for loading by a processor to perform the steps in the character height recognition method for table images as described in any of the above embodiments.
[0030] This application also provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the steps in the character height recognition method for table images as described in any of the above embodiments by calling the computer program stored in the memory.
[0031] The method, apparatus, computer-readable storage medium, and computer device for character height recognition of table images provided in this application embodiment acquire a grayscale table image and obtain a set grayscale threshold. Based on the grayscale threshold, the table image is converted into a black and white image. Contour points are extracted from the black and white image, converted into bounding boxes, and anomaly filtering is performed on the bounding boxes to obtain remaining bounding boxes. If the number of remaining bounding boxes is less than a preset number of bounding boxes, the grayscale threshold is updated based on a preset grayscale value to obtain an updated grayscale threshold. Then, the step of converting the table image into a black and white image based on the grayscale threshold is executed. If the number of remaining bounding boxes is not less than the preset number of bounding boxes, the character height of the table image is determined based on the height of the remaining bounding boxes. In this application embodiment, by setting a grayscale threshold and adjusting it when the number of remaining bounding boxes is less than the preset number of bounding boxes, more bounding boxes are recognized, thus avoiding the problem of insufficient character height recognition or inaccurate character height recognition due to too few remaining bounding boxes. That is, this application embodiment improves the accuracy of character height recognition by dynamically adjusting the grayscale threshold to recognize more bounding boxes. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0033] Figure 1 This is a flowchart illustrating the method for recognizing the character height of a table image provided in an embodiment of this application.
[0034] Figure 2 This is a schematic diagram of the identified bounding box provided in an embodiment of this application.
[0035] Figure 3 This is a flowchart illustrating a method for recognizing the character height of a table image provided in an embodiment of this application.
[0036] Figure 4 Another flowchart illustrating the method for recognizing the character height of a table image provided in this application embodiment.
[0037] Figure 5 This is a schematic diagram of a manually annotated bounding box provided in an embodiment of this application.
[0038] Figure 6 This is a schematic diagram illustrating the recognition time of 2479 table images provided in the embodiments of this application.
[0039] Figure 7 This is a schematic diagram illustrating the table structure recognition effect without zooming in on the table image, as provided in an embodiment of this application.
[0040] Figure 8 This is a schematic diagram illustrating the table structure recognition effect when the table image is magnified 2 times as provided in the embodiments of this application.
[0041] Figure 9 This is a schematic diagram illustrating the table structure recognition effect when the table image is magnified 4 times according to an embodiment of this application.
[0042] Figure 10 A schematic diagram of the structure of the character height recognition device for the table image provided in the embodiments of this application.
[0043] Figure 11 A schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0044] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0045] This application provides a method, apparatus, computer-readable storage medium, and computer device for recognizing the character height of a table image. Specifically, the method for recognizing the character height of a table image in this application can be executed by a computer device, which can be a terminal or a server. The terminal can be a smartphone, tablet computer, laptop computer, touch screen, robot, personal computer (PC), in-vehicle device, or other terminal device. The server can be a standalone physical server, a server cluster consisting of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services and cloud databases.
[0046] Before introducing the solutions in the embodiments of this application, we will further analyze the current character height recognition solutions based on sliding windows.
[0047] The character height recognition scheme based on sliding windows involves setting several sliding windows of fixed height from top to bottom for a table image. Within each sliding window, the outline points of the table image are first obtained, then some abnormal bounding boxes are filtered out, and the heights of bounding boxes that meet the rules are counted. The total height and number of each sliding window are counted from top to bottom, and finally the maximum total height and number are taken, and the ratio between them is taken as the character height recognition result.
[0048] Current character height recognition schemes based on sliding windows require statistical analysis of all contour points under each sliding window, which presents several major problems:
[0049] First, the time cost is too high. The sliding window-based approach involves a large amount of computation, with the same calculations performed in each sliding window. Additionally, filtering out abnormal bounding boxes by setting rules incurs additional time consumption. In total, for table images with too many elements or moiré patterns, recognizing a single table image can take several minutes.
[0050] Second, the bias is too large. The sliding window-based approach calculates the final character height by comparing the sum of the maximum heights with the number of characters. This method is prone to introducing large biases, especially with a fixed window height. Many characters in table images will be vertically segmented by the sliding window, thus underestimating the statistical results and leading to significant errors.
[0051] Third, determining the initial height of the sliding window. Different heights will have vastly different effects on different table images. Currently, the initial height of the window is mainly fixed by setting a fraction of the table image height. However, this approach only considers the table image height and doesn't account for the fact that the height of the characters and the table image may not be proportional in different scenarios. For example, image A is 1000*1000 pixels with a character height of 10, and image B is 100*100 pixels with a character height of 10. In this case, taking a fraction of the image size as the fixed height of the sliding window introduces a discrepancy.
[0052] Therefore, the high time cost, large result deviation, and difficulty in determining the initial height of the sliding window in the sliding window-based scheme pose challenges to the character height recognition of table images, affecting the accuracy and efficiency of character height recognition in table images.
[0053] The solution in this application embodiment does not require setting a sliding window, and identifies the character height in a table image in a completely new way, improving the accuracy and efficiency of character height recognition in table images.
[0054] The following will provide a detailed description of a method, apparatus, computer-readable storage medium, and computer device for recognizing the character height of a table image according to embodiments of this application. It should be noted that the sequence numbers of the following embodiments are not intended to limit the preferred order of the embodiments.
[0055] Figure 1 This is a flowchart illustrating a method for recognizing the character height of a table image provided in an embodiment of this application. The method is applied in a computer device and includes the following steps.
[0056] 101. Obtain the grayscale table image and the set grayscale threshold.
[0057] In this context, a table image refers to an image whose content includes a table. A grayscale table image is a table image obtained by converting the original table image to grayscale. Most original table images in practice are color images with RGB channels; the grayscale image obtained after converting the original table image to grayscale is called a grayscale table image.
[0058] Grayscale table images are single-channel images. Processing grayscale table images can speed up the calculation while preserving gradient information, which is of great significance for contour point detection in the following text. The statistics of character height in table images are based on contour points, which will be described later.
[0059] The set grayscale threshold can be a default grayscale threshold, which can be the grayscale threshold calculated after recognizing the character height of multiple table images. This can be understood as the accuracy of character height recognition of table images being relatively high under this default grayscale threshold. Alternatively, the default grayscale threshold can be the minimum or maximum grayscale threshold at which most table images can be correctly recognized for character height recognition; or any grayscale threshold between the minimum and maximum grayscale thresholds, etc.
[0060] In this embodiment, the grayscale threshold is set to the default grayscale threshold of 120 for illustration.
[0061] 102. Convert the table image to a black and white image based on the grayscale threshold.
[0062] For each pixel in the table image, obtain the corresponding grayscale value. If the grayscale value is greater than the grayscale threshold, set the grayscale value of that pixel to zero; otherwise, set the grayscale value of that pixel to 255. This process converts the table image into a black and white image, also known as a binary image, based on the grayscale threshold. The main purpose of converting the table image to a black and white image is to facilitate the extraction of contour points and improve the speed of contour point extraction; in other words, it prepares the image for contour point extraction.
[0063] For example, set pixels with a grayscale value greater than 120 in the table image to zero, and set pixels with a grayscale value no greater than 120 in the table image to 255.
[0064] 103. Extract the contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0065] First, extract the contour points from the black and white image. Specifically, you can use a contour point extraction interface to extract the contour points from the black and white image. For example, you can use the `findContours` function in OpenCV to extract the contour points and obtain the coordinates and structure of all contour points in the black and white image. By extracting the contour points from the black and white image, you can find the positions of the characters in the table image.
[0066] Next, the contour points are converted into bounding boxes. Specifically, the contour point conversion interface can be called to convert the extracted contour points, find the bounding rectangle of each contour point, and use this bounding rectangle as the bounding box corresponding to the contour point. For example, the `boundingRect` function in OpenCV can be called to extract the bounding box from the contour points. By converting the contour points into bounding boxes, the bounding boxes containing the characters in the table image can be found. Figure 2 The image shown is a schematic diagram of the bounding boxes containing some of the characters extracted from the table image.
[0067] Next, anomaly filtering is performed on the bounding boxes. Since there may be many bounding boxes for the contour points extracted using OpenCV functions, if the bounding box is too small, it will not effectively frame the position of the character, and if the bounding box is too large, it will frame many characters, resulting in an overestimation of the value. Both excessively large and small bounding boxes will cause deviations in the recognition of character height. Therefore, anomaly filtering is required for the bounding boxes.
[0068] In this embodiment, the width and height of each bounding box are first obtained, as well as the width, height and height of the table image. Then, anomaly filtering is performed on the bounding boxes based on their width and height, and the width and height of the table image.
[0069] The filtering conditions for abnormal bounding boxes are as follows: the width of the bounding box is not greater than a first preset pixel, or the height of the bounding box is not greater than a second preset pixel, or the width of the bounding box is not less than the width of the table image at a first preset ratio, or the height of the bounding box is not less than the height of the table image at a second preset ratio. The first and second preset pixels can be the same or different; for example, both the first and second preset pixels can be 5 pixels or other suitable pixels. Similarly, the first and second preset ratios can be the same or different; for example, both can be set to 1 / 10 or other suitable ratios.
[0070] For each bounding box, determine whether its width or height meets the above filtering conditions. If the filtering conditions are met, the corresponding bounding box is filtered. If the filtering conditions are not met, it means that the width of the bounding box is greater than the first preset pixel, the height of the bounding box is greater than the second preset pixel, the width of the bounding box is less than the width of the table image with the first preset ratio, and the height of the bounding box is less than the height of the table image with the second preset ratio. That is, it does not meet all four conditions at the same time, so the corresponding bounding box is retained. In this way, each bounding box is processed to filter out the bounding boxes that meet the filtering conditions, and the remaining bounding boxes are obtained.
[0071] By using filtering conditions, a batch of abnormal bounding boxes can be effectively filtered out, thereby reducing the bias in subsequent statistics, improving the accuracy of character height recognition, and speeding up post-processing, thus improving the efficiency of character height recognition.
[0072] 104. If the number of remaining bounding boxes is less than the preset number of bounding boxes, update the grayscale threshold according to the preset grayscale value to obtain the updated grayscale threshold. Then proceed to step 102.
[0073] The preset number of bounding boxes can be the minimum number of bounding boxes that can correctly identify the character height, or other bounding box numbers obtained based on experience. In one embodiment, the preset number of bounding boxes can be set to 5.
[0074] If the number of remaining bounding boxes is less than the preset number of bounding boxes, it means that the number of remaining bounding boxes after filtering is too small. If the number of remaining bounding boxes is too small, the final result is not very accurate. Inaccuracy can easily lead to deviations and affect the accuracy and precision of character recognition results.
[0075] Therefore, the grayscale threshold is updated based on the preset grayscale value to obtain the updated grayscale threshold.
[0076] If the default grayscale threshold is the minimum grayscale threshold, then updating the grayscale threshold according to the preset grayscale value to obtain the updated grayscale threshold may include: adding the preset grayscale value to the current grayscale threshold to obtain the updated grayscale threshold.
[0077] If the default grayscale threshold is the maximum grayscale threshold, then updating the grayscale threshold according to the preset grayscale value to obtain the updated grayscale threshold may include: subtracting the preset grayscale value from the current grayscale threshold to obtain the updated grayscale threshold.
[0078] If the default grayscale threshold is the grayscale threshold between the maximum grayscale threshold and the minimum grayscale threshold, then updating the grayscale threshold according to the preset grayscale value to obtain the updated grayscale threshold can include: adding the preset grayscale value to the current grayscale threshold to obtain the updated grayscale threshold; or subtracting the preset grayscale value from the current grayscale threshold to obtain the updated grayscale threshold.
[0079] The preset grayscale value can be an integer such as 20, 15, or 25. For example, if the current grayscale threshold is 120 and the preset grayscale value is 20, then the updated grayscale threshold will be 120 + 20 = 140. The table image is then converted to a black and white image using a grayscale threshold of 140. For the same table image, the preset grayscale value used to update the grayscale threshold each time can be the same or different. If different, the preset grayscale value for each update should be saved in advance. For different table images, the preset grayscale value for each update can be the same.
[0080] The grayscale threshold is dynamically updated based on the preset grayscale value, thereby finding more contour points and obtaining more remaining bounding boxes. More bounding boxes mean more accurate character height recognition results, thus improving the accuracy and precision of character recognition results.
[0081] 105. If the number of remaining bounding boxes is not less than the preset number of bounding boxes, determine the character height of the table image based on the height of the remaining bounding boxes.
[0082] If the number of remaining bounding boxes is not less than the preset number of bounding boxes, it means that the current number of remaining bounding boxes is not too few. In this case, the character height of the table image is determined based on the height of the remaining bounding boxes.
[0083] In one instance, the step of determining the character height of a table image based on the height of the remaining bounding box includes: determining a plurality of adjacent height intervals based on the height of the remaining bounding box; and determining the character height of the table image based on the height and the plurality of adjacent height intervals.
[0084] For example, for each unique height of the remaining bounding boxes, a neighboring height interval is determined, thus obtaining multiple neighboring height intervals. Specifically, for each unique height of the multiple remaining bounding boxes, a first preset height is added to each height to obtain a larger height value, and a second preset height is subtracted from each height to obtain a smaller height value, where both the first and second preset heights are greater than zero. The height interval formed by the smaller and larger height values is used as the neighboring height interval corresponding to each height, thus obtaining multiple neighboring height intervals.
[0085] The first preset height and the second preset height can be the same, for example, the first preset height is 2 and the second preset height is 2. The first preset height and the second preset height can also be different, for example, the first preset height is 1 and the second preset height is 2. In this embodiment, we will use an example where both the first preset height and the second preset height are 1.
[0086] For example, by obtaining the height of each remaining bounding box in the remaining bounding box, a height list can be obtained. For example, the height list 1 can be 1, 2, 3, 2, 5, 5, 5, 8, 8, 9. Based on each unique height in height list 1, the adjacent height intervals are determined. The unique heights in height list 1 are 1, 2, 3, 5, 8, and 9. Correspondingly, the adjacent height interval of height 1 in height list is [0,2], the adjacent height interval of height 2 in height list is [1,3], the adjacent height interval of height 3 in height list is [2,4], and so on. The adjacent height intervals of heights 3, 5, 8, and 9 in height list are [2,4], [4,6], [7,9], and [8,10].
[0087] After determining multiple neighboring height intervals, the character height of the table image is determined based on each height of the remaining bounding box (i.e., each height in the height list) and multiple neighboring height intervals. For multiple neighboring height intervals, the neighboring height interval with the highest occurrence of the height of the remaining bounding box is taken as the target neighboring height interval. The character height of the table image is determined based on the height corresponding to the target neighboring height interval. For example, the height corresponding to the target neighboring height interval is determined as the character height of the table image.
[0088] The beneficial effects of determining the neighboring height range corresponding to each height of the remaining bounding box in this embodiment are also described in the corresponding steps below, and will not be repeated here.
[0089] In one scenario, the step of determining the character height of a table image based on the height of the remaining bounding box includes: obtaining the height of the remaining bounding box to obtain a height list, and determining a pre-set number of candidate heights that appear most frequently from the height list; determining multiple neighboring height intervals corresponding to the multiple candidate heights; and determining the character height of the table image based on the heights in the height list and the multiple neighboring height intervals.
[0090] Specifically, the height of each remaining bounding box in the remaining bounding boxes is obtained to obtain a height list. For example, the obtained height list 1 can be 1, 2, 3, 2, 5, 5, 5, 8, 8, 9.
[0091] After obtaining the height list, a predetermined number of candidate heights with the most occurrences are determined from the height list. These heights are sorted according to their frequency of occurrence, such as from largest to smallest, and the predetermined number of heights is then used as candidate heights. The predetermined number can be 3, 5, etc. In one embodiment, the predetermined number is 3, because 3 is sufficient to ensure accuracy, and a larger number is unnecessary to reduce computational load and time complexity while maintaining accuracy. This embodiment uses a predetermined number of 3 as an example. For instance, in height list 1, the occurrences of 1, 2, 3, 5, 8, and 9 are 1, 2, 1, 3, 2, and 1 respectively. After sorting by frequency from largest to smallest, the first three heights are 5, 2, and 8, which are the candidate heights.
[0092] Next, multiple neighboring height intervals corresponding to multiple candidate heights are determined. Specifically, the step of determining multiple neighboring height intervals corresponding to multiple candidate heights includes: for each candidate height among the multiple candidate heights, adding a first preset height to each candidate height to obtain a larger height value, and subtracting a second preset height from each candidate height to obtain a smaller height value, wherein both the first preset height and the second preset height are greater than zero; the height interval formed by the smaller height value and the larger height value is taken as the neighboring height interval corresponding to each candidate height, so as to obtain multiple neighboring height intervals.
[0093] The first preset height and the second preset height can be the same, for example, the first preset height is 2 and the second preset height is 2. The first preset height and the second preset height can also be different, for example, the first preset height is 1 and the second preset height is 2. In this embodiment, we will use an example where both the first preset height and the second preset height are 1.
[0094] For candidate height 5, adding 1 to 5 gives the larger height value 6, and subtracting 1 from 5 gives the smaller height value 4. Correspondingly, the adjacent height interval corresponding to candidate height 5 is [4, 6]. Similarly, the adjacent height intervals corresponding to candidate heights 2 and 8 are [1, 3] and [7, 9] respectively.
[0095] The purpose of setting the adjacent height interval based on each candidate height is to take into account that in the process of finding the character height of a table picture, due to Chinese fonts, after the height of each character is counted by code, there may be slight differences. For example, for the two characters "三个", the height of "个" is slightly higher than that of "三". Therefore, by setting the adjacent height interval, the statistical character height can be made more accurate and the accuracy of character height recognition can be improved.
[0096] It can also be understood from the opposite side why the adjacent height interval needs to be set. For example, the heights in height list 2 are 2, 3, 2, 3, 1, 1, 4, 4, 10, 10, 10. Obviously, the character height is around 2 or 3 because the heights in height list 2 are concentrated in this range. However, if there is no adjacent height interval, the finally counted height is 10. Therefore, 10 appears the most times, which has a large deviation from the actual situation and the statistical result is not accurate enough. But if the adjacent height interval is set, it can be seen that the number of heights appearing within the adjacent height interval of height 10 is obviously less than the number of heights appearing within the adjacent height interval of height 2. Setting the adjacent height interval also ensures that the final error is smaller, the result is more accurate, and the accuracy of character height recognition is improved.
[0097] After obtaining multiple adjacent height intervals, determine the character height of the table picture according to the heights in the height list and the multiple adjacent height intervals. Specifically, for multiple adjacent height intervals, take the adjacent height interval with the most occurrences of the heights in the height list as the target adjacent height interval; determine the character height of the table picture according to the candidate height corresponding to the target adjacent height interval.
[0098] For example, for the adjacent height intervals corresponding to 2, 5, and 8 in height list 1, which are [1, 3], [4, 6], and [7, 9] respectively, the number of heights appearing in the adjacent height interval [1, 3] is 4, the number of heights appearing in the adjacent height interval [4, 6] is 3, and the number of heights appearing in the adjacent height interval [7, 9] is 3. Then, correspondingly, the adjacent height interval [1, 3] has the most occurrences of heights. Take the adjacent height interval [1, 3] as the target adjacent height interval, and take the candidate height 2 corresponding to the target adjacent height interval as the character height of the table picture.
[0099] Understandably, the heights of characters in a table image will vary, but since they are characters within a table image, their heights generally won't differ significantly; most should be similar. Using the candidate heights corresponding to the nearest height range of the target character as the character height in the table image also aligns with real-world scenarios.
[0100] The above method embodiments can ensure that the number of remaining bounding boxes is not less than the preset number of bounding boxes by using the dynamic grayscale threshold method, thereby improving the recognition accuracy and precision. Furthermore, the method of using the adjacent height interval can further improve the character recognition accuracy of table images. The above method embodiments are suitable for character height recognition in complex scenes, and are still applicable to table images with too many elements and severe moiré patterns. Moreover, they have high execution efficiency. Since there is no need to consider the initial height setting of the sliding window, the time consumption and accuracy error caused by the sliding window are avoided.
[0101] In one embodiment, before the step of converting the table image to a black and white image based on a grayscale threshold, the method further includes: obtaining the width and height of the table image, and determining the larger of the width and height; determining a scaling factor based on the larger value and a preset range, for example, determining a scaling factor to scale the larger value to within a preset range; and scaling the table image according to the scaling factor. Correspondingly, after determining the character height of the table image, the method further includes: determining the final character height of the table image based on the scaling factor and the character height. In this embodiment, scaling the table image according to the scaling factor and scaling it to a preset range allows for faster finding of contour points and determination of bounding boxes, improving the efficiency of character height recognition.
[0102] In one embodiment, after obtaining the updated grayscale threshold, the method further includes: detecting whether the updated grayscale threshold exceeds the threshold range corresponding to the preset grayscale threshold; if so, determining the character height of the table image based on the default character height; if not, then proceeding to the step of converting the table image into a black and white image based on the grayscale threshold. This embodiment further defines the loop termination condition, namely whether the updated grayscale threshold exceeds the threshold range corresponding to the preset grayscale threshold. This avoids terminating the character height recognition of multiple table images due to one table image not recognizing a suitable character height.
[0103] Figure 3 This is a flowchart illustrating a method for recognizing the character height of a table image provided in an embodiment of this application. The method is applied in a computer device and includes the following steps.
[0104] 201. Obtain the grayscale table image and the set grayscale threshold.
[0105] 202. Convert the table image to a black and white image based on the grayscale threshold.
[0106] 203. Extract the contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0107] Please refer to the descriptions of the corresponding steps above for details of steps 201 to 203, which will not be repeated here.
[0108] 204. Determine multiple adjacent height ranges based on the height of the remaining bounding box.
[0109] For example, for each unique height of the remaining bounding box, a neighboring height interval is determined, thus obtaining multiple neighboring height intervals.
[0110] Specifically, for each unique height of multiple remaining bounding boxes, a first preset height is added to each height to obtain a larger height value, and a second preset height is subtracted from each height to obtain a smaller height value, wherein both the first preset height and the second preset height are greater than zero; the height interval formed by the smaller height value and the larger height value is used as the neighboring height interval corresponding to each height to obtain multiple neighboring height intervals.
[0111] In one scenario, the step of determining multiple neighboring height intervals based on the height of the remaining bounding box includes: obtaining the height of the remaining bounding box to obtain a height list, and determining a pre-set number of candidate heights that appear most frequently from the height list; and determining multiple neighboring height intervals corresponding to the multiple candidate heights.
[0112] 205. Determine the character height of the table image based on its height and multiple adjacent height ranges.
[0113] After determining multiple neighboring height intervals, the character height of the table image is determined based on each height of the remaining bounding box (i.e., each height in the height list) and multiple neighboring height intervals. For multiple neighboring height intervals, the neighboring height interval with the highest occurrence of the height of the remaining bounding box is taken as the target neighboring height interval. The character height of the table image is determined based on the height corresponding to the target neighboring height interval. For example, the height corresponding to the target neighboring height interval is determined as the character height of the table image.
[0114] In one scenario, after obtaining the remaining bounding boxes, the method further includes: if the number of remaining bounding boxes is less than a preset number of bounding boxes, updating the grayscale threshold according to a preset grayscale value to obtain an updated grayscale threshold, and then performing the step of converting the table image into a black and white image according to the grayscale threshold; if the number of remaining bounding boxes is not less than the preset number of bounding boxes, performing the step of determining multiple adjacent height intervals based on the height of the remaining bounding boxes.
[0115] Furthermore, after obtaining the updated grayscale threshold, the method further includes: detecting whether the updated grayscale threshold exceeds the threshold range corresponding to the preset grayscale threshold; if not, then proceeding to the step of converting the table image into a black and white image based on the grayscale threshold; if so, then determining the character height of the table image based on the default character height.
[0116] In one scenario, before the step of converting the table image to a black and white image based on the grayscale threshold, the method further includes: obtaining the width and height of the table image and determining the larger of the width and the height; determining a scaling factor based on the larger value and a preset range; scaling the table image based on the scaling factor; and after determining the character height of the table image, the method further includes: determining the final character height of the table image based on the scaling factor and the character height.
[0117] Figure 4 This is another flowchart illustrating the method for recognizing the character height of a table image provided in this application embodiment. The method is applied in a computer device and includes the following steps.
[0118] 301. Obtain the grayscale table image and the set grayscale threshold.
[0119] 302. Get the width and height of the table image and determine the larger of the two values.
[0120] In this context, width can also be understood as length. After obtaining the width and height of the table image, determine the larger of the two values. For example, if the size of the table image is 2098*1054, then the width is 2098 and the height is 1054, with the larger of the two values being 2098.
[0121] 303, determine whether the table image needs to be scaled based on the larger value.
[0122] For very large and complex table images, the sheer number of elements significantly increases the time cost during contour point recognition and bounding box determination. To improve efficiency, table images are scaled proportionally. Extensive experimental results show that performance is fastest when the maximum value is below 500.
[0123] The need for scaling of table images can be determined by the largest value. Specifically, if the largest value is greater than 1000, the table image needs scaling; if the largest value is less than or equal to 1000, the table image does not need scaling. Alternatively, if the largest value is greater than a preset pixel value (1000), the table image needs scaling; if the largest value is not greater than a preset pixel value, the table image does not need scaling. This ensures that the maximum value of all resulting table images is below 1000, accelerating the efficiency of subsequent contour point recognition and bounding box determination, and improving the efficiency of character height recognition.
[0124] If scaling is required, proceed to step 304; otherwise, proceed to step 305.
[0125] 304. Determine the scaling factor based on the larger value and the preset range, and scale the table image accordingly.
[0126] The preset range is [0, 1000]. The larger value is controlled within the preset range, and the corresponding scaling factor is determined accordingly. For example, if 1000 < the larger value <= 2000, the scaling factor is determined to be 2; if 2000 < the larger value <= 3000, the scaling factor is determined to be 4; if 3000 < the larger value <= 4000, the scaling factor is determined to be 6; if 4000 < the larger value <= 5000, the scaling factor is determined to be 8, and so on, to determine the scaling factor of the table image.
[0127] After determining the scaling factor for the table image, scale the image accordingly. The scaled table image is typically between 500 and 1000 pixels in size. This scaling process improves the efficiency of extracting contour points later.
[0128] 305. Convert the table image to a black and white image based on the grayscale threshold.
[0129] 306. Extract the contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0130] 307. Is the number of remaining bounding boxes less than the preset number of bounding boxes?
[0131] If the number of remaining bounding boxes is not less than the preset number of bounding boxes, proceed to step 308; otherwise, proceed to step 312.
[0132] 308. Obtain the height of the remaining bounding box to get a height list, and determine the first preset number of candidate heights that appear most frequently from the height list.
[0133] 309, determine multiple neighboring height intervals corresponding to multiple candidate heights.
[0134] 310. For multiple neighboring height intervals, the neighboring height interval with the highest frequency of height in the height list is taken as the target neighboring height interval, and the character height of the table image is determined according to the candidate height and scaling factor corresponding to the target neighboring height interval.
[0135] If the number of remaining bounding boxes is not less than the preset number of bounding boxes, it means that the current number of remaining bounding boxes is not too few, or that the current number of remaining bounding boxes will not cause a non-negligible error in height recognition. Therefore, the character height of the table image can be further determined directly based on the height of the current remaining bounding boxes.
[0136] Specifically, after determining the candidate heights corresponding to the target's neighboring height ranges, the character height of the table image is determined based on the candidate heights and the scaling factor. For example, the candidate height is multiplied by the scaling factor to obtain the character height of the table image. Since the table image was previously scaled down, the character height after scaling down is the candidate height. Therefore, the character height of the restored table image is the candidate height multiplied by the scaling factor. For example, if the candidate height is 4 and the scaling factor is 2, then the character height of the table image is 2 * 4 = 8.
[0137] 311. Determine the final character height of the table image based on the character height and scaling factor.
[0138] 312. Update the grayscale threshold according to the preset grayscale value to obtain the updated grayscale threshold.
[0139] If the number of remaining bounding boxes is less than the preset number of bounding boxes, it means that the number of remaining bounding boxes after filtering is too small. A small number of remaining bounding boxes can easily lead to errors. Therefore, the grayscale threshold is updated based on the preset grayscale value to obtain the updated grayscale threshold. This step involves a dynamic grayscale thresholding method, which dynamically updates the grayscale threshold using the preset grayscale value, and then performs subsequent processing based on the updated grayscale threshold.
[0140] 313. Check whether the updated grayscale threshold exceeds the threshold range corresponding to the preset grayscale threshold.
[0141] If the default grayscale threshold starts from the minimum adjustable grayscale threshold, and the update increments the preset grayscale value from the minimum grayscale threshold, then the preset grayscale threshold becomes the maximum adjustable grayscale threshold. The threshold range corresponding to the preset grayscale threshold is the threshold range of the maximum grayscale threshold. For example, if the default grayscale threshold is 120 and the maximum grayscale threshold is 200, then the update grayscale threshold is checked to see if it exceeds 200. If the default grayscale threshold starts from the maximum adjustable grayscale threshold, and the update increments the preset grayscale value from the maximum grayscale threshold, then the preset grayscale threshold becomes the minimum adjustable grayscale threshold. For example, if the default grayscale threshold is 200 and the minimum grayscale threshold is 120, then the update grayscale threshold is checked to see if it is less than 120. If the default grayscale threshold starts from a grayscale threshold between the minimum and maximum adjustable grayscale thresholds, then the preset grayscale threshold is [minimum grayscale threshold, maximum grayscale threshold], and the update grayscale threshold is checked to see if it is less than 120 or greater than 200.
[0142] If not, it means that the updated grayscale threshold is within the threshold range corresponding to the preset grayscale threshold, and further processing can continue. Accordingly, step 305 is executed. If yes, it means that the updated grayscale threshold has exceeded the threshold range corresponding to the preset grayscale threshold, and no further adjustment can be made. Accordingly, step 314 is executed.
[0143] 314. Determine the character height of the table image based on the default character height and scaling factor.
[0144] If the updated grayscale threshold exceeds the threshold range corresponding to the preset grayscale threshold, meaning that multiple grayscale threshold adjustments have resulted in the remaining bounding box not meeting the requirements, then no further adjustments will be made. The character height of the table image will be determined based on the default character height and the scaling factor. For example, the character height of the table image will be obtained by multiplying the default character height by the scaling factor. If the table image is not scaled, the scaling factor defaults to 1.
[0145] The default character height can be set to 10, 11, 12, 15, 20, etc. In some embodiments, the default character height is preferably set to 10 because after scaling the table image according to the scaling factor, most table images are uniformly in the range of 500 to 1000. Within this range, the character height is generally around 10. Therefore, the default character height is set to 10. If the scaling factor is 2, then the character height of the table image determined by the default character height and the scaling factor is 10 * 2 = 20.
[0146] Another purpose of setting a default character height is to determine the final character height of a table image when some table images have too few elements to obtain the character height statistically. This ensures that the computer program will not be interrupted during operation and guarantees its robustness.
[0147] In this embodiment, the table image is scaled using a scaling factor so that the maximum value of the scaled table image is mostly between 500 and 1000, improving the efficiency of extracting contour points and determining bounding boxes. Furthermore, this embodiment sets a grayscale threshold, and adjusts the grayscale threshold when the number of remaining bounding boxes is less than a preset number, thereby recognizing more bounding boxes and avoiding problems such as inaccurate character height recognition due to too few remaining bounding boxes. Additionally, if the number of remaining bounding boxes does not meet the standard within the preset grayscale threshold range, a default character height is set, and the character height of the table image is determined based on the default character height, ensuring the robustness of the computer program. Moreover, by setting a proximity height range, considering the size of Chinese fonts, the proximity height range reduces errors and improves the accuracy of character height recognition. Furthermore, the character height recognition method in this embodiment is applicable to character height recognition in table images in complex scenarios; even the presence of moiré patterns in the table image has little impact on the recognition results, resulting in faster recognition speed and higher accuracy.
[0148] In order to evaluate this embodiment ( Figure 4 The deviation of the character height recognition method in the illustrated embodiment from the character height recognition in table images was addressed by manually annotating the data. A dataset of 60 table images was created using the labelImg tool, with each table image having three bounding boxes, as shown below. Figure 5 As shown, the text in the three labeled boxes is "Ending Investment Cost", "-10000.00", and "Present Value Ratio", respectively. After labeling, an XML file corresponding to each image is automatically generated. The file contains the position of each labeled box. The height of each labeled box is obtained by calculating the height difference between the top and bottom edges, and the average of the three heights is taken to obtain the final result. Figure 5 It can be observed that the actual bounding box annotated manually is slightly larger than the character height.
[0149] Using the same dataset, the method in this application embodiment is used to obtain the prediction result for each table image. Then, the degree of deviation of the prediction result is determined based on the actual result and the prediction result, and the average of the deviation degrees of multiple table images is used as the overall deviation. For example, the difference between the actual result and the prediction result is divided by the actual result to obtain the deviation degree of the corresponding table image, where the deviation degree = (|gt-pred|) / gt*100%.
[0150] Experimental results show that the overall bias on 60 manually labeled datasets is 23.9%. From the perspective of the distribution of recognized character heights, the prediction results obtained by the character height recognition method in this application embodiment are smaller than the actual results. This is because, under normal circumstances, manual annotation will enclose the entire character, while in the recognition results of the character height recognition method, the bounding box is close to the character. In this case, the recognition results of the character height recognition method are generally smaller, so the corresponding overall bias will be smaller, that is, the overall bias is actually less than 23.9%.
[0151] In addition, execution time tests were conducted on 2479 table images, and the results of the time tests are as follows: Figure 6 As shown, it took a total of 6 minutes and 36 seconds to recognize the character height of 2479 table images, averaging 6.25 images / second, which meets the time requirements of various business operations.
[0152] Based on the above embodiments, after determining the character height of the table image, the method further includes: determining the size adjustment parameters of the table image according to the character height and the preset character height, adjusting the size of the table image according to the size adjustment parameters, and performing table recognition processing on the size-adjusted table image to obtain each cell of the table image and the text in each cell.
[0153] Extensive experiments revealed that table images with a character height of approximately 40 pixels exhibit better table recognition performance. Therefore, in this embodiment, the preset character height is set to 40 pixels to improve the table recognition processing results. A size adjustment parameter is determined based on the recognized character height and the preset character height to adjust the size of the table image to match the preset character height. For example, if the recognized character height is 10 pixels, the size adjustment parameter is set to 4, and the table image is enlarged by a factor of 4 to ensure that the character height in the enlarged table image meets the preset character height. If the recognized character height is 50 pixels, the size adjustment parameter is set to 4 / 5, and the table image is reduced to 4 / 5 of its original size.
[0154] Since the character height recognition method shown above can improve the accuracy of character height recognition in table images, the table images are resized based on the recognized character height and the preset character height. This ensures that the character height in the resized table images is as close as possible to the preset character height of 40, thereby improving the processing results of table recognition.
[0155] After resizing the table image according to the resizing parameters, table recognition processing is performed on the resized table image to obtain each cell of the table image and the text information in each cell. For example, the resized table image can be input into an OCR recognition system for table recognition processing.
[0156] In one scenario, the steps described above for performing table recognition processing on a resized table image to obtain each cell of the table image and the text information within each cell include: performing text detection and recognition processing on the resized table image to obtain text information, wherein the text information includes text content and the coordinate values of the text content; performing table structure recognition processing on the resized table image to obtain each cell and the coordinate values of each cell; and aggregating the text content, the coordinate values of the text content, each cell, and the coordinate values of each cell to obtain each cell of the resized table image and the text information within each cell.
[0157] The above-mentioned text detection and recognition processing of the scaled table image to obtain text information can be performed in the following ways: For example, perform text detection processing on the resized table image to identify the text box containing the text and the coordinate values of the text box, such as using a text detection model for text detection processing; from the resized table image, crop the text box according to the identified text box and coordinate values to obtain the text image; perform text recognition processing on the text image to obtain the text content in the text image and the coordinate values of the text content, such as using a text recognition model for text recognition processing on the text image.
[0158] The above aggregation process, which combines the text content, the coordinates of the text content, each cell, and the coordinates of each cell, can be performed as follows: For example, to reconstruct the text table, aggregate the text content, the coordinates of the text content, each cell, and the coordinates of each cell. Then, aggregate the coordinates of each cell and the coordinates of the text boxes. Sort the text boxes according to their coordinates, from top to bottom and from left to right. Then, locate the cell containing the text content based on its coordinates. Finally, concatenate the text content within the cell to obtain the text information within the cell.
[0159] like Figure 7 The image shown is the result of table structure recognition without zooming in on the table image. Only a portion of the table structure, such as some cells, was recognized, indicating that many table structures were missed. Figure 8 The results of table structure recognition are obtained from a table image magnified 2 times. Most table structures were detected, but a small number were still missed. Figure 9 The table structure recognition results are obtained by magnifying the table image by 4 times. Basically, all table structures can be effectively recognized, meaning all cells can be identified. It can be seen that the more the table image is magnified, the closer the character height is to 40, the more accurate the table structure recognition results. Among them, drawing... Figure 7 , Figure 8 and Figure 9 The borders of the cells identified in the image have the same brush thickness.
[0160] Because the accuracy and efficiency of character height recognition are improved, when the table image is resized according to the size adjustment parameters, the character height in the resized table image is closer to 40, and the efficiency is higher. Therefore, table recognition processing is performed on the resized table image, which further improves the accuracy and efficiency of table recognition processing.
[0161] All of the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here.
[0162] To facilitate better implementation of the character height recognition method for table images according to the embodiments of this application, the embodiments of this application also provide a character height recognition device for table images. Please refer to... Figure 10 , Figure 10 This is a schematic diagram of the structure of a character height recognition device for a table image provided in an embodiment of this application. The character height recognition device 400 for the table image may include an acquisition module 401, a conversion module 402, an extraction and filtering module 403, an update module 404, and a height recognition module 405.
[0163] The acquisition module 401 is used to acquire a grayscale table image and obtain the set grayscale threshold.
[0164] The conversion module 402 is used to convert the table image into a black and white image according to the grayscale threshold.
[0165] The extraction and filtering module 403 is used to extract contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain the remaining bounding boxes.
[0166] The update module 404 is used to update the grayscale threshold according to the preset grayscale value if the number of remaining bounding boxes is less than the preset number of bounding boxes, so as to obtain the updated grayscale threshold, and then trigger the conversion module.
[0167] The height recognition module 405 is used to determine the character height of the table image based on the height of the remaining bounding boxes if the number of remaining bounding boxes is not less than the preset number of bounding boxes.
[0168] In one embodiment, the height recognition module 405 is specifically used to determine multiple adjacent height intervals based on the height of the remaining bounding box; and to determine the character height of the table image based on the height and the multiple adjacent height intervals.
[0169] Specifically, when performing the step of determining multiple adjacent height intervals based on the height of the remaining bounding boxes, the height recognition module 405 performs the following: for each non-repeating height of the multiple remaining bounding boxes, a first preset height is added to each height to obtain a larger height value, and a second preset height is subtracted from each height to obtain a smaller height value, wherein both the first preset height and the second preset height are greater than zero; the height interval formed by the smaller height value and the larger height value is taken as the adjacent height interval corresponding to each height to obtain multiple adjacent height intervals.
[0170] Specifically, when the height recognition module 405 performs the step of determining the character height of the table image based on the height and the multiple adjacent height intervals, it performs the following: for the multiple adjacent height intervals, the adjacent height interval in which the height of the remaining bounding box appears most frequently is taken as the target adjacent height interval, and the character height of the table image is determined based on the height corresponding to the target adjacent height interval.
[0171] In one embodiment, when performing the step of determining multiple adjacent height intervals based on the height of the remaining bounding box, the height recognition module 405 specifically performs the following: obtaining the height of the remaining bounding box to obtain a height list, and determining a number of candidate heights that appear most frequently from the height list; and determining multiple adjacent height intervals corresponding to the multiple candidate heights.
[0172] In one embodiment, the height recognition module 405 is specifically used to obtain the height of the remaining bounding box to obtain a height list, and to determine a number of candidate heights that appear most frequently from the height list; to determine a number of neighboring height intervals corresponding to the candidate heights; and to determine the character height of the table image based on the heights in the height list and the number of neighboring height intervals.
[0173] Specifically, when performing the step of determining the multiple neighboring height intervals corresponding to the multiple candidate heights, the height recognition module 405 performs the following: for each candidate height among the multiple candidate heights, a first preset height is added to each candidate height to obtain a larger height value, and a second preset height is subtracted from each candidate height to obtain a smaller height value, wherein both the first preset height and the second preset height are greater than zero; the height interval formed by the smaller height value and the larger height value is taken as the neighboring height interval corresponding to each candidate height, so as to obtain multiple neighboring height intervals.
[0174] Specifically, when the height recognition module 405 performs the step of determining the character height of the table image based on the height in the height list and the multiple adjacent height intervals, it performs the following: for the multiple adjacent height intervals, the adjacent height interval in the height list that appears most frequently is taken as the target adjacent height interval; the character height of the table image is determined based on the candidate height corresponding to the target adjacent height interval.
[0175] In one embodiment, such as Figure 10 As shown, the device 400 may further include a scaling module 406. The scaling module 406 is used to acquire the width and height of the table image, and determine the larger of the width and height; determine a scaling factor based on the larger value and a preset range; and scale the table image according to the scaling factor. Correspondingly, the height recognition module 405 is also used to determine the final character height of the table image based on the scaling factor and the determined character height.
[0176] In one embodiment, such as Figure 10 As shown, the device 400 may further include a detection module 407, which is used to detect whether the updated grayscale threshold exceeds the threshold range corresponding to the preset grayscale threshold. If yes, the conversion module 402 is triggered; if no, the height recognition module 405 is triggered so as to use the height recognition module 405 to determine the character height of the table image based on the default character height.
[0177] In one embodiment, such as Figure 10As shown, the device 400 may further include an adjustment module 408 and a table recognition module 409. The adjustment module 408 is used to determine the size adjustment parameters of the table image based on the character height and a preset character height, and to adjust the size of the table image according to the size adjustment parameters. Correspondingly, the table recognition module 409 is used to perform table recognition processing on the resized table image to obtain each cell of the table image and the text information in each cell.
[0178] All the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here. For example, in one embodiment, the device includes an acquisition module 401, a conversion module 402, an extraction and filtering module 403, and a height recognition module 405. Correspondingly, the acquisition module 401, conversion module 402, and extraction and filtering module 403 are described above. The height recognition module 405 is used to determine multiple adjacent height intervals based on the height of the remaining bounding box; and to determine the character height of the table image based on the height and the multiple adjacent height intervals. Further, the device also includes an update module 404.
[0179] Accordingly, embodiments of this application also provide a computer device, which can be a terminal or a server. For example... Figure 11 As shown, Figure 11 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device 500 includes a processor 501 with one or more processing cores, a memory 502 with one or more computer-readable storage media, and a computer program stored in the memory 502 and executable on the processor. The processor 501 is electrically connected to the memory 502.
[0180] The processor 501 is the control center of the computer device 500. It connects various parts of the computer device 500 through various interfaces and lines. By running or loading software programs (computer programs) and / or modules stored in the memory 502, and calling data stored in the memory 502, it performs various functions of the computer device 500 and processes data, thereby monitoring the computer device 500 as a whole.
[0181] In this embodiment, the processor 501 in the computer device 500 loads the instructions corresponding to the processes of one or more applications into the memory 502 according to the following steps, and the processor 501 runs the applications stored in the memory 502 to achieve various functions:
[0182] A grayscale table image is obtained, and a set grayscale threshold is obtained; the table image is converted into a black and white image according to the grayscale threshold; contour points are extracted from the black and white image, the contour points are converted into bounding boxes, and the bounding boxes are subjected to anomaly filtering to obtain remaining bounding boxes; if the number of remaining bounding boxes is less than the preset number of bounding boxes, the grayscale threshold is updated according to the preset grayscale value to obtain the updated grayscale threshold, and then the step of converting the table image into a black and white image according to the grayscale threshold is executed; if the number of remaining bounding boxes is not less than the preset number of bounding boxes, the character height of the table image is determined according to the height of the remaining bounding boxes.
[0183] And / or,
[0184] Obtain a grayscale table image and a set grayscale threshold; convert the table image to a black and white image based on the grayscale threshold; extract contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain remaining bounding boxes; determine multiple neighboring height intervals based on the height of the remaining bounding boxes; determine the character height of the table image based on the height and the multiple neighboring height intervals.
[0185] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0186] Optional, such as Figure 11 As shown, the computer device 500 also includes: a touch screen display 503, a radio frequency circuit 504, an audio circuit 505, an input unit 506, and a power supply 507. The processor 501 is electrically connected to the touch screen display 503, the radio frequency circuit 504, the audio circuit 505, the input unit 506, and the power supply 507. Those skilled in the art will understand that... Figure 11 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0187] The touch display screen 503 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 503 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the computer device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), an organic light-emitting diode (OLED), or other similar devices. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program. The touch panel may cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the data to the processor 501 to determine the type of touch event. Subsequently, the processor 501 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and display panel can be integrated into the touch display screen 503 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 503 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 503 can also be used as part of the input unit 506 to achieve input functions.
[0188] In this embodiment, the touch display screen 503 is used to present a graphical user interface and receive operation commands generated by the user interacting with the graphical user interface.
[0189] The radio frequency circuit 504 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other computer devices, and to transmit and receive signals with network devices or other computer devices.
[0190] Audio circuitry 505 can be used to provide an audio interface between a user and a computer device via a speaker and a microphone. Audio circuitry 505 converts received audio data into electrical signals, transmits them to the speaker, and the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuitry 505, converted back into audio data, and output to processor 501 for processing. The audio data is then transmitted via radio frequency circuitry 504 to, for example, another computer device, or output to memory 502 for further processing. Audio circuitry 505 may also include an earphone jack to facilitate communication between peripheral headphones and the computer device.
[0191] The input unit 506 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.
[0192] Power supply 507 is used to supply power to various components of computer device 500. Optionally, power supply 507 can be logically connected to processor 501 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 507 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0193] although Figure 11 As not shown in the diagram, the computer device 500 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.
[0194] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0195] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0196] Therefore, embodiments of this application provide a computer-readable storage medium storing multiple computer programs that can be loaded by a processor to execute the steps in any of the character height recognition methods for table images provided in embodiments of this application. For example, the computer program can execute the following steps:
[0197] A grayscale table image is obtained, and a set grayscale threshold is obtained; the table image is converted into a black and white image according to the grayscale threshold; contour points are extracted from the black and white image, the contour points are converted into bounding boxes, and the bounding boxes are subjected to anomaly filtering to obtain remaining bounding boxes; if the number of remaining bounding boxes is less than the preset number of bounding boxes, the grayscale threshold is updated according to the preset grayscale value to obtain the updated grayscale threshold, and then the step of converting the table image into a black and white image according to the grayscale threshold is executed; if the number of remaining bounding boxes is not less than the preset number of bounding boxes, the character height of the table image is determined according to the height of the remaining bounding boxes.
[0198] And / or,
[0199] Obtain a grayscale table image and a set grayscale threshold; convert the table image to a black and white image based on the grayscale threshold; extract contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain remaining bounding boxes; determine multiple neighboring height intervals based on the height of the remaining bounding boxes; determine the character height of the table image based on the height and the multiple neighboring height intervals.
[0200] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0201] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0202] Since the computer program stored in the storage medium can execute the steps in any of the character height recognition methods for table images provided in the embodiments of this application, the beneficial effects that any of the character height recognition methods for table images provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.
[0203] The foregoing has provided a detailed description of a method, apparatus, storage medium, and computer device for character height recognition of a table image provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and its core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for recognizing the character height of a table image, characterized in that, include: Obtain the grayscale image of the table and the set grayscale threshold; Convert the table image into a black and white image based on the grayscale threshold. Contour points are extracted from the black and white image, converted into bounding boxes, and anomaly filtering is performed on the bounding boxes to obtain remaining bounding boxes. The filtering conditions for the anomaly filtering include: the width of the bounding box is not greater than a first preset pixel, or the height of the bounding box is not greater than a second preset pixel, or the width of the bounding box is not less than the width of the table image at a first preset ratio, or the height of the bounding box is not less than the height of the table image at a second preset ratio. If the number of remaining bounding boxes is less than the preset number of bounding boxes, the grayscale threshold is updated according to the preset grayscale value to obtain the updated grayscale threshold, and then the step of converting the table image into a black and white image according to the grayscale threshold is performed. If the number of remaining bounding boxes is not less than the preset number of bounding boxes, the character height of the table image is determined based on the height of the remaining bounding boxes; The step of determining the character height of the table image based on the height of the remaining bounding box includes: obtaining the height of the remaining bounding box to obtain a height list, and determining a number of candidate heights that appear most frequently from the height list; determining a number of adjacent height intervals corresponding to the candidate heights; and determining the character height of the table image based on the heights in the height list and the number of adjacent height intervals. The step of determining the character height of the table image based on the height in the height list and the plurality of adjacent height intervals includes: for the plurality of adjacent height intervals, selecting the adjacent height interval in the height list that appears most frequently as the target adjacent height interval; and determining the character height of the table image based on the candidate heights corresponding to the target adjacent height interval. The method further includes, after determining the character height of the table image, determining the size adjustment parameters of the table image based on the character height and a preset character height, and adjusting the size of the table image according to the size adjustment parameters; and performing table recognition processing on the size-adjusted table image to obtain each cell of the table image and the text information in each cell.
2. The method according to claim 1, characterized in that, The step of determining the multiple neighboring height intervals corresponding to the multiple candidate heights includes: For each of the plurality of candidate heights, a first preset height is added to each candidate height to obtain a larger height value, and a second preset height is subtracted from each candidate height to obtain a smaller height value, wherein both the first preset height and the second preset height are greater than zero; The height interval formed by the smaller height value and the larger height value is used as the neighboring height interval corresponding to each candidate height, so as to obtain multiple neighboring height intervals.
3. The method according to claim 1, characterized in that, Before the step of converting the table image to a black and white image based on the grayscale threshold, the method further includes: Obtain the width and height of the table image, and determine the larger of the width and the height; The scaling factor is determined based on the larger value and the preset range; Scale the table image according to the scaling factor; After determining the character height of the table image, the method further includes: determining the final character height of the table image based on the scaling factor and the character height.
4. The method according to claim 1 or 3, characterized in that, After obtaining the updated grayscale threshold, the following is also included: Check whether the updated grayscale threshold exceeds the threshold range corresponding to the preset grayscale threshold; If not, then proceed to the step of converting the table image into a black and white image based on the grayscale threshold; If so, the character height of the table image is determined based on the default character height.
5. A method for recognizing character height in a table image, characterized in that, include: Obtain the grayscale image of the table and the set grayscale threshold; Convert the table image into a black and white image based on the grayscale threshold. Contour points are extracted from the black and white image, converted into bounding boxes, and anomaly filtering is performed on the bounding boxes to obtain remaining bounding boxes. The filtering conditions for the anomaly filtering include: the width of the bounding box is not greater than a first preset pixel, or the height of the bounding box is not greater than a second preset pixel, or the width of the bounding box is not less than the width of the table image at a first preset ratio, or the height of the bounding box is not less than the height of the table image at a second preset ratio. Multiple adjacent height ranges are determined based on the height of the remaining bounding box; The character height of the table image is determined based on the height and the plurality of adjacent height ranges; The step of determining multiple neighboring height intervals based on the height of the remaining bounding box includes: obtaining the height of the remaining bounding box to obtain a height list, and determining a number of candidate heights that appear most frequently from the height list; and determining multiple neighboring height intervals corresponding to the multiple candidate heights. The step of determining the character height of the table image based on the height and the plurality of adjacent height intervals includes: for the plurality of adjacent height intervals, selecting the adjacent height interval in the height list that appears most frequently as the target adjacent height interval; and determining the character height of the table image based on the candidate heights corresponding to the target adjacent height interval. The method further includes, after determining the character height of the table image, determining the size adjustment parameters of the table image based on the character height and a preset character height, and adjusting the size of the table image according to the size adjustment parameters; and performing table recognition processing on the size-adjusted table image to obtain each cell of the table image and the text information in each cell.
6. A device for recognizing the character height of a table image, characterized in that, include: The acquisition module is used to acquire a grayscale table image and obtain the set grayscale threshold. The conversion module is used to convert the table image into a black and white image based on the grayscale threshold. An extraction and filtering module is used to extract contour points from the black and white image, convert the contour points into bounding boxes, and perform anomaly filtering on the bounding boxes to obtain remaining bounding boxes. The anomaly filtering conditions include: the width of the bounding box is not greater than a first preset pixel, or the height of the bounding box is not greater than a second preset pixel, or the width of the bounding box is not less than the width of the table image at a first preset ratio, or the height of the bounding box is not less than the height of the table image at a second preset ratio. An update module is used to update the grayscale threshold according to a preset grayscale value if the number of remaining bounding boxes is less than the preset number of bounding boxes, so as to obtain the updated grayscale threshold, and then trigger the conversion module. A height recognition module is used to determine the character height of the table image based on the height of the remaining bounding boxes if the number of remaining bounding boxes is not less than the preset number of bounding boxes. The height recognition module is further configured to: obtain the height of the remaining bounding box to obtain a height list, and determine a number of candidate heights that appear most frequently from the height list; determine a number of adjacent height intervals corresponding to the candidate heights; and determine the character height of the table image based on the heights in the height list and the number of adjacent height intervals. The height recognition module is further configured to: for the plurality of adjacent height intervals, select the adjacent height interval in the height list that appears most frequently as the target adjacent height interval; and determine the character height of the table image based on the candidate heights corresponding to the target adjacent height interval. The device further includes an adjustment module and a table recognition module; the adjustment module is used to: determine the size adjustment parameters of the table image based on the character height and a preset character height, and adjust the size of the table image according to the size adjustment parameters; the table recognition module is used to: perform table recognition processing on the size-adjusted table image to obtain each cell of the table image and the text information in each cell.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program adapted for loading by a processor to perform the steps in the character height recognition method for a table image as described in any one of claims 1-5.
8. A computer device, characterized in that, The computer device includes a memory and a processor. The memory stores a computer program, and the processor executes the steps of the character height recognition method for table images as described in any one of claims 1-5 by calling the computer program stored in the memory.