Method and device for plain text detection
By identifying the character color of the target character and converting it into a text picture, and judging its solid color, the problem of low accuracy in emoji recognition in the prior art is solved, and the accuracy and applicability of pure text detection are improved.
Patent Information
- Application Number
- CN202310525138.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-10
- Publication Date
- 2024-11-12
AI Technical Summary
The prior art has low accuracy when identifying emojis, and cannot recognize all emojis, and the fast update speed of emojis leads to problems such as "missing recognition" or "misrecognition".
By determining the character color of the target character, generating a view label and converting it into a text picture, determining whether the text picture is solid, and thus determining that the target character is plain text or non-plain text. The method includes obtaining the color mode value of the pixel point, comparing the brightness value or color mode value to determine the solid color, which is suitable for plain text detection in various scenarios.
It improves the accuracy and universal applicability of plain text detection, avoids the problem of unrecognizable due to emoji updates, simplifies the solid color judgment steps, saves network resources, and ensures that only a single character is detected at a time.
Smart Images

Figure CN118942095A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for plain text detection. Background Art
[0002] In many scenarios, business systems need to receive text information input by users. For example, a text input box is provided on the product order page to receive the delivery address entered by the user, or a text input box is provided on the product query page to receive the query conditions entered by the user. In addition to text content, non-text content such as emoticons can also be entered in the text input box. It is difficult for business systems to accurately identify received emoticons. Therefore, when obtaining data from the text input box, non-text content such as emoticons is usually intercepted and no further processing is performed.
[0003] In the process of implementing the present invention, the inventors found that the prior art has at least the following problems:
[0004] The accuracy of intercepting emojis is low and not all emojis can be recognized. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method and device for plain text detection, which can be applied to a variety of scenarios and improve the recognition accuracy of plain text content.
[0006] To achieve the above object, according to a first aspect of an embodiment of the present invention, a method for plain text detection is provided, comprising:
[0007] In response to receiving a target character, determining a character color of the target character, and obtaining a view label including the target character according to the character color;
[0008] Converting the view label into a text image;
[0009] It is identified whether the text image is a pure color, and when the text image is a pure color, it is determined that the target character is a pure text.
[0010] Optionally, obtaining a view label including the target character according to the character color includes:
[0011] Calling a preset generation method to generate an initial view label, wherein the initial view label includes a label text attribute, a label text color attribute, and a label background color attribute;
[0012] Setting the label text attribute to the target character;
[0013] Set the label text color attribute and label background color attribute to the character color;
[0014] The set initial view label is used as the view label of the target character.
[0015] Optionally, identifying whether the text image is a solid color includes:
[0016] Determine the color mode corresponding to the pixels included in the text image;
[0017] Acquire a color mode value corresponding to the pixel point according to the color mode;
[0018] Determine whether the text image is a pure color according to the color mode value.
[0019] Optionally, obtaining a color mode value corresponding to the pixel point according to the color mode includes:
[0020] Obtaining size information of the text image;
[0021] Get the preset pixel format parameters;
[0022] According to the size information and the pixel format parameters, the pixel points included in the text image are traversed in sequence from a preset starting pixel point along a preset direction, and the color mode value corresponding to the pixel point is obtained according to the color mode.
[0023] Optionally, judging whether the text image is a pure color according to the color mode value includes:
[0024] Convert the color mode value corresponding to the pixel point into a brightness value;
[0025] The brightness value corresponding to the preset first pixel point is used as the target brightness value;
[0026] The target brightness value is compared with the brightness values corresponding to the remaining pixels. When the target brightness value and the brightness values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
[0027] Optionally, the color mode is a red, green, and blue color mode; and judging whether the text image is a pure color according to the color mode value includes:
[0028] Obtaining a preset target color mode value corresponding to a second pixel point;
[0029] The target color mode value is compared with the color mode values corresponding to the remaining pixels. When the target color mode value and the color mode values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
[0030] Optionally, before determining the character color of the target character, the method further includes:
[0031] Determine whether the target character is a single character;
[0032] In the case that the target character includes multiple characters, the multiple characters are split to obtain a target character including a single character.
[0033] According to a second aspect of an embodiment of the present invention, a device for plain text detection is provided, comprising:
[0034] A generating module, configured to determine the character color of the target character in response to receiving the target character, and obtain a view label including the target character according to the character color;
[0035] A conversion module, used for converting the view label into a text image;
[0036] The recognition module is used to recognize whether the text image is a pure color, and determine that the target character is a pure text when the text image is a pure color.
[0037] Optionally, obtaining a view label including the target character according to the character color includes:
[0038] Calling a preset generation method to generate an initial view label, wherein the initial view label includes a label text attribute, a label text color attribute, and a label background color attribute;
[0039] Setting the label text attribute to the target character;
[0040] Set the label text color attribute and label background color attribute to the character color;
[0041] The set initial view label is used as the view label of the target character.
[0042] Optionally, identifying whether the text image is a solid color includes:
[0043] Determine the color mode corresponding to the pixels included in the text image;
[0044] Acquire a color mode value corresponding to the pixel point according to the color mode;
[0045] Determine whether the text image is a pure color according to the color mode value.
[0046] Optionally, obtaining a color mode value corresponding to the pixel point according to the color mode includes:
[0047] Obtaining size information of the text image;
[0048] Get the preset pixel format parameters;
[0049] According to the size information and the pixel format parameters, the pixel points included in the text image are traversed in sequence from a preset starting pixel point along a preset direction, and the color mode value corresponding to the pixel point is obtained according to the color mode.
[0050] Optionally, judging whether the text image is a pure color according to the color mode value includes:
[0051] Convert the color mode value corresponding to the pixel point into a brightness value;
[0052] The brightness value corresponding to the preset first pixel point is used as the target brightness value;
[0053] The target brightness value is compared with the brightness values corresponding to the remaining pixels. When the target brightness value and the brightness values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
[0054] Optionally, the color mode is a red, green, and blue color mode; and judging whether the text image is a pure color according to the color mode value includes:
[0055] Obtaining a preset target color mode value corresponding to a second pixel point;
[0056] The target color mode value is compared with the color mode values corresponding to the remaining pixels. When the target color mode value and the color mode values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
[0057] Optionally, the device further comprises:
[0058] A determination module, used for determining whether the target character is a single character;
[0059] The splitting module is used for splitting the multiple characters to obtain the target character including a single character when the target character includes multiple characters.
[0060] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, including:
[0061] one or more processors;
[0062] a storage device for storing one or more programs,
[0063] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the above embodiments.
[0064] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method described in any one of the above embodiments is implemented.
[0065] An embodiment of the above invention has the following advantages or beneficial effects: obtaining a view label including a target character according to the character color, converting the view label into a text image, and determining that the target character is pure text when the text image is a pure color, which can improve the accuracy and universal applicability of pure text detection and avoid the inability to recognize emoticons due to frequent updates; generating an initial view label, setting the label text attributes according to the target character, and setting the label text color and label background color according to the character color, which can improve the generation efficiency of the target character and facilitate subsequent pure text detection according to color; obtaining the color mode value corresponding to the pixel points included in the text image, and determining whether the text image is a pure color according to the color mode value, which can improve the accuracy of pure color determination and is suitable for pure color determination in a variety of scenarios. The invention relates to a method for determining a pure color image by converting the color mode value into a brightness value, and determining whether the text image is a pure color according to the brightness value, so as to improve the efficiency of pure color determination, simplify the steps of pure color determination, and save network resources; the method comprises the following steps: determining a target color mode value, and comparing the color mode values of the remaining pixels with the target color mode value to determine whether the text image is a pure color, so as to improve the accuracy of pure color determination, and is applicable to pure color determination in various scenarios; when the target field includes multiple characters, the multiple characters are split to obtain a target character including a single character, so as to ensure that only a single character is detected as pure text each time, and effectively identify the specific location of non-pure text content.
[0066] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0068] Figure 1 is a schematic diagram of the main process of the method for plain text detection according to an embodiment of the present invention;
[0069] Figure 2 is a schematic diagram of a system flow of a method for plain text detection according to a reference embodiment of the present invention;
[0070] Figure 3 is a schematic diagram of an application scenario of a method for plain text detection according to a reference embodiment of the present invention;
[0071] Figure 4 is a schematic diagram of color mode value comparison of a method for plain text detection according to a reference embodiment of the present invention;
[0072] Figure 5is a schematic diagram of the main process of a method for plain text detection according to a reference embodiment of the present invention;
[0073] Figure 6 is a schematic diagram of the main process of a method for plain text detection according to another reference embodiment of the present invention;
[0074] Figure 7 is a schematic diagram of the main process of a method for plain text detection according to yet another reference embodiment of the present invention;
[0075] Figure 8 is a schematic diagram of main modules of a device for plain text detection according to an embodiment of the present invention;
[0076] Fig. 9 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0077] Fig.10 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0078] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0079] It should be noted that in the technical solution of the present invention, the collection, use, storage, sharing and transfer of user personal information involved are in compliance with the provisions of relevant laws and regulations, and it is necessary to inform the user and obtain the user's consent or authorization. When applicable, the user's personal information is de-identified and / or anonymized and / or encrypted.
[0080] In many scenarios, business systems need to receive text information input by users. For example, a text input box is provided on the product order page to receive the delivery address entered by the user, or a text input box is provided on the product query page to receive the query conditions entered by the user. This information is typed into the text input box through the keyboard and received and processed by the business system. In addition to text content, non-text content such as emoticons can also be entered in the text input box. It is difficult for the business system to accurately identify the received emoticons. Therefore, when obtaining data from the text input box, non-text content such as emoticons is usually intercepted and no further processing is performed; or the Unicode code corresponding to the text information is determined, and the text information is identified as a specific emoticon according to the Unicode code and processed.
[0081] The accuracy of intercepting emojis is low, and not all emojis can be recognized; and because emojis are updated very quickly, the corresponding Unicode codes cannot be adjusted in time, resulting in "missed recognition" or "misrecognition".
[0082] In view of this, according to a first aspect of an embodiment of the present invention, a method for plain text detection is provided.
[0083] Figure 1 FIG. 1 is a schematic diagram of the main process of the method for plain text detection according to an embodiment of the present invention. Figure 1 As shown, the method for plain text detection according to an embodiment of the present invention mainly includes the following steps S101 to S103.
[0084] Step S101 , in response to receiving a target character, determining the character color of the target character, and obtaining a view label including the target character according to the character color.
[0085] The business system provides various text input boxes to users, allowing users to input information in the text input boxes. The execution subject of the embodiment of the present invention monitors the text input box on the front-end page, and when it is detected that there are new characters in the text input box, the new characters are used as target characters for plain text detection; specifically, the execution subject of the embodiment of the present invention monitors the change in the number of characters in the text input box, and after each change in the number of characters, obtains the characters in the text input box, compares them with the characters after the last change in the number of characters, determines whether there are new characters, and when there are new characters, uses the new characters as target characters for plain text detection.
[0086] After receiving the target character, determine which text input box the target character comes from, use the text input box as the target text input box, and determine the character color of the target character according to the text color attribute of the target text input box; the text color attribute of the text input box is pre-set, and different text input boxes can have different text color attributes. The text color attribute of the text input box determines the color of the character input into the text input box. For example, the page code of text input box A is " <input type=‘text’style=‘color:red;’> ", where "input" indicates that this is an input box, "type = 'text'" indicates that the type of the input box is a text input box, and "style = 'color:red;'" indicates that the text color attribute of the text input box is red.
[0087] After determining the character color of the target character according to the text color attribute of the target text input box, a view label including the target character is generated according to the character color, so that the label text color of the view label is the same as the character color, and the label background color of the view label is also the same as the character color. The view label is a view tool for displaying one or more lines of informational text, and the label attributes included in the view label are configurable. Since the label text color and the label background color are the same, in the case where the target character only includes plain text, the view label only includes one color, and the text image converted by the view label is a solid color image, thereby identifying that the target character is plain text content; in the case where the target character also includes non-text content such as emoticons, as long as the non-text content such as emoticons includes at least one color different from the character color, the view label includes at least two colors, and the text image converted by the view label is not a solid color image, thereby identifying that the target character is not plain text content.
[0088] Some non-text content such as emoticons has only one color, and this color is the same as the color indicated by the text color attribute of the text input box. When the target character includes the above non-text content, the obtained view label only includes one color. Therefore, a color different from the previously determined character color is selected as the reference color, and a reference view label including the target character is generated according to the reference color, so that the label text color of the reference view label is the same as the reference color, and the label background color of the reference view label is also the same as the reference color. Since the color of other non-text content such as emoticons cannot change with the change of the label text color of the reference view label, therefore, in the reference view label, the color of other non-text content such as emoticons is different from the label background color of the reference view label, and the reference view label includes at least two colors. In the subsequent steps, the view label is converted into a text image, and the control view label is converted into a control text image, and it is respectively identified whether the text image and the control text image are both solid colors. When the text image and the control text image are both solid colors, the target character is determined to be solid text. Specifically, it is first identified whether the text images are both solid colors. When the text image is not a solid color image, the target character is determined not to be solid text. When the text image is a solid color image, the control text image is then identified. When the control text image is a solid color image, the target character is determined to be solid text. When the control text image is not a solid color image, the target character is determined not to be solid text.
[0089] Figure 2 FIG. 1 is a schematic diagram of a system flow of a method for plain text detection according to a reference embodiment of the present invention. For example, Figure 2As shown, after the user inputs information in the text input box, the execution body of the embodiment of the present invention monitors the changes in the text input box and receives the information input by the user, and then generates a view label according to the attributes of the text input box, and sets the label text color and the label background color of the view label to the same color. Specifically, the label text color and the label background color of the view label are set to the color corresponding to the text color attribute of the text input box, or to a pre-set color.
[0090] Figure 3 is a schematic diagram of an application scenario of a method for plain text detection according to a reference embodiment of the present invention. Figure 3 As shown, page 301 includes a text input box for user feedback, wherein the text input box has the words "I hope to add background music to the page" entered, followed by an emoticon representing a musical note, which is colorful and different from the text color; page 302 includes a text input box for order notes, wherein the text input box has the words "The order item is a camera, please handle it with care" entered, followed by an emoticon representing a camera, which is colorful and different from the text color; page 303 includes a text input box for user name modification, wherein the text input box has the letters "XY" entered, followed by a diamond-shaped emoticon, which is colorful and different from the text color; the execution body of the embodiment of the present invention will generate a view label according to each character and text color in the text input box in turn, and convert it into a text image; when recognizing the emoticon, since the color included in the emoticon is different from the text color, it can accurately recognize that the corresponding text image is not a solid color, thereby determining that the emoticon is not pure text content.
[0091] As another example, the characters in the text input box B are "ab". After that, the execution subject of the embodiment of the present invention detects that the number of characters in the text input box B has changed, and the characters in the text input box B have changed to "abc". By comparison, it is determined that a new character "c" is added, and the new character "c" is used as the target character. Since the target character comes from the text input box B, specifically, the page code is " <input id=‘B’type=‘text’style=‘color:black;’> ", wherein "id='B'" indicates that the identifier of the text input box is "B", and "style='color:black;'" indicates that the text color attribute of the text input box is black, thus determining that the character color of the target character is black; using the code "UILabel*uiLabel=[UILabel alloc]init];" to generate a view label including the target character, so that the label text color of the view label is the same as the character color, and the label background color of the view label is also the same as the character color.
[0092] The character color of the target character is determined, and a view label including the target character is obtained according to the character color, so that the view label corresponding to the plain text content and the view label corresponding to the non-text content are distinguished in color, which facilitates the subsequent recognition of the plain text content.
[0093] According to a reference embodiment of the present invention, a view label including the target character is obtained according to the character color, comprising: calling a preset generation method to generate an initial view label, the initial view label including a label text attribute, a label text color attribute and a label background color attribute; setting the label text attribute to the target character; setting the label text color attribute and the label background color attribute to the character color; and using the set initial view label as the view label of the target character.
[0094] The shape of the view label is a rectangle. Obtain the preset rectangle starting point coordinate information, rectangle width information and rectangle height information, and create an initial view label according to the above information; multiple label attributes of the initial view label have not been set yet, obtain the label text attribute of the initial view label, and set the value of the label text attribute to the target character; obtain the label text color attribute of the initial view label, and set the value of the label text color attribute to the character color of the target character; obtain the label background color attribute of the initial view label, and set the value of the label background color attribute to the character color of the target character. After setting the label attributes of the initial view label, use the set initial view label as the view label of the target character.
[0095] For example, after receiving the target character "D" and determining that the character color of the target character "D" is gray; obtaining the preset rectangle starting point coordinate information: (0,0), rectangle width information: 1, and rectangle height information: 1; calling the method UILabel*uiLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,1,1)], generate the initial view label "uiLabel"; use the code uiLabel.text = "D" to set the value of the label text attribute of the initial view label "uiLabel" to the target character "D", use the code uiLabel.textColor = "#808080" to set the value of the label text color attribute of the initial view label "uiLabel" to gray, use the code uiLabel.backgroundColor = "#808080" to set the value of the label background color attribute of the initial view label "uiLabel" to gray, where "#808080" represents the RGB color code of gray, and the initial view label with the label text attribute, label text color attribute and label background color attribute set is used as the view label of the target character "D".
[0096] According to a reference embodiment of the present invention, before determining the character color of the target character, the method also includes: judging whether the target character is a single character; when the target character includes multiple characters, splitting the multiple characters to obtain a target character including a single character.
[0097] When a user inputs content into a text input box, one character or multiple characters can be input at a time. When inputting a single character, the character is directly used as the target character and the character color is determined. When inputting multiple characters, before determining the character color of the target character, first determine whether the target character is a single character and obtain the character length of the target character. When the character length of the target character is greater than 1, determine that the target character includes multiple characters, split the multiple characters, and obtain the single character corresponding to each position in turn according to the sorting position of the multiple characters. Use the single character obtained by the split as the target character, so that the character length of the target character obtained after the split is equal to 1.
[0098] Exemplarily, the target character received from the user input is "你好". Since the length of this character is equal to 2, it is determined that this character is not a single character. Using the method charAt(0) on the target character, the character "你" is obtained. The length of the character "你" is equal to 1, and it is used as the target character. Using the method charAt(1) on the target character, the character "好" is obtained. The length of the character "好" is equal to 1, and it is also used as the target character; according to the above steps, the target character "你好" is split into two target characters, "你" and "好", and according to the arrangement order of these two characters, the subsequent pure text detection method is first executed on the target character "你", and then the subsequent pure text detection method is executed on the target character "好", so that only a single character is subjected to pure text detection each time.
[0099] Step S102, convert the view label into a text picture.
[0100] After obtaining the view label of the target character, use a pre-set conversion method to convert the view label into a text picture. First, create an image context based on a bitmap. A bitmap, also known as a dot matrix image or a raster image, is composed of pixel points; specifically, obtain the size information of the view label, obtain a pre-set transparency flag, which is a boolean value, and the transparency flag indicates whether the bitmap is transparent, obtain the scale factor applied to the bitmap, and create an image context based on the bitmap according to the above size information, transparency flag, and scale factor. Render the label text and label background of the view label into the above image context, and obtain the text picture from the rendered image context.
[0101] Exemplarily, after obtaining the view label "uilabel" of the target character, use the size() method to obtain the size information of the view label, obtain a pre-set transparency flag as "YES", which indicates that the bitmap is transparent, obtain the scale factor "0.0f" applied to the bitmap, call the method UIGraphicsBeginImageContextWithOptions(size(), "YES", 0.0f) with the above information as parameters to generate an image context based on the bitmap, then call the method lbic = UIGraphicsGetCurrentContext() to obtain the current image context "lbic", then call the method [uilabel.layer renderInContext:lbic] to render the label text and label background of the view label "uilabel" into the image context "lbic", and then call the method UIGraphicsGetImageFromCurrentImageContext() to obtain the text picture from the rendered image context "lbic".
[0102] For example, Figure 2 As shown, after obtaining a view label whose label text color and label background color are the same color, the view label is converted into a text image to provide a recognition basis for subsequent recognition of whether the text image is a pure color.
[0103] By converting the view label into a text image based on a bitmap image context, the acquisition efficiency and image quality of the text image can be improved. By generating an image context based on various parameters, the flexibility of the image context can be improved.
[0104] Step S103, identifying whether the text image is a pure color, and determining that the target character is a pure text when the text image is a pure color.
[0105] After obtaining the text image, determine whether the text image includes only one color, that is, determine whether the text image is a pure color. Obtain each pixel included in the text image, and compare whether the color value of each pixel is the same. The color value is composed of a set of data, and this set of data determines the color presented by the corresponding pixel. In the case where the color data of each pixel included in the text image are the same, that is, in the multiple sets of data corresponding to each pixel, the data at the same position are the same, then it is determined that the pixels included in the text image are the same, and the color presented by each pixel is the same, that is, the text image is a pure color; in the case where the color data of each pixel included in the text image are not the same, that is, in the multiple sets of data corresponding to each pixel, there are different data at the same position, then it is determined that the pixels included in the text image are not all the same, and the colors presented by each pixel are not all the same, that is, the text image is not a pure color. In the case of a pure color text image, it is determined that the target character is a pure text, and in the case of a non-pure color text image, it is determined that the target character is not a pure text. When it is determined that the target character is not plain text, a prompt message is returned. For example, the prompt message "Emoji input is not supported yet, please enter plain text content" is displayed on the front-end page.
[0106] For example, Figure 2 As shown, after the view label is converted into a text image, the pixels included in the text image are obtained, the color values corresponding to the pixels are determined, and it is judged whether the color data included in each pixel are all corresponding and equal; when the color data included in each pixel are all corresponding and equal, it is determined that the text image is pure color, and the information input by the user in the text input box is pure text content; when there are two pixels whose color data are not corresponding and equal, it is determined that the text image is not pure color, and the information input by the user in the text input box is not pure text content.
[0107] The text image is recognized. When the text image is a solid color, the target characters are determined to be pure text. When the text image is not a solid color, the target characters are determined to include non-text content. This can be applied to a variety of plain text detection scenarios, improve the recognition accuracy of plain text content, effectively solve the problem that non-text content such as emoticons is frequently updated and difficult to recognize, and improve the stability of plain text detection.
[0108] According to a reference embodiment of the present invention, identifying whether the text image is a pure color includes: determining a color mode corresponding to pixels included in the text image; obtaining a color mode value corresponding to the pixel based on the color mode; and judging whether the text image is a pure color based on the color mode value.
[0109] The color mode is a description method used to describe the color presented by the pixel points. Common color modes include: RGB (Red Green Blue) color mode, CMYK color mode (where C stands for Cyan, M stands for Magenta, Y stands for Yellow, and K stands for Black), bitmap mode, grayscale mode, etc. Determine the color mode corresponding to the pixel points included in the text image, obtain the color mode value corresponding to the pixel points according to the color mode, compare the color mode values corresponding to the pixel points included in the text image, and when the color mode values corresponding to the pixel points are all the same, determine that the text image is a pure color.
[0110] Exemplarily, after obtaining the text image, it is determined that the color mode corresponding to the pixels included in the text image is a grayscale mode. In the grayscale mode, each pixel of the text image has a grayscale value (i.e., color mode value) between 0 (black) and 255 (white); specifically, the text image includes four pixels, namely, pixel e, pixel f, pixel g, and pixel h, wherein the grayscale value of pixel e in the grayscale mode is 10, the grayscale value of pixel f in the grayscale mode is 10, the grayscale value of pixel g in the grayscale mode is 11, and the grayscale value of pixel h in the grayscale mode is 10. By comparing the grayscale values of the above-mentioned pixel points, it is obtained that the grayscale value of pixel g is different from the grayscale values of other pixel points, then it is determined that the text image is not a solid color image, and then it is determined that the corresponding target character is not pure text.
[0111] Obtaining the color mode value corresponding to the pixel points included in the text image and judging whether the text image is a pure color according to the color mode value can improve the accuracy of pure color judgment and is applicable to pure color judgment in various scenarios.
[0112] According to a reference embodiment of the present invention, obtaining the color mode value corresponding to the pixel point according to the color mode includes: obtaining the size information of the text image; obtaining the preset pixel format parameters; according to the size information and the pixel format parameters, traversing the pixel points included in the text image in sequence from a preset starting pixel point along a preset direction, and obtaining the color mode value corresponding to the pixel point according to the color mode.
[0113] The size information of the text image includes: the width and height of the text image; the pixel point can correspond to one or more color mode values in different color modes, and the pre-set pixel format parameters include: the number of bits required for each color mode value (that is, how many digits are needed to represent the color mode value. It should be noted that the number of bits required for the color mode values under the same color mode is the same), the number of memory bytes required for a single line in the text image, and the color mode corresponding to the pixel points included in the text image. According to the above information, a color mode value set included in the text image is obtained, and the color mode value set includes color mode values. The color mode values are arranged according to the positions of the pixel points included in the text image; the coordinates and traversal direction of the pre-set starting pixel point are obtained, and the color mode values corresponding to the pixel points are obtained from the corresponding positions of the color mode value set in turn according to the coordinates and traversal direction.
[0114] Exemplarily, the method CGImageGetWidth(imageRef) is used to obtain the width "width" of the text image "imageRef", and the method CGImageGetHeight(imageRef) is used to obtain the height "height" of the text image "imageRef"; the number of bits "bitNum" required for each preset color mode value, the number of memory bytes "byteNum" required for a single line in the text image, and the color mode "rgbMode" corresponding to the pixels included in the text image are obtained, where "rgbMode" represents the RGB color mode; the method CGBitmapContextCreate(imageRef,width,height,bitNum,byteNum,rgbMode) with the above information as parameters is called to obtain the color mode value set including the text image; the preset starting pixel coordinates (0,0) are obtained, and the traversal direction is obtained as "from left to right, from top to bottom", and the color mode values corresponding to the pixels are obtained from the corresponding positions of the color mode value set in turn according to the above coordinates and the traversal direction.
[0115] Acquiring the color mode value according to the pixel format parameter and the size information of the text image can improve the acquisition efficiency and accuracy of the color mode value.
[0116] According to a reference embodiment of the present invention, the color mode is a red, green and blue color mode; judging whether the text image is a pure color based on the color mode value includes: obtaining a target color mode value corresponding to a preset second pixel point; comparing the target color mode value with the color mode values corresponding to the remaining pixel points, and when the target color mode value and the color mode values corresponding to the remaining pixel points are equal, judging that the text image is a pure color.
[0117] When the color mode is a red, green and blue color mode (i.e., RGB color mode), the color mode value is composed of three color values of red, yellow and blue, and the range of each color value is between 0 and 255; a preset starting pixel point is used as a second pixel point, and the color mode value corresponding to the second pixel point is obtained, and the color mode value is used as the target color mode value, and the target color mode value is temporarily stored; according to a preset traversal direction, the color mode value corresponding to the next pixel point is obtained, and it is used as a temporary color mode value, and the red, yellow and blue color values included in the target color mode value are compared with the red, yellow and blue color values corresponding to the temporary color mode value. If they are equal, it is determined that the target color mode value is equal to the temporary color mode value, and the colors presented by the corresponding two pixels are the same, then according to the preset traversal direction, the color mode value corresponding to the next pixel point is obtained, and it is used as a temporary color mode value, and the target color mode value is compared with the temporary color mode value. The set traversal direction is used to obtain the color mode value corresponding to the next pixel point, and use it as a temporary color mode value for comparison until all pixel points are compared or a temporary color mode value that is not equal to one or more of the three color values of red, yellow, and blue included in the target color mode value is obtained; when temporary color mode values with unequal color values are obtained, it is determined that the target color mode value is not equal to the temporary color mode value, and the colors presented by the corresponding two pixel points are different, then it is determined that the text image is not a pure color image, and the target character is not pure text; when all pixel points are compared, it means that the three color values of red, yellow, and blue included in the target color mode value are equal to the remaining temporary color mode values, then it is determined that the colors presented by all pixel points included in the text image are the same, the text image is a pure color image, and the target character is pure text.
[0118] Figure 4 is a schematic diagram of color mode value comparison of a method for plain text detection according to a reference embodiment of the present invention. Figure 4As shown, emoticon 401 is the target character received by an embodiment of the present invention, and a view label is generated based on the target character and converted into a text image 402; the text image 402 includes 9 pixels, and each pixel includes two sets of data, wherein the data enclosed in parentheses indicates the coordinate information of the pixel, and the data enclosed in square brackets indicates the red, yellow, and blue color values of the pixel in the RGB color mode; the preset starting pixel coordinates are obtained as (0,0), and the red, yellow, and blue color values of the pixel in the RGB color mode are [1,3,5] respectively; the preset recognition order is obtained, and the recognition order is "from top to bottom, from left to right", therefore, the coordinates of the next pixel are obtained as (1,0), and the red, yellow, and blue color values of the pixel in the RGB color mode are [2,4,5] respectively, and the two sets of color values are compared to determine that the colors presented by the two pixels are different, so the text image is not a pure color, and the corresponding target character is not a pure text.
[0119] As another example, the acquired text image includes four pixels, namely pixel i, pixel j, pixel k, and pixel l, among which the red, yellow, and blue color values of pixel i in RGB mode are (15, 20, 25) respectively, the red, yellow, and blue color values of pixel j in RGB mode are (15, 20, 25) respectively, the red, yellow, and blue color values of pixel k in RGB mode are (15, 20, 25) respectively, and the red, yellow, and blue color values of pixel l in RGB mode are (15, 20, 25) respectively. By comparing the red, yellow, and blue color values of the above-mentioned pixels, it is obtained that the red, yellow, and blue color values of all pixels are equal, then it is determined that the text image is a solid color image, and then it is determined that the corresponding target character is plain text.
[0120] Determine the target color mode value, and compare the color mode values of the remaining pixels with the target color mode value to judge whether the text image is a pure color. This can improve the accuracy of pure color judgment and is suitable for pure color judgment in various scenarios.
[0121] According to a reference embodiment of the present invention, judging whether the text image is a pure color based on the color mode value includes: converting the color mode value corresponding to the pixel point into a brightness value; taking the brightness value corresponding to a preset first pixel point as a target brightness value; comparing the target brightness value with the brightness values corresponding to the remaining pixel points, and judging that the text image is a pure color when the target brightness value is equal to the brightness values corresponding to the remaining pixel points.
[0122] When the color mode is not the HSB (Hue Saturation Brightness) color mode, a preset method is called to convert the color mode to the HSB color mode, and the brightness value included in the HSB color mode is obtained. The brightness value indicates the brightness of the color, and the value range is between 0 and 100%. The preset starting point coordinates are obtained, and the pixel corresponding to the starting point coordinates is taken as the first pixel, and the brightness value corresponding to the first pixel is obtained, and the brightness value is taken as the target brightness value, and the target brightness value is temporarily stored; according to the preset traversal direction, the brightness value corresponding to the next pixel is obtained, and it is taken as a temporary brightness value, and the target brightness value is compared with the temporary brightness value to see whether they are equal. If they are equal, it is determined that the colors presented by the corresponding two pixels are the same, and then according to the preset traversal direction, the brightness value corresponding to the next pixel is obtained again, and it is used as a temporary brightness value for comparison until all pixels are compared or a temporary brightness value that is not equal to the target brightness value is obtained; if a temporary brightness value that is not equal to the target brightness value is obtained, it is determined that the colors presented by the corresponding two pixels are different, and then it is further determined that the text image is not a pure color image, and the target character is not a pure text; if all pixels are compared, it means that the target brightness value is equal to the remaining temporary brightness values, and then it is determined that the colors presented by all pixels included in the text image are the same, the text image is a pure color image, and the target character is a pure text.
[0123] Exemplarily, the current color mode is the RGB color mode, and the method UIColor uic = [UIColorcolorWithRed:re green:gr blue:bl alpha:1.0f] is called to generate a color object "uic" that stores the color data of the text image, and the color object includes the color mode values "re", "gr", and "bl" corresponding to the RGB color mode; then the method [uic getHues:&hu saturation:&sa brightness:&br alpha:&a] is called to convert the color data included in the color object "uic" into hue "hu", saturation "sa", and brightness "br"; the obtained text image includes four pixels, namely, pixel m, pixel n, pixel o, and pixel p, among which the brightness value of pixel m is 50%, the brightness value of pixel n is 50%, the brightness value of pixel o is 50%, and the brightness value of pixel p is 50%. By comparing the brightness values of the above-mentioned pixel points, it is obtained that the brightness values of all pixel points are equal, then it is determined that the text image is a solid color image, and then it is determined that the corresponding target character is plain text.
[0124] The color mode value is converted into a brightness value, and the text image is judged based on the brightness value whether it is a pure color. Only one value needs to be judged each time, which significantly reduces the number of judgments, can improve the efficiency of pure color judgment, simplify the steps of pure color judgment, and save network resources.
[0125] Figure 5 FIG. 1 is a schematic diagram of the main process of a method for plain text detection according to a reference embodiment of the present invention. Figure 5 As shown, the method for plain text detection may include:
[0126] Step S501, in response to receiving a target character, determining a target text input box corresponding to the target character, and determining a character color of the target character according to a text color attribute of the target text input box;
[0127] Step S502, calling a preset method to generate an initial view tag;
[0128] Step S503, setting the label text attribute to the target character;
[0129] Step S504, setting the label text color attribute and the label background color attribute to the character color;
[0130] Step S505, using the set initial view label as the view label of the target character;
[0131] Step S506, converting the view label into a text image;
[0132] Step S507, determining the color mode corresponding to the pixels included in the text image;
[0133] Step S508, obtaining a color mode value corresponding to the pixel point according to the color mode;
[0134] Step S509, determining whether the color mode values corresponding to each pixel are all equal, if so, jump to step S511, otherwise, jump to step S510;
[0135] Step S510, determining that the text image is not a pure color and the target character is not a pure text;
[0136] Step S511, determining that the text image is a pure color and the target character is a pure text.
[0137] The specific implementation content of the method for plain text detection of the above-mentioned reference embodiment of the present invention has been described in detail in the method for plain text detection described above, so the repeated content will not be described again here.
[0138] Figure 6 FIG. 1 is a schematic diagram of the main process of a method for plain text detection according to another reference embodiment of the present invention. Figure 6 As shown, the method for plain text detection may include:
[0139] Step S601, in response to receiving a target character, determining a target text input box corresponding to the target character, and determining a character color of the target character according to a text color attribute of the target text input box;
[0140] Step S602, calling a preset method to generate an initial view tag;
[0141] Step S603, setting the label text attribute to the target character;
[0142] Step S604, setting the label text color attribute and the label background color attribute to the character color;
[0143] Step S605, using the set initial view label as the view label of the target character;
[0144] Step S606, converting the view label into a text image;
[0145] Step S607, determining that the color mode corresponding to the pixel points included in the text image is a red, green and blue color mode;
[0146] Step S608, determining the target pixel point according to the preset starting coordinates, and taking the color mode value corresponding to the target pixel point as the target color mode value;
[0147] Step S609, comparing the target color mode value with the color mode values corresponding to the remaining pixels;
[0148] Step S610, determining whether the target color mode value is equal to the color mode values corresponding to the other pixels, if so, jump to step S611, otherwise, jump to step S612;
[0149] Step S611, determining that the text image is a solid color and the target character is a solid text;
[0150] Step S612, determining that the text image is not a pure color and the target character is not a pure text;
[0151] Step S613, return a prompt message: "Emoji input is not supported yet, please enter plain text content."
[0152] The specific implementation content of the method for plain text detection of another reference embodiment of the present invention has been described in detail in the method for plain text detection described above, so the repeated content will not be described here.
[0153] Figure 7FIG. 1 is a schematic diagram of the main process of a method for plain text detection according to another reference embodiment of the present invention. Figure 7 As shown, the method for plain text detection may include:
[0154] Step S701, monitoring the text input box on the front page, and acquiring target characters in response to a change in the number of characters monitored;
[0155] Step S702, determine whether the target character is multiple characters, if yes, jump to step S703, otherwise, jump to step S704;
[0156] Step S703, splitting the multiple characters to obtain target characters including a single character;
[0157] Step S704, in response to receiving the target character, determining a target text input box corresponding to the target character, and determining the character color of the target character according to a text color attribute of the target text input box;
[0158] Step S705, calling a preset method to generate an initial view tag;
[0159] Step S706, setting the label text attribute to the target character;
[0160] Step S707, setting the label text color attribute and the label background color attribute to the character color;
[0161] Step S708, using the set initial view label as the view label of the target character;
[0162] Step S709, converting the view label into a text image;
[0163] Step S710, determining that the color mode corresponding to the pixels included in the text image is the RGB color mode;
[0164] Step S711, converting the red, green and blue color values corresponding to the RGB color mode into the hue, saturation and brightness corresponding to the HSB color mode;
[0165] Step S712, determining a target pixel point according to a preset starting coordinate, and taking a brightness value corresponding to the target pixel point as a target brightness value;
[0166] Step S713, comparing the target brightness value with the brightness values corresponding to the remaining pixels;
[0167] Step S714, determining whether the target brightness value is equal to the brightness values corresponding to the remaining pixels, if so, jump to step S715, otherwise, jump to step S716;
[0168] Step S715, determining that the text image is a solid color and the target character is a solid text;
[0169] Step S716, determining that the text image is not a pure color and the target character is not a pure text;
[0170] Step S717, return a prompt message: "Emoji input is not supported yet, please enter plain text content."
[0171] The specific implementation content of the method for plain text detection of another reference embodiment of the present invention has been described in detail in the method for plain text detection described above, so the repeated content will not be described here.
[0172] According to a second aspect of an embodiment of the present invention, a device for plain text detection is provided.
[0173] Figure 8 is a schematic diagram of main modules of a device for plain text detection according to an embodiment of the present invention, such as Figure 8 As shown, the apparatus 800 for plain text detection mainly includes:
[0174] A generating module 801 is used for determining the character color of the target character in response to receiving the target character, and obtaining a view label including the target character according to the character color;
[0175] A conversion module 802, used to convert the view label into a text image;
[0176] The recognition module 803 is used to recognize whether the text image is a pure color, and determine that the target character is a pure text when the text image is a pure color.
[0177] According to a reference embodiment of the present invention, obtaining a view label including the target character according to the character color includes:
[0178] Calling a preset generation method to generate an initial view label, wherein the initial view label includes a label text attribute, a label text color attribute, and a label background color attribute;
[0179] Setting the label text attribute to the target character;
[0180] Set the label text color attribute and label background color attribute to the character color;
[0181] The set initial view label is used as the view label of the target character.
[0182] According to another reference embodiment of the present invention, identifying whether the text image is a pure color includes:
[0183] Determine the color mode corresponding to the pixels included in the text image;
[0184] Acquire a color mode value corresponding to the pixel point according to the color mode;
[0185] Determine whether the text image is a pure color according to the color mode value.
[0186] According to another reference embodiment of the present invention, obtaining a color mode value corresponding to the pixel point according to the color mode includes:
[0187] Obtaining size information of the text image;
[0188] Get the preset pixel format parameters;
[0189] According to the size information and the pixel format parameters, the pixel points included in the text image are traversed in sequence from a preset starting pixel point along a preset direction, and the color mode value corresponding to the pixel point is obtained according to the color mode.
[0190] According to another reference embodiment of the present invention, judging whether the text image is a pure color according to the color mode value includes:
[0191] Convert the color mode value corresponding to the pixel point into a brightness value;
[0192] The brightness value corresponding to the preset first pixel point is used as the target brightness value;
[0193] The target brightness value is compared with the brightness values corresponding to the remaining pixels. When the target brightness value and the brightness values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
[0194] According to another reference embodiment of the present invention, the color mode is a red, green, and blue color mode; judging whether the text image is a pure color according to the color mode value includes:
[0195] Obtaining a preset target color mode value corresponding to a second pixel point;
[0196] The target color mode value is compared with the color mode values corresponding to the remaining pixels. When the target color mode value and the color mode values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
[0197] According to a reference embodiment of the present invention, the apparatus 800 for detecting plain text further includes:
[0198] A determination module, used for determining whether the target character is a single character;
[0199] The splitting module is used for splitting the multiple characters to obtain the target character including a single character when the target character includes multiple characters.
[0200] It should be noted that the specific implementation content of the apparatus for plain text detection in the embodiment of the present invention has been described in detail in the method for plain text detection described above, so the repeated content will not be described again here.
[0201] According to the technical solution of the embodiment of the present invention, a view label including a target character is obtained according to the character color, the view label is converted into a text image, and the target character is determined to be pure text when the text image is a pure color, which can improve the accuracy and universal applicability of pure text detection and avoid the inability to recognize emoticons due to frequent updates; an initial view label is generated, and the label text attribute is set according to the target character, and the label text color and label background color are set according to the character color, which can improve the generation efficiency of the target character and facilitate the subsequent pure text detection according to color; the color mode value corresponding to the pixel point included in the text image is obtained, and whether the text image is a pure color is determined according to the color mode value, which can improve the accuracy of pure color determination and is applicable to pure color determination in various scenarios; according to Obtaining the color mode value based on the pixel format parameters and the size information of the text image can improve the efficiency and accuracy of obtaining the color mode value; converting the color mode value into a brightness value, and judging whether the text image is a pure color based on the brightness value can improve the efficiency of pure color judgment, simplify the steps of pure color judgment, and save network resources; determining the target color mode value, and comparing the color mode values of the remaining pixels with the target color mode value to judge whether the text image is a pure color can improve the accuracy of pure color judgment, and is suitable for pure color judgment in various scenarios; when the target field includes multiple characters, splitting the multiple characters to obtain a target character including a single character can ensure that only a single character is detected as pure text each time, and effectively identify the specific location of non-pure text content.
[0202] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for plain text detection, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided by the first aspect of the embodiment of the present invention.
[0203] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
[0204] Fig. 9 An exemplary system architecture 900 is shown to which the method for plain text detection or the apparatus for plain text detection according to the embodiments of the present invention can be applied.
[0205] like Fig. 9 As shown, system architecture 900 may include terminal devices 901, 902, 903, network 904 and server 905. Network 904 is used to provide a medium for communication links between terminal devices 901, 902, 903 and server 905. Network 904 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0206] The user can use the terminal devices 901, 902, 903 to interact with the server 905 through the network 904 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 901, 902, 903, such as plain text detection applications, plain text judgment applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0207] The terminal devices 901 , 902 , and 903 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0208] The server 905 may be a server that provides various services, such as a background management server (only an example) that provides support for the request for plain text detection sent by the upstream terminal devices 901, 902, and 903. In response to receiving the target character, the background management server may determine the character color of the target character, obtain a view label including the target character according to the character color; convert the view label into a text image; identify whether the text image is a pure color, and determine that the target character is plain text if the text image is a pure color; and feed back the plain text detection situation (only an example) to the terminal device.
[0209] It should be noted that the method for plain text detection provided in the embodiment of the present invention is generally executed by the server 905, and accordingly, the apparatus for plain text detection is generally set in the server 905. The method for plain text detection provided in the embodiment of the present invention can also be executed by the terminal devices 901, 902, and 903, and accordingly, the apparatus for plain text detection can be set in the terminal devices 901, 902, and 903.
[0210] It should be understood that Fig. 9 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0211] Reference below Fig.10 , which shows a schematic diagram of the structure of a computer system 1000 of a terminal device suitable for implementing an embodiment of the present invention. Fig.10The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0212] like Fig.10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage portion 908 into a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for the operation of the system 1000 are also stored. The CPU 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0213] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage section 1008 as needed.
[0214] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1009, and / or installed from the removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, the above-mentioned functions defined in the system of the embodiment of the present invention are executed.
[0215] It should be noted that the computer-readable medium shown in the embodiment of the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In an embodiment of the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0216] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0217] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, they may be described as: a processor includes a generation module, a conversion module, and a recognition module, wherein the names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the conversion module may also be described as a "module for converting a view label into a text image".
[0218] As another aspect, an embodiment of the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device implements the following method: in response to receiving a target character, determining the character color of the target character, obtaining a view label including the target character according to the character color; converting the view label into a text image; identifying whether the text image is a pure color, and determining that the target character is pure text when the text image is a pure color.
[0219] According to the technical solution of the embodiment of the present invention, a view label including a target character is obtained according to the character color, the view label is converted into a text image, and the target character is determined to be pure text when the text image is a pure color, which can improve the accuracy and universal applicability of pure text detection and avoid the inability to recognize emoticons due to frequent updates; an initial view label is generated, and the label text attribute is set according to the target character, and the label text color and label background color are set according to the character color, which can improve the generation efficiency of the target character and facilitate the subsequent pure text detection according to color; the color mode value corresponding to the pixel point included in the text image is obtained, and whether the text image is a pure color is determined according to the color mode value, which can improve the accuracy of pure color determination and is applicable to pure color determination in various scenarios; according to Obtaining the color mode value based on the pixel format parameters and the size information of the text image can improve the efficiency and accuracy of obtaining the color mode value; converting the color mode value into a brightness value, and judging whether the text image is a pure color based on the brightness value can improve the efficiency of pure color judgment, simplify the steps of pure color judgment, and save network resources; determining the target color mode value, and comparing the color mode values of the remaining pixels with the target color mode value to judge whether the text image is a pure color can improve the accuracy of pure color judgment, and is suitable for pure color judgment in various scenarios; when the target field includes multiple characters, splitting the multiple characters to obtain a target character including a single character can ensure that only a single character is detected as pure text each time, and effectively identify the specific location of non-pure text content.
[0220] The above specific implementations do not constitute a limitation on the protection scope of the embodiments of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the embodiments of the present invention should be included in the protection scope of the embodiments of the present invention.
Claims
1. A method for plain text detection, characterized in that: include: In response to receiving a target character, determining a character color of the target character, and obtaining a view label including the target character according to the character color; Converting the view label into a text image; It is identified whether the text image is a pure color, and when the text image is a pure color, it is determined that the target character is a pure text.
2. The method according to claim 1, characterized in that Obtaining a view label including the target character according to the character color, including: Calling a preset generation method to generate an initial view label, wherein the initial view label includes a label text attribute, a label text color attribute, and a label background color attribute; Setting the label text attribute to the target character; Set the label text color attribute and label background color attribute to the character color; The set initial view label is used as the view label of the target character.
3. The method according to claim 1, characterized in that Identifying whether the text image is a solid color includes: Determine the color mode corresponding to the pixels included in the text image; Acquire the color mode value corresponding to the pixel point according to the color mode; Determine whether the text image is a pure color according to the color mode value.
4. The method according to claim 3, characterized in that Acquiring a color mode value corresponding to the pixel point according to the color mode includes: Obtaining size information of the text image; Get the preset pixel format parameters; According to the size information and the pixel format parameters, the pixel points included in the text image are traversed in sequence from a preset starting pixel point along a preset direction, and the color mode value corresponding to the pixel point is obtained according to the color mode.
5. The method according to claim 3, characterized in that: Judging whether the text image is a pure color according to the color mode value includes: Convert the color mode value corresponding to the pixel point into a brightness value; The brightness value corresponding to the preset first pixel point is used as the target brightness value; The target brightness value is compared with the brightness values corresponding to the remaining pixels. When the target brightness value and the brightness values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
6. The method according to claim 3, characterized in that: The color mode is a red, green and blue color mode; judging whether the text image is a pure color according to the color mode value includes: Obtaining a preset target color mode value corresponding to a second pixel point; The target color mode value is compared with the color mode values corresponding to the remaining pixels. When the target color mode value and the color mode values corresponding to the remaining pixels are equal, it is determined that the text image is a pure color.
7. The method according to claim 1, characterized in that Before determining the character color of the target character, the method further includes: Determine whether the target character is a single character; In the case that the target character includes multiple characters, the multiple characters are split to obtain a target character including a single character.
8. A device for plain text detection, characterized in that: include: A generating module, configured to determine the character color of the target character in response to receiving the target character, and obtain a view label including the target character according to the character color; A conversion module, used for converting the view label into a text image; The recognition module is used to recognize whether the text image is a pure color, and determine that the target character is a pure text when the text image is a pure color.
9. An electronic device, characterized in that: include: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Image-text drawing method and device, computer readable storage medium and computer device
CN109933751A
Text information display method and device, electronic equipment and storage medium
CN114895827A
Emoticon prediction method and device, equipment and storage medium
CN115424266A
Information processing apparatus, information processing method and storage medium
US20090284786A1
