Image automatic deviation correction method and system
By preprocessing the image and using Hough transform to identify line segments and calculate the tilt angle, accurate rotation correction of the image is achieved while maintaining efficient processing. This solves the problem of balancing robustness and accuracy in traditional methods and improves image recognition accuracy.
Patent Information
- Application Number
- CN202511416415.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-30
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2045-09-30
AI Technical Summary
Traditional image rotation methods struggle to balance robustness and accuracy while maintaining high processing efficiency, leading to a decline in OCR recognition and structure extraction performance due to image tilt.
By acquiring images and preprocessing them to remove noise and background interference, enhancing line features, using Hough transform to identify vertical and horizontal line segments, calculating tilt angles, and performing rotation correction within a preset angle range.
It improves the accuracy of image structure recognition and the level of system intelligence, and significantly enhances the accuracy of tilt angle recognition.
Smart Images

Figure CN120894532B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image processing technology, and specifically relates to an automatic image correction method and system. Background Technology
[0002] In practical applications such as intelligent homework systems, exam paper photography, and document recognition, users often use handheld devices to photograph homework pages. This shooting method is very likely to produce slight or moderate angle tilts in the image, which leads to a significant decrease in the performance of subsequent OCR recognition, structure extraction, and other algorithms.
[0003] Traditional image rotation methods, such as template matching and coordinate axis-based estimation, have limited accuracy and cannot balance robustness and accuracy while maintaining efficient processing. Summary of the Invention
[0004] Based on this, the present invention provides an automatic image correction method and system, which aims to identify the tilt angle of an image and perform rotation correction to improve the accuracy of image structure recognition and the overall intelligence level of the system.
[0005] A first aspect of this invention provides an automatic image correction method, the method comprising:
[0006] An image is acquired and preprocessed to remove noise and background interference while enhancing line features, thus obtaining the image to be detected.
[0007] Identify vertical and horizontal line segments in the image to be detected, and calculate the vertical and horizontal tilt angles of the image to be detected based on the vertical and horizontal line segments.
[0008] Determine whether the vertical tilt angle and the horizontal tilt angle are less than a preset angle;
[0009] If so, the image to be detected is rotated to obtain the rotated image.
[0010] Furthermore, the steps of acquiring the image and preprocessing the image to remove noise and background interference while enhancing line features to obtain the image to be detected include:
[0011] The image is converted to grayscale, and a hot pixel removal algorithm is used to filter noise.
[0012] The grayscale image with noise filtered is subjected to a vertical running length smoothing algorithm to enhance the vertical line segments, and then dilation is performed to obtain the image to be detected.
[0013] Furthermore, the step of identifying vertical and horizontal line segments in the image to be detected, and calculating the vertical and horizontal tilt angles of the image to be detected based on the vertical and horizontal line segments, includes:
[0014] The Hough transform is used to identify vertical line segments in the image to be detected. The angle between each vertical line segment and the line in the image to be detected is calculated. Based on the first preset angle and the angle between each vertical line segment and the line in the image to be detected, the first line segment is selected.
[0015] Cluster analysis is performed on the first line segment near the left and right edges of the image to be detected to determine the central candidate region;
[0016] In the central candidate region, the line segment group with the highest density and the largest coverage length is selected. The angle between each first line segment in the line segment group and the center line of the image to be detected is obtained. The average value of the angle between each first line segment in the line segment group and the center line of the image to be detected is calculated. The average value is determined as the vertical tilt angle of the image to be detected.
[0017] Furthermore, the step of performing cluster analysis on the first line segments near the left and right edges of the image to be detected to determine the central candidate region includes:
[0018] The first line segment is sorted according to its horizontal position, wherein the horizontal position is the position of the midpoint of the horizontal axis of the first line segment;
[0019] Within the left 1 / 5 width range of the image to be detected, find the first line segment whose length exceeds 95% of the height of the image to be detected, and use it as the left boundary line;
[0020] Within the right 1 / 5 width range of the image to be detected, find the first line segment whose length exceeds 95% of the height of the image to be detected, and use it as the right boundary line;
[0021] Based on the left boundary line and the right boundary line, determine the midpoint and use the midpoint as the position of the image's central axis;
[0022] Based on the central axis position, the image width is expanded to the left and right by 1 / 6 to obtain the central candidate region.
[0023] Furthermore, the step of selecting the line segment group with the highest density and largest coverage length in the central candidate region, obtaining the angle between each line segment in the line segment group and the center line of the image to be detected, calculating the average value of the angle between each line segment in the line segment group and the center line of the image to be detected, and determining the average value as the vertical tilt angle of the image to be detected includes:
[0024] Step 1: Obtain the lateral position of the first line segment in the central candidate region, and group line segments with a lateral position difference of less than or equal to 3 pixels into the same line segment group.
[0025] Step 2: Calculate the maximum length of the first segment in each segment group, and calculate the average angle between the first segment in each segment group and the vertical direction;
[0026] Step 3: Sort the line segment groups in descending order of their maximum length;
[0027] Step 4: Sequentially obtain the maximum length of the first line segment in the line segment group, and determine whether the maximum length of the first line segment in the line segment group is greater than half of the image height, and at the same time determine whether the number of the first line segments in the line segment group is less than 15.
[0028] Step 5: If yes, then it is determined to be a valid group of line segments;
[0029] Step six: If not, gradually adjust the threshold of the maximum length of the first segment in the segment group to relax the conditions, and re-execute the judgment operation in step four until a valid segment group is determined.
[0030] Step 7: Obtain the angle between each first line segment in the effective line segment group and the center line of the image to be detected, calculate the average value of the angle between each first line segment in the effective line segment group and the center line of the image to be detected, and determine the average value as the vertical tilt angle of the image to be detected.
[0031] Furthermore, the step of identifying vertical and horizontal line segments in the image to be detected, and calculating the vertical tilt angle and horizontal tilt angle of the image to be detected based on the vertical and horizontal line segments, further includes:
[0032] The image to be detected is subjected to Canny edge detection, and the horizontal line segments in the image to be detected are identified by Hough transform. The slope of each horizontal line segment is calculated and converted into an angle.
[0033] The second line segment is selected based on the second preset angle and the angles of the line segments in each horizontal direction;
[0034] Based on the number of second line segments, a calculation strategy is determined, and the horizontal tilt angle is calculated based on the calculation strategy, the angle of the second line segments, and the number of second line segments. The calculation strategy includes using a density interval algorithm to extract concentrated angles when the number of second line segments is greater than a first preset number; calculating the average angle of the second line segments when the number of second line segments is between the first preset number and the second preset number; and calculating the weighted average angle of the second line segments based on length weighting when the number of second line segments is less than the second preset number.
[0035] Furthermore, the step of extracting concentrated angles using the density interval algorithm includes:
[0036] Set an initial interval width and control the initial interval width to gradually decrease to obtain the width of each interval;
[0037] Obtain the angle of the second line segment, form an angle set, control the width of each interval to slide in the angle set, and count the number of angles contained in each interval width;
[0038] Based on the number of angles, determine the target interval width with the largest number of line segments and the smallest interval width span, and calculate the average angle within the target interval width to obtain the horizontal tilt angle.
[0039] A second aspect of the present invention provides an automatic image correction system for implementing an automatic image correction method provided in the first aspect of the present invention, the system comprising:
[0040] An acquisition module is used to acquire an image and preprocess the image to remove noise and background interference, while enhancing line features to obtain the image to be detected.
[0041] The recognition module is used to recognize vertical and horizontal line segments in the image to be detected, and to calculate the vertical tilt angle and horizontal tilt angle of the image to be detected based on the vertical and horizontal line segments.
[0042] The judgment module is used to determine whether the vertical tilt angle and the horizontal tilt angle are less than a preset angle;
[0043] The rotation module is used to rotate the image to be detected when the vertical tilt angle and the horizontal tilt angle are both less than a preset angle, so as to obtain a rotated image.
[0044] A third aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the automatic image correction method provided in the first aspect.
[0045] A fourth aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the program to implement the automatic image correction method provided in the first aspect.
[0046] The present invention provides an automatic image correction method and system, which acquires an image and preprocesses it to remove noise and background interference while enhancing line features to obtain an image to be detected. The system identifies vertical and horizontal line segments in the image and calculates the vertical and horizontal tilt angles based on these line segments. It then determines whether the vertical and horizontal tilt angles are less than preset angles. If so, the image is rotated to obtain a rotated image. Specifically, by fusing the vertical and horizontal line segments, the accuracy of tilt angle recognition is significantly improved. Attached Figure Description
[0047] Figure 1 This is a flowchart illustrating the implementation of an automatic image correction method according to Embodiment 1 of the present invention.
[0048] Figure 2 This is a structural block diagram of an automatic image correction system provided in Embodiment 2 of the present invention;
[0049] Figure 3 This is a structural block diagram of an electronic device provided in Embodiment 3 of the present invention. Detailed Implementation
[0050] To facilitate understanding of the present invention, a more complete description will be given below with reference to the accompanying drawings. Several embodiments of the invention are illustrated in the drawings. However, the invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
[0051] It should be noted that when a component is said to be "fixed to" another component, it can be directly on the other component or there may be an intervening component. When a component is said to be "connected to" another component, it can be directly connected to the other component or there may be an intervening component. The terms "vertical," "horizontal," "left," "right," and similar expressions used in this document are for illustrative purposes only.
[0052] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0053] Example 1
[0054] Please see Figure 1 , Figure 1 The present invention illustrates an automatic image correction method according to Embodiment 1 of the present invention, which specifically includes steps S01 to S04.
[0055] Step S01: Acquire an image and preprocess the image to remove noise and background interference, while enhancing line features to obtain the image to be detected.
[0056] Specifically, the image is converted to grayscale and noise is filtered using the ClearHotPixel algorithm;
[0057] The grayscale image with noise filtered is subjected to a vertical run length smoothing algorithm to enhance vertical line segments, and then dilated (Dilatation3x3) to enhance line connectivity, thus obtaining the image to be detected.
[0058] Step S02: Identify the vertical and horizontal line segments in the image to be detected, and calculate the vertical tilt angle and horizontal tilt angle of the image to be detected based on the vertical and horizontal line segments.
[0059] In this embodiment of the invention, Hough Lines Binary is used to identify vertical line segments in the image to be detected, calculate the angle between each vertical line segment and the line in the image to be detected, and filter out the first line segment based on the first preset angle and the angle between each vertical line segment and the line in the image to be detected. Specifically, the first line segment is a line segment with an angle of 90°±5°.
[0060] Cluster analysis is performed on the first line segments near the left and right edges of the image to be detected to determine the central candidate region. Specifically, the first line segments are sorted according to their horizontal positions, where the horizontal position is the midpoint of the horizontal axis of the first line segment.
[0061] Within the left 1 / 5 width range of the image to be detected, find the first line segment whose length exceeds 95% of the height of the image to be detected, and use it as the left boundary line;
[0062] Within the right 1 / 5 width range of the image to be detected, find the first line segment whose length exceeds 95% of the height of the image to be detected, and use it as the right boundary line;
[0063] Based on the left and right boundary lines, the midpoint is determined and used as the position of the image's central axis. It can be understood that if the right boundary is missing, the average value of the left boundary and the midpoint of the image width is used to approximate it. Similarly, if the left boundary is missing, the average value of the right boundary and the midpoint of the image width is used to approximate it.
[0064] Based on the central axis position, expand the image width to the left and right by 1 / 6 to obtain the central candidate region;
[0065] In the central candidate region, the line segment group with the highest density and the largest coverage length is selected. The angle between each first line segment in the line segment group and the center line of the image to be detected is obtained. The average value of the angle between each first line segment in the line segment group and the center line of the image to be detected is calculated. The average value is determined as the vertical tilt angle of the image to be detected. It should be noted that the specific steps include:
[0066] Step 1: Obtain the lateral position of the first line segment in the central candidate region, and group line segments with a lateral position difference of less than or equal to 3 pixels into the same line segment group.
[0067] Step 2: Calculate the maximum length of the first segment in each segment group, and calculate the average angle between the first segment in each segment group and the vertical direction;
[0068] Step 3: Sort the line segment groups in descending order of their maximum length;
[0069] Step 4: Sequentially obtain the maximum length of the first line segment in the line segment group, and determine whether the maximum length of the first line segment in the line segment group is greater than half of the image height, and at the same time determine whether the number of the first line segments in the line segment group is less than 15.
[0070] Step 5: If yes, then it is determined to be a valid group of line segments;
[0071] Step 6: If not, gradually adjust the threshold of the maximum length of the first line segment in the line segment group to relax the conditions, and re-execute the judgment operation in Step 4 until a valid line segment group is determined. For example, if the maximum length of the first line segment in the line segment group is not greater than half of the image height and the number of the first line segments in the line segment group is less than 15, then determine whether the maximum length of the first line segment in the line segment group is greater than one-third of the image height and whether the number of the first line segments in the line segment group is less than 15. If it is still not satisfied, then determine whether the maximum length of the first line segment in the line segment group is greater than one-quarter of the image height and whether the number of the first line segments in the line segment group is less than 15, and so on.
[0072] Step 7: Obtain the angle between each first line segment in the effective line segment group and the center line of the image to be detected, calculate the average value of the angle between each first line segment in the effective line segment group and the center line of the image to be detected, and determine the average value as the vertical tilt angle of the image to be detected.
[0073] Specifically, the calculation of the horizontal tilt angle includes the following steps:
[0074] The image to be detected is subjected to Canny edge detection, and the horizontal line segments in the image to be detected are identified by Hough transform. The slope of each horizontal line segment is calculated and converted into an angle.
[0075] Based on the second preset angle and the angles of line segments in each horizontal direction, the second line segment is selected, wherein the second line segment is a line segment with an angle of less than 10°;
[0076] Based on the number of second line segments, a calculation strategy is determined, and the horizontal tilt angle is calculated based on the calculation strategy, the angle of the second line segments, and the number of second line segments. The calculation strategy includes using a density interval algorithm to extract concentrated angles when the number of second line segments is greater than a first preset number; calculating the average angle of the second line segments when the number of second line segments is between the first preset number and the second preset number; and calculating the weighted average angle of the second line segments based on length weighting when the number of second line segments is less than the second preset number.
[0077] It should be noted that the step of extracting concentrated angles using the density interval algorithm includes:
[0078] Set an initial interval width and control the initial interval width to gradually decrease to obtain the width of each interval;
[0079] Obtain the angle of the second line segment, form an angle set, control the width of each interval to slide in the angle set, and count the number of angles contained in each interval width;
[0080] Based on the number of angles, determine the target interval width with the largest number of line segments and the smallest interval width span, and calculate the average angle within the target interval width to obtain the horizontal tilt angle.
[0081] Step S03: Determine whether the vertical tilt angle and the horizontal tilt angle are less than a preset angle. If so, proceed to step S04.
[0082] For example, if the absolute values of the vertical tilt angle and the horizontal tilt angle are less than 10°, the image is considered to have a tilt within a tolerable range and is then rotated.
[0083] In step S04, the image to be detected is rotated to obtain the rotated image.
[0084] In this embodiment of the invention, the image is rotated in reverse using the Rotator.Rotate tool to correct the deviation, and finally the rotated image and the corrected angle value are output.
[0085] In summary, the automatic image correction method in the above embodiments of the present invention acquires an image and preprocesses it to remove noise and background interference while enhancing line features to obtain an image to be detected; identifies vertical and horizontal line segments in the image to be detected, and calculates the vertical and horizontal tilt angles of the image to be detected based on the vertical and horizontal line segments; determines whether the vertical and horizontal tilt angles are less than a preset angle; if so, rotates the image to be detected to obtain a rotated image. Specifically, by fusing and judging the line segments in both vertical and horizontal dimensions, the accuracy of tilt angle recognition is greatly improved.
[0086] Example 2
[0087] Please see Figure 2 , Figure 2 This is a structural block diagram of an automatic image correction system 200 provided in Embodiment 2 of the present invention. The automatic image correction system 200 specifically includes: an acquisition module 21, a recognition module 22, a judgment module 23, and a rotation module 24, wherein:
[0088] The acquisition module 21 is used to acquire an image and preprocess the image to remove noise and background interference in the image, while enhancing line features to obtain the image to be detected.
[0089] The recognition module 22 is used to recognize vertical line segments and horizontal line segments in the image to be detected, and to calculate the vertical tilt angle and horizontal tilt angle of the image to be detected based on the vertical line segments and horizontal line segments.
[0090] The judgment module 23 is used to determine whether the vertical tilt angle and the horizontal tilt angle are less than a preset angle;
[0091] The rotation module 24 is used to rotate the image to be detected when it is determined that the vertical tilt angle and the horizontal tilt angle are less than a preset angle, so as to obtain the rotated image.
[0092] Furthermore, in some optional embodiments of the present invention, the acquisition module 21 includes:
[0093] A grayscale conversion unit is used to perform grayscale conversion on the image and to filter noise using a hot pixel removal algorithm;
[0094] The dilation processing unit is used to apply a vertical running length smoothing algorithm to the grayscale image with filtered noise to enhance the vertical line segments and perform dilation processing to obtain the image to be detected.
[0095] Furthermore, in some optional embodiments of the present invention, the identification module 22 includes:
[0096] The first calculation unit is used to identify vertical line segments in the image to be detected using Hough transform, calculate the angle between each vertical line segment and the line in the image to be detected, and filter out the first line segment based on the first preset angle and the angle between each vertical line segment and the line in the image to be detected.
[0097] The clustering analysis unit is used to perform clustering analysis on the first line segments near the left and right edges of the image to be detected to determine the central candidate region;
[0098] The second calculation unit is used to filter out the line segment group with the highest density and the largest coverage length in the central candidate region, obtain the angle between each first line segment in the line segment group and the center line of the image to be detected, calculate the average value of the angle between each first line segment in the line segment group and the center line of the image to be detected, and determine the average value as the vertical tilt angle of the image to be detected.
[0099] Furthermore, in some optional embodiments of the present invention, the clustering analysis unit includes:
[0100] The first sorting subunit is used to sort the first line segment according to its horizontal position, wherein the horizontal position is the position of the midpoint of the horizontal axis of the first line segment;
[0101] The first searching subunit is used to search for a first line segment whose length exceeds 95% of the height of the image to be detected within the left 1 / 5 width range of the image to be detected, and to serve as the left boundary line.
[0102] The second searching subunit is used to search for a first line segment whose length exceeds 95% of the height of the image to be detected within the right 1 / 5 width range of the image to be detected, as the right boundary line;
[0103] The first determining subunit is used to determine the midpoint based on the left boundary line and the right boundary line, and to use the midpoint as the position of the image central axis;
[0104] An extended subunit is used to expand the image width to the left and right by 1 / 6 according to the central axis position to obtain the central candidate region.
[0105] Furthermore, in some optional embodiments of the present invention, the second computing unit includes:
[0106] The sub-unit is used to obtain the lateral position of the first line segment in the central candidate region and to group line segments with a lateral position difference of less than or equal to 3 pixels into the same line segment group.
[0107] The first calculation subunit is used to calculate the maximum length of the first line segment in each line segment group, and to calculate the average value of the angle between the first line segment in each line segment group and the vertical direction.
[0108] The second sorting subunit is used to sort the line segment groups in descending order of maximum length;
[0109] The judgment sub-unit is used to sequentially obtain the maximum length of the first line segment in the line segment group, and determine whether the maximum length of the first line segment in the line segment group is greater than half of the image height, and at the same time determine whether the number of the first line segments in the line segment group is less than 15.
[0110] The second determining subunit is determined as follows: if the maximum length of the first line segment in the line segment group is greater than half the image height, and the number of the first line segments in the line segment group is less than 15, then it is determined as a valid line segment group.
[0111] If the third determining subunit determines that the maximum length of the first line segment in the line segment group is not greater than half the image height, and the number of the first line segments in the line segment group is not less than 15, then the threshold of the maximum length of the first line segment in the line segment group is gradually adjusted to relax the conditions, and the judgment operation in the second determining subunit is re-executed until a valid line segment group is determined.
[0112] The second calculation subunit is used to obtain the angle between each first line segment in the effective line segment group and the center line of the image to be detected, calculate the average value of the angle between each first line segment in the effective line segment group and the center line of the image to be detected, and determine the average value as the vertical tilt angle of the image to be detected.
[0113] Furthermore, in some optional embodiments of the present invention, the identification module 22 further includes:
[0114] The third calculation unit is used to perform Canny edge detection on the image to be detected, identify horizontal line segments in the image to be detected through Hough transform, calculate the slope of each horizontal line segment, and convert it into an angle.
[0115] The filtering unit is used to filter out the second line segment based on the second preset angle and the angles of the line segments in each horizontal direction.
[0116] The determining unit is used to determine a calculation strategy based on the number of second line segments, and to calculate the horizontal tilt angle based on the calculation strategy, the angle of the second line segments, and the number of second line segments. The calculation strategy includes using a density interval algorithm to extract concentrated angles when the number of second line segments is greater than a first preset number, calculating the average angle of the second line segments when the number of second line segments is between the first preset number and the second preset number, and calculating the weighted average angle of the second line segments based on length weighting when the number of second line segments is less than the second preset number.
[0117] Furthermore, in some optional embodiments of the present invention, the determining unit includes:
[0118] A sub-unit is set to set the initial interval width and control the initial interval width to gradually decrease to obtain the width of each interval;
[0119] The control subunit is used to acquire the angle of the second line segment, form an angle set, control the width of each interval to slide in the angle set, and count the number of angles contained in each interval width.
[0120] The third calculation subunit is used to determine the target interval width with the maximum number of line segments and the minimum interval width span based on the number of angles, and to calculate the average value of the angles within the target interval width to obtain the horizontal tilt angle.
[0121] Example 3
[0122] In another aspect, the present invention also proposes an electronic device, please refer to [link to relevant documentation]. Figure 3 The image shown is an electronic device according to Embodiment 3 of the present invention, including a memory 20, a processor 10, and a computer program 30 stored in the memory and executable on the processor. When the processor 10 executes the computer program 30, it implements the image automatic correction method as described above.
[0123] In some embodiments, the processor 10 may be a central processing unit (CPU), controller, microcontroller, microprocessor or other data processing chip, used to run program code stored in memory 20 or process data, such as executing access restriction programs.
[0124] The memory 20 includes at least one type of readable storage medium, such as flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 20 can be an internal storage unit of an electronic device, such as the hard disk of the electronic device. In other embodiments, the memory 20 can also be an external storage device of the electronic device, such as a plug-in hard disk, SmartMediaCard (SMC), SecureDigital (SD) card, FlashCard, etc., equipped on the electronic device. Furthermore, the memory 20 can include both internal and external storage units of the electronic device. The memory 20 can be used not only to store application software and various types of data of the electronic device, but also to temporarily store data that has been output or will be output.
[0125] It should be pointed out that, Figure 3The structure shown does not constitute a limitation on the electronic device. In other embodiments, the electronic device may include fewer or more components than shown, or combine certain components, or have different component arrangements.
[0126] This invention also proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the image automatic correction method described above.
[0127] Those skilled in the art will understand that the logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can mean any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0128] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0129] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0130] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0131] The above embodiments merely illustrate several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this patent should be determined by the appended claims.
Claims
1. An automatic image correction method, characterized in that, The method includes: An image is acquired and preprocessed to remove noise and background interference while enhancing line features, thus obtaining the image to be detected. Identify vertical and horizontal line segments in the image to be detected, and calculate the vertical and horizontal tilt angles of the image to be detected based on the vertical and horizontal line segments. Determine whether the vertical tilt angle and the horizontal tilt angle are less than a preset angle; If so, the image to be detected is rotated to obtain the rotated image; The step of identifying vertical and horizontal line segments in the image to be detected, and calculating the vertical and horizontal tilt angles of the image to be detected based on the vertical and horizontal line segments, includes: The Hough transform is used to identify vertical line segments in the image to be detected. The angle between each vertical line segment and the line in the image to be detected is calculated. Based on the first preset angle and the angle between each vertical line segment and the line in the image to be detected, the first line segment is selected. Cluster analysis is performed on the first line segment near the left and right edges of the image to be detected to determine the central candidate region; In the central candidate region, the line segment group with the highest density and the largest coverage length is selected. The angle between each first line segment in the line segment group and the center line of the image to be detected is obtained. The average value of the angle between each first line segment in the line segment group and the center line of the image to be detected is calculated. The average value is determined as the vertical tilt angle of the image to be detected.
2. The automatic image correction method according to claim 1, characterized in that, The steps of acquiring an image and preprocessing the image to remove noise and background interference while enhancing line features to obtain the image to be detected include: The image is converted to grayscale, and a hot pixel removal algorithm is used to filter noise. The grayscale image with noise filtered is subjected to a vertical running length smoothing algorithm to enhance the vertical line segments, and then dilation is performed to obtain the image to be detected.
3. The automatic image correction method according to claim 2, characterized in that, The step of performing cluster analysis on the first line segments near the left and right edges of the image to be detected to determine the central candidate region includes: The first line segment is sorted according to its horizontal position, wherein the horizontal position is the position of the midpoint of the horizontal axis of the first line segment; Within the left 1 / 5 width range of the image to be detected, find the first line segment whose length exceeds 95% of the height of the image to be detected, and use it as the left boundary line; Within the right 1 / 5 width range of the image to be detected, find the first line segment whose length exceeds 95% of the height of the image to be detected, and use it as the right boundary line; Based on the left boundary line and the right boundary line, determine the midpoint and use the midpoint as the position of the image's central axis; Based on the central axis position, the image width is expanded to the left and right by 1 / 6 to obtain the central candidate region.
4. The automatic image correction method according to claim 3, characterized in that, The steps of selecting the line segment group with the highest density and largest coverage length in the central candidate region, obtaining the angle between each line segment in the line segment group and the center line of the image to be detected, calculating the average value of the angle between each line segment in the line segment group and the center line of the image to be detected, and determining the average value as the vertical tilt angle of the image to be detected include: Step 1: Obtain the lateral position of the first line segment in the central candidate region, and group line segments with a lateral position difference of less than or equal to 3 pixels into the same line segment group. Step 2: Calculate the maximum length of the first segment in each segment group, and calculate the average angle between the first segment in each segment group and the vertical direction; Step 3: Sort the line segment groups in descending order of their maximum length; Step 4: Sequentially obtain the maximum length of the first line segment in the line segment group, and determine whether the maximum length of the first line segment in the line segment group is greater than half of the image height, and at the same time determine whether the number of the first line segments in the line segment group is less than 15. Step 5: If yes, then it is determined to be a valid group of line segments; Step six: If not, gradually adjust the threshold of the maximum length of the first segment in the segment group to relax the conditions, and re-execute the judgment operation in step four until a valid segment group is determined. Step 7: Obtain the angle between each first line segment in the effective line segment group and the center line of the image to be detected, calculate the average value of the angle between each first line segment in the effective line segment group and the center line of the image to be detected, and determine the average value as the vertical tilt angle of the image to be detected.
5. The automatic image correction method according to claim 2, characterized in that, The step of identifying vertical and horizontal line segments in the image to be detected, and calculating the vertical tilt angle and horizontal tilt angle of the image to be detected based on the vertical and horizontal line segments, further includes: The image to be detected is subjected to Canny edge detection, and the horizontal line segments in the image to be detected are identified by Hough transform. The slope of each horizontal line segment is calculated and converted into an angle. The second line segment is selected based on the second preset angle and the angles of the line segments in each horizontal direction; Based on the number of second line segments, a calculation strategy is determined, and the horizontal tilt angle is calculated based on the calculation strategy, the angle of the second line segments, and the number of second line segments. The calculation strategy includes using a density interval algorithm to extract concentrated angles when the number of second line segments is greater than a first preset number; calculating the average angle of the second line segments when the number of second line segments is between the first preset number and the second preset number; and calculating the weighted average angle of the second line segments based on length weighting when the number of second line segments is less than the second preset number.
6. The automatic image correction method according to claim 5, characterized in that, The steps for extracting concentrated angles using the density interval algorithm include: Set an initial interval width and control the initial interval width to gradually decrease to obtain the width of each interval; Obtain the angle of the second line segment, form an angle set, control the width of each interval to slide in the angle set, and count the number of angles contained in each interval width; Based on the number of angles, determine the target interval width with the largest number of line segments and the smallest interval width span, and calculate the average angle within the target interval width to obtain the horizontal tilt angle.
7. An automatic image correction system, characterized in that, The system for implementing the automatic image correction method as described in any one of claims 1-6 includes: An acquisition module is used to acquire an image and preprocess the image to remove noise and background interference, while enhancing line features to obtain the image to be detected. The recognition module is used to recognize vertical and horizontal line segments in the image to be detected, and to calculate the vertical tilt angle and horizontal tilt angle of the image to be detected based on the vertical and horizontal line segments. The judgment module is used to determine whether the vertical tilt angle and the horizontal tilt angle are less than a preset angle; The rotation module is used to rotate the image to be detected when the vertical tilt angle and the horizontal tilt angle are both less than a preset angle, so as to obtain a rotated image.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the automatic image correction method as described in any one of claims 1-6.
9. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the program to implement the automatic image correction method as described in any one of claims 1-6.
Citation Information
Patent Citations
Text image tilt correction method, system and device and storage medium
CN111553344A
Image calibration method and device, storage medium and electronic equipment
CN111899240A