Image correction method and device based on text block angle and dichotomy model
Through the image deviation correction method based on the text block angle and binary classification model, feature straight lines are extracted and eliminated, and the image state is judged by the pre-trained model, the problems of image deviation accuracy and GPU occupancy in the prior art are solved, and fast and accurate are achieved image correction effect.
Patent Information
- Application Number
- CN202411332628.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-07
AI Technical Summary
The existing image deviation correction technology has problems in accuracy and GPU occupancy, making it difficult to effectively correct rotating or tilted images.
Using the image deviation correction method based on the text block angle and binary classification model, the feature straight lines of each line of text in the image are extracted, the abnormal feature straight lines are eliminated, and the pre-trained binary classification model is used to determine whether the image is reversed, and preliminary correction or rotation is performed 180 degrees. deal with.
It realizes fast and accurate image deviation correction, improves deviation correction accuracy, and optimizes GPU occupancy.
Smart Images

Figure CN119274186A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to an image correction algorithm based on text block angle and a binary classification model. Background Art
[0002] Image deflection, or image rotation correction, is a common problem in computer vision and image processing. The goal of this task is to adjust tilted or rotated images to the correct orientation. When performing this task, common image deflection tasks always face the problem of low accuracy when using image processing libraries, or high GPU usage when using models. Summary of the invention
[0003] In view of the above problems, the present invention proposes a technical solution:
[0004] The present invention provides an image correction method based on text block angle and binary classification model, which is used to correct the angle of an image including text, and comprises the following steps:
[0005] S1: Extract the characteristic straight line representing the row direction of each line of text in the image;
[0006] S2: Eliminate abnormal feature lines;
[0007] S3: The average deviation angle of the characteristic straight line relative to the horizontal direction is used as the deviation angle of the image, and the image is initially corrected based on the deviation angle;
[0008] S4: Use the pre-trained binary classification model to determine whether the image is upright or inverted. If it is upright, the image processing is completed; if it is inverted, rotate the image 180 degrees, and the image processing is completed.
[0009] Preferably, the method for extracting the characteristic straight line is:
[0010] Use the erosion algorithm to perform image erosion operation on the image;
[0011] Then use the edge detection algorithm to process the image and get the text border of each line;
[0012] The image is further processed using the Hough line detection algorithm to obtain the characteristic straight lines.
[0013] The preferred method for extracting characteristic lines is:
[0014] Use the pre-trained deep learning model to segment each line of text into a separate line of text image.
[0015] Draw a circumscribed rectangle for each line of text image, and take the long side of the circumscribed rectangle as the characteristic straight line of the text line.
[0016] Preferably, the algorithm for drawing the circumscribed rectangle is a corner point detection algorithm or an edge fitting algorithm.
[0017] Preferably, the method for removing abnormal characteristic straight lines is:
[0018] For all feature lines, the deviation angle relative to the horizontal direction is used as the feature, and clustering is performed using a clustering algorithm that does not specify the number of cluster centers;
[0019] Only the characteristic lines in the cluster with the largest number of clusters are retained, and the remaining characteristic lines are removed as abnormal characteristic lines.
[0020] Preferably, the method for removing abnormal characteristic straight lines is:
[0021] The deviation angles of all characteristic lines relative to the horizontal direction are counted, and all characteristic lines whose angles are greater than a preset range near the average value are eliminated.
[0022] Preferably, the binary classification model is a CNN model.
[0023] The present invention also provides an image correction device based on text block angle and binary classification model, which is used to correct the angle of an image whose content includes text, and includes the following modules:
[0024] Feature extraction module: used to extract the characteristic straight line representing the row direction of each line of text in the image;
[0025] Abnormal elimination module: used to eliminate abnormal characteristic straight lines;
[0026] Preliminary deflection correction module: used to take the average deflection angle of the characteristic straight line relative to the horizontal direction as the deflection angle of the image, and perform preliminary deflection correction on the image accordingly;
[0027] Inversion correction module: used to use the pre-trained binary classification model to determine whether the image is upright or inverted. If it is upright, the image processing is completed; if it is inverted, the image is rotated 180 degrees, and the image processing is completed.
[0028] Preferably, the method for extracting the characteristic straight line is:
[0029] Use the erosion algorithm to perform image erosion operation on the image;
[0030] Then use the edge detection algorithm to process the image and get the text border of each line;
[0031] The image is further processed using the Hough line detection algorithm to obtain the characteristic straight lines.
[0032] Preferably, the method for extracting the characteristic straight line is:
[0033] Use the pre-trained deep learning model to segment each line of text into a separate line of text image.
[0034] Draw a circumscribed rectangle for each line of text image, and take the long side of the circumscribed rectangle as the characteristic straight line of the text line.
[0035] Beneficial effects:
[0036] The present invention uses the graphics processing algorithm in OpenCV image processing or the image segmentation technology based on the deep learning model to detect the text blocks of the image and make preliminary corrections. At this time, it is impossible to know whether the corrected image is upright or inverted. Then, the CNN binary classification model is used to correct the corrected image, so that the corrected image can be obtained quickly and accurately. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 is a flow chart in an embodiment of the present invention; DETAILED DESCRIPTION
[0038] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0039] like Figure 1 As shown, an image correction method based on text block angle and binary classification model is used to correct the angle of an image containing text, including the following steps:
[0040] S1: Extract the characteristic straight line representing the row direction of each line of text in the image;
[0041] In this embodiment, the method for extracting the characteristic straight line is:
[0042] Use the erosion algorithm to perform image erosion operation on the image; this step can make the text in each line blur together, so as to reduce interference and amplify the line attributes;
[0043] Then use the edge detection algorithm to process the image and get the text border of each line; the border obtained at this time will be intermittent and uneven, but it further reduces interference and amplifies the properties of the line;
[0044] The Hough line detection algorithm is used to further process the image and obtain characteristic lines. The Hough line detection algorithm can process the intermittent and uneven borders after edge detection into characteristic lines.
[0045] The above-mentioned corrosion algorithm, edge detection algorithm, and Hough line detection algorithm all belong to the existing technology and can be directly called using libraries such as OpenCV; therefore, the specific content of the algorithm will not be repeated here.
[0046] In some possible implementations, the method for extracting the characteristic straight line is:
[0047] Use the pre-trained deep learning model to segment each line of text into a separate line of text image.
[0048] Draw a circumscribed rectangle for each line of text image, and take the long side of the circumscribed rectangle as the characteristic straight line of the text line; in this embodiment, the algorithm for drawing the circumscribed rectangle is a corner point detection algorithm or an edge fitting algorithm;
[0049] S2: Eliminate abnormal feature lines;
[0050] Among the feature lines obtained in the previous step, if there are lines of watermarks in the form of text, and the angles of these watermarks deviate greatly from the normal text, then the feature lines extracted from these watermark texts are all abnormal feature lines; or if some lines of normal text are too short, with only one word, then the feature line extracted from this line of text may be exactly perpendicular to the real line direction, so the feature line extracted from this line of text in this case is also an abnormal feature line;
[0051] For normal text, the deviation angle between the row direction and the horizontal direction is generally small, while the deviation angle between the characteristic straight line of the watermark or the abnormal characteristic straight line perpendicular to the normal direction and the horizontal direction is significantly larger. At the same time, the number of characteristic straight lines extracted from normal text is also the largest.
[0052] Therefore, in this embodiment, the abnormal feature straight lines are removed in the following manner:
[0053] For all feature lines, the deviation angle relative to the horizontal direction is used as the feature, and clustering is performed using a clustering algorithm that does not specify the number of cluster centers;
[0054] Only the characteristic lines in the cluster with the largest number of clusters are retained, and the remaining characteristic lines are removed as abnormal characteristic lines.
[0055] In some possible implementations, abnormal feature lines are removed using the following method:
[0056] Count the deviation angles of all characteristic lines relative to the horizontal direction, and remove all characteristic lines whose angles are greater than a preset range near the average value;
[0057] S3: The average deviation angle of the characteristic straight line relative to the horizontal direction is used as the deviation angle of the image, and the image is initially corrected based on the deviation angle;
[0058] S4: Use the pre-trained binary classification model to determine whether the image is normal or inverted. If it is normal, the image processing is completed; if it is inverted, rotate the image 180 degrees, and the image processing is completed. In this embodiment, the binary classification model is a CNN model.
[0059] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. An image correction method based on text block angle and binary classification model, used to correct the angle of an image containing text, characterized in that: The following steps are involved: S1: Extract the characteristic straight line representing the row direction of each line of text in the image; S2: Eliminate abnormal feature lines; S3: The average deviation angle of the characteristic straight line relative to the horizontal direction is used as the deviation angle of the image, and the image is initially corrected based on the deviation angle; S4: Use the pre-trained binary classification model to determine whether the image is upright or inverted. If it is upright, the image processing is completed; if it is inverted, rotate the image 180 degrees, and the image processing is completed.
2. The image correction method based on text block angle and binary classification model according to claim 1 is characterized in that: The method for extracting characteristic lines is: Use the erosion algorithm to perform image erosion operation on the image; Then use the edge detection algorithm to process the image and get the text border of each line; The image is further processed using the Hough line detection algorithm to obtain the characteristic straight lines.
3. The image correction method based on text block angle and binary classification model according to claim 1 is characterized in that: The method for extracting characteristic lines is: Use the pre-trained deep learning model to segment each line of text into a separate line of text image. Draw a circumscribed rectangle for each line of text image, and take the long side of the circumscribed rectangle as the characteristic straight line of the text line.
4. The image correction method based on text block angle and binary classification model according to claim 3 is characterized in that: The algorithm for drawing the bounding rectangle is a corner detection algorithm or an edge fitting algorithm.
5. The image correction method based on text block angle and binary classification model according to claim 1 is characterized in that: The method for removing abnormal feature lines is: For all feature lines, the deviation angle relative to the horizontal direction is used as the feature, and clustering is performed using a clustering algorithm that does not specify the number of cluster centers; Only the characteristic lines in the cluster with the largest number of clusters are retained, and the remaining characteristic lines are removed as abnormal characteristic lines.
6. The image correction method based on text block angle and binary classification model according to claim 1, characterized in that: The method for removing abnormal feature lines is: The deviation angles of all characteristic lines relative to the horizontal direction are counted, and all characteristic lines whose angles are greater than a preset range near the average value are eliminated.
7. The image correction method based on text block angle and binary classification model according to claim 1 is characterized in that: The binary classification model is a CNN model.
8. An image correction device based on text block angle and binary classification model, used to correct the angle of an image containing text, characterized in that: Includes the following modules: Feature extraction module: used to extract the characteristic straight line representing the row direction of each line of text in the image; Abnormal elimination module: used to eliminate abnormal characteristic straight lines; Preliminary deflection correction module: used to take the average deflection angle of the characteristic straight line relative to the horizontal direction as the deflection angle of the image, and perform preliminary deflection correction on the image accordingly; Inversion correction module: used to use the pre-trained binary classification model to determine whether the image is upright or inverted. If it is upright, the image processing is completed; if it is inverted, the image is rotated 180 degrees, and the image processing is completed.
9. The image correction device based on text block angle and binary classification model according to claim 8, characterized in that: The method for extracting characteristic lines is: Use the erosion algorithm to perform image erosion operation on the image; Then use the edge detection algorithm to process the image and get the text border of each line; The image is further processed using the Hough line detection algorithm to obtain the characteristic straight lines.
10. The image correction device based on text block angle and binary classification model according to claim 8, characterized in that: The method for extracting characteristic lines is: Use the pre-trained deep learning model to segment each line of text into a separate line of text image. Draw a circumscribed rectangle for each line of text image, and take the long side of the circumscribed rectangle as the characteristic straight line of the text line.