An image processing method, device, storage medium and computer program product

CN122821565APending Publication Date: 2026-09-25IFLYTEK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611054081.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-15
Publication Date
2026-09-25

AI Technical Summary

Technical Problem

但是,这种校正方法至少会存在三点不足:一是该方法使用固定尺寸膨胀核确定的矩形结构元素来膨胀文字前景,容易造成跨行粘连,导致最终的倾斜角估计产生严重偏差;二是该方法在获得多个文本行候选区域的方向角后,通常采用简单算术平均或少数服从多数的投票机制来确定最终倾斜角,融合方式过于粗放,也可能会造成倾斜角的计算结果不够准确;三是该方法缺乏对非文本区域的有效过滤和闭环修正,也会影响倾斜角的计算结果

Benefits of technology

[0016]本申请实施例提供的一种图像处理方法、设备、存储介质及计算机程序产品,首先获取待处理的目标文本图像;并对目标文本图像进行预处理,得到二值化目标文本图像。然后提取与二值化目标文本图像的字符几何结构和文本行间距相关的目标文本结构参数,以利用该目标文本结构参数,生成目标文本图像对应的目标自适应膨胀核;并利用目标自适应膨胀核对目标文本图像的文本前景区域进行膨胀,得到N个文本行候选区域;其中,N为大于0的正整数。接着,计算N个文本行候选区域各自对应的方向角及区域置信度;并根据区域置信度,对所有方向角进行正余弦分量合成的加权融合处理,得到目标文本图像对应的倾斜角,以利用该倾斜角对目标文本图像进行旋转校正,得到校正后的目标文本图像。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122821565A_ABST
    Figure CN122821565A_ABST
Patent Text Reader

Abstract

The application discloses an image processing method, device, storage medium and computer program product. The method comprises the following steps: first, a dilated kernel which is adaptively matched with the text structure of a target text image is generated by using the target text structure parameters (such as character height, text line spacing and other related parameters) related to the character geometric structure and text line spacing of the target text image, so that the cross-line sticking is avoided from the root, and the quality of the text line candidate region is ensured while ensuring the effective connection of the same line characters. Then, the weighted fusion processing of the sine and cosine components of the direction angle is further combined with the confidence of each text line candidate region, the abnormal angle interference and the periodic crossing problem of the abnormal regions such as the seal and the table line are effectively eliminated, a more accurate inclination angle is obtained, and the rotation correction of the target text image is completed according to the inclination angle, so that the accuracy and the robustness of the inclination correction of the target text image can be significantly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to an image processing method, apparatus, storage medium, and computer program product. Background Technology

[0002] In numerous applications such as Optical Character Recognition (OCR), document digitization and archiving, intelligent financial reimbursement, and electronic medical record management, text images acquired through devices like mobile phone cameras, scanners, or industrial cameras often exhibit a degree of tilt. This tilt directly impacts subsequent layout analysis, text segmentation, and field extraction, significantly reducing OCR accuracy. Therefore, high-precision text image tilt correction has become an indispensable and crucial step in document image preprocessing.

[0003] Currently, the commonly used text image tilt correction method is based on connected component morphological dilation. This method first dilates the text region, connecting the strokes or character regions into text line blocks. Then, it calculates the tilt angle through fitting, edge detection, or Hough transform. Next, the image is rotated around its center in the opposite direction of the tilt angle to counteract the tilt effect, resulting in the corrected image. However, this correction method has at least three shortcomings: First, it uses a rectangular structuring element determined by a fixed-size dilation kernel to dilate the text foreground, which easily causes line-by-line adhesion, leading to a serious deviation in the final tilt angle estimation. Second, after obtaining the orientation angles of multiple candidate text line regions, this method typically uses a simple arithmetic mean or a majority voting mechanism to determine the final tilt angle. This coarse fusion method may also result in inaccurate tilt angle calculations. Third, this method lacks effective filtering and loop closure correction for non-text regions, which also affects the tilt angle calculation results. Therefore, improving the accuracy of text image tilt angle calculation to further enhance the text image tilt correction effect is an urgent problem to be solved. Summary of the Invention

[0004] In view of the above problems, this application provides an image processing method, device, storage medium, and computer program product that can generate an expansion kernel adaptively matched to the text structure of the image based on the text structure parameters of the image (such as character height, text line spacing, and other related parameters), so as to connect characters in the same line while avoiding cross-line adhesion at the source. Even if adhesion still occurs in local extreme cases, it can be effectively detected and closed-loop correction can be performed. In addition, it can also perform highly robust fusion of the orientation angles of multiple text line candidate regions to eliminate abnormal angle interference and correctly handle the problem of periodic angle crossing, thereby improving the accuracy of image tilt angle calculation and thus improving the tilt correction effect of text images. The specific solution is as follows: This application provides an image processing method, including: Obtain the target text image to be processed; and preprocess the target text image to obtain a binarized target text image; Extract the target text structure parameters related to the character geometry and line spacing of the binarized target text image; Using the target text structure parameters, a target adaptive dilation kernel corresponding to the target text image is generated; and the target adaptive dilation kernel is used to dilate the text foreground region of the target text image to obtain N text line candidate regions; where N is a positive integer greater than 0. Calculate the orientation angle and region confidence of each of the N candidate text line regions; and perform weighted fusion processing of sine and cosine components on the orientation angles based on the region confidence to obtain the tilt angle corresponding to the target text image. The target text image is rotated and corrected using the tilt angle to obtain the corrected target text image.

[0005] In one possible implementation, the extraction of target text structure parameters related to the character geometry and line spacing of the binarized target text image includes: The binarized target text image is subjected to 8-connected component labeling analysis to obtain an initial set of connected components; Calculate the geometric properties of each initial connected component in the initial connected component set; Using the geometric properties of each initial connected component, the median character height, median character width, estimated character spacing, and estimated line spacing of the binarized target text image are calculated as target text structure parameters related to the character geometry and line spacing of the binarized target text image.

[0006] In one possible implementation, generating the target adaptive dilation kernel corresponding to the target text image using the target text structure parameters includes: The median character width and the estimated character spacing are weighted and summed to generate the width of the target adaptive dilation kernel corresponding to the target text image; The constrained median character height is obtained by multiplying the median character height by a first constraint coefficient; and the constrained estimated text line spacing is obtained by multiplying the estimated text line spacing by a second constraint coefficient; both the first constraint coefficient and the second constraint coefficient are real numbers greater than 0 and less than 1. The smaller value between the constrained median character height and the constrained estimated text line spacing is selected as the height of the target adaptive dilation kernel corresponding to the target text image.

[0007] In one possible implementation, after dilating the text foreground region of the target text image using the target adaptive dilation kernel to obtain N text line candidate regions, the method further includes: Cross-line adhesion detection is performed on the N candidate text line regions; and anti-adhesion processing is performed on the detected adhesion regions to obtain M processed candidate text line regions; where M is a positive integer greater than 0; The processed M text line candidate regions are merged with the text line candidate regions in the N text line candidate regions that are not stuck together to form K text line candidate regions; where K is a positive integer greater than 0.

[0008] In one possible implementation, the cross-line adhesion detection of the N text line candidate regions includes: Detect whether there are any text line candidate regions among the N text line candidate regions whose region height exceeds the median of the character height; if so, project the center point of the initial connected region contained in the corresponding text line candidate region onto the vertical axis, and when it is determined that there are multiple peaks in the vertical projection, determine that the corresponding text line candidate region is a region where adhesion occurs.

[0009] In one possible implementation, the step of performing anti-adhesion processing on the detected sticky regions to obtain M processed text line candidate regions includes: The expansion kernels of the detected sticky regions are reduced in size, and the reduced expansion kernels are used to re-expand the sticky regions to obtain M candidate text line regions after processing. Alternatively, the projection valley segmentation method can be used. In the vertical projection curve corresponding to the region where adhesion occurs, the region where adhesion occurs is vertically segmented along the horizontal line corresponding to the lowest valley position between adjacent peaks, resulting in M ​​processed text line candidate regions.

[0010] In one possible implementation, after merging the processed M text line candidate regions with the non-adhesive text line candidate regions from the N text line candidate regions into K text line candidate regions, the method further includes: The K candidate text line regions are filtered for non-text regions to obtain T filtered candidate text line regions; where T is a positive integer greater than 0. The calculation of the orientation angle and region confidence of each of the N candidate text line regions includes: Calculate the orientation angle and region confidence of each of the T filtered candidate text lines.

[0011] In one possible implementation, the weighted fusion processing of the orientation angle based on the region confidence level, combining sine and cosine components to obtain the tilt angle corresponding to the target text image, includes: Clustering is performed on all directional angles to obtain P angle clusters; and the total weight corresponding to each of the P angle clusters is calculated based on the region confidence; where P is a positive integer greater than 0. Select the angle cluster with the highest total weight from the P angle clusters as the main angle cluster; Using each orientation angle and region confidence in the principal angle cluster, weighted sine and cosine components are calculated; and based on the calculation results, the tilt angle corresponding to the target text image is determined.

[0012] In one possible implementation, after performing a weighted fusion process of sine and cosine component synthesis on the orientation angle based on the region confidence to obtain the tilt angle corresponding to the target text image, the method further includes: The confidence level of the tilt angle is quantitatively evaluated to generate a confidence level for the tilt angle; and based on the confidence level, a tilt correction strategy for the target text image is determined.

[0013] This application also provides an image processing device, including: a processor, a memory, and a system bus; The processor and the memory are connected via the system bus; The memory is used to store one or more programs, the one or more programs including instructions, which, when executed by the processor, cause the processor to perform any of the above-described image processing methods.

[0014] This application also provides a computer-readable storage medium storing instructions that, when executed on a terminal device, cause the terminal device to perform any of the above-described image processing methods.

[0015] This application also provides a computer program product, which, when run on a terminal device, causes the terminal device to execute any of the above-described image processing methods.

[0016] This application provides an image processing method, device, storage medium, and computer program product. First, a target text image to be processed is acquired. The target text image is then preprocessed to obtain a binarized target text image. Next, target text structure parameters related to the character geometry and line spacing of the binarized target text image are extracted. These target text structure parameters are used to generate a target adaptive dilation kernel corresponding to the target text image. The target adaptive dilation kernel is then used to dilate the text foreground region of the target text image, resulting in N candidate text line regions, where N is a positive integer greater than 0. Then, the orientation angle and region confidence score corresponding to each of the N candidate text line regions are calculated. Based on the region confidence score, a weighted fusion process of sine and cosine component synthesis is performed on all orientation angles to obtain the tilt angle corresponding to the target text image. This tilt angle is then used to perform rotation correction on the target text image, resulting in a corrected target text image.

[0017] As can be seen, when performing tilt correction on the target text image, this application first generates an expansion kernel that adaptively matches the text structure by extracting target text structure parameters related to the character geometry and line spacing from the image itself. This ensures effective connection of characters in the same line while preventing cross-line adhesion at the source, thus guaranteeing the quality of text line candidate regions. Furthermore, it combines the confidence scores of each text line candidate region with weighted fusion processing of sine and cosine components to synthesize the direction angle. This effectively eliminates abnormal angle interference and periodic crossing problems in abnormal areas such as seals and table lines, obtaining a more accurate tilt angle. Based on this, rotation correction of the target text image is completed, thereby effectively improving the accuracy and robustness of tilt correction for the target text image. Attached Figure Description

[0018] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 A schematic flowchart of an image processing method provided in an embodiment of this application; Figure 2 Example diagram of the target text image provided in the embodiments of this application; Figure 3 A comparison example of the target text image and the binarized target text image provided in the embodiments of this application; Figure 4 Example diagram of the initial connected domain provided in the embodiments of this application; Figure 5 Example diagram of target text structure parameters provided in embodiments of this application; Figure 6 Example diagrams of the target adaptive expansion kernel width and height provided in embodiments of this application; Figure 7 The width and height of the target adaptive expansion kernel provided in the embodiments of this application are compared with the median character height. Median character width Character spacing estimate Estimated line spacing of text Example diagram of the relationship between them; Figure 8 Example diagram of text line candidate regions provided in embodiments of this application; Figure 9 This is a schematic diagram of cross-row adhesion detection and anti-adhesion treatment provided in an embodiment of this application; Figure 10 A schematic diagram comparing normal text line candidate regions with text line candidate regions that overlap across lines, provided for embodiments of this application; Figure 11 Example diagram of the area where adhesion occurs, provided in an embodiment of this application; Figure 12 Example diagrams of non-text region filtering provided in embodiments of this application; Figure 13 Example diagram of the orientation angle provided in the embodiments of this application; Figure 14 Example diagram of the orientation angle clustering and weighted fusion processing results provided in the embodiments of this application; Figure 15 A schematic diagram comparing an uncorrected target text image and a corrected target text image provided in an embodiment of this application; Figure 16 A visual bar chart illustrating the tilt angle confidence sub-indices provided in this application embodiment; Figure 17 This is a schematic diagram of the structure of an image processing device provided in an embodiment of this application. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, 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, 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.

[0020] Currently, in numerous application scenarios such as OCR, document digitization and archiving, intelligent financial reimbursement, and electronic medical record management, text images acquired by people through devices such as mobile phone cameras, scanners, or industrial cameras often exhibit a certain degree of tilt. This tilt can be caused by factors such as shooting angle deviations, improper paper placement, or skewed paper feeding in scanning machinery. Consequently, the demand for text image tilt correction is increasing, and the scenarios are becoming increasingly complex. For example, in applications such as express delivery slip photo recognition, intelligent VAT invoice entry, electronic contract archiving, and ID document information extraction, the text images to be processed often come from diverse sources and vary in quality. In addition to the main text, the images may contain various interfering elements such as stamps, QR codes, barcodes, table borders, background patterns, and stains. The direction of these interfering elements is often inconsistent with the main text lines, easily misleading the estimation of the tilt angle.

[0021] To achieve tilt correction of text images, the traditional methods used to estimate the tilt angle of the text image typically include the following two: (1) An estimation method for detecting straight lines based on Hough transform.

[0022] This method typically involves first binarizing or edge detection of the image, then using Hough transform to detect straight lines in the image, and finally estimating the tilt angle of the text image based on the direction of the dominant straight line. However, this method has the drawback of heavily relying on the presence of obvious long straight lines (such as table lines or text baselines) in the image. For plain text documents without significant line segments, it is difficult to stably measure angles due to the lack of effective voting points, and it is also sensitive to parameter thresholds, easily misjudging decorative borders or scan noise as the dominant direction, leading to inaccurate angle estimation.

[0023] (2) Estimation method based on projection profile.

[0024] This method typically projects the image from multiple candidate angles and determines the angle at which the text line is closest to the horizontal based on the changes in the peaks and valleys of the horizontal projection, the projection variance, or the energy value. However, the drawbacks of this method are that it requires repeated reprojection from multiple candidate angles, resulting in high computational cost, poor real-time performance, and its statistical features are extremely sensitive to the text density distribution. When faced with large areas of white space, multi-column layouts, or binarization breaks, the peaks and valleys of the projection histogram will become blurred and distorted, leading to misjudgment of the global tilt angle.

[0025] As can be seen, the main drawback of the two traditional estimation methods mentioned above is their high sensitivity to text density, image quality, and document type, which can lead to deviations in angle estimation. Therefore, to overcome these shortcomings, the commonly used text image tilt correction method is based on connected component morphological dilation. This method first dilates the text region, connecting the strokes or character regions into text line blocks. Then, it calculates the tilt angle using fitting, edge detection, or Hough transform. Next, it rotates the image around its center in the opposite direction of the tilt angle to counteract the tilt effect, resulting in the corrected image. This fundamentally avoids dependence on continuous long lines or global pixel distribution density, making it particularly suitable for plain text, low-quality scans, and handwritten text scenarios. However, this estimation method has at least three shortcomings: ① Using a rectangular structural element determined by a fixed-size expansion kernel to expand the text foreground can easily cause line overlap, resulting in a serious deviation in the final tilt angle estimation.

[0026] The dilation kernel (structuring element) is a small-sized shape template used in morphological dilation operations, which can be understood as a window sliding on the image. The size of the dilation kernel refers to the width × height (pixels) of the template; for example, 18 × 12 pixels is a rectangular template that is 18 pixels wide and 12 pixels high. The function of the dilation kernel is to connect scattered characters within the same line of text into a coherent strip-like region, so that the image tilt angle can be determined by analyzing the direction of the strip.

[0027] However, the character size, character spacing, and line spacing of different document images often vary significantly. If a rectangular structuring element determined by a fixed-size dilation kernel is used to dilate the text foreground, when the height of the fixed dilation kernel is large, or the line spacing of the original image is small, the morphological dilation operation will stick two or even multiple adjacent lines of text vertically into a single connected region. Once cross-line sticking occurs, the orientation angle calculated for this sticking region is no longer the true direction of any single line of text, but a false direction generated by the mixing of multiple lines of text, leading to a serious deviation in the final tilt angle estimation. Even more problematic is that the parameters of the fixed dilation kernel (examples are shown in Table 1 below) usually need to be manually adjusted repeatedly for images from different sources, lacking universality and adaptability.

[0028] Table 1

[0029] For example, when inputting an image of an invoice with small font and dense line spacing, a 5-pixel high dilation kernel may be sufficient to connect strokes across lines; however, when inputting an image of a document with large font, a 5-pixel high dilation kernel may not be sufficient to connect vertically distributed strokes within the same line. This is the fundamental reason why existing methods using fixed-size dilation kernels lack versatility and adaptability.

[0030] ② The multi-line angle fusion method is too crude.

[0031] Specifically, existing methods based on connected component morphological dilation typically use a simple arithmetic mean or a majority voting mechanism to determine the final tilt angle after obtaining the orientation angles of multiple candidate text line regions. This overly coarse fusion method has two problems: First, it does not consider the difference in confidence between different candidate text line regions. For example, long text lines with more characters should obviously contribute more weight than short text lines or regions containing only a few fragmented characters. Second, it cannot correctly handle the periodic crossing of angles around ±90°. For example, -89° and +89° are geometrically only 2° apart, but after arithmetic averaging, we get (-89°+89°) / 2=0° / 2=0°, which will produce obvious errors and make the tilt angle calculation result inaccurate.

[0032] ③ Lack of effective filtering and closed-loop correction for non-text areas.

[0033] Specifically, in existing methods based on connected component morphological dilation, non-text regions such as stamps, QR codes, and table lines may form connected regions after dilation. Their orientation angles are independent of the text lines, but they are directly fed into angle fusion, contaminating the final result. Furthermore, existing methods lack detection and correction mechanisms for existing cross-line adhesion, which also affects the calculation of the tilt angle.

[0034] To address the aforementioned shortcomings, this application provides an image processing method. First, a target text image to be processed is acquired. The target text image is then preprocessed to obtain a binarized target text image. Next, target text structure parameters related to the character geometry and line spacing of the binarized target text image are extracted. These target text structure parameters are then used to generate a target adaptive dilation kernel corresponding to the target text image. The target adaptive dilation kernel is then used to dilate the text foreground region of the target text image, resulting in N candidate text line regions, where N is a positive integer greater than 0. Then, the orientation angle and region confidence score corresponding to each of the N candidate text line regions are calculated. Based on the region confidence score, a weighted fusion process of sine and cosine component synthesis is performed on all orientation angles to obtain the tilt angle corresponding to the target text image. This tilt angle is then used to perform rotation correction on the target text image, resulting in a corrected target text image.

[0035] As can be seen, when performing tilt correction on the target text image, this application first generates an expansion kernel that adaptively matches the text structure by extracting target text structure parameters related to the character geometry and line spacing from the image itself. This ensures effective connection of characters within the same line while preventing cross-line adhesion at the source, thus guaranteeing the quality of text line candidate regions. Furthermore, it combines the confidence scores of each text line candidate region with a weighted fusion process of sine and cosine component synthesis of the direction angle. This effectively eliminates abnormal angle interference and periodic crossing problems in abnormal regions such as seals and table lines, obtaining a more accurate tilt angle and using this to complete the rotation correction of the target text image. This effectively improves the accuracy and robustness of tilt correction for target text images.

[0036] See Figure 1 This is a flowchart illustrating an image processing method provided in this embodiment. The method includes the following steps: S101: Obtain the target text image to be processed; and preprocess the target text image to obtain a binarized target text image.

[0037] In this embodiment, any image containing text content that undergoes image tilt correction using the processing method provided in this application is defined as the target text image to be processed. Furthermore, this embodiment does not limit the type of the target text image; for example, the target text image can be a color image composed of the three primary colors red (R), green (G), and blue (B), or it can be a grayscale image. Also, this embodiment does not limit the resolution of the target text image; for example, the target text image can have a resolution of 720. 480 RGB image, or a high-resolution 1920 image. 1280 RGB images, etc. Furthermore, this application does not limit the source of the target text image or the text content it contains; the source can include, but is not limited to, mobile phone cameras, flatbed scanners, images uploaded to OCR systems, industrial cameras, or video frames. The text content can be invoices, certificates, contracts, forms, express delivery slips, medical records, archives, exam papers, or other ordinary documents.

[0038] For example: the target text image can be like... Figure 2 The invoice image shown is an example. It should be noted that, for the purpose of protecting sensitive information and complying with patent application specifications, this application [does not include]... Figure 2 The actual information in the buyer, seller, and remarks columns has been obscured or blurred. It should be understood that in practical applications, the above information is complete and specific real data. Similarly, similar sensitive information in the subsequent figures of this application will also be blurred in the same way, and is only used as an example and does not constitute an actual limitation on the technical solution of this application.

[0039] In practical applications, after obtaining the target text image to be processed, existing or future image preprocessing methods can be used to preprocess the target text image. For example, the target text image can be gradually processed by grayscale conversion, Gaussian denoising, binarization, etc., until a binarized target text image is obtained, which is then used to perform the subsequent step S102.

[0040] Specifically, if the target text image is a color image, it needs to be converted to grayscale first (this step can be omitted if the target text image is already grayscale). Then, a Gaussian filter is used for noise reduction, with a kernel size of 5×5 pixels (for example only). Next, to address potential uneven lighting, adaptive histogram equalization can be used for brightness equalization, or large-scale morphological closing operations can be used to estimate the background image. The difference between the original image and the background image is then calculated to complete background correction. Finally, a local adaptive thresholding method (such as the Sauvola algorithm) can be used for binarization to obtain a binary target text image with a foreground region of 1 (white) and a background region of 0 (black).

[0041] For example: taking the target text image as an example... Figure 2 The invoice image shown (also) Figure 3 Taking the left-hand image as an example, since it is a color RGB image, it first needs to be converted to a single-channel grayscale image. Then, Gaussian filtering (for example, a 5×5 kernel with σ=1.0) is used to eliminate shooting noise. Next, the Otsu algorithm can be combined for global binarization and adaptive Gaussian binarization to obtain a binary image. Then, morphological opening operations are used to remove small noise points, resulting in the final binary target text image, such as... Figure 3 As shown in the diagram on the right.

[0042] The Otsu algorithm can be understood as a classic and practical tool in image processing, especially suitable for images with high contrast between the target and the background. Combining it with adaptive Gaussian binarization can effectively address the shortcomings of the Otsu algorithm alone in complex situations with uneven lighting, achieving complementary advantages.

[0043] S102: Extract target text structure parameters related to the character geometry and line spacing of the binarized target text image.

[0044] In this embodiment, after obtaining the binarized target text image through step S101, further, text structure parameters related to the character geometry and text line spacing (here defined as target text structure parameters, such as character height, text line spacing, etc.) can be extracted from the binarized target text image itself to execute the subsequent step S103, generating an expansion kernel that adaptively matches the text structure of the binarized target text image. This allows the kernel to connect characters in the same line while avoiding cross-line adhesion at the source. In this way, compared with the existing method of using a fixed-size expansion kernel (a determined rectangular structural element) to expand the text foreground, the quality of the text line candidate region can be effectively improved.

[0045] Specifically, one possible implementation is that, after obtaining the binarized target text image, firstly, 8-connected component labeling analysis can be performed on the binarized target text image to obtain an initial set of connected components. Then, the geometric properties of each initial connected component in this initial set can be calculated (including but not limited to area A, bounding rectangle width W, bounding rectangle height H, and center point coordinates). Aspect Ratio Foreground pixel density wait).

[0046] In this implementation, the process of performing 8-connected component labeling analysis on the binarized target text image can include: scanning the binarized target text image line by line, and checking whether there are already labeled pixels in the eight neighborhood directions (up, down, left, right, and four diagonal directions: top left, top right, bottom left, and bottom right) for each white foreground pixel. If there are, assign the same label; otherwise, assign a new label. Adjacent labels are finally merged through an equivalence table to obtain the initial set of connected components.

[0047] Each initial connected component in the initial connected component set may contain, but is not limited to: label number, pixel set (coordinates of all foreground pixels that make up the connected component), and geometric properties (area A, bounding rectangle width W, height H, center point coordinates, aspect ratio r, foreground pixel density ρ).

[0048] Furthermore, to improve the quality of the initial connected components, non-character regions can be initially filtered out based on the geometric properties of each initial connected component. The specific filtering rules are as follows: (1) Isolated noise with too small an area: , The default value is 15 pixels (this is just an example; it can also be 20 pixels, etc.).

[0049] (2) Non-text blocks with excessive area: The area is greater than 5% of the total area of ​​the image (this is just an example, it can also be 3%, etc.).

[0050] (3) Extremely thin table lines or border lines: r>15 and extremely small height (for example only, height H<3 pixels).

[0051] (4) Vertical thin lines: and extremely small width (for example only, width W< 3 pixels).

[0052] In this way, the filtered initial connected component set can be expressed as , wherein each initial connected component has a height , a width , an area and center point coordinates .

[0053] Next, taking the Figure 3 binarized target text image shown on the right as an example, the calculation process of the geometric attributes of each initial connected component in the initial connected component set is described as follows: After performing 8-connected component labeling analysis on the Figure 3 binarized target text image shown on the right to obtain an initial connected component (shown by Figure 4 the green rectangular box in Figure 4 ) set, taking the initial connected component corresponding to a Chinese character (e.g., "房") as an example, assuming that the pixel coordinate range of the character is x∈[503, 520], y∈[150, 168], the calculation process of each geometric attribute is as follows: (1) Area A: Count the total number of all foreground pixels in the initial connected component. By traversing all pixels of the initial connected component and accumulating the number of white foreground pixels, we can obtain A = 156 pixels.

[0054] (2) Bounding rectangle width W: the maximum x-coordinate of all pixels of the initial connected component minus the minimum x-coordinate plus 1, that is W=x max -x min +1= 520-503+1=18 pixels. The reason for adding 1 can be understood as: pixel coordinates are discrete integer values. From x=503 to x=520, the actual number of pixel columns included is: 503, 504, 505, ..., 520, totaling 18 columns, instead of 520-503=17 columns.

[0055] (3) Bounding rectangle height H: the maximum y-coordinate of all pixels of the initial connected component minus the minimum y-coordinate plus 1, that is H=y max -y min +1=168-150+1=19 pixels. The reason for adding 1 can be understood as: pixel coordinates are discrete integer values. From y=150 to y=168, it actually includes 19 rows of pixels.

[0056] (4) Coordinates of the center point :x c = (x max +x min y / 2 = (520 + 503) / 2 = 511.5. c =(y max + y min ) / 2=(168+150) / 2=159.

[0057] (5) Aspect ratio r: r=W / H=18 / 19≈0.947.

[0058] (6) Foreground pixel density ρ: ρ=A / (W×H)=156 / (18×19)=156 / 342≈0.456, which means that 45.6% of the pixels within the bounding rectangle are foreground (character strokes), and the rest are background.

[0059] Next, the median character height of the binarized target text image can be calculated using the geometric properties of each initial connected component (area A, bounding rectangle width W, height H, center point coordinates, aspect ratio r, foreground pixel density ρ). ), median character width (represented as ), character spacing estimate (represented as ), estimated text line spacing (represented as The median is used as a target text structure parameter related to the character geometry and line spacing of the binarized target text image. The median is used to reduce the influence of abnormal characters, noise, and non-text regions. The main reason for using existing techniques such as the median non-mean is that large headings, small punctuation marks, or individual noisy connected components do not significantly affect the statistical results, thus enhancing the robustness of the overall scheme.

[0060] Among them, the median character height The calculation formula is: ,express The value of is the median of the heights of the bounding rectangles of all initial connected components. This indicates a median-based operation, which is robust against outlier interference.

[0061] Median character width The calculation formula is: ,express The value of is the median of the width of the bounding rectangle of all initial connected regions.

[0062] In calculating the estimated character spacing At that time, for each initial connected component , searching can be performed horizontally for other initial connected components with the closest distance to the x-coordinate of their center point (i.e., the horizontal nearest neighbor), and the horizontal spacing between the edges of the bounding rectangles of the two is calculated (that is the x-coordinate of the left edge minus the x-coordinate of the right edge, or take the positive value otherwise). Then the median of the spacing between all initial connected components and their horizontal nearest neighbors is taken as , and the specific calculation formula is: , which represents calculating the typical horizontal spacing between adjacent characters in the current target text image, serving as a basis for subsequently generating the width of the target adaptive dilation kernel.

[0063] For example: taking Figure 4 the initial connected components of two adjacent Chinese characters (such as "房" and "费") as an example, the initial connected component (such as "房") has a bounding rectangle with the x-coordinate of the left edge being 503 and the x-coordinate of the right edge being 520, and the x-coordinate of the center point c is 511.5. Search for another initial connected component that is closest to the x-coordinate of the center point the center point's x-coordinate (such as the character "费" on the right) has a left edge x-coordinate of 528 and a center point x-coordinate c of 536. On this basis, the edge spacing can be calculated as: = left edge of minus right edge of = 528 - 520 = 8 pixels. By analogy, repeating the foregoing steps for all initial connected components can obtain all values, and then the median is extracted from them to obtain: .

[0064] It should be noted that if there are fewer text columns in the target text image, calculation can be performed in a local sliding window to enhance stability. For example, when the target text image has only 2-3 columns of text, global calculation of nearest neighbors may misjudge characters from different columns as nearest neighbors. At this time, a horizontal sliding window can be set (an example of the window width can be 1 / 4 of the image width), and only search for the nearest neighbor connected component and calculate the spacing within the window to avoid cross-column interference. For example, Figure 5 adopts a strategy of limiting the search range in actual calculation: only searching for the nearest neighbor within the range where the vertical distance < 1.5× and the horizontal spacing > 2 pixels, and the median is taken to obtain .

[0065] When calculating the estimated text line spacing , the y-coordinates of the center points of all initial connected components can be first extracted as a one-dimensional data sequence {y1, y2, ..., y nThen, perform histogram statistics on the data sequence (bin count = image height ÷ ( ( / 2) = 733 ÷ 6.5 ≈ 112), and detect all local maxima (peaks) in the histogram. The difference in the y-coordinate of adjacent peaks is the line spacing between the corresponding two lines of text. Then, take the median of the distances between all adjacent peaks as... .

[0066] Specifically, the detected peak y-coordinates can be represented from top to bottom as y1, y2, ..., y n (where n is the total number of peak values), then The specific calculation formula can be: Gy=median({y2-y1, y3-y2, ..., y n -y n-1}),express The value is taken as the median of the y-coordinate differences between all adjacent peaks. For example, as... Figure 5 The green arrow in the middle indicates The position (vertical distance between two lines of text), The values ​​were obtained by performing histogram peak detection on the y-coordinates of the center points of 454 initial connected components: each peak corresponds to the y-position of a line of text, and the difference in y-coordinates between adjacent peaks is the line spacing at that point. Finally, the median of all line spacings was taken. =22 pixels. Assuming the histogram shows 5 peaks at y=65, 87, 109, 131, 153, then the distances between adjacent peaks are: 87-65=22, 109-87=22, 131-109=22, 153-131=22, and the median is... =22 pixels. This value indicates that the typical vertical spacing between the centers of two adjacent lines of text in this document is 22 pixels.

[0067] It should be noted that if only one line of text is detected (i.e., a single line of text), then it can be set to... This is the default value, meaning that when only one text line is detected from the target text image (i.e., the histogram has only one peak, and the distance between adjacent peaks cannot be calculated), the line spacing cannot be estimated using the above method. In this case, a reasonable default value is needed. The reason for choosing 4 as the coefficient is that in common Chinese typesetting, the line spacing is usually 1.5 to 2 times the character height (i.e., "1.5 times line spacing" or "2 times line spacing"). Adding the height of the character itself, the vertical distance between the center points of adjacent lines is approximately 2.5 to 4 times the character height. Taking the upper bound of 4 as a conservative estimate, i.e. =4×13=52 pixels. Furthermore, choosing a larger value (4 times instead of 2.5 times) is also to ensure the accuracy of the expansion kernel height determined in subsequent steps (expressed as...). The height of the expanded nucleus will not be too large: because the subsequent steps will expand the core height ( The formula for calculating ) is ,like An underestimation will lead to Too small (unable to effectively connect characters in the same row), and The estimate is too large, which only makes δ× This item does not become a bottleneck (ultimately) by (Constraints) will not cause negative impacts. Therefore, taking a conservative, slightly larger value of 4 times is safer.

[0068] S103: Using the target text structure parameters, generate the target adaptive dilation kernel corresponding to the target text image; and use the target adaptive dilation kernel to dilate the text foreground region of the target text image to obtain N text line candidate regions; where N is a positive integer greater than 0.

[0069] In this embodiment, step S102 obtains target text structure parameters (such as median character height) related to the character geometry and line spacing of the binarized target text image. Median character width Character spacing estimate Estimated line spacing of text After that, we can further utilize these target text structure parameters to dynamically generate an expansion kernel that adaptively matches the target text image (here it is defined as the target adaptive expansion kernel). Then, using the target adaptive expansion kernel as a morphological structural element, we can expand the text foreground region of the target text image to obtain N (the specific value is not limited and can be any positive integer greater than 0) text line candidate regions to improve the quality of the text line candidate regions, which are then used to execute the subsequent step S104.

[0070] Specifically, one possible implementation is to obtain the median character height. Median character width Character spacing estimate Estimated line spacing of text First, we can determine the median character width. Character spacing estimate Perform a weighted summation calculation to generate the width of the target adaptive dilation kernel corresponding to the target text image (represented as...). The specific calculation formula is as follows:

[0071] in, This represents the spacing magnification factor, with typical examples ranging from 1.5 to 2.0, used to ensure that the width of the expansion kernel is sufficient to connect adjacent characters in the same line; This represents the width compensation factor, with typical values ​​ranging from 0.1 to 0.3. This indicates that the calculation result will be limited to a preset minimum value. and maximum value To prevent extreme situations, this application addresses the minimum value. and maximum value The value of is not limited and can be set according to actual conditions and experience. For example, the minimum value can be set. The value is set to 5 pixels to prevent the expansion kernel from being too narrow to connect characters, and to set the maximum value... The value is set to 80 pixels to prevent the expansion kernel from being too wide, which could lead to incorrect concatenation of different words or fields. For example, in... Figure 6 In China, regarding The calculation process can be summarized as follows: =clamp(11.2, 5, 80)=11 pixels, so after the constraint of clamp(5, 80), the final result can be obtained. The value of .

[0072] Then, the median of the character height can be used. Multiply by the first constraint coefficient (expressed as) (The value can be a real number greater than 0 and less than 1), to obtain the constrained median character height; and, using the estimated text line spacing... Multiply by the second constraint coefficient (expressed as) The value can be a real number greater than 0 and less than 1, to obtain the constrained text line spacing estimate. Then, the smaller value between the constrained median character height and the constrained text line spacing estimate is selected as the height of the target adaptive dilation kernel corresponding to the target text image. The specific calculation formula is as follows:

[0073] in, δ represents the first constraint coefficient (which can also be understood as the height proportional coefficient), used to maintain the vertical continuity of the character strokes themselves. A typical example value range is [0.6, 0.9], with a preferred value of 0.7. δ represents the second constraint coefficient (which can also be understood as the line spacing constraint coefficient), used to prevent excessively large expansion kernel heights from causing line overlap. A typical example value range is [0.3, 0.6], with a preferred value of 0.5. The key feature is... This means the upper limit determined by the estimated line spacing of the text. It is strictly smaller than the estimated text line spacing. Thus, the height of the expanding core is forced to increase. Take the smaller of the constrained median character height and the constrained estimated line spacing (which can be understood as the smaller of "character height multiplied by height ratio factor" and "estimated line spacing multiplied by line spacing constraint factor"). For example... Figure 7 The width of the target adaptive expansion kernel is shown in the figure. and height , with the median character height Median character width Character spacing estimate Estimated line spacing of text Example diagram of the relationship between them, thus, from Figure 7 It can be seen intuitively from the image that the height of the expansion core is... Strictly limited to values ​​much smaller than the estimated text line spacing. Within the range, the expansion process will not extend to adjacent text lines.

[0074] For example: Suppose the median character height of the target text image (such as a ticket image) is obtained statistically. Pixels, estimated text line spacing Pixels, and If δ takes values ​​of 0.7 and 0.5 respectively, then the calculation yields: Pixels Pixels In terms of pixels, the height of the dilation kernel is 12.6 pixels, which is strictly less than half of the line spacing of 30 pixels (15 pixels). When performing morphological dilation, the vertical expansion is strictly limited to within half of the line spacing to ensure that cross-line adhesion does not occur.

[0075] It should be noted that if the above steps reveal a highly discrete distribution of character heights (e.g., a document containing both large headings and small footnotes), the connected components can be divided into two groups based on height quantiles. The target text structure parameters can then be calculated separately, generating two adaptive dilation kernels. After dilating the binarized target text image separately, the candidate text line regions are merged before proceeding with subsequent steps. This multi-scale dilation kernel strategy ensures that text of different sizes is correctly processed even in complex layouts with vastly different font sizes.

[0076] For example: Based on the above examples, for such as Figure 2 The invoice image shown contains various font sizes. For example, the top title "Tianjin Value-Added Tax Electronic General Invoice" is in large font (character height approximately 25px), the body text such as "Room Booking Fee" is in medium font (character height approximately 13px), and the fonts such as "Buyer" and "Name" are in small font (character height approximately 9px).

[0077] The implementation process of using a multi-scale dilation kernel strategy is as follows: After statistically analyzing the height distribution of all 454 connected components through the above steps, it was found that the height standard deviation was relatively large (covering a range of 9~25px). At this point, the height median was used. With a boundary of 13 pixels, all initial connected components are divided into the following two groups: Large font group (H>13px): includes large fonts such as titles. ≈25px Small text group (H≤13px): includes body text and tags. ≈11px For large byte groups: calculate G y 1 (large character line spacing), resulting in =clamp(1.8× +0.2× , 5, 80), =min(0.7×25, 0.5× ).

[0078] For small groups: calculate G y 2 (small line spacing), resulting in =clamp(1.8× +0.2× , 5, 80), =min(0.7×11, 0.5× ) .

[0079] The binarized text image is then dilated using two dilation kernels respectively, and the two sets of results are merged to obtain the final text line candidate region.

[0080] Furthermore, in generating the target text image corresponding to the target adaptive dilation kernel ( Afterwards, it can be used as a morphological structural element to perform dilation operations on the target text image. This dilation operation can connect characters, stroke fragments, or text segments within the same text line into continuous strip-shaped connected regions. After further labeling the connected components of the dilated image, the resulting connected regions are the candidate regions for the text line.

[0081] For example: Based on the above examples, for such as Figure 2 The invoice image shown is used as the target text image. The specific dilation operation process can be as follows: [The text then describes the process of performing a dilation operation on the invoice image shown.] A rectangular kernel of 11×9 pixels is slid across the binarized target text image. For each pixel position in the binarized target text image, if there is at least one white foreground pixel within the kernel's coverage area, then that position is set to white in the output binarized target text image. The intuitive effect is that each white character region expands horizontally by approximately 5 pixels (half the kernel width) and vertically by approximately 4 pixels (half the kernel height), thus obtaining... Figure 8 The text line candidate area shown in the green box reveals that the originally scattered individual characters (see also...) Figure 4 After expansion, they form strip-shaped white areas, and each green box (which can be labeled R1, R2, R3... a total of 43) corresponds to a text line candidate area.

[0082] It should be noted that in the above example, for example, Figure 2 For target text images with a small tilt angle (approximately 3°), standard [methods] can be used. Expanding a rectangular kernel of 11×9 pixels can effectively connect characters in the same row. For target text images with a large tilt angle (e.g., greater than 5°), directional dilation can be used to more accurately match the text direction. The specific process is as follows: First, preset the angle range [-8°, +8°], with a step size of 1°, generating a total of 17 rotation angles. Then, for each angle θk, ... A rectangular kernel is rotated by θk degrees to generate an orientation kernel. Then, the binary image is dilated using these 17 orientation kernels to obtain 17 groups of candidate text line regions. Next, the angular variance σ² is calculated for each group: groups with good directional consistency have smaller variances. Finally, the result corresponding to θk with the smallest variance is selected as the final candidate text line region.

[0083] Furthermore, it should be noted that although using the target adaptive dilation kernel to dilate the text foreground region of the target text image to obtain N text line candidate regions can significantly reduce the probability of cross-line adhesion, a small amount of residual adhesion may still occur in extreme local areas where text lines are extremely dense or character heights differ greatly. To address this, one possible approach is to first perform cross-line adhesion detection on the N text line candidate regions; and then perform anti-adhesion processing on the detected adhesion regions to obtain M (the specific value is not limited and can be any positive integer greater than 0) processed text line candidate regions; then, the M processed text line candidate regions can be merged with the non-adhesive text line candidate regions from the N text line candidate regions to form K (the specific value is not limited and can be any positive integer greater than 0) text line candidate regions for subsequent step S104.

[0084] Specifically, in this implementation, firstly, it can be detected whether there are any text line candidate regions whose height exceeds the median character height among these N text line candidate regions. That is, for each text line candidate region (represented as...), ), determine its region height (represented as Whether the height exceeds the median of the character height is determined by the following formula:

[0085] Where λ represents the adhesion determination factor, and its empirical value ranges from 2.0 to 3.0, with a typical example value of 2.5. If the area height... Significantly greater than the median character height If so, it can be preliminarily determined to be suspected adhesion.

[0086] In other words, if a candidate text line has a height exceeding the median character height, it can be preliminarily identified as a suspected line overlap. Furthermore, since the center point y-coordinates of non-overlapping regions are concentrated near the same horizontal line, forming a single peak after projection, this indicates no cross-line overlap. Conversely, for overlapping regions, the center point y-coordinates are distributed near two different y-values, forming a double peak after projection, thus indicating cross-line overlap. Therefore, for a candidate text line initially identified as a suspected line overlap, the center point of its initial connected component can be further projected onto the vertical axis (y-axis). If multiple peaks are detected in the vertical projection, the corresponding candidate text line is confirmed as an area of ​​line overlap.

[0087] In practical applications, by projecting the center points of the initial connected components within the candidate region of the text line onto the vertical axis (y-axis), a projection histogram (represented as...) can be obtained. After that, the projected histogram can be smoothed and peak detection can be performed. If the number of peaks satisfies the formula " ", and there exists an interval between adjacent peaks that satisfies the formula " (where μ represents the line spacing threshold coefficient, which can range from 0.6 to 0.8), which indicates that there are vertically separated multi-line character centers in the candidate area of ​​the text line, thus determining that the candidate area of ​​the text line is the area where cross-line adhesion occurs.

[0088] Where μ represents the line spacing threshold coefficient ranging from 0.6 to 0.8, the formula " The meaning of "" can be understood as follows: if the y-direction distance between two adjacent peaks in the vertical projection histogram is greater than 60% to 80% of the line spacing, then these two peaks are considered to represent two different lines of text (rather than vertical fluctuations within the same line). For example, see Figure 5 As shown =22 pixels, taking μ=0.7 as an example, the threshold = 0.7 × 22 = 15.4 pixels. If a region's projection has two peaks and the peak spacing is greater than this threshold, then cross-line adhesion is confirmed. For example... Figure 10 As shown, it illustrates a comparison between the candidate regions of normal text lines (i.e., the left-side single-peak projection) and the candidate regions of text lines with cross-line adhesion (i.e., the right-side double-peak projection).

[0089] Furthermore, it should be noted that each text line candidate region regional height Specifically, it refers to the candidate area of ​​the corresponding text line. The height of the bounding rectangle (i.e., the height of the connected region obtained after dilation using the target adaptive dilation kernel) is the maximum value minus the minimum value of the y-coordinates of all pixels in that region, plus 1. For example, suppose a candidate region of a text line... If the pixel y-range is [150, 175], then the height of the corresponding region is... =175-150+1=26 pixels. The center point of the initial connected region within the candidate text line region can be understood as a larger connected region formed after expansion. (like Figure 11 The red box area covers the initial connected components spatially (such as...). Figure 4 The center point of the character marked in the green box.

[0090] Then, for the detected areas of adhesion, existing or future anti-adhesion processing methods need to be used for anti-adhesion processing. Specifically, one possible implementation is to shrink the expansion kernel of the detected areas of adhesion and then use the shrunken expansion kernel to re-expand the areas of adhesion to obtain M text line candidate areas after processing.

[0091] Among these, the height of the expansion core can be reduced to Then, it uses only the local binary map corresponding to the adhesion region to perform dilation operation again to separate the inter-row connections.

[0092] For example, such as Figure 9 Taking the candidate region of the right-side contiguous text lines (bimodal) as an example, we can first determine the corresponding local region in the binary image (by clipping with an outer rectangle), then clear the connected pixels generated by the original dilation in this local region, restoring the original local region of the binary image. Then, we calculate the height of the reduced dilation kernel as follows: = 0.4 × 13 = 5 pixels (original kernel height) =9 pixels), while maintaining the kernel width The kernel height remains unchanged at 11 pixels, but a new 11×5 rectangular kernel is used to re-perform the dilation operation on this local binary image region. Because the kernel height is significantly reduced (from 9 to 5 pixels), the two lines of text are no longer vertically connected and are separated into two independent strip-shaped regions. These two separated sub-regions then replace the original connected region, serving as the two processed candidate text line regions (where M is now set to 2). Figure 9 The lower half shows the candidate text line area obtained after the anti-adhesion processing, which successfully separates the previously adhered area into two independent regions, Ra and Rb.

[0093] Alternatively, the projection valley segmentation method can be used. In the vertical projection curve corresponding to the region where adhesion occurs, the region where adhesion occurs is vertically segmented along the horizontal line corresponding to the lowest valley position between adjacent peaks to obtain M sub-regions, which are used as the M candidate regions for the processed text lines.

[0094] "Vertical segmentation" can be understood as first performing projection analysis along the vertical direction, and then performing horizontal segmentation at the horizontal position corresponding to the projection valley value to separate the upper and lower rows.

[0095] For example: still using Figure 9 Taking the candidate region of the right-side contiguous text lines (bimodal) as an example, the contiguous region... Projecting the center points of all initially connected components onto the y-axis yields a projected histogram, as shown below. Figure 9 As shown in the projection curve of the "adhesive text line candidate region (bimodal)," two peaks were detected. Then, the valley with the lowest projection value was found between the two peaks, and the lowest value was determined along the horizontal line corresponding to the valley (e.g., ...). Figure 9 The area is divided into two sub-regions by the blue line: sub-region Ra represents the pixels and characters above the blue line; sub-region Rb represents the pixels and characters below the blue line. These two sub-regions are used as independent candidate text line regions for subsequent processing.

[0096] Based on this, after merging the M text line candidate regions obtained through anti-adhesion processing with the non-adhesive text line candidate regions from the N text line candidate regions into K (the specific value is not limited and can be any positive integer greater than 0) text line candidate regions, in order to further improve the quality of the text line candidate regions, an optional implementation is to further filter these K text line candidate regions for non-text regions, obtaining T (the specific value is not limited and can be any positive integer greater than 0) filtered text line candidate regions, which are then used to execute the subsequent step S104. The conditions for performing non-text region filtering can be set according to the actual situation and empirical values, and may include, but are not limited to, the following five items: (1) Area condition: The area of ​​the region is less than Fragmented regions. Regions smaller than one character in size are considered fragments and need to be filtered out.

[0097] (2) Aspect Ratio Condition: Aspect Ratio And the height is the median of the character height. Significantly different long table line areas, such as those with a height < 0.5× This indicates that areas with an aspect ratio greater than 12 and a height less than half the character height are considered table lines and need to be filtered out. Alternatively, aspect ratio... The thin vertical lines need to be filtered out.

[0098] (3) Character density condition: the number of initial connected components contained within the region. And the length of the region exceeds The text indicates a long line but lacks sufficient character support, and needs to be filtered out.

[0099] (4) Texture periodicity condition: For QR codes, the entropy value of the local binary pattern (LBP) histogram is calculated. If the entropy value is extremely high (e.g., entropy value > 4.5) and the histogram shows obvious periodicity (e.g., autocorrelation peak value > 0.6 and peak spacing is uniform), it can be determined as a non-text area and filtered out.

[0100] (5) Seal feature conditions: If the color is significantly different from normal text (e.g., red detection based on HSV color space), it is determined to be a seal area and filtered out.

[0101] In this way, by performing multi-dimensional feature filtering on the K candidate text line regions, regions that meet any of the above conditions are identified as non-text regions and filtered out, resulting in T higher-quality candidate text line regions. For example, Figure 12 The areas marked with red boxes are the non-text areas that need to be filtered (marked with X), while the green boxes are the valid text line candidate areas that are retained (with typical text line characteristics).

[0102] S104: Calculate the orientation angle and region confidence of each of the N candidate text line regions; and perform weighted fusion processing of sine and cosine components on the orientation angles based on the region confidence to obtain the tilt angle corresponding to the target text image.

[0103] In this embodiment, after dilating the text foreground region of the target text image using the target adaptive dilation kernel in step S103 to obtain N text line candidate regions (or T text line candidate regions obtained after anti-adhesion processing and non-text region filtering; the subsequent explanation of the processing steps will use N text line candidate regions, but if there are T text line candidate regions, the implementation can be the same), further, the orientation angles corresponding to each of these N text line candidate regions can be calculated (which can be expressed as...). The system first obtains the region confidence score and then performs a weighted fusion process on the direction angle by combining sine and cosine components based on the region confidence score. This effectively eliminates abnormal angle interference and periodic crossing problems in abnormal regions such as seals and table lines, and obtains a more accurate tilt angle corresponding to the target text image, which is then used to execute the subsequent step S105.

[0104] Specifically, one possible implementation is to first extract the set of coordinates of the foreground points for each of the N candidate text line regions. The specific extraction formula is as follows: Then, Principal Component Analysis (PCA) is used to calculate the orientation angle of this region. The specific implementation process is as follows: First, calculate the point set. The covariance matrix is ​​calculated using the following formula:

[0105] in, Let represent a 2×2 covariance matrix, describing the distribution of all foreground coordinates within the candidate region of the corresponding text line; P represents the set of foreground coordinates {(x1,y1), (x2,y2), ..., (x...} within the candidate region of the corresponding text line. m ,y m )}; var(y) represents the variance of the x-coordinates of all foreground points, reflecting the degree of dispersion of the point set in the horizontal direction; var(y) represents the variance of the y-coordinates of all foreground points, reflecting the degree of dispersion of the point set in the vertical direction. This represents the covariance of the x and y coordinates, reflecting the correlation (i.e., the degree of slant) in the horizontal and vertical directions. Understandably, when the text line is horizontal... Much larger than var(y), Close to 0; when the text line is slanted, Not zero, its magnitude and sign reflect the direction and degree of slant. For example Figure 13 The green rotating rectangle in the middle is the visualization result of the PCA main direction.

[0106] Then, calculate the covariance matrix. The eigenvector corresponding to the largest eigenvalue The specific calculation process includes: first, solving the eigenvalue equation Σv = λv for the covariance matrix Σ, obtaining two eigenvalues ​​λ1 and λ2 (satisfying λ1 ≥ λ2) and their corresponding eigenvectors v1 and v2. Among them, the eigenvector v corresponding to the largest eigenvalue λ1 is... max =(v x , v y The direction of the maximum variance in the data distribution is indicated, which is the main direction (major axis direction) of the candidate region for that text line. Subsequently, the direction angle θ is calculated using the arctangent function. i = arctan2(v y , v x Since text lines, as line segments, do not have directionality (i.e., there is no "head" and "tail", i.e., θ),... i With θ i ±180° represents the same direction), +91° and -89° actually describe the direction of the same straight line. Therefore, the angles need to be normalized to the half-cycle range of [-90°, 90°) to eliminate the ambiguity of 180° and ensure the consistency of the direction angle data. The specific normalization method can be: if θ i If ≥90°, then subtract 180°; if θ i If the angle is less than -90°, add 180°. This process ensures that the same line of text corresponds to the same angle representation under different feature vector directions, thus avoiding errors in subsequent angle fusion processes caused by the same direction being represented as two angles differing by 180°. For example, as... Figure 13 The angle values ​​marked next to each text line area are calculated through the PCA process described above (the direction angles of the effective area in the figure are concentrated around 2.95°). The direction of the long side of the green rotating rectangle is the feature vector v. max The direction.

[0107] Based on this, the orientation angle (θ) of the candidate region of the text line can be obtained. i The calculation formula for ) is as follows:

[0108] Simultaneously, in order to provide a weighting basis for subsequent direction angle weighted fusion, the regional confidence of each text line candidate region can also be calculated (represented as...). One alternative implementation is regional confidence (). ) can be based on the length of the text line (represented as ), the number of candidate characters in the region (represented as The specific calculation formula is as follows: (This is obtained by linear weighting of factors such as aspect ratio and other factors.)

[0109] in, and These represent the maximum length and maximum number of characters in all regions, respectively. Indicates the aspect ratio of the candidate region for the corresponding text line; This represents the median value of the ideal text line length-to-width ratio range. The specific value is not limited and can be determined based on actual conditions and experience. For example, it can be the median value of 6 between 4 and 8. These represent weighting coefficients, and their specific values ​​are not limited. They can be determined based on actual circumstances and experience. The default value is 1 / 3 (for example only).

[0110] Furthermore, based on the calculated regional confidence scores of each candidate region in the text line ( ), for all direction angles (represented as A weighted fusion process involving sine and cosine components is performed to eliminate angular periodicity errors, resulting in a more accurate tilt angle corresponding to the target text image. One possible implementation is to perform weighted fusion processing on all orientation angles (…). The weighted fusion process for synthesizing sine and cosine components can be specifically described as follows: First, for all direction angles ( Clustering is performed to remove isolated outlier angles (such as outlier angles caused by missed filtering areas like seals or QR codes), resulting in P (the specific value is not limited and can be any positive integer greater than 0) angle clusters. Then, based on the regional confidence of each text line candidate region (…),… ), calculate the total weight corresponding to each of these P angle clusters. Then, select the angle cluster with the highest total weight from these P angle clusters as the principal angle cluster, and use the confidence scores of each direction angle and region in the principal angle cluster ( The weighted sine and cosine components are calculated to determine the tilt angle corresponding to the target text image based on the calculation results.

[0111] Specifically, in this implementation, the clustering algorithm and implementation process used in the clustering process are not limited. For example, a density-based clustering algorithm (such as the Density-Based Spatial Clustering of Applications with Noise (DBSCAN) algorithm) can be used, with the angle difference threshold set to... to After clustering, each of the P angular clusters represents a candidate text line's dominant direction.

[0112] The clustering process (gap-based clustering based on angular intervals) can be as follows: First, sort the directional angles corresponding to all candidate regions of the text lines in ascending order of their numerical values. Then, calculate the difference between two adjacent directional angles one by one. If the difference between adjacent angles is less than 2°, the two groups of directional angles are assigned to the same directional cluster. If the difference between adjacent angles is greater than or equal to 2°, a new directional cluster is created. Each directional cluster synchronously records all directional angles within the cluster, the corresponding text line region number, the total region weight (obtained by multiplying the text line length, the number of candidate characters within the region, and the region confidence score), the mean of the angles within the cluster, and the directional variance. After clustering is completed, the cluster with the largest total region weight is selected as the principal directional cluster (denoted as Θmain).

[0113] As shown in Figure 14, the blue dots marking the Cluster (MAIN) represent the directional angles contained in the main angle cluster, concentrated around 2.97° (or 2.95°); the red, gray, and purple crosses (×) marking the outliers represent the remaining low-weight outlier directional angles; the green dashed lines in the figure represent the tilt angle (e.g., Θ=2.97° or 2.95°) corresponding to the target text image output after weighted fusion calculation. Additionally, from... Figure 14 The vertical axis weight values ​​also show that the weight values ​​(vertical axis) of each point in the main cluster (blue dots) are significantly higher than those of the outliers. The total weight of the main cluster is much greater than that of other clusters, so it is selected as the main angle cluster (Θmain). This ensures that outliers in large areas such as stamps and table lines do not dominate the final tilt angle calculation result.

[0114] Next, assume there are M orientation angles within the principal angle cluster. and corresponding weights ,but The specific calculation formula can be:

[0115] in, Indicates the length of a text line (in pixels); This indicates the number of candidate characters within the candidate area of ​​the corresponding text line; This indicates the regional confidence level of the candidate region corresponding to the text line.

[0116] Based on this, the formula for calculating the weighted sine and cosine components using each orientation angle and region confidence level in the principal angle cluster can be specifically as follows:

[0117]

[0118] Furthermore, using the calculation results obtained from the above formula, the tilt angle corresponding to the target text image is determined. The formula is as follows:

[0119] In this way, by using the double-angle transformation method described above, angles that differ by 180° can be mapped to the same position, perfectly solving the problem of periodic leaps in direction angles. For example, -89° and +89° correspond to -178° and +178° respectively in double-angle space, and their sine and cosine synthesis results can correctly reflect the fact that the two actually differ by only 2°.

[0120] For example: Figure 14 Taking the orientation angles within the principal angle cluster as an example, the weighted fusion process for synthesizing sine and cosine components can be as follows: Assume the principal angle cluster contains N text line orientation angles θ1, θ2, ..., θ n The weights corresponding to each direction angle are w1, w2, ..., w n ; respectively use the above formulas to calculate the weighted sine and cosine components (i.e. and ), calculate the weighted cosine cumulative value and the weighted sine cumulative value within the cluster, and then solve for the tilt angle corresponding to the target text image based on the two sets of cumulative values. The calculation formula is as follows: ,like Figure 14 The green dashed line marks (or 2.95°) is the final tilt angle.

[0121] Compared to the simple arithmetic average or majority voting mechanism used in existing technologies, the weighted fusion method of sine and cosine component synthesis adopted in this application has a significant advantage when the angle crosses the ±90° critical range. For example, if the orientation angles of the three text line regions within the main angle cluster are {89°, -89°, -88°}, all three are actually close to the vertical 90° direction. If the arithmetic average is used, the resulting angle is (89 + (-89) + (-88)) / 3 = -29.3°, which deviates greatly from the actual tilt direction and contains a serious calculation error; while the weighted fusion method of sine and cosine component synthesis, through a double angle (i.e., 2... The transformation can eliminate the defect of periodic discontinuity of angle, and the final tilt angle is obtained. The calculated value is approximately -89.3°, which closely matches the actual tilt of the text line, thus effectively avoiding recognition errors caused by angle jumps.

[0122] S105: Rotate and correct the target text image using the tilt angle to obtain the corrected target text image.

[0123] In this embodiment, after obtaining the tilt angle corresponding to the target text image in step S104, the tilt angle can be used to perform reverse rotation correction on the target text image to obtain the corrected target text image. The specific correction process can be as follows: an affine transformation matrix is ​​constructed with the center point of the target text image as the rotation center, causing the image to rotate in the opposite direction around this center by the tilt angle to eliminate text tilt; furthermore, during the rotation process, bicubic interpolation can be used to calculate new pixel values ​​to maximize the sharpness and clarity of the text edges; simultaneously, the boundary size of the corrected image can be calculated based on the rotation angle, and the translation parameters of the affine transformation matrix can be adjusted to ensure that the corrected image is displayed completely without cropping, and the blank boundary areas generated by the rotation are filled with a white background. Experiments show that after correction, all text lines in the target text image are restored to a horizontal state, the text baseline is parallel to the horizontal edge of the image, and the residual angle error is less than 0.1 degrees. The obtained corrected target text image can be directly input into downstream OCR recognition modules, layout analysis modules, field extraction modules, or document archiving systems to further improve the accuracy and robustness of subsequent text recognition and processing.

[0124] For example: Figure 15 As shown, the left image is the uncorrected target text image, in which all text lines are tilted clockwise by approximately 2.95°; the right image is the target text image after the aforementioned rotation correction, in which all text lines have been basically restored to a horizontal state, and the text baseline is parallel to the horizontal boundary of the image.

[0125] Furthermore, to further improve the reliability of the tilt angle calculation results and the subsequent tilt correction effect on the target text image, an optional implementation method is to quantify and evaluate the confidence level of the tilt angle obtained in step S104, generating a confidence level (denoted as Conf); and based on this confidence level, a more accurate tilt correction strategy for the target text image can be determined. The specific formula for calculating the confidence level (Conf) of the tilt angle is as follows:

[0126] in, The normalized score representing the number of valid candidate regions in a text line can be calculated using the following formula: = min(Neffective / Nexpected, 1.0), where Neffective represents the number of effective text line candidate regions retained after filtering (which can be understood as the value of T mentioned in step S103 above), and Nexpected represents the expected threshold for the number of text lines (the specific value is not limited and can be set according to the actual situation and experience, such as setting it to 12, etc.). When the number of effective regions reaches or exceeds this value, the filtering can be stopped. The value is 1.0. And a, b, c, d all represent weight coefficients. Their specific values are not limited and can be set according to actual conditions and empirical values, but they need to satisfy a+b+c+d=1. Exemplary values can be a=0.25, b=0.25, c=0.25, d=0.25 (equal weight, default value), or can be adjusted adaptively according to application scenarios. For example, if more attention is paid to the sufficiency of the number of text lines, it can be adjusted to a=0.3, b=0.25, c=0.25, d=0.2; or if more attention is paid to angle consistency, it can be adjusted to a=0.2, b=0.2, c=0.4, d=0.2; represents the ratio of the number of regions in the main angle cluster to the total number of effective regions; represents the normalized value of the angle variance within the main angle cluster; represents the proportion of the image area covered by the effective text line regions.

[0127] In addition, two confidence thresholds can also be preset according to actual conditions and empirical values: a high confidence threshold T_high (e.g., 0.8) and a low confidence threshold T_low (e.g., 0.4). In this way, if Conf ≥ T_high is satisfied, the rotation correction strategy in the above step S105 can be directly executed; or if T_low ≤ Conf < T_high is satisfied, secondary verification can be performed (such as comparing the OCR recognition rate of the corrected target text image, etc.); or if Conf < T_low is satisfied, other correction strategies such as Hough transform and projection method can be switched to improve the correction effect, and the user can also be prompted to re-shoot the target text image.

[0128] Specifically, after performing rotation correction on the target text image using the tilt angle, an OCR recognition engine can be called on the corrected target text image to obtain the recognition result of the corrected target text image and its corresponding recognition confidence score Score_corrected; meanwhile, the same OCR recognition process is performed on the uncorrected target text image to obtain its recognition confidence score Score_original. Then the two are compared: if Score_corrected > Score_original, it indicates that the tilt correction is effective, and the corrected image can be used as the final result; if Score_corrected ≤ Score_original, it indicates that the correction here fails to improve the recognition effect and even produces a negative impact. At this time, the correction result can be discarded and the original uncorrected target text image can be output, or switch to other correction strategies (such as Hough transform, projection method, etc.) for reprocessing. It can be seen that this verification mechanism is equivalent to adding a layer of safety guarantee to the entire correction process, and is especially suitable for medium confidence levels (e.g., Figure 16Conf=0.754 as shown, which is close to the 0.8 threshold), the risk of OCR recognition rate degradation caused by correction errors can be effectively avoided. For situations with high confidence (e.g., Conf≥0.8), no secondary verification is required, and the correction result can be directly output to ensure processing efficiency.

[0129] For ease of understanding, the following Figure 16 takes the visualized bar chart of the sub-indicators of tilt angle confidence (confidence calculated with equal weights (0.25, 0.25, 0.25, 0.25)) as shown as an example, and introduces three scenarios divided according to the interval where Conf is located (that is, the relationship between Conf and the high confidence threshold Thigh (e.g., 0.8) and the low confidence threshold Tlow (e.g., 0.4)) as follows: The first scenario: high confidence (Conf≥Thigh). At this time, the number of effective text line regions is sufficient, so that the normalized value is high; most direction angles are classified into the main angle cluster, which is close to 1.0; the variance of direction angles within the main angle cluster is small, and the angle consistency is high, that is, 1-Var is close to 1.0; and the effective region covers a large area of the image, the value is high. These comprehensive conditions make the value of Conf reach above 0.8. For such high-confidence situations, it can be directly determined that the tilt angle calculated through the aforementioned step S104 is accurate and reliable, and no secondary verification is required, and the rotation correction operation in the aforementioned step S105 can be directly performed.

[0130] The second scenario: medium confidence (Tlow≤Conf <Thigh). This situation corresponds to Figure 16 the sample data shown. In this example, after normalization processing of all effective text lines, the obtained = 1.0 (full score); the ratio of the total number of direction angles contained in the main angle cluster to the total number of direction angles is = 0.902; the angle variance of the main angle cluster is small, and 1-Var is close to 1.0; but the coverage area ratio is low, that is, the proportion of the text region relative to the entire image area is relatively limited. After weighted fusion of the above dimensions, Conf = 0.754 is obtained, which is between Figure 16 the red dashed line Tlow = 0.4 and the green dashed line Thigh = 0.8 in the figure. For such medium-confidence scenarios, a secondary verification strategy can be adopted: first perform rotation correction according to the tilt angle calculated through the aforementioned step S104, then verify the actual effectiveness of the correction by comparing whether the OCR recognition rate is improved before and after correction, so as to decide whether to accept the correction result.

[0131] Third scenario: low confidence (Conf<Tlow). When the image is blurred, there is very little text, or the layout is severely abnormal, the scores of all dimensions are at extremely low levels, resulting in Conf being lower than 0.4 and lower than Figure 16 the red dashed line Tlow. At this time, the inclination angle calculated through the above step S104 can be abandoned, and other备用 correction strategies such as the Hough transform line detection method are automatically switched to for correction, so as to improve the correction effect.

[0132] In this way, through the above-mentioned multi-dimensional confidence evaluation and hierarchical processing mechanism, the reliability of the inclination calculation result can be quantitatively evaluated without relying on additional labeled data or external verification, and direct correction, secondary verification or switching to other more appropriate备用 correction strategies can be adaptively selected accordingly, so that while ensuring high-precision correction effects, the robustness and fault tolerance of the overall correction scheme are also taken into account.

[0133] Further, an embodiment of the present application further provides an image processing apparatus, comprising: a processor, a memory, and a system bus; the processor and the memory are connected via the system bus; the memory is configured to store one or more programs, where the one or more programs comprise instructions, and when the instructions are executed by the processor, the processor is caused to execute any implementation of the above image processing method.

[0134] With reference to Figure 17 , it shows a structural schematic diagram suitable for implementing the image processing apparatus in the embodiment of the present application. The image processing apparatus in the embodiment of the present application may include, but is not limited to, terminals, cloud platforms, servers, server clusters, etc. Figure 17 the image processing apparatus shown is only an example of an electronic device, and should not impose any limitation on the function and scope of use of the embodiments of the present application.

[0135] As shown in Figure 17 , the image processing apparatus may comprise a processor (e.g., central processing unit, graphics processing unit, etc.) 1701, which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 1702 or programs loaded into a random access memory (RAM) 1703 from a storage device 1708. When the image processing apparatus is powered on, various programs and data required for device operation are also stored in RAM 1703. The processor 1701, ROM 1702, and RAM 1703 are connected to each other via a bus 1704. An input / output (I / O) interface 1705 is also connected to the bus 1704.

[0136] Typically, the following devices can be connected to I / O interface 1705: input devices 1706 including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 1707 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1708 including, for example, memory card, hard disk, etc.; and communication devices 1709. Communication device 1709 allows the electronic device to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 17 An image processing apparatus with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0137] Furthermore, embodiments of this application also provide a computer-readable storage medium storing instructions that, when executed on a terminal device, cause the terminal device to perform any of the above-described implementations of the image processing method.

[0138] Furthermore, this application embodiment also provides a computer program product, which, when run on a terminal device, causes the terminal device to execute any of the above-described image processing methods.

[0139] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that all or part of the steps in the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network communication device such as a media gateway, etc.) to execute the methods described in various embodiments or some parts of the embodiments of this application.

[0140] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0141] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0142] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. An image processing method, characterized in that, include: Obtain the target text image to be processed; The target text image is then preprocessed to obtain a binarized target text image; Extract the target text structure parameters related to the character geometry and line spacing of the binarized target text image; Using the target text structure parameters, a target adaptive dilation kernel corresponding to the target text image is generated; and the target adaptive dilation kernel is used to dilate the text foreground region of the target text image to obtain N text line candidate regions; where N is a positive integer greater than 0. Calculate the orientation angle and region confidence of each of the N candidate text line regions; and perform weighted fusion processing of sine and cosine components on the orientation angles based on the region confidence to obtain the tilt angle corresponding to the target text image. The target text image is rotated and corrected using the tilt angle to obtain the corrected target text image.

2. The method according to claim 1, characterized in that, The extraction of target text structure parameters related to the character geometry and line spacing of the binarized target text image includes: The binarized target text image is subjected to 8-connected component labeling analysis to obtain an initial set of connected components; Calculate the geometric properties of each initial connected component in the initial connected component set; Using the geometric properties of each initial connected component, the median character height, median character width, estimated character spacing, and estimated line spacing of the binarized target text image are calculated as target text structure parameters related to the character geometry and line spacing of the binarized target text image.

3. The method according to claim 2, characterized in that, The step of generating the target adaptive dilation kernel corresponding to the target text image using the target text structure parameters includes: The median character width and the estimated character spacing are weighted and summed to generate the width of the target adaptive dilation kernel corresponding to the target text image; The constrained median character height is obtained by multiplying the median character height by a first constraint coefficient; and the constrained estimated text line spacing is obtained by multiplying the estimated text line spacing by a second constraint coefficient; both the first constraint coefficient and the second constraint coefficient are real numbers greater than 0 and less than 1. The smaller value between the constrained median character height and the constrained estimated text line spacing is selected as the height of the target adaptive dilation kernel corresponding to the target text image.

4. The method according to claim 1, characterized in that, After dilating the text foreground region of the target text image using the target adaptive dilation kernel to obtain N text line candidate regions, the method further includes: Cross-line adhesion detection is performed on the N candidate text line regions; and anti-adhesion processing is performed on the detected adhesion regions to obtain M processed candidate text line regions; where M is a positive integer greater than 0; The processed M text line candidate regions are merged with the text line candidate regions in the N text line candidate regions that are not stuck together to form K text line candidate regions; where K is a positive integer greater than 0.

5. The method according to claim 4, characterized in that, The step of detecting cross-line adhesion in the N candidate text line regions includes: Detect whether there are any text line candidate regions among the N text line candidate regions whose region height exceeds the median of the character height; if so, project the center point of the initial connected region contained in the corresponding text line candidate region onto the vertical axis, and when it is determined that there are multiple peaks in the vertical projection, determine that the corresponding text line candidate region is a region where adhesion occurs.

6. The method according to claim 5, characterized in that, The detected areas of adhesion are subjected to anti-adhesion processing to obtain M processed text line candidate regions, including: The expansion kernels of the detected sticky regions are reduced in size, and the reduced expansion kernels are used to re-expand the sticky regions to obtain M candidate text line regions after processing. Alternatively, the projection valley segmentation method can be used. In the vertical projection curve corresponding to the region where adhesion occurs, the region where adhesion occurs is vertically segmented along the horizontal line corresponding to the lowest valley position between adjacent peaks, resulting in M ​​processed text line candidate regions.

7. The method according to claim 4, characterized in that, After merging the processed M text line candidate regions with the non-adhesive text line candidate regions from the N text line candidate regions into K text line candidate regions, the method further includes: The K candidate text line regions are filtered for non-text regions to obtain T filtered candidate text line regions; where T is a positive integer greater than 0. The calculation of the orientation angle and region confidence of each of the N candidate text line regions includes: Calculate the orientation angle and region confidence of each of the T filtered candidate text lines.

8. The method according to claim 1, characterized in that, The step of performing a weighted fusion process based on the region confidence level to synthesize the sine and cosine components of the orientation angle to obtain the tilt angle corresponding to the target text image includes: Clustering is performed on all directional angles to obtain P angle clusters; and the total weight corresponding to each of the P angle clusters is calculated based on the region confidence; where P is a positive integer greater than 0. Select the angle cluster with the highest total weight from the P angle clusters as the main angle cluster; Using each orientation angle and region confidence in the principal angle cluster, weighted sine and cosine components are calculated; and based on the calculation results, the tilt angle corresponding to the target text image is determined.

9. The method according to any one of claims 1-8, characterized in that, After performing a weighted fusion process of synthesizing sine and cosine components of the orientation angle based on the region confidence level to obtain the tilt angle corresponding to the target text image, the method further includes: The confidence level of the tilt angle is quantitatively evaluated to generate a confidence level for the tilt angle; and based on the confidence level, a tilt correction strategy for the target text image is determined.

10. An image processing device, characterized in that, include: Processor, memory, system bus; The processor and the memory are connected via the system bus; The memory is used to store one or more programs, the one or more programs including instructions that, when executed by the processor, cause the processor to perform the method according to any one of claims 1-9.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed on a terminal device, cause the terminal device to perform the method described in any one of claims 1-9.

12. A computer program product, comprising a computer program, characterized in that, The program product includes a computer program that, when executed by an electronic product, can implement the method described in any one of claims 1-9.