Text content writing direction identification method and device
By extracting and analyzing the unified character encoding and character external coordinate boxes of text objects, the problem of not being able to identify the writing direction of text content in the prior art is solved, and the accurate identification and processing of the writing direction of text content is achieved.
Patent Information
- Application Number
- CN202311051329.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-18
- Publication Date
- 2025-02-21
AI Technical Summary
The prior art cannot effectively identify the writing direction of text content, resulting in difficulty in identifying and processing subsequent texts.
By extracting multiple text objects in the target text content to be identified, the unified character encoding and character external coordinate boxes of each text object are determined, and the writing direction of the target text content is determined based on these characteristics.
It realizes accurate identification of the writing direction of text content, which is conducive to subsequent text recognition and processing, and is suitable for a variety of application scenarios.
Smart Images

Figure CN119494335A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of text processing, and in particular to a method and device for identifying the writing direction of text content. Background Art
[0002] With the development of office applications, the use of office software to create documents has replaced manual writing in a wide range. Even though the use of office software to create documents can replace manual writing, the layout of the documents still needs to be carried out according to the writing direction of the language used. For example, for classical Chinese, the writing direction is from top to bottom in the line direction and from right to left in the paragraph direction. For simplified Chinese, the writing direction is from left to right in the line direction and from top to bottom in the paragraph direction.
[0003] Furthermore, in some application scenarios, such as text reformatting scenarios, correctly identifying the writing direction of text content is a prerequisite for subsequent text recognition and processing. Therefore, correctly identifying the writing direction of text content has very important application significance.
[0004] To this end, no effective solution has been proposed in the prior art. Summary of the invention
[0005] The present application provides a method and device for identifying the writing direction of text content, so as to solve the technical problem that the writing direction of text content cannot be identified in the prior art.
[0006] In a first aspect, the present application provides a method for identifying a writing direction of text content, the method comprising:
[0007] Extracting a plurality of text objects included in the target text content to be recognized;
[0008] Determine the Unicode and character circumscribed coordinate frame of each of the text objects;
[0009] Determine a first typesetting salient feature of the target text content according to the unified character encoding of each of the text objects, and determine a second typesetting salient feature of the target text content according to a character circumscribed coordinate frame of each of the text objects;
[0010] The writing direction of the target text content is determined according to the first typesetting prominent feature and / or the second typesetting prominent feature.
[0011] Optionally, determining the writing direction of the target text content according to the first typesetting prominent feature and / or the second typesetting prominent feature includes:
[0012] Determining the writing direction of the target text content according to the first typesetting salient feature;
[0013] Alternatively, when the writing direction of the target text content cannot be determined according to the first typesetting salient feature, the writing direction of the target text content is determined according to the second typesetting salient feature.
[0014] Optionally, determining the first typesetting salient feature of the target text content according to the unified character encoding of each of the text objects includes:
[0015] Determine the character type of each text object according to the unified character code of each text object, and determine the proportion of text objects of each character type in the target text content;
[0016] The character types and the proportions involved in the target text content are determined as the first typesetting salient features of the target text content.
[0017] Optionally, determining the second typesetting salient feature of the target text content according to the character circumscribed coordinate frame of each of the text objects includes:
[0018] Determining the number of rows and columns of the target text content according to the character circumscribed coordinate frame of each of the text objects, and determining the horizontal projection statistics in the horizontal direction and the vertical projection statistics in the vertical direction of all the text objects in the target text content according to the character circumscribed coordinate frame of each of the text objects;
[0019] The number of rows, the number of columns, the horizontal projection statistics, and the vertical projection statistics are determined as second layout salient features of the target text content.
[0020] Optionally, determining the number of rows and columns of the target text content according to the character circumscribed coordinate frame of each text object includes:
[0021] Determine the average width and average height of the character bounding box of all text objects;
[0022] Determine a total circumscribed coordinate frame of all text objects, and determine a total width and a total height of the total circumscribed coordinate frame;
[0023] The number of columns of the target text content is determined according to the total width and the average width, and the number of rows of the target text content is determined according to the total height and the average height.
[0024] Optionally, determining the horizontal projection statistics in the horizontal direction and the vertical projection statistics in the vertical direction of all the text objects in the target text content according to the character circumscribed coordinate frame of each of the text objects includes:
[0025] Constructing a horizontal projection array and a vertical projection array, wherein each element in the horizontal projection array corresponds to a width interval in sequence, and each element in the vertical projection array corresponds to a height interval in sequence, the width interval is obtained by dividing the total width of the total circumscribed coordinate frame of all text objects in the target text content, and the height interval is obtained by dividing the total height of the total circumscribed coordinate frame of all text objects in the target text content;
[0026] Traverse each text object in the target text content, and perform the following processing on the traversed text object:
[0027] Determine a target width interval and a target height interval where a character circumscribed coordinate frame of the traversed text object is located;
[0028] Add a first preset value to the value of the element corresponding to the target width interval in the horizontal projection array, and add a second preset value to the value of the element corresponding to the target height interval in the vertical projection array;
[0029] After the traversal is completed, the horizontal projection array is determined as the horizontal projection statistics of all text objects in the target text content in the horizontal direction, and the vertical projection array is determined as the vertical projection statistics of all text objects in the target text content in the vertical direction.
[0030] Optionally, determining the writing direction of the target text content according to the first typesetting significant feature includes:
[0031] When it is determined according to the first typesetting significant feature that the character types of all text objects in the target text content belong to a first specified character type set, determining the writing direction of the target text content to be a first preset writing direction;
[0032] When it is determined according to the first typesetting significant feature that there is a text object in the target text content whose character type belongs to the second specified character type set and the proportion corresponding to the text object exceeds a preset proportion threshold, determining the writing direction of the target text content to be a second preset writing direction;
[0033] When it is determined according to the first typesetting significant feature that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the third specified character type set and the proportion corresponding to the text object exceeds the preset proportion threshold, determining that the writing direction of the target text content is the third preset writing direction;
[0034] When it is determined based on the first typesetting salient feature that there is no text object in the target text content whose character type belongs to the second specified character type set, and there is a text object whose character type belongs to the fourth specified character type set and the proportion corresponding to this text object exceeds the preset proportion threshold, the writing direction of the target text content is determined to be the first preset writing direction.
[0035] Optionally, the method further includes:
[0036] determining a font and writing mode to be used by each of said text objects;
[0037] When it is determined that there are text objects using a specified font and a specified writing mode in the target text content and the proportion of such text objects in the target text content exceeds a preset proportion threshold, the writing direction of the target text content is determined to be a second preset writing direction.
[0038] Optionally, determining the writing direction of the target text content according to the second typesetting significant feature includes:
[0039] When the number of lines is less than a set value, determining the writing direction of the target text content to be a first preset writing direction;
[0040] When the number of lines is not less than the set value, the writing direction of the target text content is determined according to the horizontal projection statistic and the vertical projection statistic.
[0041] Optionally, determining the writing direction of the target text content according to the horizontal projection statistics and the vertical projection statistics includes:
[0042] Determine the number of horizontal gaps in the target text content in the horizontal direction according to the horizontal projection statistics, and determine the number of vertical gaps in the target text content in the vertical direction according to the vertical projection statistics;
[0043] Determine the line writing direction of the target text content according to the number of horizontal gaps, the number of vertical gaps, the number of rows and the number of columns;
[0044] The writing direction of the target text content is determined according to the line writing direction of the target text content and the rotation angle of the text object of the specified character type in the target text content.
[0045] Optionally, determining the writing direction of the target text content according to the line writing direction of the target text content and the rotation angle of a text object of a specified character type in the target text content includes:
[0046] When the target text content has a horizontal writing direction and the rotation angle of a text object whose character type belongs to a second specified character type set in the target text content satisfies a first rotation condition, determining the writing direction of the target text content to be a second preset writing direction;
[0047] When the writing direction of the target text content is vertical and the rotation angle of the text object whose character type belongs to the second specified character type set in the target text content satisfies the second rotation condition, determining the writing direction of the target text content to be the second preset writing direction;
[0048] When the line writing direction of the target text content is vertical and the rotation angle of the text object whose character type in the target text content belongs to the first specified character type set satisfies the first rotation condition, the writing direction of the target text content is determined to be the second preset writing direction.
[0049] Optionally, determining the line writing direction of the target text content according to the number of horizontal gaps, the number of vertical gaps, the number of rows, and the number of columns includes:
[0050] Dividing the number of horizontal gaps by the number of columns to obtain a first quotient, and dividing the number of vertical gaps by the number of rows to obtain a second quotient;
[0051] In the case where the first quotient value and the second quotient value satisfy a first set condition, determining that the line writing direction of the target text content is vertical;
[0052] In the case where the first quotient value and the second quotient value satisfy a second set condition, determining that the line writing direction of the target text content is horizontal;
[0053] In the case that neither the first setting condition nor the second setting condition is satisfied between the first quotient value and the second quotient value, determining a first variance of all elements in the horizontal projection statistics, and determining a second variance of all elements in the vertical projection statistics;
[0054] When the first variance is greater than the second variance, the writing direction of the target text content is determined to be vertical; when the first variance is less than or equal to the second variance, the writing direction of the target text content is determined to be horizontal.
[0055] In a second aspect, the present application provides a device for identifying the writing direction of text content, the device comprising:
[0056] An object extraction module, used to extract a plurality of text objects included in the target text content to be identified;
[0057] A first determination module is used to determine the unified character code and character circumscribed coordinate frame of each of the text objects;
[0058] A second determination module is used to determine the first typesetting salient feature of the target text content according to the unified character encoding of each of the text objects;
[0059] A third determination module is used to determine the second typesetting salient feature of the target text content according to the character circumscribed coordinate frame of each text object;
[0060] The fourth determination module is used to determine the writing direction of the target text content according to the first typesetting significant feature and / or the second typesetting significant feature.
[0061] Optionally, the fourth determining module includes:
[0062] A first determining unit, configured to determine a writing direction of the target text content according to the first typesetting salient feature;
[0063] The second determination unit is used to determine the writing direction of the target text content according to the second typesetting significant feature when the writing direction of the target text content cannot be determined according to the first typesetting significant feature.
[0064] Optionally, the second determining module includes:
[0065] A character type identification unit, used to determine the character type of each text object according to the unified character code of each text object;
[0066] A ratio determination unit, used to determine the ratio of text objects of a specified character type in the target text content;
[0067] The first feature determination unit is used to determine the character type and the proportion involved in the target text content as the first typesetting significant feature of the target text content.
[0068] Optionally, the third determining module includes:
[0069] A row and column number determination unit, used to determine the number of rows and columns of the target text content according to the character circumscribed coordinate frame of each text object;
[0070] A projection statistic determining unit, used for determining horizontal projection statistics in the horizontal direction and vertical projection statistics in the vertical direction for all text objects in the target text content according to a character circumscribed coordinate frame of each text object;
[0071] The second feature determination unit is used to determine the number of rows, the number of columns, the horizontal projection statistics and the vertical projection statistics as second layout salient features of the target text content.
[0072] Optionally, the row and column number determination unit includes:
[0073] The average size determination subunit is used to determine the average width and average height of the character circumscribed coordinate boxes of all text objects;
[0074] A total size determination subunit, used to determine a total circumscribed coordinate frame of all text objects, and determine a total width and a total height of the total circumscribed coordinate frame;
[0075] The first calculation subunit is used to determine the number of columns of the target text content according to the total width and the average width, and to determine the number of rows of the target text content according to the total height and the average height.
[0076] Optionally, the projection statistic determining unit includes:
[0077] An initial array construction subunit is used to construct a horizontal projection array and a vertical projection array, wherein each element in the horizontal projection array corresponds to a width interval in turn, and each element in the vertical projection array corresponds to a height interval in turn, the width interval is obtained by dividing the total width of the total circumscribed coordinate frame of all text objects in the target text content, and the height interval is obtained by dividing the total height of the total circumscribed coordinate frame of all text objects in the target text content;
[0078] A traversal subunit is used to traverse each text object in the target text content, and perform the following processing on the traversed text object: determine the target width interval and target height interval where the character circumscribed coordinate frame of the traversed text object is located; add a first preset value to the value of the element corresponding to the target width interval in the horizontal projection array, and add a second preset value to the value of the element corresponding to the target height interval in the vertical projection array;
[0079] The first determination subunit is used to determine the horizontal projection array as the horizontal projection statistics of all text objects in the target text content in the horizontal direction after the traversal is completed, and to determine the vertical projection array as the vertical projection statistics of all text objects in the target text content in the vertical direction.
[0080] Optionally, the first determining unit includes:
[0081] A second determination subunit is used to determine that the writing direction of the target text content is a first preset writing direction when it is determined according to the first typesetting significant feature that the character types of all text objects in the target text content belong to a first specified character type set;
[0082] A third determination subunit is used to determine that the writing direction of the target text content is a second preset writing direction when it is determined according to the first typesetting significant feature that there is a text object whose character type belongs to a second specified character type set in the target text content and the proportion corresponding to the text object exceeds a preset proportion threshold;
[0083] a fourth determination subunit, configured to determine that the writing direction of the target text content is a third preset writing direction, when it is determined according to the first typesetting significant feature that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the third specified character type set and the proportion corresponding to the text object exceeds a preset proportion threshold value;
[0084] The fifth determination subunit determines that the writing direction of the target text content is the first preset writing direction when it is determined based on the first typesetting salient feature that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the fourth specified character type set and the proportion corresponding to this text object exceeds a preset proportion threshold.
[0085] Optionally, the device further comprises:
[0086] A font and mode determination module, used to determine the font and writing mode used by each of the text objects;
[0087] The fifth determination module is used to determine that the writing direction of the target text content is a second preset writing direction when it is determined that there are text objects using a specified font and a specified writing mode in the target text content and the proportion of such text objects in the target text content exceeds a preset proportion threshold.
[0088] A third determination subunit is used to determine that the writing direction of the target text content is a second preset writing direction when it is determined according to the first typesetting significant feature that there is a text object whose character type belongs to a second specified character type set in the target text content and the corresponding ratio exceeds a preset ratio threshold;
[0089] a fourth determination subunit, configured to determine that the writing direction of the target text content is a third preset writing direction, when it is determined according to the first typesetting significant feature that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the third specified character type set and the corresponding ratio exceeds a preset ratio threshold value;
[0090] The fifth determination subunit is used to determine that the writing direction of the target text content is the first preset writing direction when it is determined based on the first typesetting salient features that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the fourth specified character type set, and the corresponding ratio exceeds a preset ratio threshold.
[0091] Optionally, the second determining unit includes:
[0092] A sixth determining subunit, configured to determine, when the number of lines is less than a set value, that the writing direction of the target text content is a first preset writing direction;
[0093] A seventh determination subunit is configured to determine the writing direction of the target text content according to the horizontal projection statistic and the vertical projection statistic when the number of lines is not less than the set value.
[0094] Optionally, the seventh determining subunit includes:
[0095] a gap number determination subunit, configured to determine the number of horizontal gaps existing in the target text content in the horizontal direction according to the horizontal projection statistic, and to determine the number of vertical gaps existing in the target text content in the vertical direction according to the vertical projection statistic;
[0096] A line writing direction determining subunit, used to determine the line writing direction of the target text content according to the number of horizontal gaps, the number of vertical gaps, the number of rows and the number of columns;
[0097] The eighth determination subunit is used to determine the writing direction of the target text content according to the line writing direction of the target text content and the rotation angle of the text object of the specified character type in the target text content.
[0098] Optionally, the eighth determining subunit is specifically configured to:
[0099] When the target text content has a horizontal writing direction and the rotation angle of a text object whose character type belongs to a second specified character type set in the target text content satisfies a first rotation condition, determining the writing direction of the target text content to be a second preset writing direction;
[0100] When the writing direction of the target text content is vertical and the rotation angle of the text object whose character type belongs to the second specified character type set in the target text content satisfies the second rotation condition, determining the writing direction of the target text content to be the second preset writing direction;
[0101] When the line writing direction of the target text content is vertical and the rotation angle of the text object whose character type in the target text content belongs to the first specified character type set satisfies the first rotation condition, the writing direction of the target text content is determined to be the second preset writing direction.
[0102] Optionally, the line writing direction determination subunit includes:
[0103] A second calculation subunit is used to divide the number of horizontal gaps by the number of columns to obtain a first quotient, and divide the number of vertical gaps by the number of rows to obtain a second quotient;
[0104] A ninth determining subunit, configured to determine that the line writing direction of the target text content is vertical when a first set condition is satisfied between the first quotient value and the second quotient value;
[0105] In the case where the first quotient value and the second quotient value satisfy a second set condition, determining that the line writing direction of the target text content is horizontal;
[0106] In the case that neither the first setting condition nor the second setting condition is satisfied between the first quotient value and the second quotient value, determining a first variance of all elements in the horizontal projection statistics, and determining a second variance of all elements in the vertical projection statistics;
[0107] When the first variance is greater than the second variance, the writing direction of the target text content is determined to be vertical; when the first variance is less than or equal to the second variance, the writing direction of the target text content is determined to be horizontal.
[0108] In a third aspect, the present application provides an electronic device comprising: a processor and a memory, wherein the processor is used to execute a text content writing direction recognition program stored in the memory to implement the text content writing direction recognition method described in any one of the first aspects.
[0109] In a fourth aspect, the present application provides a storage medium storing one or more programs, which can be executed by one or more processors to implement the method for identifying the writing direction of text content described in any one of the first aspects.
[0110] The above-mentioned technical scheme provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application, by extracting multiple text objects included in the target text content to be identified, determines the unified character code and the character external coordinate frame of each text object, determines the first typesetting significant feature of the target text content according to the unified character code of each text object, and determines the second typesetting significant feature of the target text content according to the character external coordinate frame of each text object, determines the writing direction of the target text content according to the first typesetting significant feature and / or the second typesetting significant feature, thereby realizing the identification of the writing direction of the text content, facilitating subsequent text recognition and processing, and has very important application significance in many application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0111] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0112] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0113] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0114] Figure 1 A flowchart of an embodiment of a method for identifying the writing direction of text content provided in an embodiment of the present application;
[0115] Figure 2 A specific implementation flow chart for determining the writing direction of the target text content according to the first typesetting salient features;
[0116] Figure 3 It is a scene diagram of the statistical process of horizontal projection statistics;
[0117] Figure 4 A flow chart of an embodiment for determining the writing direction of target text content according to horizontal projection statistics and vertical projection statistics;
[0118] Figure 5 A flow chart of an embodiment for determining the line writing direction of target text content according to the number of horizontal gaps, the number of vertical gaps, the number of rows and the number of columns;
[0119] Figure 6 A block diagram of an embodiment of a device for identifying the writing direction of text content provided in an embodiment of the present application;
[0120] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0121] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings 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 making creative work are within the scope of protection of this application.
[0122] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0123] In order to solve the technical problem that the prior art cannot effectively identify the writing direction of text content, the present application provides a method and device for identifying the writing direction of text content, which can realize the identification of the writing direction of text content and facilitate subsequent text recognition and processing.
[0124] Figure 1 The following is a flow chart of an embodiment of a method for identifying the writing direction of text content provided in an embodiment of the present application. Figure 1 As shown, the following steps are included:
[0125] Step 101: extract multiple text objects included in the target text content to be recognized.
[0126] The above-mentioned target text content refers to all or part of the text content in the document. The document can be a layout document in a format such as .pdf, .ofd, etc., or a document in a picture format such as .jpg, .jpeg, etc. For a document in picture format, it can be converted into a layout document through OCR (Optical Character Recognition) technology and scanned document recognition technology. In the case where the target text content refers to part of the text content in the document, the target text content can be one or several paragraphs in the document. The embodiment of the present application does not limit the specific form of the document and the target text content.
[0127] Taking a document in .pdf format as an example, the method provided in this application can be used to identify the writing direction of the text in each paragraph, which has the following application significance: it is convenient to determine the direction and order of text editing during PDF editing, it is convenient to determine the writing direction of text when converting to streaming documents, it is convenient to determine the reading order of text when reflowing PDF, and so on.
[0128] In one embodiment, a text extractor may be used to extract multiple text objects included in the target text content to be recognized.
[0129] Step 102: Determine the Unicode and character circumscribed coordinate frame of each text object.
[0130] Unicode is a unified and unique binary code set for each character in each language in the field of computer science. For example, the code range of basic Latin characters is 0x00 to 0x7f, and the code range of Mongolian characters is 0x1800 to 0x18af. It can be seen that the character type of a text object can be determined by the Unicode of the text object.
[0131] The character external coordinate box of a text object refers to the smallest rectangular box that can surround the text object.
[0132] The unified character encoding and character external coordinate frame are attributes of the text object. In addition, the text object can also include attributes such as character code (CharCode), font information (Font), rotation angle (ie, transformation matrix), etc.
[0133] Step 103: determining a first typesetting salient feature of the target text content according to the unified character encoding of each text object, and determining a second typesetting salient feature of the target text content according to the character circumscribed coordinate frame of each text object.
[0134] Step 104: Determine the writing direction of the target text content according to the first typesetting prominent feature and / or the second typesetting prominent feature.
[0135] The following is a unified description of step 103 and step 104:
[0136] In the embodiment of the present application, the typesetting significant feature refers to a feature that has a clear characterization meaning for the writing direction. As can be seen from the descriptions in step 103 and step 104, in the embodiment of the present application, the typesetting significant features are extracted from two aspects, namely, the first typesetting significant feature of the target text content determined according to the unified character encoding of each text object in the target text content, and the second typesetting significant feature of the target text content determined according to the character circumscribed coordinate frame of each text object in the target text content, and then the writing direction of the target text content is determined according to the first typesetting significant feature and / or the second typesetting significant feature.
[0137] That is to say, in the embodiment of the present application, the writing direction of the target text content can be determined from two aspects: the unified character encoding of the text object and the character external coordinate frame. Here, the writing direction includes three types: LrTb, RlTb and TbRl. Among them, LrTb refers to typeset from left to right in the row direction and typeset from top to bottom in the paragraph direction. In practical applications, most types of characters adopt this writing direction. RlTb refers to typeset from right to left in the row direction and typeset from top to bottom in the paragraph direction. In practical applications, it is common in the writing system using Arabic / Hebrew languages. TbRl refers to typeset from top to bottom in the row direction and typeset from right to left in the paragraph direction. In practical applications, it is common in the writing system using languages such as ancient Chinese, Japanese, or Mongolian.
[0138] As described above, the character type of the text object can be determined by the unified character encoding of the text object, and for some character types, their writing directions are conventionally known. For example, ancient Chinese characters, Japanese characters, or Mongolian characters use the TbRl writing direction, and Arabic / Hebrew characters use the RlTb writing direction. Therefore, in the embodiment of the present application, the writing direction of the target text content can be determined based on the first typesetting salient feature of the target text content.
[0139] The character external coordinate frame can also reflect the layout characteristics of the text object. Therefore, in the embodiment of the present application, the writing direction of the target text content can also be determined according to the second typesetting significant feature of the target text content.
[0140] In one embodiment, the writing direction of the target text content can be determined first according to the first typesetting prominent feature. If the writing direction of the target text content can be determined according to the first typesetting prominent feature, the writing direction determined according to the first typesetting prominent feature is directly used. If the writing direction of the target text content cannot be determined according to the first typesetting prominent feature, the writing direction of the target text content is determined according to the second typesetting prominent feature. Through this processing, on the one hand, the accuracy of the recognized writing direction can be prioritized, and on the other hand, the determination of the writing direction when the unified character encoding is not provided can be supported.
[0141] In one embodiment, determining the first typesetting salient feature of the target text content based on the uniform character encoding of each text object includes: determining the character type of each text object based on the uniform character encoding of each text object, and determining the proportion of text objects of a specified character type in the target text content, and determining the character types and proportions involved in the target text content (referring to the proportion of text objects of each character type involved in the target text content in the target text content) as the first typesetting salient feature of the target text content.
[0142] The above-mentioned designated character types refer to character types with strong and obvious characteristics in writing direction. In other words, the designated character types refer to character types whose writing direction can be clearly determined based on the character types, including but not limited to: Latin characters, CJK (Chinese, Japanese and Korean Unified Ideographs) characters, Mongolian characters, Unicode characters written from right to left, Unicode characters written from left to right, and the like.
[0143] Here, three character type sets are divided according to the writing direction, namely, a first designated character type set, a second designated character type set, and a third designated character type set. Among them, the first designated character type set includes character types using the LrTb writing direction, such as Latin characters. The second designated character type set includes character types using the TbRl writing direction, such as CJK characters and Mongolian characters. The third designated character type set includes Unicode characters written from right to left.
[0144] In one embodiment, determining the writing direction of the target text content according to the first typesetting significant feature includes: when it is determined according to the first typesetting significant feature that the character types of all text objects in the target text content belong to the first specified character type set, determining the writing direction of the target text content to be the first preset writing direction. Here, the first preset writing direction is LrTb. It should be noted that the actual writing direction of Mongolian is TbLr, but in the current PDF standard, only three attribute directions, LrTb, RlTb, and TbRl, are given. In the embodiment of the present application, in order to be consistent with the standard and for convenience, the vertical direction is uniformly considered to be TbRl.
[0145] When it is determined based on the first typesetting salient feature that there are text objects in the target text content whose character types belong to the second specified character type set and the corresponding ratio of such text objects exceeds the preset ratio threshold, the writing direction of the target text content is determined to be the second preset writing direction. Here, the second preset writing direction is TbR1, and the value range of the preset ratio threshold is [1 / 2, 1]. Here, based on the probability theory, when there are at least half of the text objects in the second specified character type set in the target text content, the writing direction of the target text content is determined to be the second preset writing direction, and therefore, the lower limit of the value range of the preset ratio threshold is set to 1 / 2.
[0146] When it is determined based on the first typesetting salient feature that there are no text objects in the target text content whose character types belong to the second specified character type set (this means that the target text content is horizontal, and it is necessary to determine whether it is from left to right or from right to left later), and there are text objects whose character types belong to the third specified character type set and the corresponding ratio of this type of text object exceeds the preset ratio threshold, the writing direction of the target text content is determined to be the third preset writing direction. Here, the third preset writing direction is RlTb, and the preset ratio threshold is [1 / 2, 1]. This is based on probability theory. When there are at least half of the text objects in the third specified character type set in the target text content, the writing direction of the target text content is determined to be the third preset writing direction. Therefore, the lower limit of the value range of the preset ratio threshold is set to 1 / 2.
[0147] When it is determined based on the first typesetting significant feature that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the third specified character type set and the proportion corresponding to this text object does not exceed the preset proportion threshold, the writing direction of the target text content is determined to be the first preset writing direction.
[0148] In addition, when the writing direction of the target text content cannot be determined according to the above description, the font and writing mode used by each text object can be further determined. When it is determined that there are text objects using the specified font and the specified writing mode in the target text content and the proportion of such text objects in the target text content exceeds the preset proportion threshold, the writing direction of the target text content is determined to be the second preset writing direction. Here, the specified font is the CIDFont font, and the specified writing mode is the vertical writing mode (horizontal writing mode). Among them, the CIDFont font refers to a character identification font (Character Identifier Font, referred to as CIDFont font), which is different from traditional font formats (such as TrueType or Type1). It uses character identifiers (Character Identifier, referred to as CID) to represent characters instead of using Unicode encoding or other standard encodings of characters. In CIDFont, each character is represented by a unique CID, and this CID is mapped to glyph data. CIDFont contains the attribute Vertical Writing, so the CIDFont font can be used to determine the writing direction in the embodiment of the present application.
[0149] Based on the above description, as an optional implementation method, the specific implementation process of determining the writing direction of the target text content according to the first typesetting salient feature is as follows: Figure 2 As shown, the following steps are included:
[0150] Step 201 , determining whether all text objects in the target text content are Latin characters based on the first typesetting salient feature; if so, executing step 206 , otherwise, executing step 202 .
[0151] Step 202: determine whether there is a text object of CJK or Mongolian characters in the target text content according to the first typesetting significant feature; if so, execute step 203; otherwise, execute step 204.
[0152] Step 203 , determining the proportion of text objects in CJK or Mongolian characters in the target text content, if the proportion exceeds 1 / 2, executing step 207 , otherwise, executing step 205 .
[0153] Step 204, determine whether there are Unicode characters written from right to left in the target text content; if there are and the corresponding ratio exceeds 1 / 2, execute step 208, if there are and the corresponding ratio does not exceed 1 / 2, execute step 206, if not, execute step 205.
[0154] Step 205, determine the font and writing mode used by each text object. If it is determined that there are text objects using the CIDFont font and the vertical writing mode in the target text content and the proportion of such text objects in the target text content exceeds 1 / 2, execute step 207.
[0155] Step 206: Determine that the writing direction of the target text content is LrTb.
[0156] Step 207: Determine that the writing direction of the target text content is TbR1.
[0157] Step 208: Determine that the writing direction of the target text content is R1Tb.
[0158] Further, if the writing direction of the target text content cannot be determined according to the first typesetting significant feature as described in the above embodiment, for example, when the determination result of the above step 205 is that there is no text object using the CIDFont font and the vertical writing mode in the target text content, or the proportion of such text objects in the target text content does not exceed 1 / 2, the writing direction of the target text content cannot be determined. At this time, the writing direction of the target text content can continue to be determined according to the second typesetting significant feature.
[0159] In one embodiment, determining the second layout salient feature of the target text content according to the character circumscribed coordinate frame of each text object includes: determining the number of rows and columns of the target text content according to the character circumscribed coordinate frame of each text object, and determining the horizontal projection statistics in the horizontal direction and the vertical projection statistics in the vertical direction of all text objects in the target text content, and determining the number of rows, the number of columns, the horizontal projection statistics and the vertical projection statistics as the second layout salient feature of the target text content. Here, the horizontal projection statistics can characterize the layout of the target text content in the horizontal direction, and correspondingly, the vertical projection statistics can characterize the layout of the target text content in the vertical direction.
[0160] Among them, determining the number of rows and columns of the target text content based on the character circumscribed coordinate frame of each text object includes: determining the average width and average height of the character circumscribed coordinate frames of all text objects, determining the total circumscribed coordinate frame of all text objects, and determining the total width and total height of the total circumscribed coordinate frame, determining the number of columns of the target text content based on the total width and average width, and determining the number of rows of the target text content based on the total height and average height.
[0161] The total circumscribed coordinate frame refers to the minimum circumscribed rectangular frame that can surround all text objects in the target text content, the total width refers to the width of the minimum circumscribed rectangular frame, and the total height refers to the height of the minimum circumscribed rectangular frame.
[0162] Let the total width be Width, the total height be Height, the average width be CWidth, and the average height be CHeight. Then the number of rows and columns of the target text content can be calculated by the following formula:
[0163] Col=Width / CWidth
[0164] Row=Height / CHeight
[0165] Determining the horizontal projection statistics of all text objects in the target text content in the horizontal direction and the vertical projection statistics in the vertical direction includes: constructing a horizontal projection array and a vertical projection array, wherein each element in the horizontal projection array corresponds to a width interval in turn, and each element in the vertical projection array corresponds to a height interval in turn, the width interval is obtained by dividing the total width of the total circumscribed coordinate frame of all text objects in the target text content, and the height interval is obtained by dividing the total height of the total circumscribed coordinate frame of all text objects in the target text content; then traversing each text object in the target text content, and performing the following processing for the traversed text object: determining the target width interval and target height interval where the character circumscribed coordinate frame of the traversed text object is located; adding a first preset value to the value of the element corresponding to the target width interval in the horizontal projection array, and adding a second preset value to the value of the element corresponding to the target height interval in the vertical projection array. After the traversal is completed, the horizontal projection array is determined as the horizontal projection statistics of all text objects in the target text content in the horizontal direction, and the vertical projection array is determined as the vertical projection statistics of all text objects in the target text content in the vertical direction. The first preset value and the second preset value are both positive integers, and are usually set to 1. When set to 1, the value of the above element represents the number of text objects falling into the corresponding interval.
[0166] In an embodiment of the present application, the interval length of the above-mentioned width interval and height interval can be a preset value between (0,1], and the smaller the interval length, the more interval divisions there are, which means that the statistical granularity is finer and the final statistical result is more accurate.
[0167] To facilitate understanding of the statistical process of horizontal projection statistics and vertical projection statistics, the following table shows Figure 3 The specific example shown:
[0168] like Figure 3 As shown in FIG. 1 , the target text content includes three text objects A, B, and C. The total width of the total external coordinate frame of the three text objects is divided into four width intervals. Correspondingly, the initial value of the horizontal projection array is [0,0,0,0]. Figure 3As shown, text object A falls into the first and second width intervals, text object B falls into the third and fourth width intervals, and text object C falls into the second and third width intervals. According to the above description, traverse text objects A, B, and C in turn, and finally get the horizontal projection statistic [1,2,2,1].
[0169] In one embodiment, determining the writing direction of the target text content according to the second typesetting salient feature includes: when the number of lines of the target text content is less than a set value, determining the writing direction of the target text content to be a first preset writing direction. Here, since in actual applications, if the typesetting is performed from top to bottom in the line direction, then in daily writing habits, the number of lines of the target text content is at least greater than 3 lines. Only when the typesetting is performed from left to right in the line direction and from top to bottom in the paragraph direction, the number of lines may be less than 3, for example, only 1 line or only 2 lines. Therefore, the above set value is set to 3, that is, when the number of lines of the target text content is less than 3, the writing direction of the target text content is determined to be LrTb.
[0170] When the number of lines of the target text content is not less than a set value, the writing direction of the target text content is determined according to the horizontal projection statistics and the vertical projection statistics.
[0171] Specifically, in one embodiment, by Figure 4 The process shown in the figure determines the writing direction of the target text content according to the horizontal projection statistics and the vertical projection statistics. Figure 4 As shown, the following steps are included:
[0172] Step 401: Determine the number of horizontal gaps in the target text content in the horizontal direction according to the horizontal projection statistics, and determine the number of vertical gaps in the target text content in the vertical direction according to the vertical projection statistics.
[0173] The number of horizontal gaps refers to the number of times non-zero numbers in the horizontal projection statistics are separated by 0, and the number of vertical gaps refers to the number of times non-zero numbers in the vertical projection statistics are separated by 0.
[0174] For example, suppose the horizontal projection statistic is [0,0,1,3,0,2,0,1,0,4,0,0,8], where the 4th and 6th elements are separated by 0, the 6th and 8th elements are separated by 0, the 8th and 10th elements are separated by 0, and the 10th and 13th elements are separated by 0, that is, the number of horizontal gaps is 4.
[0175] Step 402: Determine the line writing direction of the target text content according to the number of horizontal gaps, the number of vertical gaps, the number of rows, and the number of columns.
[0176] The writing direction of the lines here includes horizontal and vertical.
[0177] Specifically, Figure 5 As shown, the specific implementation of step 402 includes the following steps:
[0178] Step 501: Divide the number of horizontal gaps by the number of columns to obtain a first quotient, and divide the number of vertical gaps by the number of rows to obtain a second quotient.
[0179] Step 502: When a first set condition is satisfied between the first quotient value and the second quotient value, determine that the writing direction of the target text content is vertical.
[0180] The above-mentioned first setting condition is: XGapSize / Col>a*YGapSize / Row, where XGapSize is the number of horizontal gaps, YGapSize is the number of vertical gaps, and a is a floating point value greater than 1. Here, by performing statistical analysis on a large number of samples, the empirical value of 3 is selected as the value of a to balance the number of paragraphs of recognizable writing directions and the accuracy.
[0181] Step 503: When the second set condition is satisfied between the first quotient value and the second quotient value, determine that the line writing direction of the target text content is horizontal.
[0182] The second setting condition is: YGapSize / Row>b*XGapSize / Col. b is a floating point value greater than 1. Here, by statistically analyzing a large number of samples, the empirical value of 3 is selected as the value of b to balance the number of paragraphs of recognizable writing directions and the accuracy.
[0183] Step 504: when neither the first set condition nor the second set condition is satisfied between the first quotient value and the second quotient value, determine the first variance of all elements in the horizontal projection statistics, and determine the second variance of all elements in the vertical projection statistics.
[0184] Step 505: When the first variance is greater than the second variance, determine that the writing direction of the target text content is vertical.
[0185] Step 506: When the first variance is less than or equal to the second variance, determine that the writing direction of the target text content is horizontal.
[0186] Step 403: Determine the writing direction of the target text content according to the line writing direction of the target text content and the rotation angle of the text object of the specified character type in the target text content.
[0187] In one embodiment, the writing direction of the target text content is determined according to the writing direction of the target text content and the rotation angle of the text object of the specified character type in the target text content, including: when the writing direction of the target text content is horizontal, and the rotation angle of the text object of the character type in the target text content belongs to the second specified character type set satisfies the first rotation condition, the writing direction of the target text content is determined to be the second preset writing direction. Here, the first rotation condition is: the rotation angle is [90°-c°, 90°+c°] or [270°-d°, 270°+d°]. When the rotation angle of the text object satisfies the first rotation condition, it means that the page is rotated, that is, the writing direction of the target text content is actually vertical, and therefore, the writing direction of the target text content is determined to be TbRl. The above c and d are positive numbers. Through this setting, it can be achieved that the rotation angle deviation within a certain range is allowed, and in actual applications, it is usually set to a smaller value to avoid large deviations leading to final judgment errors. For example, the above c is 5, which means that when the target text content is written in a horizontal direction and the rotation angle of the text object whose character type belongs to the second specified character type set in the target text content is any angle in the range of 85° to 95°, the writing direction of the target text content is determined to be the second preset writing direction. As for the specific values of c and d, this application does not make specific restrictions.
[0188] When the line writing direction of the target text content is vertical, and the rotation angle of the text object whose character type belongs to the second specified character type set in the target text content satisfies the second rotation condition, the writing direction of the target text content is determined to be the second preset writing direction. Here, the second rotation condition is: the rotation angle is [0°-e°, 0°+e°] or [180°-f°, 180°+f°]. When the rotation angle of the text object satisfies the second rotation condition, it means that there is no rotation of the page, that is, the line writing direction of the target text content is actually vertical, so the writing direction of the target text content is determined to be TbRl. The above e and f are positive numbers. Through this setting, it is possible to allow a rotation angle deviation within a certain range, and in actual applications, it is usually set to a smaller value to avoid a large deviation leading to a final judgment error. For example, the above f is 5, which means that when the line writing direction of the target text content is vertical, and the rotation angle of the text object whose character type belongs to the second specified character type set in the target text content is any angle in the range of 175° to 185°, the writing direction of the target text content is determined to be the second preset writing direction. As for the specific values of e and f, this application does not make any specific limitations.
[0189] When the target text content is written in a vertical direction and the rotation angle of the text object of the character type in the target text content belongs to the first specified character type set satisfies the first rotation condition, the writing direction of the target text content is determined to be the second preset writing direction. Here, taking Latin characters as an example, Latin characters cannot be typeset when written vertically and the page will be rotated. Therefore, even if the rotation angle of the text object of Latin characters is [90°
[0190] -c°,90°+c°] or [270°-d°,270°+d°] will also determine the writing direction of Latin characters as TbRl.
[0191] It can be seen that the method provided in the embodiment of the present application can accurately determine the writing direction of the text content even when the page is rotated.
[0192] The method provided by the embodiment of the present application extracts multiple text objects included in the target text content to be identified, determines the unified character code and the character circumscribed coordinate frame of each text object, determines the first typesetting significant feature of the target text content according to the unified character code of each text object, and determines the second typesetting significant feature of the target text content according to the character circumscribed coordinate frame of each text object, determines the writing direction of the target text content according to the first typesetting significant feature and / or the second typesetting significant feature, thereby realizing the recognition of the writing direction of the text content, facilitating subsequent text recognition and processing, and having very important application significance in many application scenarios.
[0193] Figure 6 This is a block diagram of an embodiment of a device for identifying the writing direction of text content provided in an embodiment of the present application. Figure 6 As shown, the device comprises:
[0194] An object extraction module 61 is used to extract a plurality of text objects included in the target text content to be identified;
[0195] A first determination module 62, used to determine the unified character code and character circumscribed coordinate frame of each of the text objects;
[0196] A second determination module 63, configured to determine a first typesetting salient feature of the target text content according to the Unicode of each of the text objects;
[0197] A third determination module 64 is used to determine the second typesetting salient feature of the target text content according to the character circumscribed coordinate frame of each text object;
[0198] The fourth determination module 65 is used to determine the writing direction of the target text content according to the first typesetting prominent feature and / or the second typesetting prominent feature.
[0199] Optionally, the fourth determining module 65 includes:
[0200] A first determining unit, configured to determine a writing direction of the target text content according to the first typesetting salient feature;
[0201] The second determination unit is used to determine the writing direction of the target text content according to the second typesetting significant feature when the writing direction of the target text content cannot be determined according to the first typesetting significant feature.
[0202] Optionally, the second determining module 63 includes:
[0203] A character type identification unit, used to determine the character type of each text object according to the unified character code of each text object;
[0204] A ratio determination unit, used to determine the ratio of text objects of a specified character type in the target text content;
[0205] The first feature determination unit is used to determine the character type and the proportion involved in the target text content as the first typesetting significant feature of the target text content.
[0206] Optionally, the third determining module 64 includes:
[0207] A row and column number determination unit, used to determine the number of rows and columns of the target text content according to the character circumscribed coordinate frame of each text object;
[0208] A projection statistic determining unit, used for determining horizontal projection statistics in the horizontal direction and vertical projection statistics in the vertical direction for all text objects in the target text content according to a character circumscribed coordinate frame of each text object;
[0209] The second feature determination unit is used to determine the number of rows, the number of columns, the horizontal projection statistics and the vertical projection statistics as second layout salient features of the target text content.
[0210] Optionally, the row and column number determination unit includes:
[0211] The average size determination subunit is used to determine the average width and average height of the character circumscribed coordinate boxes of all text objects;
[0212] A total size determination subunit, used to determine a total circumscribed coordinate frame of all text objects, and determine a total width and a total height of the total circumscribed coordinate frame;
[0213] The first calculation subunit is used to determine the number of columns of the target text content according to the total width and the average width, and to determine the number of rows of the target text content according to the total height and the average height.
[0214] Optionally, the projection statistic determining unit includes:
[0215] An initial array construction subunit is used to construct a horizontal projection array and a vertical projection array, wherein each element in the horizontal projection array corresponds to a width interval in turn, and each element in the vertical projection array corresponds to a height interval in turn, the width interval is obtained by dividing the total width of the total circumscribed coordinate frame of all text objects in the target text content, and the height interval is obtained by dividing the total height of the total circumscribed coordinate frame of all text objects in the target text content;
[0216] A traversal subunit is used to traverse each text object in the target text content, and perform the following processing on the traversed text object: determine the target width interval and target height interval where the character circumscribed coordinate frame of the traversed text object is located; add a first preset value to the value of the element corresponding to the target width interval in the horizontal projection array, and add a second preset value to the value of the element corresponding to the target height interval in the vertical projection array;
[0217] The first determination subunit is used to determine the horizontal projection array as the horizontal projection statistics of all text objects in the target text content in the horizontal direction after the traversal is completed, and to determine the vertical projection array as the vertical projection statistics of all text objects in the target text content in the vertical direction.
[0218] Optionally, the first determining unit includes:
[0219] A second determination subunit is used to determine that the writing direction of the target text content is a first preset writing direction when it is determined according to the first typesetting significant feature that the character types of all text objects in the target text content belong to a first specified character type set;
[0220] A third determination subunit is used to determine that the writing direction of the target text content is a second preset writing direction when it is determined according to the first typesetting significant feature that there is a text object whose character type belongs to a second specified character type set in the target text content and the proportion corresponding to the text object exceeds a preset proportion threshold;
[0221] a fourth determination subunit, configured to determine that the writing direction of the target text content is a third preset writing direction, when it is determined according to the first typesetting significant feature that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the third specified character type set and the proportion corresponding to the text object exceeds a preset proportion threshold value;
[0222] The fifth determination subunit determines that the writing direction of the target text content is the first preset writing direction when it is determined based on the first typesetting salient feature that there is no text object whose character type belongs to the second specified character type set in the target text content, and there is a text object whose character type belongs to the fourth specified character type set and the proportion corresponding to this text object exceeds a preset proportion threshold.
[0223] Optionally, the device further comprises:
[0224] A font and mode determination module, used to determine the font and writing mode used by each of the text objects;
[0225] The fifth determination module is used to determine that the writing direction of the target text content is a second preset writing direction when it is determined that there are text objects using a specified font and a specified writing mode in the target text content and the proportion of such text objects in the target text content exceeds a preset proportion threshold.
[0226] Optionally, the second determining unit includes:
[0227] A sixth determining subunit, configured to determine, when the number of lines is less than a set value, that the writing direction of the target text content is a first preset writing direction;
[0228] A seventh determination subunit is configured to determine the writing direction of the target text content according to the horizontal projection statistic and the vertical projection statistic when the number of lines is not less than the set value.
[0229] Optionally, the seventh determining subunit includes:
[0230] a gap number determination subunit, configured to determine the number of horizontal gaps existing in the target text content in the horizontal direction according to the horizontal projection statistic, and to determine the number of vertical gaps existing in the target text content in the vertical direction according to the vertical projection statistic;
[0231] A line writing direction determining subunit, used to determine the line writing direction of the target text content according to the number of horizontal gaps, the number of vertical gaps, the number of rows and the number of columns;
[0232] The eighth determination subunit is used to determine the writing direction of the target text content according to the line writing direction of the target text content and the rotation angle of the text object of the specified character type in the target text content.
[0233] Optionally, the eighth determining subunit is specifically configured to:
[0234] When the target text content has a horizontal writing direction and the rotation angle of a text object whose character type belongs to a second specified character type set in the target text content satisfies a first rotation condition, determining the writing direction of the target text content to be a second preset writing direction;
[0235] When the writing direction of the target text content is vertical and the rotation angle of the text object whose character type belongs to the second specified character type set in the target text content satisfies the second rotation condition, determining the writing direction of the target text content to be the second preset writing direction;
[0236] When the line writing direction of the target text content is vertical and the rotation angle of the text object whose character type in the target text content belongs to the first specified character type set satisfies the first rotation condition, the writing direction of the target text content is determined to be the second preset writing direction.
[0237] Optionally, the line writing direction determination subunit includes:
[0238] A second calculation subunit is used to divide the number of horizontal gaps by the number of columns to obtain a first quotient, and divide the number of vertical gaps by the number of rows to obtain a second quotient;
[0239] A ninth determining subunit, configured to determine that the line writing direction of the target text content is vertical when a first set condition is satisfied between the first quotient value and the second quotient value;
[0240] In the case where the first quotient value and the second quotient value satisfy a second set condition, determining that the line writing direction of the target text content is horizontal;
[0241] In the case that neither the first setting condition nor the second setting condition is satisfied between the first quotient value and the second quotient value, determining a first variance of all elements in the horizontal projection statistics, and determining a second variance of all elements in the vertical projection statistics;
[0242] When the first variance is greater than the second variance, the writing direction of the target text content is determined to be vertical; when the first variance is less than or equal to the second variance, the writing direction of the target text content is determined to be horizontal.
[0243] like Figure 7 As shown, an embodiment of the present application provides an electronic device, including a processor 711, a communication interface 712, a memory 713 and a communication bus 714, wherein the processor 711, the communication interface 712, and the memory 713 communicate with each other through the communication bus 714.
[0244] Memory 713, used for storing computer programs;
[0245] In one embodiment of the present application, the processor 711 is used to implement the method for identifying the writing direction of text content provided by any one of the aforementioned method embodiments when executing the program stored in the memory 713, including:
[0246] Extracting a plurality of text objects included in the target text content to be recognized;
[0247] Determine the Unicode and character circumscribed coordinate frame of each of the text objects;
[0248] Determine a first typesetting salient feature of the target text content according to the unified character encoding of each of the text objects, and determine a second typesetting salient feature of the target text content according to a character circumscribed coordinate frame of each of the text objects;
[0249] The writing direction of the target text content is determined according to the first typesetting prominent feature and / or the second typesetting prominent feature.
[0250] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for identifying the writing direction of text content provided in any of the aforementioned method embodiments are implemented.
[0251] The device embodiments described above are merely illustrative, wherein 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 modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0252] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0253] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0254] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for identifying the writing direction of text content, characterized in that: The method comprises: Extracting a plurality of text objects included in the target text content to be recognized; Determine the Unicode and character circumscribed coordinate frame of each of the text objects; Determine a first typesetting salient feature of the target text content according to the unified character encoding of each of the text objects, and determine a second typesetting salient feature of the target text content according to a character circumscribed coordinate frame of each of the text objects; The writing direction of the target text content is determined according to the first typesetting prominent feature and / or the second typesetting prominent feature.
2. The method according to claim 1, characterized in that The step of determining the writing direction of the target text content according to the first typesetting prominent feature and / or the second typesetting prominent feature includes: Determining the writing direction of the target text content according to the first typesetting salient feature; Alternatively, when the writing direction of the target text content cannot be determined according to the first typesetting salient feature, the writing direction of the target text content is determined according to the second typesetting salient feature.
3. The method according to claim 1, characterized in that: The determining the first typesetting salient feature of the target text content according to the unified character encoding of each of the text objects comprises: Determine the character type of each text object according to the unified character code of each text object, and determine the proportion of text objects of each character type in the target text content; The character types and the proportions involved in the target text content are determined as the first typesetting salient features of the target text content.
4. The method according to claim 1, characterized in that: The determining of the second typesetting salient feature of the target text content according to the character circumscribed coordinate frame of each text object comprises: Determining the number of rows and columns of the target text content according to the character circumscribed coordinate frame of each of the text objects, and determining the horizontal projection statistics in the horizontal direction and the vertical projection statistics in the vertical direction of all the text objects in the target text content according to the character circumscribed coordinate frame of each of the text objects; The number of rows, the number of columns, the horizontal projection statistics, and the vertical projection statistics are determined as second layout salient features of the target text content.
5. The method according to claim 4, characterized in that The step of determining the horizontal projection statistics of all the text objects in the target text content in the horizontal direction and the vertical projection statistics in the vertical direction according to the character circumscribed coordinate frame of each of the text objects comprises: Constructing a horizontal projection array and a vertical projection array, wherein each element in the horizontal projection array corresponds to a width interval in sequence, and each element in the vertical projection array corresponds to a height interval in sequence, the width interval is obtained by dividing the total width of the total circumscribed coordinate frame of all text objects in the target text content, and the height interval is obtained by dividing the total height of the total circumscribed coordinate frame of all text objects in the target text content; Traverse each text object in the target text content, and perform the following processing on the traversed text object: Determine a target width interval and a target height interval where a character circumscribed coordinate frame of the traversed text object is located; Add a first preset value to the value of the element corresponding to the target width interval in the horizontal projection array, and add a second preset value to the value of the element corresponding to the target height interval in the vertical projection array; After the traversal is completed, the horizontal projection array is determined as the horizontal projection statistics of all text objects in the target text content in the horizontal direction, and the vertical projection array is determined as the vertical projection statistics of all text objects in the target text content in the vertical direction.
6. The method according to claim 2, characterized in that The first typesetting significant features include: the character type of each text object in the target text content and the proportion of the text objects of each character type in the target text content; The step of determining the writing direction of the target text content according to the first typesetting salient feature includes: When it is determined according to the first typesetting significant feature that the character types of all text objects in the target text content belong to a first specified character type set, determining the writing direction of the target text content to be a first preset writing direction; When it is determined according to the first typesetting significant feature that there is a text object in the target text content whose character type belongs to the second specified character type set and the proportion corresponding to the text object exceeds a preset proportion threshold, determining the writing direction of the target text content to be a second preset writing direction; In the case where it is determined according to the first typesetting significant feature that there is no text object in the target text content whose character type belongs to the second specified character type set, and there is a text object whose character type belongs to the third specified character type set and the proportion corresponding to the text object exceeds the preset proportion threshold, determining that the writing direction of the target text content is the third preset writing direction; When it is determined based on the first typesetting salient feature that there is no text object in the target text content whose character type belongs to the second specified character type set, and when there is a text object whose character type belongs to the third specified character type set and the proportion corresponding to such text object does not exceed the preset proportion threshold, the writing direction of the target text content is determined to be the first preset writing direction.
7. The method according to claim 1, characterized in that The method further comprises: determining a font and writing mode to be used by each of said text objects; When it is determined that there are text objects using a specified font and a specified writing mode in the target text content and the proportion of such text objects in the target text content exceeds a preset proportion threshold, the writing direction of the target text content is determined to be a second preset writing direction.
8. The method according to claim 2, characterized in that: The second typesetting significant features include the number of rows and columns of the target text content, and the horizontal projection statistics of all text objects in the target text content in the horizontal direction and the vertical projection statistics in the vertical direction; The step of determining the writing direction of the target text content according to the second typesetting significant feature includes: When the number of lines is less than a set value, determining the writing direction of the target text content to be a first preset writing direction; In the case where the number of rows is not less than the set value, determining the number of horizontal gaps existing in the target text content in the horizontal direction according to the horizontal projection statistic, and determining the number of vertical gaps existing in the target text content in the vertical direction according to the vertical projection statistic; Determine the line writing direction of the target text content according to the number of horizontal gaps, the number of vertical gaps, the number of rows and the number of columns; The writing direction of the target text content is determined according to the line writing direction of the target text content and the rotation angle of the text object of the specified character type in the target text content.
9. The method according to claim 8, characterized in that The step of determining the writing direction of the target text content according to the line writing direction of the target text content and the rotation angle of the text object of the specified character type in the target text content includes: When the target text content has a horizontal writing direction and the rotation angle of a text object whose character type belongs to a second specified character type set in the target text content satisfies a first rotation condition, determining the writing direction of the target text content to be a second preset writing direction; When the writing direction of the target text content is vertical and the rotation angle of the text object whose character type belongs to the second specified character type set in the target text content satisfies the second rotation condition, determining the writing direction of the target text content to be the second preset writing direction; When the line writing direction of the target text content is vertical and the rotation angle of the text object whose character type in the target text content belongs to the first specified character type set satisfies the first rotation condition, the writing direction of the target text content is determined to be the second preset writing direction.
10. A device for identifying the writing direction of text content, characterized in that: The device comprises: An object extraction module, used to extract a plurality of text objects included in the target text content to be identified; A first determination module is used to determine the unified character code and character circumscribed coordinate frame of each of the text objects; A second determination module is used to determine the first typesetting salient feature of the target text content according to the unified character encoding of each of the text objects; A third determination module is used to determine the second typesetting salient feature of the target text content according to the character circumscribed coordinate frame of each text object; The fourth determination module is used to determine the writing direction of the target text content according to the first typesetting significant feature and / or the second typesetting significant feature.