Text processing method, device and equipment
By determining the target angle range and average direction of text lines in text images, the problem of inconsistent direction of text blocks and text lines is solved, achieving a better visual experience.
Patent Information
- Application Number
- CN202310962507.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-31
- Publication Date
- 2025-02-14
AI Technical Summary
In the prior art, the direction of the text block surrounding the text line is inconsistent with the direction of the text line, which affects the user's visual experience.
By obtaining text line information of text image, including text line direction, length and vertex coordinates, determine the target angle range to minimize the angle variance, and then determine the average direction of text line based on the text line angle within the target angle range, and finally according to the average direction and vertex coordinates determine the orientation of the text block.
Ensure that the direction of the text block is consistent with the direction of the text line, improve the user's visual experience, and solve the problem of inconsistent direction of the text block.
Smart Images

Figure CN119445586A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and more specifically, to a text processing method, device and equipment. Background Art
[0002] Currently, in the process of recognizing text content in a text image, it is necessary to use a text block to frame a text line area corresponding to the text content in the text image, and then recognize the text content in a certain order in the text line area framed by the text block.
[0003] In traditional technology, the text block surrounding the text line is determined based on the coordinate information of the text line in the text image. However, the text blocks obtained after processing the text images obtained in some scenes based on this method have the following problems: the direction of the text block surrounding the text line is inconsistent with the direction of the text line, thereby affecting the user's visual experience.
[0004] Therefore, there is an urgent need to provide a text processing method to solve the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line. Summary of the invention
[0005] The present application provides a text processing method, apparatus and device, which can solve the technical problem that the direction of a text block surrounding a text line is inconsistent with the direction of the text line.
[0006] In a first aspect, a text processing method is provided, the method comprising: acquiring text line information of a text image, wherein the text line information comprises N text line directions of N text lines, N text line lengths of the N text lines and multiple text line vertex coordinates of the N text lines, and N is a positive integer; determining a target angle range of the N text lines from multiple angle ranges according to the N text line directions and the N text line lengths, wherein an angle variance corresponding to the target angle range is a minimum angle variance among multiple angle variances corresponding to the multiple angle ranges, and the angle variance corresponding to each angle range is used to represent the difference between each text line angle of the N text line angles corresponding to the N text lines within each angle range and an expected angle of the N text lines within each angle range. The sum of deviations, each text line angle being the angle between the text line direction of the corresponding text line and a preset direction, and the expected angle of the N text lines within each angle range is obtained based on the N text line lengths and the N text line angles; determining the average direction of the N text lines according to the N target text line angles corresponding to the N text lines within the target angle range, wherein each target text line angle is the angle between the text line direction of the corresponding text line and the preset direction; determining a text block surrounding the N text lines according to the average direction of the N text lines and the multiple text line vertex coordinates of the N text lines, wherein the text block includes two sides parallel to the average direction, and two sides parallel to a first direction perpendicular to the average direction.
[0007] In the above implementation, the angle variance corresponding to each angle range is used to represent the sum of the deviations between the angle of each text line in the N text line angles corresponding to the N text lines in each angle range and the expected angle of the N text lines in each angle range, and the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges. In other words, the average angle of the N text lines determined based on the N target text line angles corresponding to the N text lines in the target angle range is more consistent with the actual situation of the N text lines than the average angle of the N text lines determined based on the N text line angles corresponding to the N text lines in any angle range other than the target angle range in the multiple angle ranges.
[0008] In the above technical solution, the average direction of the N text lines is determined according to the N target text line angles corresponding to the N text lines within the target angle range, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, so that the average direction of the N text lines obtained is kept consistent with the overall direction of the N text lines as much as possible. Thereafter, the electronic device determines the direction of the text block surrounding the N text lines according to the average direction and the multiple text line vertex coordinates of the N text lines, so that the direction of the text block obtained can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line.
[0009] In some implementations, determining the average direction of the N lines of text based on N target text line angles corresponding to the N lines of text within the target angle range includes: determining the average angle of the N lines of text within the target angle range based on the N target text line angles; determining the average direction of the N lines of text based on the average angle, wherein the angle between the average direction of the N lines of text and the preset direction is the average angle.
[0010] In the above technical solution, the average direction of N lines of text is determined based on the N target text line angles corresponding to the N lines of text within the target angle range, wherein the angle variance corresponding to the target angle range is the smallest angle variance among multiple angle variances corresponding to multiple angle ranges, so that the average direction of the N lines of text is kept consistent with the overall direction of the N lines of text as much as possible.
[0011] In other implementations, determining the average angle of the N text lines within the target angle range based on the N target text line angles includes: determining whether the N text lines are all normal text lines based on the N target text line angles; when the N text lines are all normal text lines, determining the expected angle of the N text lines within the target angle range as the average angle; or, when at least one text line among the N text lines is an abnormal text line, determining the expected angle of the remaining text lines in the N text lines except the at least one text line within the target angle range as the average angle, wherein the expected angle of the remaining text lines within the target angle range is obtained based on the text line lengths of the remaining text lines among the N text line lengths and the text line angles of the remaining text lines within the target angle range.
[0012] It should be understood that one of the N lines of text lines is an abnormal text line, which means that the text line angle of one of the N lines of text lines is significantly different from the text line angle of any of the remaining text lines in the N lines of text lines. One of the N lines of text lines is a normal text line, which means that the text line angle of one of the N lines of text lines is significantly different from the text line angle of any of the remaining text lines in the N lines of text lines.
[0013] In the above technical solution, the average angle of the N text lines within the target angle range is determined based on the target text line angle corresponding to the normal text lines in the N text lines. In this way, the influence of the target text line angle of the abnormal text line on the average angle of the N text lines can be avoided, so that the determined average angle is more consistent with the overall situation of the N text lines. Thereafter, the direction of the text block surrounding the N text lines is determined based on the average direction determined by the average angle and the coordinates of multiple text line vertices of the N text lines. In this way, the direction of the obtained text block can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line.
[0014] In other implementations, determining whether the N lines of text are all normal text lines based on the N target text line angles includes: mapping each target text line angle among the N target text line angles to a normal distribution whose mean is the expected angle of the N lines of text within the target angle range and whose standard deviation is the arithmetic square root of the angle variance corresponding to the target angle range, so as to obtain N standardized results for the N target text line angles; determining that the N lines of text are all normal text lines when the absolute values of the N standardized results do not exceed a first preset threshold; determining that at least one line of text among the N lines of text is the abnormal text line when the absolute value of the standardized result corresponding to at least one line of text among the N standardized results exceeds the first preset threshold, and the absolute values of the standardized results corresponding to the remaining text lines among the N standardized results do not exceed the first preset threshold.
[0015] In the above technical solution, the N target text line angles of N text lines are standardized, and the absolute values of the N standardized results of the N target text line angles are compared with the size of the first preset threshold value to determine whether the text line corresponding to any target text line angle is a normal text line. The result obtained in this way is more accurate, which is conducive to making the subsequent average angle of the N text lines within the target angle range more accurate. Thereafter, the direction of the text block surrounding the N text lines is determined based on the average direction determined by the average angle and the coordinates of multiple text line vertices of the N text lines. In this way, the direction of the obtained text block can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line.
[0016] In other implementations, determining whether the N lines of text are all normal text lines based on the N target text line angles includes: determining that the N lines of text are all normal text lines when the absolute value of the difference between any target text line angle among the N target text line angles and the expected angle of the N lines of text within the target angle range does not exceed a second preset threshold; determining that at least one line of text among the N lines of text is an abnormal text line when the absolute value of the difference between the target text line angle corresponding to at least one line of text among the N target text line angles and the expected angle of the N lines of text within the target angle range exceeds the second preset threshold, and the absolute value of the difference between the target text line angle corresponding to any text line among the remaining text lines among the N target text line angles and the expected angle of the N lines of text within the target angle range does not exceed the second preset threshold.
[0017] In the above technical solution, by comparing the absolute value of the difference between the angle of any target text line and the expected angle of N text lines within the target angle range and the size of the second preset threshold, it is determined whether the text line corresponding to any target text line angle is a normal text line. This determination method is relatively simple.
[0018] In some other implementations, determining a text block surrounding the N lines of text lines based on the average direction of the N lines of text lines and the multiple text line vertex coordinates of the N lines of text lines includes: obtaining a plurality of first candidate lines and a plurality of second candidate lines based on the average direction and the multiple text line vertex coordinates, wherein the plurality of first candidate lines and the plurality of second candidate lines correspond one-to-one to the multiple text line vertex coordinates, each first candidate line is a straight line passing through the corresponding text line vertex coordinates and parallel to the average direction, and each second candidate line is a straight line passing through the corresponding text line vertex coordinates and perpendicular to the first direction of the average direction; determining a plurality of first candidate intersections based on the plurality of first candidate lines and the straight lines along the second direction perpendicular to the preset direction, and placing the plurality of first candidate lines at the intersection of the first and second candidate lines. A first candidate line corresponding to a first candidate intersection having the largest coordinate value along the second direction among the intersections is determined as a first boundary line, and a first candidate line corresponding to a first candidate intersection having the smallest coordinate value along the second direction among the multiple first candidate intersections is determined as a second boundary line; multiple second candidate intersections are determined based on the multiple second candidate lines and the straight line along the preset direction, and a second candidate line corresponding to a second candidate intersection having the largest coordinate value along the preset direction among the multiple second candidate intersections is determined as a third boundary line, and a second candidate line corresponding to a second candidate intersection having the smallest coordinate value along the preset direction among the multiple second candidate intersections is determined as a fourth boundary line; the text block is determined based on the first boundary line, the second boundary line, the third boundary line and the fourth boundary line.
[0019] In the above technical scheme, a text block including N text lines is determined based on the average direction and the coordinates of multiple text line vertices of the N text lines. In this way, the direction of the obtained text block can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text lines is inconsistent with the direction of the text lines.
[0020] In other implementations, determining the text block based on the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line includes: determining a square frame formed by the intersection of the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line as the text block.
[0021] It should be understood that the above method of determining the text block according to the first boundary line, the second boundary line, the third boundary line and the fourth boundary line is only for illustration and does not constitute any limitation to the present application. That is, the electronic device may determine the text block according to the first boundary line, the second boundary line, the third boundary line and the fourth boundary line, or may use other methods to determine the text block.
[0022] In the above technical solution, the square frame formed by the intersection of the first boundary line, the second boundary line, the third boundary line and the fourth boundary line is determined as a text block. In this way, not only can the technical problem of the inconsistency between the direction of the text block including the text line and the direction of the text line be solved, but also the area of the text block surrounding the text line can be ensured to be as small as possible.
[0023] In other implementations, the angular variance corresponding to each angular range is a weighted variance determined by taking each text line angle among the N text line angles corresponding to the N lines of text within each angular range as a variable and the expected angle of the N lines of text within each angular range as the mean, wherein the weight of each text line angle used to determine the weighted variance is the ratio of the text line length of the corresponding text line to the N text line lengths, or the weight of each text line angle used to determine the weighted variance is 1.
[0024] In the above technical solution, the angle variance corresponding to each angle range is a weighted variance determined based on the N text line angles corresponding to the N text lines in each angle range as a variable and the expected angle of the N text lines in each angle range as the mean, so that the result of the angle variance corresponding to each angle range is more accurate, and the target angle range determined based on the angle variances corresponding to multiple angle ranges is more accurate. Furthermore, the average direction of the N text lines determined based on the N target text line angles corresponding to the N text lines in the target angle range is also more consistent with the overall direction of the N text lines. Thereafter, the direction of the text block surrounding the N text lines is determined based on the average direction and the coordinates of the multiple text line vertices of the N text lines. In this way, the direction of the obtained text block can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text lines is inconsistent with the direction of the text lines.
[0025] In other implementations, the expected angle of the N lines of text within each angle range is a weighted average determined based on the N text line angles corresponding to the N lines of text within each angle range, wherein the weight of each text line angle used to determine the weighted average is the ratio of the text line length of the corresponding text line to the lengths of the N text lines.
[0026] In the above technical solution, the text line length of each text line is taken into account when determining the expected angle of N text lines in each angle range (i.e., the weight of each text line angle used to determine the weighted average is the ratio of the text line length of the corresponding text line to the length of N text lines), so that the expected angle of the N text lines in each angle range is more accurate, and the angle variance determined based on the expected angle of the N text lines in each angle range is more accurate, so that the determined target angle range is the optimal angle range among multiple angle ranges, thereby making the average angle determined based on the weighted average more accurate. Thereafter, the direction of the text block surrounding the N text lines is determined based on the average direction determined by the average angle and the multiple text line vertex coordinates of the N text lines. In this way, the direction of the obtained text block can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line.
[0027] In other implementations, the method of obtaining text line information of a text image includes: clustering the N text lines according to N text line position information of the N text lines to determine that the N text lines belong to the same category; and when the N text lines belong to the same category, obtaining the text line information from the text image.
[0028] In some other implementations, the multiple angle ranges include an angle range of 0° to 180° and an angle range of -90° to 90°.
[0029] It should be understood that the multiple angle ranges in the above implementation are only for illustration and do not constitute any limitation to the multiple angle ranges.
[0030] In a second aspect, a text processing device is provided, which includes a processing unit, wherein the processing unit is used to: obtain text line information of a text image, wherein the text line information includes N text line directions of N text lines, N text line lengths of the N text lines and multiple text line vertex coordinates of the N text lines, and N is a positive integer; determine a target angle range of the N text lines from multiple angle ranges according to the N text line directions and the N text line lengths, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, and the angle variance corresponding to each angle range is used to represent the difference between each text line angle of the N text line angles corresponding to the N text lines in each angle range and the angle variance of the N text lines in each angle range. The sum of deviations of expected angles within a range, each text line angle being the angle between the text line direction of the corresponding text line and a preset direction, and the expected angles of the N text lines within each angle range are obtained based on the N text line lengths and the N text line angles; determining an average direction of the N text lines according to N target text line angles corresponding to the N text lines within the target angle range, wherein each target text line angle is the angle between the text line direction of the corresponding text line and the preset direction; determining a text block surrounding the N text lines according to the average direction of the N text lines and the multiple text line vertex coordinates of the N text lines, wherein the text block includes two sides parallel to the average direction, and two sides parallel to a first direction perpendicular to the average direction.
[0031] In some implementations, the processing unit is also used to: determine the average angle of the N lines of text within the target angle range based on the N target text line angles; determine the average direction of the N lines of text based on the average angle, wherein the angle between the average direction of the N lines of text and the preset direction is the average angle.
[0032] In other implementations, the processing unit is also used to: determine whether the N text lines are all normal text lines based on the N target text line angles; when the N text lines are all normal text lines, determine the expected angle of the N text lines within the target angle range as the average angle; or, when at least one text line among the N text lines is an abnormal text line, determine the expected angle of the remaining text lines in the N text lines except the at least one text line within the target angle range as the average angle, wherein the expected angle of the remaining text lines within the target angle range is obtained based on the text line lengths of the remaining text lines among the N text line lengths and the text line angles of the remaining text lines within the target angle range.
[0033] In other implementations, the processing unit is also used to: map each target text line angle among the N target text line angles to a normal distribution whose mean is the expected angle of the N text lines within the target angle range and whose standard deviation is the arithmetic square root of the angle variance corresponding to the target angle range, so as to obtain N standardized results for the N target text line angles; determine that the N text lines are all normal text lines when the absolute values of the N standardized results do not exceed a first preset threshold; and determine that at least one text line among the N text lines is the abnormal text line when the absolute value of the standardized result corresponding to at least one text line among the N standardized results exceeds the first preset threshold, and the absolute values of the standardized results corresponding to the remaining text lines among the N standardized results do not exceed the first preset threshold.
[0034] In other implementations, the processing unit is also used to: determine that the N lines of text are all normal text lines when the absolute value of the difference between any target text line angle among the N target text line angles and the expected angle of the N lines of text within the target angle range does not exceed a second preset threshold; determine that at least one line of text among the N lines of text is the abnormal text line when the absolute value of the difference between the target text line angle corresponding to at least one line of text among the N target text line angles and the expected angle of the N lines of text within the target angle range exceeds the second preset threshold, and the absolute value of the difference between the target text line angle corresponding to any text line among the remaining text lines among the N target text line angles and the expected angle of the N lines of text within the target angle range does not exceed the second preset threshold.
[0035] In some other implementations, the processing unit is also used to: obtain a plurality of first candidate lines and a plurality of second candidate lines according to the average direction and the plurality of text line vertex coordinates, wherein the plurality of first candidate lines and the plurality of second candidate lines correspond one-to-one to the plurality of text line vertex coordinates, each first candidate line is a straight line passing through the corresponding text line vertex coordinates and parallel to the average direction, and each second candidate line is a straight line passing through the corresponding text line vertex coordinates and perpendicular to the first direction of the average direction; determine a plurality of first candidate intersections according to the plurality of first candidate lines and the straight line along the second direction perpendicular to the preset direction, and select the first candidate intersection with the largest coordinate value along the second direction among the plurality of first candidate intersections The first candidate line corresponding to the point is determined as the first boundary line, and the first candidate line corresponding to the first candidate intersection with the smallest coordinate value along the second direction among the multiple first candidate intersections is determined as the second boundary line; multiple second candidate intersections are determined according to the multiple second candidate lines and the straight line along the preset direction, and the second candidate line corresponding to the second candidate intersection with the largest coordinate value along the preset direction among the multiple second candidate intersections is determined as the third boundary line, and the second candidate line corresponding to the second candidate intersection with the smallest coordinate value along the preset direction among the multiple second candidate intersections is determined as the fourth boundary line; the text block is determined according to the first boundary line, the second boundary line, the third boundary line and the fourth boundary line.
[0036] In some other implementations, the processing unit is further configured to: determine a square frame formed by the intersection of the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line as the text block.
[0037] In other implementations, the angular variance corresponding to each angular range is a weighted variance determined by taking each text line angle among the N text line angles corresponding to the N lines of text within each angular range as a variable and the expected angle of the N lines of text within each angular range as the mean, wherein the weight of each text line angle used to determine the weighted variance is the ratio of the text line length of the corresponding text line to the N text line lengths, or the weight of each text line angle used to determine the weighted variance is 1.
[0038] In other implementations, the expected angle of the N lines of text within each angle range is a weighted average determined based on the N text line angles corresponding to the N lines of text within each angle range, wherein the weight of each text line angle used to determine the weighted average is the ratio of the text line length of the corresponding text line to the lengths of the N text lines.
[0039] In other implementations, the processing unit is also used to: cluster the N text lines according to N text line position information of the N text lines to determine that the N text lines belong to the same category; and when the N text lines belong to the same category, obtain the text line information from the text image.
[0040] In some other implementations, the multiple angle ranges include an angle range of 0° to 180° and an angle range of -90° to 90°.
[0041] It should be understood that the beneficial effects of the above-mentioned second aspect can be referred to the corresponding beneficial effects of the first aspect above, and will not be described in detail here.
[0042] In a third aspect, an electronic device is provided, comprising a unit for executing any one of the text processing methods in the first aspect. The device may be a terminal device or a chip in a terminal device. The device may include an input unit and a processing unit.
[0043] When the device is a terminal device, the processing unit may be a processor, and the input unit may be a communication interface; the terminal device may also include a memory, which is used to store computer program code. When the processor executes the computer program code stored in the memory, the terminal device executes any one of the text processing methods in the first aspect.
[0044] When the device is a chip in a terminal device, the processing unit may be a processing unit inside the chip, and the input unit may be an output interface, a pin or a circuit, etc.; the chip may also include a memory, which may be a memory inside the chip (for example, a register, a cache, etc.) or a memory located outside the chip (for example, a read-only memory, a random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes any one of the text processing methods in the first aspect.
[0045] In one possible implementation, a memory is used to store computer program code; a processor executes the computer program code stored in the memory, and when the computer program code stored in the memory is executed, the processor is used to execute any one of the text processing methods in the first aspect.
[0046] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code. When the computer program code is executed by a text processing device, the text processing device executes any one of the text processing methods in the first aspect.
[0047] In a fifth aspect, a computer program product is provided, the computer program product comprising: a computer program code, when the computer program code is executed by a text processing device, the text processing device executes any one of the text processing methods in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 is a schematic diagram of a text block generated based on traditional techniques.
[0049] Figure 2 is a schematic diagram of a text block generated based on traditional techniques.
[0050] Figure 3 It is a schematic diagram of the hardware system of the electronic device 100 provided in an embodiment of the present application.
[0051] Figure 4 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.
[0052] Figure 5A It is a schematic diagram of the desktop of the mobile phone 1 executing the text processing method provided in the embodiment of the present application.
[0053] Figure 5B It is a schematic diagram of the desktop of the mobile phone 1 executing the text processing method provided in the embodiment of the present application.
[0054] Figure 6 It is a schematic diagram of a text processing method provided in an embodiment of the present application.
[0055] Figure 7 yes Figure 6 Schematic diagram of the text line direction and preset direction described in .
[0056] Figure 8 yes Figure 6 Schematic diagram of the text line angles in each angle range for the N text lines described in .
[0057] Fig. 9 yes Figure 6 Schematic diagram of the text line angles in each angle range for the N text lines described in .
[0058] Fig.10 yes Figure 6 Schematic diagram of the text line angles in each angle range for the N text lines described in .
[0059] Fig.11 yes Figure 6 A schematic diagram in which at least one of the N text lines described in the figure is an abnormal text line.
[0060] Fig.12 yes Figure 6A schematic diagram of an electronic device described in the text block determining a text block according to a first boundary line, a second boundary line, a third boundary line and a fourth boundary line.
[0061] Fig.13 It is a schematic diagram of another text processing method provided in an embodiment of the present application.
[0062] Fig.14 yes Fig.13 Schematic diagram of the original text image, text image, and text block described in the provided text processing method.
[0063] Fig.15 yes Fig.13 Schematic diagram of the original text image, text image, and text block described in the provided text processing method.
[0064] Fig.16 Electronic devices perform Fig.13 A schematic diagram of the S1360 is shown.
[0065] Fig.17 It is a schematic diagram of a text processing device provided in an embodiment of the present application.
[0066] Fig.18 It is a schematic diagram of the structure of an electronic device provided by the present application. DETAILED DESCRIPTION
[0067] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0068] Currently, in the process of recognizing text content in a text image, it is necessary to use a text block to frame a text line area corresponding to the text content in the text image, and then recognize the text content in a certain order in the text line area framed by the text block.
[0069] In the conventional technology, the text block surrounding the text line is determined based on the coordinate information of the text line in the text image. In order to minimize the area of the obtained text block surrounding the text line, the text block obtained after processing the text image based on this method has the following problems: the direction of the text block surrounding the text line is inconsistent with the direction of the text line. For example, in some scenes, the text image obtained is Figure 1 The text image shown in (1) in FIG. 1 , that is, the directions of the multiple text lines included in the text image (that is, the directions of reading the text lines) are all the same. Figure 1 The text block obtained after the text image processing shown in (1) is as follows Figure 1 The text block shown in (2) is Figure 1 The direction of the text block enclosing the multiple text lines shown in (2) is inconsistent with the direction of the multiple text lines. For another example, in some scenes, the text image obtained is as follows Figure 2 The text image shown in (1) in FIG. 1 , i.e., the text line image includes multiple text lines whose directions are not completely the same. Figure 2 The text block obtained after the text image processing shown in (1) is as follows Figure 2 The text block shown in (2) is Figure 2 The direction of the text block surrounding the multiple text lines shown in (2) is inconsistent with the direction of the multiple text lines.
[0070] In order to solve the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line, the present application provides a text processing method, device and equipment. The text processing method provided by the present application includes: obtaining text line information of a text image, wherein the text line information includes N text line directions of N text lines, N text line lengths of N text lines and multiple text line vertex coordinates of N text lines, and N is a positive integer; according to the N text line directions and the N text line lengths, determining the target angle range of the N text lines from multiple angle ranges, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, and the angle variance corresponding to each angle range is used to represent the difference between each text line angle of the N text line angles corresponding to the N text lines in each angle range and the expected angle of the N text lines in each angle range. The sum of deviations, each text line angle is the angle between the text line direction of the corresponding text line and a preset direction, and the expected angle of N text lines in each angle range is obtained based on N text line lengths and N text line angles; according to N target text line angles corresponding to the N text lines in the target angle range, the average direction of the N text lines is determined, wherein each target text line angle is the angle between the text line direction of the corresponding text line and a preset direction; according to the average direction of the N text lines and multiple text line vertex coordinates of the N text lines, a text block surrounding the N text lines is determined, wherein the text block includes two sides parallel to the average direction, and two sides parallel to a first direction perpendicular to the average direction.
[0071] In the above technical solution, the average direction of the N text lines is determined according to the N target text line angles corresponding to the N text lines within the target angle range, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, so that the average direction of the N text lines obtained is kept consistent with the overall direction of the N text lines as much as possible. Thereafter, the electronic device determines the direction of the text block surrounding the N text lines according to the average direction and the multiple text line vertex coordinates of the N text lines, so that the direction of the text block obtained can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line.
[0072] The following is a detailed introduction to the technical solution of the text processing method provided by this application.
[0073] The text processing method provided in the embodiment of the present application can be applied to electronic devices. For example, the electronic device can be, but is not limited to, a mobile phone, a tablet computer, a wearable device, a laptop computer, a netbook, a personal digital assistant (PDA), and other electronic devices capable of network communication. The hardware structure and software structure of the electronic device are described in detail below in conjunction with the accompanying drawings.
[0074] Figure 3 1 is a schematic diagram of the structure of the electronic device 100 provided in an embodiment of the present application. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0075] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0076] The processor 110 may perform the text processing method provided in the present application on the acquired table image. The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural-network processing unit (neural-network processing unit, NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.
[0077] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0078] A memory may also be provided in the processor 110 for storing instructions and data. When the processor 110 executes instructions on the data stored in the memory, the processor 110 executes the text processing method provided in the present application. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or circulated. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. Repeated access is avoided, the waiting time of the processor 110 is reduced, and the efficiency of the system is improved.
[0079] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0080] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface, thereby realizing the touch function of the electronic device 100.
[0081] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to achieve communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 via the I2S interface to achieve the function of answering a call through a Bluetooth headset.
[0082] The PCM interface can also be used for audio communication, sampling, quantizing and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface to realize the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0083] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.
[0084] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to implement the shooting function of the electronic device 100. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the electronic device 100.
[0085] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0086] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and a peripheral device. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other electronic devices, such as AR devices, etc.
[0087] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0088] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device through the power management module 141.
[0089] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.
[0090] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0091] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0092] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0093] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.
[0094] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0095] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).
[0096] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0097] The display screen 194 is used to display images (for example, text blocks obtained by executing the text processing method provided in the present application), videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0098] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
[0099] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.
[0100] The camera 193 is used to capture static images (e.g., table images) or videos (e.g., videos including table images). The object generates an optical image through the lens and is projected onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0101] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0102] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0103] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.
[0104] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0105] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (sound playback function, image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0106] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0107] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0108] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.
[0109] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.
[0110] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to microphone 170C to input the sound signal into microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify the sound source, realize directional recording function, etc.
[0111] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.
[0112] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
[0113] The gyro sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyro sensor 180B. The gyro sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyro sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyro sensor 180B can also be used for navigation and somatosensory game scenes.
[0114] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.
[0115] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. Then, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, the flip cover can be automatically unlocked.
[0116] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in all directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.
[0117] The distance sensor 180F is used to measure the distance. The electronic device 100 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 100 can use the distance sensor 180F to measure the distance to achieve fast focusing.
[0118] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device 100 emits infrared light outward through the light emitting diode. The electronic device 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100. The electronic device 100 can use the proximity light sensor 180G to detect that the user holds the electronic device 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used in leather case mode and pocket mode to automatically unlock and lock the screen.
[0119] The ambient light sensor 180L is used to sense the ambient light brightness. The electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.
[0120] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
[0121] The temperature sensor 180J is used to detect temperature. In some embodiments, the electronic device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the electronic device 100 reduces the performance of a processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to avoid abnormal shutdown of the electronic device 100 due to low temperature. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 performs a boost on the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperature.
[0122] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0123] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone block of the vocal part of the human body. The bone conduction sensor 180M can also contact the human pulse to receive a blood pressure beat signal. In some embodiments, the bone conduction sensor 180M can also be set in an earphone and combined into a bone conduction earphone. The audio module 170 can parse out a voice signal based on the vibration signal of the vibrating bone block of the vocal part obtained by the bone conduction sensor 180M to realize a voice function. The application processor can parse the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 180M to realize a heart rate detection function.
[0124] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0125] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (such as time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0126] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.
[0127] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.
[0128] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.
[0129] Figure 4 1 is a software structure diagram of the electronic device 100 of the embodiment of the present application. The layered architecture divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the system library of the Android runtime (Android runtime), and the kernel layer. The application layer can include a series of application packages.
[0130] like Figure 4 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
[0131] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0132] like Figure 4 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0133] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0134] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0135] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0136] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0137] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0138] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0139] Android runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0140] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0141] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0142] The system library may include multiple functional modules, such as surface manager, media libraries, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0143] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0144] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0145] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0146] A 2D graphics engine is a drawing engine for 2D drawings.
[0147] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0148] It should be understood that the technical solutions in the embodiments of the present application can be used in Android, IOS, Hongmeng and other systems.
[0149] Next, taking the above-mentioned electronic device 100 as a mobile phone 1 as an example, the desktop of the mobile phone 1 executing the text processing method provided in the embodiment of the present application is described.
[0150] Figure 5A It is a schematic diagram of the desktop of the mobile phone 1 executing the text processing method provided in the embodiment of the present application.
[0151] See also Figure 5A The desktop 510 is shown to include icons of a plurality of applications including an icon 511 of a memo application.
[0152] When the mobile phone 1 detects that the user clicks the icon 511 of the memo application on the desktop 510, the memo application can be started and the display will be as follows: Figure 5A The memo interface 520 is shown. The memo interface 520 may include a picture icon 521, a return control 522, and a storage control 523.
[0153] When the mobile phone 1 detects that the user clicks the picture icon 521 on the memo interface 520, the function control associated with the picture icon 521 can be displayed, such as Figure 5AThe memo interface 530 is shown. The memo interface 530 may include a photo control 531 associated with the picture icon 521, a text scanning control 532, a card collection control 533, and a select from gallery control 534.
[0154] If the user needs to identify the text content in the text image, the user can click the text scanning control 532. When the mobile phone 1 detects that the text scanning control 532 is in the selected state, the text scanning control 532 executes the text processing method provided by the present application on the text in the scanned text image, and the following can be obtained: Figure 5A The memo interface 540 shown in FIG. 5 includes a text area 541, a text image 542, and a text block 543 surrounding multiple text lines in the text image 542, wherein the direction of the text block 543 is consistent with the direction of the multiple text lines in the text image 542 surrounded by the text block 561. Figure 5A The memo interface 540 shown may also be Figure 5B Memo interface 540 is shown.
[0155] It should be understood that the above Figure 5A and Figure 5B The schematic diagram of the desktop of the mobile phone 1 is for illustration only and does not constitute any limitation on the desktop of the electronic device that executes the text processing method provided in the embodiment of the present application.
[0156] Next, combine Figures 6 to 16 The text processing method provided in the embodiment of the present application is introduced in detail.
[0157] Figure 6 is a schematic diagram of a text processing method provided in an embodiment of the present application. The text processing method provided in an embodiment of the present application can be executed by an electronic device. It is understood that the electronic device can be implemented as software, or a combination of software and hardware. Exemplarily, the electronic device that executes the text processing method provided in an embodiment of the present application can be, but is not limited to, Figure 3 The electronic device 100 is shown. Figure 6 As shown, the text processing method provided in the embodiment of the present application includes S610 to S640.
[0158] In step S610, the electronic device obtains text line information of the text image, wherein the text line information includes N text line directions of N text lines, N text line lengths of N text lines and multiple text line vertex coordinates of N text lines, and N is a positive integer.
[0159] In the embodiment of the present application, the text image is an image including N lines of text lines, and optionally, the text image may also include text lines other than the N lines of text lines. It is understandable that, in the case where the text image includes N lines of text lines and text lines other than the N lines of text lines, the text line information refers to the information of the N lines of text lines in the text image, that is, the text line information includes N text line directions of the N lines of text lines, N text line lengths of the N lines of text lines, and multiple text line vertex coordinates of the N lines of text lines.
[0160] There is no specific limitation on the shape of each text line in the N text lines, and there is no specific limitation on the value of N. For example, the text image can be Figure 1 The text image shown in (1) or Figure 2 The text image shown in (1) in FIG.
[0161] In the embodiment of the present application, N text lines correspond to N text line directions one by one, wherein each text line direction in the N text lines is an extension direction of each corresponding text line. It can be understood that the extension direction of each text line refers to the reading direction of each text line.
[0162] For example, Figure 7 Taking the tilted text line shown as an example, the reading direction of the tilted text line is the direction indicated by the tilted straight line arrow, and therefore, the text line direction of the tilted text line is the direction indicated by the tilted straight line arrow.
[0163] For example, Figure 7 The horizontal text line shown is an example, wherein the horizontal text line refers to Figure 7 The text line shown is parallel to the horizontal direction. The reading direction of the horizontal text line is the direction indicated by the straight arrow parallel to the horizontal direction. Therefore, the text line direction of the horizontal text line is the direction indicated by the straight arrow parallel to the horizontal direction.
[0164] For example, Figure 7 The vertical text line shown is an example, wherein the vertical text line refers to a vertical Figure 7 The horizontal text line shown, the reading direction of the vertical text line is the direction indicated by the straight arrow perpendicular to the horizontal direction, therefore, the text line direction of the vertical text line is the direction indicated by the straight arrow perpendicular to the horizontal direction.
[0165] In an embodiment of the present application, the multiple vertex coordinates of N text lines include the vertex coordinates of each text line in the N text lines. The text line vertex coordinates of each text line may at least include the upper left vertex coordinates of each text line, the lower left vertex coordinates of each text line, the upper right vertex coordinates of each text line, and the lower right vertex coordinates of each text line. Optionally, the text line vertex coordinates of each text line may also include the coordinates of other points on the straight line constituting each text line.
[0166] In the embodiment of the present application, N text lines correspond to N text line lengths one by one, that is, the length of each text line can be determined according to the text line vertex coordinates of the corresponding text line. For example, the text line vertex coordinates of a text line are respectively expressed as (x1, y2), (x2, y2), (x1, y1), (x2, y1), where x2 is greater than x1, and y2 is greater than y1. Therefore, the text line length of the text line is the difference between x2 and x1.
[0167] In practical applications, the content of different regions in a text image is usually recognized in the form of blocks. In this way, the content in each region is recognized, which is conducive to improving the accuracy of the recognition result. Therefore, before recognizing the content in a text image, it is necessary to divide the content in the text image into regions to obtain the text line information of the text content in the corresponding region.
[0168] Next, based on the above recognition principle, the method for obtaining text line information of a text image by an electronic device provided in an embodiment of the present application is introduced. It should be understood that the method for obtaining text line information by an electronic device described below is only for illustration and does not constitute any limitation to the embodiment of the present application.
[0169] In some implementations, the electronic device executes obtaining text line information of a text image, including: the electronic device clusters N text lines according to N text line position information of the N text lines, and determines that the N text lines belong to the same category; when the N text lines belong to the same category, the electronic device obtains the text line information from the text image.
[0170] In other implementations, the electronic device executes obtaining text line information of a text image, including: the electronic device determines that N lines of text in the text image belong to the same category based on marking information recorded in the electronic device; when the N lines of text belong to the same category, the electronic device obtains the text line information from the text image.
[0171] In the above-mentioned step of the electronic device acquiring text line information, the text image may be a text binary image including N text lines, and the N text line position information of the N text lines may be acquired from the text binary image. For example, in the text binary image, the pixel value of each text line in the N text lines is "1", and the pixel value of the background of the text binary image is "0". For another example, in the text binary image, the pixel value of each text line in the N text lines is "0", and the pixel value of the background of the text binary image is "1". In the above-mentioned step, the electronic device acquires the text line information from the text image, which may be the electronic device acquiring the text line information from the text binary image.
[0172] In the above step of the electronic device acquiring text line information, if the text image is a non-binary image including N text lines, the electronic device may further perform a binarization process on the text image to obtain a text binary image.
[0173] The clustering algorithm used by the electronic device in the above steps is not specifically limited and can be selected according to actual conditions. For example, the clustering algorithm can be but is not limited to any of the following algorithms: K-means clustering algorithm, hierarchical clustering algorithm, support vector machine classification algorithm or classification algorithm based on deep learning.
[0174] In step S620, the electronic device determines a target angle range for N lines of text from multiple angle ranges based on N text line directions and N text line lengths, wherein the angle variance corresponding to the target angle range is the smallest angle variance among multiple angle variances corresponding to the multiple angle ranges, and the angle variance corresponding to each angle range is used to represent the sum of deviations between each text line angle of the N text line angles corresponding to the N lines of text in each angle range and the expected angle of the N lines of text in each angle range, each text line angle is the angle between the text line direction of the corresponding text line and a preset direction, and the expected angle of the N lines of text in each angle range is obtained based on the N text line lengths and the N text line angles.
[0175] In the embodiment of the present application, N text lines correspond to N text line angles in each angle range of multiple angle ranges, wherein the N text lines correspond to the N text line angles one by one, and each text line angle is the angle between the text line direction of each corresponding text line and a preset direction. It can be understood that the text line angle corresponding to each text line in each angle range does not exceed the maximum angle in each angle range.
[0176] In some implementations, it is specified that the angle obtained by rotating counterclockwise from the preset direction to the text line direction of each text line is a positive angle, and the angle obtained by rotating clockwise from the preset direction to the text line direction of each text line is a negative angle. It should also be understood that the angle obtained by rotating from the preset direction to the text line direction without any rotation is a zero angle. Figure 8 Taking the text line shown as an example, the angle obtained by rotating counterclockwise from the preset direction to the text line direction is 45° (i.e. a positive angle), and the angle obtained by rotating clockwise from the preset direction to the text line direction is -135° (i.e. a negative angle).
[0177] In other implementations, it is specified that the angle obtained by rotating clockwise from the preset direction to the text line direction of each text line is a positive angle, and the angle obtained by rotating counterclockwise from the preset direction to the text line direction of each text line is a negative angle. It should also be understood that the angle obtained by rotating from the preset direction to the text line direction without any rotation is a zero angle.
[0178] In the embodiments of the present application, the preset direction is not specifically limited and can be selected according to actual conditions. In some scenarios, the preset direction can be a direction parallel to the edge of the text image, or the preset direction can also be a direction with a certain inclination angle to the edge of the text image. Fig. 9 Taking the text image shown in (1) as an example, the text image includes edge 1 and edge 2, and the extension direction of edge 1 and the extension direction of edge 2 are perpendicular to each other. Therefore, the preset direction can be a direction parallel to edge 1 or a direction parallel to edge 2.
[0179] In an embodiment of the present application, for each angle range in the multiple angle ranges, the difference between the maximum angle and the minimum angle included in each angle range does not exceed 180°. The number of multiple angle ranges and the value of each angle range are not specifically limited. For example, it can be set according to the shape of multiple lines of text in the text image. For another example, multiple historical angle ranges stored in the electronic device can also be used as the multiple angle ranges in the above step S620.
[0180] In some other implementations, the plurality of angle ranges include two angle ranges. For example, the two angle ranges may be an angle range of 0° to 180° and an angle range of -90° to 90°. For another example, the two angle ranges may be an angle range of 0° to 180° and an angle range of 0° to 90°.
[0181] In some implementations, the plurality of angle ranges include more than two angle ranges. For example, the two or more angle ranges may be, but are not limited to, an angle range of 0° to 180°, an angle range of -90° to 90°, and an angle range of 10° to -90°.
[0182] For ease of description, the following text uses "the angle obtained by rotating counterclockwise from the preset direction to the text line direction of each text line as a positive angle, and the angle obtained by rotating clockwise from the preset direction to the text line direction of each text line as a negative angle" as an example. The preset direction is the direction parallel to the edge of the text image, and multiple angle ranges include 0° to 180° and -90° to 90°. The text image includes N text lines and the corresponding N text line angles in each angle range (i.e., 0° to 180° or -90° to 90°) are described.
[0183] For example, Fig. 9 The text image shown in (1) includes text line 1 and text line 2 which are the above-mentioned N text lines. Fig. 9 The preset direction shown in (2) is the same as Fig. 9 The direction in which the edge of the text image is parallel to 1 is shown in (1). Fig. 9 In (2), when the angle range is 0° to 180°, the corresponding text line angle of text line 1 is 10°, and when the angle range is 0° to 180°, the corresponding text line angle of text line 2 is 170°. Fig. 9 In (2), when the angle range is -90° to 90°, the corresponding text line angle of text line 1 is 10°, and when the angle range is -90° to 90°, the corresponding text line angle of text line 2 is -10°. Fig. 9 The edge 2 shown in (1) is used as the preset direction and will not be described in detail here.
[0184] For example, Fig.10 The text image shown in (1) includes text line 1 and text line 2 which are the above-mentioned N text lines. Fig.10 The preset direction shown in (2) is the same as Fig.10 The direction in which the edge of the text image is parallel to 1 is shown in (1). Fig.10 In (2), when the angle range is 0° to 180°, the corresponding text line angle of text line 1 is 80°, and when the angle range is 0° to 180°, the corresponding text line angle of text line 2 is 100°. Fig.10 In (2), when the angle range is -90° to 90°, the corresponding text line angle of text line 1 is 80°, and when the angle range is -90° to 90°, the corresponding text line angle of text line 2 is -80°. Fig.10 The edge 2 shown in (1) is used as the preset direction and will not be described in detail here.
[0185] In the above step S620, the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges. It is understandable that, when at least two angle variances among the multiple angle variances are the same, and the at least two angle variances are both smaller than the other angle variances among the multiple angle variances, the angle range corresponding to any one of the at least two angle variances can be used as the target angle range.
[0186] In the above step S620, the angle variance corresponding to each angle range is used to represent the sum of the deviations between each text line angle among the N text line angles corresponding to the N text lines in each angle range and the expected angle of the N text lines in each angle range. In some implementations, the angle variance corresponding to each angle range is a weighted variance determined by taking each text line angle among the N text line angles corresponding to the N text lines in each angle range as a variable and the expected angle of the N text lines in each angle range as the mean, wherein the weight of each text line angle used to determine the weighted variance is the ratio of the text line length of the corresponding text line to the lengths of the N text lines, or the weight of each text line angle used to determine the weighted variance is 1. Therefore, the angle variance corresponding to each angle range can be expressed by the following mathematical formula:
[0187]
[0188] In the above formula (6.1), Var represents the angle variance corresponding to each angle range. i Indicates the text line angle of the i-th text line in N text lines, i = 1, 2, ..., N. Mean indicates the expected angle corresponding to each angle range. represents the weight of the text line angle 1 of the i-th text line. It can be understood that when the weight of each text line angle used to determine the weighted variance is the ratio of the text line length of the corresponding text line to the N text line lengths, w in the above formula (6.1) is i Indicates the length of the i-th text line, vw i represents the sum of the lengths of N text lines. When the weight of each text line angle used to determine the weighted variance is 1, w in the above formula (6.1) is i is 1,∑w i =N.
[0189] In some implementations, the expected angle of N lines of text in each angle range is obtained based on N text line lengths and N text line angles. In this implementation, the expected angle of N lines of text in each angle range is a weighted average value determined based on the N text line angles corresponding to the N lines of text in each angle range, wherein the weight of each text line angle used to determine the weighted average value is the ratio of the text line length of the corresponding text line to the N text line lengths. Therefore, the expected angle of N lines of text in each angle range can be expressed by the following mathematical formula:
[0190]
[0191] In the above formula (6.2), Mean represents the expected angle of N lines of text in each angle range. i Indicates the text line angle of the i-th text line in N text lines, i = 1, 2, ..., N. Mean indicates the expected angle corresponding to each angle range. Represents the weight of the text line angle of the i-th text line.
[0192] It can be understood that, when the weight of each text line angle used to determine the weighted average is the ratio of the text line length of the corresponding text line to the lengths of N text lines, w in the above formula (6.2) is i represents the length of the i-th text line, ∑w i represents the sum of the lengths of N text lines. When the weight of each text line angle used to determine the weighted average is 1, w in the above formula (6.2) is i is 1,∑w i =N.
[0193] In some other implementations, the expected angle of the N text lines in each angle range may also be an average value of the lengths of the N text lines.
[0194] In step S630, the electronic device determines the average direction of N text lines based on N target text line angles corresponding to the N text lines within the target angle range, wherein each target text line angle is the angle between the text line direction of the corresponding text line and a preset direction.
[0195] In an embodiment of the present application, the electronic device determines the average direction of N lines of text based on N target text line angles corresponding to the N lines of text within a target angle range, including: the electronic device determines the average angle of N lines of text within a target angle range based on the N target text line angles; the electronic device determines the average direction of N lines of text based on the average angle, wherein the angle between the average direction of the N lines of text and a preset direction is the average angle.
[0196] In the above steps, the electronic device determines the average angle of N text lines within the target angle range based on the N target text line angles. In some implementations, the difference between any two target text line angles among the N target text line angles is small, so it can be considered that the average angle determined based on the N target text line angles is accurate. In other implementations, there is a large difference between at least one target text line angle among the N target text line angles and any target text line angle among the remaining target text line angles among the N target text line angles. In order to avoid the direction of the final text block deviating from the overall direction of the N text lines, in this scenario, it can be considered that the average angle determined based on the remaining target text line angles among the N target text line angles is accurate. That is to say, in this scenario, the text line angles of abnormal text lines (i.e., text lines corresponding to at least one target text line angle) will be ignored when determining the average angle.
[0197] In an embodiment of the present application, the electronic device performs the above steps to determine the average angle of N text lines within a target angle range based on N target text line angles, exemplarily including: the electronic device determines whether the N text lines are all normal text lines based on the N target text line angles; when the N text lines are all normal text lines, the electronic device determines the expected angle of the N text lines within the target angle range as the average angle; or, when at least one text line among the N text lines is an abnormal text line, the electronic device determines the expected angle of the remaining text lines among the N text lines except at least one text line within the target angle range as the average angle, wherein the expected angle of the remaining text lines within the target angle range is obtained based on the text line lengths of the remaining text lines among the N text line lengths and the text line angles of the remaining text lines within the target angle range.
[0198] It can be understood that the principle by which the electronic device determines the expectation of the remaining text lines within the target angle range in the above steps is the same as the principle by which the N lines of text are expected to be within the target angle range. For matters not described in detail here, please refer to the relevant description above.
[0199] For example, Fig.11 The multiple text lines shown are examples, text line 1 is an abnormal text line, and any text line from text line 2 to text line 5 is a normal text line.
[0200] In the above technical solution, the electronic device determines the average angle of N text lines within the target angle range based on the target text line angle corresponding to the normal text lines in the N text lines. In this way, the influence of the target text line angle of the abnormal text line on the average angle of the N text lines can be avoided, so that the determined average angle is more in line with the overall situation of the N text lines.
[0201] Next, the method for the electronic device to determine whether N text lines are all normal text lines according to N target text line angles in the above steps is described. It should be understood that the method for determining whether N text lines are all normal text lines according to N target text line angles is only for illustration and does not constitute any limitation to the present application.
[0202] In some implementations, the electronic device determines whether N target text line angles are all normal text lines based on N target text line angles, including: the electronic device maps each target text line angle among the N target text line angles to a normal distribution whose mean is the expected angle of the N target text line angles within the target angle range and whose standard deviation is the arithmetic square root of the angle variance corresponding to the target angle range, so as to obtain N standardized results for the N target text line angles; when the absolute values of the N standardized results do not exceed a first preset threshold, the electronic device determines that the N text lines are all normal text lines; when the absolute value of the standardized result corresponding to at least one text line among the N standardized results exceeds the first preset threshold, and the absolute values of the standardized results corresponding to the remaining text lines among the N standardized results do not exceed the first preset threshold, the electronic device determines that at least one text line among the N text lines is an abnormal text line.
[0203] In the above technical scheme, the electronic device performs standardization processing on N target text line angles of N lines of text, and determines whether the text line corresponding to any target text line angle is a normal text line by comparing the absolute values of the N standardized results of the N target text line angles with the size of the first preset threshold. The result obtained in this way is more accurate, which is conducive to making the subsequent average angle of the N lines of text within the target angle range more accurate.
[0204] The arithmetic square root of the angle variance corresponding to the target angle range in the above steps is the standard deviation of the angle variance corresponding to the target angle range.
[0205] The i-th standardized processing result among the N standardized results in the above steps can be expressed by the following formula:
[0206]
[0207] In the above formula (6.3), Y i represents the i-th normalized result corresponding to the i-th target text line angle, i = 1, 2, ... N. Mean represents the expected angle of N text lines within the target angle range. i Represents the angle 1 of the i-th text line in at least one cluster set. The square root of the angle variance corresponding to the target angle range is the standard deviation of the angle variance corresponding to the target angle range. In the above steps, the first preset threshold is the value of the normal distribution curve on the x-axis. There is no specific limitation on the value of the first preset threshold, which can be set according to the actual application. For example, the first preset threshold can be equal to 1.5, 2 or 3.
[0208] It is understood that the absolute value of the standardized result of each text line angle does not exceed the first preset threshold, that is, the probability that the standardized result of each text line angle follows the normal distribution is the probability indicated by the first preset threshold. For example, when the first preset threshold is equal to 2, the probability that the standardized result of each text line angle follows the normal distribution is about 95.44%. For example, when the first preset threshold is equal to 3, the probability that the standardized result of each text line angle follows the normal distribution is about 99.7%.
[0209] In other implementations, the electronic device determines whether N lines of text are all normal text lines based on N target text line angles, including: when the absolute value of the difference between any target text line angle among the N target text line angles and the expected angle of the N lines of text lines within the target angle range does not exceed a second preset threshold, the electronic device determines that the N lines of text are all normal text lines; when the absolute value of the difference between the target text line angle corresponding to at least one line of text among the N target text line angles and the expected angle of the N lines of text lines within the target angle range exceeds the second preset threshold, and the absolute value of the difference between the target text line angle corresponding to any text line among the remaining text lines among the N target text line angles and the expected angle of the N lines of text lines within the target angle range does not exceed the second preset threshold, the electronic device determines that at least one line of the N lines of text is an abnormal text line.
[0210] For example, taking N target text line angles including 10°, 12° and 23°, the expected angle of the N lines of text within the target angle range is 15°, and the second threshold is 5°, then the text line corresponding to 10° and the text line corresponding to 12° are both normal text lines, and the text line corresponding to 23° is an abnormal text line.
[0211] In the above implementation method, by comparing the absolute value of the difference between the angle of any target text line and the expected angle of N lines of text within the target angle range and the size of the second preset threshold, it is determined whether the text line corresponding to any target text line angle is a normal text line. This determination method is relatively simple.
[0212] In step S640, the electronic device determines a text block surrounding N text lines based on an average direction of the N text lines and multiple text line vertex coordinates of the N text lines, wherein the text block includes two edges parallel to the average direction and two edges parallel to a first direction perpendicular to the average direction.
[0213] In an embodiment of the present application, an electronic device determines a text block surrounding N lines of text based on an average direction of the N lines of text and multiple text line vertex coordinates of the N lines of text, including: the electronic device obtains multiple first candidate lines and multiple second candidate lines based on the average direction and the multiple text line vertex coordinates, wherein the multiple first candidate lines and the multiple second candidate lines correspond to the multiple text line vertex coordinates one-to-one, each first candidate line is a straight line passing through the corresponding text line vertex coordinates and parallel to the average direction, and each second candidate line is a straight line passing through the corresponding text line vertex coordinates and perpendicular to the first direction of the average direction; the electronic device determines multiple first candidate intersections based on the multiple first candidate lines and the straight lines along the second direction perpendicular to the preset direction, and places the multiple first candidate lines at the intersection of the first candidate lines and the second candidate lines. The first candidate line corresponding to the first candidate intersection with the largest coordinate value along the second direction among the intersections is determined as the first boundary line, and the first candidate line corresponding to the first candidate intersection with the smallest coordinate value along the second direction among the multiple first candidate intersections is determined as the second boundary line; the electronic device determines multiple second candidate intersections based on the multiple second candidate lines and the straight line along the preset direction, and determines the second candidate line corresponding to the second candidate intersection with the largest coordinate value along the preset direction among the multiple second candidate intersections as the third boundary line, and determines the second candidate line corresponding to the second candidate intersection with the smallest coordinate value along the preset direction among the multiple second candidate intersections as the fourth boundary line; the electronic device determines the text block based on the first boundary line, the second boundary line, the third boundary line and the fourth boundary line.
[0214] In the above steps, the multiple first candidate lines and the multiple second candidate lines correspond one-to-one with the multiple text line vertex coordinates, which means that the multiple first candidate lines correspond one-to-one with the multiple text line vertex coordinates, and the multiple second candidate lines correspond one-to-one with the multiple text line vertex coordinates.
[0215] The step of obtaining a plurality of first candidate lines and a plurality of second candidate lines by the electronic device according to the average direction and the coordinates of the vertices of the plurality of text lines includes: the electronic device obtains a plurality of first candidate lines according to the average direction and the coordinates of the vertices of the plurality of text lines; and the electronic device obtains a plurality of second candidate lines according to the average direction and the coordinates of the vertices of the plurality of text lines. The first boundary line and the second boundary line are two candidate lines among the plurality of first candidate lines, and the third boundary line and the fourth boundary line are two candidate lines among the plurality of second candidate lines.
[0216] The following describes the process of the electronic device determining the first boundary line, the second boundary line, the third boundary line and the fourth boundary line in the above steps by way of example with reference to the accompanying drawings.
[0217] For example, Fig.12 The multiple black solid circular points shown are used as the multiple text line vertex coordinates of N lines of text, the preset direction is the positive direction of the x-axis of the two-dimensional coordinate system, the second direction perpendicular to the preset direction is the positive direction of the y-axis of the two-dimensional coordinate system, and the average angle of the N lines of text within the target range is the angle between the first direction and the preset direction. As an example, therefore, it can be obtained through Fig.12 Each of the plurality of black solid circular points shown in FIG. 1 and a plurality of first candidate lines parallel to the first direction can be obtained by passing through Fig.12 Each of the plurality of black solid circular points shown is a plurality of first candidate lines in a first direction perpendicular to the average direction. It should be understood that Fig.12 Only two first candidate lines and two second candidate lines are shown, and the remaining first candidate lines and the remaining second candidate lines are not shown.
[0218] See also Fig.12 It can be seen that Fig.12 The maximum coordinate value of one first candidate line along the second direction is Y2, and the minimum coordinate value of another first candidate line along the second direction is Y1. Therefore, the first candidate line corresponding to Y2 is used as the first boundary line, and the first candidate line corresponding to Y1 is used as the second boundary line. Fig.12 The coordinate value of one second candidate line along the preset direction is maximum X2, and the coordinate value of another second candidate line along the preset direction is minimum X1. Therefore, the second candidate line corresponding to X2 is used as the third boundary line, and the second candidate line corresponding to X1 is used as the fourth boundary line.
[0219] Next, the method for the electronic device to determine the text block according to the first boundary line, the second boundary line, the third boundary line and the fourth boundary line in the above steps is introduced. It should be understood that the method for determining the text block according to the boundary line described below is only for illustration and does not constitute any limitation to the present application.
[0220] In some implementations, the electronic device performs the step of determining a text block based on the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line, including: the electronic device determines a square frame formed by the intersection of the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line as a text block.
[0221] In the above implementation, the electronic device determines the square frame formed by the intersection of the first boundary line, the second boundary line, the third boundary line and the fourth boundary line as a text block. In this way, not only can the technical problem of the inconsistency between the direction of the text block including the text line and the direction of the text line be solved, but also the area of the text block surrounding the text line can be kept as small as possible.
[0222] In other implementations, the electronic device performs the step of determining a text block based on the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line, including: the electronic device determines a candidate text block based on the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line, wherein the candidate text block includes two sides parallel to the average direction and two sides parallel to a first direction perpendicular to the average direction; the electronic device determines a text block surrounding the candidate text block as a text block, wherein the direction of the text block is the same as the direction of the candidate text block, and the area of the text block is larger than the area of the candidate text block.
[0223] In the above implementation, the electronic device determines the square box formed by the intersection of the first boundary line, the second boundary line, the third boundary line and the fourth boundary line as a candidate text block, and further determines the text block including the candidate text block as a text block. In this way, the technical problem of the inconsistency between the direction of the text block including the text line and the direction of the text line can be solved.
[0224] In the embodiment of the present application, after the electronic device executes the above S610 to S640, a rectangular text block with the same overall direction as the N text lines can be obtained. Optionally, after the electronic device executes the above S610 to S640, the electronic device can also perform the following steps: the electronic device determines the coordinates of the four vertices included in the text block according to the four edges included in the text block.
[0225] In the above steps, the method by which the electronic device calculates the intersection of the two boundary lines based on the two boundary lines is not specifically limited. For example, the electronic device can combine the two linear equations corresponding to the two boundary lines, and solve the binary linear equation to obtain the intersection of the two boundary lines. For another example, the electronic device can also calculate the intersection of the two boundary lines based on the vector cross product method.
[0226] It should be understood that the above Figure 6 The text processing method shown is for illustration only and does not constitute any limitation to the text processing method provided in this application.
[0227] In an embodiment of the present application, the electronic device determines the average direction of N text lines based on the N target text line angles corresponding to the N text lines within the target angle range, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, so that the average direction of the N text lines obtained is kept consistent with the overall direction of the N text lines as much as possible. Thereafter, the electronic device determines the direction of the text block surrounding the N text lines based on the average direction and the multiple text line vertex coordinates of the N text lines, so that the direction of the text block obtained can be kept consistent with the direction of the N text lines as much as possible, thereby solving the technical problem that the direction of the text block surrounding the text line is inconsistent with the direction of the text line.
[0228] Next, combine Fig.13 Another text processing method provided by the embodiment of the present application is introduced. It can be understood that, Fig.13 The text processing method described is the above Figure 6 A specific example of the described text processing method, Fig.13 The described method is for illustration only and does not constitute any limitation to the text processing method provided in this application.
[0229] Fig.13 is a schematic diagram of another text processing method provided in an embodiment of the present application. The text processing method provided in an embodiment of the present application can be Figure 3 The electronic device 100 shown is executed, wherein the electronic device 100 may be, but is not limited to, a mobile phone. It can be understood that the electronic device 100 may be implemented as software, or a combination of software and hardware. Fig.13 The method shown includes S1310 to S1390. S1310 to S1390 are described in detail below.
[0230] S1310, the electronic device uses a detection model to segment an original text image including multiple text lines to obtain a text image, wherein the text image includes N text lines in the original text image, and N is a positive integer.
[0231] The detection model in the above S1310 may be, but is not limited to, an optical character recognition (OCR) model.
[0232] In some implementations, the original text image in S1310 may be Fig.14 The original text image shown in (1) in FIG. 1 can be Fig.14 The text image shown in (2) in . Fig.14 In (1), the original text image has 5 text lines on the left and 3 text lines on the right. Fig.14In (2), all text lines in the text image are displayed in white, and the 5 white text lines displayed on the left side of the text image are Fig.14 The five text lines displayed on the left side of the original text image shown in (1) correspond one to one, and the three white text lines displayed on the right side of the text image correspond one to one. Fig.14 The three lines of text displayed on the right side of the original text image shown in (1) correspond one to one.
[0233] In some other implementations, the original text image in S1310 may be Fig.15 The original text image shown in (1) in FIG. 1 can be Fig.15 The text image shown in (2) in FIG. Fig.15 The original text image shown in (1) includes 6 lines of text, and Fig.15 The six text lines indicated in white in the text image shown in (2) correspond one to one.
[0234] S1320, the electronic device clusters the N text lines in the text image, determines that the N text lines in the text image belong to the same category, and obtains N text line directions of the N text lines, N text line lengths of the N text lines, and multiple text line vertex coordinates of the N text lines from the text image.
[0235] In some implementations, the text image in S1320 is Fig.14 For the text image shown in (2), clustering all the text lines in the text image can be obtained Fig.14 Cluster set 1 and cluster set 2 shown in (2) in FIG. 1 , wherein cluster set 1 includes Fig.14 In the text image shown in (2) in FIG. 1 , the 5 text lines shown on the left side, the cluster set 2 includes Fig.14 The three lines of text are shown on the right side of the text image shown in (2).
[0236] In some other implementations, the text image in the above step S1320 is Fig.15 For the text image shown in (2) in FIG, clustering all text lines in the text image can obtain a cluster set, which includes Fig.14 The text image shown in (2) in FIG. 6 shows 6 lines of text on the left.
[0237] S1330, the electronic device determines the angle variance 1 of N text line angles 1 corresponding to N lines of text lines within the angle range 1 according to the first preset direction and the angle range 1, wherein the angle range 1 is an angle range of 0° to 180°, and each text line angle 1 is the angle between the text line direction of each corresponding text line and the first preset direction.
[0238] The principle by which the electronic device determines the angle variance 1 in the above S1330 is the same as the principle by which the electronic device determines the angle variance of N lines of text within an angle range in the above step S630. For matters not described in detail here, please refer to the relevant description in the above S630.
[0239] In some implementations, the N lines of text in S1330 may be Fig.14 (2) in the figure shows the multiple text lines included in cluster set 1, or the multiple text lines included in cluster set 2.
[0240] In some other implementations, the N lines of text in S1330 may be Fig.15 (2) in FIG. 4 shows multiple text lines belonging to the same class.
[0241] S1340, the electronic device determines the angle variance 2 of N text line angles 2 corresponding to N lines of text line angles within the angle range 2 based on the first preset direction and the angle range 2, wherein the angle range 2 is an angle range of -90° to 90°, and each text line angle 2 is the angle between the text line direction of each corresponding text line and the first preset direction.
[0242] The principle by which the electronic device determines the angle variance 2 in the above S1340 is the same as the principle by which the electronic device determines the angle variance of N lines of text within an angle range in the above step S630. For contents not described in detail here, please refer to the relevant description in the above S630.
[0243] The difference between the above S1340 and the above S1330 is that the angle range is different. It can be understood that the electronic device determines that the angle of a line of text is the same or different according to the first preset direction and different angle ranges (for example, angle range 1 or angle range 2).
[0244] S1350: The electronic device determines whether angle variance 1 is smaller than angle variance 2.
[0245] In the embodiment of the present application, after the electronic device executes the above S1350, if it is determined that the angle variance 1 corresponding to the angle range 1 is less than the angle variance 2 corresponding to the angle range 2, the electronic device continues to execute S1360. After the electronic device executes the above S1350, if it is determined that the angle variance 1 corresponding to the angle range 1 is not less than the angle variance 2 corresponding to the angle range 2, the electronic device continues to execute S1370.
[0246] S1360: The electronic device determines a rectangular text block surrounding N text lines according to a first preset direction and angle range 1.
[0247] In the embodiment of the present application, the electronic device executes the above-mentioned process of S1360, which can be referred to as Fig.16 S1361 to S1365 are shown. S1361 to S1365 are described in detail below.
[0248] In actual applications, in some scenarios, one text line angle among multiple text line angles is significantly different from the other text line angles. In this implementation, if a rectangular text block is determined based on the multiple text line angles, the direction of the rectangular text block finally calculated will deviate from the text line directions of most of the multiple text lines corresponding to the multiple text line angles. For ease of description, the text line corresponding to the one text line angle is referred to as an abnormal text line below. In order to solve the above problem, after the electronic device determines that the angle range is angle range 1, next, the electronic device needs to perform an abnormality judgment on each of the N text lines. Furthermore, when the electronic device subsequently determines the direction of the rectangular text block, the text line angle corresponding to the abnormal text line will be ignored.
[0249] The following is an introduction to a method for determining that a text line is an abnormal text line provided in an embodiment of the present application. It should be understood that the method for determining that a text line is an abnormal text line described in S1361 and S1362 below is only for illustration and does not constitute any limitation on the text processing method provided in the embodiment of the present application. In other words, the electronic device 1 can also determine which text lines among N text lines are abnormal text lines by executing other methods, and no specific limitation is made to this.
[0250] S1361, the electronic device maps each target text line angle 1 among N text line angles 1 to a normal distribution whose mean is the expected angle of the N text lines within the angle range 1 and whose standard deviation is the arithmetic square root of the angle variance 1 corresponding to the angle range 1, so as to obtain N standardized results of the N text line angles 1.
[0251] In the above step S1361, the principle by which the electronic device obtains the standardized result of the angle 1 of each text line is the same as the principle by which the electronic device obtains the standardized result of the angle of each text line in the above step S630, that is, the electronic device can use the formula (6.3) described in the above S630 to standardize the angle 1 of each text line to obtain the standardized result of the angle 1 of each text line. For the contents not described in detail here, please refer to the relevant description in the above S630.
[0252] S1362, the electronic device determines whether the absolute value of the standardized result of each text line angle 1 among N text line angles 1 is less than or equal to a first preset threshold.
[0253] In an embodiment of the present application, the first preset threshold in the above step S1362 may be equal to 2.
[0254] In an embodiment of the present application, after the electronic device executes the above S1362, if it is determined that the absolute value of each target text line angle 1 among the N text line angles 1 is less than or equal to the first preset threshold, the electronic device continues to execute S1363 after executing the above S1362 step; if it is determined that the absolute value of the standardized result of at least one text line angle 1 among the N standardized results of the N text line angles 1 is greater than the first preset threshold, the electronic device continues to execute S1364 after executing the above S1362 step.
[0255] S1363, when the absolute value of the standardized result of each text line angle 1 among N text line angles 1 is less than or equal to a first preset threshold value, the electronic device determines a rectangular text block surrounding N text lines based on multiple text line vertex coordinates of the N text lines and the average direction of the N text line angles 1, wherein the angle between the average direction and the first preset direction within the angle range 1 is the weighted average 1 of the N text line angles 1 corresponding to the N text lines within the angle range 1.
[0256] In the above step S1363, the principle by which the electronic device obtains the rectangular text block is the same as the principle by which the electronic device obtains the text block by executing the above step S640. For matters not described in detail here, reference can be made to the relevant description in the above step S640.
[0257] It can be understood that if the absolute value of the normalized result of a text line angle 1 is less than or equal to the first preset threshold, then a text line corresponding to the text line angle 1 is a normal text line.
[0258] In some implementations, the N lines of text in the above step S1363 are Fig.14 For all text lines shown in (2) (i.e., the first to fifth text lines), the boundary lines of the rectangular text blocks involved in the above S1363 process performed by the electronic device can refer to Fig.14 The boundary line shown in (3) in FIG. 1 and the rectangular text block obtained by the electronic device executing the above S1363 can be referred to as Fig.14 The black solid line shown in (4) in FIG. It can be understood that Fig.14 (4) in the figure only shows the partial structure of the rectangular text block obtained by the electronic device executing the above S1363.
[0259] S1364, when the absolute value of the standardized result of at least one text line angle 1 among N text line angles 1 exceeds the first preset threshold, the electronic device determines the weighted average of the text line angles 1 of the remaining text lines in the N text lines except the text line corresponding to at least one text line angle 1 according to the first preset direction and angle range 1, wherein the absolute value of the standardized result of the text line angle 1 corresponding to any text line in the remaining text lines is less than or equal to the first preset threshold.
[0260] In the above step S1364, the principle by which the electronic device determines the weighted average value of the text line angle 1 of the remaining text lines is the same as the principle by which the electronic device determines the weighted average value 1 in the above step S1330. For matters not described in detail here, please refer to the relevant description in the above step S1330.
[0261] It can be understood that if the absolute value of the normalized result of a text line angle 1 exceeds the first preset threshold, the text line corresponding to the text line angle 1 is an abnormal text line. Fig.15 The first text line in the text image shown in (2) is an abnormal text line. Fig.15 Any of the second to sixth text lines in the text image shown in (2) is a normal text line.
[0262] S1365, the electronic device determines a rectangular text block surrounding N text lines based on multiple text line vertex coordinates of the remaining text lines and the average direction of the text line angle 1 corresponding to the remaining text lines, wherein the angle between the average direction and the first preset direction within the angle range 1 is the weighted average 1 of the text line angle 1 corresponding to the remaining text lines within the angle range 1.
[0263] The difference between the above step S1365 and the above step S1363 is that the weighted average is different. The principle of the electronic device determining the rectangular text block 1 in the above step S1365 is the same as the principle of the electronic device determining the rectangular text block 1 in the above step S1363. For the contents not described in detail here, please refer to the relevant description in the above step S1363.
[0264] In some implementations, the remaining text lines in the above step S1365 are Fig.15 From the second to the sixth text lines shown in (2), the boundary lines of the rectangular text blocks involved in the process of the electronic device executing the above S1365 can be referred to as Fig.15 The boundary line shown in (3) in FIG. 1 and the rectangular text block obtained by the electronic device executing the above S1365 can be referred to as Fig.15 The black solid line shown in (4) in FIG. It can be understood that Fig.15 (4) in the figure only shows the partial structure of the rectangular text block obtained by the electronic device executing the above S1365.
[0265] So far, the principle of the electronic device executing the above-mentioned step S1360 has been described in combination with S1361 to S1365.
[0266] S1370: The electronic device determines whether angle variance 1 is equal to angle variance 2.
[0267] In the embodiment of the present application, if the electronic device determines that angle variance 1 is equal to angle variance 2 after executing the above S1370, S1390 is executed after executing the above S1370. If the electronic device determines that angle variance 1 is greater than angle variance 2 after executing the above S1350 and S1370, S1380 is executed after executing the above S1370.
[0268] S1380: The electronic device determines a rectangular text block surrounding N text lines according to the first preset direction and angle range 2.
[0269] S1390: The electronic device determines a rectangular text block surrounding N text lines according to the first preset direction and angle range 1, or the first preset direction and angle range 2.
[0270] The principle of the electronic device executing the above step S1380 or S1390 is the same as the principle of the electronic device executing the above step S1360. For the contents not described in detail here, please refer to the relevant description in the above step S1360.
[0271] It should be understood that the above Fig.13 The text processing method shown is only for illustration and does not constitute any limitation on the text processing method provided in this application. Fig.13 The illustrated method is described using multiple angle ranges including two angle ranges as an example. Optionally, the text processing method provided in the embodiment of the present application may also be described using more than two angle ranges as an example.
[0272] Combination of the above Figures 1 to 16 , describes in detail the text processing method of the embodiment of the present application, and will now be combined with Fig.17 and Fig.18 , describes the device embodiment of the present application in detail. It should be understood that the text processing device in the embodiment of the present application can execute the various text processing methods in the aforementioned embodiment of the present application, that is, the specific working process of the following various products can refer to the corresponding process in the aforementioned method embodiment.
[0273] Fig.17 is a schematic diagram of a text processing device provided in an embodiment of the present application. For example, Fig.17 The illustrated text processing apparatus 1700 includes a processing unit 1710 .
[0274] The processing unit 1710 is used to: obtain text line information of a text image, wherein the text line information includes N text line directions of N text lines, N text line lengths of the N text lines and multiple text line vertex coordinates of the N text lines, and N is a positive integer; determine a target angle range of the N text lines from multiple angle ranges according to the N text line directions and the N text line lengths, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, and the angle variance corresponding to each angle range is used to represent the sum of deviations between each text line angle of the N text line angles corresponding to the N text lines within each angle range and an expected angle of the N text lines within each angle range, Each text line angle is the angle between the text line direction of the corresponding text line and a preset direction, and the expected angle of the N text lines within each angle range is obtained based on the N text line lengths and the N text line angles; according to the N target text line angles corresponding to the N text lines within the target angle range, the average direction of the N text lines is determined, wherein each target text line angle is the angle between the text line direction of the corresponding text line and the preset direction; according to the average direction of the N text lines and the multiple text line vertex coordinates of the N text lines, a text block surrounding the N text lines is determined, wherein the text block includes two sides parallel to the average direction, and two sides parallel to a first direction perpendicular to the average direction.
[0275] In some implementations, the processing unit 1710 is also used to: determine the average angle of the N lines of text within the target angle range based on the N target text line angles; determine the average direction of the N lines of text based on the average angle, wherein the angle between the average direction of the N lines of text and the preset direction is the average angle.
[0276] In other implementations, the processing unit 1710 is also used to: determine whether the N text lines are all normal text lines based on the N target text line angles; when the N text lines are all normal text lines, determine the expected angle of the N text lines within the target angle range as the average angle; or, when at least one text line among the N text lines is an abnormal text line, determine the expected angle of the remaining text lines in the N text lines except the at least one text line within the target angle range as the average angle, wherein the expected angle of the remaining text lines within the target angle range is obtained based on the text line lengths of the remaining text lines among the N text line lengths and the text line angles of the remaining text lines within the target angle range.
[0277] In other implementations, the processing unit 1710 is also used to: map each target text line angle among the N target text line angles to a normal distribution whose mean is the expected angle of the N text lines within the target angle range and whose standard deviation is the arithmetic square root of the angle variance corresponding to the target angle range, so as to obtain N standardized results of the N target text line angles; determine that the N text lines are all normal text lines when the absolute values of the N standardized results do not exceed a first preset threshold; determine that at least one text line among the N text lines is the abnormal text line when the absolute value of the standardized result corresponding to at least one text line among the N standardized results exceeds the first preset threshold, and the absolute values of the standardized results corresponding to the remaining text lines among the N standardized results do not exceed the first preset threshold.
[0278] In other implementations, the processing unit 1710 is also used to: determine that the N lines of text are all normal text lines when the absolute value of the difference between any target text line angle among the N target text line angles and the expected angle of the N lines of text within the target angle range does not exceed a second preset threshold; determine that at least one line of text among the N lines of text is the abnormal text line when the absolute value of the difference between the target text line angle corresponding to at least one line of text among the N target text line angles and the expected angle of the N lines of text within the target angle range exceeds the second preset threshold, and the absolute value of the difference between the target text line angle corresponding to any text line among the remaining text lines among the N target text line angles and the expected angle of the N lines of text within the target angle range does not exceed the second preset threshold.
[0279] In some other implementations, the processing unit 1710 is also used to: obtain a plurality of first candidate lines and a plurality of second candidate lines according to the average direction and the plurality of text line vertex coordinates, wherein the plurality of first candidate lines and the plurality of second candidate lines correspond one-to-one to the plurality of text line vertex coordinates, each first candidate line is a straight line passing through the corresponding text line vertex coordinates and parallel to the average direction, and each second candidate line is a straight line passing through the corresponding text line vertex coordinates and perpendicular to the first direction of the average direction; determine a plurality of first candidate intersections according to the plurality of first candidate lines and the straight line along the second direction perpendicular to the preset direction, and select the first candidate intersection with the largest coordinate value along the second direction among the plurality of first candidate intersections. The first candidate line corresponding to the selected intersection is determined as the first boundary line, and the first candidate line corresponding to the first candidate intersection with the smallest coordinate value along the second direction among the multiple first candidate intersections is determined as the second boundary line; multiple second candidate intersections are determined according to the multiple second candidate lines and the straight line along the preset direction, and the second candidate line corresponding to the second candidate intersection with the largest coordinate value along the preset direction among the multiple second candidate intersections is determined as the third boundary line, and the second candidate line corresponding to the second candidate intersection with the smallest coordinate value along the preset direction among the multiple second candidate intersections is determined as the fourth boundary line; the text block is determined according to the first boundary line, the second boundary line, the third boundary line and the fourth boundary line.
[0280] In some other implementations, the processing unit 1710 is further configured to: determine a square frame formed by the intersection of the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line as the text block.
[0281] In other implementations, the angular variance corresponding to each angular range is a weighted variance determined by taking each text line angle among the N text line angles corresponding to the N lines of text within each angular range as a variable and the expected angle of the N lines of text within each angular range as the mean, wherein the weight of each text line angle used to determine the weighted variance is the ratio of the text line length of the corresponding text line to the N text line lengths, or the weight of each text line angle used to determine the weighted variance is 1.
[0282] In other implementations, the expected angle of the N lines of text within each angle range is a weighted average determined based on the N text line angles corresponding to the N lines of text within each angle range, wherein the weight of each text line angle used to determine the weighted average is the ratio of the text line length of the corresponding text line to the lengths of the N text lines.
[0283] In other implementations, the processing unit 1710 is also used to: cluster the N text lines according to N text line position information of the N text lines to determine that the N text lines belong to the same category; and when the N text lines belong to the same category, obtain the text line information from the text image.
[0284] In some other implementations, the multiple angle ranges include an angle range of 0° to 180° and an angle range of -90° to 90°.
[0285] It should be noted that the above-mentioned text processing device 1700 is embodied in the form of a functional unit. The term "unit" here can be implemented in the form of software and / or hardware, and is not specifically limited to this.
[0286] For example, a "unit" may be a software program, a hardware circuit, or a combination of the two that implements the above functions. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (e.g., a shared processor, a dedicated processor, or a group processor, etc.) and a memory for executing one or more software or firmware programs, a combined logic circuit, and / or other suitable components that support the described functions.
[0287] Therefore, the units of each example described in the embodiments of the present application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
[0288] Fig.18 It is a schematic diagram of the structure of an electronic device provided by the present application. Fig.18 The dotted line in indicates that the unit or the module is optional. The electronic device 1800 can be used to implement the text processing method described in the above method embodiment.
[0289] The electronic device 1800 includes one or more processors 1801, which can support the electronic device 1800 to implement the text processing method in the method embodiment. The processor 1801 can be a general-purpose processor or a special-purpose processor. For example, the processor 1801 can be a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, such as discrete gates, transistor logic devices or discrete hardware components.
[0290] The processor 1801 may be used to control the electronic device 1800, execute software programs, and process data of the software programs. The electronic device 1800 may also include a communication unit 1805 to implement input (reception) and output (transmission) of signals.
[0291] For example, the electronic device 1800 may be a chip, the communication unit 1805 may be an input and / or output circuit of the chip, or the communication unit 1805 may be a communication interface of the chip, and the chip may be a component of a terminal device or other electronic devices.
[0292] For another example, the electronic device 1800 may be a terminal device, and the communication unit 1805 may be a transceiver of the terminal device, or the communication unit 1805 may be a transceiver circuit of the terminal device.
[0293] The electronic device 1800 may include one or more memories 1802 on which a program 1804 is stored. The program 1804 can be executed by the processor 1801 to generate instructions 1803, so that the processor 1801 executes the text processing method described in the above method embodiment according to the instructions 1803.
[0294] Optionally, data may be stored in the memory 1802. Optionally, the processor 1801 may read data stored in the memory 1802. The data may be stored at the same storage address as the program 1804, or may be stored at a different storage address than the program 1804.
[0295] The processor 1801 and the memory 1802 may be provided separately or integrated together; for example, integrated on a system on chip (SOC) of a terminal device.
[0296] Exemplarily, the memory 1802 can be used to store the related program 1804 of the text processing method provided in the embodiment of the present application, and the processor 1801 can be used to call the related program 1804 of the text processing method stored in the memory 1802 to execute the text processing method of the embodiment of the present application.
[0297] The present application also provides a computer program product, which, when executed by the processor 1801, implements the text processing method described in any method embodiment of the present application.
[0298] The computer program product may be stored in the memory 1802 , for example, a program 1804 , which is converted into an executable target file that can be executed by the processor 1801 after preprocessing, compilation, assembly, and linking.
[0299] The present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a computer, the text processing method described in any method embodiment of the present application is implemented. The computer program can be a high-level language program or an executable target program.
[0300] The computer-readable storage medium is, for example, memory 1802. Memory 1802 may be a volatile memory or a nonvolatile memory, or memory 1802 may include both a volatile memory and a nonvolatile memory. Among them, the nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DR RAM).
[0301] In this application, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can be represented by: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.
[0302] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0303] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0304] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0305] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic; for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0306] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0307] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0308] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A text processing method, characterized in that: The method comprises: Acquire text line information of the text image, wherein the text line information includes N text line directions of N text lines, N text line lengths of the N text lines, and multiple text line vertex coordinates of the N text lines, where N is a positive integer; According to the N text line directions and the N text line lengths, a target angle range of the N text lines is determined from multiple angle ranges, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, and the angle variance corresponding to each angle range is used to represent the sum of deviations between each text line angle of the N text line angles corresponding to the N text line angles within each angle range and the expected angle of the N text line within each angle range, wherein each text line angle is the angle between the text line direction of the corresponding text line and a preset direction, and the expected angle of the N text line within each angle range is obtained based on the N text line lengths and the N text line angles; Determining an average direction of the N text lines according to N target text line angles corresponding to the N text lines within the target angle range, wherein each target text line angle is an angle between a text line direction of the corresponding text line and the preset direction; According to the average direction of the N text lines and the multiple text line vertex coordinates of the N text lines, a text block surrounding the N text lines is determined, wherein the text block includes two sides parallel to the average direction and two sides parallel to a first direction perpendicular to the average direction.
2. The method according to claim 1, characterized in that Determining the average direction of the N text lines according to the N target text line angles corresponding to the N text lines within the target angle range includes: Determine, according to the N target text line angles, an average angle of the N text lines within the target angle range; The average direction of the N text lines is determined according to the average angle, wherein the angle between the average direction of the N text lines and the preset direction is the average angle.
3. The method according to claim 2, characterized in that Determining, according to the N target text line angles, an average angle of the N text lines within the target angle range includes: Determining whether the N target text line angles are all normal text lines; In the case that the N text lines are all normal text lines, the expected angles of the N text lines within the target angle range are determined as the average angle; or In the case that at least one text line among the N text lines is an abnormal text line, the expected angles of the remaining text lines among the N text lines except the at least one text line within the target angle range are determined as the average angle, wherein the expected angles of the remaining text lines within the target angle range are obtained based on the text line lengths of the remaining text lines among the N text line lengths and the text line angles of the remaining text lines within the target angle range.
4. The method according to claim 3, characterized in that The determining, according to the N target text line angles, whether the N text lines are all normal text lines includes: Mapping each of the N target text line angles to a normal distribution whose mean is the expected angle of the N text lines within the target angle range and whose standard deviation is the arithmetic square root of the angle variance corresponding to the target angle range, so as to obtain N standardized results of the N target text line angles; When the absolute values of the N normalization results do not exceed a first preset threshold, determining that the N text lines are all normal text lines; When the absolute value of the standardized result corresponding to at least one line of text in the N standardized results exceeds the first preset threshold, and the absolute values of the standardized results corresponding to the remaining text lines in the N standardized results do not exceed the first preset threshold, it is determined that at least one line of text in the N lines of text is the abnormal text line.
5. The method according to claim 3, characterized in that: The determining, according to the N target text line angles, whether the N text lines are all normal text lines includes: When the absolute value of the difference between any target text line angle among the N target text line angles and the expected angle of the N text lines within the target angle range does not exceed a second preset threshold, determining that the N text lines are all normal text lines; When the absolute value of the difference between the target text line angle corresponding to at least one of the N target text line angles and the expected angle of the N text lines within the target angle range exceeds the second preset threshold, and the absolute value of the difference between the target text line angle corresponding to any of the remaining text lines among the N target text line angles and the expected angle of the N text lines within the target angle range does not exceed the second preset threshold, it is determined that at least one of the N text lines is the abnormal text line.
6. The method according to any one of claims 1 to 5, characterized in that: The determining of a text block surrounding the N text lines according to the average direction of the N text lines and the plurality of text line vertex coordinates of the N text lines comprises: According to the average direction and the plurality of text line vertex coordinates, a plurality of first candidate lines and a plurality of second candidate lines are obtained, wherein the plurality of first candidate lines and the plurality of second candidate lines correspond to the plurality of text line vertex coordinates one by one, each first candidate line is a straight line passing through the corresponding text line vertex coordinate and parallel to the average direction, and each second candidate line is a straight line passing through the corresponding text line vertex coordinate and perpendicular to the first direction of the average direction; Determine a plurality of first candidate intersection points according to the plurality of first candidate lines and a straight line along a second direction perpendicular to the preset direction, and determine a first candidate line corresponding to a first candidate intersection point having a maximum coordinate value along the second direction among the plurality of first candidate intersection points as a first boundary line, and determine a first candidate line corresponding to a first candidate intersection point having a minimum coordinate value along the second direction among the plurality of first candidate intersection points as a second boundary line; Determine a plurality of second candidate intersection points according to the plurality of second candidate lines and the straight line along the preset direction, and determine the second candidate line corresponding to the second candidate intersection point with the largest coordinate value along the preset direction among the plurality of second candidate intersection points as the third boundary line, and determine the second candidate line corresponding to the second candidate intersection point with the smallest coordinate value along the preset direction among the plurality of second candidate intersection points as the fourth boundary line; The text block is determined according to the first boundary line, the second boundary line, the third boundary line and the fourth boundary line.
7. The method according to claim 6, characterized in that The step of determining the text block according to the first boundary line, the second boundary line, the third boundary line, and the fourth boundary line includes: A square frame formed by the intersection of the first boundary line, the second boundary line, the third boundary line and the fourth boundary line is determined as the text block.
8. The method according to any one of claims 1 to 7, characterized in that: The angular variance corresponding to each angular range is a weighted variance determined by taking each text line angle among the N text line angles corresponding to the N text lines within each angular range as a variable and the expected angle of the N text lines within each angular range as the mean, wherein the weight of each text line angle used to determine the weighted variance is the ratio of the text line length of the corresponding text line to the N text line lengths, or the weight of each text line angle used to determine the weighted variance is 1.
9. The method according to any one of claims 1 to 8, characterized in that: The expected angle of the N lines of text within each angle range is a weighted average determined based on the N text line angles corresponding to the N lines of text within each angle range, wherein the weight of each text line angle used to determine the weighted average is the ratio of the text line length of the corresponding text line to the N text line lengths.
10. The method according to any one of claims 1 to 9, characterized in that: The obtaining of text line information of the text image includes: Clustering the N text lines according to N text line position information of the N text lines to determine that the N text lines belong to the same class; In the case that the N text lines belong to the same category, the text line information is acquired from the text image.
11. The method according to any one of claims 1 to 10, characterized in that: The plurality of angle ranges include an angle range of 0° to 180° and an angle range of -90° to 90°.
12. A text processing device, characterized in that: The text processing device comprises a processing unit, wherein the processing unit is used for: Acquire text line information of the text image, wherein the text line information includes N text line directions of N text lines, N text line lengths of the N text lines, and multiple text line vertex coordinates of the N text lines, where N is a positive integer; According to the N text line directions and the N text line lengths, a target angle range of the N text lines is determined from multiple angle ranges, wherein the angle variance corresponding to the target angle range is the smallest angle variance among the multiple angle variances corresponding to the multiple angle ranges, and the angle variance corresponding to each angle range is used to represent the sum of deviations between each text line angle of the N text line angles corresponding to the N text line angles within each angle range and the expected angle of the N text line within each angle range, wherein each text line angle is the angle between the text line direction of the corresponding text line and a preset direction, and the expected angle of the N text line within each angle range is obtained based on the N text line lengths and the N text line angles; Determining an average direction of the N text lines according to N target text line angles corresponding to the N text lines within the target angle range, wherein each target text line angle is an angle between a text line direction of the corresponding text line and the preset direction; According to the average direction of the N text lines and the multiple text line vertex coordinates of the N text lines, a text block surrounding the N text lines is determined, wherein the text block includes two sides parallel to the average direction and two sides parallel to a direction perpendicular to the average direction.
13. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program from the memory, so that the processor executes the text processing method according to any one of claims 1 to 11.
14. A chip, characterized in that: The invention comprises a processor, and when the processor executes instructions, the processor performs the text processing method according to any one of claims 1 to 11.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the text processing method according to any one of claims 1 to 11.
Citation Information
Cited By
Text recognition method, device and program product
CN120635911A