Text recognition method and electronic device
Through reverse order processing and glyph shaping technology, the accuracy of the mirror language text recognition model is improved, the problem of low accuracy of mirror language recognition in the existing technology is solved, and more efficient training and recognition effects are achieved.
Patent Information
- Application Number
- CN202310862704.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-13
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2043-07-13
AI Technical Summary
The existing technology has low accuracy in recognizing text in mirror languages (such as Arabic), mainly due to the complexity of writing direction and character morphology, which leads to training data errors and low accuracy of the recognition model.
In the text recognition method, the training data of the mirror language is judged and processed in reverse order to ensure the data quality, and replace the non-independent glyphs with independent glyphs, simplify the character table, and improve the quantity and quality of the training data.
The training efficiency and recognition accuracy of the text recognition model have been significantly improved, especially for mirror languages, and the recognition capabilities of languages such as Arabic have been enhanced.
Smart Images

Figure CN117690147B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to electronic technology, and more particularly to a text recognition method and electronic device. Background Art
[0002] Currently, many electronic devices have the function of text recognition for images, that is, they can recognize the text in the image. With the development of text recognition technology, more and more languages can be recognized.
[0003] Mirror languages refer to languages that are written from right to left, such as Arabic, Persian, Urdu, Hebrew, etc. Mirror languages are written from right to left, which is opposite to English and Chinese, which are written from left to right. Influenced by the writing direction of the text, users of Arabic and other languages have a completely opposite understanding of left-right logic than the left-to-right (LTR) habits of English and other languages. For example, they are used to seeing the right side as the beginning and the left side as the end.
[0004] Due to the writing direction of mirror language and the different forms (fonts) of the same character, the current algorithm has a low accuracy in recognizing mirror language in images. Summary of the invention
[0005] The present application provides a text recognition method and electronic device. In the text recognition method, the annotated text corresponding to the first image includes a logo and text on the first image. The server can determine whether the stored first text is reversed by the logo in the annotated text; the reversed text is processed by reverse order to obtain the first text; and finally, the initial file recognition model is trained based on the first image and the first text. The method can avoid errors in the training data, effectively improve the training efficiency when training the text recognition model, and improve the accuracy of the text recognition model.
[0006] In a first aspect, an embodiment of the present application provides a text recognition method, the method comprising:
[0007] The server stores the first image and the annotated text corresponding to the first image; the first image includes the first text; the annotated text includes the identifier and the first text, at least two consecutive characters in the first text belong to the mirror language, and the identifier is the first character or the last character of the annotated text;
[0008] The server reads the annotated text from the storage to obtain a first stored text;
[0009] When the server recognizes that the position of the mark in the first stored text has changed, the server reverses the first stored text to obtain a second stored text; the second stored text includes the first text;
[0010] The server trains the initial document recognition model based on the first image and the second stored text to obtain a trained text recognition model, and the trained text recognition model is used to recognize text in the image.
[0011] In an embodiment of the present application, the annotated text corresponding to the first image includes an identifier and a first text on the first image. The server can determine whether the first text stored in the server is reversed through the identifier in the annotated text; the server reads the annotated text from the storage to obtain a first stored text; when it is recognized that the position of the identifier in the first stored text has changed, the first stored text is reversed to obtain a second stored text, and the second stored text includes the first text; the server trains an initial file recognition model based on the first image and the pre-annotated text to obtain a trained text recognition model, and the trained text recognition model is used to perform text recognition on images including mirror language.
[0012] This method can avoid the situation where the text in the training data is reversed when the server stores the training data of the mirror language, resulting in errors in the training data. The errors in the training data will cause the text recognition model to learn incorrect results, resulting in low accuracy of the text recognition model and low training efficiency. The embodiments of the present application can effectively improve the training efficiency when training the text recognition model, and improve the accuracy of text recognition of the text recognition model.
[0013] In combination with the first aspect, in a possible implementation, the first stored text includes K consecutive characters, the K consecutive characters all belong to the mirror language, and K is a positive integer greater than 1; the j-th character in the second stored text is the K+1-j-th character of the first stored text, and j is a positive integer not greater than K.
[0014] In combination with the first aspect, in a possible implementation manner, the first stored text includes a non-mirror language and K consecutive characters, the K characters all belong to the mirror language, and K is a positive integer greater than 1;
[0015] The positions of the characters belonging to the non-mirror language in the first stored text and the second stored text remain unchanged;
[0016] The j-th character among the K consecutive characters in the second stored text is the K+1-j-th character among the K consecutive characters in the first stored text, where j is a positive integer not greater than K.
[0017] In a possible implementation, the positions of the preset symbols in the first stored text and the second stored text remain unchanged, wherein the preset symbols refer to symbols whose forms change after the reverse processing.
[0018] The embodiment of the present application takes into account that the fragments composed of non-mirror language or preset symbols will only be treated as one character and reversed with the characters of the mirror language during the storage process, and the characters in the fragment will not be reversed. Therefore, after the first stored text is reversed, if the reversed characters include non-mirror language or preset symbols, the fragments composed of non-mirror language or preset symbols in the acquired characters are reversed again to ensure the accuracy of the training data. This method can effectively improve the quality of training data, thereby improving the accuracy of the text recognition model.
[0019] In combination with the first aspect, in a possible implementation manner, the server trains an initial document recognition model based on the first image and the second stored text to obtain a trained text recognition model, including:
[0020] The server deletes the identifier from the second stored text;
[0021] The server splits the stored text obtained by deletion to obtain multiple characters;
[0022] The server replaces characters of non-independent glyphs among the multiple characters with independent glyphs to obtain a first shaped text;
[0023] The server inputs the first image into an initial text recognition model to obtain a first predicted text;
[0024] The server compares the first predicted text with the first shaped text to obtain a first loss;
[0025] The server optimizes the initial text recognition model based on the first loss to obtain a trained text recognition model.
[0026] The embodiment of the present application replaces characters of non-independent glyphs with independent glyphs corresponding to the characters, does not pay attention to the multiple forms of the characters, simplifies the character table (from training four glyphs to training only independent glyphs), and can reduce the dependence of the text recognition model training process on large corpora. The recognition accuracy of the text recognition model corresponding to conventional languages can be improved with less training data.
[0027] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0028] The server performs reverse processing on the first text in the second stored text to obtain a second text;
[0029] The server deletes the first text from the first image to obtain a first background image;
[0030] The server merges the second text and the first background image to obtain a second image, where the second image includes the second text;
[0031] The second image and the second text are used to train an initial document recognition model.
[0032] In the embodiment of the present application, the second image and the second text are obtained based on the first image and the second stored text. The method obtains new training data by processing the training data with improved quality (such as the first image and the pre-annotated text mentioned above), thereby increasing the amount of training data while ensuring the quality of the training data.
[0033] In combination with the first aspect, in a possible implementation manner, the identifier is an invisible character.
[0034] Invisible characters refer to characters that can be detected in code detection but cannot be displayed (ie, invisible), such as / u200b.
[0035] It should be noted that languages can also be divided into weak directional languages and strong directional languages, among which strong directional languages have a higher probability of causing glyphs to change, while weak directional languages have a lower probability of causing glyphs to change; for example, Latin and Chinese are strong directional languages, and weak directional languages can include symbols and letters. In the embodiment of the present application, weak directional languages can be selected as invisible characters to avoid affecting the glyphs in Arabic.
[0036] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0037] When the server recognizes that the position identified in the first stored text has not changed, the server trains the initial file recognition model based on the first image and the first stored text.
[0038] In combination with the first aspect, in a possible implementation manner, the mirror language is one of Arabic, Urdu, Uighur, Persian, and Hebrew.
[0039] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0040] The server obtains a first image and a first text;
[0041] The server adds a marker before the first character or after the last character of the first text to obtain the marked text.
[0042] In an embodiment of the present application, the server obtains an annotated text by adding an identifier (such as an invisible character) before the first text. The identifier in the annotated text can be used to determine whether the first text stored in the server is reversed; the server reads the annotated text from the storage to obtain a first stored text; when it is recognized that the position of the identifier in the first stored text has changed, the first stored text is reversed to obtain a second stored text, and the second stored text includes the first text; the server trains an initial file recognition model based on the first image and the pre-annotated text to obtain a trained text recognition model, and the trained text recognition model is used to perform text recognition on images including mirror language.
[0043] In a second aspect, an embodiment of the present application provides a text recognition method, the method comprising:
[0044] When receiving a user operation instructing to perform text recognition on a target image, the terminal device obtains a target text based on the target image and the text recognition model;
[0045] The terminal device displays the target text;
[0046] Among them, the training process of the text recognition model includes a training process based on the first image and the second stored text. The second stored text is obtained by reversing the first stored text when the server recognizes that the position of the identifier in the first stored text has changed. The first stored text is obtained by reading the annotated text of the first image stored in the server. The annotated text includes the identifier and the first text. At least two consecutive characters in the first text belong to the mirror language, and the identifier is the first character or the last character of the annotated text.
[0047] In conjunction with the second aspect, in a possible implementation, the text recognition model is obtained by optimizing a first loss, the first loss is a comparison result between a first predicted text and a first shaped text, the first predicted text is obtained by inputting the first image into an initial text recognition model, and the first shaped text is obtained by text splitting after deleting a mark from the second stored text; the mirror language in the first shaped text is an independent glyph;
[0048] The target text is obtained based on the target image and text recognition model, including:
[0049] The terminal device inputs the target image into the initial text recognition model to obtain a predicted text, where the predicted text includes multiple characters of the mirror language, and the multiple characters are all independent glyphs;
[0050] The terminal device replaces the multiple characters with the glyphs corresponding to the positions of the multiple characters according to the positions of the multiple characters in the predicted text and the shaping correspondence table to obtain the target text; the shaping correspondence table includes the glyphs of the multiple characters at different positions.
[0051] In a third aspect, an embodiment of the present application provides an electronic device, comprising one or more functional modules, which can be used to execute a text recognition method as in any of the above aspects or any possible implementation of any of the aspects.
[0052] In a fourth aspect, the present application provides a computer storage medium comprising computer instructions, which, when executed on an electronic device, enables a communication device to execute a text recognition method in any of the above aspects or in any possible implementation of any of the aspects.
[0053] In a fifth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the text recognition method in any of the above aspects or in any possible implementation of any of the aspects.
[0054] In a sixth aspect, the present application provides a chip, comprising: a processor and an interface, wherein the processor and the interface cooperate with each other so that the chip executes the text recognition method in any of the above aspects or any possible implementation of any of the aspects.
[0055] It is understandable that the electronic device provided in the third aspect, the computer-readable storage medium provided in the fourth aspect, the computer program product provided in the fifth aspect, and the chip provided in the sixth aspect are all used to execute the method provided in the embodiment of the present application. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 is a schematic diagram of optical character recognition provided by an embodiment of the present application;
[0057] Figure 2 It is a schematic diagram of the three main modules of OCR provided by this application;
[0058] Figure 3 It is a flowchart of a training process provided by this application;
[0059] Figure 4 This is a flowchart of adding training data provided by this application;
[0060] Figure 5 is a schematic diagram of obtaining second training data provided by the present application;
[0061] Figure 6 is a comparative schematic diagram of Image 1 and Image 2 provided in the embodiment of the present application;
[0062] Figure 7 is a flowchart of another training process provided in an embodiment of the present application;
[0063] Figure 8 is a schematic diagram of a text recognition method provided by the present application;
[0064] Fig. 9 It is the correspondence between the training process of the server provided in the embodiment of the present application and the identification process of the terminal device;
[0065] Fig.10 is a schematic diagram of the hardware structure of the electronic device 100 provided in an embodiment of the present application;
[0066] Fig.11 It is a software architecture of an electronic device 100 provided in this application. DETAILED DESCRIPTION
[0067] The technical solutions in the embodiments of the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0068] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0069] The term "user interface (UI)" in the following embodiments of the present application refers to a medium interface for interaction and information exchange between an application or operating system and a user, which realizes the conversion between the internal form of information and the form acceptable to the user. The user interface is a source code written in a specific computer language such as Java and extensible markup language (XML). The interface source code is parsed and rendered on an electronic device, and finally presented as content that can be recognized by the user. The commonly used form of user interface is a graphical user interface (GUI), which refers to a user interface related to computer operation displayed in a graphical manner. It can be a visual interface element such as text, icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, widgets, etc. displayed on the display screen of an electronic device.
[0070] Optical Character Recognition (OCR) is the process of analyzing and identifying image files containing text data to obtain text and layout information. Figure 1 The schematic diagram of optical character recognition is shown as an example. Figure 1 As shown, after optical character recognition, image 1 with text 1 can obtain text 1.
[0071] Figure 2 The three main modules of OCR are shown as examples: text detection module, language recognition module and text recognition module. The text detection module is used to detect the text area on the image; the language recognition module at the front end is used to detect and classify the language; the text recognition module is used to recognize the text, and the text recognition module can include a text recognition model corresponding to at least one language.
[0072] The language recognition module and the text recognition module are associated with each other. The text recognition module may include text recognition models corresponding to multiple languages. After the language recognition module recognizes a language, the text recognition model corresponding to the language is called.
[0073] For example, Figure 2 Several languages are shown as examples, such as Chinese, numbers, Latin, and Arabic (referred to as Arabic); several text recognition models included in the text recognition module are shown as examples, such as the text recognition model corresponding to Chinese, the number recognition model, the text recognition model corresponding to Latin, and the text recognition model corresponding to Arabic. For example, for the text recognition model, the end-to-end process of model training and deployment can be as follows:
[0074] (1) Dataset collection: Collect images containing text. In this step, the collected data can include text in various fonts, sizes, colors, and in complex backgrounds. This can improve the generalization ability of the text recognition model.
[0075] (2) Data preprocessing: The collected images are preprocessed, such as scaling, rotation, blurring, noise enhancement, etc., to increase the diversity of the dataset and simulate actual scenarios.
[0076] (3) Data Annotation: Provide text annotations for each image in the dataset, including the text content. Optionally, the text bounding box can also be normalized. In this step, the accuracy of the annotations needs to be ensured.
[0077] (4) Divide the dataset: Divide the dataset into training set, validation set and test set to facilitate verification and final evaluation during the text recognition model training process. Each set of data in the dataset includes at least an image and the text corresponding to the image; the data in the training set, validation set and test set can be different.
[0078] (5) Select or build a model architecture for the text recognition model: Select a suitable text recognition model architecture. For example, the text recognition model architecture can be a convolutional recurrent neural network (CRNN), EAST, YOLOv3, etc. You can also build a custom deep learning architecture based on the problem.
[0079] (6) Training model: Use the training set to train the text recognition model. During the training process, adjust the hyperparameters of the text recognition model, such as the learning rate, optimizer, and loss function, to optimize the training.
[0080] (7) Model verification and adjustment: Use the verification set to evaluate the performance of the text recognition model. Based on the needs, multiple iterations of training and adjustment of the text recognition model structure or hyperparameters can be performed to obtain better performance.
[0081] (8) Model testing: Use the test set to evaluate the text recognition model to understand the performance of the text recognition model in actual application scenarios.
[0082] (9) Model deployment: Deploy the trained text recognition model to actual application scenarios, such as servers, mobile terminals, etc.
[0083] In the embodiment of the present application, the text types can be divided into mirror languages and non-mirror languages. Among them, non-mirror languages can also be called regular languages; mirror languages include Arabic, Urdu, Uyghur, Persian and Hebrew.
[0084] At present, the industry's algorithms and frameworks for conventional languages such as Latin and Chinese characters are relatively mature (the relevant processes and final indicators such as accuracy and recall rate have met user experience requirements). However, due to the characteristics of mirror languages such as writing direction and shaping, the training of text recognition models corresponding to mirror languages is difficult, and there is a lot of room for improvement in indicators such as accuracy and recall rate.
[0085] The following article takes Arabic as an example. Arabic has the following characteristics:
[0086] 1. Arabic glyph changes: Arabic characters change shape depending on their position (alone, at the beginning of a word, in the middle of a word, at the end of a word). This increases the number and complexity of character shapes that the model needs to recognize. It should be noted that Arabic characters can also be called Arabic letters.
[0087] 2. Arabic ligatures: Arabic letters are often written as ligatures, which makes character segmentation and recognition more challenging.
[0088] 3. Right-to-left writing: Arabic is written from right to left, while most OCR technologies are designed for languages written from left to right.
[0089] 4. Words and Shapes: Some Arabic characters can be easily confused with other characters’ shapes (such as connectors and dashes).
[0090] 5. Rich fonts: Arabic letters have a variety of fonts and styles, such as simplified, complex, handwritten, etc.
[0091] 6. Highly similar characters: There are some very similar characters in Arabic, such as (dal) and (dhal), which makes model identification difficult.
[0092] The following is a partial character table exemplarily shown in the embodiment of the present application. The character table shows four glyphs corresponding to five Arabic characters, and the hexadecimal encoding corresponding to each glyph, also known as Unicode. Different forms (also known as glyphs) of the same character have different Unicodes.
[0093] Table 1: Character table
[0094]
[0095] In Table 1, the same row contains four glyphs of the same character. The four columns named independent character, end of word, beginning of word and middle of word respectively represent the forms of the character when the character is in different positions (alone, beginning of word, middle of word and end of word) (hereinafter referred to as glyphs).
[0096] Among them, an independent character refers to the shape of the character when it is not combined with other characters to form a word or sentence (also called an independent glyph); the end of a word refers to the shape of the character when it is at the end of a word when it is combined with other characters to form a word or sentence; the beginning of a word refers to the shape of the character when it is at the beginning of a word when it is combined with other characters to form a word or sentence; the middle of a word refers to the shape of the character when it is in the middle of a word when it is combined with other characters to form a word or sentence.
[0097] It can be seen from the character table shown in Table 1 that the same character may have different glyphs when it is an independent character, at the end of a word, at the beginning of a word, and in the middle of a word. Each glyph uniquely corresponds to a hexadecimal code. The hexadecimal code corresponding to the glyph in Table 1 is the code in the previous grid of the same row as the glyph.
[0098] When training the text recognition model corresponding to Arabic (that is, the text recognition model for recognizing Arabic), due to the above characteristics of Arabic, the initial text recognition model needs to be trained multiple times with the support of a large amount of training data to achieve a good recognition accuracy, that is, the training of the text recognition model corresponding to Arabic needs to rely on a large-scale training corpus. Among them, the training corpus (referred to as corpus) can also be called training data.
[0099] In addition, at present, even after multiple trainings on a large amount of corpus, the recognition accuracy of the text recognition model corresponding to Arabic is still low (it can also be called a low indicator).
[0100] At present, there is no technical solution that focuses on improving the recognition accuracy of the text recognition model corresponding to the mirror language. For example, the new application "Handwritten model training method, Chinese character recognition method, device, equipment and medium" with application number 201810563511.2 is for the recognition optimization of different Chinese fonts and handwritten characters, not for mirror languages. Mirror languages such as Chinese and non-mirror languages such as Arabic are different in writing order and display form; for another example, the new application "Arabic vowel recovery method, device, equipment and storage medium" with application number 202110234392.8 is trained on a large amount of Arabic corpus to learn the phonetic characteristics of Arabic, and then restore the recognition results, which solves the problem of phonetic loss.
[0101] Therefore, how to improve the recognition accuracy of the text recognition model corresponding to Arabic is an issue that the industry urgently needs to solve.
[0102] The inventors of the present application have discovered that in the training process of the text recognition model corresponding to the mirror language, the quality and quantity distribution of the training data are very critical and can effectively improve the recognition accuracy of the text recognition model corresponding to the mirror language.
[0103] The training data includes sample images and sample texts of the mirror language.
[0104] The embodiments of the present application can improve the quality of training data and train the text recognition model corresponding to the mirror language based on the training data with improved quality, thereby improving the recognition accuracy of the text recognition model and the training efficiency during the training process.
[0105] The embodiment of the present application can also increase the amount of training data by reversing the text in the training data.
[0106] The embodiment of the present application can also perform character splitting and shaping processing on the training data, and then train the text recognition model corresponding to the mirror language based on the processed corpus, thereby improving the recognition accuracy of the text recognition model.
[0107] At present, the pre-annotated text corresponding to the sample image is often manually annotated. However, regardless of whether the manually annotated pre-annotated text is the same as the text content on the sample image, when the server stores the sample image and the pre-annotated text locally, due to the above characteristics of Arabic, it is easy for the pre-annotated text stored by the server (referred to as stored text) to be different from the text content on the sample image. It can be understood that the difference between the stored text and the text content on the sample image can also be called poor quality of training data.
[0108] When the quality of training data is poor (also known as too much dirty data in the training corpus), the text recognition model will learn incorrect results during training, so the training data needs to be preprocessed by cleaning. The cleaning of conventional languages is mainly caused by labeling problems caused by improper cleaning. However, because Arabic is displayed from right to left (RTL) and is displayed in both directions when Arabic and conventional languages appear in one line, the labeled text will be out of order, reversed, and have punctuation misplaced.
[0109] For example, the server stores the sample image and the pre-annotated text in a file. Specifically, the pre-annotated text and the image information of the sample image are stored in the text in the form of code. Since Arabic and the code language are in the same line, the Arabic appears in reverse order, resulting in the pre-annotated text (referred to as stored text) stored in the file being different from the text content in the sample image. Then, assuming that the server trains the text recognition model based on the stored sample image and stored text, the text recognition accuracy of the trained text recognition model will be low.
[0110] In the embodiment of the present application, the server can improve the quality of the training data of the stored mirror language, thereby improving the recognition accuracy of the text recognition model corresponding to the mirror language. For the specific process, please refer to the relevant content of the first embodiment below.
[0111] Embodiment 1: The server processes N groups of initial training data to obtain N groups of training data with improved quality (referred to as N groups of first training data). Then, the initial text recognition model is trained based on the N groups of first training data to obtain a first recognition model, where N is a positive integer.
[0112] Among the N groups of initial training data, one group of initial training data includes an initial image and pre-annotated text corresponding to the image, and the image content of the initial image includes text, and the text includes at least two Arabic characters.
[0113] Among them, one set of first training data of the N sets of first training data includes an initial image and an annotated text corresponding to the image, and the annotated text is the same as the text in the image content of the image.
[0114] Taking a set of initial training data including a first image and its corresponding pre-labeled text as an example, a training process is introduced.
[0115] See also Figure 3 , Figure 3 It is a flowchart of a training process provided by this application.
[0116] S301: The server obtains a set of initial training data, the set of initial training data including a first image and its corresponding pre-annotated text (hereinafter referred to as the first annotated text), wherein the first annotated text includes at least two Arabic characters.
[0117] The embodiment of the present application does not limit the method by which the server obtains training data.
[0118] S302: The server adds invisible characters before the first character of the first annotated text to obtain a second annotated text.
[0119] Among them, the first character can refer to the first character from left to right of the first annotation text, and can also be called the beginning of the line of the first annotation text; the invisible character refers to the character that can be detected in the code detection but cannot be displayed (ie, invisible), such as / u200b.
[0120] It should be noted that languages can also be divided into weak directional languages and strong directional languages, among which strong directional languages have a higher probability of causing glyphs to change, while weak directional languages have a lower probability of causing glyphs to change; for example, Latin and Chinese are strong directional languages, and weak directional languages can include symbols and letters. In the embodiment of the present application, weak directional languages can be selected as invisible characters to avoid affecting the glyphs in Arabic.
[0121] It should be noted that the first annotated text may be referred to as the first text, and the second annotated text may also be referred to as the annotated text.
[0122] In some other embodiments of the present application, the server may also add an invisible character after the last character of the first annotated text to obtain a second annotated text; then step S305 may be to determine the position of the invisible character in the first stored text, or to determine whether the invisible character is the last character of the first stored text. The last character may refer to the last character from left to right in the text.
[0123] S303: The server stores the first image and the second annotated text into a first file.
[0124] In some embodiments, the server can create a new first file in the memory and store the image information of the first image and the second annotation text into the first file. The above image information may include the storage path, size, language, etc. of the first image; the first image is stored in the location corresponding to the above storage path.
[0125] S304: The server obtains data from the storage location of the second annotated text in the first file to obtain the first stored text.
[0126] It should be noted that, due to the above characteristics of Arabic, the second annotated text stored in the server is prone to change, so the first stored text and the second annotated text obtained by the server from the storage location of the second annotated text are in reverse order.
[0127] Exemplarily, reverse order means that the same characters are arranged in opposite directions. For example, the characters in the second annotation text are the same as the characters in the first stored text, the characters in the second annotation text are arranged in a first direction, and the characters in the first stored text are arranged in a second direction, wherein the first direction and the second direction are opposite directions, then it is considered that the first stored text and the second annotation text are in reverse order. Exemplarily, the first direction may be from left to right, and the second direction may be from right to left.
[0128] For ease of understanding, English letters are used as an example. For example, the second annotated text is ABCD and the first stored text is DCBA. Then, the first stored text and the second annotated text are in reverse order.
[0129] Exemplarily, the first annotation text is: The first stored text is:
[0130] In some embodiments, when the server is about to train the initial text recognition model corresponding to Arabic, it can obtain multiple sets of training data from the storage, wherein the multiple sets of training data include the above-mentioned first file.
[0131] S305: The server determines whether the invisible character is the first character of the first stored text.
[0132] Since the invisible characters can be detected in the code detection, the server can identify the positions of the invisible characters in the first stored text.
[0133] In some other embodiments of the present application, step S305 may also be to identify the position of the invisible character in the first stored text.
[0134] S306: When the server recognizes that the invisible character is not the first character of the first stored text, the server reverses the first stored text to obtain a second stored text.
[0135] The inventors of the present application discovered during the training process that when the invisible character is not before the first character of the first stored text, it is mostly located at the last character of the first stored text. Here, the first stored text and the second annotated text are often in reverse order.
[0136] Reverse order means: the first stored text includes K consecutive characters, the K consecutive characters all belong to the mirror language, and K is a positive integer greater than 1; the j-th character in the second stored text is the K+1-j-th character of the first stored text, and j is a positive integer not greater than K.
[0137] Exemplarily, the reverse processing may be to arrange the characters obtained from the text in a first direction in sequence in a second direction, wherein the first direction and the second direction are opposite directions, for example, the first direction is from left to right, and the second direction is from right to left.
[0138] In one implementation, the server sequentially obtains characters from the first stored text in a first direction; the server sequentially arranges the obtained characters in a second direction to obtain a second stored text, and the first direction and the second direction are opposite directions. For the convenience of the example, English letters are used as an example for explanation. Assuming that the first stored text is ABCD, the first character obtained by the server from the first stored text from left to right is A, then the server arranges A in the first position from right to left (that is, the first character on the rightmost side); performing the above operation on each character can obtain DCBA.
[0139] In some embodiments, after reversing the first stored text, the server determines the reversed text as the second stored text.
[0140] In some other embodiments of the present application, after the server reverses the first stored text, it can check whether there is a language segment composed of non-mirror language and / or preset symbols (such as Arabic numerals, periods, question marks, etc.) in the reversed text; if there is such a language segment, the server reverses the language segment in the reversed text to obtain the above-mentioned second stored text. The preset symbol refers to a symbol whose form changes after the reverse processing.
[0141] Exemplarily, the first stored text includes a non-mirror language and K consecutive characters, the K characters all belong to the mirror language, and K is a positive integer greater than 1; the positions of the characters belonging to the non-mirror language in the first stored text and the second stored text remain unchanged; the j-th character among the K consecutive characters in the second stored text is the K+1-j-th character among the K consecutive characters in the first stored text, and j is a positive integer not greater than K.
[0142] It should be noted that the text composed of the above language fragment and Arabic characters may have a problem when stored: the language fragment will be reversed as a character, but the character position in the language fragment will not be changed. For example, if the pre-annotated text is 123abc (here 123 is used as an example of a language fragment and abc is used as an example of an Arabic character), the first stored text may be cba123. Then after a reverse processing, the text obtained is 321abc. In the embodiment of the present application, 321 in 321abc is reversed to obtain 123abc.
[0143] In other embodiments of the present application, step S305 may also be to identify the position of the invisible character in the first stored text; step S306 is to reverse the first stored text to obtain the second stored text when the invisible character is identified as the last character of the first stored text (also called the end of a line).
[0144] Since Arabic itself is written from right to left, in the embodiment of the present application, the invisible character is not the first character of the first stored text, so the first stored text and the second annotated text are in reverse order (i.e., from left to right), S306 reverses the first stored text, that is, changes the position order of Arabic to from right to left, and this reverse processing can also be called left to right (RLT) processing. The method reverses the text when it is recognized that the stored text is reversed, and obtains the same text as the text on the image corresponding to the text, thereby avoiding the reverse error of the sample text in the training data, and can improve the quality of the training data.
[0145] S307: The server uses the first image and the second stored text as a set of first training data, wherein the first image is a sample image and the second stored text is a sample text.
[0146] In some embodiments, after executing S306 above, the server uses the first image and the second stored text as a set of training data (that is, uses the first image as a sample image and the second stored text as a sample text).
[0147] Among them, the sample image is the input data of the text recognition model during the training process, and the sample text is the target data to be compared with the output data.
[0148] In the embodiment of the present application, the first image and the second stored text are referred to as a set of training data with improved quality.
[0149] S308: The server trains the initial text recognition model based on the first image and the second stored text.
[0150] In some embodiments, the server can obtain the storage path of the first image from the first file, and obtain the first image based on the storage path; then, the server can input the first image into the initial text recognition model to obtain predicted text; the server optimizes the parameters of the initial text recognition model based on the second stored text and the predicted text to obtain a trained text recognition model.
[0151] It should be noted that the second stored text compared with the predicted text during training is the text with the invisible characters deleted. For example, when the server performs the above step S306, when it recognizes that the invisible character is not the first character of the first stored text, it can delete the invisible character in the first stored text, and then reverse the deleted text to obtain the second stored text; the server can also delete the invisible characters from the second stored text during the training process and update the second stored text. The embodiment of the present application does not limit the time for deleting the invisible characters.
[0152] S309: When the server recognizes that the invisible character is the first character of the first stored text, the server uses the first image and the first stored text as a set of first training data, wherein the first image is a sample image and the first stored text is a sample text.
[0153] Among them, the sample image is the input data of the text recognition model during the training process, and the sample text is the target data to be compared with the output data.
[0154] S310: The server trains an initial text recognition model based on the first image and the first stored text.
[0155] In some embodiments, when the server recognizes that the invisible character is the first character of the stored text, it uses the first image and the stored text as a set of training data (that is, uses the first image as a sample image and the stored text as a sample text) to train the initial text recognition model.
[0156] Exemplarily, the server can obtain the storage path of the first image from the first file, and obtain the first image based on the storage path; further, the server can input the first image into the initial text recognition model to obtain the predicted text; the server optimizes the parameters of the initial text recognition model based on the stored text and the predicted text to obtain the trained text recognition model. It should be noted that the first stored text compared with the predicted text during training is the text with the invisible characters deleted.
[0157] In the embodiment of the present application, the server can store N sets of training data (such as N first files) through S301 to S303, and then, when the initial text recognition model corresponding to Arabic is to be trained, some steps in S304 to S308 are performed on each set of training data, and when the loss of the predicted text and the sample text (i.e., the stored text or the second stored text) meets the preset conditions, a trained text recognition model (i.e., the first recognition model) is obtained. The contents of the images or pre-annotated texts in the multiple sets of training data may be different.
[0158] The method improves the quality of training data and trains the initial text recognition model based on the improved training data, thereby improving the recognition accuracy of the text recognition model corresponding to Arabic.
[0159] Since the annotation difficulty of Arabic training data is much more complicated than that of conventional languages, the amount of training data is relatively small. However, due to the characteristics of Arabic glyphs, the corpus needs to cover different glyphs, which means that the amount of training data required is much larger than that of conventional languages.
[0160] The embodiment of the present application can process sample images and sample texts of the images in existing training data (such as the above-mentioned initial training data) to obtain new training data, thereby increasing the amount of training data.
[0161] The embodiment of the present application can also process the training data after the quality is improved in the first embodiment (such as the first training data mentioned above) to obtain new training data, thereby increasing the amount of training data while ensuring the quality of the training data.
[0162] Embodiment 2: The server may also process the characters and sample texts in the sample images in the N groups of first training data to obtain M groups of second training data. Further, the first recognition model is trained based on the M groups of second training data to obtain a second recognition model, where M is a positive integer not less than N.
[0163] Among them, one set of first training data in the N sets of first training data corresponds to at least one set of second training data in the M sets of second training data. A set of first training data has the same background content as the image in the corresponding second training data, and the sample text in the second training data is obtained based on the sample text of the corresponding first training data.
[0164] Taking a set of initial training data including a first image and its corresponding sample text (referred to as the first sample text) as an example, a training process is introduced.
[0165] See also Figure 4 , Figure 4 This is a flowchart of adding training data provided by this application.
[0166] S401: The server performs reverse processing on the first sample text corresponding to the first image to obtain a second sample text, wherein the first sample text may be the first stored text or the second stored text.
[0167] The reverse processing refers to arranging the characters obtained from the text in a first direction in sequence in a second direction, wherein the first direction and the second direction are opposite directions. For example, the first direction is from left to right, and the second direction is from right to left.
[0168] In some embodiments, the server may sequentially arrange the characters obtained from the first sample text in the first direction in the second direction to obtain the second sample text. For example, the annotated text corresponding to the first image is: The text after reverse processing can be:
[0169] In some embodiments, the first sample text corresponding to the first image may be the first stored text or the second stored text. Figure 3 The method shown is determined.
[0170] Exemplarily, if the server determines that the invisible character is the first character of the first stored text when executing the above S305, then the above-mentioned first sample text may be the above-mentioned first stored text; if the server determines that the invisible character is not the first character of the first stored text when executing the above S305, then the above-mentioned first sample text may be the above-mentioned second stored text.
[0171] Optionally, the reverse order processing may be specifically implemented by a text conversion module.
[0172] S402: The server deletes text content from the first image to obtain a first background image.
[0173] In some embodiments, S402 may be specifically implemented by a background extraction module (Background in painting module) in the server. The server inputs the first image into the background extraction module to obtain a first background image.
[0174] S403: The server merges the second sample text and the first background image to obtain a second image.
[0175] In some embodiments, S403 may be specifically implemented by a fusion module in the server. The server inputs the second sample text and the first background image into the fusion module to obtain the second image.
[0176] S404: The server may use the second image and the second sample text as a set of second training data.
[0177] Figure 5 A schematic diagram of obtaining second training data is exemplarily shown.
[0178] Figure 5 exemplarily shows that in a set of first training data, the sample text is text 1 and the sample image is image 1; the server can input text 1 into the text conversion module to obtain text 2; input image 1 into the background extraction module to obtain the background image of image 1; and then input text 2 and the background image of image 1 into the fusion module to obtain image 2. Finally, the server can use text 2 and image 2 as a set of second training data.
[0179] Figure 6 A comparison diagram of Image 1 and Image 2 is shown as an example. Figure 6 Taking the background content of image 1 and image 2 as the diagonal area as an example, it can be seen that the background content of image 1 and image 2 is the same, and text 1 and text 2 are in reverse order.
[0180] For example, text 1 may be: Text 2 can be:
[0181] It can be seen that through the above Figure 4 and Figure 5 The method shown can obtain N groups of reversed training data based on N groups of first training data. The N groups of reversed training data are the above-mentioned M groups of second training data.
[0182] Since Arabic is written from right to left, in the present embodiment, Arabic is processed in reverse order, that is, the position order of Arabic is changed from left to right. Figure 4 and Figure 5 The method shown may also be referred to as left to right (LTR) processing. This method processes a set of training data to obtain another set of training data with reversed text order, thereby increasing the diversity of training data.
[0183] In some other embodiments of the present application, the server can also perform a first operation such as deleting or swapping the text in the sample image and the characters in the sample text in the N groups of reversed training data simultaneously, so as to obtain the above-mentioned M groups of second training data. Wherein, M can be xN; x is a positive integer, and x is the type of the first operation.
[0184] In other embodiments of the present application, after obtaining the N groups of first training data and the M groups of second training data, the server may also train the initial text recognition model based on the N groups of first training data and the M groups of second training data to obtain a second recognition model.
[0185] In the scenarios of Example 1 and Example 2, after the server obtains the above-mentioned first recognition model or the above-mentioned second recognition model through training, the terminal device can store the above-mentioned first recognition model or the above-mentioned second recognition model; then, when receiving text recognition of an image including Arabic, the image is input into the above-mentioned first recognition model or the above-mentioned second recognition model to obtain the Arabic in the image.
[0186] Exemplarily, the terminal device can be pre-installed with several applications before leaving the factory, such as the gallery application, camera application, and memo application; and pre-installed ORC related modules, such as the text detection module, language recognition module, and text recognition module, wherein the text recognition module can be pre-installed with the above-mentioned first recognition model or the above-mentioned second recognition model. Then, when the user gets the terminal device, if the gallery application performs text recognition on an image, the gallery application can call the above-mentioned text detection module through the interface to detect the text area on the image; then, the language recognition module is used to detect and classify the language; when the text is recognized as Arabic, the image is input into the above-mentioned first recognition model or the above-mentioned second recognition model to obtain the text on the image.
[0187] The present application tested the initial text recognition model and the second recognition model, and found that when the precision (Precision) of the initial text recognition model was 80%, the recall rate (Recall) was 73%, and the F1 value (F1-score) was 76.339%, the precision rate of the second recognition model obtained by the above-mentioned embodiment one and embodiment two was 87%, the recall rate was 86%, and the F1 value was 86.497%. Among them, the recall rate is also called sensitivity (Sensitivity); the precision rate, recall rate and F1 value are all between 0 and 1, and the larger the value, the better the effect of the model. It can be seen that the implementation of the first and second embodiments of the present application can effectively improve the accuracy of the text recognition model corresponding to Arabic. Since Arabic is one of the mirror languages, then by the same token, the first and second embodiments of the present application can effectively improve the accuracy of the text recognition model corresponding to the conventional language.
[0188] Embodiment 3: The server may perform character splitting and shaping on sample text in at least one set of third training data to obtain at least one set of fourth training data. Further, the initial text recognition model is trained based on multiple sets of fourth training data to obtain a third recognition model. The third training data may include at least one of the initial training data, the first training data, or the second training data.
[0189] Among them, shaping refers to replacing a character of a non-independent glyph with an independent glyph corresponding to the character. As shown in Table 1 above, Arabic characters have four glyphs, among which the non-independent glyphs are the glyphs of Arabic characters at the end, middle and beginning of a word. Among them, the independent glyphs can also be called basic glyphs.
[0190] Among them, a group of third training data corresponds to a group of fourth training data, the images in the third training data and the corresponding fourth training data are the same, and the sample text in the fourth training data is obtained by character splitting and shaping based on the corresponding third training data.
[0191] Since Arabic characters will be deformed due to different positions, the whole line processing will result in poor recognition results due to data sparsity (arbitrary combination of characters). There are few character forms in a line of text, so multiple lines of data are needed, and a lot of training data is needed. When there is little data, the recognition accuracy of the text recognition model trained is low. Therefore, the industry's mainstream OCR processing methods for Arabic are as follows: (1) split the image by word; (2) split the image by character. The above two methods require the support of precise cutting algorithms and are highly dependent on multiple corpus scenarios and quantities. Among them, the multi-corpus scenario refers to the scenario where the same character is in different positions.
[0192] The embodiment of the present application simplifies the character table (the number of characters in the character table is reduced from more than 100 to 28) by replacing characters of non-independent glyphs with independent glyphs corresponding to the characters, without paying attention to the multiple forms of the characters; from training four glyphs to training only independent glyphs, the text recognition model training process does not need to deliberately supplement the corpus with deformation, extension, etc., which can reduce the dependence on the amount of training data and multiple corpus scenarios.
[0193] The following describes a training process by taking a set of third training data as the set of first training data as an example. The set of first training data includes a first image and its corresponding sample text (referred to as first sample text).
[0194] See also Figure 7 , Figure 7 It is a flowchart of another training process provided by this application.
[0195] S701: The server splits the first sample text into characters to obtain a plurality of characters, wherein the first sample text may be the first stored text or the second stored text; and the plurality of characters include at least one character whose glyph is a non-independent glyph.
[0196] Exemplarily, the first sample text is The multiple characters obtained by splitting are
[0197] In some embodiments, the server may first split the first sample text into words, and then traverse each word to split each word into characters. This method can improve the efficiency of splitting characters.
[0198] Exemplarily, if the server determines that the invisible character is the first character of the first stored text when executing the above S305, then the above-mentioned first sample text may be the above-mentioned first stored text; if the server determines that the invisible character is not the first character of the first stored text when executing the above S305, then the above-mentioned first sample text may be the above-mentioned second stored text.
[0199] S702: The server replaces the characters of the non-independent glyphs in the multiple characters with the independent glyphs corresponding to the characters, and obtains multiple characters after shaping (referred to as shaped texts corresponding to the first image for short).
[0200] In some embodiments, the server may store an integer correspondence table, wherein the integer correspondence table includes the correspondence between the four glyphs of Arabic characters. Exemplarily, the integer correspondence table may include the above-mentioned Table 1; further, the server may first determine the character of the non-independent glyph from the above-mentioned multiple characters, search the independent glyph corresponding to the character in the integer correspondence table, and replace the character of the non-independent glyph in the character with the independent glyph corresponding to the character.
[0201] Among them, the Arabic characters in the shaped text are all independent glyphs.
[0202] Exemplarily, the multiple characters obtained by splitting are The multiple characters after shaping are
[0203] S703: The server uses the first image and its corresponding shaped text as a set of fourth training data.
[0204] In some embodiments, the server may store the first image and its corresponding shaped text as a set of fourth training data.
[0205] S704: The server trains an initial text recognition model based on the first image and its corresponding shaped text.
[0206] In some embodiments, the server may train an initial text recognition model using the first image and the shaped text corresponding to the first image.
[0207] Exemplarily, the server can obtain the storage path of the first image from the first file, and obtain the first image based on the storage path; then, the server can input the first image into the initial text recognition model to obtain the predicted text, which includes multiple characters; then, based on the shaped text corresponding to the first image and the predicted text, the parameters of the initial text recognition model are optimized to obtain the trained text recognition model. It should be noted that the shaped text corresponding to the first image compared with the predicted text during training is the text with the invisible characters deleted.
[0208] In an embodiment of the present application, the electronic device can perform the training process as described above on the initial text recognition model through multiple sample images and their corresponding shaped texts, and when the loss of the sample images and their corresponding shaped texts meets the preset conditions, a trained text recognition model (i.e., the above-mentioned third recognition model) is obtained.
[0209] The embodiment of the present application replaces characters of non-independent glyphs with independent glyphs corresponding to the characters, does not pay attention to the multiple forms of the characters, simplifies the character table (from training four glyphs to training only independent glyphs), and can reduce the dependence of the text recognition model training process on a large corpus. The recognition accuracy of the text recognition model corresponding to Arabic can be improved with less training data.
[0210] In the scenario of Example 3, after the server obtains the above-mentioned third recognition model through training, the terminal device can store the above-mentioned third recognition model; then, when receiving text recognition of an image including Arabic, the image is input into the above-mentioned third recognition model to obtain the characters corresponding to the Arabic in the image, and the characters are all independent glyphs; then, the terminal can splice the characters according to the positional relationship to obtain the Arabic in the image.
[0211] Exemplarily, the terminal device can be pre-installed with several applications before leaving the factory, such as a gallery application, a camera application, and a memo application; and pre-installed ORC related modules, such as a text detection module, a language recognition module, and a text recognition module, wherein the text recognition module can be pre-installed with the above-mentioned third recognition model. Then, when the user gets the terminal device, if the gallery application performs text recognition on an image, the gallery application can call the above-mentioned text detection module through the interface to detect the text area on the image; then, the language recognition module is used to detect and classify the language; when the text is recognized as Arabic, the image is input into the above-mentioned third recognition model to obtain multiple characters; the multiple characters are combined into words according to the positional relationship, and then the words are spliced in order from right to left to obtain the text on the image.
[0212] In combination with the above-mentioned embodiments 1 to 3, the following Figure 8 The text recognition method provided in the embodiment of the present application is introduced in detail.
[0213] S801: The server obtains N groups of initial training data, each of which includes a sample image and its corresponding pre-annotated text, wherein the pre-annotated text includes at least two Arabic characters.
[0214] S802: The server executes part of the above steps S301 to S307 and S309 for each group of initial training data to obtain N groups of first training data.
[0215] That is, the server can add invisible characters before the first character of the pre-annotated text when storing each set of initial training data. Then, based on the invisible characters, it is determined whether to reverse the pre-annotated text, thereby determining the sample image and sample text of each set of training data. In the embodiment of the present application, the determined training data is referred to as the first training data.
[0216] Among the N groups of first training data, at least one group executes the above S301 to S307.
[0217] S803: The server performs the above steps S401 to S404 on the N groups of first training data to obtain N groups of second training data.
[0218] That is, the server can reverse the text in the sample text and sample image in each set of first training data, and use the reversed text as the sample text of a set of second training data, and use the reversed image as the sample image of the set of second training data.
[0219] S804: The server performs steps S701 to S703 on the N groups of first training data and the N groups of second training data to obtain 2N groups of fourth training data.
[0220] That is to say, the server can split the characters of the sample text in each of the N groups of first training data and the N groups of second training data, and then replace the split characters with independent glyphs corresponding to the characters to obtain multiple processed characters, and use the processed multiple characters as sample text of a group of fourth training data, and use the sample images in the group of training data as sample images of the group of fourth training data.
[0221] S805: The server trains the initial text recognition model based on the 2N groups of fourth training data, and obtains a third recognition model when the model is trained to meet preset requirements.
[0222] For example, when the server can predict that the loss of the text and the sample text meets the preset conditions, the text recognition model at this time is considered to be a trained text recognition model, that is, the third recognition model.
[0223] S806: The terminal device obtains the third recognition model from the server.
[0224] In some embodiments, the terminal device does not interact directly with the server, but the manufacturer of the terminal device presets the third recognition model in the server to the terminal device.
[0225] Exemplarily, before leaving the factory, the terminal device can pre-install several applications at the application layer, such as the gallery application, the camera application, and the memo application; and pre-install ORC related modules at the application framework layer, such as the text detection module, the language recognition module, and the text recognition module, wherein the text recognition module can pre-install the third recognition model. The above-mentioned application can call the ORC related modules, such as the text detection module, the language recognition module, and the text recognition module, through a preset interface (such as HonorLens) to realize text recognition in the image.
[0226] In other embodiments, the terminal device may establish a communication connection with the server, and then the server may send the third recognition model to the terminal device.
[0227] S807: When receiving a user operation for performing text recognition on a target image, the terminal device inputs the target image into a third recognition model to obtain a predicted shaped text, where the predicted shaped text includes a plurality of characters.
[0228] Exemplarily, the terminal device displays a large image interface of the target image in response to a user operation instructing to display the target image; further, when a user operation instructing to perform text recognition (such as clicking a text recognition control) is detected, in response to the user operation, the text detection module is called to detect the text area on the image; further, the language is detected and classified through the language recognition module; when the text is recognized as Arabic, the text area is recognized through the third recognition model to obtain a predicted shaped text, which includes multiple characters.
[0229] Among them, multiple characters can all be independent glyphs.
[0230] S808: The terminal device concatenates the above multiple characters to obtain a target text.
[0231] In some embodiments, the multiple characters may all be independent glyphs, and the terminal device splices the multiple characters according to the recognized positional relationship to obtain the target text.
[0232] Exemplarily, the terminal device may first combine the above-mentioned multiple characters into words according to the position relationship; and then combine the words into text in a right-to-left order.
[0233] Fig. 9 The corresponding relationship between the training process of the server and the identification process of the terminal device is exemplified.
[0234] Fig. 9 The example shows a training process of the server, and the first image and the shaped text corresponding to the first image can be a set of data in the above-mentioned 2N sets of fourth training data. Among them, the Arabic characters in the shaped text are all independent glyphs. The server inputs the first image into the initial text recognition model and inputs the predicted text; the server can compare the predicted text with the shaped text corresponding to the first image to obtain the loss; and optimize the initial text recognition model based on the loss. After multiple trainings, if the loss meets the preset conditions, the third recognition model can be obtained.
[0235] Since the sample texts used in the training process are all shaped texts, when the terminal device uses the third recognition model for text recognition, the output predicted text is also shaped text. Exemplarily, when the terminal device inputs the target image including the target text into the third training model, the predicted shaped text can be obtained; further, the terminal device can splice the predicted shaped text according to the position in the target image to obtain the above target text.
[0236] The present application tested the initial text recognition model and the third recognition model and found that when the accuracy of the initial text recognition model was 80%, the recall rate was 73%, and the F1 value was 76.339%, after the above Figure 8 The third recognition model obtained by the embodiment shown (i.e., implementing the above-mentioned embodiments 1 to 3) has an accuracy rate of 87%, a recall rate of 86%, and an F1 value of 86.497%. It can be seen that the implementation of the embodiment of the present application can effectively improve the accuracy of the text recognition model corresponding to Arabic. Since Arabic is one of the mirror languages, then by the same token, the implementation of the embodiment of the present application on the text recognition model corresponding to the conventional language can effectively improve the accuracy of the text recognition model corresponding to the conventional language.
[0237] Next, the form and software and hardware architecture of the above terminal device are introduced by taking the electronic device 100 as an example.
[0238] The electronic device 100 may be equipped with Or portable terminal devices with other operating systems, such as mobile phones, tablet computers, desktop computers, laptop computers, handheld computers, notebook computers, ultra-mobile personal computers (UMPC), netbooks, as well as cellular phones, personal digital assistants (PDA), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (AI) devices, wearable devices, vehicle-mounted devices, smart home devices and / or smart city devices, etc.
[0239] Fig.10 A schematic diagram of the hardware structure of the electronic device 100 is shown.
[0240] It should be understood that the electronic device 100 may have more Fig.10 More or fewer components may be shown, two or more components may be combined, or there may be a different configuration of components. Fig.10 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.
[0241] The electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194 and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0242] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0243] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a storage device, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0244] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0245] A storage device may also be provided in the processor 110 for storing instructions and data. In some embodiments, the storage device in the processor 110 is a cache memory device. The storage device may store instructions or data that the processor 110 has just used or circulated. If the processor 110 needs to use the instruction or data again, it may be directly called from the storage device. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0246] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0247] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface, thereby realizing the touch function of the electronic device 100.
[0248] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to achieve communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 via the I2S interface to achieve the function of answering a call through a Bluetooth headset.
[0249] The PCM interface can also be used for audio communication, sampling, quantizing and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface to realize the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0250] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.
[0251] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to implement the shooting function of the electronic device 100. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the electronic device 100.
[0252] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0253] The SIM interface can be used to communicate with the SIM card interface 195 to implement the function of transmitting data to the SIM card or reading data in the SIM card.
[0254] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and a peripheral device. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other electronic devices, such as AR devices, etc.
[0255] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0256] The charging management module 140 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.
[0257] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160.
[0258] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0259] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0260] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0261] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In an embodiment of the present application, the modem processor may be independent of the processor 110 and may be arranged in the same device as the mobile communication module 150 or other functional modules.
[0262] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and filters it, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0263] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).
[0264] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0265] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0266] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
[0267] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, etc. of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.
[0268] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0269] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0270] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0271] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.
[0272] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0273] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, applications required for at least one function (such as face recognition function, fingerprint recognition function, mobile payment function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as face information template data, fingerprint information template, etc.), etc.
[0274] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0275] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0276] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.
[0277] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.
[0278] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to the microphone 170C to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In the embodiment of the present application, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In the embodiment of the present application, the electronic device 100 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify the source of sound, realize directional recording function, etc.
[0279] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.
[0280] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
[0281] The gyro sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyro sensor 180B. The gyro sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyro sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyro sensor 180B can also be used for navigation and somatosensory game scenes.
[0282] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.
[0283] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. Then, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, the flip cover can be automatically unlocked.
[0284] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in all directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.
[0285] The distance sensor 180F is used to measure the distance. The electronic device 100 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 100 can use the distance sensor 180F to measure the distance to achieve fast focusing.
[0286] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device 100 emits infrared light outward through the light emitting diode. The electronic device 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100. The electronic device 100 can use the proximity light sensor 180G to detect that the user holds the electronic device 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used in leather case mode and pocket mode to automatically unlock and lock the screen.
[0287] The ambient light sensor 180L is used to sense the ambient light brightness. The electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.
[0288] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
[0289] The temperature sensor 180J is used to detect temperature. In some embodiments, the electronic device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the electronic device 100 reduces the performance of the processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In an embodiment of the present application, when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to avoid abnormal shutdown of the electronic device 100 due to low temperature. In some other embodiments, when the temperature is lower than another threshold, the electronic device 100 boosts the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperature.
[0290] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In the embodiment of the present application, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0291] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0292] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0293] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, synthesis requests, missed calls, notifications, etc.
[0294] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications.
[0295] In the embodiment of the present application, the electronic device 100 can execute the following steps through the processor 110 and the internal memory 121: Figure 8 Steps S806 to S808 are shown to implement the text recognition method provided by the present application.
[0296] Fig.11 The software architecture of the electronic device 100 according to the embodiment of the present application is exemplified.
[0297] like Fig.11 As shown, the layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the runtime layer, and the application framework layer. Fig.11 Take Android as an example) and system libraries, as well as the kernel layer.
[0298] The application layer (application) may include a series of application packages. For example, an application package may include a gallery application, a camera application, a memo application, and other applications.
[0299] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0300] like Fig.11 As shown, the application framework layer may include a text detection module, a language recognition module, a text recognition module, a window manager, a content provider, a view system and a resource manager, and may also include Fig.11 The phone manager and notification manager, etc. are not shown.
[0301] In the embodiment of the present application, the text recognition module can preset at least one of the first recognition model, the second recognition model and the third recognition model. The above applications (such as gallery applications, camera applications, and memo applications) can call relevant modules of ORC through a preset interface (such as HonorLens), such as a text detection module, a language recognition module, and a text recognition module to realize text recognition in an image.
[0302] For example, when text recognition is performed on an image through a gallery application, the gallery application can call the above-mentioned text detection module through an interface to detect the text area on the image; then, the language is detected and classified through the language recognition module; when the text is recognized as Arabic, the text in the image is recognized through at least one of the above-mentioned first recognition model, second recognition model and third recognition model.
[0303] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0304] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0305] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0306] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0307] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0308] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications from applications running in the background, or a notification that appears on the screen in the form of a dialogue interface. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0309] The runtime includes the core library and the virtual machine. The runtime is responsible for the scheduling and management of the system.
[0310] The core library consists of two parts: one part is the function that the programming language (for example, Java language) needs to call, and the other part is the core library of the system.
[0311] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the programming files of the application layer and the application framework layer (for example, java files) as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0312] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0313] The surface manager is used to manage the display subsystem and provide the fusion of two-dimensional (2D) and three-dimensional (3C) layers for multiple applications.
[0314] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0315] The 3D graphics processing library is used to implement 3C graphics drawing, image rendering, synthesis, and layer processing.
[0316] A 2D graphics engine is a drawing engine for 2D drawings.
[0317] The kernel layer is the layer between hardware and software. The kernel layer can contain display drivers, camera drivers, audio drivers, sensor drivers, etc.
[0318] The following is an illustrative description of the workflow of the software and hardware of the electronic device 100 in conjunction with capturing a photo scene.
[0319] When the touch sensor 180K receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into a raw input event (including touch coordinates, timestamp of the touch operation, and other information). The raw input event is stored in the kernel layer. The application framework layer obtains the raw input event from the kernel layer and identifies the control corresponding to the input event. For example, if the touch operation is a touch single-click operation and the control corresponding to the single-click operation is the control of the camera application icon, the camera application calls the interface of the application framework layer to start the camera application, and then starts the camera driver by calling the kernel layer to capture static images or videos through the camera 193.
[0320] An embodiment of the present application also provides an electronic device, which includes one or more processors and one or more memories; wherein the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program codes, and the computer program codes include computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method described in the above embodiment.
[0321] The embodiments of the present application also provide a computer program product including instructions. When the computer program product is executed on an electronic device, the electronic device executes the method described in the above embodiments.
[0322] An embodiment of the present application also provides a computer-readable storage medium, including instructions, which, when executed on an electronic device, enable the electronic device to execute the method described in the above embodiment.
[0323] It can be understood that the various embodiments of the present application can be combined arbitrarily to achieve different technical effects.
[0324] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in this application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk SolidStateDisk), etc.
[0325] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.
[0326] In short, the above is only an embodiment of the technical solution of this application, and is not intended to limit the protection scope of this application. Any modification, equivalent replacement, improvement, etc. made according to the disclosure of this application shall be included in the protection scope of this application.
Claims
1. A text recognition method, characterized in that: The method comprises: The server stores a first image and annotated text corresponding to the first image; the first image includes a first text; the annotated text includes an identifier and the first text, at least two consecutive characters in the first text belong to a mirror language, and the identifier is the first character or the last character of the annotated text; The server reads the annotated text from storage to obtain a first stored text; When the server recognizes that the position of the identifier in the first stored text has changed, the server performs reverse processing on the first stored text to obtain a second stored text; the second stored text includes the first text; The server trains an initial text recognition model based on the first image and the second stored text to obtain a trained text recognition model, wherein the trained text recognition model is used to recognize text in the image; The server trains an initial text recognition model based on the first image and the second stored text to obtain a trained text recognition model, including: The server deletes the identifier from the second stored text; The server splits the stored text obtained by deletion to obtain multiple characters; The server replaces the characters of the plurality of characters that are not independent glyphs with independent glyphs to obtain a first shaped text; The server inputs the first image into the initial text recognition model to obtain a first predicted text; The server compares the first predicted text with the first shaped text to obtain a first loss; The server optimizes the initial text recognition model based on the first loss to obtain the trained text recognition model.
2. The method according to claim 1, characterized in that The first stored text includes K consecutive characters, the K consecutive characters all belong to the mirror language, and K is a positive integer greater than 1; the j-th character in the second stored text is the K+1-j-th character of the first stored text, and j is a positive integer not greater than K.
3. The method according to claim 1, characterized in that The first stored text includes a non-mirror language and K consecutive characters, the K characters all belong to the mirror language, and K is a positive integer greater than 1; The positions of the characters belonging to the non-mirror language in the first stored text and the second stored text remain unchanged; The j-th character among the K consecutive characters in the second stored text is the K+1-j-th character among the K consecutive characters in the first stored text, where j is a positive integer not greater than K.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: The server performs reverse processing on the first text in the second stored text to obtain a second text; The server deletes the first text from the first image to obtain a first background image; The server fuses the second text and the first background image to obtain a second image, where the second image includes the second text; The second image and the second text are used to train the initial text recognition model.
5. The method according to any one of claims 1 to 3, characterized in that: The mark is an invisible character.
6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When the server recognizes that the position of the logo in the first stored text has not changed, the server trains the initial text recognition model based on the first image and the first stored text.
7. The method according to any one of claims 1 to 3, characterized in that: The mirror language is one of Arabic, Urdu, Uyghur, Persian and Hebrew.
8. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: The server obtains the first image and the first text; The server adds the identifier before the first character or after the last character of the first text to obtain the marked text.
9. A text recognition method, characterized in that: The method comprises: When receiving a user operation instructing to perform text recognition on a target image, the terminal device obtains a target text based on the target image and the text recognition model; The terminal device displays the target text; The training process of the text recognition model includes a training process based on the first image and the second stored text, the second stored text is obtained by reversing the first stored text when the server recognizes that the position of the identifier in the first stored text changes, the first stored text is obtained by reading the annotated text of the first image stored in the server, the annotated text includes the identifier and the first text, at least two consecutive characters in the first text belong to the mirror language, and the identifier is the first character or the last character of the annotated text; The text recognition model is obtained by optimizing the first loss, the first loss is the comparison result of the first predicted text and the first shaped text, the first predicted text is obtained by inputting the first image into the initial text recognition model, and the first shaped text is obtained by text splitting after deleting the identifier from the second stored text; the mirror language in the first shaped text is an independent glyph; The obtaining the target text based on the target image and the text recognition model includes: The terminal device inputs the target image into the initial text recognition model to obtain a predicted text, wherein the predicted text includes a plurality of characters of a mirror language, and the plurality of characters are all independent glyphs; The terminal device replaces the multiple characters with glyphs corresponding to the positions of the multiple characters according to the positions of the multiple characters in the predicted text and a shaping correspondence table to obtain the target text; the shaping correspondence table includes the glyphs of the multiple characters at different positions.
10. An electronic device, characterized in that: The electronic device includes one or more processors and one or more memories; wherein the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, and the computer program code includes computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method as described in any one of claims 1-9.
11. A computer-readable storage medium comprising instructions, characterized in that: When the instructions are executed on an electronic device, the electronic device is caused to execute the method as claimed in any one of claims 1 to 9.
