A method and apparatus for calculating the line direction of text in an image

By creating an undirected graph in the image and processing the text box, the direction of text lines is determined, which solves the problem that model training in the prior art depends on scene data, and improves the detection and recognition rate of text line direction in different scenes.

CN117789234BActive Publication Date: 2026-11-17SHANGHAI SHANGHU INFORMATION TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211158886.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-22
Publication Date
2026-11-17
Estimated Expiration
2042-09-22

AI Technical Summary

Technical Problem

Existing image text line direction detection methods require model training on scene-related text line direction data. The models have poor universality and are difficult to effectively detect the line direction of image text in scenes with different distributions.

Method used

By acquiring the input image, determining the text region, creating an undirected graph, traversing the nodes and undirected edges in the undirected graph, obtaining the text line segment set, determining the text line direction information based on the text line segment set, and using the maximum extremum stable region algorithm and non-maximum suppression algorithm to process the text boxes in the image to ensure that the undirected edges are connected between the text.

Benefits of technology

It achieves accurate recognition of text line direction in images under different scenarios, improves the recognition rate of text information, and solves the problem of poor model universality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117789234B_ABST
    Figure CN117789234B_ABST
Patent Text Reader

Abstract

This invention provides a method and apparatus for calculating the line direction of text in an image. The method includes: acquiring an input image; determining a text region corresponding to the input image; taking adjacent characters in the text region that meet preset conditions as two nodes; taking the line segment connecting the two nodes as an undirected edge; creating an undirected graph corresponding to the text region; traversing the nodes and undirected edges in the undirected graph; taking any two parallel undirected edges that share a common node as a text line segment; acquiring a set of text line segments; and determining the line direction information of the text in the input image based on the set of text line segments. This method solves the problem that existing image text line direction detection methods require model training on scene-related text line direction data, resulting in a cumbersome process and poor model universality. This method requires no training, is simple to implement, and meets the performance requirements of real-time computing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision, and in particular to a method and apparatus for calculating the direction of text lines in an image. Background Technology

[0002] With the widespread use of smartphones and other mobile devices, a large number of electronic images are generated by the imaging modules of these devices. Images containing text information are a common type of image, recording the textual content to be expressed or conveyed in the form of electronic images. Therefore, recognizing the text in images and extracting the information it conveys has become crucial for current image recognition.

[0003] Since a large proportion of images are currently taken by users using mobile devices, user habits directly affect the orientation of text within the image, and different text orientations impact text recognition rates. Therefore, a crucial preliminary step before text recognition is determining the orientation of the text in the image, i.e., the direction of the text lines. Further, by adjusting the text line orientation to horizontal, the text information in the image is then recognized, thereby improving the text recognition rate.

[0004] Currently, existing image text line direction detection methods rely on collecting a large amount of image text data containing annotation information (coordinates and rotation angles) from the applicable scene as training data to train a text line horizontal rectangle detection network model. When the distribution of the input image text data in the scene is relatively consistent with the distribution of the training data, the text line horizontal rectangle detection network model can detect the line direction of the image text. However, when the distribution of the input image text data in the scene differs significantly from the distribution of the training data, or when the input is image text data from other scenes, the text line horizontal rectangle detection network model experiences significant performance degradation and struggles to detect the line direction of the image text. Summary of the Invention

[0005] This invention provides a method and apparatus for calculating the line direction of text in an image, which solves the problem that existing methods for detecting the line direction of text in an image require training a model on scene-related text line direction data, resulting in poor model universality.

[0006] In a first aspect, embodiments of the present invention provide a method for calculating the direction of text lines in an image, including:

[0007] Obtain the input image;

[0008] Determine the text region corresponding to the input image;

[0009] Take adjacent characters in the text region that meet the preset conditions as two nodes, and the line segment connecting the two nodes as an undirected edge to create an undirected graph corresponding to the text region.

[0010] Traverse the nodes and undirected edges in the undirected graph, and take any two parallel undirected edges that share a common node as a text line segment to obtain a set of text line segments.

[0011] Based on the set of text line segments, determine the text line direction information corresponding to the input image.

[0012] In the above technical solution, by determining the text region of the input image, creating the undirected edges of the text region and its corresponding undirected graph, and traversing the nodes and undirected edges in the undirected graph to obtain the set of text line segments, the text line direction information of the input image can be determined. This solves the problem that existing image text line direction detection methods require model training on scene-related text line direction data, resulting in poor model universality. It realizes the recognition of text line direction in the image, thereby improving the recognition rate of text information.

[0013] Optionally, determining the text region corresponding to the input image includes: determining the text region corresponding to the input image according to the maximum extremum stable region algorithm.

[0014] Optionally, determining the text region corresponding to the input image based on the maximum extremum stable region algorithm includes: annotating the text in the input image using text boxes.

[0015] Optionally, after determining the text region corresponding to the input image according to the maximum extremum stable region algorithm, the method further includes: deleting text boxes that do not meet the preset aspect ratio; and / or, if a text box contains a sub-text box, deleting the sub-text box.

[0016] By employing the above design, deleting text boxes that do not meet the preset aspect ratio ensures that subsequent undirected edges connect between text elements, not between other non-textual elements. Deleting sub-text boxes ensures that subsequent undirected edges connect between adjacent text elements in the image, not between text elements that cross a space.

[0017] Optionally, adjacent characters that meet the preset conditions are those whose ratio of the distance between the centers of the text boxes corresponding to the adjacent characters to half the sum of the widths of the text boxes corresponding to the adjacent characters is less than or equal to the sum of the character spacing coefficient and 1, where the character spacing coefficient is a preset value.

[0018] Optionally, the text line direction information corresponding to the input image is determined based on the set of text line segments, including:

[0019] A first direction is determined based on the direction of each text line segment in the set of text line segments, wherein the number of text line segments in the set of text line segments with the first direction is the largest.

[0020] The text line direction information corresponding to the input image is determined based on the first direction, and the text line direction information corresponding to the input image includes the angle between the first direction and the horizontal direction.

[0021] In a second aspect, embodiments of the present invention provide an image text line direction calculation device, comprising:

[0022] The transceiver unit is used to acquire the input image;

[0023] The processing unit is used to determine the text region corresponding to the input image;

[0024] The processing unit is used to take adjacent characters in the text region that meet preset conditions as two nodes, and the line segment connecting the two nodes as an undirected edge, to create an undirected graph corresponding to the text region.

[0025] The processing unit is used to traverse the nodes and undirected edges in the undirected graph, take any two parallel undirected edges that have a common node as a text line segment, and obtain a set of text line segments.

[0026] The processing unit is used to determine the text line direction information corresponding to the input image based on the set of text line segments.

[0027] Optionally, the processing unit is configured to determine the text region corresponding to the input image according to the maximum extremum stable region algorithm when determining the text region corresponding to the input image.

[0028] Optionally, the processing unit is configured to annotate the text in the input image using text boxes when determining the text region corresponding to the input image according to the maximum extremum stable region algorithm.

[0029] Optionally, the processing unit is configured to delete text boxes that do not meet a preset aspect ratio after determining the text region corresponding to the input image according to the maximum extremum stable region algorithm; and / or, if a text box contains a sub-text box, delete the sub-text box.

[0030] Optionally, adjacent characters that meet the preset conditions are those whose ratio of the distance between the centers of the text boxes corresponding to the adjacent characters to half the sum of the widths of the text boxes corresponding to the adjacent characters is less than or equal to the sum of the character spacing coefficient and 1, where the character spacing coefficient is a preset value.

[0031] Optionally, the processing unit is configured to, when determining the text line direction information corresponding to the input image based on the text line segment set, determine a first direction based on the direction of each text line segment in the text line segment set, wherein the number of text line segments in the text line segment set with the first direction is the largest; and determine the text line direction information corresponding to the input image based on the first direction, wherein the text line direction information corresponding to the input image includes the angle between the first direction and the horizontal direction.

[0032] Thirdly, this application also provides an apparatus. This apparatus can perform the above-described method design. The apparatus may be a chip or circuit capable of performing the functions corresponding to the above-described method, or a device including the chip or circuit.

[0033] In one possible implementation, the device includes: a memory for storing computer-executable program code; and a processor coupled to the memory. The program code stored in the memory includes instructions that, when executed by the processor, cause the device or a device equipped with the device to perform any of the methods described above.

[0034] The device may also include a communication interface, which may be a transceiver, or, if the device is a chip or circuit, the communication interface may be the chip's input / output interface, such as input / output pins.

[0035] In one possible design, the device includes corresponding functional units, each used to implement the steps in the above method. The functions can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more units corresponding to the functions described above.

[0036] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when run on a device, executes the method described in any of the above possible designs.

[0037] Furthermore, the technical effects of any of the implementation methods in the second to fourth aspects can be found in the technical effects of different implementation methods in the first aspect, and will not be repeated here. Attached Figure Description

[0038] Figure 1 A flowchart of an image text line direction calculation method provided in an embodiment of the present invention;

[0039] Figure 2(a) is a schematic diagram of an input image provided in an embodiment of the present invention;

[0040] Figure 2(b) is a schematic diagram of an input image MSER algorithm for detecting marked text boxes according to an embodiment of the present invention;

[0041] Figure 3(a) is a schematic diagram of an overlapping and redundant area in a text box region provided by an embodiment of the present invention;

[0042] Figure 3(b) is a schematic diagram of an embodiment of the present invention that retains the most suitable text box;

[0043] Figure 4(a) is a schematic diagram of a text box containing multiple sub-text boxes provided in an embodiment of the present invention;

[0044] Figure 4(b) is a schematic diagram of a text box area after deleting a sub-text box according to an embodiment of the present invention;

[0045] Figure 5 An undirected connected graph of a text region provided in an embodiment of the present invention;

[0046] Figure 6 An apparatus 600 is provided for an embodiment of the present invention;

[0047] Figure 7 The present invention also provides another device 700. Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0049] The application scenarios described in the embodiments of this invention are for the purpose of more clearly illustrating the technical solutions of the embodiments of this invention, and do not constitute a limitation on the technical solutions provided by the embodiments of this invention. Those skilled in the art will understand that with the emergence of new application scenarios, the technical solutions provided by the embodiments of this invention are also applicable to similar technical problems. In the description of this invention, unless otherwise stated, "multiple" means two or more.

[0050] Currently, existing image text line direction detection methods use text line horizontal rectangle detection network models. These methods require the prior collection of a large amount of image text data containing annotation information from the application scenario as training data for model training. Furthermore, the distribution of the input image text data in this scenario differs significantly from the distribution of the training data. Alternatively, when the input is image text data from other scenarios, the text line horizontal rectangle detection network model may struggle to detect the line direction of the image text.

[0051] In view of this, the present application provides a method for calculating the text line direction in an image, which is used to solve the problem that existing methods for detecting the text line direction in an image require model training on scene-related text line direction data, resulting in poor model universality.

[0052] In the method for calculating the text line direction in an image proposed by the present application, the execution subject of the method may be a processor, a chip, etc., which is not limited in the present application. As Figure 1 shown, the specific steps are as follows:

[0053] Step 100: Acquire an input image.

[0054] Acquire any image whose text line direction needs to be calculated as the input image.

[0055] Step 200: Determine a text region corresponding to the input image.

[0056] For the input image, detection is performed using the Maximally Stable Extremal Regions (MSER) algorithm, and each character in the text portion of the image is labeled with a text bounding box, so that the text region of the image is obtained based on the text bounding boxes in the image. Among them, the MSER algorithm can be widely applied to various scenarios with strong applicability.

[0057] For example, Figure 2(a) is the input image, and Figure 2(b) is the text region obtained by detecting and marking text bounding boxes on the input image after applying the MSER algorithm, where the rectangular boxes in Figure 2(b) are the text bounding boxes that mark characters after detection by the MSER algorithm.

[0058] Optionally, preprocess the text region of the input image.

[0059] For the text region determined by the MSER algorithm in step 200, the MSER algorithm may make a judgment error and mark non-text portions in the image with text bounding boxes as well, so it is necessary to delete the text bounding boxes of the non-text portions.

[0060] For example, delete text bounding boxes that do not meet the aspect ratio requirement. For instance, the aspect ratio range of the text bounding boxes is set to the interval [r_min, r_max], and text regions with an aspect ratio < r_min or an aspect ratio > r_max are all regarded as text bounding boxes of non-text portions, which may also be referred to as interference regions and are deleted. Among them, this interval is a universal range determined based on empirical values and applicability to most scenarios, and the interval range can be adjusted appropriately for a few special scenarios.

[0061] For example, as shown in Figure 2(a) and Figure 2(b), the icon before "system optimized image" in Figure 2(a) is not text, but it is marked by a text box in Figure 2(b), and this text box needs to be deleted.

[0062] In addition, for the text region determined in step 200, overlapping and redundant text boxes need to be deleted. The overlapping and redundant text boxes refer to that the text box regions of different characters have overlapping areas, or one text box contains multiple sub-text boxes. For example, when there is an overlapping area between the text box regions of different characters, the most appropriate text box is retained, and the rest of the text boxes are deleted; when one text box contains multiple sub-text boxes, the sub-text boxes are deleted. Specifically, the overlapping and redundant text boxes can be deleted by using a Non-Maximum Suppression (NMS) algorithm. The NMS algorithm is used to calculate the overlapping area of any two overlapping and redundant text boxes. If the overlapping area is greater than a preset value, the text box with a larger area (or higher confidence, or closer aspect ratio) of the two text boxes is retained. The preset value can be set according to empirical values, which is not limited in this application.

[0063] For example, as shown in Figure 3(a), there are multiple overlapping and redundant text boxes in the text box region of the character "li", the NMS algorithm needs to be used to retain one most appropriate text box and delete the rest of the text boxes, and the result of the retained most appropriate text box at this time is shown in Figure 3(b).

[0064] For example, as shown in Figure 4(a), the text box region of the character "ti" contains multiple overlapping and redundant sub-text boxes, the NMS algorithm needs to be used to delete the multiple overlapping and redundant sub-text boxes, and the schematic diagram of the text box region after deleting the sub-text boxes is shown in Figure 4(b).

[0065] Step 300: Taking adjacent characters that meet a preset condition in the text region as two nodes, and taking the line segment connecting the two nodes as an undirected edge, an undirected graph corresponding to the text region is created.

[0066] Specifically, the adjacent characters that meet the preset condition refer to that the ratio of the distance between the centers of the text boxes respectively corresponding to the adjacent characters to half of the sum of the widths of the text boxes respectively corresponding to the adjacent characters is less than or equal to the sum of a character spacing coefficient and 1, where the character spacing coefficient is a preset value.

[0067] Specifically, the undirected edge refers to an edge without direction.

[0068] For example, a character spacing coefficient is set as β, which is a preset value of the distance between adjacent edges of the text boxes respectively corresponding to two adjacent characters. The value of β may vary according to different text paragraphs. The preset condition is that the ratio of the distance between the centers of the text boxes respectively corresponding to adjacent characters to half of the sum of the widths of the text boxes respectively corresponding to the adjacent characters is less than or equal to β+1 (β≥0). When adjacent characters satisfy the preset condition, an undirected edge can be established between the center points of the text boxes of the two characters, so as to ensure that the undirected edge is established between two adjacent characters, rather than between two characters separated by a space.

[0069] For example, as shown in Fig. 2(b), the value of β is 0, and the width of each text box is 2. In the figure, the distance between the centers of the text boxes respectively corresponding to the character "体" and the character "验" in "立即体验" is 2, so the ratio of the distance between the centers of the text boxes respectively corresponding to "体" and "验" to half of the sum of the widths of the text boxes respectively corresponding to "体" and "验" is 1 (2 / 2), which is equal to the preset condition 1 (0+1), and an undirected edge can be established. In the figure, the distance between the centers of the text boxes respectively corresponding to the character "验" in "立即体验" and the character "资" in "资源包限时3折" is 7, so the ratio of the distance between the centers of the text boxes respectively corresponding to "验" and "资" to half of the sum of the widths of the text boxes respectively corresponding to "验" and "资" is 3.5 (7 / 2), which is greater than the preset condition 1 (0+1), and no undirected edge can be established.

[0070] Based on this, the undirected edges of the text region can form an undirected graph corresponding to the text region. Specifically, M undirected graphs can be constructed for any image text region, where M≥1.

[0071] For example, as shown in Fig. 2(b), undirected edges can be established between every two of the four characters "立即体验" in the figure, and the corresponding undirected edges can be connected through nodes at this time, so that the text region of "立即体验" in Fig. 2(b) can construct one undirected graph.

[0072] For example, as shown in Fig. 2(b), undirected edges can be respectively established for "立即体验" and "资源包限时3折" in the figure, but no undirected edge can be established between "验" and "资". At this time, the undirected edges of "立即体验" form one undirected graph, and the undirected edges of "资源包限时3折" form another undirected graph. Therefore, the text region corresponding to Fig. 2(b) can construct a plurality of undirected graphs.

[0073] Step 400: Traverse the nodes and undirected edges in the undirected graph, take any two parallel undirected edges with a common passing node as one text line segment, and obtain a text line segment set.

[0074] The condition that any two parallel undirected edges with a common passing node are taken as one text line segment can be used as the judgment condition for a text line segment.

[0075] For example, with Figure 5 Taking the undirected graph shown as an example, Figure 5 It contains 11 nodes, corresponding to 11 undirected edges. The steps to obtain the set of text line segments are as follows:

[0076] (1) Set the initialization result of the text line segment set to Ls={}, and randomly set the initial starting point of the line segment. For example, take node2 as the initial starting point.

[0077] (2) Starting from the starting point, a depth-first traversal algorithm with the condition for determining text line segments is used to obtain the text line segments. Specifically, the depth-first traversal algorithm process is as follows: For example, starting from the starting point node 2, there are two undirected edges passing through node 2. The edge from node 2 to node 1 is called line segment 2-1, and the edge from node 2 to node 3 is called line segment 2-3. Since the above line segments have directionality, they are no longer called undirected edges, but the above line segments are determined by the undirected edges.

[0078] First, from node 2 to node 1, line segment 2-1 is formed, and the order in which line segment 2-1 passes through the nodes is represented as (2, 1). Since node 1 is the terminal node, we return to node 2 and switch to from node 2 to node 3, forming line segment 2-3 (2, 3). Based on the condition for determining the line segment, we know that line segment 2-1 is parallel to line segment 2-3, and both line segments pass through node 2. Therefore, line segment 1-3 (2, 1, 3) is formed, which is a single line segment. The order of the nodes in parentheses follows the order in which the nodes were traversed when forming the line segment.

[0079] Next, from node 3 to node 4, line segment 1-4 (2, 1, 3, 4) is obtained using a depth-first traversal algorithm. Similarly, from node 4 to node 5, line segment 1-5 (2, 1, 3, 4, 5) is obtained using the same algorithm. Since node 5 is the terminal node, we return to node 4 and switch to the line segment 4-6 (4, 6) from node 4 to node 6. Then, from node 6 to node 3, line segment 6-3 (6, 3) is formed. For ease of subsequent processing, all line segments in this application are uniformly arranged with numbers from smallest to largest, i.e., line segment 6-3 is considered as line segment 3-6. After judging the line segments in the text line, it is found that the directions of line segments 4-6 and 3-6 are inconsistent with the existing known line segments, and all undirected edges of line segment 1-5 have been traversed. Therefore, line segment 1-5 is traversed and placed into the text line segment set Ls.

[0080] Similarly, for Figure 5The remaining part is obtained by using a depth-first traversal algorithm to obtain line segments, which are then placed into the text line segment set Ls. Finally, Ls contains 6 line segments, that is, 6 text line segments, Ls={1—5(2,1,3,4,5),3—6(3,6),4—7(4,6,7),7—9(7,8,9),7—10(7,10),10—11(10,11)}.

[0081] Optionally, if the line segments in the text line segment set contain duplicate nodes, the duplicate nodes can be removed. Among these duplicate nodes, the longer line segments can be retained first.

[0082] Specifically, in the text line segment set Ls, segments 3-6 and 1-5 share a common node 3, so only node 6 is retained for segment 3-6. Segment 4-7 shares a common node 4 with segment 1-5 and also includes node 6, so segment 4-7 becomes 6-7(6, 7). Segment 7-9 shares a common node 7 with segment 6-7; since segment 7-9 is longer than segment 6-7, only node 6 is retained for segment 6-7. Similarly, segment 7-10 shares the same node 7 with segment 7-9 and the same node 10 with segment 10-11, so this segment is removed. The final text line segment set Ls = {1-5(2, 1, 3, 4, 5), 6, 7-9(7, 8, 9), 10-11(10, 11)}. Furthermore, Ls may not include node 6.

[0083] Step 500: Determine the text line direction information corresponding to the input image based on the set of text line segments.

[0084] Specifically, firstly, the first direction is determined based on the direction of each text line segment in the text line segment set. The first direction refers to the direction of the text line segment that appears most frequently in the text line segment set. Then, the angle between the first direction of the text line segment and the horizontal direction is calculated, thereby obtaining the text line direction information corresponding to the input image.

[0085] For example, it can be seen from the text line segment set Ls in step 400 that the line segments (i.e., text line segments) 1-5, 7-9, and 10-11 have the same direction, and these three text line segments appear most frequently. Therefore, this direction is the first direction, which is the text line direction of the input image. Since these three text line segments have the same direction, any text line segment can be selected, such as text line segment 1-5, and a coordinate system can be constructed for its nodes 1 and 5. Based on the coordinates of these two nodes, the angle between the text line segment and the horizontal direction can be calculated, which is the angle between the first direction and the horizontal direction. Thus, the text line direction information corresponding to the input image can be obtained.

[0086] This invention also provides a device 600, see [link to device 600]. Figure 6 As shown, it includes: a processing module 610 and a transceiver module 620.

[0087] The transceiver module 620 may include a receiving unit and a transmitting unit. The processing module 610 is used to control and manage the operation of the device 600. The transceiver module 620 is used to support communication between the device 600 and other devices. In one or more embodiments, the device 600 may further include a storage unit for storing the program code and data of the device 600.

[0088] In one or more embodiments, the various modules in the device 600 may be implemented by software.

[0089] In one or more embodiments, the processing module 610 may be a processor or controller, such as a general-purpose central processing unit (CPU), a general-purpose processor, a digital signal processing unit (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, modules, and circuits described in connection with the embodiments of this application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc. The transceiver module 620 may be a communication interface, transceiver, or transceiver circuit, etc., wherein the communication interface is a general term, and in a specific implementation, the communication interface may include multiple interfaces, and the storage unit may be a memory.

[0090] The transceiver module 620 is used to acquire the input image;

[0091] Processing module 610 is used to determine the text region corresponding to the input image;

[0092] The processing module 610 is used to take adjacent characters in the text region that meet preset conditions as two nodes, and the line segment connecting the two nodes as an undirected edge, to create an undirected graph corresponding to the text region.

[0093] The processing module 610 is used to traverse the nodes and undirected edges in the undirected graph, take any two parallel undirected edges that have a common node as a text line segment, and obtain a set of text line segments.

[0094] The processing module 610 is used to determine the text line direction information corresponding to the input image based on the set of text line segments.

[0095] This invention also provides another device 700, see [link to previous document]. Figure 7 As shown, it includes:

[0096] Communication interface 701, memory 702, and processor 703;

[0097] The communication device 700 communicates with other devices through the communication interface 701, such as sending and receiving messages; the memory 702 is used to store program instructions; and the processor 703 is used to call the program instructions stored in the memory 702 and execute them according to the obtained program.

[0098] Processor 703 executes program instructions stored in communication interface 701 and memory 702:

[0099] Obtain the input image;

[0100] Determine the text region corresponding to the input image;

[0101] Take adjacent characters in the text region that meet the preset conditions as two nodes, and the line segment connecting the two nodes as an undirected edge to create an undirected graph corresponding to the text region.

[0102] Traverse the nodes and undirected edges in the undirected graph, and take any two parallel undirected edges that share a common node as a text line segment to obtain a set of text line segments.

[0103] Based on the set of text line segments, determine the text line direction information corresponding to the input image.

[0104] In this embodiment of the invention, the specific connection medium between the communication interface 701, the memory 702 and the processor 703 is not limited, such as a bus. A bus can be divided into an address bus, a data bus, a control bus, etc.

[0105] In this embodiment of the invention, the processor may be a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in this embodiment of the invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in this embodiment of the invention can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.

[0106] In embodiments of the present invention, the memory can be non-volatile memory, such as a hard disk drive (HDD) or a solid-state drive (SSD), or it can be volatile memory, such as random-access memory (RAM). The memory can also be any other medium capable of carrying or storing desired program code having an instruction or data structure form and accessible by a computer, but is not limited thereto. The memory in embodiments of the present invention can also be a circuit or any other device capable of implementing a storage function for storing program instructions and / or data.

[0107] This invention also provides a computer-readable storage medium including program code. When the program code is run on a computer, the program code is used to cause the computer to perform the steps of the method provided in the above embodiments of this invention.

[0108] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0109] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0110] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0111] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0112] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0113] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.

Claims

1. A method for calculating the direction of text lines in an image, characterized in that The method includes: Obtain the input image; Determine the text region corresponding to the input image; Adjacent characters in the text region that meet preset conditions are treated as two nodes, and the line segments connecting the two nodes are treated as undirected edges, creating an undirected graph corresponding to the text region. Adjacent characters that meet the preset conditions are those whose ratio of the distance between the centers of the text boxes corresponding to the adjacent characters to half the sum of the widths of the text boxes corresponding to the adjacent characters is less than or equal to the sum of the character spacing coefficient and 1, where the character spacing coefficient is a preset value. M undirected graphs are constructed for any text region, where M≥1. Traverse the nodes in the undirected graph, and return to the node that is passed through when the terminal node is encountered; take any two parallel undirected edges that have the node that is passed through as a text line segment, and obtain the set of text line segments. A first direction is determined based on the direction of each text line segment in the set of text line segments, wherein the number of text line segments in the set whose direction is the first direction is the largest; the text line direction information corresponding to the input image is determined based on the first direction, wherein the text line direction information corresponding to the input image includes the angle between the first direction and the horizontal direction.

2. The method of claim 1, wherein, Determining the text region corresponding to the input image includes: The text region corresponding to the input image is determined based on the maximum extremum stable region algorithm.

3. The method as described in claim 2, characterized in that, The step of determining the text region corresponding to the input image based on the maximum extremum stable region algorithm includes: The text in the input image is annotated using text boxes.

4. The method as described in claim 3, characterized in that, After determining the text region corresponding to the input image according to the maximum extremum stable region algorithm, the method further includes: Delete text boxes that do not meet the preset aspect ratio; And / or, if a text box contains a child text box, then delete the child text box.

5. A device for calculating the line direction of image text, characterized in that, The device includes: The transceiver unit is used to acquire the input image; The processing unit is used to determine the text region corresponding to the input image; The processing unit is used to take adjacent characters in the text region that meet preset conditions as two nodes, and the line segment connecting the two nodes as an undirected edge, to create an undirected graph corresponding to the text region; adjacent characters that meet the preset conditions are those whose ratio of the distance between the centers of the text boxes corresponding to the adjacent characters to half the sum of the widths of the text boxes corresponding to the adjacent characters is less than or equal to the sum of the character spacing coefficient and 1, where the character spacing coefficient is a preset value; M undirected graphs are constructed for any text region, where M≥1; The processing unit is used to traverse the nodes in the undirected graph, and when it encounters a terminal node, it returns to the node that it has passed through together; and takes any two parallel undirected edges that have passed through the node as a text line segment to obtain a set of text line segments. The processing unit is configured to determine a first direction based on the direction of each text line segment in the text line segment set, wherein the number of text line segments in the text line segment set that have the first direction is the largest; and to determine the text line direction information corresponding to the input image based on the first direction, wherein the text line direction information corresponding to the input image includes the angle between the first direction and the horizontal direction.

6. The apparatus as claimed in claim 5, characterized in that, The processing unit is used to determine the text region corresponding to the input image according to the maximum extremum stable region algorithm when determining the text region corresponding to the input image.

7. The apparatus as claimed in claim 6, characterized in that, The processing unit is used to annotate the text in the input image using text boxes when determining the text region corresponding to the input image according to the maximum extremum stable region algorithm.

8. The apparatus as claimed in claim 7, characterized in that, The processing unit is configured to, after determining the text region corresponding to the input image according to the maximum extremum stable region algorithm, delete text boxes that do not meet the preset aspect ratio; and / or, if a text box contains a sub-text box, delete the sub-text box.

9. A device for calculating the line direction of image text, characterized in that, The device includes a processor and an interface circuit, the interface circuit being used to receive signals from other devices outside the device and transmit them to the processor or to send signals from the processor to other devices outside the device, the processor being used to implement the method as described in any one of claims 1 to 4 via logic circuits or execution code instructions.

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

Citation Information

Patent Citations

  • Methods and apparatus for inferring orientation of lines of text

    US5664027A