Method and device for recognizing text image
By determining the positive direction of the text image through the trained direction recognition model and using the text recognition model for recognition, the problem of poor generalization ability of text image recognition in the existing technology is solved, and accurate recognition of various types of text images is achieved.
Patent Information
- Application Number
- CN201910572252.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-06-28
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2039-06-28
AI Technical Summary
Text image recognition methods in the prior art have poor generalization capabilities and cannot effectively recognize different types of text images.
Use the trained direction recognition model to determine the positive direction of the text image to be recognized, and use the trained text recognition model to perform text recognition. By extracting multiple image areas, using a deep neural network to optimize the direction recognition model parameters, and performing pre-recognition Grayscale processing.
The generalization ability of the text image recognition method is improved, and various types of text images can be accurately recognized.
Smart Images

Figure CN110443239B_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to the field of big data technology, and in particular to a text image recognition method and a device thereof. [Background technology]
[0002] Text image recognition is achieved through text detection, text recognition, and required field extraction, but the positive direction of the text image to be recognized must be determined first.
[0003] In the related art, only the positive direction of a specified type of text image to be recognized can be automatically determined, and then the text image can be recognized, which has a technical problem of poor generalization ability. [Summary of the invention]
[0004] In view of this, an embodiment of the present invention provides a text image recognition method and a device thereof, so as to solve the problem of poor generalization ability of the text image recognition method in the prior art.
[0005] On the one hand, an embodiment of the present invention provides a method for recognizing text images, the method comprising: obtaining a text image to be recognized; extracting multiple image regions from the text image to be recognized; using a trained direction recognition model to perform direction recognition on each of the image regions respectively; determining the positive direction of the text image to be recognized based on the positive directions of the multiple image regions; and performing text recognition on the text image to be recognized based on the positive direction of the text image to be recognized using a trained text recognition model.
[0006] Furthermore, the trained direction recognition model is trained and generated by the following steps: obtaining a reference text image; wherein the reference text image includes multiple text boxes; respectively obtaining a positive direction mark and a position mark corresponding to each of the text boxes; randomly cutting out a square area from the reference text image; wherein the square area includes the text box with a first value as a training text box; rotating the square area, and respectively modifying the positive direction mark corresponding to each of the training text boxes in the square area; inputting the square area into a deep neural network; comparing the output of the deep neural network with the positive direction mark and the position mark corresponding to each of the training text boxes to optimize the parameters of the deep neural network; and determining the trained direction recognition model based on the optimized parameters of the deep neural network.
[0007] Furthermore, the use of the trained direction recognition model to perform direction recognition on each of the image regions separately includes: inputting the image region into the trained direction recognition model to generate the positive direction mark corresponding to the multiple text boxes in the image region; calculating the confidence levels when the image regions correspond to different positive direction marks respectively based on the positive direction marks corresponding to the multiple text boxes; and determining the positive direction mark corresponding to the image region based on the confidence levels.
[0008] Furthermore, before performing text recognition on the image of text to be recognized using a trained text recognition model according to the positive direction of the image of text to be recognized, the method further includes: performing grayscale processing on the image of text to be recognized.
[0009] Furthermore, the trained text recognition model is generated by the following steps: obtaining a reference text image and a corresponding reference text; inputting the reference text image into a two-layer stacked bidirectional long short-term memory network; using a loss function to calculate the difference between the output of the two-layer stacked bidirectional long short-term memory network and the reference text to train the two-layer stacked bidirectional long short-term memory network.
[0010] On the one hand, an embodiment of the present invention provides a device for recognizing text images, the device comprising: a first acquisition module, used to acquire a text image to be recognized; an extraction module, used to extract multiple image areas from the text image to be recognized; a direction recognition module, used to use a trained direction recognition model to perform direction recognition on each of the image areas respectively; a first determination module, used to determine the positive direction of the text image to be recognized based on the positive directions of the multiple image areas; and a text recognition module, used to perform text recognition on the text image to be recognized based on the positive direction of the text image to be recognized using a trained text recognition model.
[0011] Furthermore, the device also includes: a second acquisition module, which acquires a reference text image; wherein the reference text image includes multiple text boxes; a third acquisition module, which respectively acquires the positive direction mark and position mark corresponding to each of the text boxes; a cropping module, which is used to randomly crop a square area from the reference text image; wherein the square area includes the text box of the first value as a training text box; a rotation module, which is used to rotate the square area; a modification module, which is used to respectively modify the positive direction mark corresponding to each of the training text boxes in the square area; a first input module, which is used to input the square area into a deep neural network; a comparison module, which is used to compare the output of the deep neural network with the positive direction mark and the position mark corresponding to each of the training text boxes to optimize the parameters of the deep neural network; a second determination module, which is used to determine the trained direction recognition model based on the optimized parameters of the deep neural network.
[0012] Furthermore, the direction recognition module includes: an input submodule, used to input the image area into the trained direction recognition model to generate the positive direction mark corresponding to the multiple text boxes in the image area; a calculation submodule, used to calculate the confidence level when the image area corresponds to different positive direction marks according to the positive direction marks corresponding to the multiple text boxes; and a determination submodule, used to determine the positive direction mark corresponding to the image area according to the confidence level.
[0013] Furthermore, the device also includes: a grayscale processing module, which is used to perform grayscale processing on the text image to be recognized.
[0014] Furthermore, the device also includes: a fourth acquisition module, used to acquire a reference text image and a corresponding reference text; a second input module, used to input the reference text image into a two-layer stacked bidirectional long short-term memory network; and a calculation module, used to use a loss function to calculate the difference between the output of the two-layer stacked bidirectional long short-term memory network and the reference text to train the two-layer stacked bidirectional long short-term memory network.
[0015] On the one hand, an embodiment of the present invention provides a computer device, including a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions, and the program instructions, when loaded and executed by the processor, implement the steps of the above-mentioned text image recognition method.
[0016] On the one hand, an embodiment of the present invention provides a storage medium, wherein the storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the above-mentioned text image recognition method.
[0017] In an embodiment of the present invention, a direction recognition model is first used to determine the positive direction of the text image to be recognized, and then a text recognition model is used to perform text recognition. Various types of text images can be recognized, which solves the problem of poor generalization ability of the text image recognition method in the prior art and achieves the effect of improving the generalization ability of the text image recognition method.
Brief Description of the Drawings
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 A flowchart of a text image recognition method provided by an embodiment of the present invention;
[0020] Figure 2 A schematic diagram of the structure of a long short-term memory network provided by an embodiment of the present invention;
[0021] Figure 3 A schematic diagram of the structure of a double-layer stacked bidirectional long short-term memory neural network provided by an embodiment of the present invention;
[0022] Figure 4 A schematic diagram of the structure of a multi-layer stacked bidirectional long short-term memory neural network provided by an embodiment of the present invention;
[0023] Figure 5 An example of a CTC model provided in an embodiment of the present invention for recognizing a text image;
[0024] Figure 6 A schematic diagram of a flow chart of a method for generating a direction recognition model provided by an embodiment of the present invention;
[0025] Figure 7 An example of determining the positive direction of a text image to be recognized provided by an embodiment of the present invention;
[0026] Figure 8 A schematic diagram of the structure of a text image recognition device provided by an embodiment of the present invention;
[0027] Fig. 9 A schematic diagram of the structure of another text image recognition device provided by an embodiment of the present invention; and
[0028] Fig.10 A schematic diagram of a computer device provided by an embodiment of the present invention. [Specific implementation method]
[0029] In order to better understand the technical solution of the present invention, the embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0030] It should be clear that the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0032] It should be understood that the term "and / or" used in this article is only a description of the same field of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0033] It should be understood that, although the terms first, second, third, etc. may be used to describe preset ranges, etc. in the embodiments of the present invention, these preset ranges should not be limited to these terms. These terms are only used to distinguish preset ranges from each other. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.
[0034] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0035] Based on the description of the prior art, it can be known that in the related technology, only the positive direction of the specified type of text image to be recognized can be automatically determined, and then the text image can be recognized, which has a technical problem of poor generalization ability.
[0036] To address this problem, an embodiment of the present invention provides a method for recognizing text images. A direction recognition model is first used to determine the positive direction of the text image to be recognized, and then a text recognition model is used to perform text recognition. This method is capable of recognizing various types of text images, thereby improving the generalization capability of the text image recognition method.
[0037] Figure 1 A flowchart of a text image recognition method provided by an embodiment of the present invention.
[0038] like Figure 1 As shown, the method includes:
[0039] Step S101, obtaining a text image to be recognized.
[0040] The text image refers to an image including text content, such as a photo of a certificate, a photo of a bill, a screenshot of a browsing page, etc., which is not limited in the embodiment of the present invention.
[0041] Step S102: extracting a plurality of image regions from the image of the text to be recognized.
[0042] It should be noted that the text formats in different types of text images to be recognized are different. Specifically, the positive directions of texts at different positions in the same text image may be different. Therefore, in order to determine the positive direction of the text image to be recognized, it is necessary to recognize the positive directions of the texts at different positions respectively, and then combine the positive directions of the texts at different positions to obtain the positive direction of the text image to be recognized.
[0043] For example, the tax information on the VAT invoice is arranged along a first direction, while the information of the invoice printer is arranged along a second direction perpendicular to the first direction. Therefore, when determining the positive direction of the invoice, it is necessary to comprehensively consider the impact of the tax information and the invoice printer information on determining the positive direction of the entire VAT invoice, and then use the first direction as a reference direction for determining the positive direction of the invoice.
[0044] It should be understood that in order to realize the recognition of the positive direction of text in different positions and reduce the workload of direction recognition of the text image to be recognized, different image areas can be extracted as samples for direction recognition and direction recognition can be performed separately to obtain the positive direction of the entire text image to be recognized.
[0045] Furthermore, since the positions of the characters in different types of text images are different, and the text images are usually rectangular or square. In order to make the text image recognition method proposed in the embodiment of the present invention applicable to various types of text images, a possible implementation method is to extract five square image areas at the center and four corners of the text image as a general image area extraction scheme. Among them, the side length of the square is equal to half of the smaller value of the height and width of the text image.
[0046] Step S103: Use the trained direction recognition model to perform direction recognition on each image region.
[0047] The trained direction recognition model can recognize the positive direction of each paragraph of text content in each image area, and comprehensively determine the positive direction of each image area based on the positive directions of multiple paragraphs of text content in each image area.
[0048] Step S104, determining the positive direction of the to-be-recognized text image according to the positive directions of the plurality of image regions.
[0049] It can be understood that different image regions have different influences on determining the positive direction of the text image to be recognized because they are located in different positions in the text image to be recognized and have different proportions of text content. Therefore, the influence is also different when determining the positive direction of the text image to be recognized.
[0050] Step S105 , performing text recognition on the text image to be recognized using a trained text recognition model according to the positive direction of the text image to be recognized.
[0051] It can be understood that the trained text recognition model can perform text recognition on the text image to be recognized from the positive direction to improve the efficiency and accuracy of model recognition.
[0052] Among them, the trained text recognition model can be generated by training through the following steps:
[0053] Step S11, obtaining a reference text image and corresponding reference text.
[0054] The reference text image and the reference text are used to train the text recognition model, so the reference text is the correct recognition result of the reference text image and is pre-entered by manual recognition.
[0055] Step S12, inputting the reference text image into a two-layer stacked bidirectional long short-term memory network.
[0056] It should be noted that the two-layer stacked bidirectional long short-term memory network proposed in the embodiment of the present invention is an optimized network of the long short-term memory network.
[0057] like Figure 2 As shown in the figure, compared with the simple recurrent neural network, the long short-term memory network adds memory unit c, input gate i, forget gate f and output gate o. The combination of these gates and memory units greatly improves the ability of the recurrent neural network to process long sequence data. If the function represented by the long short-term memory network is recorded as
[0058] F, then its formula is:
[0059] h t =F(x t ,h t-1 )
[0060] F is composed of the following formula:
[0061] it =σ(W xi x t +W hi c t-1 +W ci c t-1 +b i )
[0062] f t =σ(W xf x t +W hf c t-1 +W cf c t-1 +b f )
[0063] c t =f t ⊙c t-1 +i t ⊙tanh(W xc x t +W hc h t-1 +b c )
[0064] o t =σ(W xo x t +W ho h t-1 +W co c t-1 +b o )
[0065] h t =o t ⊙tanh(c t )
[0066] Among them, i t ,f t ,c t ,o t Represent the vector values of the input gate, forget gate, memory unit and output gate respectively. The ones with subscript W and b are model parameters, tanh is the hyperbolic tangent function, and ⊙ represents the element-by-element multiplication operation. The input gate controls the strength of the new input entering the memory unit c, the forget gate controls the strength of the memory unit to maintain the value of the previous moment, and the output gate controls the strength of the output memory unit. The three gates are calculated in a similar way, but have completely different parameters, and they each control the memory unit c in a different way. The long short-term memory network enhances its ability to handle long-distance dependency problems by adding memory and control gates to the simple recurrent neural network, and can handle longer sequence data.
[0067] h in long short-term memory networkst Contains the input information before time t, that is, the previous information. Similarly, in order to obtain the following information, we can use a recurrent neural network in the opposite direction (processing the input in reverse order).
[0068] like Figure 3 As shown in the figure, combined with the method of building deep recurrent neural networks (deep neural networks can often obtain more abstract and advanced feature representations), we can model time series data by building a more powerful stacked bidirectional long short-term memory neural network.
[0069] like Figure 4 As shown in the figure, the odd-numbered LSTM neural network is forward, the even-numbered LSTM neural network is reverse, the higher-level LSTM neural network uses the information of the lower-level LSTM neural network and all previous layers as input, and the highest-level LSTM neural network sequence is subjected to the maximum pooling in the time dimension to obtain a fixed-length vector representation of the text (this representation fully integrates the contextual information of the text and performs a deep abstraction of the text), and finally the text is connected to softmax to build a classification model.
[0070] It should be noted that in deep learning, increasing the number of neural network layers means increasing the depth and the number of parameters. While ensuring that the model size is moderate, more layers can extract more abstract image feature information.
[0071] The biggest advantage of deep learning is its more advanced ability to automatically mine "structures". For example, it does not require us to provide all the features, but instead spontaneously searches for the most appropriate features to describe the data set.
[0072] A complex pattern, such as "face recognition", can actually be seen as a hierarchical superposition of simple patterns, from the underlying pattern of contour texture on the face, to the intermediate pattern such as eyes and nose, to the highest level of complex pattern such as a unique individual.
[0073] Only by identifying the underlying pattern can we find the intermediate pattern, and only by finding the intermediate pattern can we further find the advanced pattern. We cannot directly process pixels to achieve such a complex pattern. Instead, we need to learn the structure from simple patterns to complex patterns, so we need to adopt a multi-layer network structure.
[0074] It can be understood that the text recognition model proposed in the embodiment of the present invention can also use a three-layer or even more-layer stacked bidirectional long short-term memory neural network for feature extraction, and the embodiment of the present invention does not limit this.
[0075] Step S13, using a loss function to calculate the difference between the output of the two-layer stacked bidirectional long short-term memory network and the reference text, so as to train the two-layer stacked bidirectional long short-term memory network.
[0076] It should be understood that the output of the two-layer stacked bidirectional long short-term memory network is the recognition result of the reference text image. In order to quantify the difference between the recognition results of the reference text and the reference text image, the difference can be calculated by the loss function.
[0077] One possible implementation method is to use the CTC loss function for calculation. CTC is suitable for time series problems with uncertain alignment relationships between input features and output labels. CTC can automatically optimize model parameters and alignment segmentation boundaries end-to-end.
[0078] For example, a 32x 256 image can be divided into 256 columns at most, that is, the maximum input feature is 256, and the maximum length of the output label is set to 18. This can be optimized using the CTC model. Regarding the CTC model, assume that the 32x 256 image has a digital string label of "123". The image is divided into columns (CTC will optimize the segmentation model), and then each block is used to identify the number and find out the probability of each number or special character (unrecognizable blocks are marked as special characters "-"). In this way, the category probability distribution of each independent modeling unit individual (divided block) (including the "-" node) based on the input feature sequence (image) is obtained. Based on the probability distribution, the probability P(123) that the label sequence is "123" is calculated. Of course, the probability of "123" is set as the sum of all subsequences, where the subsequences include '-' and continuous repetitions of '1', '2', and '3'.
[0079] For example, if Figure 5 As shown in the figure, the CTC model is used to identify text images containing the THE-CAT-letter sequence. The corresponding recognition result may be __TH____E_-_C__AAA__TT__-, with a corresponding probability of P1, or _T__H__EE__-_C__AA__T___, with a corresponding probability of P2. After alignment, repeated letters and spaces "_" are removed to obtain the probability P corresponding to the THE-CAT-letter sequence, and then the recognition result is determined to be THE-CAT-.
[0080] Furthermore, in order to reduce the computational complexity of text recognition model training and recognition, a possible implementation method is, before using the trained text recognition model to perform text recognition on the text image to be recognized according to the positive direction of the text image to be recognized, it also includes: grayscale processing of the text image to be recognized.
[0081] It should be understood that the color of each pixel in the image is determined by three components, A, G, and B, and each component has 256 possible values, so a pixel can have a range of more than 16 million (256*256*256) colors. In order to reduce the amount of computation for image recognition, the text image to be recognized can be grayscaled.
[0082] The first possible implementation method is to find the average value of the three components R, G, and B of each pixel, and then assign the average value to the three components of the pixel.
[0083] The second possible implementation method is that according to the physical meaning of the Y component in the YUV color space, the brightness of the pixel point is reflected by this value. According to the changing relationship between the RGB and YUV color spaces, the correspondence between the brightness Y and the three color components R, G, and B can be established: Y=0.3R+0.59G+0.11B, and the grayscale value of the pixel point is expressed by the brightness value.
[0084] Furthermore, in order to keep the size of the text image to be recognized consistent and improve the efficiency of text recognition, a possible implementation method is to scale the text image to be recognized proportionally so that its height is a preset value, such as 32, and then set a maximum width value. For pixels whose width after scaling is less than the maximum width value, fill them with a grayscale value of 0.
[0085] Accordingly, when training a text recognition model, the reference text image that has been grayed and / or scaled may be used for model training to reduce the amount of computation required for model training.
[0086] In summary, the text image recognition method provided in the embodiment of the present invention obtains a text image to be recognized, and extracts multiple image regions from the text image to be recognized. A trained direction recognition model is used to perform direction recognition on each image region respectively, and the positive direction of the text image to be recognized is determined according to the positive directions of the multiple image regions. According to the positive direction of the text image to be recognized, a trained text recognition model is used to perform text recognition on the text image to be recognized. In this way, the positive direction of the text image to be recognized is first determined using the direction recognition model, and then the text recognition model is used for text recognition. This allows recognition of various types of text images, thereby improving the generalization ability of the text image recognition method.
[0087] In order to more clearly illustrate the direction recognition model proposed in the embodiment of the present invention, the embodiment of the present invention further proposes a method for generating a direction recognition model. Figure 6 A flow chart of a method for generating a direction recognition model provided by an embodiment of the present invention is shown as follows: Figure 6 As shown, the trained direction recognition model can be generated by the following steps:
[0088] Step S201, obtaining a reference text image.
[0089] The reference text image includes a plurality of text boxes.
[0090] It should be noted that, unlike the aforementioned reference text image, the purpose of the reference text image proposed in the embodiment of the present invention is to train the direction recognition performance of the direction recognition model, so the positive directions of the text contents in the reference text image are different. The text contents are distinguished in the form of text boxes, and the positive directions of the text contents in the same text box are the same.
[0091] Furthermore, if a text image contains text content in multiple directions and corresponds to correct text recognition results, then the text image can be used as a reference text image to train a direction recognition model, and can also be used as a reference text image to train a text recognition model.
[0092] Step S202, respectively obtain the positive direction mark and position mark corresponding to each text box.
[0093] It should be understood that the direction recognition model in the embodiment of the present invention first divides the text content in the image area into text boxes, then performs direction recognition on each text box, and then determines the positive direction of the image area. In order to distinguish different text boxes, they need to be marked with positions.
[0094] Therefore, when training the direction recognition model, it is also necessary to obtain the positive direction mark and position mark corresponding to each text box in the reference text image used for training.
[0095] Among them, a possible marking method for the positive direction is that -1 represents an uncertain direction, 0 represents a positive direction, 1 represents 90 degrees counterclockwise, 2 represents 180 degrees counterclockwise, and 3 represents 270 degrees counterclockwise.
[0096] A possible method of marking the position is to use the horizontal and vertical coordinates of the four vertices of the text box, a total of 8 numbers, as position codes for marking.
[0097] Step S203: randomly cropping a square area from the reference text image.
[0098] The square area includes a text box of the first value as a training text box.
[0099] It should be understood that since the image area proposed in the embodiment of the present invention is a square, the square area can be used to train the direction recognition model.
[0100] In addition, in combination with the position mark corresponding to each text box, it is possible to determine which text boxes in the reference text image are within the square area.
[0101] Furthermore, in order to make the square area more representative, a possible implementation method is to remove 1 / 8 of the width on the left and right sides of the reference text image and 1 / 8 of the height on the top and bottom sides before randomly cropping a square area from the reference text image to obtain an optimized reference text image.
[0102] Furthermore, the side length of the square area can be randomly generated from [len / 3, len], where len is a smaller value of the height and width of the reference text image.
[0103] A preferred implementation manner is that the square area includes at least three text boxes.
[0104] Step S204: rotate the square area and modify the positive direction mark corresponding to each training text box in the square area respectively.
[0105] It should be noted that, since the square area proposed in the embodiment of the present invention is for training the direction recognition performance of the direction recognition model, the square area can be rotated and the rotated square area can also be used as a training sample of the direction recognition model.
[0106] It can be understood that after the square area is rotated, the positive direction mark corresponding to each training text box also needs to be modified accordingly, as the positive direction mark corresponding to each training text box in the new training sample.
[0107] Step S205: input the square area into the deep neural network.
[0108] The square area here includes not only a square area directly cropped from the reference text image, but also a new training sample obtained by rotation in step S204.
[0109] Step S206, comparing the output of the deep neural network with the positive direction mark and position mark corresponding to each training text box to optimize the parameters of the deep neural network.
[0110] Step S207, determining a trained direction recognition model based on the optimized parameters of the deep neural network.
[0111] Among them, the deep neural network can be a resnet network or a mobilenet network. Compared with the resnet network, the mobilenet network has a smaller model, runs faster, and has more accurate recognition.
[0112] Thus, the training of the direction recognition model is achieved.
[0113] Based on the above description of the direction recognition model training process, it can be known that the training data of the direction recognition model proposed in the embodiment of the present invention is the text box in the square area and the corresponding positive direction mark and position mark. Accordingly, step S103 uses the trained direction recognition model to perform direction recognition on each image area respectively, including:
[0114] Step S21, inputting the image region into the trained direction recognition model to generate positive direction marks corresponding to multiple text boxes in the image region.
[0115] It should be noted that since the position of the text box and the size of the image area occupied will affect its determination of the positive direction of the image area, it is also necessary to determine the influence of each text box on the determination of the positive direction of the image area based on the position mark of the text box, which is specifically quantified by the confidence level.
[0116] Step S22, calculating the confidence when the image areas correspond to different positive direction marks respectively according to the positive direction marks corresponding to the multiple text boxes.
[0117] Specifically, weighted calculations are performed on different positive directions based on the position of each text box and the size of the image area it occupies, and the confidences corresponding to different positive direction marks are obtained after normalization.
[0118] Step S23: determining the positive direction mark corresponding to the image area according to the confidence level.
[0119] Specifically, the positive direction with the largest corresponding confidence value is selected as the positive direction mark corresponding to the image area.
[0120] Furthermore, after respectively determining the positive direction mark and the corresponding confidence value corresponding to each image region, the positive direction mark with the largest corresponding confidence value is selected as the positive direction of the text image to be recognized.
[0121] In order to more clearly illustrate how the text image recognition method proposed in the embodiment of the present invention determines the positive direction of the text image to be recognized based on the positive directions of multiple image regions, an example is given below.
[0122] like Figure 7As shown, the text image includes 5 image areas. The maximum possible positive direction of the first image area is 270 degrees counterclockwise, marked with the number 3, and the corresponding confidence is 0.687790. The maximum possible positive direction of the second image area is 270 degrees counterclockwise, marked with the number 3, and the corresponding confidence is 0.856162. The maximum possible positive direction of the third image area is 270 degrees counterclockwise, marked with the number 3, and the corresponding confidence is 0.997811. The maximum possible positive direction of the fourth image area is 270 degrees counterclockwise, marked with the number 3, and the corresponding confidence is 0.950631. The maximum possible positive direction of the fifth image area is 270 degrees counterclockwise, marked with the number 3, and the corresponding confidence is 0.985696. According to the recognition results of the five image areas, it is finally determined that the positive direction of the entire text image is 270 degrees counterclockwise, marked with the number 3.
[0123] In order to implement the above embodiment, the present invention further provides a text image recognition device. Figure 8 The structure diagram of a text image recognition device provided by an embodiment of the present invention is shown in FIG. Figure 8 As shown, the device includes: a first acquisition module 310 , an extraction module 320 , a direction recognition module 330 , a first determination module 340 , and a text recognition module 350 .
[0124] The first acquisition module 310 is used to acquire a text image to be recognized.
[0125] The extraction module 320 is used to extract multiple image regions from the text image to be recognized.
[0126] The direction recognition module 330 is used to perform direction recognition on each image region using the trained direction recognition model.
[0127] The first determination module 340 is used to determine the positive direction of the to-be-recognized text image according to the positive directions of the plurality of image regions.
[0128] The text recognition module 350 is used to perform text recognition on the text image to be recognized using a trained text recognition model according to the positive direction of the text image to be recognized.
[0129] Furthermore, in order to reduce the amount of computation for text recognition model training and recognition, a possible implementation is that the device further includes: a grayscale processing module 360 for performing grayscale processing on the text image to be recognized.
[0130] Furthermore, in order to train the text recognition model, in a possible implementation, the device further includes: a fourth acquisition module 370, for acquiring a reference text image and a corresponding reference text. A second input module 380, for inputting the reference text image into a two-layer stacked bidirectional long short-term memory network. A calculation module 390, for calculating the difference between the output of the two-layer stacked bidirectional long short-term memory network and the reference text using a loss function to train the two-layer stacked bidirectional long short-term memory network.
[0131] It should be noted that the above explanation of the embodiment of the text image recognition method is also applicable to the text image recognition device of this embodiment, and will not be repeated here.
[0132] In summary, the text image recognition device provided in the embodiment of the present invention obtains a text image to be recognized and extracts multiple image regions from the text image to be recognized. A trained direction recognition model is used to perform direction recognition on each image region respectively, and the positive direction of the text image to be recognized is determined according to the positive directions of the multiple image regions. According to the positive direction of the text image to be recognized, a trained text recognition model is used to perform text recognition on the text image to be recognized. In this way, the positive direction of the text image to be recognized is first determined using the direction recognition model, and then the text recognition model is used to perform text recognition. This allows recognition of various types of text images, thereby improving the generalization ability of the text image recognition method.
[0133] In order to implement the above embodiment, the present invention further provides another text image recognition device. Fig. 9 FIG. 1 is a schematic diagram of the structure of another text image recognition device provided by an embodiment of the present invention. Fig. 9 As shown, based on Figure 8 As shown in the device structure, the device also includes: a second acquisition module 410, a third acquisition module 420, a cropping module 430, a rotation module 440, a modification module 450, a first input module 460, a comparison module 470, and a second determination module 480.
[0134] The second acquisition module 410 acquires a reference text image, wherein the reference text image includes a plurality of text boxes.
[0135] The third acquisition module 420 acquires the positive direction mark and the position mark corresponding to each text box respectively.
[0136] The cropping module 430 is used to randomly crop a square area from the reference text image, wherein the square area includes a text box of the first value as a training text box.
[0137] The rotation module 440 is used to rotate the square area.
[0138] The modification module 450 is used to modify the positive direction mark corresponding to each training text box in the square area respectively.
[0139] The first input module 460 is used to input the square area into the deep neural network.
[0140] The comparison module 470 is used to compare the output of the deep neural network with the positive direction mark and the position mark corresponding to each training text box to optimize the parameters of the deep neural network.
[0141] The second determination module 480 is used to determine the trained direction recognition model based on the parameters of the optimized deep neural network.
[0142] Furthermore, in order to determine the positive direction mark corresponding to the image area, a possible implementation method is that the direction recognition module 330 includes: an input submodule 331, which is used to input the image area into the trained direction recognition model to generate positive direction marks corresponding to multiple text boxes in the image area. A calculation submodule 332 is used to calculate the confidence when the image area corresponds to different positive direction marks according to the positive direction marks corresponding to the multiple text boxes. A determination submodule 333 is used to determine the positive direction mark corresponding to the image area according to the confidence.
[0143] It should be noted that the above explanation of the embodiment of the text image recognition method is also applicable to the text image recognition device of this embodiment, and will not be repeated here.
[0144] Thus, the training of the direction recognition model is achieved.
[0145] In order to implement the above-mentioned embodiments, the embodiments of the present invention further propose a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the text image recognition method of the above-mentioned method embodiment are implemented.
[0146] Fig.10 A schematic diagram of a computer device provided by an embodiment of the present invention. Fig.10 As shown, the computer device 50 of this embodiment includes: a processor 51, a memory 52, and a computer program 53 stored in the memory 52 and executable on the processor 51. When the computer program 53 is executed by the processor 51, the text image recognition method of the embodiment is implemented. To avoid repetition, it is not described one by one here. Alternatively, when the computer program is executed by the processor 51, the functions of each model / unit in the text image recognition device of the embodiment are implemented. To avoid repetition, it is not described one by one here.
[0147] The computer device 50 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device may include, but is not limited to, a processor 51 and a memory 52. Those skilled in the art will appreciate that Fig.10 This is only an example of the computer device 50 and does not constitute a limitation of the computer device 50. The computer device 50 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, etc.
[0148] The processor 51 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0149] The memory 52 may be an internal storage unit of the computer device 50, such as a hard disk or memory of the computer device 50. The memory 52 may also be an external storage device of the computer device 50, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 50. Further, the memory 52 may also include both an internal storage unit of the computer device 50 and an external storage device. The memory 52 is used to store computer programs and other programs and data required by the computer device. The memory 52 may also be used to temporarily store data that has been output or is to be output.
[0150] In order to implement the above embodiment, the embodiment of the present invention further proposes a computer-readable storage medium, which stores a computer program, and is characterized in that when the computer program is executed by a processor, the steps of the text image recognition method as described in the above method embodiment are implemented.
[0151] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0152] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0153] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0154] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0155] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (Processor) to perform some steps of the methods of various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0156] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for recognizing a text image, characterized in that: The method comprises: Obtain the text image to be recognized; Extracting multiple image regions from the to-be-recognized text image; Use the trained direction recognition model to perform direction recognition on each of the image regions respectively; Determining the positive direction of the to-be-recognized text image according to the positive directions of the plurality of image regions; and According to the positive direction of the to-be-recognized text image, using a trained text recognition model to perform text recognition on the to-be-recognized text image; The step of using the trained direction recognition model to perform direction recognition on each image region comprises: Inputting the image region into the trained direction recognition model to generate positive direction marks corresponding to a plurality of text boxes in the image region; According to the positive direction marks corresponding to the multiple text boxes, calculating the confidence when the image area corresponds to different positive direction marks respectively; Determining the positive direction mark corresponding to the image area according to the confidence level; Among them, the calculation of the confidence when the image area corresponds to different positive direction marks respectively according to the positive direction marks corresponding to the multiple text boxes includes: performing weighted calculation on different positive directions according to the position of each text box and the area size of the image area occupied, and obtaining the confidence corresponding to different positive direction marks after normalization.
2. The method according to claim 1, characterized in that The trained direction recognition model is generated by training in the following steps: Acquire a reference text image; wherein the reference text image includes a plurality of text boxes; Respectively obtain the positive direction mark and the position mark corresponding to each of the text boxes; Randomly cropping a square area from the reference text image; wherein the square area includes the text box of the first value as a training text box; Rotating the square area, and respectively modifying the positive direction mark corresponding to each training text box in the square area; Inputting the square area into a deep neural network; Comparing the output of the deep neural network with the positive direction mark and the position mark corresponding to each of the training text boxes to optimize the parameters of the deep neural network; The trained direction recognition model is determined based on the optimized parameters of the deep neural network.
3. The method according to claim 1, characterized in that Before performing text recognition on the to-be-recognized text image using a trained text recognition model according to the positive direction of the to-be-recognized text image, the method further includes: Grayscale processing is performed on the text image to be recognized.
4. The method according to any one of claims 1 to 3, characterized in that The trained text recognition model is generated by the following steps: Obtain a reference text image and corresponding reference text; Inputting the reference text image into a two-layer stacked bidirectional long short-term memory network; A loss function is used to calculate the difference between the output of the two-layer stacked bidirectional long short-term memory network and the reference text to train the two-layer stacked bidirectional long short-term memory network.
5. A text image recognition device, characterized in that: The device comprises: A first acquisition module, used for acquiring a text image to be recognized; An extraction module, used for extracting a plurality of image regions from the image of the text to be recognized; A direction recognition module, used to use a trained direction recognition model to perform direction recognition on each of the image regions; A first determination module, configured to determine the positive direction of the to-be-recognized text image according to the positive directions of the plurality of image regions; and The text recognition module is used to perform text recognition on the text image to be recognized using a trained text recognition model according to the positive direction of the text image to be recognized; wherein, The direction recognition module comprises: An input submodule, used for inputting the image area into the trained direction recognition model to generate positive direction marks corresponding to a plurality of text boxes in the image area; A calculation submodule, used for calculating the confidence when the image area corresponds to different positive direction marks respectively according to the positive direction marks corresponding to the multiple text boxes; A determination submodule is used to determine the positive direction mark corresponding to the image area according to the confidence level; wherein, The calculation submodule is specifically used to perform weighted calculation on different positive directions according to the position of each text box and the area size of the image area occupied, and obtain the confidence corresponding to the different positive direction marks after normalization processing.
6. The device according to claim 5, characterized in that The device also includes: A second acquisition module is used to acquire a reference text image; wherein the reference text image includes a plurality of text boxes; A third acquisition module is used to respectively acquire a positive direction mark and a position mark corresponding to each of the text boxes; A cropping module, used for randomly cropping a square area from the reference text image; wherein the square area includes the text box of the first value as a training text box; A rotation module, used for rotating the square area; A modification module, used to modify the positive direction mark corresponding to each of the training text boxes in the square area respectively; A first input module, used to input the square area into a deep neural network; A comparison module, used for comparing the output of the deep neural network with the positive direction mark and the position mark corresponding to each of the training text boxes to optimize the parameters of the deep neural network; The second determination module is used to determine the trained direction recognition model based on the optimized parameters of the deep neural network.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the text image recognition method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the text image recognition method according to any one of claims 1 to 4 are implemented.
