Text feature recognition method, device, computer equipment and storage medium

Through the OCR recognition model and image processing technology, the minimum external matrix of the text and the foreground color projection value are calculated, and the watershed algorithm is used to identify the character position in the image, which solves the problem of inaccurate character position recognition in the existing technology and achieves character-level accuracy. Positioning and matching.

CN114387600BActive Publication Date: 2024-09-20CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210058236.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-19
Publication Date
2024-09-20
Estimated Expiration
2042-01-19

AI Technical Summary

Technical Problem

Existing OCR technology is not accurate enough in character position recognition and cannot effectively identify character positions in images.

Method used

The image to be recognized is processed through the OCR recognition model, grayscaled and binarized, the text's minimum circumscribed matrix and the foreground color projection value are calculated, the watershed algorithm is used to obtain the segmentation point, and the text within the text's minimum circumscribed matrix is ​​processed from left to right. The information is identified, and the matching text information and position are determined by matching the smallest unit of characters.

Benefits of technology

It achieves accurate recognition of character positions in images, improves the matching and positioning accuracy of text information, and supports users to search and display matching words in images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114387600B
    Figure CN114387600B
Patent Text Reader

Abstract

The present application discloses a text feature recognition method, device, computer equipment and storage medium. The text feature recognition method comprises: using an OCR recognition model to process an image to be recognized to obtain a text box area and a text string; graying the text box area to obtain a grayscale image; using a binarization algorithm to process the grayscale image to obtain a binary image; calculating the text minimum circumscribed matrix according to the binary image; calculating the foreground color projection value of the binary image in the horizontal direction according to the binary image; using a watershed algorithm to obtain a segmentation point according to the foreground color projection value of the binary image in the horizontal direction; using an OCR recognition model to recognize text information in the text minimum circumscribed matrix from left to right according to the segmentation point and the text string, and determining the matching text information in a matching method with the smallest unit as a character; and determining the position of each character in the text minimum circumscribed matrix according to the matching text information. The text feature recognition method can accurately identify the character position in the image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a text feature recognition method, device, computer equipment and storage medium. Background Art

[0002] With the development of deep learning, OCR (Optical Character Recognition) technology has become more and more mature, and the recognition effect and efficiency have been greatly improved. Many service providers can already provide image text detection and recognition services. However, the existing OCR technology is mostly implemented by inputting pictures, then detecting the entire text box and recognizing the string, lacking accurate recognition of the character position. Summary of the invention

[0003] In view of this, embodiments of the present application provide a text feature recognition method, apparatus, computer device and storage medium to solve the problem of inaccurate character position recognition.

[0004] In a first aspect, an embodiment of the present application provides a text feature recognition method, the method comprising:

[0005] Use the OCR recognition model to process the image to be recognized and obtain the text box area and text string;

[0006] Grayscale the text box area to obtain a grayscale image;

[0007] Processing the grayscale image using a binarization algorithm to obtain a binary image;

[0008] Calculate the text minimum circumscribed matrix according to the binary graph;

[0009] Calculate the foreground color projection value of the binary image in the horizontal direction according to the binary image;

[0010] According to the foreground color projection value in the horizontal direction of the binary image, a segmentation point is obtained by using a watershed algorithm;

[0011] According to the segmentation point and the text string, the OCR recognition model is used to recognize the text information in the text minimum circumscribed matrix from left to right, and the matching text information is determined in a matching manner in which the smallest unit is a character;

[0012] The position of each character in the text minimum circumscribed matrix is ​​determined according to the matched text information.

[0013] According to the above aspects and any possible implementation manner, an implementation manner is further provided, before calculating the foreground color projection value of the binary image in the horizontal direction according to the binary image, the method further includes:

[0014] Step 1: Get color categories, where the color categories include foreground colors and background colors;

[0015] Step 2: Obtain sample division rules, and obtain multiple classification samples from the text minimum circumscribed matrix;

[0016] Step 3: Calculate the distance between each of the classification samples, take the two classification samples with the farthest distance as the center point samples, and remove them from the classification samples, wherein the distance is the Euclidean distance;

[0017] Step 4: Calculate the distance between each of the classified samples and the two center point samples, classify the classified samples close to the center point samples into one category, and obtain two sample sets;

[0018] Step 5: Select two new center point samples from the two sample sets, repeat the steps of Step 4 until a preset number of steps or convergence condition is reached, stop selecting two new center point samples, and obtain the first color area and the second color area according to the obtained two sample sets;

[0019] Step 6: Expand the first text box area in the vertical direction according to a preset ratio, and repeat steps Step 1 to Step 5 to obtain a third color area and a fourth color area;

[0020] Step 7: The area with more samples in the third color area and the fourth color area is taken as the main area;

[0021] Step 8: Calculate the distances from the classified samples in the first color area and the second color area to the main area, and use the color of the color area with a short distance as the background color, and the color of the color area with a long distance as the foreground color.

[0022] According to the above aspects and any possible implementation, an implementation is further provided, wherein according to the segmentation point and the text string, the text information in the minimum circumscribed matrix of the text is recognized from left to right using the OCR recognition model, and the matching text information is determined in a matching manner in which the minimum unit is a character, including:

[0023] Segment and identify the text information in the text minimum circumscribed matrix from left to right according to the segmentation points to obtain character information to be matched;

[0024] Comparing the character information to be matched with the text recognition string, if the character information to be matched matches the characters in the text recognition string, continuing to recognize the next character information;

[0025] If the character information to be matched does not match the characters in the text recognition string, the area currently matching the characters is merged with the area where the next character information to be matched is located, and then compared with the text recognition string until the character information to be matched matches the characters in the text recognition string.

[0026] According to the above aspect and any possible implementation, an implementation is further provided, wherein determining the position of each character in the text minimum circumscribed matrix according to the matched text information comprises:

[0027] Segment each of the characters in the text minimum circumscribed matrix according to the matched text information, and obtain the horizontal coordinate of the segmentation position;

[0028] Obtaining the ordinate of each character according to the text minimum circumscribed matrix;

[0029] The position of each character in the text minimum circumscribed matrix is ​​determined according to the horizontal coordinate of the segmentation position and the vertical coordinate of each character in the text minimum circumscribed matrix.

[0030] According to the above aspects and any possible implementation manner, an implementation manner is further provided, after determining the position of each character in the text minimum circumscribed matrix according to the matched text information, the method further includes:

[0031] Get the search keyword or text information color acquisition instruction entered by the user;

[0032] By text matching, determining matching words in the text minimum circumscribed matrix according to the search keyword;

[0033] Obtaining the position of each character in the matching word, and displaying the matching word in the image to be recognized using a preset annotation method;

[0034] Determine the area where the target text is located according to the text information color acquisition instruction;

[0035] Get the foreground color and background color of the area where the target text is located.

[0036] In a second aspect, an embodiment of the present application provides a text feature recognition device, comprising:

[0037] The first acquisition module is used to process the image to be recognized using the OCR recognition model to obtain the text box area and the text string;

[0038] A second acquisition module is used for gray-scaling the text box area to obtain a grayscale image;

[0039] A third acquisition module is used to process the grayscale image using a binarization algorithm to obtain a binary image;

[0040] A first calculation module, used for calculating the text minimum circumscribed matrix according to the binary graph;

[0041] A second calculation module, used for calculating a foreground color projection value of the binary image in a horizontal direction according to the binary image;

[0042] A fourth acquisition module, configured to obtain segmentation points by using a watershed algorithm according to the foreground color projection value in the horizontal direction of the binary image;

[0043] A matching module, for identifying the text information in the minimum circumscribed matrix of the text from left to right using the OCR recognition model according to the segmentation point and the text string, and determining the matching text information in a matching manner in which the minimum unit is a character;

[0044] A position determination module is used to determine the position of each character in the text minimum circumscribed matrix according to the matched text information.

[0045] Furthermore, the device is also used for:

[0046] Obtaining a color category, wherein the color category includes a foreground color and a background color;

[0047] Obtaining a sample division rule, and obtaining a plurality of classification samples from the text minimum circumscribed matrix;

[0048] Calculate the distance between each of the classification samples, take the two classification samples with the farthest distance as center point samples, and remove them from the classification samples, wherein the distance is the Euclidean distance;

[0049] Calculating the distance between each of the classified samples and the two center point samples, classifying the classified samples close to the center point samples into one category, and obtaining two sample sets;

[0050] Selecting two new center point samples from the two sample sets, repeating step 4 until a preset number of steps or convergence condition is reached, stopping selecting two new center point samples, and obtaining a first color area and a second color area according to the obtained two sample sets;

[0051] Expand the first text box area in the vertical direction according to a preset ratio, and repeat steps 1 to 5 to obtain a third color area and a fourth color area;

[0052] taking the area with more samples in the third color area and the fourth color area as the main area;

[0053] The distances from the classified samples in the first color area and the second color area to the main area are calculated, and the color of the color area with a short distance is used as the background color, and the color of the color area with a long distance is used as the foreground color.

[0054] Furthermore, the matching module is also used for:

[0055] Segment and identify the text information in the text minimum circumscribed matrix from left to right according to the segmentation points to obtain character information to be matched;

[0056] Comparing the character information to be matched with the text recognition string, if the character information to be matched matches the characters in the text recognition string, continuing to recognize the next character information;

[0057] If the character information to be matched does not match the characters in the text recognition string, the area currently matching the characters is merged with the area where the next character information to be matched is located, and then compared with the text recognition string until the character information to be matched matches the characters in the text recognition string.

[0058] Furthermore, the location determination module is also used for:

[0059] Segment each of the characters in the text minimum circumscribed matrix according to the matched text information, and obtain the horizontal coordinate of the segmentation position;

[0060] Obtaining the ordinate of each character according to the text minimum circumscribed matrix;

[0061] The position of each character in the text minimum circumscribed matrix is ​​determined according to the horizontal coordinate of the segmentation position and the vertical coordinate of each character in the text minimum circumscribed matrix.

[0062] Furthermore, the device is also used for:

[0063] Get the search keyword or text information color acquisition instruction entered by the user;

[0064] By text matching, determining matching words in the text minimum circumscribed matrix according to the search keyword;

[0065] Obtaining the position of each character in the matching word, and displaying the matching word in the image to be recognized using a preset annotation method;

[0066] Determine the area where the target text is located according to the text information color acquisition instruction;

[0067] The text color information is determined according to the area where the target text is located.

[0068] Furthermore, the device is also used for:

[0069] Recognizing the voice information sent by the user through a voice recognition model to generate the search keyword;

[0070] Alternatively, the user clicks a color acquisition button to enter a color acquisition interface with the image to be identified as the background. When the user clicks any position on the color acquisition interface, the coordinate information of the position will be recorded.

[0071] Furthermore, the device is also used for:

[0072] According to the coordinate information, using Euclidean distance to calculate the distance from the coordinate information to the center of the minimum circumscribed matrix of each text;

[0073] The text minimum circumscribed matrix with the shortest distance from the coordinate information to the center of the text minimum circumscribed matrix is ​​used as the area where the target text is located.

[0074] In a third aspect, an embodiment of the present application provides a computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the processor executes the steps of the text feature recognition method described in the first aspect when executing the computer-readable instructions.

[0075] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the text feature recognition method described in the first aspect are implemented.

[0076] In the embodiment of the present application, the image to be recognized is first processed by the OCR recognition model to obtain the text box area and the text string, so as to further optimize the recognition of the position of the text information on the basis of OCR recognition; then the text minimum external matrix is ​​calculated by graying and binarization processing, which can remove the redundant information in the text area box, so that the position of the text information in the image to be recognized is more accurate; then the foreground color projection value in the horizontal direction of the binary image is calculated, and the segmentation point is calculated using the foreground color projection value to segment the text information using the segmentation point; finally, according to the segmentation point and the text string, the OCR recognition model is used to recognize the text information in the text minimum external matrix from left to right, and the matching text information is determined by the matching method with the smallest unit as the character, and the position of each character in the text minimum external matrix is ​​determined. Starting from the segmentation characteristics between characters, the text information is matched and accurately positioned at the character level. The embodiment of the present application can accurately identify the position of characters in the image. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0078] Figure 1 is a flow chart of a text feature recognition method in an embodiment of the present application;

[0079] Figure 2 It is a principle block diagram of a text feature recognition device in an embodiment of the present application;

[0080] Figure 3 It is a schematic diagram of a computer device in an embodiment of the present application. DETAILED DESCRIPTION

[0081] In order to better understand the technical solution of the present application, the embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0082] It should be clear that the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0083] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0084] It should be understood that the term "and / or" used in this article is only a description of the same field of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0085] It should be understood that, although the terms first, second, third, etc. may be used to describe preset ranges, etc. in the embodiments of the present application, these preset ranges should not be limited to these terms. These terms are only used to distinguish preset ranges from each other. For example, without departing from the scope of the embodiments of the present application, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.

[0086] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0087] Figure 1 1 is a flowchart of a text feature recognition method in an embodiment of the present application. The text feature recognition method can be applied to a scenario where a user searches for keywords from an image, and the text feature recognition method can be implemented on a computer device used by the user. Figure 1 As shown, the text feature recognition method includes the following steps:

[0088] S10: Using the OCR recognition model to process the image to be recognized, and obtaining a text box area and a text string.

[0089] The image to be identified can be a PPT image, a poster, a flyer, or other image with a lot of text information and rich text colors. In addition, an image captured from a video can also be used as an image to be identified. The text feature recognition method supports searching for text information in a video.

[0090] In one embodiment, an OCR recognition model may be used to recognize text in an image to be recognized, and obtain a preliminary text box area and text string. It is understandable that the recognition result of the OCR recognition model is mostly used to obtain the meaning of the text in the image, and the recognition accuracy is relatively poor.

[0091] S20: grayscale the text box area to obtain a grayscale image.

[0092] S30: Using a binarization algorithm to process the grayscale image to obtain a binary image.

[0093] In one embodiment, the grayscale conversion can convert the image of the text area frame into a grayscale value with a brightness range of [0-255], and then classify the pixel value greater than the preset grayscale value as black, and classify the pixel value not greater than the preset grayscale value as white, so that the text area frame is processed into a binary image. Since the area covered by the text area frame is large and the accuracy is low, in order to obtain a more accurate area of ​​text information, this embodiment performs a binary processing after grayscale processing on the image to be recognized.

[0094] S40: Calculate the text minimum circumscribed matrix according to the binary graph.

[0095] In one embodiment, the binary image may be used to determine the minimum circumscribed matrix corresponding to the text information, so that redundant information in the original text area frame can be removed, making the position of the text information in the image to be recognized more accurate.

[0096] S50: Calculate the foreground color projection value of the binary image in the horizontal direction according to the binary image.

[0097] Among them, the foreground color is a concept corresponding to the background color. Generally speaking, the font color in the image to be recognized is the foreground color, and the color of the area near the font is the background color. In this embodiment, the foreground color projection value of the binary image is calculated in the horizontal direction in order to accurately distinguish the gaps between characters and more accurately determine the position of each character in the text information. Among them, the selection of the foreground color projection value in the horizontal direction is determined according to the font arrangement style. This application uses the situation that there are many gaps between the left and right sides of the characters to accurately divide the characters from the text information based on this feature.

[0098] S60: According to the foreground color projection value in the horizontal direction of the binary image, a watershed algorithm is used to obtain segmentation points.

[0099] Among them, the watershed algorithm can be understood as an algorithm for dividing the critical line according to the value with large difference. It can be understood that after obtaining the foreground color projection value of the binary image, due to the existence of the gap between characters (corresponding to the background color), the text information can be segmented according to the change of the foreground color and the background color.

[0100] S70: According to the segmentation points and the text string, the OCR recognition model is used to recognize the text information in the text minimum circumscribed matrix from left to right, and the matching text information is determined in a matching manner in which the minimum unit is a character.

[0101] In one embodiment, considering that some characters are left-right structures, when using the watershed algorithm to segment text information, a complete character may be divided into two meaningless parts. Therefore, in this embodiment, the OCR recognition in S10 is referred to and the text information matching is performed again. When the text information obtained according to the segmentation point matches the result of the OCR recognition, the matching of the single character is completed, which can further improve the accuracy of text feature recognition.

[0102] S80: Determine the position of each character in the text minimum circumscribed matrix according to the matched text information.

[0103] In one embodiment, when all characters in the minimum circumscribed matrix are matched, the position of each character on the image to be recognized can be accurately located according to the coordinate information of the minimum circumscribed matrix relative to the image to be recognized. It can be understood that such accurate positioning can support the user to search for text information in the image to be recognized, and accurately locate the text information on the image and display it, thereby achieving the function of searching for text information in the image.

[0104] In an embodiment of the present application, the image to be recognized is firstly processed by an OCR recognition model to obtain a text box area and a text string, so as to further optimize the recognition of the position of the text information based on OCR recognition; then, the text minimum circumscribed matrix is ​​calculated by grayscale and binarization processing, and redundant information in the text area box can be removed, so that the position of the text information in the image to be recognized is more accurate; then, the foreground color projection value in the horizontal direction of the binary image is calculated, and the segmentation point is calculated using the foreground color projection value to segment the text information using the segmentation point; finally, according to the segmentation point and the text string, the OCR recognition model is used to recognize the text information in the text minimum circumscribed matrix from left to right, and the matching text information is determined in a matching manner with the smallest unit being the character, and the position of each character in the text minimum circumscribed matrix is ​​determined, and based on the segmentation characteristics between characters, character-level matching and precise positioning of the text information are achieved.

[0105] Furthermore, before step S50, that is, before calculating the foreground color projection value of the binary image in the horizontal direction according to the binary image, the text feature recognition method further includes the step of determining the foreground color:

[0106] Step 1: Get the color category, where the color category includes foreground color and background color.

[0107] Step 2: Obtain sample division rules and obtain multiple classification samples from the text minimum circumscribed matrix.

[0108] Step 3: Calculate the distance between each classification sample, take the two classification samples with the farthest distance as the center point samples, and remove them from the classification samples, where the distance is the Euclidean distance.

[0109] Step 4: Calculate the distance between each classification sample and the two center point samples, classify the classification samples close to the center point samples into one category, and obtain two sample sets.

[0110] Step 5: Select two new center point samples from the two sample sets, repeat the steps of Step 4 until the preset number of steps or convergence condition is reached, stop selecting two new center point samples, and obtain the first color area and the second color area based on the two sample sets.

[0111] Step 6: Expand the first text box area in the vertical direction according to a preset ratio, and repeat steps Step 1-Step 5 to obtain the third color area and the fourth color area.

[0112] Step 7: Take the area with more samples in the third color area and the fourth color area as the main area.

[0113] Step 8: Calculate the distance between the classified samples in the first color area and the second color area and the main area, and use the color of the color area with a short distance as the background color and the color of the color area with a long distance as the foreground color.

[0114] In Step 1-Step 8, clustering is used to determine the foreground color and background color of the area box. Among them, the first color area and the second color area obtained in Step 1-Step 5 are the areas obtained preliminarily, and the result may reverse the foreground color and the background color. Steps Step 6-Step 8 have made improvements on this basis. Specifically, by utilizing the large background gap in the vertical direction of the text, the text box area is expanded in the vertical direction according to a preset ratio, and then the third color area and the fourth color area are calculated. It can be understood that the color values ​​of the third color area and the fourth color area are not necessarily accurate, but after vertical expansion, it can be considered that the main color obtained is the background color (the background color accounts for a large proportion). In this way, by calculating the distance from the sample points of the first color area and the second color area to the main color, it can be determined that the shorter distance is the background color and the longer distance is the foreground color.

[0115] Furthermore, since there is a coordinate relationship between the image pixel sample points, it is more appropriate to use the Euclidean distance for the distance, and the obtained foreground color will be more accurate.

[0116] Further, in step S70, that is, according to the segmentation point and the text string, the OCR recognition model is used to recognize the text information within the minimum bounding rectangle of the text from left to right. In the matching method with the minimum unit being a character, the following specific steps are included:

[0117] S71: Segment and recognize the text information within the minimum bounding rectangle of the text from left to right according to the segmentation point, and obtain the character information to be matched.

[0118] In one embodiment, based on the segmentation point, the text information within the minimum bounding rectangle is segmented to obtain a segmentation line that may be the gap between characters.

[0119] S72: Compare the character information to be matched with the text recognition string. If the characters in the character information to be matched and the text recognition string match, continue to recognize the next character information.

[0120] S73: If the characters in the character information to be matched and the text recognition string do not match, merge the region of the current matched character with the region where the next character information to be matched is located, and then compare it with the text recognition string until the characters in the character information to be matched and the text recognition string match.

[0121] In one embodiment, the character here refers to a single Chinese character, such as the character '好' (good). When matching characters, it is based on characters. Since the text information is segmented using the segmentation point, there may be a situation where a complete character like '好' is segmented into two characters '女' (female) and '子' (son). Therefore, in this embodiment, the OCR recognition model is used to verify and match the result of the segmented text information with the text recognition string to improve the accuracy of character recognition.

[0122] In steps S71 - S73, following the principle of taking a single character as a matching object, matching is performed from left to right according to the text recognition string. If a situation that does not conform to a single character is encountered, the matched region is merged until the single - character matching is satisfied. In this way, the position of each character can be accurately located.

[0123] Further, in step S80, that is, in determining the position of each character within the minimum bounding rectangle of the text according to the matched text information, the following specific steps are included:

[0124] S811: Segment each character within the minimum bounding rectangle of the text according to the matched text information, and obtain the abscissa of the segmentation position.

[0125] S812: Obtain the ordinate of each character according to the minimum bounding rectangle of the text.

[0126] In one embodiment, in order to accurately locate the characters, the coordinate information of each character can be recorded by coordinate positioning. Specifically, the segmentation position between characters can be known through the matched text information, so that the horizontal coordinate of the character can be obtained according to the segmentation. For the vertical coordinate, since the text external matrix has reduced the text box area, the upper coordinate and the lower coordinate of the text minimum external matrix can be directly obtained.

[0127] S813: Determine the position of each character in the text minimum circumscribed matrix according to the horizontal coordinate of the segmentation position and the vertical coordinate of each character in the text minimum circumscribed matrix.

[0128] In one embodiment, the character determines the coordinate information of the horizontal and vertical coordinates, and its position can be uniquely determined on the image to be recognized. When searching for text information in the image to be recognized, the text information that the user wants to find on the image to be recognized can be accurately located.

[0129] In steps S811-S813, the position of each character in the minimum circumscribed matrix of the text is determined using the coordinates as a reference, wherein the ordinate can be the ordinate of the minimum circumscribed matrix, and the abscissa is determined according to the segmented characters. In this way, each character can be accurately located in the image to be recognized, and the search function of the image text information can be realized through the character positioning.

[0130] Furthermore, in addition to accurately identifying the location of the text, text feature recognition can also include the recognition of text color and background color.

[0131] Furthermore, after step S80, that is, after determining the position of each character in the text minimum circumscribed matrix according to the matched text information, the method further comprises the following steps:

[0132] S821: Obtain the search keyword or text information color acquisition instruction input by the user.

[0133] The text information color acquisition instruction is used to acquire the color of the characters in the image or the background color of the characters.

[0134] In one embodiment, if the user wants to search for characters in a picture, or obtain the color of the characters in the picture or the background color of the characters, the color acquisition instruction of the search keyword or text information input by the user can be obtained to achieve it.

[0135] S822: Determine matching words in the text minimum circumscribed matrix according to the search keyword through text matching.

[0136] The text information color acquisition instruction is used to acquire the foreground color (the color of the corresponding character) or background color (the background color of the corresponding character) related to the target text.

[0137] In one embodiment, when a user wants to find the search keyword "health" in an image, the user can accurately locate the information corresponding to the word "health" in the image by inputting the search keyword. It can be understood that if the user thinks that the color matching (foreground color) or background color matching of the characters in an image (such as a poster) is good and wants to obtain it for reference, the foreground color and background color related to the target text can be obtained by inputting a text information color acquisition instruction.

[0138] S823: Obtain the position of each character in the matching word, and display the matching word in the image to be recognized using a preset annotation method.

[0139] The preset marking method may be highlighting, bolding, font deformation, etc. The user can quickly find the search keyword of his / her interest from the image to be identified.

[0140] S824: Determine the area where the target text is located according to the text information color acquisition instruction.

[0141] It can be understood that the image to be recognized includes multiple text box areas, and the colors of text information in different text box areas may be different. In order to obtain the color of the characters more accurately, it is necessary to determine the area where the target text is located.

[0142] S825: Determine text color information according to the area where the target text is located.

[0143] The text color information refers to the color of the characters in the text or the background color of the characters.

[0144] In one embodiment, by distinguishing the foreground color and the background color of the area where the target text is located, the color of the characters and the background color of the characters in the area where the target text is located can be determined.

[0145] In steps S821-S825, a practical application extension of the image text positioning is given. The user can search for the corresponding content from the image by entering the search keyword, and display it using a preset annotation method such as highlighting. Alternatively, when the user needs to obtain the foreground color or background color of the text information, he can also obtain it through the text color acquisition instruction. In this way, in PPT, posters, and video screenshots, the user can extract the font color or its background color.

[0146] Furthermore, in step S821, the search keyword or text information color acquisition instruction input by the user is obtained, which specifically includes the following steps:

[0147] S8211: Recognize the voice information sent by the user through the voice recognition model and generate search keywords.

[0148] In one embodiment, when a user wants to search for characters in an image to be recognized, the user can input voice information and obtain search keywords through voice recognition model analysis. Alternatively, the user can directly input the search keyword in the text box by calling the text input box to quickly locate and mark the displayed characters using the search keyword.

[0149] S8212: The user clicks a color acquisition button to enter a color acquisition interface with the image to be identified as the background. When the user clicks any position on the color acquisition interface, the coordinate information of the position is recorded.

[0150] In one embodiment, when the user wants to obtain the color of a character or the background color of a character, he can first click the color acquisition button to enter the color acquisition interface. The color acquisition interface uses the image to be recognized as the background and is ready to obtain the coordinate information of the user's click position at any time. In this way, the user can easily obtain the character color by clicking on the text area where the character color to be obtained is located or the adjacent text area on the image to be recognized.

[0151] Further, in step S824, the area where the target text is located is determined according to the text information color acquisition instruction, which specifically includes the following steps:

[0152] S8241: Based on the coordinate information, the distance from the coordinate information to the center of the minimum circumscribed matrix of each text is calculated using the Euclidean distance.

[0153] S8242: The text minimum circumscribed matrix with the shortest distance from the coordinate information to the center of the text minimum circumscribed matrix is ​​used as the area where the target text is located.

[0154] In one embodiment, each text minimum circumscribed matrix is ​​distributed at different positions in the image to be recognized. Based on the coordinate information of the position clicked by the user, the Euclidean distance from the coordinate information to the center of each text minimum circumscribed matrix is ​​calculated, and it can be determined which text minimum circumscribed matrix the coordinate information is closest to on the two-dimensional plane. In this way, when the user clicks the position of the text area where the character color is located, the text area where the user expects to obtain the character color, that is, the area where the target text is located, can also be automatically found.

[0155] In an embodiment of the present application, the image to be recognized is firstly processed by an OCR recognition model to obtain a text box area and a text string, so as to further optimize the recognition of the position of the text information based on OCR recognition; then, the text minimum circumscribed matrix is ​​calculated by grayscale and binarization processing, and redundant information in the text area box can be removed, so that the position of the text information in the image to be recognized is more accurate; then, the foreground color projection value in the horizontal direction of the binary image is calculated, and the segmentation point is calculated using the foreground color projection value to segment the text information using the segmentation point; finally, according to the segmentation point and the text string, the OCR recognition model is used to recognize the text information in the text minimum circumscribed matrix from left to right, and the matching text information is determined in a matching manner with the smallest unit being the character, and the position of each character in the text minimum circumscribed matrix is ​​determined, and based on the segmentation characteristics between characters, character-level matching and precise positioning of the text information are achieved.

[0156] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0157] Figure 2 is a principle block diagram of a text feature recognition device in an embodiment of the present application. Figure 2 As shown, the text feature recognition device includes a first acquisition module 10, a second acquisition module 20, a third acquisition module 30, a first calculation module 40, a second calculation module 50, a fourth acquisition module 60, a matching module 70 and a position determination module 80. Among them, the implementation functions of the first acquisition module 10, the second acquisition module 20, the third acquisition module 30, the first calculation module 40, the second calculation module 50, the fourth acquisition module 60, the matching module 70 and the position determination module 80 correspond to the steps corresponding to the text feature recognition method one by one, and in order to avoid redundancy, this embodiment will not be described in detail one by one.

[0158] Furthermore, the device is also used for:

[0159] Get the color category, where the color category includes foreground color and background color;

[0160] Obtain sample division rules and obtain multiple classification samples from the text minimum circumscribed matrix;

[0161] Calculate the distance between each classification sample, take the two classification samples with the farthest distance as the center point samples, and remove them from the classification samples, where the distance is the Euclidean distance;

[0162] Calculate the distance between each classification sample and the two center point samples, classify the classification samples close to the center point samples into one category, and obtain two sample sets;

[0163] Select two new center point samples from the two sample sets, repeat step 4 until a preset number of steps or convergence condition is reached, stop selecting two new center point samples, and obtain a first color area and a second color area based on the obtained two sample sets;

[0164] Expand the first text box area in the vertical direction according to a preset ratio, and repeat Step 1 to Step 5 to obtain a third color area and a fourth color area;

[0165] The area with more samples in the third color area and the fourth color area is taken as the main area;

[0166] The distances from the classified samples in the first color area and the second color area to the main area are calculated, and the color of the color area with a short distance is used as the background color, and the color of the color area with a long distance is used as the foreground color.

[0167] Furthermore, the matching module 70 is also used for:

[0168] According to the segmentation points, the text information in the minimum circumscribed matrix of the text is segmented and recognized from left to right to obtain the character information to be matched;

[0169] Compare the character information to be matched with the text recognition string, and if the character information to be matched matches the characters in the text recognition string, continue to recognize the next character information;

[0170] If the character information to be matched does not match the characters in the text recognition string, the area of ​​the current matching character is merged with the area where the next character information to be matched is located, and then compared with the text recognition string until the character information to be matched matches the characters in the text recognition string.

[0171] Furthermore, the location determination module 80 is also used for:

[0172] Segment each character in the minimum circumscribed matrix of the text according to the matched text information, and obtain the horizontal coordinate of the segmentation position;

[0173] Get the ordinate of each character according to the text minimum circumscribed matrix;

[0174] The position of each character in the text minimum circumscribed matrix is ​​determined according to the abscissa of the segmentation position and the ordinate of each character in the text minimum circumscribed matrix.

[0175] Furthermore, the device is also used for:

[0176] Get the search keyword or text information color acquisition instruction entered by the user;

[0177] Through text matching, the matching words in the minimum circumscribed matrix of the text are determined according to the search keywords;

[0178] Obtain the position of each character in the matching word, and display the matching word in the image to be recognized using a preset annotation method;

[0179] Determine the area where the target text is located according to the text information color acquisition instruction;

[0180] Determine the text color information according to the area where the target text is located.

[0181] Furthermore, the device is also used for:

[0182] Recognize the user's voice information through the voice recognition model and generate search keywords;

[0183] Alternatively, the user clicks a color acquisition button to enter a color acquisition interface with the image to be identified as the background. When the user clicks any position on the color acquisition interface, the coordinate information of the position will be recorded.

[0184] Furthermore, the device is also used for:

[0185] According to the coordinate information, the distance from the coordinate information to the center of the minimum circumscribed matrix of each text is calculated using the Euclidean distance;

[0186] The text minimum external matrix with the shortest distance from the coordinate information to the center of the text minimum external matrix is ​​taken as the area where the target text is located.

[0187] Figure 3 It is a schematic diagram of a computer device in one embodiment of the present application.

[0188] like Figure 3 As shown, the computer device 90 includes a processor 91, a memory 92, and a computer readable instruction 93 stored in the memory 92 and executable on the processor 91. When the processor 91 executes the computer readable instruction 93, each step of the text feature recognition method described in the above embodiment is implemented. Alternatively, when the processor 91 executes the computer readable instruction 93, the functions of each module / unit of the text feature recognition device are implemented.

[0189] Exemplarily, the computer readable instructions 93 may be divided into one or more modules / units, one or more modules / units are stored in the memory 92, and are executed by the processor 91 to complete the present application. One or more modules / units may be a series of computer readable instruction segments capable of completing a specific function, and the instruction segments are used to describe the execution process of the computer readable instructions 93 in the computer device 90.

[0190] The computer device 90 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device may include, but is not limited to, a processor 91 and a memory 92. Those skilled in the art will appreciate that Figure 3 This is only an example of the computer device 90 and does not constitute a limitation of the computer device 90. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, etc.

[0191] The processor 91 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0192] The memory 92 may be an internal storage unit of the computer device 90, such as a hard disk or memory of the computer device 90. The memory 92 may also be an external storage device of the computer device 90, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 90. Further, the memory 92 may also include both an internal storage unit of the computer device 90 and an external storage device. The memory 92 is used to store computer-readable instructions and other programs and data required by the computer device. The memory 92 may also be used to temporarily store data that has been output or is to be output.

[0193] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0194] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0195] In the embodiments of the present application, the server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.

[0196] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0197] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0198] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium, and the computer-readable instructions can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer-readable instructions include computer-readable instruction codes, and the computer-readable instruction codes can be in source code form, object code form, executable files or some intermediate forms. The computer-readable medium may include: any entity or device capable of carrying the computer-readable instruction code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practices in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practices, computer-readable media does not include electrical carrier signals and telecommunication signals.

[0199] The present application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the text feature recognition method described in the above embodiment is implemented.

[0200] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A text feature recognition method, characterized in that: include: Use the OCR recognition model to process the image to be recognized and obtain the text box area and text string; Grayscale the text box area to obtain a grayscale image; Processing the grayscale image using a binarization algorithm to obtain a binary image; Calculate the text minimum circumscribed matrix according to the binary graph; Step 1: Get color categories, where the color categories include foreground colors and background colors; Step 2: Obtain sample division rules, and obtain multiple classification samples from the text minimum circumscribed matrix; Step 3: Calculate the distance between each of the classification samples, take the two classification samples with the farthest distance as the center point samples, and remove them from the classification samples, wherein the distance is the Euclidean distance; Step 4: Calculate the distance between each of the classified samples and the two center point samples, classify the classified samples close to the center point samples into one category, and obtain two sample sets; Step 5: Select two new center point samples from the two sample sets, repeat the steps of Step 4 until a preset number of steps or convergence condition is reached, stop selecting two new center point samples, and obtain the first color area and the second color area according to the obtained two sample sets; Step 6: Expand the text box area in the vertical direction according to a preset ratio, and repeat Step 1-Step 5 to obtain a third color area and a fourth color area; Step 7: The third color area and the fourth color area with more samples are taken as the main area; Step 8: Calculate the distances between the classified samples in the first color area and the second color area and the main area, and use the color of the color area with a short distance as the background color, and the color of the color area with a long distance as the foreground color; Calculate the foreground color projection value of the binary image in the horizontal direction according to the binary image; According to the foreground color projection value in the horizontal direction of the binary image, a segmentation point is obtained by using a watershed algorithm; According to the segmentation point and the text string, the OCR recognition model is used to recognize the text information in the text minimum circumscribed matrix from left to right, and the matching text information is determined in a matching manner in which the smallest unit is a character; The position of each character in the text minimum circumscribed matrix is ​​determined according to the matched text information.

2. The method according to claim 1, characterized in that The method of identifying the text information in the minimum circumscribed matrix of the text from left to right using the OCR recognition model according to the segmentation point and the text string, and determining the matching text information in a matching manner in which the minimum unit is a character, includes: Segment and identify the text information in the text minimum circumscribed matrix from left to right according to the segmentation points to obtain character information to be matched; Comparing the character information to be matched with the text recognition string, if the character information to be matched matches the characters in the text recognition string, continuing to recognize the next character information; If the character information to be matched does not match the characters in the text recognition string, the area currently matching the characters is merged with the area where the next character information to be matched is located, and then compared with the text recognition string until the character information to be matched matches the characters in the text recognition string.

3. The method according to claim 1, characterized in that The step of determining the position of each character in the text minimum circumscribed matrix according to the matched text information comprises: Segment each of the characters in the text minimum circumscribed matrix according to the matched text information, and obtain the horizontal coordinate of the segmentation position; Obtaining the ordinate of each character according to the text minimum circumscribed matrix; The position of each character in the text minimum circumscribed matrix is ​​determined according to the horizontal coordinate of the segmentation position and the vertical coordinate of each character in the text minimum circumscribed matrix.

4. The method according to claim 1, characterized in that After determining the position of each character in the text minimum circumscribed matrix according to the matched text information, the method further includes: Get the search keyword or text information color acquisition instruction entered by the user; By text matching, determining matching words in the text minimum circumscribed matrix according to the search keyword; Obtaining the position of each character in the matching word, and displaying the matching word in the image to be recognized using a preset annotation method; Determine the area where the target text is located according to the text information color acquisition instruction; The text color information is determined according to the area where the target text is located.

5. The method according to claim 4, characterized in that The step of obtaining the search keyword or text information color obtained by the user includes: Recognizing the voice information sent by the user through a voice recognition model to generate the search keyword; Alternatively, the user clicks a color acquisition button to enter a color acquisition interface with the image to be identified as the background. When the user clicks any position on the color acquisition interface, the coordinate information of the position will be recorded.

6. The method according to claim 5, characterized in that The step of determining the area where the target text is located according to the text information color acquisition instruction includes: According to the coordinate information, using Euclidean distance to calculate the distance from the coordinate information to the center of the minimum circumscribed matrix of each text; The text minimum circumscribed matrix with the shortest distance from the coordinate information to the center of the text minimum circumscribed matrix is ​​used as the area where the target text is located.

7. A text feature recognition device, characterized in that: include: The first acquisition module is used to process the image to be recognized using the OCR recognition model to obtain the text box area and the text string; A second acquisition module is used for gray-scaling the text box area to obtain a grayscale image; A third acquisition module is used to process the grayscale image using a binarization algorithm to obtain a binary image; A first calculation module, used for calculating the text minimum circumscribed matrix according to the binary graph; Step 1: Get color categories, where the color categories include foreground colors and background colors; Step 2: Obtain sample division rules, and obtain multiple classification samples from the text minimum circumscribed matrix; Step 3: Calculate the distance between each of the classification samples, take the two classification samples with the farthest distance as the center point samples, and remove them from the classification samples, wherein the distance is the Euclidean distance; Step 4: Calculate the distance between each of the classified samples and the two center point samples, classify the classified samples close to the center point samples into one category, and obtain two sample sets; Step 5: Select two new center point samples from the two sample sets, repeat the steps of Step 4 until a preset number of steps or convergence condition is reached, stop selecting two new center point samples, and obtain the first color area and the second color area according to the obtained two sample sets; Step 6: Expand the text box area in the vertical direction according to a preset ratio, and repeat Step 1-Step 5 to obtain a third color area and a fourth color area; Step 7: The third color area and the fourth color area with more samples are taken as the main area; Step 8: Calculate the distances between the classified samples in the first color area and the second color area and the main area, and use the color of the color area with a short distance as the background color, and the color of the color area with a long distance as the foreground color; A second calculation module, used for calculating a foreground color projection value of the binary image in a horizontal direction according to the binary image; A fourth acquisition module, configured to obtain segmentation points by using a watershed algorithm according to the foreground color projection value in the horizontal direction of the binary image; A matching module, for identifying the text information in the minimum circumscribed matrix of the text from left to right using the OCR recognition model according to the segmentation point and the text string, and determining the matching text information in a matching manner in which the minimum unit is a character; A position determination module is used to determine the position of each character in the text minimum circumscribed matrix according to the matched text information.

8. A computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the computer-readable instructions, the processor performs the steps of the text feature recognition method according to any one of claims 1 to 6.

9. A computer-readable storage medium storing computer-readable instructions, characterized in that: When the computer-readable instructions are executed by a processor, the steps of the text feature recognition method according to any one of claims 1 to 6 are implemented.