Text recognition method, computer device and storage medium
Through the combination of detection model and recognition classification model, the problem of high logical complexity in text recognition is solved, efficient and accurate rearrangement of text content is achieved, and robustness is improved.
Patent Information
- Application Number
- CN202011021318.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-25
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2040-09-25
AI Technical Summary
The high logic complexity in existing text recognition technology makes the rearrangement process cumbersome and not robust.
The detection model is used to detect text images, the recognition classification model is used for text recognition and classification, and text boxes are rearranged based on their positions and categories to reduce the logical judgment process and improve robustness.
It reduces the logical complexity of text content rearrangement and improves the accuracy and robustness of recognition and classification.
Smart Images

Figure CN112183307B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a text recognition method, apparatus, computer equipment and storage medium. Background Art
[0002] With the continuous development of deep learning technology, all walks of life are actively applying deep learning technology to assist the faster and better development of technology in their fields. In the field of text recognition, more and more software companies are using deep learning technology to assist in text recognition.
[0003] In related technologies, when performing text recognition, a detection network is usually used to detect and locate the text on the image, and then a recognition network is used to recognize the text on the detected text to obtain the recognized text content. Finally, the text content is parsed and multiple logical judgments are performed to output the text content according to its version position on the image.
[0004] However, the above technology has the problem of complex logic. Summary of the invention
[0005] Based on this, it is necessary to provide a text recognition method, apparatus, computer device and storage medium that can reduce the complexity of rearrangement logic in order to address the above technical problems.
[0006] A text recognition method, the method comprising:
[0007] Using the detection model to detect the acquired text image, to obtain each text box image; each text box image includes a position of each text box image on the text image;
[0008] Input each text box image into the recognition and classification model for text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs;
[0009] Based on the position of each text box image and the text category corresponding to each text box image, the text content in each text box image is rearranged, and each text content is output according to the rearranged result.
[0010] In one embodiment, the recognition and classification model includes a feature extraction subnetwork, a text recognition subnetwork and a classification subnetwork;
[0011] In the above, each text box image is input into the recognition and classification model for text recognition and text classification, and the text content and text category corresponding to each text box image are obtained, including:
[0012] Input each text box image into the feature extraction subnetwork for feature extraction to obtain a feature map corresponding to each text box image;
[0013] The feature map corresponding to each text box image is input into the text recognition subnetwork for text recognition to obtain the text content corresponding to each text box image;
[0014] The feature map corresponding to each text box image is input into the classification subnetwork for classification to obtain the text category corresponding to each text box image.
[0015] In one of the embodiments, the text categories include non-fixed items;
[0016] The above-mentioned rearranging of the text contents in each text box image based on the position of each text box image and the text category corresponding to each text box image includes:
[0017] Based on the position of each text box image, the position of the text content in each text box image is obtained;
[0018] Sort the positions of the text contents in each text box image to obtain the relative position relationship between the text contents;
[0019] Based on the relative position relationship between the text contents, determine whether the text contents belonging to the non-fixed items have positional offset, and obtain a determination result;
[0020] The text contents are rearranged according to the judgment result and the text category corresponding to each text box image.
[0021] In one embodiment, the above-mentioned rearranging of the text contents according to the judgment result and the text category corresponding to each text box image includes:
[0022] If there is no positional offset for the text contents belonging to the non-fixed items, the text contents are arranged in rows or columns in turn according to the relative positional relationship between the text contents and the text categories corresponding to the text box images to obtain the rearranged text contents.
[0023] In one embodiment, the text category includes fixed items, and the text contents are rearranged according to the judgment result and the text category corresponding to each text box image, including:
[0024] If the text content of the non-fixed item is offset, the text content of the fixed item matching the text content of the non-fixed item is obtained;
[0025] Adjusting the position of the text content belonging to the non-fixed item according to the position of the text content of the fixed item to obtain the adjusted position of the text content of the non-fixed item;
[0026] Based on the adjusted positions of the text contents of the non-fixed items, the text contents are arranged in rows or columns to obtain rearranged text contents.
[0027] In one embodiment, the step of obtaining the text content of the fixed item that matches the text content of the non-fixed item includes:
[0028] Determine whether the text content of each fixed item has matching text content of a non-fixed item;
[0029] If the text content of the fixed item does not have any matching text content of the non-fixed item, then the position of the text content of the fixed item is obtained;
[0030] Based on the position of the text content of the fixed item, determining whether there is text content of the non-fixed item within a preset distance around the position of the text content;
[0031] If there is text content of a non-fixed item within the preset distance, it is determined that the text content of the non-fixed item matches the text content of the fixed item.
[0032] In one embodiment, the method further comprises:
[0033] If there is no text content of the non-fixed item within the preset distance, determining that the text content of the fixed item has no matching text content of the non-fixed item;
[0034] Based on the relative position relationship between the text contents, obtaining the text content of the fixed item adjacent to the text content of the fixed item;
[0035] According to the relative positional relationship between the text content of the fixed item and the text content of the adjacent fixed item, the text contents are arranged in rows or columns to obtain rearranged text contents.
[0036] In one embodiment, the feature extraction subnetwork includes a long short-term memory network and a residual network.
[0037] In one embodiment, the training method of the above recognition classification model includes:
[0038] Acquire multiple training text box images; each training text box image includes annotated text content and annotated text category;
[0039] Input each training text box image into the feature extraction subnetwork for feature extraction, and obtain a feature map corresponding to each training text box image;
[0040] Input the feature map corresponding to each training text box image into the initial text recognition subnetwork for text recognition, and obtain the predicted text content corresponding to each training text box image;
[0041] Input the feature map corresponding to each training text box image into the initial classification subnetwork for classification, and obtain the predicted text category corresponding to each training text box image;
[0042] Based on the predicted text content and the annotated text content corresponding to each training text box image, as well as the predicted text category and the annotated text category corresponding to each training text box image, an initial text recognition subnetwork and an initial classification subnetwork are trained to obtain a text recognition subnetwork and a classification subnetwork;
[0043] According to the text recognition subnetwork and the classification subnetwork, a recognition and classification model is obtained.
[0044] In one embodiment, the initial text recognition subnetwork and the initial classification subnetwork are trained based on the predicted text content and the annotated text content corresponding to each training text box image, and the predicted text category and the annotated text category corresponding to each training text box image to obtain the text recognition subnetwork and the classification subnetwork, including:
[0045] Calculate the first loss between the predicted text content and the annotated text content corresponding to each training text box image;
[0046] Calculate the second loss between the predicted text category and the annotated text category corresponding to each training text box image;
[0047] The initial text recognition subnetwork and the initial classification subnetwork are trained according to the first loss and the second loss to obtain the text recognition subnetwork and the classification subnetwork.
[0048] A text recognition device, comprising:
[0049] A detection module, used to detect the acquired text image using a detection model to obtain various text box images; the various text box images include positions of the various text box images on the text image;
[0050] The recognition and classification module is used to input each text box image into the recognition and classification model to perform text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs;
[0051] The rearrangement module is used to rearrange the text content in each text box image based on the position of each text box image and the text category corresponding to each text box image, and output each text content according to the rearranged result.
[0052] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0053] Using the detection model to detect the acquired text image, to obtain each text box image; each text box image includes a position of each text box image on the text image;
[0054] Input each text box image into the recognition and classification model for text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs;
[0055] Based on the position of each text box image and the text category corresponding to each text box image, the text content in each text box image is rearranged, and each text content is output according to the rearranged result.
[0056] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0057] Using the detection model to detect the acquired text image, to obtain each text box image; each text box image includes a position of each text box image on the text image;
[0058] Input each text box image into the recognition and classification model for text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs;
[0059] Based on the position of each text box image and the text category corresponding to each text box image, the text content in each text box image is rearranged, and each text content is output according to the rearranged result.
[0060] The above-mentioned text recognition method, device, computer equipment and storage medium can detect the text image using the detection model to obtain each text box image, input each text box image into the recognition and classification model for text recognition and text classification, obtain the text content and text category corresponding to each text box image, rearrange each text content based on the position and text category of each text box image, and output each text content according to the rearranged result. Among them, each text box image includes the position of each text box image on the text image, and each text category represents the category of each text content. In this method, since each text content and the category of each text content can be obtained by the recognition and classification model, the category and position of each text content can be used to assist in rearranging each text content, thereby reducing a part of the logical judgment process, reducing the logical complexity of the rearrangement, and thus improving the robustness of the text content rearrangement. At the same time, using the recognition and classification model for content recognition and classification has better performance than a separate recognition network and a separate classification network, and the recognition and classification results are more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 is an internal structure diagram of a computer device in one embodiment;
[0062] Figure 2 A flowchart of a text recognition method in one embodiment;
[0063] Figure 2a This is an example diagram of layout reconstruction using a driver's license as an example in an embodiment;
[0064] Figure 3 is a flowchart of a text recognition method in another embodiment;
[0065] Figure 3a This is a structural example diagram of two residual blocks of a residual network in another embodiment;
[0066] Figure 3b A diagram showing an example structure of a long short-term memory network in another embodiment;
[0067] Figure 4 is a flowchart of a text recognition method in another embodiment;
[0068] Figure 5 is a flowchart of a text recognition method in another embodiment;
[0069] Figure 6 is a flowchart of a text recognition method in another embodiment;
[0070] Figure 7 FIG. 4 is a structural block diagram of a text recognition device in an embodiment. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0072] The text recognition method provided in the embodiment of the present application can be applied to a computer device, which can be a terminal or a server. Taking the computer device as a terminal as an example, the computer device can be, for example, a laptop computer, a desktop computer, an industrial computer, etc., and its internal structure diagram can be as shown in FIG. Figure 1 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a text recognition method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0073] Those skilled in the art will understand that Figure 1 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0074] It should be noted that the execution subject of the embodiments of the present application may be a text recognition device or a computer device. The following embodiments are described using a computer device as the execution subject.
[0075] In one embodiment, Figure 2 As shown, a text recognition method is provided. This embodiment relates to a specific process of how to recognize, classify and rearrange the text content in a text image. The method may include the following steps:
[0076] S202, using a detection model to detect the acquired text image to obtain various text box images; the various text box images include positions of the various text box images on the text image.
[0077] Among them, the detection model can be a yolo detection model (You Only Live Once), an SSD detection model (Single Shot MultiBox Detector), etc. Taking the SSD detection model as an example, the SSD detection model can also be called an SSD network. The SSD network uses VGG-16 as the basic network. The network contains several convolutional layers and four pooling layers for feature extraction and feature dimension reduction. Since the receptive fields of each convolutional layer are different, the scales of the output text feature maps are different. Finally, 6 feature maps of different scales will be output, which can be used to detect targets of different scales. The convolutional layer close to the input layer can detect small targets, and the convolutional layer close to the output layer can detect large targets. In this way, both large and small targets can be detected to prevent missed detection. Secondly, a default box with different aspect ratios is generated for each pixel on the feature map generated during the target detection process. Here, since the detection targets are all long strips of text information, the aspect ratio of the default box that can be set is {1, 1 / 2, 1 / 3, 1 / 4, 1 / 5}. In addition, the SSD network can classify and regress the default box during training, taking the prior box / default box as the benchmark, which can reduce the difficulty of training to a certain extent.
[0078] In addition, the text image may be a PDF (Portable Document Format) document in picture format, a web page, report, certificate, bill, etc. in picture format, and each text box image obtained here may be an image of each text bar, etc.
[0079] Specifically, when it is necessary to detect a text image, the SSD detection model can be used to perform target detection on the text image. Here, the text contents on the text image are all targets, so the frame images where the text contents are located can be obtained through detection. Generally, the text image includes multiple text contents, so here we can get the frame images where the multiple text contents are located, which are recorded as multiple text frame images; at the same time, the position information of the frame where the text content is located can also be obtained, that is, the position of each text frame image on the text image, which can include the center point coordinates, length, width, height, etc. of the frame.
[0080] S204, input each text box image into a recognition and classification model to perform text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to represent the category to which the text content in each text box image belongs.
[0081] The recognition and classification model here is an overall model, which may include multiple sub-networks or only one sub-network. Taking multiple sub-networks as an example, the recognition and classification model here may include a timing network and a reference network, etc., and of course may also include other networks.
[0082] In addition, the recognition and classification model here has two branches, one branch can be used to recognize the text content in each text box image, and the other branch can be used to classify the text content in each text box image. The two branches are parallel branches, that is, the text content can be classified while recognizing the text content.
[0083] In addition, before using the above-mentioned recognition and classification model to recognize and classify the text content in the text box image, the recognition and classification model can also be trained. The specific training process will be described in detail in the following embodiments. In short, a trained recognition and classification model can be obtained after training.
[0084] Furthermore, when the text content in the text box image is classified here, the category of the text content can be obtained. The category here can be a binary category or a multi-category category (i.e., a classification of at least three categories). Taking binary classification as an example, the category of the text content here can be two categories: fixed items and non-fixed items. Of course, it can also be two categories: handwritten or non-handwritten. Of course, it can also be other two categories. Taking the text image as a certificate, and the certificate is an ID card as an example, the fixed items here can be text items such as name and nationality on the ID card, and the non-fixed items can be text items such as the real name behind the name item (such as Zhang San) and the real nationality behind the nationality item (such as Han).
[0085] Specifically, after obtaining the text box images corresponding to each text content on the text image, each text box image can be input into a trained recognition and classification model. In the recognition and classification model, the text content in each text box image can be identified and classified to obtain the text content in each text box image and the category of the text content in each text box image.
[0086] S206 , rearranging the text contents in each text box image based on the position of each text box image and the text category corresponding to each text box image, and outputting each text content according to the rearranged result.
[0087] In this step, the text content in each text box image is rearranged, which can also be called layout reconstruction. Figure 2aAs shown, layout reconstruction is to output the text content in the layout of a driver's license, that is, the first line outputs: Motor Vehicle Driving License of the People's Republic of China, the second line outputs: License plate number Shanghai 123456 Vehicle type small car, the third line outputs the owner... and so on.
[0088] Specifically, the position of each text box image can be obtained through target detection, and the position of each text box can be arranged to roughly obtain the layout form of each text box image. Then, after obtaining the category of the text content in each text box image, according to the prior information and using the category and position (taking the category as a fixed item and a non-fixed item as an example, for example, the prior information can be that each fixed item will be followed by a non-fixed item), the position of each text content and the text content or empty position immediately following each text content can be determined. After determination, each question can be output line by line according to the determined position and text content. Of course, it can also be output column by column.
[0089] In the above text recognition method, the detection model can be used to detect the text image to obtain each text box image, and each text box image is input into the recognition and classification model for text recognition and text classification to obtain the text content and text category corresponding to each text box image, and the text content is rearranged based on the position and text category of each text box image, and each text content is output according to the rearranged result. Among them, each text box image includes the position of each text box image on the text image, and each text category represents the category of each text content. In this method, since each text content and the category of each text content can be obtained by the recognition and classification model, the category and position of each text content can be used to assist in rearranging each text content, thereby reducing a part of the logical judgment process, reducing the logical complexity of the rearrangement, and then improving the robustness of the text content rearrangement. At the same time, the recognition and classification model is used for content recognition and classification, which has better performance than a separate recognition network and a separate classification network, and the recognition and classification results are more accurate.
[0090] In another embodiment, another text recognition method is provided. This embodiment involves a recognition and classification model including a feature extraction subnetwork, a text recognition subnetwork and a classification subnetwork. Then, how to use these three subnetworks to recognize and classify each text box image. Figure 3 As shown, the above S204 may include the following steps:
[0091] S302, input each text box image into a feature extraction sub-network for feature extraction, and obtain a feature map corresponding to each text box image.
[0092] In this step, optionally, the feature extraction subnetwork may include a long short-term memory network and a residual network. The long short-term network here may be a bidirectional long short-term memory network bi-LSTM (bi-Long Short-Term Memory) or a unidirectional long short-term memory network LSTM (Long Short-Term Memory). The residual network here may be a network composed of residual blocks, which may include one residual block or two residual blocks, or more than two residual blocks. For example, the residual network includes two residual blocks, and the structures of the two residual blocks may be the same or different, see Figure 3a As shown, the residual network provided in this embodiment is composed of two residual blocks with different structures, such as residual module 1-resblock1 and residual module 2-resblock2 in the figure, wherein conv|bn|activation is to perform convolution, normalization, pooling, activation and other operations on the input data, conv|bn is to perform convolution and normalization operations on the input data, and add|activation is to perform summation, activation and other processing on the data. Figure 3a In the figure, residual module 1 performs convolution, normalization, pooling, activation and other operations on the input data, and performs convolution and normalization operations on the input data to obtain two intermediate results, and then performs summation and activation and other processing to obtain the output result; residual module 1 performs convolution, normalization, pooling, activation and other operations on the input data, and then performs summation and activation and other processing on the input data and the intermediate results obtained here to obtain the output result. It can be seen that compared with residual module 2, before summing and activating the intermediate results, residual module 1 will perform convolution and normalization operations on the input data again to obtain the intermediate results, and then perform summation and activation and other processing on the two intermediate results. This can ensure that the features extracted using the residual module are more accurate.
[0093] Specifically, after obtaining each text box image, each text box image can be input into the residual network to extract the features of each text box image in the image space, obtain the spatial feature map corresponding to each text box image, and use the convolution kernel (the convolution kernel size can be 8*1) to perform pooling processing (i.e., perform dimensionality reduction processing) on each spatial feature map to obtain each pooled spatial feature map (also called feature vector, vector). After that, each pooled feature map can be input into the long short-term memory network for further feature extraction, see here Figure 3bAs shown, when performing feature extraction here, the time correlation between the spatial feature maps is fully considered. Feature extraction can be performed from front to back and from back to front in chronological order. The input vector is subjected to feature extraction using a timing network LSTM, and the features extracted in two directions are concatenated or connected (concat) to obtain the concatenated features, i.e., the feature maps corresponding to the text box images here.
[0094] S304: Input the feature map corresponding to each text box image into the text recognition sub-network to perform text recognition, and obtain the text content corresponding to each text box image.
[0095] In this step, the text recognition subnetwork can be a convolutional neural network, or other networks.
[0096] After obtaining the feature maps corresponding to each text box image, each feature map can be input into the text recognition subnetwork. In the text recognition subnetwork, each feature map can be subjected to convolution and pooling processing to obtain further features on each feature map. Finally, the obtained features can be decoded to obtain the text content in each text box image.
[0097] S306: Input the feature map corresponding to each text box image into the classification subnetwork for classification to obtain the text category corresponding to each text box image.
[0098] In this step, the classification sub-network can be a random forest network, a support vector machine SVM (support vector machine), etc., and of course it can also be other networks.
[0099] After obtaining the feature maps corresponding to each text box image, each feature map can be input into a classification subnetwork. In the classification subnetwork, each feature map can also be subjected to convolution, pooling, decoding and other processing to obtain the category of the text content in each text box image.
[0100] The text recognition method of this embodiment can extract features from each text box image through a feature extraction subnetwork, and perform text recognition on the extracted feature map through a text recognition subnetwork in a recognition classification model to obtain each text content, and classify the extracted feature map using a classification subnetwork in a recognition classification model to obtain the category of each text content. In this embodiment, since text recognition and text classification can be achieved through two subnetworks in the recognition classification model, compared with a separate recognition network for recognition and a classification network for classification, two subnetworks in a recognition classification model are used here, and the network performance is better, and the accuracy of final recognition and classification is also higher.
[0101] In another embodiment, another text recognition method is provided. This embodiment relates to a specific process of rearranging the text contents based on the position and category of each text box image when the text category includes fixed items or non-fixed items. Figure 4 As shown, the above S206 may include the following steps:
[0102] S402: Based on the position of each text box image, obtain the position of the text content in each text box image.
[0103] In this step, each text box image includes text content, so the position of each text box image can also be considered as the position of the text content in each text box image.
[0104] S404, sorting the positions of the text contents in each text box image to obtain the relative position relationship between the text contents.
[0105] In this step, the position of the text content is taken as an example of the two-dimensional position of the four corner points on the text box corresponding to it. The two-dimensional position can be an x and y value, that is, each corner point is a coordinate composed of x and y. Then the x and y of the four corner point coordinates corresponding to each text content can be sorted to obtain the relative position relationship between different text contents. Here, the relative position relationship can be that a text box is above / below / left / right of another text box, etc.
[0106] S406: Based on the relative position relationship between the text contents, determine whether the text contents belonging to the non-fixed items have positional offset, and obtain a determination result.
[0107] In this step, take the categories of fixed items and non-fixed items as an example, fixed items refer to the fixed content in the text content, such as the name on the driver's license, etc., and non-fixed items refer to the content that will change relative to the fixed items in the text content, such as the specific name followed by the fixed item name is a non-fixed item, which varies from person to person, and the name will be different. Usually, the text content of each fixed item will be next to the text content of a non-fixed item, and the position of the text content of each fixed item and the text content of the non-fixed item next to it are usually aligned, and the position of the text content of each fixed item is usually not offset. Then here, after obtaining the relative position relationship of the text content in each text box image, the category of each text content can also be obtained at the same time, so it can be judged by the corner point coordinates of each text content whether the position of the text content belonging to each non-fixed item is aligned with the position of the text content of the fixed item next to it.
[0108] Optionally, if the y values of the coordinates of the upper and lower boundary corner points of the text content of the non-fixed item are the same as the y values of the upper and lower boundary corner points of the text content of the adjacent fixed item, then it can be considered that the text content of the non-fixed item is aligned with the text content of the adjacent fixed item, that is, there is no position offset for the text content of the non-fixed item.
[0109] Optionally, if the y values of the coordinates of the upper and lower boundary corner points of the text content of the non-fixed item are different from the y values of the upper and lower boundary corner points of the text content of the adjacent fixed item, then it can be considered that the text content of the non-fixed item is not aligned with the text content of the adjacent fixed item, that is, there is a position offset in the text content of the non-fixed item.
[0110] S408: rearrange the text contents according to the judgment result and the text categories corresponding to the text box images.
[0111] In this step, optionally, if there is no positional offset for the text contents belonging to non-fixed items, the text contents are arranged in rows or columns in accordance with the relative positional relationship between the text contents and the text category corresponding to each text box image to obtain rearranged text contents.
[0112] That is to say, when there is no positional offset in the text content of the non-fixed items, the arrangement position between the text content of each fixed item and the text content of the non-fixed items can be obtained according to the prior information and the category and position. After that, the text content of each fixed item and the text content of the adjacent non-fixed item can be output line by line or column by column according to the layout setting position / arrangement position on the text image.
[0113] In addition, optionally, if the text content belonging to the non-fixed item has a positional offset, then it is necessary to further determine its positional relationship to achieve the rearrangement of each text content by category and position. These will be described in detail in the following embodiments and will not be described in detail here.
[0114] The text recognition method of this embodiment can determine whether the text content of each non-fixed item has positional offset according to the relative position relationship between the text contents, and rearrange the text contents according to the positional offset result and the text category of each text content. In this way, the correct layout position can be obtained, and then when outputting each text content, the correct output result can also be obtained.
[0115] The above embodiment introduces the situation of rearranging the text contents when there is no position offset of the text contents of non-fixed items. Of course, there is also the situation of how to rearrange the text contents when there is a position offset of the text contents of non-fixed items. The following describes this situation.
[0116] In another embodiment, another text recognition method is provided. This embodiment relates to a specific process of rearranging the text contents based on the positions and categories of the text box images when the non-fixed text contents are offset. Figure 5 As shown, the above S408 may include the following steps:
[0117] S502: If the text content of the non-fixed item is offset, obtain the text content of the fixed item that matches the text content of the non-fixed item.
[0118] In this step, the judgment process of S406 above can be used to determine whether the non-fixed item has a positional offset. After that, the position of the non-fixed item can be adjusted by the fixed item that matches the non-fixed item, and then the text content of the fixed item that matches the non-fixed item needs to be obtained. In addition, the non-fixed item with a positional offset here can be one or more non-fixed items.
[0119] Optionally, it can be obtained in the following manner: determine whether the text content of each fixed item has matching text content of non-fixed items; if the text content of the fixed item does not have matching text content of non-fixed items, obtain the position of the text content of the fixed item; based on the position of the text content of the fixed item, determine whether there is text content of non-fixed items within a preset distance around the position of the text content; if there is text content of non-fixed items within the preset distance, determine that the text content of the non-fixed item matches the text content of the fixed item.
[0120] That is to say, on a text image, fixed items are usually not missing, so it can be determined whether the text content of each fixed item has content matching (content matching can be understood as, for example, the non-fixed item after the fixed item name is Zhang San, etc., and it will not be a document number composed of numbers) and position matching (position matching can be understood as adjacent positions) of the text content of non-fixed items. If both are present, it is determined that each fixed item has a matching non-fixed item; if a fixed item has no content matching and position matching non-fixed items, it can be considered that the fixed item may not have a matching non-fixed item. Then it can be classified according to the text category within the preset distance above and below the coordinates of the fixed item. If there is a non-fixed item and it is not successfully matched with any fixed item, the non-fixed item will be used as the matching item of the fixed item. The preset distance here can be set according to the actual situation, for example, it can be 0.5cm above and below.
[0121] For example, continue with Figure 2aTaking a driver's license as an example, assuming the license plate number is Shanghai A123456 and the printing is on the lower side, then the layout is reconstructed according to the coordinates. The next digit of the number is the vehicle type, and the next line is Shanghai A123456. At this time, each line will be disordered. If only adjusted according to the coordinates and the content of the picture text, many situations need to be considered. If the logic is unreasonable, it is very easy to be disordered. Here, the category judgment of the text is used to determine fixed items and non-fixed items. At this time, the license plate number is a fixed item, the vehicle type is also a fixed item, and Shanghai A123456 is a non-fixed item. And if Shanghai A123456 cannot match all items of the fixed items, it is considered that Shanghai A123456 is a non-fixed item of the fixed item license plate number, and the driver's license layout can be adjusted.
[0122] S504, adjust the position of the text content belonging to the non-fixed item according to the position of the text content of the fixed item, and obtain the adjusted position of the text content of the non-fixed item.
[0123] In this step, after obtaining the fixed item that matches the non-fixed item with the position offset, the position of the non-fixed item can be translated according to the position of the fixed item (for example, it can be the corner point coordinates of the text box) to align the position of the non-fixed item with the position of the matching fixed item, and finally obtain the adjusted position of the non-fixed item.
[0124] S506, based on the adjusted position of the text content of the non-fixed item, arrange each text content row by row or column by column to obtain the rearranged text content.
[0125] In this step, after adjusting the position of the non-fixed item with the position offset, the layout position between the text content of each fixed item and the text content of the non-fixed item can be obtained according to the prior information and by using the category and position. Then, the text content of each fixed item and the text content of the non-fixed item adjacent to it can be output row by row or column by column according to the layout position / arrangement position on the text image.
[0126] Of course, there may also be a situation where there is no non-fixed item within the preset distance in the above S504. In this case, when rearranging each text content, optionally, the following steps can be adopted, including: if there is no text content of the non-fixed item within the preset distance, it is determined that there is no text content of the non-fixed item matching the text content of the fixed item; based on the relative position relationship between each text content, obtain the text content of the fixed item adjacent to the text content of the fixed item; arrange each text content row by row or column by column according to the relative position relationship between the text content of the fixed item and the text content of the adjacent fixed item to obtain the rearranged text content.
[0127] Here, for example, if there is no non-fixed item within a preset distance of a fixed item, then it can be considered that the fixed item has no matching non-fixed item, that is, it can be considered that the non-fixed item corresponding to the fixed item is missing. In this case, one or more fixed items adjacent to the fixed item can be obtained based on the obtained text category, and the adjacent here can be adjacent in the form of up and down, left and right, front and back, etc. Other fixed items can also be judged in this way.
[0128] After obtaining adjacent fixed items, a certain space can be left between the fixed item and the adjacent fixed item to obtain the arrangement position between the two or more fixed items, and then the text content of other fixed items and the text content of the adjacent non-fixed items, as well as the text content of these two or more fixed items, can be output line by line or column by column according to the layout setting position / arrangement position on the text image.
[0129] For example, continue with Figure 2a For example, assuming that Shanghai A123456 is missing, the license plate number is a fixed item, and there is no non-fixed item corresponding to the upper and lower coordinates of the license plate number, and the vehicle type is a fixed item, then it can be determined that Shanghai A123456 is lost and there is no non-fixed item.
[0130] The text recognition method of this embodiment can adjust the position of the text content of the non-fixed item by the position of the text content of the matching fixed item when there is a position shift, and rearrange the text content according to the adjusted position. This can avoid the layout disorder caused by the position shift, thereby improving the accuracy of the rearranged layout, so that the user's viewing experience can be improved when viewing the rearranged layout.
[0131] The above embodiment introduces the application process of the recognition classification model. The following describes in detail the training process of the recognition classification model.
[0132] In another embodiment, another text recognition method is provided. This embodiment relates to a specific process of how to train a recognition classification model. Figure 6 As shown, the training method of the above recognition and classification model may include the following steps:
[0133] S602, obtaining a plurality of training text box images; each training text box image includes annotated text content and annotated text category.
[0134] S604: Input each training text box image into a feature extraction subnetwork to perform feature extraction, and obtain a feature map corresponding to each training text box image.
[0135] S606: Input the feature map corresponding to each training text box image into the initial text recognition sub-network for text recognition to obtain the predicted text content corresponding to each training text box image.
[0136] S608: Input the feature map corresponding to each training text box image into the initial classification subnetwork for classification to obtain the predicted text category corresponding to each training text box image.
[0137] S610, based on the predicted text content and annotated text content corresponding to each training text box image, and the predicted text category and annotated text category corresponding to each training text box image, train the initial text recognition subnetwork and the initial classification subnetwork to obtain the text recognition subnetwork and the classification subnetwork.
[0138] S612, obtaining a recognition and classification model according to the text recognition sub-network and the classification sub-network.
[0139] In this embodiment, first, each training text image can be obtained, and the detection model can be used to perform target detection on each training text image to obtain a text box image on each training text image, which is recorded as multiple training text box images here. At the same time, each training text image can be labeled, and the label includes annotated text content and annotated text category. The annotated text content refers to the real text content in the training text box image, and the annotated text category refers to the category to which the real text content in the training text box image belongs.
[0140] Afterwards, each training text box image can be processed using the feature extraction subnetwork, the initial text recognition subnetwork and the initial classification subnetwork in accordance with the above-mentioned S302-S306 method to obtain the predicted text content and predicted text category corresponding to each training text box image. Afterwards, the predicted text content and predicted text category can be used to train the initial text recognition subnetwork and the initial classification subnetwork.
[0141] When training here, optionally, a first loss can be calculated between the predicted text content and the annotated text content corresponding to each training text box image; a second loss can be calculated between the predicted text category and the annotated text category corresponding to each training text box image; and an initial text recognition subnetwork and an initial classification subnetwork can be trained according to the first loss and the second loss to obtain a text recognition subnetwork and a classification subnetwork.
[0142] That is to say, the loss between the predicted text content and the corresponding annotated text content of each training text box image can be calculated to obtain multiple losses, all of which are recorded as the first loss, that is, multiple first losses are obtained; the loss between the predicted text category and the corresponding annotated text category of each training text box image can also be calculated, and multiple losses can also be obtained, all of which are recorded as the second loss here, that is, multiple second losses are obtained; then, the multiple first losses can be simply summed or weighted summed to obtain the first loss sum value, and the multiple second losses can be simply summed or weighted summed to obtain the second loss sum value. Then, the first loss sum value and the second loss sum value are weighted summed to obtain the final loss sum value, and the final loss sum value is used to adjust the initial text recognition subnetwork and the initial classification subnetwork until the final calculated loss sum value reaches the threshold requirement or remains stable, then it can be considered that the initial text recognition subnetwork and the initial classification subnetwork have been trained, and the trained text recognition subnetwork and classification subnetwork can be obtained at this time.
[0143] Afterwards, the feature extraction subnetwork, the trained text recognition subnetwork, and the classification subnetwork are combined to form a trained recognition and classification model.
[0144] The text recognition method of this embodiment can train the initial text recognition subnetwork and the initial classification subnetwork through each training text box image and the corresponding annotated text content and annotated text category, obtain a trained text recognition subnetwork and classification subnetwork, and then obtain a recognition classification model. In this embodiment, since the recognition classification model can be trained through multiple training text box images and their corresponding labels, the recognition classification model trained in this way is more accurate, and then when the trained recognition classification model is used to recognize and classify text, the recognition results and classification results obtained will also be more accurate.
[0145] In another embodiment, in order to explain the technical solution of the present application in more detail, the solution of the present application is described in detail below in conjunction with a specific embodiment. The method may include the following steps:
[0146] S1, obtaining a plurality of training text images, and using a detection model to detect each training text image to obtain a plurality of training text frame images, each training text frame image including annotated text content and annotated text category.
[0147] S2, input each training text box image into the feature extraction subnetwork for feature extraction, and obtain the feature map corresponding to each training text box image; input the feature map corresponding to each training text box image into the initial text recognition subnetwork for text recognition, and obtain the predicted text content corresponding to each training text box image; input the feature map corresponding to each training text box image into the initial classification subnetwork for classification, and obtain the predicted text category corresponding to each training text box image.
[0148] S3, calculate the first loss between the predicted text content and the annotated text content corresponding to each training text box image; calculate the second loss between the predicted text category and the annotated text category corresponding to each training text box image; train the initial text recognition subnetwork and the initial classification subnetwork according to the first loss and the second loss to obtain the text recognition subnetwork and the classification subnetwork.
[0149] S4, combines the feature extraction subnetwork with the trained text recognition subnetwork and classification subnetwork to obtain a trained recognition and classification model.
[0150] S5, using the detection model to detect the acquired text image to obtain various text box images; the various text box images include the positions of the various text box images on the text image.
[0151] S6, input each text box image into the feature extraction subnetwork for feature extraction, and obtain the feature map corresponding to each text box image; input the feature map corresponding to each text box image into the text recognition subnetwork for text recognition, and obtain the text content corresponding to each text box image; input the feature map corresponding to each text box image into the classification subnetwork for classification, and obtain the text category corresponding to each text box image, wherein the above text category includes fixed items or non-fixed items.
[0152] S7, based on the position of each text box image, obtaining the position of the text content in each text box image.
[0153] S8, sorting the positions of the text contents in each text box image to obtain the relative position relationship between the text contents.
[0154] S9, based on the relative position relationship between the text contents, determine whether the text contents belonging to the non-fixed items have positional offsets, if there are no positional offsets, execute S10, otherwise execute S11.
[0155] S10 , according to the relative position relationship between the text contents and the text categories corresponding to the text box images, the text contents are arranged in rows or columns to obtain rearranged text contents.
[0156] S11, if the text content of the non-fixed item has a position offset, determine whether the text content of each fixed item has matching non-fixed item text content; if the text content of the fixed item does not have matching non-fixed item text content, obtain the position of the text content of the fixed item.
[0157] S12, based on the position of the text content of the fixed item, determine whether there is text content of a non-fixed item within a preset distance around the position of the text content, if so, execute S13, otherwise, execute S16.
[0158] S13, determining whether the text content of the non-fixed item matches the text content of the fixed item.
[0159] S14, adjusting the position of the text content belonging to the non-fixed item according to the position of the text content of the fixed item to obtain the adjusted position of the text content of the non-fixed item.
[0160] S15, based on the adjusted positions of the text contents of the non-fixed items, the text contents are arranged in rows or columns to obtain rearranged text contents.
[0161] S16, determining that the text content of the fixed item has no matching text content of the non-fixed item.
[0162] S17, based on the relative position relationship between the text contents, obtaining the text content of the fixed item adjacent to the text content of the fixed item.
[0163] S18, arranging the text contents in rows or columns in sequence according to the relative positional relationship between the text contents of the fixed items and the text contents of the adjacent fixed items, to obtain rearranged text contents.
[0164] S19, outputting each text content according to the rearranged result.
[0165] It should be understood that although Figure 2-6 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-6 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0166] In one embodiment, Figure 7As shown, a text recognition device is provided, comprising: a detection module 10, a recognition and classification module 11 and a rearrangement module 12, wherein:
[0167] A detection module 10 is used to detect the acquired text image using a detection model to obtain various text box images; each text box image includes a position of each text box image on the text image;
[0168] The recognition and classification module 11 is used to input each text box image into the recognition and classification model to perform text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs;
[0169] The rearrangement module 12 is used to rearrange the text contents in each text box image based on the position of each text box image and the text category corresponding to each text box image, and output each text content according to the rearranged result.
[0170] For the specific definition of the text recognition device, please refer to the definition of the text recognition method above, which will not be repeated here.
[0171] In another embodiment, another text recognition device is provided. Based on the above embodiment, the recognition and classification model includes a feature extraction subnetwork, a text recognition subnetwork and a classification subnetwork; the recognition and classification module 11 may include a feature extraction unit, a recognition unit and a classification unit, wherein:
[0172] A feature extraction unit is used to input each text box image into a feature extraction subnetwork for feature extraction to obtain a feature map corresponding to each text box image;
[0173] A recognition unit is used to input the feature map corresponding to each text box image into the text recognition subnetwork for text recognition, so as to obtain the text content corresponding to each text box image;
[0174] The classification unit is used to input the feature map corresponding to each text box image into the classification subnetwork for classification, so as to obtain the text category corresponding to each text box image.
[0175] Optionally, the feature extraction subnetwork includes a long short-term memory network and a residual network.
[0176] In another embodiment, another text recognition device is provided. Based on the above embodiment, the above text category includes a fixed item or a non-fixed item; the above rearrangement module 12 may include a position determination unit, a relative position relationship determination unit, a judgment unit and a rearrangement unit, wherein:
[0177] A position determination unit, used to obtain the position of the text content in each text box image based on the position of each text box image;
[0178] A relative position relationship determination unit, used to sort the positions of the text contents in each text box image to obtain the relative position relationship between the text contents;
[0179] A judgment unit, used to judge whether the text content belonging to the non-fixed item has a position shift based on the relative position relationship between the text contents, and obtain a judgment result;
[0180] The rearrangement unit is used to rearrange the text contents according to the judgment result and the text categories corresponding to the text box images.
[0181] Optionally, the above-mentioned rearrangement unit is specifically used to arrange the text contents in rows or columns in sequence according to the relative position relationship between the text contents and the text category corresponding to each text box image if there is no position offset for the text contents belonging to non-fixed items, so as to obtain rearranged text contents.
[0182] In another embodiment, another text recognition device is provided. Based on the above embodiment, the above rearrangement unit may include an acquisition subunit, an adjustment subunit and a rearrangement subunit, wherein:
[0183] An acquisition subunit is used to acquire the text content of the fixed item that matches the text content of the non-fixed item if there is a position offset in the text content of the non-fixed item;
[0184] An adjusting subunit, used to adjust the position of the text content belonging to the non-fixed item according to the position of the text content of the fixed item, so as to obtain the adjusted position of the text content of the non-fixed item;
[0185] The rearrangement subunit is used to arrange the text contents in rows or columns based on the adjusted positions of the text contents of the non-fixed items to obtain rearranged text contents.
[0186] Optionally, the above-mentioned acquisition sub-unit is specifically used to determine whether the text content of each fixed item has matching text content of non-fixed items; if the text content of the fixed item does not have matching text content of non-fixed items, then the position of the text content of the fixed item is obtained; based on the position of the text content of the fixed item, it is determined whether there is text content of non-fixed items within a preset distance around the position of the text content; if there is text content of non-fixed items within the preset distance, it is determined that the text content of the non-fixed item matches the text content of the fixed item.
[0187] Optionally, the above device may further include a matching determination module, an adjacent item acquisition module and a fixed rearrangement module, wherein:
[0188] a matching determination module, configured to determine that the text content of the fixed item has no matching text content of the non-fixed item if there is no text content of the non-fixed item within a preset distance;
[0189] An adjacent item acquisition module, used to acquire text content of a fixed item adjacent to the text content of the fixed item based on the relative position relationship between the text contents;
[0190] The fixed rearrangement module is used to arrange the text contents in rows or columns in turn according to the relative position relationship between the text contents of the fixed items and the text contents of the adjacent fixed items to obtain the rearranged text contents.
[0191] In another embodiment, another text recognition device is provided. Based on the above embodiment, the above device may further include a training module, which includes a training text acquisition unit, a training feature extraction unit, a training recognition unit, a training classification unit, a training unit and a model determination unit, wherein:
[0192] A training text acquisition unit, used to acquire a plurality of training text frame images; each training text frame image includes annotated text content and annotated text category;
[0193] A training feature extraction unit is used to input each training text box image into a feature extraction subnetwork for feature extraction to obtain a feature map corresponding to each training text box image;
[0194] A training recognition unit is used to input the feature map corresponding to each training text box image into the initial text recognition subnetwork for text recognition, so as to obtain the predicted text content corresponding to each training text box image;
[0195] A training classification unit is used to input the feature map corresponding to each training text box image into the initial classification subnetwork for classification, so as to obtain the predicted text category corresponding to each training text box image;
[0196] A training unit, used to train an initial text recognition subnetwork and an initial classification subnetwork based on the predicted text content and annotated text content corresponding to each training text box image, and the predicted text category and annotated text category corresponding to each training text box image, to obtain a text recognition subnetwork and a classification subnetwork;
[0197] The model determination unit is used to obtain a recognition and classification model according to the text recognition subnetwork and the classification subnetwork.
[0198] Optionally, the above-mentioned training unit is specifically used to calculate the first loss between the predicted text content and the annotated text content corresponding to each training text box image; calculate the second loss between the predicted text category and the annotated text category corresponding to each training text box image; and train the initial text recognition subnetwork and the initial classification subnetwork according to the first loss and the second loss to obtain the text recognition subnetwork and the classification subnetwork.
[0199] For the specific definition of the text recognition device, please refer to the definition of the text recognition method above, which will not be repeated here.
[0200] Each module in the above-mentioned text recognition device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0201] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0202] Using the detection model to detect the acquired text image, to obtain each text box image; each text box image includes a position of each text box image on the text image;
[0203] Input each text box image into the recognition and classification model for text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs;
[0204] Based on the position of each text box image and the text category corresponding to each text box image, the text content in each text box image is rearranged, and each text content is output according to the rearranged result.
[0205] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0206] Each text box image is input into the feature extraction subnetwork for feature extraction to obtain the feature map corresponding to each text box image; the feature map corresponding to each text box image is input into the text recognition subnetwork for text recognition to obtain the text content corresponding to each text box image; the feature map corresponding to each text box image is input into the classification subnetwork for classification to obtain the text category corresponding to each text box image.
[0207] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0208] Based on the position of each text box image, the position of the text content in each text box image is obtained; the position of the text content in each text box image is sorted to obtain the relative position relationship between each text content; based on the relative position relationship between each text content, it is judged whether there is a position offset in the text content belonging to the non-fixed item to obtain a judgment result; according to the judgment result and the text category corresponding to each text box image, each text content is rearranged.
[0209] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0210] If there is no positional offset for the text contents belonging to the non-fixed items, the text contents are arranged in rows or columns in turn according to the relative positional relationship between the text contents and the text categories corresponding to the text box images to obtain the rearranged text contents.
[0211] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0212] If the text content of the non-fixed item is offset in position, the text content of the fixed item that matches the text content of the non-fixed item is obtained; the position of the text content belonging to the non-fixed item is adjusted according to the position of the text content of the fixed item to obtain the adjusted position of the text content of the non-fixed item; based on the adjusted position of the text content of the non-fixed item, the text contents are arranged in rows or columns in sequence to obtain the rearranged text contents.
[0213] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0214] Determine whether the text content of each fixed item has matching text content of non-fixed items; if the text content of the fixed item does not have matching text content of the non-fixed item, obtain the position of the text content of the fixed item; based on the position of the text content of the fixed item, determine whether there is text content of the non-fixed item within a preset distance around the position of the text content; if there is text content of the non-fixed item within the preset distance, determine that the text content of the non-fixed item matches the text content of the fixed item.
[0215] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0216] If there is no text content of a non-fixed item within a preset distance, it is determined that the text content of the fixed item has no matching text content of the non-fixed item; based on the relative position relationship between each text content, the text content of the fixed item adjacent to the text content of the fixed item is obtained; according to the relative position relationship between the text content of the fixed item and the text content of the adjacent fixed item, each text content is arranged in rows or columns in turn to obtain rearranged text contents.
[0217] In one embodiment, the feature extraction subnetwork includes a long short-term memory network and a residual network.
[0218] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0219] Acquire multiple training text box images; each training text box image includes annotated text content and annotated text category; input each training text box image into a feature extraction subnetwork for feature extraction to obtain a feature map corresponding to each training text box image; input the feature map corresponding to each training text box image into an initial text recognition subnetwork for text recognition to obtain a predicted text content corresponding to each training text box image; input the feature map corresponding to each training text box image into an initial classification subnetwork for classification to obtain a predicted text category corresponding to each training text box image; based on the predicted text content and annotated text content corresponding to each training text box image, as well as the predicted text category and annotated text category corresponding to each training text box image, train the initial text recognition subnetwork and the initial classification subnetwork to obtain a text recognition subnetwork and a classification subnetwork; obtain a recognition and classification model based on the text recognition subnetwork and the classification subnetwork.
[0220] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0221] Calculate the first loss between the predicted text content and the annotated text content corresponding to each training text box image; calculate the second loss between the predicted text category and the annotated text category corresponding to each training text box image; train the initial text recognition subnetwork and the initial classification subnetwork according to the first loss and the second loss to obtain the text recognition subnetwork and the classification subnetwork.
[0222] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0223] Using the detection model to detect the acquired text image, to obtain each text box image; each text box image includes a position of each text box image on the text image;
[0224] Input each text box image into the recognition and classification model for text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs;
[0225] Based on the position of each text box image and the text category corresponding to each text box image, the text content in each text box image is rearranged, and each text content is output according to the rearranged result.
[0226] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0227] Each text box image is input into the feature extraction subnetwork for feature extraction to obtain the feature map corresponding to each text box image; the feature map corresponding to each text box image is input into the text recognition subnetwork for text recognition to obtain the text content corresponding to each text box image; the feature map corresponding to each text box image is input into the classification subnetwork for classification to obtain the text category corresponding to each text box image.
[0228] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0229] Based on the position of each text box image, the position of the text content in each text box image is obtained; the position of the text content in each text box image is sorted to obtain the relative position relationship between each text content; based on the relative position relationship between each text content, it is judged whether there is a position offset in the text content belonging to the non-fixed item to obtain a judgment result; according to the judgment result and the text category corresponding to each text box image, each text content is rearranged.
[0230] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0231] If there is no positional offset for the text contents belonging to the non-fixed items, the text contents are arranged in rows or columns in turn according to the relative positional relationship between the text contents and the text categories corresponding to the text box images to obtain the rearranged text contents.
[0232] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0233] If the text content of the non-fixed item is offset in position, the text content of the fixed item that matches the text content of the non-fixed item is obtained; the position of the text content belonging to the non-fixed item is adjusted according to the position of the text content of the fixed item to obtain the adjusted position of the text content of the non-fixed item; based on the adjusted position of the text content of the non-fixed item, the text contents are arranged in rows or columns in sequence to obtain the rearranged text contents.
[0234] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0235] Determine whether the text content of each fixed item has matching text content of non-fixed items; if the text content of the fixed item does not have matching text content of the non-fixed item, obtain the position of the text content of the fixed item; based on the position of the text content of the fixed item, determine whether there is text content of the non-fixed item within a preset distance around the position of the text content; if there is text content of the non-fixed item within the preset distance, determine that the text content of the non-fixed item matches the text content of the fixed item.
[0236] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0237] If there is no text content of a non-fixed item within a preset distance, it is determined that the text content of the fixed item has no matching text content of the non-fixed item; based on the relative position relationship between each text content, the text content of the fixed item adjacent to the text content of the fixed item is obtained; according to the relative position relationship between the text content of the fixed item and the text content of the adjacent fixed item, each text content is arranged in rows or columns in turn to obtain rearranged text contents.
[0238] In one embodiment, the feature extraction subnetwork includes a long short-term memory network and a residual network.
[0239] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0240] Acquire multiple training text box images; each training text box image includes annotated text content and annotated text category; input each training text box image into a feature extraction subnetwork for feature extraction to obtain a feature map corresponding to each training text box image; input the feature map corresponding to each training text box image into an initial text recognition subnetwork for text recognition to obtain a predicted text content corresponding to each training text box image; input the feature map corresponding to each training text box image into an initial classification subnetwork for classification to obtain a predicted text category corresponding to each training text box image; based on the predicted text content and annotated text content corresponding to each training text box image, as well as the predicted text category and annotated text category corresponding to each training text box image, train the initial text recognition subnetwork and the initial classification subnetwork to obtain a text recognition subnetwork and a classification subnetwork; obtain a recognition and classification model based on the text recognition subnetwork and the classification subnetwork.
[0241] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0242] Calculate the first loss between the predicted text content and the annotated text content corresponding to each training text box image; calculate the second loss between the predicted text category and the annotated text category corresponding to each training text box image; train the initial text recognition subnetwork and the initial classification subnetwork according to the first loss and the second loss to obtain the text recognition subnetwork and the classification subnetwork.
[0243] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0244] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0245] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A text recognition method, characterized in that: The method comprises: Using the detection model to detect the acquired text image, to obtain each text box image; each text box image includes a position of each text box image on the text image; Input each of the text box images into a recognition and classification model to perform text recognition and text classification, and obtain text content and text category corresponding to each of the text box images; the text category is used to characterize the category to which the text content in each of the text box images belongs; Based on the position of each of the text box images and the text category corresponding to each of the text box images, the text content in each of the text box images is rearranged, and each of the text contents is output according to the rearranged result; Wherein, the text category includes non-fixed items; and the rearranging of the text contents in each of the text box images based on the position of each of the text box images and the text category corresponding to each of the text box images includes: Based on the position of each of the text box images, obtaining the position of the text content in each of the text box images; Sorting the positions of the text contents in each of the text box images to obtain the relative position relationship between the text contents; Based on the relative position relationship between the text contents, determining whether the text contents belonging to the non-fixed items have positional offset, and obtaining a determination result; The text contents are rearranged according to the judgment result and the text category corresponding to each text box image.
2. The method according to claim 1, characterized in that The recognition and classification model includes a feature extraction subnetwork, a text recognition subnetwork and a classification subnetwork; The step of inputting each text box image into a recognition and classification model to perform text recognition and text classification to obtain text content and text category corresponding to each text box image includes: Inputting each of the text box images into the feature extraction subnetwork to perform feature extraction, and obtaining a feature map corresponding to each of the text box images; Inputting the feature map corresponding to each of the text box images into the text recognition subnetwork to perform text recognition, and obtaining the text content corresponding to each of the text box images; The feature maps corresponding to the text box images are input into the classification subnetwork for classification to obtain the text categories corresponding to the text box images.
3. The method according to claim 2, characterized in that The rearranging of the text contents according to the judgment result and the text category corresponding to each text box image includes: If the text contents belonging to the non-fixed items do not have positional offset, then the text contents are arranged in rows or columns in turn according to the relative positional relationship between the text contents and the text categories corresponding to the text box images to obtain rearranged text contents.
4. The method according to claim 2, characterized in that: The text category includes fixed items, and the rearranging of the text contents according to the judgment result and the text category corresponding to each text box image includes: If the text content of the non-fixed item is offset, obtaining the text content of the fixed item that matches the text content of the non-fixed item; Adjusting the position of the text content belonging to the non-fixed item according to the position of the text content of the fixed item to obtain the adjusted position of the text content of the non-fixed item; Based on the adjusted positions of the text contents of the non-fixed items, the text contents are arranged in rows or columns to obtain rearranged text contents.
5. The method according to claim 4, characterized in that The acquiring of the text content of the fixed item matching the text content of the non-fixed item includes: Determine whether the text content of each fixed item has matching text content of a non-fixed item; If the text content of the fixed item does not have any matching text content of the non-fixed item, obtaining the position of the text content of the fixed item; Based on the position of the fixed item text content, determining whether there is a non-fixed item text content within a preset distance around the position of the text content; If there is text content of a non-fixed item within the preset distance, it is determined that the text content of the non-fixed item matches the text content of the fixed item.
6. The method according to claim 5, characterized in that The method further comprises: If there is no text content of a non-fixed item within the preset distance, determining that the text content of the fixed item has no matching text content of a non-fixed item; Based on the relative position relationship between the text contents, acquiring the text content of the fixed item adjacent to the text content of the fixed item; According to the relative positional relationship between the text content of the fixed item and the text content of the adjacent fixed item, the text contents are arranged in rows or columns to obtain rearranged text contents.
7. The method according to claim 2, characterized in that The feature extraction subnetwork includes a long short-term memory network and a residual network.
8. A text recognition device, characterized in that: The device comprises: A detection module, used to detect the acquired text image using a detection model to obtain various text box images; the various text box images include positions of the various text box images on the text image; The recognition and classification module is used to input each text box image into the recognition and classification model to perform text recognition and text classification, and obtain the text content and text category corresponding to each text box image; the text category is used to characterize the category to which the text content in each text box image belongs; A rearrangement module, used to rearrange the text content in each text box image based on the position of each text box image and the text category corresponding to each text box image, and output each text content according to the rearranged result; Wherein, the text category includes non-fixed items; the rearrangement module may include a position determination unit, a relative position relationship determination unit, a judgment unit and a rearrangement unit, wherein: A position determination unit, used to obtain the position of the text content in each text box image based on the position of each text box image; A relative position relationship determination unit, used to sort the positions of the text contents in each text box image to obtain the relative position relationship between the text contents; A judgment unit, used to judge whether the text content belonging to the non-fixed item has a position shift based on the relative position relationship between the text contents, and obtain a judgment result; The rearrangement unit is used to rearrange the text contents according to the judgment result and the text categories corresponding to the text box images.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
