Text recognition method, apparatus, device, and medium
By generating character detection boxes and matrices, combining them with a language model for semantic recognition, and calculating text probability parameters, the problem of low accuracy in recognizing horizontal and vertical text was solved, achieving higher text recognition accuracy and stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-09
- Publication Date
- 2026-03-24
AI Technical Summary
Existing technologies are prone to false detections when processing horizontal and vertical text, especially when the horizontal and vertical text are close together, which makes it difficult to distinguish them and reduces the accuracy of text recognition.
Character detection boxes are generated using a pre-defined character detection model to form a character matrix. A language model is then used for semantic recognition, and text probability parameters for different text reading directions are calculated. The direction with the highest probability is then selected for text recognition.
It improves the accuracy of text recognition, avoids false detection problems caused by different text writing directions, and enhances the reliability and stability of recognition.
Smart Images

Figure CN116612489B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and for example to a text recognition method, apparatus, device, and medium. Background Technology
[0002] There are many different ways to write text. When there are both horizontal and vertical texts in a scene, existing text recognition methods are prone to false detection. For example, when detecting vertical text, they tend to only distinguish individual characters. Furthermore, when horizontal and vertical texts are close together, existing text recognition algorithms have difficulty distinguishing between them, resulting in reduced accuracy. Summary of the Invention
[0003] The purpose of this application is to provide a text recognition method, apparatus, device, and medium that can improve the accuracy of text recognition.
[0004] To achieve the above objectives, this application adopts the following technical solution:
[0005] This application provides a text recognition method, including:
[0006] Obtain a target image containing text to be recognized, wherein the text to be recognized includes several characters to be recognized;
[0007] Using a preset character detection model, a character detection box is generated for each character to be identified in the target image.
[0008] Based on the preset number of rows and columns of the matrix, select several character detection boxes to form a character matrix;
[0009] In the character matrix, the characters to be recognized within the character detection box are read as matrix characters, and based on different text reading directions, the matrix characters are combined to form several detection word groups;
[0010] The detected word groups are input into a preset language model, and semantic recognition is performed on each detected word group through the language model to obtain semantic parameters.
[0011] Based on the semantic parameters, text probability parameters corresponding to different text reading directions are obtained. The text reading direction with the largest text probability parameter is taken as the target reading direction, and text recognition is performed on the text to be recognized based on the target reading direction.
[0012] This application also provides a text recognition device, including:
[0013] A text acquisition unit is used to acquire a target image containing text to be recognized, wherein the text to be recognized includes several characters to be recognized;
[0014] The character detection unit is used to generate a character detection box for each character to be identified in the target image using a preset character detection model.
[0015] The matrix generation unit is used to select several character detection boxes to form a character matrix according to a preset number of matrix rows and columns;
[0016] The word combination unit is used to read the characters to be recognized in the character detection box as matrix characters in the character matrix, and combine the matrix characters to form several detection word groups based on different text reading directions;
[0017] The probability calculation unit is used to input the detected word groups into a preset language model, and perform semantic recognition on each detected word group through the language model to obtain semantic parameters.
[0018] The text recognition unit is used to obtain text probability parameters corresponding to different text reading directions based on the semantic parameters, take the text reading direction with the largest text probability parameter as the target reading direction, and perform text recognition on the text to be recognized based on the target reading direction.
[0019] This application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the text recognition method described in any of the above claims.
[0020] This application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the text recognition method described in any of the above claims.
[0021] This application discloses a text recognition method that generates character detection boxes for each character in a target image, and then selects a character matrix with a preset number of rows and columns within the structure formed by the character detection boxes, thereby improving the randomness of matrix selection. Furthermore, it selects detection word groups corresponding to different text reading directions within the character matrix, thus achieving random sampling for each text reading direction and improving the reliability of text probability parameter calculation. By using the text reading direction with the highest text probability parameter as the target reading direction and performing text recognition based on this target reading direction, it avoids the problem of false text detection caused by different text writing directions, thereby improving the accuracy of text recognition. Attached Figure Description
[0022] Figure 1 This is a flowchart illustrating a text recognition method according to one embodiment;
[0023] Figure 2This is a schematic diagram of a conventional text detection result in the prior art.
[0024] Figure 3 This is a schematic diagram of a character detection box according to an embodiment;
[0025] Figure 4 This is a schematic diagram of a character matrix according to one embodiment;
[0026] Figure 5 This is a schematic diagram illustrating the recognition result of the text to be recognized in one embodiment;
[0027] Figure 6 This is a structural block diagram of a text recognition device according to an embodiment;
[0028] Figure 7 This is a schematic block diagram of the structure of a computer device according to one embodiment.
[0029] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0030] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0031] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of features, integers, steps, operations, elements, modules, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, modules, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any modules and all combinations of one or more associated listed items.
[0032] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0033] Reference Figure 1 , which is a schematic flowchart of a text recognition method disclosed in this solution, includes:
[0034] S11: Obtain a target image containing the text to be recognized, where the text to be recognized includes several characters to be recognized;
[0035] S12: Generate a character detection box for each character to be recognized in the target image through a preset character detection model;
[0036] S13: Select several character detection boxes to form a character matrix according to the preset matrix row and column numbers;
[0037] S14: In the character matrix, read the characters to be recognized within the character detection box as matrix characters, and form several detection phrases by combining the matrix characters based on different text reading directions;
[0038] S15: Input the detection phrases into a preset language model respectively, and perform semantic recognition on each detection phrase through the language model to obtain semantic parameters;
[0039] S16: Obtain text probability parameters corresponding to different text reading directions according to the semantic parameters, take the text reading direction with the largest text probability parameter as the target reading direction, and perform text recognition on the text to be recognized according to the target reading direction.
[0040] As described in step S11 above, in daily writing, different writing directions of characters often occur due to reasons such as typesetting aesthetics or personal writing habits. For example, in the writing of ancient poems, a vertical arrangement is usually adopted. At this time, if the conventional detection model in the prior art is used for text detection, it is easy to have the situation of incorrect semantic recognition. Exemplarily, if the ancient poem "The sun along the mountain bows; The Yellow River seawards flows. You can enjoy a great sight; By climbing to a greater height." is written vertically, the conventional text detection results in the prior art are usually as Figure 2 shown, that is, recognition results such as "White Yellow Want More" that completely do not conform to the original sentence meaning appear. Therefore, in this embodiment, a target image containing the text to be recognized is first obtained, and the text to be recognized is composed of different characters combined in different writing directions.
[0041] As described in step S12 above, reference Figure 3, which is a schematic diagram of a character detection box provided in this embodiment. Still taking the above-mentioned ancient poem "The sun along the mountain bows; The Yellow River seawards flows. You can enjoy a great sight; By climbing to a greater height." as an example, since when obtaining the target picture, the correct text reading direction cannot be known in advance. Therefore, in this embodiment, a character detection box is generated for each character to be recognized respectively, that is, each character to be recognized is regarded as an independent individual for subsequent recognition, so as to avoid the problem that the text reading direction is misjudged due to preset phrases before determining the text reading direction.
[0042] As described in step S13 above, among the number of rows and columns of the above matrix, the number of columns and the number of rows can be the same or can be preset to be different. In this embodiment, only a matrix with the same number of columns and rows is selected for illustration. Specifically, let the number of columns and rows be n respectively, then any n×n character matrix can be recognized in the Figure 3 character detection box structure shown in, referring to Figure 4 , which is a schematic diagram of a character matrix provided in this embodiment, where n = 2, and matrix combinations such as "white yellow, day river", "want more, poor up", "mountain sea, end flow" can be obtained, and then a combination is randomly selected from the above matrix combinations as the above character matrix.
[0043] As described in step S14 above, according to the recognition result of the previous step, if "white yellow, day river" is used as the character matrix, then the matrix characters "white", "yellow", "day" and "river" can be read. Based on the angle, the text reading directions can be horizontal, vertical and oblique, and based on the reading order, the text reading directions can be forward and backward. Therefore, the detection phrases that can be obtained from the character matrix "white yellow, day river" include ["white yellow", "white day", "yellow river", "day river", "white river", "yellow day", "yellow white", "river day", "day white", "river yellow", "river white", "day yellow"]. For the convenience of description, in this embodiment, only the forward text reading direction is used for illustration. That is, based on different text reading directions, a forward phrase set W = ["white yellow", "white day", "yellow river", "day river", "white river", "yellow day"] can be obtained, and its corresponding subset Wv = ["white day", "yellow river"] represents the vertical direction, that is, the perpendicular direction, and the subset Wh = ["white yellow", "day river"] represents the horizontal direction, that is, the horizontal direction, and the subset Wx = ["white river", "yellow day"] represents the oblique direction. The "white yellow", "white day", "yellow river", "day river", etc. in each subset are the detection phrases.
[0044] As described in step S15 above, after obtaining the detection phrases with different text reading directions, the semantic recognition of each detection phrase can be performed through a language model. In a specific implementation manner, the detection phrases can be scored, or the determination result can be directly output. Specifically, when calculating the semantic parameter by means of scoring, the semantic similarity between the detection phrase and the preset words in the database can be calculated through the language model. The higher the semantic similarity, the larger the semantic parameter, that is, the greater the probability that the detection phrase has correct semantics; when representing the semantic parameter by means of the determination result, it can be determined whether there is a preset word in the database that has the same semantics as the detection phrase through the language model. If it exists, the semantic parameter is 1; if it does not exist, the semantic parameter is 0.
[0045] As described in step S16 above, by comprehensively judging which of the subsets Wx, Wv, and Wh is more in line with the semantics through the semantic parameters of the detection phrases, that is, the vertical text probability parameter is obtained by superimposing the semantic parameters of "day" and "Yellow River", the horizontal text probability parameter is obtained by superimposing the semantic parameters of "white and yellow" and "day and river", and the oblique text probability parameter is obtained by superimposing the semantic parameters of "white river" and "yellow day", so as to determine the final text reading direction according to the magnitude of the text probability parameter. Refer to Figure 5 , which is a schematic diagram of the recognition result of the text to be recognized provided in this embodiment. Since the vertical text probability parameter is the largest, the vertical direction is taken as the final target reading direction. At this time, the text to be recognized is recognized in the vertical manner to obtain the correct recognition result.
[0046] In summary, by generating character detection frames for the characters in the target picture respectively, and then selecting a character matrix with a preset matrix row and column number in the structure composed of the character detection frames, the randomness of matrix selection is improved; different detection phrases corresponding to different text reading directions are respectively selected in the character matrix, so as to randomly sample each text reading direction, and the reliability of text probability parameter calculation is improved; by taking the text reading direction with the largest text probability parameter as the target reading direction and performing text recognition based on this target reading direction, the problem of incorrect text detection caused by different text writing directions is avoided, and the accuracy of text recognition is improved.
[0047] In one embodiment, the semantic recognition of each detection phrase through the language model to obtain the semantic parameter includes:
[0048] Read the semantic dictionary in the language model, where the semantic dictionary contains several reference words whose number of characters corresponds to the matrix row and column number;
[0049] Perform comparison recognition on each detection phrase through the semantic dictionary to obtain the semantic parameter.
[0050] As described above, in this embodiment, semantic recognition is performed through a semantic dictionary, which contains a large number of common words. To ensure the finiteness of the semantic dictionary, the number of characters of the reference words included is limited to be the same as the number of rows and columns n of the matrix. Therefore, as long as there are more elements in the subsets Wx, Wv, and Wh that exist in the semantic dictionary, the greater the text probability parameter, and thus the text reading direction is determined. For example, "white day" and "Yellow River" are more common words, while "white yellow" and "day river" are not common, so it can be determined that the direction of this character matrix is vertical. In addition, when none of the elements in the subsets Wx, Wv, and Wh exist in the semantic dictionary, a character matrix is randomly obtained again for semantic recognition.
[0051] In one embodiment, obtaining the text probability parameters corresponding to different text reading directions according to the semantic parameters and taking the text reading direction with the largest text probability parameter as the target reading direction includes:
[0052] Adding up the semantic parameters corresponding to the detection phrases with the same text reading direction to obtain the text probability parameter corresponding to the text reading direction;
[0053] Identifying the magnitude of the parameter of the text probability parameter for each text reading direction. When there is only one text probability parameter that is the maximum value, taking the text reading direction with the largest text probability parameter as the target reading direction;
[0054] When there are at least two text probability parameters that are the same and are both the maximum values, reselecting a number of character detection frames to form an updated matrix according to the preset updated number of rows and columns, and recalculating the text probability parameter based on the updated matrix until there is only one text probability parameter that is the maximum value, and taking the text reading direction with the largest text probability parameter as the target reading direction.
[0055] As described above, when the text probability parameters corresponding to the subsets Wx, Wv, and Wh are calculated, if the text probability parameter corresponding to Wv is the largest, then taking the vertical text reading direction as the target reading direction.
[0056] Specifically, due to the certain complexity of the combination of Chinese characters, especially the existence of Chinese character expressions such as "acrostic poems" where both horizontal and vertical arrangements conform to common semantics. Therefore, if the size relationship of the text probability parameters is Wx = Wv > Wh and there are at least two cases where the text probability parameters are the same and both are the maximum values, then randomly reselect the update matrix, such as "Yi Ru Shan Hai", and based on the above steps, re-obtain the new subsets, Wv’ = ["Yi Shan", "Ru Hai"], Wh’ = ["Yi Ru", "Shan Hai"], Wx’ = ["Yi Hai", "Ru Shan"], thereby calculating and updating the corresponding text probability parameters. If the size relationship of the text probability parameters obtained at this time is still Wx’ = Wv’ > Wh’ and there are at least two cases where the text probability parameters are the same and both are the maximum values, then randomly select the update matrix again and repeat the above steps until there is only one text probability parameter that is the maximum value. Take the text reading direction with the largest text probability parameter at this time as the target reading direction of the text to be recognized.
[0057] In one embodiment, the recalculating the text probability parameters based on the update matrix until there is only one text probability parameter that is the maximum value, and taking the text reading direction with the largest text probability parameter as the target reading direction includes:
[0058] Record the calculation times of the text probability parameters;
[0059] When the calculation times do not exceed the preset iteration upper limit and there is only one text probability parameter that is the maximum value, then take the text reading direction with the largest text probability parameter as the target reading direction;
[0060] When the calculation times are greater than the iteration upper limit and there are still at least two text probability parameters that are the same and both are the maximum values, then randomly select the text reading direction as the target reading direction.
[0061] As described above, if after multiple re-selections of the update matrix, there are still two or more text probability parameters that are equal and both are the maximum values, it means that no matter which direction the text segment to be recognized is read, it is a sentence that conforms to normal semantics. Therefore, randomly select a text reading direction for text recognition, which can avoid the recognition process from entering an infinite loop and improve the stability of text recognition.
[0062] In one embodiment, the selecting a number of character detection frames to form a character matrix according to the preset matrix row and column numbers includes:
[0063] Generate a coordinate information for each character detection frame according to the arrangement position of the character detection frame;
[0064] Based on the coordinate information, a number of character detection boxes with consecutive coordinate information are selected to form a character matrix according to the number of rows and columns of the matrix, wherein the number of rows and columns of the matrix is a hyperparameter.
[0065] As described above, the character matrix M of the region can be obtained by using the number of character detection boxes and their coordinate information. r×c ,like Figure 3 As shown, the total matrix of this region is 5×4. This scheme takes an n×n character matrix from the total matrix, denoted as m. n×n n is a hyperparameter, which is set to n=2 in this embodiment, such as Figure 4 As shown, characters are extracted from the 2×2 matrix for recognition, and the recognition results are in the order of "white", "yellow", "sun", and "river". Furthermore, when the character region matrix M... r×c When the number of rows or columns in a given array is less than n, then n equals the number of rows or columns, which can be expressed mathematically as:
[0066]
[0067] Here, α is a hyperparameter, and α>1. Based on the characteristics of Chinese, there are relatively few words composed of five characters. Considering the computational complexity, the maximum value of α can be set to 4, that is, α∈(1,4).
[0068] Specifically, in this embodiment, continuous coordinate information means that two adjacent character detection boxes in the character matrix must be character detection boxes with continuous coordinate information. For example, the coordinate information of "white" is (1, 1), "yellow" is (1, 2), and "sun" is (2, 1). Therefore, the coordinate information of "white" is continuous with "yellow" and "sun". However, the coordinate of "building" is (4, 5), so "building" is obviously not an adjacent character detection box of "white".
[0069] In one embodiment, the text reading direction includes horizontal and vertical directions. Then, in the character matrix, the characters to be recognized within the character detection box are read as matrix characters, and based on different text reading directions, the matrix characters are combined to form several detection word groups, including:
[0070] The character detection boxes that make up the rows of the character matrix are used as row detection boxes. The characters to be recognized in the row detection boxes located in the same row are read as row matrix characters. The row matrix characters are arranged into a detection word group in the directions from left to right and from right to left.
[0071] The character detection boxes that make up the columns of the character matrix are used as column detection boxes. The characters to be recognized in the column detection boxes located in the same column are read as column matrix characters. The column matrix characters are arranged into a detection word group in the directions from top to bottom and from bottom to top.
[0072] As mentioned above, in common text layouts, only horizontal or vertical writing is usually used to ensure readability. Therefore, this application can detect only horizontal and vertical text, that is, it only needs to generate detection phrases for rows and columns. In other words, it only needs to retain the positive subsets Wv = ["white sun", "yellow river"] and Wh = ["white yellow", "sun river"], and the negative subsets Wo = ["sun white", "river yellow"] and Wp = ["yellow white", "river sun"], thereby simplifying the calculation steps and improving the recognition efficiency.
[0073] In one embodiment, the training method for the character detection model includes:
[0074] Obtain training images, the initial model, and anchors in the horizontal and vertical directions;
[0075] The initial model is used to generate training text boxes from the training images, and the training images are then divided into grids.
[0076] The grid located in the training text box is used as a positive sample;
[0077] The character detection model is obtained by performing regression calculations on the training text boxes corresponding to the positive samples using the anchor.
[0078] As mentioned above, when only horizontal and vertical text is detected, only horizontal and vertical anchors need to be designed. Specifically, in this embodiment, the anchor design is achieved by designing the aspect ratio. During text detection, a grid is drawn on the image to distinguish different text types. When the grid falls within the training text box, it is a positive sample. At this time, the designed anchor is used to perform regression calculation on the training text box corresponding to the positive sample, thereby eliminating the need for complex anchor design from multiple angles, simplifying the character detection model, and making the model's prediction results more reliable.
[0079] Reference Figure 6 This is a structural block diagram of a text recognition device disclosed in this solution. The device includes:
[0080] The text acquisition unit 100 is used to acquire a target image containing text to be recognized, wherein the text to be recognized includes a plurality of characters to be recognized;
[0081] The character detection unit 200 is used to generate a character detection box for each character to be identified in the target image using a preset character detection model;
[0082] The matrix generation unit 300 is used to select several character detection boxes to form a character matrix according to a preset number of matrix rows and columns;
[0083] The word combination unit 400 is used to read the characters to be recognized in the character detection box as matrix characters in the character matrix, and combine the matrix characters to form several detection word groups based on different text reading directions;
[0084] The probability calculation unit 500 is used to input the detected word groups into a preset language model, and perform semantic recognition on each of the detected word groups through the language model to obtain semantic parameters.
[0085] The text recognition unit 600 is used to obtain text probability parameters corresponding to different text reading directions based on the semantic parameters, take the text reading direction with the largest text probability parameter as the target reading direction, and perform text recognition on the text to be recognized based on the target reading direction.
[0086] In one embodiment, the probability calculation unit 500 is specifically used for:
[0087] Read the semantic dictionary in the language model, wherein the semantic dictionary contains several reference words whose number of characters corresponds to the number of rows and columns of the matrix;
[0088] The semantic parameters are obtained by comparing and identifying each detected word group using the semantic dictionary.
[0089] In one embodiment, the text recognition unit 600 is specifically used for:
[0090] The semantic parameters corresponding to the detected word groups with the same text reading direction are superimposed to obtain the text probability parameters corresponding to the text reading direction.
[0091] The parameter size of the text probability parameter for each text reading direction is identified. When there is only one text probability parameter with a maximum value, the text reading direction with the largest text probability parameter is taken as the target reading direction.
[0092] When at least two of the text probability parameters are the same and both are at their maximum values, several character detection boxes are reselected to form an update matrix according to the preset number of update rows and columns, and the text probability parameters are recalculated based on the update matrix until only one of the text probability parameters is at its maximum value. Then, the text reading direction with the largest text probability parameter is taken as the target reading direction.
[0093] In one embodiment, the text recognition unit 600 is specifically used for:
[0094] Record the number of times the text probability parameter is calculated;
[0095] When the number of calculations is not greater than the preset iteration limit, and there is only one text probability parameter with a maximum value, then the text reading direction with the largest text probability parameter is taken as the target reading direction;
[0096] If the number of calculations exceeds the iteration limit, and there are still at least two text probability parameters that are the same and both are at their maximum values, then the text reading direction is randomly selected as the target reading direction.
[0097] In one embodiment, the matrix generation unit 300 is specifically used for:
[0098] Based on the arrangement of the character detection boxes, generate coordinate information for each character detection box;
[0099] Based on the coordinate information, a number of character detection boxes with consecutive coordinate information are selected to form a character matrix according to the number of rows and columns of the matrix, wherein the number of rows and columns of the matrix is a hyperparameter.
[0100] In one embodiment, the phrase combination unit 400 is specifically used for:
[0101] The character detection boxes that make up the rows of the character matrix are used as row detection boxes. The characters to be recognized in the row detection boxes located in the same row are read as row matrix characters. The row matrix characters are arranged into a detection word group in the directions from left to right and from right to left.
[0102] The character detection boxes that make up the columns of the character matrix are used as column detection boxes. The characters to be recognized in the column detection boxes located in the same column are read as column matrix characters. The column matrix characters are arranged into a detection word group in the directions from top to bottom and from bottom to top.
[0103] In one embodiment, a model training unit 700 is further included, for:
[0104] Obtain training images, the initial model, and anchors in the horizontal and vertical directions;
[0105] The initial model is used to generate training text boxes from the training images, and the training images are then divided into grids.
[0106] The grid located in the training text box is used as a positive sample;
[0107] The character detection model is obtained by performing regression calculations on the training text boxes corresponding to the positive samples using the anchor.
[0108] Reference Figure 7 This application also provides a computer device whose internal structure can be as follows: Figure 7 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor is designed to provide computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores operating devices, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores text detection data, etc. The network interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a text recognition method.
[0109] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer equipment on which the present application is applied.
[0110] One embodiment of this application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a text recognition method. It is understood that the computer-readable storage medium in this embodiment can be a volatile readable storage medium or a non-volatile readable storage medium.
[0111] This application discloses a text recognition method, apparatus, device, and medium. By generating character detection boxes for each character in a target image, a character matrix with a preset number of rows and columns is selected from the structure formed by the character detection boxes, improving the randomness of matrix selection. Detection word groups corresponding to different text reading directions are selected from the character matrix, thereby achieving random sampling for each text reading direction and improving the reliability of text probability parameter calculation. By using the text reading direction with the highest text probability parameter as the target reading direction and performing text recognition based on this target reading direction, the problem of false text detection caused by different text writing directions is avoided, thus improving the accuracy of text recognition.
[0112] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media provided in this application and in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0113] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0114] The above description is merely a preferred embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A text recognition method, wherein, include: Obtain a target image containing text to be recognized, wherein the text to be recognized includes several characters to be recognized; Using a preset character detection model, a character detection box is generated for each character to be identified in the target image. A character matrix is formed by selecting several character detection boxes according to a preset number of matrix rows and columns; this includes: generating coordinate information for each character detection box according to its arrangement position; and selecting several character detection boxes with consecutive coordinate information to form a character matrix based on the coordinate information, according to the number of matrix rows and columns, wherein the number of matrix rows and columns is a hyperparameter; consecutive coordinate information means that two adjacent character detection boxes in the character matrix must be character detection boxes with consecutive coordinate information. In the character matrix, the characters to be recognized within the character detection box are read as matrix characters, and based on different text reading directions, the matrix characters are combined to form several detection word groups; The detected word groups are input into a preset language model, and semantic recognition is performed on each detected word group through the language model to obtain semantic parameters. Based on the semantic parameters, text probability parameters corresponding to different text reading directions are obtained. The text reading direction with the largest text probability parameter is taken as the target reading direction, and text recognition is performed on the text to be recognized based on the target reading direction.
2. The text recognition method according to claim 1, wherein, The step of performing semantic recognition on each detected word group using the language model to obtain semantic parameters includes: Read the semantic dictionary in the language model, wherein the semantic dictionary contains several reference words whose number of characters corresponds to the number of rows and columns of the matrix; The semantic parameters are obtained by comparing and identifying each detected word group using the semantic dictionary.
3. The text recognition method according to claim 1, wherein, The step of obtaining text probability parameters corresponding to different text reading directions based on the semantic parameters, and taking the text reading direction with the largest text probability parameter as the target reading direction, includes: The semantic parameters corresponding to the detected word groups with the same text reading direction are superimposed to obtain the text probability parameters corresponding to the text reading direction. The parameter size of the text probability parameter for each text reading direction is identified. When there is only one text probability parameter with a maximum value, the text reading direction with the largest text probability parameter is taken as the target reading direction. When at least two of the text probability parameters are the same and both are at their maximum values, several character detection boxes are reselected to form an update matrix according to the preset number of update rows and columns, and the text probability parameters are recalculated based on the update matrix until only one of the text probability parameters is at its maximum value. Then, the text reading direction with the largest text probability parameter is taken as the target reading direction.
4. The text recognition method according to claim 3, wherein, The step of recalculating the text probability parameters based on the update matrix until only one text probability parameter has a maximum value, and then taking the text reading direction with the maximum text probability parameter as the target reading direction, includes: Record the number of times the text probability parameter is calculated; When the number of calculations is not greater than the preset iteration limit, and there is only one text probability parameter with a maximum value, then the text reading direction with the largest text probability parameter is taken as the target reading direction; If the number of calculations exceeds the iteration limit, and there are still at least two text probability parameters that are the same and both are at their maximum values, then the text reading direction is randomly selected as the target reading direction.
5. The text recognition method according to claim 1, wherein, In the character matrix, the characters to be recognized within the character detection box are read as matrix characters, and based on different text reading directions, the matrix characters are combined to form several detection word groups, including: The character detection boxes that make up the rows of the character matrix are used as row detection boxes. The characters to be recognized in the row detection boxes located in the same row are read as row matrix characters. The row matrix characters are arranged into a detection word group in the directions from left to right and from right to left. The character detection boxes that make up the columns of the character matrix are used as column detection boxes. The characters to be recognized in the column detection boxes located in the same column are read as column matrix characters. The column matrix characters are arranged into a detection word group in the directions from top to bottom and from bottom to top.
6. The text recognition method according to claim 1, wherein, The training method for the character detection model includes: Obtain training images, the initial model, and anchors in the horizontal and vertical directions; The initial model is used to generate training text boxes from the training images, and the training images are then divided into grids. The grid located in the training text box is used as a positive sample; The character detection model is obtained by performing regression calculations on the training text boxes corresponding to the positive samples using the anchor.
7. A text recognition device for implementing the method of any one of claims 1-6, wherein, include: A text acquisition unit is used to acquire a target image containing text to be recognized, wherein the text to be recognized includes several characters to be recognized; The character detection unit is used to generate a character detection box for each character to be identified in the target image using a preset character detection model. The matrix generation unit is used to select several character detection boxes to form a character matrix according to a preset number of matrix rows and columns; The word combination unit is used to read the characters to be recognized in the character detection box as matrix characters in the character matrix, and combine the matrix characters to form several detection word groups based on different text reading directions; The probability calculation unit is used to input the detected word groups into a preset language model, and perform semantic recognition on each detected word group through the language model to obtain semantic parameters. The text recognition unit is used to obtain text probability parameters corresponding to different text reading directions based on the semantic parameters, take the text reading direction with the largest text probability parameter as the target reading direction, and perform text recognition on the text to be recognized based on the target reading direction.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the text recognition method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the text recognition method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for recognizing direction of character in image block
CN102890783A
Device and method for processing image
JP1998228530A