Text recognition method, device, electronic device and storage medium

By detecting the vertices in the image to be recognized and drawing polygons for text recognition, it solves the problem of poor recognition results in the existing technology when the inclination angle and distortion are large, and achieves efficient recognition of irregular text areas, which is suitable for a variety of scenarios. .

CN110378338BActive Publication Date: 2024-08-27TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910625593.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-07-11
Publication Date
2024-08-27
Estimated Expiration
2039-07-11

AI Technical Summary

Technical Problem

Existing OCR technology has poor recognition results when the inclination level of the object to be recognized or the image distortion is large, and cannot be applied to non-standard text areas.

Method used

By obtaining the image to be recognized, detecting the vertices of the area where the text information is located, drawing polygons and identifying them, using the trained corner point detection model to perform feature extraction and loss function optimization, the text information in the polygons is obtained.

Benefits of technology

It improves the recognition effect in the case of non-standard text areas, is suitable for various scenarios, and enhances flexibility and applicability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110378338B
    Figure CN110378338B
Patent Text Reader

Abstract

The embodiments of the present application disclose a text recognition method, device, electronic device and storage medium; as can be seen from the above, after acquiring an image to be recognized containing text information, the embodiment can determine the vertices of the area where the text information is located, obtain multiple corner points, and then draw a polygon in the image to be recognized based on the obtained multiple corner points, and recognize the text information in the polygon to obtain a recognition result; this solution can be applied to various scenarios and improve the recognition effect when the object to be recognized is not standardized (such as the text area to be recognized has a horizontal inclination or large distortion).
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a text recognition method, device, electronic equipment and storage medium. Background Art

[0002] General optical character recognition (OCR) is a commonly used text recognition technology. It can support text detection and recognition in multiple scenarios. For example, it can extract text information from images, cards or other objects to be recognized, and then display the text information in the form of text to facilitate users to edit and copy. When extracting text information, a rectangular frame is generally used to determine the area to be recognized from the object to be recognized, and then the text information in the area to be recognized is extracted for recognition.

[0003] However, in the process of research and practice on the prior art, the inventors of the present invention found that the existing scheme is only applicable to situations where the inclination level and image distortion of the text are not large. For some situations where the objects to be identified are not standardized, such as situations where the inclination level is large or the image distortion is large (such as a large degree of perspective or affine transformation), the recognition effect is poor or even impossible to recognize. Summary of the invention

[0004] The embodiments of the present application provide a text recognition method, device, electronic device and storage medium, which can be applied to various scenarios and improve the recognition effect when the object to be recognized is not standardized (such as the text area to be recognized has a horizontal inclination or large distortion).

[0005] The present application provides a text recognition method, including:

[0006] Acquire an image to be identified, wherein the image to be identified contains text information;

[0007] Detecting vertices of the area where the text information is located to obtain multiple corner points;

[0008] Drawing a polygon in the image to be recognized according to the obtained multiple corner points;

[0009] The text information in the polygon is recognized to obtain a recognition result.

[0010] Accordingly, the embodiment of the present application further provides a text recognition device, including:

[0011] An acquisition unit, used for acquiring an image to be recognized, wherein the image to be recognized contains text information;

[0012] A detection unit, used to detect vertices of the area where the text information is located, and obtain multiple corner points;

[0013] A drawing unit, used for drawing a polygon in the image to be recognized according to the obtained multiple corner points;

[0014] The recognition unit is used to recognize the text information in the polygon and obtain a recognition result.

[0015] Optionally, in some embodiments of the present application, the detection unit includes a region recognition subunit and a corner point determination subunit, as follows:

[0016] The region recognition subunit is used to use the trained corner point detection model to recognize the region where the text information is located in the image to be recognized, so as to obtain the text region;

[0017] The corner point determination subunit is used to determine the vertices of the text area envelope to obtain a plurality of corner points.

[0018] Optionally, in some embodiments of the present application, the region identification subunit is specifically used to perform feature extraction on the image to be identified using the trained corner point detection model to obtain a feature map, and based on the feature map, screen pixel points whose pixel types are consistent with the pixel types of the region where the text information is located to obtain a text region.

[0019] Optionally, in some embodiments of the embodiments of the present application, the trained corner point detection model includes a residual module, the main branch of the residual module is a fire protection module, and the region identification subunit is specifically used to perform channel compression and dimensionality reduction operations on the image to be identified through the compression layer of the fire protection module to obtain a compressed result, and use the expansion layer of the fire protection module to perform feature extraction of different scales on the compressed result to obtain a feature map.

[0020] Optionally, in some embodiments of the present application, the text recognition device may further include a collection unit and a training unit, as follows:

[0021] The acquisition unit is used to acquire a plurality of image samples with text area corner points marked;

[0022] The training unit is used to use a corner point detection model to identify the area where the text information in the image sample is located, obtain a predicted area, determine the vertices of the predicted area envelope, obtain the predicted area corner points, and converge the corner point detection model according to the predicted area corner points and the marked text area corner points to obtain a trained corner point detection model.

[0023] Optionally, in some embodiments of the present application, the training unit is specifically used to construct a loss function based on the distance between the corner points of the predicted area and the corner points of the annotated text area, and use the loss function to converge the corner detection model to obtain a trained corner detection model.

[0024] Optionally, in some embodiments of the present application, the training unit is specifically used to determine the corner point that currently needs to be processed from the annotated text area corner points, obtain the current annotated corner point, calculate the distance between the current annotated corner point and each predicted area corner point, select the predicted area corner point with the shortest distance as the target corner point of the current annotated corner point, take the current annotated corner point and the target corner point as a pair of corner point pairs, and return to execute the step of determining the corner point that currently needs to be processed from the annotated text area corner points until all annotated text area corner points are processed, and construct a loss function based on all obtained corner point pairs; use the loss function to adjust the network parameters of the corner point detection model so that the current annotated corner point in the corner point pair is displaced in the direction of the target corner point to reduce the distance between the current annotated corner point and the target corner point in the corner point pair.

[0025] Optionally, in some embodiments of the present application, the text recognition device may further include a compression unit, as follows:

[0026] The compression unit is used to compress the trained corner point detection model using a neural network compression algorithm to obtain a compressed corner point detection model;

[0027] The recognition unit is specifically used to use the compressed corner point detection model to recognize the area where the text information is located in the image to be recognized, so as to obtain the text area.

[0028] Optionally, in some embodiments of the present application, the compression unit is specifically used to prune the trained corner detection model, quantize the pruned corner detection model, and perform Huffman encoding on the quantized corner detection model to obtain a compressed corner detection model.

[0029] Optionally, in some embodiments of the present application, the drawing unit is specifically used to determine the current corner point, and determine the adjacent points of the current corner point in a preset direction, draw connecting lines between the current corner point and the adjacent points as the edges of the polygon, and return to execute the step of determining the current corner point until all corner points are traversed.

[0030] Optionally, in some embodiments of the present application, the drawing unit is specifically used to draw connecting lines between various corner points, and select the closed area with the largest area from the closed areas formed by the connecting lines to obtain a polygon.

[0031] Correspondingly, an embodiment of the present application also provides an electronic device, including a memory and a processor; the memory stores an application, and the processor is used to run the application in the memory to perform operations in any text recognition method provided in the embodiment of the present application.

[0032] In addition, an embodiment of the present application further provides a storage medium, which stores a plurality of instructions, and the instructions are suitable for loading by a processor to execute the steps in any text recognition method provided in the embodiment of the present application.

[0033] After acquiring an image to be recognized containing text information, the embodiment of the present application can detect the vertices of the area where the text information is located to obtain multiple corner points, and then draw a polygon in the image to be recognized based on the multiple corner points obtained, and recognize the text information in the polygon to obtain a recognition result; since the scheme can draw polygons based on corner points and determine the text area to be recognized based on this, therefore, compared with the existing scheme that can only determine the text area from the image to be recognized through a standard rectangular frame, the polygon obtained by the scheme can be more consistent with the text area even when the inclination level or distortion of the text area to be recognized is large (such as a large degree of perspective or affine transformation), which greatly improves the recognition effect when the text area to be recognized is not standardized; moreover, since the scheme is not limited by the inclination level or distortion size, it can be applied to various scenarios, and its flexibility and applicability are also improved compared with the existing scheme. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0035] Figure 1 is a scene schematic diagram of the text recognition method provided in an embodiment of the present application;

[0036] Figure 2 is a flowchart of a text recognition method provided by an embodiment of the present application;

[0037] Figure 3 is a schematic diagram of the structure of the trained corner point detection model provided in an embodiment of the present application;

[0038] Figure 4 is a schematic diagram of the structure of the residual module provided in an embodiment of the present application;

[0039] Figure 5 is another structural schematic diagram of a trained corner point detection model provided in an embodiment of the present application;

[0040] Figure 6 It is a structural schematic diagram of a fire protection module (fire) provided in an embodiment of the present application;

[0041] Figure 7 is a schematic diagram of corner point displacement provided in an embodiment of the present application;

[0042] Figure 8 is a structural diagram of a corner point detection model provided in an embodiment of the present application;

[0043] Fig. 9 is another flow chart of the text recognition method provided by an embodiment of the present application;

[0044] Fig.10 is a scene schematic diagram of the text recognition method provided in an embodiment of the present application;

[0045] Fig.11 is another scenario schematic diagram of the text recognition method provided in an embodiment of the present application;

[0046] Fig.12 is another scenario schematic diagram of the text recognition method provided in an embodiment of the present application;

[0047] Fig.13 is a structural diagram of a text recognition device provided in an embodiment of the present application;

[0048] Fig.14 is another structural schematic diagram of the text recognition device provided in an embodiment of the present application;

[0049] Fig.15 is another structural schematic diagram of a text recognition device provided in an embodiment of the present application;

[0050] Fig.16 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0052] The embodiments of the present application provide a text recognition method, device, electronic device and storage medium. The text recognition device can be integrated in an electronic device, which can be a server or a terminal.

[0053] For example, Figure 1As shown, after obtaining an image to be identified containing text information, the electronic device can detect the vertices of the area where the text information is located to obtain multiple corner points, and then draw a polygon in the image to be identified based on these corner points, and identify the text information in the polygon to obtain a recognition result.

[0054] There are many ways to detect corner points. For example, a trained corner point detection model can be used to identify the area where the text information is located in the image to be identified to obtain the text area. Then, the vertices of the envelope box of the text area can be determined to obtain the required corner points, and so on.

[0055] It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.

[0056] This embodiment will be described from the perspective of a text recognition device, which can be specifically integrated into an electronic device such as a server or a terminal. The terminal can include a personal computer (PC), a mobile phone, a tablet computer, a mobile computer, or a wearable smart mobile device.

[0057] A text recognition method comprises: obtaining an image to be recognized containing text information, detecting vertices of an area where the text information is located to obtain a plurality of corner points, drawing a polygon in the image to be recognized according to the obtained plurality of corner points, and recognizing the text information in the polygon to obtain a recognition result.

[0058] like Figure 2 As shown, the specific process of the text recognition method can be as follows:

[0059] 101. Obtain an image to be identified, where the image to be identified contains text information.

[0060] For example, the text recognition device can obtain the image to be recognized by photographing or scanning the object to be recognized through its own imaging component such as a camera; or, it can also receive the image to be recognized sent by other devices, that is, after the other devices capture the image of the object to be recognized, the captured image is provided to the text recognition device as the image to be recognized, and so on.

[0061] The image to be identified refers to an image obtained after image acquisition of the object to be identified, which may include invoices, cards, business cards, notepaper, notebooks, documents and other objects that require text recognition.

[0062] Optionally, in order to improve the accuracy of detection, the collected image may be preprocessed and the processed image may be used as the image to be identified.

[0063] The preprocessing may include rotation, flipping and / or cropping.

[0064] 102. Detect the vertices of the area where the text information is located to obtain multiple corner points; for example, the specific method may be as follows:

[0065] The trained corner point detection model is used to identify the area where the text information is located in the image to be identified, to obtain the text area, to determine the vertices of the envelope of the text area, and to obtain multiple corner points.

[0066] For example, the trained corner point detection model can be used to extract features of the image to be identified to obtain a feature map. Then, based on the feature map, the pixel points whose pixel types match the pixel types of the area where the text information is located can be screened to obtain the text area.

[0067] The trained corner point detection model may be trained by a plurality of image samples with text area corner points annotated thereon, and may specifically be a deep convolutional neural network.

[0068] For deep convolutional neural networks, if you need to improve the detection effect of the model, you need to deepen the depth of the network layer. However, as the network layer deepens, the features will become more abstract. For this application, during the specific implementation, the objects to be identified often have good features such as edges and corners. These features are generally low-level features (i.e., non-high-level semantic features), that is, features that can be extracted by the low-level network layer. Therefore, in order to be able to improve the detection effect of the model while better enhancing the effect of low-level features (the purpose of the trained corner detection model is to detect corners), it is necessary to propagate low-level features to high-level feature maps, so that the corner detection model can directly learn the corner and edge characteristics to directly regress the corners of the polygon. Therefore, the trained corner detection model can adopt a bottleneck structure. The number of network layers of the network structure, as well as the parameters such as the size of the convolution kernel, can be determined according to the needs of the actual application. For example, Figure 3 As shown, the trained corner point detection model may include a residual module (the residual module here refers to a module using a residual structure), and each residual module may include a main branch and a side branch, see Figure 4 .

[0069] Among them, the main branch of the residual module is the fire module (fire), which is the network structure proposed in the compression network (SqueezeNet) and is the basic building block of SqueezeNet. It can compress the model by reducing parameters.

[0070] The residual module needs to fuse the output of the main branch with the output of the side branch to obtain the output of the residual module. That is, after the input of each residual module is processed by the fire module, the processed result needs to be fused with the input to obtain the output of the residual module.

[0071] For example, see Figure 3 , after the image to be identified is processed by convolution layer 1 (Conv1), activation layer (Relu_conv1) and pooling layer 1 in sequence, the pooled data is input into fire module 2 (fire2) for processing, and then the pooled data is fused with the output of fire module 2, and the fused data is used as the input of fire module 3 (fire3). Similarly, after fire module 3 processes its input, the input of fire module 3 is fused with the output of fire module 3, and the fused data is used as the input of fire module 4 (fire4), and so on, until the output and input of the last fire module are fused, for example, Figure 3 After the output of the fire fighting module 9 in is fused with the input of the fire fighting module 9, the final feature map (i.e. the feature map output by the fire fighting module 9) can be obtained. After that, the feature map output by the fire fighting module 9 is subjected to convolution and pooling and other processing. For example, the feature map output by the fire fighting module 9 is processed by network layers such as the convolution layer 10 (Conv10), the activation layer (Relu_conv10), the pooling layer 10 and the activation function (softmax) to filter out pixel points whose pixel types are consistent with the pixel types of the area where the text information is located. The area where these pixel points are located is the text area. Finally, the vertices of the envelope box of the text area are determined to obtain multiple corner points.

[0072] It should be noted that for the convenience of description, Figure 3 Only an example of a residual module is given in FIG. , and it should be understood that Figure 3 The trained corner point detection model in also includes other residual modules, such as fire-fighting module 3, fire-fighting module 4...Fire-fighting module 9 is the main branch of other residual modules, which will not be elaborated here.

[0073] Optionally, in order to improve the accuracy of detection, before fusing the main branch output of the residual module with the side branch, the side branch data may be convolved, and then the convolved data is fused with the main branch output to obtain the output of the residual module. Figure 5 As shown in FIG. 1 , a convolution layer with a convolution kernel of 1×1 can be added to the fire fighting module 2, the fire fighting module 4, the fire fighting module 6 and the fire fighting module 8. Figure 5 In addition to the examples in the figure, convolutional layers can also be added to other firefighting modules or side branches of all firefighting modules. The specific details can be determined according to the needs of actual applications and will not be elaborated here.

[0074] Among them, the fire fighting module may include a compression layer (Squeeze) and an expansion layer (Expand). For example, the convolution kernel of the compression layer is 1×1 (i.e., Squeeze 1×1), and the convolution kernel of the expansion layer can be set to two types: 1×1 and 3×3. For the convenience of description, in the embodiment of the present application, the expansion layer with a convolution kernel of 1×1 is called the first expansion layer (i.e., Expand 1×1), and the expansion layer with a convolution kernel of 3×3 is called the second expansion layer (i.e., Expand 3×3). In addition, both the compression layer and the expansion layer use Relu as the activation function, for example, see Figure 6 , the activation function of the compression layer (i.e., the activation layer) is "Relu_squeeze 1×1", the activation function of the first expansion layer (i.e., the activation layer) is "Relu_Expand 1×1", and the activation function of the second expansion layer (i.e., the activation layer) is "Relu_Expand 3×1".

[0075] Since the parameters of a 1x1 convolution kernel are 1 / 9 of the parameters of a 3x3 convolution kernel, the use of this compression layer is equivalent to compressing the model size by 9 times, so that the corner detection model can be applied to mobile terminals in addition to servers and other devices. Of course, in order to avoid the reduction of the resolution of the feature map obtained after the model size is compressed (the feature map with a larger resolution can bring higher classification accuracy, because the input with a larger resolution can provide more information), the fire module also uses expansion layers - the first expansion layer (i.e., Expand 1×1) and the second expansion layer (i.e., Expand 3×3) to extract features of different scales from the data output by the compression layer to enhance the amount of information contained in the data output by the compression layer. Then, the output of the first expansion layer and the output of the second expansion layer are connected in the channel dimension through the connection layer (Concat).

[0076] It should be noted that in order to ensure that the first expansion layer (1x1 convolution kernel) and the second expansion layer (3x3 convolution kernel) have the same output size for connection, the second expansion layer can use a 1-pixel padding value (zero-padding) and step size, which will not be repeated here.

[0077] Based on the above description of the fire module, when the trained corner detection model includes a residual module, and the main branch of the residual module is a fire module, the step of "using the trained corner detection model to extract features of the image to be identified to obtain a feature map" may include:

[0078] The compression layer of the fire-fighting module performs channel compression and dimension reduction operations on the image to be identified to obtain a compressed result, and the expansion layer of the fire-fighting module performs feature extraction of different scales on the compressed result to obtain a feature map.

[0079] Optionally, the trained corner point detection model may be pre-trained by other devices and saved in the text recognition device, or may be trained by the text recognition device itself, that is, before the step of "using the trained corner point detection model to identify the area where the text information is located in the image to be recognized to obtain the text area", the text recognition method may further include:

[0080] (1) Collect multiple image samples with ground truth points marked with text areas.

[0081] For example, multiple images can be obtained from a gallery, or multiple images can be collected by the text recognition device's own imaging component such as a camera, and then the text area corners in the images are manually annotated, and the annotated images are used as image samples.

[0082] Among them, the text area corners refer to the vertices of the text area (default boxes), for example, see Figure 7 , if the text area is a quadrilateral "mnpq" ( Figure 7 The text area corners are the four vertices of the quadrilateral “mnpq”: m, n, p and q.

[0083] Optionally, in order to improve the quality of training samples, the images may be preprocessed before annotation, and then the preprocessed images may be annotated to obtain image samples.

[0084] The preprocessing may include operations such as deduplication, rotation, flipping and / or cropping.

[0085] (2) A corner detection model is used to identify the area where the text information is located in the image sample to obtain the predicted area.

[0086] For example, a corner detection model can be used to extract features from the image sample to obtain a feature map, and then, based on the feature map, the pixel points whose pixel types match the pixel types of the area where the text information is located can be screened to obtain the text area of ​​the image sample. For the convenience of description, the text area of ​​the image sample is referred to as a prediction area in the embodiment of the present application.

[0087] The network structure of the corner detection model is the same as the network structure of the trained corner detection model described above, that is, the corner detection model can include a residual module, and each residual module can include a main branch and a side branch. The main branch is a firefighting module. For details, see Figures 3 to 6 , and the previous embodiments are not described in detail here.

[0088] (3) Determine the vertices of the prediction region envelope to obtain the prediction region corner points.

[0089] For example, see Figure 7 , if the predicted area envelope is a quadrilateral "abcd" ( Figure 7 The predicted area corners are the four vertices of the quadrilateral "abcd": a, b, c, and d.

[0090] (4) The corner point detection model is converged according to the corner points of the predicted area and the marked corner points of the text area to obtain a trained corner point detection model.

[0091] For example, a loss function can be constructed based on the distance between the corner points of the predicted area and the corner points of the annotated text area, and then the corner point detection model is converged using the loss function to obtain a trained corner point detection model. For example, the specific convergence method can be as follows:

[0092] A. Determine the corner point that needs to be processed from the annotated text area corner points to obtain the current annotated corner point; calculate the distance between the current annotated corner point and each predicted area corner point; select the predicted area corner point with the shortest distance as the target corner point of the current annotated corner point; take the current annotated corner point and the target corner point as a pair of corner points, and return to execute the step of determining the corner point that needs to be processed from the annotated text area corner points until all the annotated text area corner points are processed; construct a loss function based on all the obtained corner point pairs.

[0093] For example, see Figure 7 , taking the prediction area corner points including a, b, c and d, and the annotated corner points as m, n, p and q as an example, if the current annotated corner point is m, then the distance between m and "a, b, c and d" can be calculated respectively. Since the distance between m and a is the shortest, a can be used as the target corner point of m. Then, a and m are used as a pair of corner points, and the current annotated corner point is updated to n. The distance between n and "a, b, c and d" is calculated respectively. Since the distance between n and b is the shortest, b can be used as the target corner point of n. Then, b and n are also used as a pair of corner points, and the current annotated corner point is updated to p. By analogy, four pairs of corner points (a, m), (b, n), (c, p) and (d, q) can be obtained. After that, the loss function can be constructed based on these corner point pairs. For example, the loss function can be specifically as follows:

[0094]

[0095] Among them, G m is the corner point of the marked text area, G mx and G my The corner points G m The horizontal and vertical coordinates of P a is the corner point of the prediction area, P ax and P ay They are corner points P a The horizontal and vertical coordinates of .

[0096] For example, if Figure 7 Taking the polygon shown in as an example, the expansion of the loss function can be as follows:

[0097]

[0098] Among them, x m is the horizontal coordinate of the corner point m, y m is the ordinate of the corner point m; x n is the horizontal coordinate of corner point n, y n is the ordinate of corner point n; x p is the horizontal coordinate of the corner point p, y p is the ordinate of the corner point p; x q is the horizontal coordinate of the corner point q, y q is the ordinate of the corner point q; x a is the horizontal coordinate of corner point a, y a is the ordinate of the corner point a; x b is the horizontal coordinate of corner point b, y b is the ordinate of the corner point b; x c is the horizontal coordinate of the corner point c, y c is the ordinate of the corner point c; x d is the horizontal coordinate of the corner point d, y d is the ordinate of corner point d.

[0099] B. Use the loss function to adjust the network parameters of the corner point detection model so that the current labeled corner point in the corner point pair is displaced toward the target corner point to reduce the distance between the current labeled corner point in the corner point pair and the target corner point.

[0100] That is to say, the distance between the current labeled corner point and the target corner point is made as small as possible (that is, the loss is minimized), and then the corresponding gradient is back-propagated to update the network weights of the corner detection model at this time. This process is repeated and optimized, and finally a trained corner detection model can be formed.

[0101] For example, see Figure 7, taking the current annotated corner point m as an example, at this time, m can be displaced toward the target corner point a, so that the distance between m and a is as small as possible (ideally overlapping). When the distance between m and a is minimized, it indicates that the adjustment of network parameters is completed. When the distances between all annotated corner points and their target corner points are minimized, it indicates that the training of the corner detection model is completed. By analogy, after multiple trainings of the corner detection model, the trained corner detection model can be obtained.

[0102] It should be noted that in the embodiment of the present application, the reason why the current marked corner point m (i.e. the marked corner point) is displaced toward the target corner point a (i.e. the predicted corner point) instead of displacing the target corner point a toward the current marked corner point m is because if the predicted corner point changes, it will have a greater impact on the parameters in the model, which is not conducive to convergence. If only the marked corner point changes, the impact on the model will be smaller, which will greatly speed up the convergence.

[0103] Optionally, in order to make the size of the trained corner point detection model smaller, so as to save computing resources and improve computing speed, the trained corner point detection model may be compressed in size; that is, after the step of "converging the corner point detection model according to the corner points of the prediction area and the annotated text area corner points to obtain the trained corner point detection model", the text recognition method may further include:

[0104] A neural network compression algorithm is used to compress the trained corner detection model to obtain a compressed corner detection model.

[0105] At this time, the step of "using the trained corner point detection model to identify the area where the text information is located in the image to be identified, and obtain the text area" may include: using the compressed corner point detection model to identify the area where the text information is located in the image to be identified, and obtain the text area.

[0106] Among them, the neural network compression algorithm can be determined according to the needs of the actual application. For example, DW (Depthwise) convolution and PW (Pointwise) convolution can be used. Among them, DW convolution and PW convolution are collectively called Depthwise Separable Convolution, which can reduce the time consumption of model inference and make the model better applied to mobile terminals.

[0107] The compression method may include operations such as pruning, quantization, and Huffman Coding. That is, the step of "compressing the trained corner detection model using a neural network compression algorithm to obtain a compressed corner detection model" may include:

[0108] The trained corner detection model is pruned, the pruned corner detection model is quantized, and the quantized corner detection model is Huffman encoded to obtain a compressed corner detection model. The concepts of pruning, quantization, and Huffman encoding can be as follows:

[0109] Pruning: Set some very small (considered unimportant) weights to 0 (since the convolutional neural network is composed of layers of nodes connected by edges, and each edge has a weight, when it is found that the weights on some edges are very small, it can be considered that such edges are unimportant and can be removed), so that the weight matrix can be stored using the compressed storage method of storing sparse matrices, such as CSR (Compressed Sparse Row) or CSC (Compressed Sparse Column).

[0110] Quantization: Generally speaking, the parameters of neural network models are represented by 32-bit floating-point numbers. In fact, there is no need to retain such high precision. It can be quantized, for example, using 0 to 255 to represent the precision represented by the original 32 bits. By sacrificing precision, the space required for each weight can be reduced. Therefore, by quantizing the weights retained after pruning, the weights retained after pruning can share some values, which can reduce the space used to store the weights and further compress the required storage space.

[0111] Huffman coding: In computer data processing, Huffman coding uses a variable-length coding table to encode source symbols (such as a letter in a file), wherein the variable-length coding table is obtained by a method of evaluating the probability of occurrence of the source symbol. Letters with a high probability of occurrence use shorter codes, whereas letters with a low probability of occurrence use longer codes. This reduces the average length and expected value of the encoded string, thereby achieving the purpose of lossless data compression. Therefore, this embodiment can reduce the storage space required for data storage by performing Huffman coding on the corner detection model after quantization processing.

[0112] 103. Draw a polygon in the image to be recognized according to the obtained multiple corner points.

[0113] There are many ways to draw a polygon in the image to be recognized based on the obtained multiple corner points. For example, the specific method is as follows:

[0114] First way:

[0115] Determine the current corner point, and determine the adjacent points of the current corner point in a preset direction, draw connecting lines between the current corner point and the adjacent points as the sides of the polygon, and return to execute the step of determining the current corner point until all corner points are traversed.

[0116] The preset direction may be determined according to actual application requirements, for example, it may be set to a clockwise direction or a counterclockwise direction, and so on.

[0117] Second way:

[0118] Draw connecting lines between each corner point, and select the largest closed area from the closed areas formed by the connecting lines to obtain a polygon.

[0119] Of course, other drawing methods may also be used, which will not be described in detail here.

[0120] Optionally, in addition to drawing a polygon based on these corner points, multiple polygons can also be drawn, and the multiple polygons drawn can be the same as or different from each other.

[0121] For example, these corner points can be grouped according to a preset strategy, such as grouping them according to the envelope boxes to which they belong (that is, the corner points belonging to the same envelope box are grouped into the same group) to obtain multiple corner point groups, and then, polygons are drawn in the image to be identified according to the corner points in each corner point group to obtain multiple polygons.

[0122] The corner points used when drawing a polygon are the vertices of the polygon. The drawn polygon may be a triangle, a quadrilateral, a pentagon or a hexagon, etc., which will not be described in detail here.

[0123] 104. Recognize the text information in the polygon to obtain a recognition result.

[0124] For example, a text recognition algorithm may be used to recognize text information in the polygon to obtain a recognition result.

[0125] The text recognition algorithm may be determined according to the needs of the actual application. For example, OCR may be used to recognize the text information in the polygon to obtain a recognition result, and so on.

[0126] As can be seen from the above, after acquiring the image to be identified containing text information, this embodiment can detect the vertices of the area where the text information is located to obtain multiple corner points, and then draw a polygon in the image to be identified based on the obtained multiple corner points, and identify the text information in the polygon to obtain a recognition result; since the scheme can draw polygons based on corner points and determine the text area to be identified based on this, therefore, compared with the existing scheme that can only determine the text area from the image to be identified through a standard rectangular frame, the polygon obtained by this scheme can be more consistent with the text area even when the inclination level or distortion of the text area to be identified is large (such as a large degree of perspective or affine transformation), which greatly improves the recognition effect when the text area to be identified is not standardized; moreover, since the scheme is not limited by the inclination level or distortion size, it can be applied to various scenarios, and its flexibility and applicability are also improved compared with the existing scheme.

[0127] The method described in the above embodiments is further described in detail below with examples.

[0128] In this embodiment, the text recognition device is specifically integrated into an electronic device as an example for description.

[0129] (a) Training of corner detection model;

[0130] like Figure 3 , 4 , 5, 6 and 8, the corner detection model may include a residual module, each residual module may include a main branch and a side branch, the main branch is a fire module, the fire module may include a compression layer and an expansion layer, the convolution kernel of the compression layer may be set to 1×1 (i.e., Squeeze 1×1), and the convolution kernel of the expansion layer may be set to 1×1 (i.e., Expand 1×1) and 3×3 (i.e., Expand 3×3), in addition, the compression layer and the expansion layer both use Relu as the activation function, for details, please refer to the previous embodiment, which will not be described here. Among them, the training process of the corner detection model may be specifically as follows:

[0131] First, the electronic device can capture multiple images, such as obtaining multiple images containing text information from a gallery or the Internet, such as images obtained after capturing business cards, invoices, or sticky notes, and then preprocessing these images, such as performing operations such as deduplication, cropping, rotation, and / or flipping. Then, in these preprocessed images, the corner points of the area where the text information is located (i.e., the text area) are marked, and multiple image samples with the corner points of the text area marked are obtained.

[0132] Secondly, see Figure 8The electronic device can input the image sample into the preset corner detection model, and after being processed by the convolution layer 1 (Conv1) and the activation layer (Relu_conv1) in sequence, the pooling layer 1 performs pooling processing on the processed data, and then the pooled data is input into the fire module 2 (fire2), and the compression layer of the fire module 2 performs channel compression and dimensionality reduction operations on the pooled data to obtain a compressed result, and then, the expansion layer of the fire module 2 is used to extract features of different scales on the compressed result, and the extracted features are fused with the input of the fire module 2 (i.e., the pooled data), so as to obtain the output of the fire module 2, that is, the feature map output by the fire module 2.

[0133] Similarly, the feature map output by the fire module 2 is used as the input of the fire module 3, and the compression layer of the fire module 3 performs channel compression and dimensionality reduction operations on the feature map output by the fire module 2 to obtain a compressed result. Then, the expansion layer of the fire module 3 is used to extract features of different scales on the compressed result, and the extracted features are fused with the input of the fire module 3 (i.e., the feature map output by the fire module 2) to obtain the output of the fire module 3 - the feature map output by the fire module 3; and by analogy, the feature map output by the fire module 3 is used as the input of the fire module 4 and continues to be processed until the output of the fire module 9 is fused with the input of the fire module 9 to obtain the feature map output by the fire module 9.

[0134] After that, the feature map output by the fire fighting module 9 can be processed by the network layers such as the convolution layer 10 (Conv10), the activation layer (Relu_conv10), the pooling layer 10 and the activation function (softmax) to filter out the pixel points whose pixel types are consistent with the pixel types of the area where the text information is located. The area where these pixel points are located is the prediction area. Finally, the vertices of the envelope of the prediction area are determined to obtain the corner points of the prediction area; for example, see Figure 7 , if the prediction region envelope is a quadrilateral "abcd", then the prediction region corner points are the four vertices of the quadrilateral "abcd": a, b, c and d.

[0135] Furthermore, after obtaining the corner points of the predicted area, the electronic device can converge the corner point detection model according to the corner points of the predicted area and the marked text area corner points to obtain a trained corner point detection model.

[0136] For example, the electronic device can determine the corner point that needs to be processed currently from the corner points of the marked text area, and obtain the current marked corner point, such as Figure 7Then, the distance between the current annotation corner point and each prediction region corner point is calculated, and the prediction region corner point with the shortest distance is selected as the target corner point of the current annotation corner point, and the current annotation corner point and the target corner point are taken as a pair of corner point pairs. Figure 7 The distance between the prediction area corner points "a" and "m" is the shortest, so "a" and "m" can be used as a corner point pair; thereafter, the corner point currently to be processed can be updated to the next text area corner point (i.e., return to execute the step of determining the corner point currently to be processed from the annotated text area corner points), such as "n", and find the prediction area corner point that can be used as a corner point pair with "n" according to the above method, and so on, until all the annotated text area corner points are found with which the prediction area corner points can be established as corner point pairs; thereafter, the loss function can be constructed with these corner point pairs, for example, the loss function can be specifically as follows:

[0137]

[0138] Among them, G m is the corner point of the marked text area, G mx and G my The corner points G m The horizontal and vertical coordinates of P a is the corner point of the prediction area, P ax and P ay They are corner points P a The horizontal and vertical coordinates of .

[0139] Finally, the electronic device can use the loss function to converge the corner point detection model. For example, the loss function can be used to adjust the network parameters of the corner point detection model so that the current labeled corner point in the corner point pair is displaced toward the target corner point, such as displacing m toward the target corner point a and getting as close to a as possible. Figure 7 When the distance between m and a is minimized, it indicates that the adjustment of network parameters is completed. When the distance between all labeled corner points and their target corner points is minimized, it indicates that the training of the corner detection model is completed.

[0140] By analogy, after training the corner detection model multiple times with a large number of image samples, a trained corner detection model can be obtained.

[0141] Optionally, in order to make the size of the corner detection model after training smaller to save computing resources and improve computing speed, the size of the corner detection model after training can also be compressed. For example, the corner detection model after training can be pruned, the pruned corner detection model can be quantized, and the quantized corner detection model can be Huffman encoded to obtain a compressed corner detection model. For details, please refer to the previous embodiment, which will not be repeated here.

[0142] (ii) Through the trained corner point detection model, text recognition can be performed on the image to be recognized.

[0143] For example, Fig. 9 As shown, the specific process of the text recognition method can be as follows:

[0144] 201. An electronic device obtains an image to be recognized, where the image to be recognized contains text information.

[0145] For example, the electronic device can call a camera process, and through the camera process, start its own camera to shoot the object to be identified, such as a courier bill, invoice, card, business card, or note paper, to obtain an image to be identified.

[0146] For another example, other devices may capture images of objects to be identified, such as invoices, cards, business cards, or sticky notes, and provide the captured images as images to be identified to the electronic device, and so on.

[0147] Optionally, in order to better identify the image to be identified, the collected image may be preprocessed, such as rotating, flipping and / or cropping, and then the processed image is used as the image to be identified, which will not be elaborated here.

[0148] 202. The electronic device uses the trained corner point detection model (or the compressed corner point detection model) to identify the area where the text information is located in the image to be identified, and obtains the text area.

[0149] For example, the electronic device performs channel compression and dimensionality reduction operations on the image to be identified through the compression layer of the fire protection module in the trained corner point detection model (or compressed corner point detection model) to obtain a compressed result, and then uses the expansion layer of the fire protection module to extract features of different scales on the compressed result to obtain a feature map. Similarly, after being processed by multiple fire protection modules, based on the feature map of the last fire protection module, pixel points whose pixel types are consistent with the pixel types of the area where the text information is located are screened out to obtain the text area.

[0150] For example, see Fig.10After collecting the image of the business card to obtain the image to be recognized, the image to be recognized can be imported into the trained corner point detection model for detection to determine the area where the text information in the "business card" image is located, and the following is obtained: Fig.10 The text area shown (the part filled with diagonal lines).

[0151] For example, see Fig.11 After collecting the image of the sticky note to obtain the image to be recognized, the image to be recognized can be imported into the trained corner point detection model for detection to determine the area where the text information in the "sticky note" image, such as "I'm going out for a while. There is tortoise jelly in the refrigerator when I come back later^^", can be obtained. Fig.11 The text area shown (the part filled with diagonal lines), and so on.

[0152] Optionally, the text area can also be multiple, for example, Fig.12 As shown, in the scenario of "reimbursement of mixed invoices", after image acquisition of these invoices to obtain images to be recognized, the images to be recognized can be imported into the trained corner point detection model for detection to determine the area where the invoice (that is, text information, because the invoice contains text information) is located. Since there are multiple invoices, multiple text areas can be obtained.

[0153] 203. The electronic device determines the vertices of the text area envelope by using a trained corner point detection model (or a compressed corner point detection model) to obtain a plurality of corner points.

[0154] For example, see Fig.10 , if the text area envelope is a quadrilateral, the corner points are the four vertices of the quadrilateral: A1, B1, C1 and D1.

[0155] For example, see Fig.11 , if the text area envelope is a hexagon, the corner points are the four vertices of the hexagon: A2, B2, C2, D2, E2 and F2.

[0156] Optionally, if there are multiple text regions, multiple sets of corner points can also be obtained. For example, see Fig.12 , since there are three text areas, three sets of corner points can be obtained in the end, as follows:

[0157] For the first text area, the corresponding corner points are: A3, B3, C3 and D3. Therefore, A3, B3, C3 and D3 can be used as the first group of corner points.

[0158] For the second text area, the corresponding corner points are: A4, B4, C4 and D4. Therefore, A4, B4, C4 and D4 can be used as the second group of corner points.

[0159] For the third text area, the corresponding corner points are: A5, B5, C5 and D5. Therefore, A5, B5, C5 and D5 can be used as the third group of corner points.

[0160] 204. The electronic device draws a polygon in the image to be identified according to the obtained multiple corner points by using the trained corner point detection model (or compressed corner point detection model).

[0161] For example, Fig.10 For example, the electronic device can determine the current corner point "A1", and select the corner point closest to A1 in the preset direction as the adjacent point of "A1". For example, since "A1" and "B1" are closest in the clockwise direction, "B1" can be used as the adjacent point of the current corner point "A1". Then, a connecting line is drawn between the current corner point "A1" and the adjacent point "B1" as the side of the polygon; thereafter, the current corner point is updated to "B1". Since "B1" and "C1" are closest in the clockwise direction, "C1" can be used as the adjacent point of the current corner point "B1", and a connecting line is drawn between "B1" and "C1", and so on, until all corner points are traversed, the polygon "A1B1C1D1" can be obtained.

[0162] The other corner points closest to the current corner point can be determined by calculating the distance between the current corner point and other corner points in the preset direction. The shorter the distance, the closer it is. The distance here refers to the length of the "text area envelope" between the current corner point and other corner points. For example, Fig.10 The distance between the midpoints "A1" and "B1" is the line segment "A1B1", and the distance between "A1" and "C1" is the sum of the line segment "A1B1" and the line segment "B1C1", and so on, which will not be elaborated here.

[0163] For another example, in addition to the above-mentioned method of drawing a polygon, other methods may also be used. For example, connecting lines may be drawn between corner points, and then the largest closed area may be selected from the closed areas formed by the connecting lines to obtain the polygon, and so on.

[0164] Optionally, if there are multiple sets of corner points, a polygon can be drawn based on each set of corner points, for example Fig.12As shown, if in step 203, three groups of corner points are obtained: (A3, B3, C3, D3), (A4, B4, C4, D4) and (A5, B5, C5, D5), then at this time, the electronic device can draw the polygon "A3B3C3D3" based on (A3, B3, C3, D3), draw the polygon "A4B4C4D4" based on (A4, B4, C4, D4), and draw another polygon "A5B5C5D5" based on (A5, B5, C5, D5).

[0165] 205. The electronic device recognizes the text information in the polygon using a text recognition algorithm to obtain a recognition result.

[0166] The text recognition algorithm may be determined according to the needs of the actual application. For example, the electronic device may specifically use OCR to recognize the text information in the polygon to obtain a recognition result, and so on.

[0167] For example, Fig.10 As shown, the text information in the business card can now be recognized, such as the company name is "tence", the name is "Li Si", the department is "Intellectual Property Department", and so on.

[0168] For example, Fig.11 As shown, the text information in the note can now be recognized, such as "I'm going out for a while. There's tortoise jelly in the refrigerator when I come back later, hehe^^", etc.

[0169] As can be seen from the above, after acquiring an image to be recognized containing text information, this embodiment can detect the area where the text information in the image to be recognized is located through the trained corner point detection model, and determine the vertices of the area where the text information is located to obtain multiple corner points, and then draw a polygon in the image to be recognized based on the obtained multiple corner points, and use the text recognition algorithm to recognize the text information in the polygon to obtain a recognition result; since the scheme can draw a polygon based on the corner points, and determine the text area to be recognized based on this, therefore, compared with the existing scheme that can only determine the text area from the image to be recognized through a standard rectangular frame, the polygon obtained by the scheme can be more consistent with the text area even when the inclination level or distortion of the text area to be recognized is large (such as a large degree of perspective or affine transformation), which greatly improves the recognition effect when the text area to be recognized is not standardized; and since the scheme is not limited by the inclination level or distortion size, it can be applied to various scenarios, and its flexibility and applicability are also improved compared with the existing scheme.

[0170] In addition, since the trained corner point model adopts a residual structure and its main branch is a fire protection module, it can not only propagate low-level features to high-level feature maps, so that the corner point detection model can directly learn corner point and edge characteristics and improve the accuracy of corner point detection, but also reduce the dimension of model input, so that the trained corner point detection model is suitable for images to be identified of various scales (that is, there is no need to set a unified standard for the input image to be identified, such as setting a unified size, etc.), greatly improving its flexibility.

[0171] In addition, since this embodiment can also compress the trained corner point detection model, it can also improve the model processing efficiency and make the model size smaller, so that in addition to being suitable for servers, it can also be better suitable for mobile terminals, thereby improving its applicability.

[0172] In order to better implement the above method, an embodiment of the present application also provides a text recognition device, which can be integrated into an electronic device, such as a server or a terminal, and the terminal may include a mobile phone, a tablet computer, a laptop computer and / or a personal computer, etc.

[0173] like Fig.13 As shown, the text recognition device may include an acquisition unit 301, a detection unit 302, a drawing unit 303 and a recognition unit 304, as follows:

[0174] (1) Acquisition unit 301;

[0175] The acquisition unit 301 is used to acquire an image to be recognized, where the image to be recognized contains text information.

[0176] For example, the acquisition unit 301 can be specifically used to acquire the image to be identified by photographing or scanning the object to be identified, such as invoices, cards, business cards, memos, notebooks, and documents, through its own imaging component such as a camera.

[0177] Alternatively, the acquisition unit 301 may be specifically configured to receive an image to be recognized sent by other devices.

[0178] Optionally, in order to improve the accuracy of detection, the collected image may be preprocessed, such as rotating, flipping and / or cropping, and then the processed image is used as the image to be identified. That is:

[0179] The acquisition unit 301 may also be used to pre-process the acquired image and then use the processed image as the image to be recognized.

[0180] (2) a detection unit 302;

[0181] The detection unit 302 is used to detect vertices of the area where the text information is located to obtain multiple corner points.

[0182] For example, the detection unit 302 may include a region recognition subunit and a corner point determination subunit, as follows:

[0183] The region recognition subunit is used to use the trained corner point detection model to identify the region where the text information is located in the image to be recognized, so as to obtain the text region.

[0184] For example, the region recognition subunit can be specifically used to extract features of the image to be recognized using the trained corner point detection model to obtain a feature map, and based on the feature map, screen pixels whose pixel types match the pixel types of the region where the text information is located to obtain the text region.

[0185] The corner point determination subunit is used to determine the vertices of the text area envelope to obtain multiple corner points.

[0186] The trained corner detection model can be trained by a plurality of image samples with corner points of text regions marked. The trained corner detection model includes a plurality of residual modules, each of which may include a main branch and a side branch. The main branch of the residual module is a fire module, and the output of the main branch needs to be fused with the output of the side branch to obtain the output of the residual module. For details, please refer to the previous method embodiment, which will not be described in detail here.

[0187] Among them, the fire fighting module can include a compression layer and an expansion layer. For example, the convolution kernel of the compression layer is 1×1, and the convolution kernel of the expansion layer can be set to two types: 1×1 and 3×3, namely:

[0188] The region recognition subunit can be specifically used to perform channel compression and dimensionality reduction operations on the image to be identified through the compression layer of the fire protection module to obtain a compressed result, and use the expansion layer of the fire protection module to perform feature extraction of different scales on the compressed result to obtain a feature map.

[0189] (3) drawing unit 303;

[0190] The drawing unit 303 is used to draw a polygon in the image to be recognized according to the obtained multiple corner points.

[0191] For example, the drawing unit 303 can be specifically used to determine the current corner point and the adjacent points of the current corner point in a preset direction, draw a connecting line between the current corner point and the adjacent points as the edge of the polygon, and return to execute the step of determining the current corner point until all corner points are traversed.

[0192] The preset direction may be determined according to actual application requirements, for example, it may be set to a clockwise direction or a counterclockwise direction, and so on.

[0193] For another example, the drawing unit 303 may be specifically configured to draw connecting lines between various corner points, and select a closed area with the largest area from the closed areas formed by the connecting lines to obtain a polygon.

[0194] Optionally, the drawing unit 303 may draw multiple polygons in addition to drawing one polygon according to the corner points. The multiple polygons may be the same as or different from each other.

[0195] For example, the drawing unit 303 can be specifically used to group the multiple corner points according to a preset strategy to obtain multiple corner point groups, and then draw polygons in the image to be identified according to the corner points in each corner point group to obtain multiple polygons.

[0196] The corner points used when drawing a polygon are the vertices of the polygon. The drawn polygon may be a triangle, a quadrilateral, a pentagon or a hexagon, etc., which will not be described in detail here.

[0197] (4) identification unit 304;

[0198] The recognition unit 304 is used to recognize the text information in the polygon using a text recognition algorithm to obtain a recognition result.

[0199] The text recognition algorithm may be determined according to the requirements of the actual application. For example, the recognition unit 304 may be used to recognize the text information in the polygon using OCR to obtain a recognition result, and so on.

[0200] Optionally, the trained corner point detection model can be pre-trained by other devices and saved in the text recognition device, or can be trained by the text recognition device itself, that is, Fig.14 As shown, the text recognition device may further include a collection unit 305 and a training unit 306, as follows:

[0201] The acquisition unit 305 is used to acquire a plurality of image samples with text area corner points marked thereon.

[0202] For example, the acquisition unit 305 can be used to obtain multiple images from a gallery, or can also acquire multiple images through its own imaging components such as a camera, and then mark the corner points of the text areas in these images, and use the marked images as image samples.

[0203] Optionally, in order to improve the quality of training samples, before labeling, the acquisition unit 305 may also preprocess the images such as deduplication, rotation, flipping and / or cropping, and then label the preprocessed images to obtain image samples.

[0204] The training unit 306 is used to use a corner point detection model to identify the area where the text information is located in the image sample, obtain a predicted area, determine the vertices of the prediction area envelope, obtain the prediction area corner points, and converge the corner point detection model based on the prediction area corner points and the marked text area corner points to obtain a trained corner point detection model.

[0205] For example, the training unit 306 can be used to construct a loss function based on the distance between the corner points of the prediction area and the corner points of the marked text area, and use the loss function to converge the corner point detection model to obtain a trained corner point detection model. For example, the convergence method can be as follows:

[0206] The training unit 306 can be specifically used to determine the corner point that currently needs to be processed from the annotated text area corner points, obtain the current annotated corner point, calculate the distance between the current annotated corner point and each predicted area corner point, select the predicted area corner point with the shortest distance as the target corner point of the current annotated corner point, use the current annotated corner point and the target corner point as a pair of corner point pairs, and return to execute the step of determining the corner point that currently needs to be processed from the annotated text area corner points until all the annotated text area corner points are processed, and construct a loss function based on all the obtained corner point pairs; use the loss function to adjust the network parameters of the corner point detection model so that the current annotated corner point in the corner point pair is displaced toward the target corner point to reduce the distance between the current annotated corner point and the target corner point in the corner point pair.

[0207] Among them, the loss function can be specifically as follows:

[0208]

[0209] Among them, G m is the corner point of the marked text area, G mx and G my The corner points G m The horizontal and vertical coordinates of P a is the corner point of the prediction area, P ax and P ay They are corner points P a The horizontal and vertical coordinates of .

[0210] Optionally, in order to make the size of the trained corner detection model smaller, to save computing resources and to improve computing speed, the trained corner detection model may be compressed. Fig.15 As shown, the text recognition device may further include a compression unit 307, as follows:

[0211] The compression unit 307 may be used to compress the trained corner detection model using a neural network compression algorithm to obtain a compressed corner detection model;

[0212] At this time, the recognition unit 304 can be specifically used to use the compressed corner point detection model to recognize the area where the text information is located in the image to be recognized, so as to obtain the text area.

[0213] Among them, the neural network compression algorithm can be determined according to the needs of the actual application, and the compression method can include operations such as pruning, quantization and Huffman coding, namely:

[0214] The compression unit 304 can be specifically used to prune the trained corner detection model, quantize the pruned corner detection model, and perform Huffman coding on the quantized corner detection model to obtain a compressed corner detection model.

[0215] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.

[0216] As can be seen from the above, after acquiring the image to be recognized containing text information, the detection unit 302 of this embodiment can detect the vertices of the area where the text information is located to obtain multiple corner points, and then the drawing unit 303 draws a polygon in the image to be recognized based on the obtained multiple corner points, and the recognition unit 304 recognizes the text information in the polygon to obtain a recognition result; since the scheme can draw polygons based on corner points and determine the text area to be recognized based on this, therefore, compared with the existing scheme that can only determine the text area from the image to be recognized by a standard rectangular frame, the polygon obtained by this scheme can be more consistent with the text area even when the inclination level or distortion of the text area to be recognized is large (such as a large degree of perspective or affine transformation), which greatly improves the recognition effect when the text area to be recognized is not standardized; and since the scheme is not limited by the inclination level or distortion size, it can be applied to various scenarios, and its flexibility and applicability are also improved compared with the existing scheme.

[0217] In addition, since the trained corner point model adopts a residual structure and its main branch is a fire module, it can not only propagate low-level features to high-level feature maps, so that the corner point detection model can directly learn corner point and edge characteristics, improve the accuracy of corner point detection, but also reduce the dimension of model input, so that the trained corner point detection model is applicable to images to be identified at various scales, greatly improving its flexibility. Furthermore, since the compression unit 307 of this embodiment can also compress the trained corner point detection model, it can also improve the model processing efficiency and make the model size smaller, so that in addition to being applicable to servers, it can also be better applicable to mobile terminals, improving its applicability.

[0218] The present application also provides an electronic device that can integrate any text recognition device provided in the present application. Fig.16 As shown, it shows a schematic diagram of the structure of the electronic device involved in the embodiment of the present application, specifically:

[0219] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that Fig.16 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0220] The processor 401 is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, the processor 401 performs various functions of the electronic device and processes data, thereby performing overall detection of the electronic device. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.

[0221] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0222] The electronic device also includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply 403 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.

[0223] The electronic device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0224] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby realizing various functions, as follows:

[0225] An image to be identified containing text information is obtained, vertices of the area where the text information is located are detected to obtain multiple corner points, a polygon is drawn in the image to be identified based on the multiple corner points obtained, and a text recognition algorithm is used to recognize the text information in the polygon to obtain a recognition result.

[0226] For example, the trained corner point detection model can be used to identify the area where the text information is located in the image to be identified, obtain the text area, determine the vertices of the envelope of the text area, and obtain multiple corner points.

[0227] Optionally, the trained corner point detection model may be pre-trained by other devices and saved in the text recognition device, or may be trained by the text recognition device itself, that is, the processor 401 may also run an application stored in the memory 402, thereby realizing the following functions:

[0228] Collect multiple image samples with marked text area corner points, use the corner point detection model to identify the area where the text information is located in the image sample, obtain the prediction area, determine the vertices of the prediction area envelope, obtain the prediction area corner points, and converge the corner point detection model according to the prediction area corner points and the marked text area corner points to obtain the trained corner point detection model.

[0229] Optionally, in order to make the size of the trained corner detection model smaller, to save computing resources, and to improve computing speed, the trained corner detection model may be compressed in size; that is, the processor 401 may also run an application stored in the memory 402, thereby realizing the following functions:

[0230] A neural network compression algorithm is used to compress the trained corner detection model to obtain a compressed corner detection model.

[0231] Among them, compression methods may include operations such as pruning, quantization, and Huffman coding.

[0232] The specific implementation of the above operations can be found in the previous embodiments and will not be described in detail here.

[0233] As can be seen from the above, after the electronic device of this embodiment obtains the image to be recognized containing text information, it can detect the vertices of the area where the text information is located, obtain multiple corner points, and then draw a polygon in the image to be recognized based on the obtained multiple corner points, and recognize the text information in the polygon to obtain a recognition result; since the scheme can draw polygons based on corner points and determine the text area to be recognized based on this, therefore, compared with the existing scheme that can only determine the text area from the image to be recognized through a standard rectangular frame, the polygon obtained by this scheme can be more consistent with the text area even when the inclination level or distortion of the text area to be recognized is large (such as a large degree of perspective or affine transformation), which greatly improves the recognition effect when the text area to be recognized is not standardized; moreover, since the scheme is not limited by the inclination level or distortion size, it can be applied to various scenarios, and its flexibility and applicability are also improved compared with the existing scheme.

[0234] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0235] To this end, an embodiment of the present application provides a storage medium in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any text recognition method provided in the embodiment of the present application. For example, the instructions can execute the following steps:

[0236] An image to be identified containing text information is obtained, vertices of the area where the text information is located are detected to obtain multiple corner points, a polygon is drawn in the image to be identified based on the multiple corner points obtained, and a text recognition algorithm is used to recognize the text information in the polygon to obtain a recognition result.

[0237] For example, the trained corner point detection model can be used to identify the area where the text information is located in the image to be identified, obtain the text area, determine the vertices of the envelope of the text area, and obtain multiple corner points.

[0238] Optionally, the trained corner point detection model may be pre-trained by other devices and saved in the text recognition device, or may be trained by the text recognition device itself, that is, the instruction may further execute the following steps:

[0239] Collect multiple image samples with marked text area corner points, use the corner point detection model to identify the area where the text information is located in the image sample, obtain the prediction area, determine the vertices of the prediction area envelope, obtain the prediction area corner points, and converge the corner point detection model according to the prediction area corner points and the marked text area corner points to obtain the trained corner point detection model.

[0240] Optionally, in order to make the size of the trained corner detection model smaller to save computing resources and improve computing speed, the size of the trained corner detection model can also be compressed; that is, the instruction can also execute the following steps:

[0241] A neural network compression algorithm is used to compress the trained corner detection model to obtain a compressed corner detection model.

[0242] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0243] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0244] Since the instructions stored in the storage medium can execute the steps in any text recognition method provided in the embodiments of the present application, the beneficial effects that can be achieved by any text recognition method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0245] The above is a detailed introduction to a text recognition method, device, electronic device and storage medium provided in the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the ideas of the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A text recognition method, characterized in that: include: Acquire an image to be identified, wherein the image to be identified contains text information; Detecting vertices of the area where the text information is located to obtain multiple corner points; The detecting of the vertices of the region where the text information is located to obtain a plurality of corner points includes: using a trained corner point detection model to identify the region where the text information is located in the image to be identified to obtain a text region; determining the vertices of the envelope of the text region to obtain a plurality of corner points; The step of using the trained corner point detection model to identify the region where the text information is located in the image to be identified to obtain the text region includes: Utilize the compression layer of the fire module to perform channel compression and dimensionality reduction operations on the image to be identified to obtain a compressed result; utilize the expansion layer of the fire module to perform feature extraction of different scales on the compressed result to obtain a feature map; input the feature map into a new fire module, and execute in the new fire module: step "utilize the compression layer of the fire module to perform channel compression and dimensionality reduction operations on the image to be identified to obtain a compressed result; utilize the expansion layer of the fire module to perform feature extraction of different scales on the compressed result to obtain a feature map; input the feature map into a new fire module" until after being processed by multiple fire modules, a feature map of the last fire module among the multiple fire modules is obtained; based on the feature map of the last fire module, filter out pixel points whose pixel types conform to the pixel types of the area where the text information is located, thereby obtaining a text area; Drawing a polygon in the image to be recognized according to the obtained multiple corner points; Wherein, drawing a polygon in the image to be recognized according to the obtained multiple corner points includes: Determine a current corner point, and determine adjacent points of the current corner point in a preset direction; Draw a connecting line between the current corner point and the adjacent point as the edge of the polygon; and use the adjacent point as the new current corner point, and return to execute the step of determining the current corner point until all corner points are traversed; The text information in the polygon is recognized to obtain a recognition result.

2. The method according to claim 1, characterized in that The method of using the trained corner point detection model to identify the region where the text information is located in the image to be identified to obtain the text region includes: Using the trained corner point detection model to extract features from the image to be identified, to obtain a feature map; Based on the feature map, pixel points whose pixel types match the pixel types of the region where the text information is located are screened to obtain the text region.

3. The method according to claim 2, characterized in that The trained corner point detection model includes a residual module, the main branch of the residual module is a fire protection module, and the trained corner point detection model is used to extract features of the image to be identified to obtain a feature map, including: Perform channel compression and dimensionality reduction operations on the image to be identified through the compression layer of the fire module to obtain a compressed result; The expansion layer of the fire protection module is used to extract features of different scales from the compressed result to obtain a feature map.

4. The method according to any one of claims 2 to 3, characterized in that: The method further comprises: using the trained corner point detection model to identify the region where the text information is located in the image to be identified, and obtaining the text region. Collect multiple image samples with corner points of text areas marked; Using a corner detection model to identify the area where the text information is located in the image sample to obtain a predicted area; Determine the vertices of the prediction region envelope to obtain the prediction region corner points; The corner point detection model is converged according to the predicted area corner points and the marked text area corner points to obtain a trained corner point detection model.

5. The method according to claim 4, characterized in that The step of converging the corner point detection model according to the predicted area corner points and the marked text area corner points to obtain a trained corner point detection model includes: Construct a loss function based on the distance between the corner points of the predicted area and the corner points of the annotated text area; The corner detection model is converged by using the loss function to obtain a trained corner detection model.

6. The method according to claim 5, characterized in that The step of constructing a loss function based on the distance between the corner points of the prediction region and the corner points of the marked text region includes: Determine the corner point that needs to be processed currently from the corner points of the annotated text area, and obtain the current annotated corner point; Calculating the distance between the current marked corner point and each predicted area corner point; Select the corner point of the predicted area with the shortest distance as the target corner point of the current annotation corner point; The currently marked corner point and the target corner point are taken as a pair of corner point pairs, and the step of determining the corner point currently to be processed from the marked text area corner points is returned to be executed until all the marked text area corner points are processed; Construct a loss function based on all the corner point pairs obtained; The method of using the loss function to converge the corner point detection model includes: using the loss function to adjust the network parameters of the corner point detection model so that the current labeled corner point in the corner point pair is displaced toward the target corner point to reduce the distance between the current labeled corner point in the corner point pair and the target corner point.

7. The method according to claim 4, characterized in that After the corner point detection model is converged according to the predicted area corner points and the marked text area corner points to obtain a trained corner point detection model, the method further includes: Using a neural network compression algorithm to compress the trained corner point detection model to obtain a compressed corner point detection model; The method of using the trained corner point detection model to identify the area where the text information is located in the image to be identified to obtain the text area includes: using the compressed corner point detection model to identify the area where the text information is located in the image to be identified to obtain the text area.

8. The method according to claim 7, characterized in that The method of compressing the trained corner point detection model using a neural network compression algorithm to obtain a compressed corner point detection model includes: Pruning the trained corner detection model; Quantize the pruned corner detection model; The quantized corner detection model is subjected to Huffman coding to obtain a compressed corner detection model.

9. The method according to any one of claims 1 to 3, characterized in that: Drawing a polygon in the image to be recognized according to the obtained multiple corner points includes: Draw connecting lines between the corner points; Select the closed area with the largest area from the closed areas formed by the connected lines to obtain a polygon.

10. A text recognition device, characterized in that: include: An acquisition unit, used for acquiring an image to be recognized, wherein the image to be recognized contains text information; A detection unit is used to detect the vertices of the area where the text information is located to obtain a plurality of corner points; the detection unit is specifically used to: use the trained corner point detection model to identify the area where the text information is located in the image to be identified to obtain a text area; determine the vertices of the envelope of the text area to obtain a plurality of corner points; The step of using the trained corner point detection model to identify the region where the text information is located in the image to be identified to obtain the text region includes: Utilize the compression layer of the fire module to perform channel compression and dimensionality reduction operations on the image to be identified to obtain a compressed result; utilize the expansion layer of the fire module to perform feature extraction of different scales on the compressed result to obtain a feature map; input the feature map into a new fire module, and execute in the new fire module: step "utilize the compression layer of the fire module to perform channel compression and dimensionality reduction operations on the image to be identified to obtain a compressed result; utilize the expansion layer of the fire module to perform feature extraction of different scales on the compressed result to obtain a feature map; input the feature map into a new fire module" until after being processed by multiple fire modules, a feature map of the last fire module among the multiple fire modules is obtained; based on the feature map of the last fire module, filter out pixel points whose pixel types conform to the pixel types of the area where the text information is located, thereby obtaining a text area; A drawing unit, used for drawing a polygon in the image to be identified according to the obtained multiple corner points; the drawing unit is specifically used for determining a current corner point, and determining adjacent points of the current corner point in a preset direction; drawing a connecting line between the current corner point and the adjacent points as the sides of the polygon; and using the adjacent points as new current corner points, returning to execute the step of determining the current corner point until all corner points are traversed; The recognition unit is used to recognize the text information in the polygon and obtain a recognition result.

11. The device according to claim 10, characterized in that The detection unit includes a region recognition subunit and a corner point determination subunit; The region recognition subunit is used to use the trained corner point detection model to recognize the region where the text information is located in the image to be recognized, so as to obtain the text region; The corner point determination subunit is used to determine the vertices of the text area envelope to obtain a plurality of corner points.

12. An electronic device, characterized in that: It comprises a memory and a processor; the memory stores an application program, and the processor is used to run the application program in the memory to perform the operations in the text recognition method according to any one of claims 1 to 9.

13. A storage medium, characterized in that: The storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the text recognition method according to any one of claims 1 to 9.