Text recognition method and device and storage medium

By obtaining and using the stretching coefficient for image stretching and restoration, the problem of close characters and deformation in complex Chinese character recognition is solved, the accuracy and efficiency of text recognition are improved, the model structure is simplified, and it is suitable for more standard image conditions. Text recognition.

CN118570816AInactive Publication Date: 2024-08-30SUZHOU CRAFTSMAN TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411038140.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-08-30
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Neural networks have problems with similar shapes and deformations when recognizing complex Chinese characters, resulting in low recognition accuracy. A deeper and more complex model structure needs to be designed, which increases the amount of calculation and training time and affects model deployment.

Method used

By obtaining the stretching coefficient of the target image, image scaling and standardization are performed, and the stretching coefficient recognition model is used to perform stretching and restoration to restore the original proportion and shape of the text, and then perform text recognition.

Benefits of technology

It significantly improves the accuracy of text recognition, simplifies the recognition process, reduces algorithm complexity and processing time, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570816A
    Figure CN118570816A
Patent Text Reader

Abstract

The invention provides a text recognition method and device and a storage medium, and relates to the technical field of text recognition, and the method comprises the steps: obtaining a target image containing a to-be-recognized text; determining a stretching coefficient of a to-be-recognized text in the target image; stretching and restoring the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; and performing text recognition on the restored image to obtain the to-be-recognized text. According to the method, the target image is stretched and restored, the original proportion and shape of the text are restored, and character deformation and uneven spacing caused by image stretching are effectively eliminated, so that the accuracy of text recognition is remarkably improved; moreover, by determining the stretching coefficient and performing reduction processing, the image deformation problem can be solved in the preprocessing stage, so that a subsequent text recognition algorithm can perform processing under a more standard image condition, the overall recognition process and algorithm complexity are simplified, and the processing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of text recognition, and in particular, to a text recognition method, device, and storage medium. Background Art

[0002] Text recognition, also known as Optical Character Recognition (OCR), refers to translating the text information contained in a picture into computer text through certain technical means. With the development of deep learning technology, neural network models can recognize some common text scenarios encountered in real life. However, for relatively complex texts such as Chinese characters, there are usually many similar-looking characters, such as "日" and "曰", and at the same time, some Chinese characters may form new Chinese characters after being deformed to a certain extent. For example, "肝" will become "月" and "干" after being stretched, resulting in a change in the meaning of the text.

[0003] Due to the above situation, the accuracy of neural network text recognition is relatively low. If a better recognition effect is to be obtained, a deeper and more complex model structure needs to be designed, resulting in an increase in the model's computational volume, and the model training and inference time become longer, which is not conducive to the deployment of the model. Summary of the Invention

[0004] Embodiments of the present disclosure at least provide a text recognition method, device, and storage device.

[0005] In a first aspect, an embodiment of the present disclosure provides a text recognition method, including: Obtain a target image containing the text to be recognized; While maintaining the aspect ratio of the target image, scale the target image so that the height of the scaled target image matches the stretching coefficient recognition model; Perform normalization processing on the scaled target image so that the width of the normalized target image matches the stretching coefficient recognition model; Input the normalized target image into the stretching coefficient recognition model to obtain the stretching coefficient output by the stretching coefficient model; Based on the stretching coefficient, perform stretching restoration on the target image to obtain the restored image corresponding to the target image; Perform text recognition on the restored image to obtain the text to be recognized.

[0006] In an optional implementation manner, the performing normalization processing on the scaled target image so that the width of the normalized target image matches the stretching coefficient recognition model includes: When the width of the scaled target image is greater than the width corresponding to the stretch coefficient identification model, the scaled target image is cropped so that the width of the standardized target image is a preset width; and / or, In the case where the width of the scaled target image is smaller than the width corresponding to the stretch coefficient identification model, the scaled target image is padded so that the width of the standardized target image is a preset width.

[0007] In an optional implementation manner, the stretching and restoring the target image based on the stretching coefficient includes: When the stretching coefficient is greater than a first threshold, compressing the height of the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; and / or, When the stretching coefficient is less than a second threshold, the width of the target image is stretched based on the stretching coefficient to obtain a restored image corresponding to the target image; and the first threshold is greater than the second threshold.

[0008] In an optional implementation, the stretch factor identification model is trained according to the following steps: Acquire a training data set; the training data set includes a plurality of unscaled training images carrying training texts; Randomly stretching the width of the training images in the training data set to obtain a plurality of stretched training images; The stretching coefficient recognition model to be trained is trained using the stretching training image and the random stretching coefficient corresponding to the stretching training image.

[0009] In an optional implementation manner, the using the stretched training image and the random stretch coefficient corresponding to the stretched training image to train the stretch coefficient recognition model to be trained includes: Under the condition of maintaining the aspect ratio of the stretch training image, scaling the stretch training image so that the height of the scaled stretch training image matches the stretch coefficient recognition model; performing standardization processing on the scaled stretch training image so that the width of the standardized stretch training image matches the stretch coefficient recognition model; The standardized stretch training image is used as an input of a stretch coefficient recognition model to be trained, and the random stretch coefficient corresponding to the standardized stretch training image is used as a label to train the stretch coefficient recognition model.

[0010] In an optional embodiment, the stretch coefficient identification model includes a plurality of feature extraction layers arranged in sequence; a global mixing module is arranged between the penultimate and second to last feature extraction layers; another global mixing module is arranged after the penultimate feature extraction layer; and the global mixing module is used to determine global features based on attention moderation.

[0011] In an optional embodiment, the global mixing module includes a multi-head scaling dot product attention module and a feedforward neural network module; a layer of normalization module is arranged between the multi-head scaling dot product attention module and the feedforward neural network module; and another layer of normalization module is arranged after the feedforward neural network module.

[0012] In a second aspect, the present disclosure also provides a text recognition device, including: An acquisition module, used for acquiring a target image containing text to be recognized; A determination module, used to determine a stretching factor of the text to be recognized in the target image; A restoration module, used for performing stretching and restoration on the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; The recognition module is used to perform text recognition on the restored image to obtain the text to be recognized.

[0013] In an optional implementation manner, the determining module is specifically configured to: While maintaining the aspect ratio of the target image, scaling the target image so that the height of the scaled target image matches the stretch coefficient recognition model; Performing standardization processing on the scaled target image so that the width of the standardized target image matches the stretch coefficient recognition model; The standardized target image is input into the stretch coefficient recognition model to obtain the stretch coefficient output by the stretch coefficient model.

[0014] In an optional implementation manner, the determining module is specifically configured to: When the width of the scaled target image is greater than the width corresponding to the stretch coefficient identification model, the scaled target image is cropped so that the width of the standardized target image is a preset width; and / or, In the case where the width of the scaled target image is smaller than the width corresponding to the stretch coefficient identification model, the scaled target image is padded so that the width of the standardized target image is a preset width.

[0015] In an optional implementation manner, the restoration module is specifically used to: When the stretching coefficient is greater than a first threshold, compressing the height of the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; and / or, When the stretching coefficient is less than a second threshold, the width of the target image is stretched based on the stretching coefficient to obtain a restored image corresponding to the target image; and the first threshold is greater than the second threshold.

[0016] In an optional implementation, the device further includes a training module, which is used to: Acquire a training data set; the training data set includes a plurality of unscaled training images carrying training texts; Randomly stretching the width of the training images in the training data set to obtain a plurality of stretched training images; The stretching coefficient recognition model to be trained is trained using the stretching training image and the random stretching coefficient corresponding to the stretching training image.

[0017] In an optional implementation manner, the training module is specifically used to include: Under the condition of maintaining the aspect ratio of the stretch training image, scaling the stretch training image so that the height of the scaled stretch training image matches the stretch coefficient recognition model; performing standardization processing on the scaled stretch training image so that the width of the standardized stretch training image matches the stretch coefficient recognition model; The standardized stretch training image is used as an input of a stretch coefficient recognition model to be trained, and the random stretch coefficient corresponding to the standardized stretch training image is used as a label to train the stretch coefficient recognition model.

[0018] In an optional embodiment, the stretch coefficient identification model includes a plurality of feature extraction layers arranged in sequence; a global mixing module is arranged between the penultimate and second to last feature extraction layers; another global mixing module is arranged after the penultimate feature extraction layer; and the global mixing module is used to determine global features based on attention moderation.

[0019] In an optional embodiment, the global mixing module includes a multi-head scaling dot product attention module and a feedforward neural network module; a layer of normalization module is arranged between the multi-head scaling dot product attention module and the feedforward neural network module; and another layer of normalization module is arranged after the feedforward neural network module.

[0020] In a third aspect, an embodiment of the present disclosure further provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned first aspect, or any possible implementation of the first aspect are performed.

[0021] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned first aspect or any possible implementation of the first aspect are executed.

[0022] The text recognition method, device and storage medium provided by the embodiments of the present disclosure stretch and restore the target image to restore the original proportion and shape of the text, effectively eliminating character deformation and uneven spacing caused by image stretching, thereby significantly improving the accuracy of text recognition; and, by determining the stretching coefficient and performing restoration processing, the image deformation problem can be solved in the preprocessing stage, so that the subsequent text recognition algorithm can be processed under more standard image conditions, simplifying the overall recognition process and algorithm complexity, and improving processing efficiency.

[0023] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.

[0025] Figure 1 A flowchart of a text recognition method provided by an embodiment of the present disclosure is shown; Figure 2 A schematic diagram showing the steps of acquiring a target image provided by an embodiment of the present disclosure; Figure 3 A schematic diagram of a stretch coefficient identification model provided by an embodiment of the present disclosure is shown; Figure 4 A schematic diagram of a global mixing module provided by an embodiment of the present disclosure is shown; Figure 5 A schematic diagram showing the steps of stretching reduction provided by an embodiment of the present disclosure; Figure 6 A schematic diagram of a text recognition device provided by an embodiment of the present disclosure is shown; Figure 7 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.

[0027] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0028] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.

[0029] Research has found that due to the complexity of text, the accuracy of neural network text recognition is low. If better recognition results are to be achieved, a deeper and more complex model structure needs to be designed, which increases the amount of model calculation and prolongs the model training and inference time, which is not conducive to model deployment. The accuracy of text recognition and model complexity cannot be taken into account at the same time.

[0030] Based on the above research, the present disclosure provides a text recognition method, device and storage medium, which restore the original proportion and shape of the text by stretching and restoring the target image, effectively eliminate the character deformation and uneven spacing caused by image stretching, thereby significantly improving the accuracy of text recognition; and, by determining the stretching coefficient and performing restoration processing, the image deformation problem can be solved in the preprocessing stage, so that the subsequent text recognition algorithm can be processed under more standard image conditions, simplifying the overall recognition process and algorithm complexity, and improving processing efficiency.

[0031] To facilitate understanding of this embodiment, a text recognition method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the text recognition method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device. The terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the text recognition method can be implemented by a processor calling a computer-readable instruction stored in a memory.

[0032] See also Figure 1 FIG. 1 is a flowchart of a text recognition method provided by an embodiment of the present disclosure, wherein the method includes steps S101 to S104, wherein: S101, obtaining a target image containing text to be recognized.

[0033] In this step, the target image may be a preprocessed image. The target image may be an image cropped from the image to be recognized. The image to be recognized may contain text to be recognized, and text recognition may be performed on the text to be recognized, thereby predicting the position of the text in the image, and cropping the position containing the text to obtain the target image.

[0034] Exemplarily, the image to be recognized can be input into the detection model to obtain the target image output by the detection model. The detection model can classify the pixels in the image using the image features to obtain the pixels corresponding to the text type, obtain the text box corresponding to the text, and crop the image to be recognized based on the text box.

[0035] The text to be recognized may include multiple characters, such as Chinese, Japanese, English, Korean, numbers, etc.

[0036] See also Figure 2 As shown in FIG. 1 , it is a schematic diagram of the steps of obtaining a target image provided by an embodiment of the present disclosure. Figure 2 As shown, a text region containing text can be determined from the image to be recognized using a text detection model, and the text region can be cropped to obtain a target image.

[0037] S102. Determine the stretching coefficient of the text to be recognized in the target image.

[0038] In some scenarios, the text to be recognized may be stretched, resulting in a certain degree of deformation, which may cause the text to be misrecognized as similar-shaped characters (such as "日" and "曰"). At the same time, stretching may change the meaning of the text in the image, such as misrecognizing "肝" as "月" and "干".

[0039] To address the problem of low recognition accuracy caused by stretching, a more complex recognition model is usually designed to obtain more context information. The structure of the recognition model needs to be designed deeper and more complex, resulting in an increase in computational complexity and an increase in the training and inference time of the model, which is not conducive to the use and deployment of the model.

[0040] To improve the accuracy of text recognition and reduce the complexity of the model, the embodiments of the present disclosure propose a method for text recognition that can first determine the stretching coefficient of the text to be recognized and stretch and restore the target image before text recognition, and then perform text recognition on the restored image. In this way, the influence of text stretching can be removed during the text recognition process, which can not only improve the accuracy of text recognition but also does not require the deployment of a complex text recognition model.

[0041] In a possible implementation, the reference text corresponding to the text to be recognized can be used to determine the stretching coefficient of the text to be recognized by comparing the sizes of the reference text and the text to be recognized.

[0042] To improve the accuracy of recognizing the stretching coefficient, a neural network model can be used to determine the stretching coefficient of the text to be recognized.

[0043] When using the neural network model, the target image can be scaled while maintaining the aspect ratio of the target image so that the height of the scaled target image matches the stretching coefficient recognition model. Then, the scaled target image can be normalized so that the width of the normalized target image matches the stretching coefficient recognition model. In this way, after processing the target image to make it conform to the size of the stretching coefficient recognition model, it can be input into the stretching coefficient recognition model to obtain the stretching coefficient output by the stretching coefficient model.

[0044] When the scaled target image is normalized, if the width of the scaled target image is equal to the width corresponding to the stretch coefficient recognition model, the scaled target image can be directly used as the normalized target image. If the width of the scaled target image is greater than or less than the width corresponding to the stretch coefficient recognition model, the width of the target image needs to be processed.

[0045] Specifically, when the width of the scaled target image is greater than the width corresponding to the stretch coefficient recognition model, the scaled target image may be cropped so that the width of the standardized target image is a preset width.

[0046] In the case that the width of the scaled target image is smaller than the width corresponding to the stretch coefficient identification model, the scaled target image may be padded so that the width of the standardized target image is a preset width.

[0047] The stretch coefficient identification model may be a neural network model, a deep learning model, a linear regression model, etc. For example, the embodiment of the present disclosure may use a neural network model to determine the stretch coefficient.

[0048] In a possible implementation, considering that the stretch factor recognition model only needs to predict the stretch factor of the text, the function is relatively simple, and a model with a relatively simple structure can be used. Exemplarily, the above-mentioned stretch factor recognition model can adopt a convolutional neural network structure, such as a residual network (Residual Network, ResNet). On this basis, the network can also be improved to reduce the amount of model calculation and improve the accuracy of stretch factor recognition.

[0049] Specifically, the accuracy of stretch factor recognition can be improved by introducing an attention mechanism and utilizing contextual information in the target image.

[0050] The computing power required by the attention-based method is related to the input feature size. Assuming that the size of the input feature is (H, W), and the dimension of each head of the attention mechanism is d, the amount of computation is (H·W)·(H·W)·d. The amount of computation required is very large, making it difficult to deploy on edge and mobile devices.

[0051] In order to reduce the computing power requirement of the attention mechanism, the above-mentioned convolutional neural network can be improved. Exemplarily, the above-mentioned stretching coefficient recognition model can include multiple feature extraction layers arranged in sequence; a global mixing module can be arranged between the penultimate and the penultimate feature extraction layers; another global mixing module is arranged after the penultimate feature extraction layer; the global mixing module is used to determine global features based on attention moderation.

[0052] See also Figure 3, which is a schematic diagram of the stretch coefficient identification model provided in an embodiment of the present disclosure. Figure 3 In the figure, the stretching coefficient recognition model can have a convolution layer Conv1, a feature extraction layer Layer1, a feature extraction layer Layer2, a feature extraction layer Layer3, a feature extraction layer Layer4, an average pooling layer Avg pool, a fully connected layer FC and two global mixing modules Global Mix Block. The input data input (standardized target image) is processed by the convolution layer, the feature extraction layer, the global mixing module and the average pooling layer, and finally the stretching coefficient is predicted in the fully connected layer to obtain the output data output.

[0053] Among them, a global mixing module is located between the feature extraction layer Layer3 and the feature extraction layer Layer4, and another global mixing module is located between the feature extraction layer Layer4 and the average pooling layer.

[0054] See also Figure 4 , which is a schematic diagram of a global hybrid module provided by an embodiment of the present disclosure. The global hybrid module may include a multi-head scaled dot-product attention module Multi-Head Scaled Dot-Product Attention and a feed-forward neural network module Feed Forwark Networks; a layer of normalization module Layer Norm may be provided between the multi-head scaled dot-product attention module and the feed-forward neural network module; another layer of normalization module Layer Norm may be provided after the feed-forward neural network module.

[0055] In this way, by adding a global hybrid module with an attention mechanism, the model can obtain more global information at the final prediction, making the prediction result more accurate. In addition, compared with the network based entirely on the attention mechanism, the model provided by the embodiment of the present disclosure will perform downsampling operations when passing through the Conv1 and Layer modules to reduce the size of the input features. For example, assuming that the image size of the model input is (H, W), the feature size after passing through Layer3 is (H / 16, W / 16), and the feature size after passing through Layer4 is (H / 32, W / 32). By adding a global hybrid module with an attention mechanism to the last two layers, the input feature size can be effectively reduced, thereby reducing the amount of computation of the model.

[0056] The stretch coefficient recognition model may be a trained model, and the stretch coefficient recognition model may be trained by the following steps: Acquire a training data set; the training data set includes a plurality of unscaled training images carrying training texts; randomly stretch the widths of the training images in the training data set to obtain a plurality of stretched training images; and train a stretch coefficient recognition model to be trained using the stretched training images and the random stretch coefficients corresponding to the stretched training images.

[0057] In this step, a normal picture can be taken as the background, and some text boxes can be randomly generated on the background picture, and texts in various fonts can be filled in them. Finally, training data can be cropped from the background picture according to the position of the text box and stored in the training data set. In a possible implementation, some pictures with text can also be cropped as training data and added to the training data set.

[0058] Afterwards, the training data in the training data set may be randomly stretched. Generally, stretching the text with the same aspect ratio will not affect the recognition accuracy of the text. Only when the aspect ratio changes will the overall shape of the text actually change. Therefore, only the length or width of the training data set may be stretched. In this embodiment, only the width of the training images in the training data set may be randomly stretched.

[0059] The random stretching coefficient may be set to F. For example, the value range of F may be [0.25, 4].

[0060] After randomly stretching the training image, the stretch coefficient recognition model to be trained can be trained using the stretched training image and the random stretch coefficient corresponding to the stretched training image.

[0061] In this way, training data can be directly generated on a large scale without the need to collect text recognition materials and label them. This results in a higher degree of automation, lower costs, more data, and better results.

[0062] During the training process, the stretched training image can be preprocessed and then input into the stretch coefficient recognition model to be trained. According to the output of the model during the training process and the label corresponding to the stretched training image, the loss of the model can be obtained, and the model parameters after training can be obtained by optimizing the loss.

[0063] The above-mentioned process of preprocessing the stretched training image can be similar to the process of preprocessing the target image. The stretched training image can be scaled while maintaining the aspect ratio of the stretched training image, so that the height of the scaled stretched training image matches the stretch coefficient recognition model; then, the scaled stretched training image is standardized so that the width of the standardized stretched training image matches the stretch coefficient recognition model, and the standardized stretched training image is used as the preprocessed stretched training image.

[0064] For example, the height of the input image is h and the width is w, and the height of the restored model is H and the width is W. While maintaining the aspect ratio of the stretched image, the height of the image is scaled to H. If the width of the image exceeds W, the image is truncated by width, otherwise the image size is made consistent with the input size of the model by padding with 0 pixels. That is, scale the image to (H, ),like , the image width is truncated to W, otherwise the image width is made W by padding with 0 pixels.

[0065] S103: Based on the stretching coefficient, stretch and restore the target image to obtain a restored image corresponding to the target image.

[0066] After obtaining the stretching coefficient, the target image can be stretched and restored using the stretching coefficient. The stretching and restoration process may include the following steps: When the stretching coefficient is greater than the first threshold, the height of the target image may be compressed based on the stretching coefficient to obtain a restored image corresponding to the target image; and / or, When the stretching coefficient is less than the second threshold, the width of the target image is stretched based on the stretching coefficient to obtain a restored image corresponding to the target image.

[0067] The first threshold is greater than the second threshold. When the stretching coefficient is between the second threshold and the first threshold, the shape of the text usually does not change much, and does not have a significant impact on the accuracy of text recognition. Therefore, the stretching coefficient within this interval can be regarded as an error. If the stretching coefficient is within this interval, the target image may not be stretched and restored, thereby reducing the amount of calculation.

[0068] Exemplarily, the first threshold may be set to 1.5, and the second threshold may be set to 0.75.

[0069] In some possible implementations, when the stretching factor f is less than 0.75, it indicates that the input image has been compressed and the predicted image width has been stretched 1 / f times. When f>1.5, it indicates that the input image has been stretched and the height of the input image needs to be stretched f times.

[0070] See also Figure 5 Shown is a schematic diagram of the stretching reduction steps provided in an embodiment of the present disclosure. Figure 5 In the example, the target image includes a target image A and a target image B. After preprocessing (i.e., scaling and normalization) the detected text (i.e., the target image), the standardized target image corresponding to the target image A may be the target image A', and the standardized target image corresponding to the target image B may be the target image B'. Afterwards, the target image A' and the target image B' may be input into the stretching coefficient recognition model to obtain the stretching coefficient, and then the input image may be restored according to the stretching coefficient. Exemplarily, the stretching coefficient of the target image A may be 0.3, and the stretching coefficient of the target image B may be 3. After stretching and restoring the target image A, the restored image A may be obtained, and after stretching and restoring the target image B, the image B may be restored.

[0071] S104: Perform text recognition on the restored image to obtain the text to be recognized.

[0072] In this step, the restored image can be used for text recognition. The text in the restored image has a normal proportion, and the recognition result obtained by performing text recognition on it is more accurate.

[0073] Exemplarily, data enhancement, prior knowledge-based, text shape restoration-based, and other methods may be used to identify the text to be identified in the restored image.

[0074] The text recognition method provided by the embodiment of the present disclosure stretches and restores the target image to restore the original proportion and shape of the text, effectively eliminating character deformation and uneven spacing caused by image stretching, thereby significantly improving the accuracy of text recognition; and, by determining the stretching coefficient and performing restoration processing, the image deformation problem can be solved in the preprocessing stage, so that the subsequent text recognition algorithm can be processed under more standard image conditions, simplifying the overall recognition process and algorithm complexity, and improving processing efficiency.

[0075] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.

[0076] Based on the same inventive concept, a text recognition device corresponding to the text recognition method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned text recognition method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0077] Reference Figure 6FIG. 1 is a schematic diagram of a text recognition device provided by an embodiment of the present disclosure, wherein the device comprises: An acquisition module 610 is used to acquire a target image containing text to be recognized; A determination module 620, configured to determine a stretch factor of the text to be recognized in the target image; A restoration module 630, configured to perform stretching and restoration on the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; The recognition module 640 is used to perform text recognition on the restored image to obtain the text to be recognized.

[0078] In an optional implementation manner, the determining module 620 is specifically configured to: While maintaining the aspect ratio of the target image, scaling the target image so that the height of the scaled target image matches the stretch coefficient recognition model; Performing standardization processing on the scaled target image so that the width of the standardized target image matches the stretch coefficient recognition model; The standardized target image is input into the stretch coefficient recognition model to obtain the stretch coefficient output by the stretch coefficient model.

[0079] In an optional implementation manner, the determining module 620 is specifically configured to: When the width of the scaled target image is greater than the width corresponding to the stretch coefficient identification model, the scaled target image is cropped so that the width of the standardized target image is a preset width; and / or, In the case where the width of the scaled target image is smaller than the width corresponding to the stretch coefficient identification model, the scaled target image is padded so that the width of the standardized target image is a preset width.

[0080] In an optional implementation manner, the restoration module 630 is specifically used to: When the stretching coefficient is greater than a first threshold, compressing the height of the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; and / or, When the stretching coefficient is less than a second threshold, the width of the target image is stretched based on the stretching coefficient to obtain a restored image corresponding to the target image; and the first threshold is greater than the second threshold.

[0081] In an optional implementation, the device further includes a training module 650, which is used to: Acquire a training data set; the training data set includes a plurality of unscaled training images carrying training texts; Randomly stretching the width of the training images in the training data set to obtain a plurality of stretched training images; The stretching coefficient recognition model to be trained is trained using the stretching training image and the random stretching coefficient corresponding to the stretching training image.

[0082] In an optional implementation manner, the training module 650 is specifically configured to include: Under the condition of maintaining the aspect ratio of the stretch training image, scaling the stretch training image so that the height of the scaled stretch training image matches the stretch coefficient recognition model; performing standardization processing on the scaled stretch training image so that the width of the standardized stretch training image matches the stretch coefficient recognition model; The standardized stretch training image is used as an input of a stretch coefficient recognition model to be trained, and the random stretch coefficient corresponding to the standardized stretch training image is used as a label to train the stretch coefficient recognition model.

[0083] In an optional embodiment, the stretch coefficient identification model includes a plurality of feature extraction layers arranged in sequence; a global mixing module is arranged between the penultimate and second to last feature extraction layers; another global mixing module is arranged after the penultimate feature extraction layer; and the global mixing module is used to determine global features based on attention moderation.

[0084] In an optional embodiment, the global mixing module includes a multi-head scaling dot product attention module and a feedforward neural network module; a layer of normalization module is arranged between the multi-head scaling dot product attention module and the feedforward neural network module; and another layer of normalization module is arranged after the feedforward neural network module.

[0085] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.

[0086] Corresponds to Figure 1 The text recognition method in the present disclosure also provides an electronic device 700, such as Figure 7 FIG. 7 is a schematic diagram of the structure of an electronic device 700 provided in an embodiment of the present disclosure, including: Processor 71, memory 72, and bus 73; memory 72 is used to store execution instructions, including internal memory 721 and external memory 722; the internal memory 721 is also called internal memory, which is used to temporarily store the operation data in the processor 71 and the data exchanged with the external memory 722 such as a hard disk. The processor 71 exchanges data with the external memory 722 through the internal memory 721. When the electronic device 700 is running, the processor 71 communicates with the memory 72 through the bus 73, so that the processor 71 executes the following instructions: Obtain a target image containing text to be recognized; Determining a stretch factor of the text to be recognized in the target image; Based on the stretching coefficient, stretch and restore the target image to obtain a restored image corresponding to the target image; Perform text recognition on the restored image to obtain the text to be recognized.

[0087] In an optional implementation manner, in the instructions executed by the processor 71, determining the stretching coefficient of the text to be recognized in the target image includes: While maintaining the aspect ratio of the target image, scaling the target image so that the height of the scaled target image matches the stretch coefficient recognition model; Performing standardization processing on the scaled target image so that the width of the standardized target image matches the stretch coefficient recognition model; The standardized target image is input into the stretch coefficient recognition model to obtain the stretch coefficient output by the stretch coefficient model.

[0088] In an optional implementation manner, in the instructions executed by the processor 71, the step of normalizing the scaled target image so that the width of the normalized target image matches the stretch coefficient recognition model includes: When the width of the scaled target image is greater than the width corresponding to the stretch coefficient identification model, the scaled target image is cropped so that the width of the standardized target image is a preset width; and / or, In the case where the width of the scaled target image is smaller than the width corresponding to the stretch coefficient identification model, the scaled target image is padded so that the width of the standardized target image is a preset width.

[0089] In an optional implementation manner, in the instruction executed by the processor 71, stretching and restoring the target image based on the stretching coefficient includes: When the stretching coefficient is greater than a first threshold, compressing the height of the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; and / or, When the stretching coefficient is less than a second threshold, the width of the target image is stretched based on the stretching coefficient to obtain a restored image corresponding to the target image; and the first threshold is greater than the second threshold.

[0090] In an optional implementation manner, the instructions executed by the processor 71 further include: Acquire a training data set; the training data set includes a plurality of unscaled training images carrying training texts; Randomly stretching the width of the training images in the training data set to obtain a plurality of stretched training images; The stretching coefficient recognition model to be trained is trained using the stretching training image and the random stretching coefficient corresponding to the stretching training image.

[0091] In an optional implementation manner, in the instructions executed by the processor 71, using the stretched training image and the random stretch coefficient corresponding to the stretched training image to train the stretch coefficient recognition model to be trained includes: Under the condition of maintaining the aspect ratio of the stretch training image, scaling the stretch training image so that the height of the scaled stretch training image matches the stretch coefficient recognition model; performing standardization processing on the scaled stretch training image so that the width of the standardized stretch training image matches the stretch coefficient recognition model; The standardized stretch training image is used as an input of a stretch coefficient recognition model to be trained, and the random stretch coefficient corresponding to the standardized stretch training image is used as a label to train the stretch coefficient recognition model.

[0092] In an optional embodiment, in the instructions executed by the processor 71, the stretch coefficient identification model includes a plurality of feature extraction layers arranged in sequence; a global mixing module is arranged between the penultimate and second to last feature extraction layers; another global mixing module is arranged after the penultimate feature extraction layer; and the global mixing module is used to determine global features based on attention moderation.

[0093] In an optional embodiment, in the instructions executed by the processor 71, the global mixing module includes a multi-head scaling dot product attention module and a feedforward neural network module; a layer of normalization module is arranged between the multi-head scaling dot product attention module and the feedforward neural network module; and another layer of normalization module is arranged after the feedforward neural network module.

[0094] The present disclosure also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the text recognition method described in the above method embodiment are executed. The storage medium may be a volatile or non-volatile computer-readable storage medium.

[0095] The embodiments of the present disclosure also provide a computer program product, which carries a program code. The instructions included in the program code can be used to execute the steps of the text recognition method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.

[0096] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).

[0097] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. 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 through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.

[0098] 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.

[0099] In addition, each functional unit in each embodiment of the present disclosure 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.

[0100] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0101] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.

Claims

1. A text recognition method, characterized in that: include: Obtain a target image containing text to be recognized; While maintaining the aspect ratio of the target image, scaling the target image so that the height of the scaled target image matches the stretch coefficient recognition model; Performing standardization processing on the scaled target image so that the width of the standardized target image matches the stretch coefficient recognition model; Inputting the standardized target image into the stretch coefficient recognition model to obtain the stretch coefficient output by the stretch coefficient model; Based on the stretching coefficient, stretch and restore the target image to obtain a restored image corresponding to the target image; Perform text recognition on the restored image to obtain the text to be recognized.

2. The method according to claim 1, characterized in that: The step of normalizing the scaled target image so that the width of the normalized target image matches the stretch coefficient recognition model includes: When the width of the scaled target image is greater than the width corresponding to the stretch coefficient identification model, the scaled target image is cropped so that the width of the standardized target image is a preset width; and / or, In the case that the width of the scaled target image is smaller than the width corresponding to the stretch coefficient identification model, the scaled target image is padded so that the width of the standardized target image is a preset width.

3. The method according to claim 1, characterized in that: The stretching and restoring of the target image based on the stretching coefficient includes: When the stretching coefficient is greater than a first threshold, compressing the height of the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; and / or, When the stretching coefficient is less than a second threshold, the width of the target image is stretched based on the stretching coefficient to obtain a restored image corresponding to the target image; and the first threshold is greater than the second threshold.

4. The method according to claim 1, characterized in that: The stretch factor identification model is trained according to the following steps: Acquire a training data set; the training data set includes a plurality of unscaled training images carrying training texts; Randomly stretching the width of the training images in the training data set to obtain a plurality of stretched training images; The stretching coefficient recognition model to be trained is trained using the stretching training image and the random stretching coefficient corresponding to the stretching training image.

5. The method according to claim 4, characterized in that The using the stretch training image and the random stretch coefficient corresponding to the stretch training image to train the stretch coefficient recognition model to be trained includes: Under the condition of maintaining the aspect ratio of the stretch training image, scaling the stretch training image so that the height of the scaled stretch training image matches the stretch coefficient recognition model; performing standardization processing on the scaled stretch training image so that the width of the standardized stretch training image matches the stretch coefficient recognition model; The standardized stretch training image is used as an input of a stretch coefficient recognition model to be trained, and the random stretch coefficient corresponding to the standardized stretch training image is used as a label to train the stretch coefficient recognition model.

6. The method according to claim 1, characterized in that The stretch coefficient identification model includes a plurality of feature extraction layers arranged in sequence; a global mixing module is arranged between the penultimate and second to last feature extraction layers; another global mixing module is arranged after the penultimate feature extraction layer; the global mixing module is used to determine global features based on attention control.

7. The method according to claim 6, characterized in that The global mixing module includes a multi-head scaling dot product attention module and a feedforward neural network module; a layer of normalization module is arranged between the multi-head scaling dot product attention module and the feedforward neural network module; another layer of normalization module is arranged after the feedforward neural network module.

8. A text recognition device, characterized in that: include: An acquisition module, used for acquiring a target image containing text to be recognized; a determination module, configured to scale the target image while maintaining the aspect ratio of the target image, so that the height of the scaled target image matches the stretch coefficient recognition model; perform standardization on the scaled target image, so that the width of the standardized target image matches the stretch coefficient recognition model; and input the standardized target image into the stretch coefficient recognition model to obtain the stretch coefficient output by the stretch coefficient model; A restoration module, used for performing stretching and restoration on the target image based on the stretching coefficient to obtain a restored image corresponding to the target image; The recognition module is used to perform text recognition on the restored image to obtain the text to be recognized.

9. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the text recognition method as described in any one of claims 1 to 7 are performed.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the text recognition method according to any one of claims 1 to 7 are executed.

Citation Information

Patent Citations

  • A Text Line Recognition Method in Chinese Scenes Based on Residual Convolutional and Recurrent Neural Networks

    AU2020101229A4

  • Method and apparatus for identifying picture characters

    CN106650719A

  • Method, apparatus, storage medium and terminal device for image restoration

    CN109447911A

  • Text recognition method and device

    CN109977935A

  • Multi-stage progressive underwater image enhancement method

    CN114445292A