Image key text extraction method and device
Through the combination of text detection and recognition models, screening and cropping techniques, the accuracy of key text extraction under complex backgrounds in advertising videos is solved, the recognition and extraction efficiency is improved, and it is suitable for efficient publicity logo generation.
Patent Information
- Application Number
- CN202410917875.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-01
AI Technical Summary
The prior art is difficult to accurately extract key text when processing complex backgrounds and diverse highlighted text in advertising videos, resulting in low recognition accuracy and extraction efficiency.
By entering the image into the pre-trained text detection model, the text detection area is extracted, and the key text areas that meet the color conditions are further filtered from the text area, and input it into the text recognition model for identification, reducing background interference and improving the determination of text areas. Sex and the accuracy of recognition of keywords.
It improves the accuracy of key text extraction in the image, enhances the efficiency and accuracy of understanding of video content and the generation of publicity logos.
Smart Images

Figure CN118887649A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image recognition, and in particular to a method and device for extracting key text from an image. Background Art
[0002] The text information in the advertising video can intuitively display the promotional purpose of the advertising video. In order to promote the promotion of the product, in the advertising video, the key sentences in the subtitles that can attract the attention of consumers are usually displayed in a different color (for example, highlight color) from other subtitle contents, such as highlighting text, to highlight the selling point of the product and promote the product more efficiently.
[0003] In the prior art, text recognition is usually performed on image frames in a video based on technologies such as OCR (Optical Character Recognition). However, in actual applications, advertising videos usually have complex and changeable backgrounds, a large amount of text information and different text positions, and a variety of highlight colors, which increases the difficulty of recognizing text in the video screen and makes it difficult to accurately extract key text in the screen. Therefore, it is particularly important to provide a technical solution that can improve the accuracy of extracting key text in an image. Summary of the invention
[0004] The present invention provides a method and device for extracting key text from an image, which can improve the accuracy of extracting key text from an image.
[0005] In order to solve the above technical problems, the first aspect of the present invention discloses a method for extracting key text from an image, the method comprising:
[0006] Inputting the acquired image into a pre-trained text detection model to obtain a text detection result; the text detection result includes a text detection area corresponding to at least one text line contained in the image;
[0007] Extracting a text area image corresponding to each text line from the image according to the text detection result;
[0008] Extracting a key text image corresponding to each text line from the text area image corresponding to the text line; the key text image includes a key text area that meets the determined color condition;
[0009] Each of the key text images is input into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image; the key text recognition result includes the key text information contained in the image.
[0010] As an optional implementation manner, in the first aspect of the present invention, extracting the key text image corresponding to each text line from the text area image corresponding to the text line includes:
[0011] Filtering out an area satisfying the determined color condition from the text area image corresponding to each of the text lines as a key text area of the text area image;
[0012] Based on the key text area of each of the text area images, a key text image corresponding to each of the text lines is determined.
[0013] As an optional implementation manner, in the first aspect of the present invention, the step of selecting an area satisfying the determined color condition from the text area image corresponding to each of the text lines as a key text area of the text area image includes:
[0014] For each of the text lines, inputting the text area image corresponding to the text line into the text recognition model to obtain a text recognition result corresponding to the text line;
[0015] For each of the text lines, a segmentation operation is performed on the text area image corresponding to the text line according to the text recognition result corresponding to the text line, so as to obtain a segmentation result corresponding to the text area image; the segmentation result corresponding to the text area image includes a character area corresponding to each of the characters contained in the text line;
[0016] For each of the text lines, at least one character area satisfying the determined area color condition is screened out from all the character areas corresponding to the text line as a key text area of the text area image.
[0017] As an optional implementation, in the first aspect of the present invention, the text recognition result corresponding to each of the text lines includes the text information contained in the text line; the text information contained in each of the text lines includes at least one character and the character type of each of the characters;
[0018] Wherein, for each of the text lines, performing a segmentation operation on the text area image corresponding to the text line according to the text recognition result corresponding to the text line to obtain a segmentation result corresponding to the text area image includes:
[0019] Acquire preset character span information; the character span information includes a preset span corresponding to each character type;
[0020] Determining the character span of each of the characters according to the character type of each of the characters and the character span information;
[0021] According to the character span of each of the characters, a segmentation operation is performed on the text area image corresponding to the text line to obtain a character area corresponding to each of the characters contained in the text line.
[0022] As an optional implementation, in the first aspect of the present invention, for each of the text lines, the step of selecting at least one character area satisfying the determined area color condition from all the character areas corresponding to the text line as a key text area of the text area image includes:
[0023] Counting the pixel mean of each character area corresponding to the text line;
[0024] For each of the character regions, determining whether the pixel mean value of the character region is within the determined region pixel value range;
[0025] For each of the character regions, when it is determined that the pixel mean value of the character region is within the pixel value range of the region, the character region is determined to be a key character region;
[0026] For each of the character regions, when it is determined that the pixel mean value of the character region is not within the pixel value range of the region, the character region is determined to be a non-key character region;
[0027] The key text area of the text area image corresponding to the text line includes all the key character areas.
[0028] As an optional implementation, in the first aspect of the present invention, extracting the text area image corresponding to each text line from the image according to the text detection result includes:
[0029] For each of the text lines, cropping the image according to the text detection area corresponding to the text line to obtain a cropped image corresponding to the text line;
[0030] For each of the text lines, based on the determined region extraction method, determine the background region in the cropped image corresponding to the text line; the region extraction method includes a contour extraction method or a connected domain extraction method;
[0031] For each of the text lines, the background area is filtered from the cropped image corresponding to the text line to obtain a text area image corresponding to the text line; the text area image includes the text area corresponding to the text line.
[0032] As an optional implementation manner, in the first aspect of the present invention, for each of the text lines, determining the background area in the cropped image corresponding to the text line based on the determined area extraction method includes:
[0033] Performing grayscale value processing on the cropped image corresponding to the text line to obtain a cropped grayscale image corresponding to the text line;
[0034] When the determined region extraction method is the contour extraction method, the contour information of the cropped grayscale image corresponding to the text line is counted; the contour information includes at least one contour and a first number of pixels occupied by the enclosed area of each contour;
[0035] For each of the contours, calculating a first pixel ratio of an enclosed area of the contour in the cropped grayscale image according to the first number of pixels;
[0036] For each of the contours, when the first pixel ratio is greater than a first preset pixel ratio, determining the enclosed area of the contour as a background area; or,
[0037] When the determined region extraction method is the connected domain extraction method, the connected domain information of the cropped grayscale image corresponding to the text line is determined according to pixel connectivity; the pixel connectivity includes four-connectivity of pixels or eight-connectivity of pixels; the connected domain information includes at least one connected domain, a connected domain identifier of each of the connected domains, and the number of second pixels occupied by each of the connected domains;
[0038] For each of the connected domains, calculating a second pixel ratio of the connected domain in the cropped grayscale image according to the second number of pixels;
[0039] For each of the connected domains, when the second pixel ratio is greater than a second preset pixel ratio, the connected domain is determined as a background area.
[0040] The second aspect of the present invention discloses a device for extracting key text from an image, the device comprising:
[0041] An input module, used to input the acquired image into a pre-trained text detection model to obtain a text detection result; the text detection result includes a text detection area corresponding to at least one text line contained in the image;
[0042] An extraction module, used for extracting a text area image corresponding to each text line from the image according to the text detection result;
[0043] The extraction module is further used to extract a key text image corresponding to each text line from the text area image corresponding to the text line; the key text image includes a key text area that meets the determined color condition;
[0044] The input module is further used to input each of the key text images into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image; the key text recognition result includes the key text information contained in the image.
[0045] As an optional implementation, in the second aspect of the present invention, the specific manner in which the extraction module extracts the key text image corresponding to each text line from the text area image corresponding to the text line includes:
[0046] Filtering out an area satisfying the determined color condition from the text area image corresponding to each of the text lines as a key text area of the text area image;
[0047] Based on the key text area of each of the text area images, a key text image corresponding to each of the text lines is determined.
[0048] As an optional implementation, in the second aspect of the present invention, the extraction module selects an area satisfying the determined color condition from the text area image corresponding to each text line, and the specific method of selecting the key text area of the text area image includes:
[0049] For each of the text lines, inputting the text area image corresponding to the text line into the text recognition model to obtain a text recognition result corresponding to the text line;
[0050] For each of the text lines, a segmentation operation is performed on the text area image corresponding to the text line according to the text recognition result corresponding to the text line, so as to obtain a segmentation result corresponding to the text area image; the segmentation result corresponding to the text area image includes a character area corresponding to each of the characters contained in the text line;
[0051] For each of the text lines, at least one character area satisfying the determined area color condition is screened out from all the character areas corresponding to the text line as a key text area of the text area image.
[0052] As an optional implementation, in the second aspect of the present invention, the text recognition result corresponding to each of the text lines includes the text information contained in the text line; the text information contained in each of the text lines includes at least one character and the character type of each of the characters;
[0053] For each of the text lines, the extraction module performs a segmentation operation on the text area image corresponding to the text line according to the text recognition result corresponding to the text line, and the specific method of obtaining the segmentation result corresponding to the text area image includes:
[0054] Acquire preset character span information; the character span information includes a preset span corresponding to each character type;
[0055] Determining the character span of each of the characters according to the character type of each of the characters and the character span information;
[0056] According to the character span of each of the characters, a segmentation operation is performed on the text area image corresponding to the text line to obtain a character area corresponding to each of the characters contained in the text line.
[0057] As an optional implementation, in the second aspect of the present invention, for each of the text lines, the extraction module selects at least one character area that satisfies the determined area color condition from all the character areas corresponding to the text line, and the specific manner of using the key text area of the text area image includes:
[0058] Counting the pixel mean of each character area corresponding to the text line;
[0059] For each of the character regions, determining whether the pixel mean value of the character region is within the determined region pixel value range;
[0060] For each of the character regions, when it is determined that the pixel mean value of the character region is within the pixel value range of the region, the character region is determined to be a key character region;
[0061] For each of the character regions, when it is determined that the pixel mean value of the character region is not within the pixel value range of the region, the character region is determined to be a non-key character region;
[0062] The key text area of the text area image corresponding to the text line includes all the key character areas.
[0063] As an optional implementation, in the second aspect of the present invention, the specific manner in which the extraction module extracts the text area image corresponding to each text line from the image according to the text detection result includes:
[0064] For each of the text lines, cropping the image according to the text detection area corresponding to the text line to obtain a cropped image corresponding to the text line;
[0065] For each of the text lines, based on the determined region extraction method, determine the background region in the cropped image corresponding to the text line; the region extraction method includes a contour extraction method or a connected domain extraction method;
[0066] For each of the text lines, the background area is filtered from the cropped image corresponding to the text line to obtain a text area image corresponding to the text line; the text area image includes the text area corresponding to the text line.
[0067] As an optional implementation, in the second aspect of the present invention, for each of the text lines, the extraction module determines the background area in the cropped image corresponding to the text line based on the determined area extraction method. The specific method includes:
[0068] Performing grayscale value processing on the cropped image corresponding to the text line to obtain a cropped grayscale image corresponding to the text line;
[0069] When the determined region extraction method is the contour extraction method, the contour information of the cropped grayscale image corresponding to the text line is counted; the contour information includes at least one contour and a first number of pixels occupied by the enclosed area of each contour;
[0070] For each of the contours, calculating a first pixel ratio of an enclosed area of the contour in the cropped grayscale image according to the first number of pixels;
[0071] For each of the contours, when the first pixel ratio is greater than a first preset pixel ratio, determining the enclosed area of the contour as a background area; or,
[0072] When the determined region extraction method is the connected domain extraction method, the connected domain information of the cropped grayscale image corresponding to the text line is determined according to pixel connectivity; the pixel connectivity includes four-connectivity of pixels or eight-connectivity of pixels; the connected domain information includes at least one connected domain, a connected domain identifier of each of the connected domains, and the number of second pixels occupied by each of the connected domains;
[0073] For each of the connected domains, calculating a second pixel ratio of the connected domain in the cropped grayscale image according to the second number of pixels;
[0074] For each of the connected domains, when the second pixel ratio is greater than a second preset pixel ratio, the connected domain is determined as a background area.
[0075] The third aspect of the present invention discloses another device for extracting key text from an image, the device comprising:
[0076] A memory storing executable program code;
[0077] a processor coupled to the memory;
[0078] The processor calls the executable program code stored in the memory to execute the method for extracting key text from an image disclosed in the first aspect of the present invention.
[0079] The fourth aspect of the present invention discloses a computer storage medium, wherein the computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the method for extracting key text from an image disclosed in the first aspect of the present invention.
[0080] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0081] In an embodiment of the present invention, an acquired image is input into a pre-trained text detection model to obtain a text detection result; the text detection result includes a text detection area corresponding to at least one text line contained in the image; based on the text detection result, a text area image corresponding to each text line is extracted from the image; a key text image corresponding to each text line is extracted from the text area image corresponding to the text line; the key text image includes a key text area that meets a determined color condition; each key text image is input into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image; the key text recognition result includes the key text information contained in the image. It can be seen that the implementation of the present invention can input the acquired image into a pre-trained text detection model to obtain a text detection result, and then extract the text area image corresponding to each text line from the image according to the text detection result, and then extract the key text image including the key text area that meets the color condition from the text area image corresponding to each text line, and then input each key text image into the pre-trained text recognition model to obtain the key text recognition result, and can crop the image area where the text is located through the text detection technology, reduce the interference of the remaining background area on the recognized text, and improve the determination accuracy of the text area, which is conducive to improving the recognition accuracy of the text; and, by screening out the text area that meets the color condition from the image, it is possible to improve the screening accuracy of the key text area in the image, thereby improving the recognition accuracy of the key characters, and then improving the extraction accuracy of the key text in the image, which is conducive to improving the accuracy of understanding the content of the image or video, and then It is conducive to efficiently generating a promotional logo for the content of the image or video based on the key text information, and can promote the content of the image or video more efficiently and accurately. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0083] Figure 1It is a flow chart of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0084] Figure 2 It is a flowchart of another method for extracting key text from an image disclosed in an embodiment of the present invention;
[0085] Figure 3 It is a cropped image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0086] Figure 4 It is a cropped grayscale image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0087] Figure 5 It is a text area image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0088] Figure 6 It is a segmentation result corresponding to a text area image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0089] Figure 7 It is a key text image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0090] Figure 8 It is a structural schematic diagram of a device for extracting key text from an image disclosed in an embodiment of the present invention;
[0091] Fig. 9 It is a structural schematic diagram of another device for extracting key text from an image disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0092] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0093] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or end including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or ends.
[0094] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0095] The present invention discloses a method and device for extracting key text from an image, which can input an acquired image into a pre-trained text detection model to obtain a text detection result, then extract a text area image corresponding to each text line from the image according to the text detection result, then extract a key text image including a key text area that meets a color condition from the text area image corresponding to each text line, and then input each key text image into a pre-trained text recognition model to obtain a key text recognition result, and can crop the image area where the text is located through text detection technology, reduce the interference of the remaining background area on the recognized text, and improve the accuracy of determining the text area, which is conducive to improving the recognition accuracy of the text; and, by screening out the text area that meets the color condition from the image, the screening accuracy of the key text area in the image can be improved, thereby improving the recognition accuracy of the key characters, and then improving the extraction accuracy of the key text in the image, which is conducive to improving the accuracy of understanding the content of the image or video, and then is conducive to efficiently generating a promotional logo for the content of the image or video based on the key text information, and can more efficiently and accurately promote the content of the image or video. The following are detailed descriptions.
[0096] Embodiment 1
[0097] See also Figure 1 , Figure 1 : is a flow chart of a method for extracting key text from an image disclosed in an embodiment of the present invention. Figure 1 The described method for extracting key text from an image can be applied to an apparatus for extracting key text from an image, which apparatus may include one of a text extraction device, a text extraction terminal, a text extraction system, and a server, wherein the server may be a local server or a cloud server, which is not limited in the embodiments of the present invention. Figure 1 As shown, the method for extracting key text of the image may include the following operations:
[0098] 101. Input the acquired image into a pre-trained text detection model to obtain a text detection result.
[0099] In the embodiment of the present invention, optionally, the above-mentioned image may be any image frame in the video data, or may be a photo, or may be other types of image data, which is not limited in the embodiment of the present invention.
[0100] In the embodiment of the present invention, the text detection model is used to detect the area where the text is located in the image.
[0101] In an embodiment of the present invention, the text detection result may include a text detection area corresponding to at least one text line contained in the image; optionally, the text detection result may also include a detection box corresponding to each text detection area. Further optionally, a minimum rectangular box is usually used to frame the image area where the text is located, which is not limited by the embodiment of the present invention; further, each detection box corresponds to at least two detection box coordinates, and optionally, each detection box coordinate may be one of the upper left vertex coordinate, the lower left vertex coordinate, the upper right vertex coordinate and the lower right vertex coordinate, which is not limited by the embodiment of the present invention; further optionally, each detection box coordinate may include an x-coordinate and a y-coordinate, which is not limited by the embodiment of the present invention.
[0102] 102. According to the text detection result, extract the text area image corresponding to each text line from the image.
[0103] In the embodiment of the present invention, the text area image corresponding to each text line includes the text area corresponding to the text line. Further, the text area image does not include the background area.
[0104] 103. Extract a key text image corresponding to each text line from the text area image corresponding to the text line.
[0105] In the embodiment of the present invention, the key text image corresponding to each text line includes a key text area that meets the determined color condition. Optionally, the key text area may include key text in a highlighted color, such as highlighted yellow text, which is not limited in the embodiment of the present invention.
[0106] 104. Input each key text image into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image.
[0107] In the embodiment of the present invention, the text recognition model is used to recognize text information in an image.
[0108] In an embodiment of the present invention, optionally, the text detection model in step 101 and the text recognition model in step 104 can be integrated into the same text detection and recognition model. Exemplarily, the text detection and recognition model can be an OCR (Optical Character Recognition) model. The text detection model in step 101 and the text recognition model in step 104 may not be integrated into the same model, that is, they may be two models respectively, which is not limited in the embodiment of the present invention.
[0109] In an embodiment of the present invention, the key text recognition result corresponding to the image includes the key text information contained in the image; wherein the key text information includes at least one key character; illustratively, the key character may be a highlighted character that meets the color condition and / or a character whose color is obviously different from that of characters in other areas, which is not limited in the embodiment of the present invention. Optionally, the key text information may be used as a basis for generating a label and / or title and / or promotional logo for video data or image data, which is not limited in the embodiment of the present invention.
[0110] It can be seen that the method described in the embodiment of the present invention can input the acquired image into a pre-trained text detection model to obtain a text detection result, and then extract the text area image corresponding to each text line from the image according to the text detection result, and then extract the key text image including the key text area that meets the color condition from the text area image corresponding to each text line, and then input each key text image into the pre-trained text recognition model to obtain the key text recognition result, and can crop the image area where the text is located through the text detection technology, reduce the interference of the remaining background area on the recognized text, and improve the accuracy of determining the text area, which is conducive to improving the recognition accuracy of the text; and, by screening out the text area that meets the color condition from the image, it is possible to improve the screening accuracy of the key text area in the image, thereby improving the recognition accuracy of the key characters, and then improving the extraction accuracy of the key text in the image, which is conducive to improving the accuracy of understanding the content of the image or video, and then It is conducive to efficiently generating a promotional logo for the content of the image or video based on the key text information, and can promote the content of the image or video more efficiently and accurately.
[0111] In an optional embodiment, extracting the text area image corresponding to each text line from the image according to the text detection result may include the following operations:
[0112] For each text line, the image is cropped according to the text detection area corresponding to the text line to obtain a cropped image corresponding to the text line;
[0113] For each text line, based on the determined region extraction method, determine the background region in the cropped image corresponding to the text line; the region extraction method includes a contour extraction method or a connected domain extraction method;
[0114] For each text line, the background area is filtered from the cropped image corresponding to the text line to obtain a text area image corresponding to the text line; the text area image includes the text area corresponding to the text line.
[0115] Specifically, the image may be cropped based on at least two detection frame coordinates of the detection frame corresponding to the text detection area to obtain a cropped image corresponding to the text line, which is not limited in the embodiment of the present invention.
[0116] Optionally, the cropped image corresponding to each text line may be an RGB format image or an image in other color formats, which is not limited in the embodiment of the present invention.
[0117] After filtering out the corresponding background area from the cropped image corresponding to each text line, the text area corresponding to the text line remains in the image, so the text area image corresponding to the text line includes the text area.
[0118] It can be seen that this optional embodiment can crop the image according to the text detection area corresponding to each text line to obtain a cropped image corresponding to the text line, and then determine the background area in the cropped image based on the contour extraction method or the connected domain extraction method to filter the background area to obtain the text area image corresponding to the text line, which can improve the cropping efficiency and cropping accuracy of the text line image, as well as improve the filtering flexibility and filtering accuracy of the background area, thereby improving the determination efficiency and determination accuracy of the text area image.
[0119] In this optional embodiment, optionally, for each text line, based on the determined region extraction method, determining the background region in the cropped image corresponding to the text line may include the following operations:
[0120] Performing grayscale value processing on the cropped image corresponding to the text line to obtain a cropped grayscale image corresponding to the text line;
[0121] When the determined region extraction method is a contour extraction method, the contour information of the cropped grayscale image corresponding to the text line is counted; the contour information includes at least one contour and a first number of pixels occupied by the enclosed area of each contour;
[0122] For each contour, according to the first number of pixels, calculate the first pixel ratio of the enclosed area of the contour in the cropped grayscale image;
[0123] For each contour, when the first pixel ratio is greater than the first preset pixel ratio, the enclosed area of the contour is determined as the background area; or,
[0124] When the determined region extraction method is a connected domain extraction method, connected domain information of the cropped grayscale image corresponding to the text line is determined according to pixel connectivity; the pixel connectivity includes four-connectivity of pixels or eight-connectivity of pixels; the connected domain information includes at least one connected domain, a connected domain identifier of each connected domain, and the number of second pixels occupied by each connected domain;
[0125] For each connected domain, according to the second pixel number, calculate the proportion of the second pixels of the connected domain in the cropped grayscale image;
[0126] For each connected domain, when the second pixel ratio is greater than the second preset pixel ratio, the connected domain is determined as a background area.
[0127] Among them, the first number of pixels occupied by the enclosed area of each contour is the number of pixels occupied by the enclosed area of the contour in the cropped grayscale image; optionally, the contour information of the cropped grayscale image may also include the number of contours, which is not limited in the embodiment of the present invention.
[0128] Among them, the numerical value of the first preset pixel ratio and the numerical value of the second preset pixel ratio may be the same or different, and the embodiment of the present invention does not limit it; illustratively, the first preset pixel ratio may be 30%, the second preset pixel ratio may also be 30%, and the second preset pixel ratio may also be other numerical values, and the embodiment of the present invention does not limit it.
[0129] The connected domain identifier of each connected domain may be unique.
[0130] It can be seen that this optional embodiment can also first perform grayscale value processing on the cropped image to obtain a cropped grayscale image corresponding to each text line. When the area extraction method is a contour extraction method, the contour information of the cropped grayscale image is counted, and then the first pixel ratio of the area surrounded by each contour is calculated. If the first pixel ratio is greater than the first preset pixel ratio, the area surrounded by the contour is determined as the background area. Or when the area extraction method is a connected domain extraction method, the connected domain information of the cropped grayscale image is counted, and then the second pixel ratio of each connected domain is calculated. If the second pixel ratio is greater than the second preset pixel ratio, the connected domain is determined as the background area. This can improve the determination accuracy and determination flexibility of the background area in the image, thereby improving the filtering accuracy of the background area, which is beneficial to improving the determination accuracy of the text area, and is beneficial to further improving the determination accuracy of the text area image.
[0131] Embodiment 2
[0132] See also Figure 2 , Figure 2 : is a flow chart of a method for extracting key text from an image disclosed in an embodiment of the present invention. Figure 2 The described method for extracting key text from an image can be applied to an apparatus for extracting key text from an image, which apparatus may include one of a text extraction device, a text extraction terminal, a text extraction system, and a server, wherein the server may be a local server or a cloud server, which is not limited in the embodiments of the present invention. Figure 2 As shown, the method for extracting key text of the image may include the following operations:
[0133] 201. Input the acquired image into a pre-trained text detection model to obtain a text detection result.
[0134] In the embodiment of the present invention, the text detection result includes a text detection area corresponding to at least one text line contained in the image.
[0135] 202. According to the text detection result, extract the text area image corresponding to each text line from the image.
[0136] 203. Filter out a region satisfying the determined color condition from the text region image corresponding to each text line as a key text region of the text region image.
[0137] 204. Determine a key text image corresponding to each text line based on the key text area of each text area image.
[0138] In the embodiment of the present invention, the key text image includes a key text area that meets the determined color condition.
[0139] 205. Input each key text image into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image.
[0140] In the embodiment of the present invention, the key text recognition result includes key text information contained in the image.
[0141] In the embodiment of the present invention, for other detailed descriptions of step 201-step 202 and step 205, please refer to the detailed description of step 101-step 102 and step 104 in the first embodiment, and the embodiment of the present invention will not be repeated here.
[0142] It can be seen that the method described in the embodiment of the present invention can input the acquired image into a pre-trained text detection model to obtain a text detection result, and then extract the text area image corresponding to each text line from the image according to the text detection result, and then extract the key text image including the key text area that meets the color condition from the text area image corresponding to each text line, and then input each key text image into the pre-trained text recognition model to obtain the key text recognition result, and can crop the image area where the text is located through the text detection technology, reduce the interference of the remaining background area on the recognized text, and improve the accuracy of determining the text area, which is conducive to improving the recognition accuracy of the text; and, by screening out the text area that meets the color condition from the image, it is possible to improve the screening accuracy of the key text area in the image, thereby improving the recognition accuracy of the key characters, and then improving the extraction accuracy of the key text in the image, which is conducive to improving the accuracy of understanding the content of the image or video, and then It is conducive to efficiently generating a promotional logo for the content of the image or video based on the key text information, and can promote the content of the image or video more efficiently and accurately. In addition, it is also possible to first filter out the key text areas that meet the color conditions from the text area images corresponding to each text line, and then determine the key text images corresponding to each text line based on the key text areas. This can improve the accuracy of screening the key text areas, thereby improving the accuracy of determining the key text images, and in turn is beneficial to improving the accuracy of subsequent key text extraction.
[0143] In an optional embodiment, selecting an area satisfying the determined color condition from the text area image corresponding to each text line as a key text area of the text area image may include the following operations:
[0144] For each text line, the text area image corresponding to the text line is input into the text recognition model to obtain the text recognition result corresponding to the text line;
[0145] For each text line, a segmentation operation is performed on the text area image corresponding to the text line according to the text recognition result corresponding to the text line, so as to obtain a segmentation result corresponding to the text area image; the segmentation result corresponding to the text area image includes a character area corresponding to each character contained in the text line;
[0146] For each text line, at least one character region satisfying the determined region color condition is screened out from all character regions corresponding to the text line as a key character region of the text region image.
[0147] The segmentation operation is used to segment the text region in the text region image into a plurality of character regions.
[0148] The text recognition model may be a pre-trained text recognition model. Optionally, the text recognition model may be the same model as the text recognition model in step 205, which is not limited in the embodiment of the present invention.
[0149] It can be seen that this optional embodiment can, for each text line, first input the text area image corresponding to the text line into the text recognition model to obtain the text recognition result of the text line, and then perform a segmentation operation on the text area image based on the text recognition result to obtain a segmentation result containing multiple character areas, and then filter out at least one key text area that meets the area color conditions, which can improve the segmentation accuracy of the character area, thereby improving the screening accuracy of the key text area, and further helps to improve the extraction accuracy of the key text.
[0150] In this optional embodiment, optionally, the text recognition result corresponding to each text line includes text information contained in the text line; the text information contained in each text line includes at least one character and the character type of each character;
[0151] Optionally, for each text line, according to the text recognition result corresponding to the text line, performing a segmentation operation on the text area image corresponding to the text line to obtain a segmentation result corresponding to the text area image may include the following operations:
[0152] Obtaining preset character span information; the character span information includes a preset span corresponding to each character type;
[0153] Determine the character span of each character according to the character type and character span information of each character;
[0154] According to the character span of each character, a segmentation operation is performed on the text area image corresponding to the text line to obtain a character area corresponding to each character contained in the text line.
[0155] Among them, optionally, the pre-set character span information may include a combination of one or more of the preset spans of Chinese characters, the preset spans of lowercase English characters, and the preset spans of uppercase English characters, and may also include preset spans corresponding to other character types (for example: Korean character type, Japanese character type, Latin character type), which is not limited to the embodiments of the present invention.
[0156] Optionally, performing a segmentation operation on the text area image corresponding to the text line according to the character span of each character to obtain a segmentation result corresponding to the text area image may include:
[0157] According to the character span of each character and the number of characters in the text information contained in the text line, a segmentation operation is performed on the text area image corresponding to the text line to obtain a character area corresponding to each character contained in the text line.
[0158] For example, assuming that the text recognition result corresponding to a text line is: "A T-shirt that is particularly comfortable to wear", it can be known that the number of characters in the text information contained in the text line is 7. Based on the pre-set character span information, it can be known that the preset span of Chinese characters is 3, the preset span of lowercase English letters is 1, and the preset span of uppercase English characters is 2. According to the above character span information, the character span of each character in the text line is determined to be: [3,3,3,3,3,1,3]. Then, according to the above character span and the number of characters in the text line, the text area image corresponding to the text line is segmented to obtain the segmentation result.
[0159] It can be seen that this optional embodiment can also determine the character span of different types of characters based on pre-set character span information, and segment the text area image based on this to obtain multiple character areas contained in the text line, which can improve the segmentation flexibility and segmentation accuracy of the character area, thereby helping to reduce the situation where characters with smaller character spans are ignored, and further helping to improve the recognition accuracy of key texts.
[0160] In this optional embodiment, optionally, for each text line, selecting at least one character area satisfying the determined area color condition from all character areas corresponding to the text line as the key text area of the text area image may include the following operations:
[0161] Count the pixel mean of each character area corresponding to the text line;
[0162] For each character region, determining whether the pixel mean value of the character region is within the determined region pixel value range;
[0163] For each character region, when it is determined that the pixel mean value of the character region is within the region pixel value range, the character region is determined to be a key character region;
[0164] For each character region, when it is determined that the pixel mean value of the character region is not within the region pixel value range, the character region is determined to be a non-key character region;
[0165] The key text area of the text area image corresponding to the text line includes all key character areas.
[0166] Optionally, the pixel mean of each character area corresponding to the text line can be counted based on the numpy dependency library, which is not limited by the embodiment of the present invention; further optionally, it can be specifically as follows: based on the numpy dependency library, create a numpy matrix corresponding to each character area corresponding to the text line, each numpy matrix includes three dimensions, each dimension can be one of the number of rows, the number of columns, and the number of channels; calculate the pixel mean corresponding to each channel in the numpy matrix; wherein the pixel mean of each character area includes the pixel mean corresponding to all the above channels. Exemplarily, the pixel mean of a certain character area obtained by statistics can be [30,45,60], which is not limited by the embodiment of the present invention; further, when the image format corresponding to each character area is RGB format, the pixel mean of the character area includes the pixel mean corresponding to the R channel, the pixel mean corresponding to the G channel, and the pixel mean corresponding to the B channel.
[0167] It can be seen that this optional embodiment can also count the pixel mean of each character area corresponding to the text line. When it is judged that the pixel mean of the character area is within the regional pixel value range, the character area is determined to be a key character area. When it is judged that the pixel mean of the character area is not within the regional pixel value range, the character area is determined to be a non-key character area. The judgment accuracy of key character areas and non-key character areas can be improved, which is beneficial to improving the determination accuracy of key text areas, and further beneficial to improving the generation accuracy of key text images.
[0168] In this optional embodiment, optionally, for each text line, before calculating the pixel mean of each character area corresponding to the text line, the following operations may also be performed:
[0169] Convert the image format corresponding to each character area corresponding to the text line into HSV format.
[0170] When the image format corresponding to each character area is in HSV format, the pixel mean of the character area includes the pixel mean corresponding to the H channel, the pixel mean corresponding to the S channel, and the pixel mean corresponding to the V channel.
[0171] It can be seen that this optional embodiment can also convert the image format corresponding to each character area corresponding to the text line into the HSV format, so as to count the pixel mean of each character area based on the character area image in the HSV format, which can help improve the statistical flexibility and accuracy of the pixel mean of the character area.
[0172] In this optional embodiment, optionally, the regional pixel value range may include a first regional pixel threshold and / or a second regional pixel threshold, wherein the first regional pixel threshold includes a first pixel threshold corresponding to each channel, the second regional pixel threshold includes a second pixel threshold corresponding to each channel, and the first pixel threshold corresponding to each channel is less than or equal to the second pixel threshold corresponding to the channel;
[0173] For each character region, determining whether the pixel mean value of the character region is within the determined region pixel value range may include the following operations:
[0174] Determine whether the average pixel value corresponding to each channel of the character area is greater than or equal to the determined first pixel threshold corresponding to the channel and whether the average pixel value corresponding to each channel is less than or equal to the determined second pixel threshold corresponding to the channel;
[0175] When it is determined that the pixel average value corresponding to each channel of the character area is greater than or equal to the first pixel threshold value corresponding to the channel and the pixel average value corresponding to each channel is less than or equal to the second pixel threshold value corresponding to the channel, it is determined that the pixel average value of the character area is within the regional pixel value range;
[0176] When it is determined that the pixel average value corresponding to any channel in the character area is less than the first pixel threshold corresponding to the channel or the pixel average value corresponding to any channel is greater than the second pixel threshold corresponding to the channel, it is determined that the pixel average value of the character area is not within the regional pixel value range.
[0177] For example, assuming that the regional pixel value range is the value range corresponding to highlighted yellow, and the first regional pixel threshold in the regional pixel value range is [20,43,46], and the second regional pixel threshold is [34,255,255], when it is determined that the pixel mean of a character area is within the regional pixel value range, it can be determined that the text contained in the character area is highlighted yellow text, that is, the character area is a key character area.
[0178] It can be seen that this optional embodiment can also determine whether the pixel mean of the character area is within the regional pixel value range by judging whether the pixel mean of each channel of the character area is greater than or equal to the first pixel threshold corresponding to the channel and less than or equal to the second pixel threshold corresponding to the channel, thereby improving the accuracy of determining whether the pixel mean is within the preset range, thereby further improving the accuracy of determining the key character area, which in turn is beneficial to improving the accuracy of determining the key text area and non-key character area, and further is beneficial to improving the accuracy of generating the key text image.
[0179] In this optional embodiment, optionally, determining the key text image corresponding to each text line based on the key text area of each text area image may include the following operations:
[0180] For each non-key character region in the text region image corresponding to each text line, determining whether the pixel mean value of the non-key character region is within the determined background pixel value range;
[0181] For each non-key character region in the text region image corresponding to each text line, when it is determined that the pixel mean value of the non-key character region is within the determined background pixel value range, the pixel value of the non-key character region is filled with 0;
[0182] For each text line, a key text image corresponding to the text line is generated based on the key text area of the text area image corresponding to the text line and the non-key character area with pixel values filled with 0.
[0183] It can be seen that this optional embodiment can count the pixel mean of all non-highlight areas, and then regard all pixel values within a certain range above and below the mean as the background, and fill them with pixel value 0. This can avoid the situation where non-key characters with small character spans are mixed in the middle of key characters and are mistakenly identified as key characters due to errors in the rough image segmentation results, thereby helping to improve the recognition accuracy and extraction accuracy of key texts.
[0184] In the embodiment of the present invention, exemplarily, the specific implementation process of the method for extracting key text from an image may include the following operations:
[0185] One of the image frames of the video data is used as an image input to the pre-trained text detection model to obtain the text detection area in the image and the detection frame coordinates corresponding to the text detection area (the detection frame coordinates include the coordinates of two vertices, namely the x and y coordinates of the upper left corner and the lower right corner of the detection frame, and then the image is cropped based on the detection frame coordinates to obtain the cropped image corresponding to each line of text in the image (for example: a cropped image in RGB format, where the cropped image corresponding to the line of text can be as follows Figure 3 As shown, Figure 3 It is a cropped image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0186] Then, the cropped image is processed in grayscale to obtain a cropped grayscale image, where the cropped grayscale image can be obtained as follows: Figure 4 As shown, Figure 4The invention discloses a cropped grayscale image of a method for extracting key text from an image disclosed in an embodiment of the present invention; then, contour information of the cropped grayscale image is calculated, and the contour information may include the number of contours and the number of pixels occupied by each contour. When the number of pixels of any contour in the cropped grayscale image accounts for more than 30% of the total number of pixels in the image, the contour is determined to be a background area, and the background area is filtered out, and the remaining contours except the background area are determined to be text areas or valid areas, and the text area is extracted from the cropped image to obtain a text area image, wherein the text area image can be as follows Figure 5 As shown, Figure 5 It is a text area image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0187] Then, the text area image corresponding to each line of text is input into the text recognition model (for example, OCR recognition model) in turn to obtain the corresponding text recognition result, for example: "a particularly comfortable T-shirt". Based on the preset character span information, it can be known that the preset span of Chinese characters is 3, the preset span of lowercase English letters is 1, and the preset span of uppercase English characters is 2. Therefore, according to the character span information, the character span of each character in the text line is determined as follows: [3,3,3,3,3,1,3]. Then, according to the above character span and the number of characters in the text line, the text area image corresponding to the text line is segmented to obtain a segmentation result including multiple character areas, wherein the segmentation result can be as follows Figure 6 As shown, Figure 6 The segmentation result corresponding to the text area image of the method for extracting key text from an image disclosed in an embodiment of the present invention is as follows; then the pixel mean of each character area is counted, and based on the pixel mean, the following is judged: Figure 6 Whether each character area in the segmentation result shown meets the area color condition (for example: judging whether the color of the character area is a highlight color or judging whether the character area is a highlight area, that is, judging whether the character area contains highlighted text), the judgment result is [yes, yes, yes, yes, no, no, no], and then because the image segmentation may not be accurate (the span units of different fonts may be different, etc.), all pixel values whose pixel means of any non-highlight area in all non-highlight areas are within the background pixel value range are regarded as background areas, and the above background area is filled with pixel value 0, so as to obtain a key text image containing only highlighted characters (i.e. key text), wherein the key text image can be as follows Figure 7 As shown, Figure 7 It is a key text image of a method for extracting key text from an image disclosed in an embodiment of the present invention;
[0188] Then, the key text image is re-input into the text recognition model to obtain the key text recognition result: "particularly good to wear", and accurate key text information (for example: highlighted text) can be obtained.
[0189] Embodiment 3
[0190] See also Figure 8 , Figure 8 1 is a schematic diagram of a structure of a device for extracting key text from an image disclosed in an embodiment of the present invention. Figure 8 The described apparatus for extracting key text from an image may include a text extraction device, a text extraction terminal, a text extraction system, and a server, wherein the server may be a local server or a cloud server, which is not limited in the embodiment of the present invention. Figure 8 As shown, the image key text extraction device may include:
[0191] An input module 301 is used to input the acquired image into a pre-trained text detection model to obtain a text detection result; the text detection result includes a text detection area corresponding to at least one text line contained in the image;
[0192] An extraction module 302 is used to extract a text area image corresponding to each text line from the image according to the text detection result;
[0193] The extraction module 302 is further used to extract the key text image corresponding to each text line from the text area image corresponding to the text line; the key text image includes the key text area that meets the determined color condition;
[0194] The input module 301 is also used to input each key text image into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image; the key text recognition result includes the key text information contained in the image.
[0195] It can be seen that the device described in the embodiment of the present invention can input the acquired image into a pre-trained text detection model to obtain a text detection result, and then extract the text area image corresponding to each text line from the image according to the text detection result, and then extract the key text image including the key text area that meets the color condition from the text area image corresponding to each text line, and then input each key text image into the pre-trained text recognition model to obtain the key text recognition result, and can crop the image area where the text is located through the text detection technology, reduce the interference of the remaining background area on the recognized text, and improve the accuracy of determining the text area, which is conducive to improving the recognition accuracy of the text; and, by screening out the text area that meets the color condition from the image, it can improve the screening accuracy of the key text area in the image, thereby improving the recognition accuracy of the key characters, and then improve the extraction accuracy of the key text in the image, which is conducive to improving the accuracy of understanding the content of the image or video, and then It is conducive to efficiently generating a promotional logo for the content of the image or video based on the key text information, and can promote the content of the image or video more efficiently and accurately.
[0196] In an optional embodiment, the specific manner in which the extraction module 302 extracts the key text image corresponding to each text line from the text area image corresponding to the text line may include:
[0197] Filter out an area satisfying the determined color condition from the text area image corresponding to each text line as a key text area of the text area image;
[0198] Based on the key text area of each text area image, a key text image corresponding to each text line is determined.
[0199] It can be seen that the device described in the implementation of this optional embodiment can first filter out the key text area that meets the color conditions from the text area image corresponding to each text line, and then determine the key text image corresponding to each text line based on the key text area, which can improve the screening accuracy of the key text area, thereby improving the accuracy of determining the key text image, and further facilitating improving the accuracy of subsequent key text extraction.
[0200] In this optional embodiment, the extraction module 302 may select an area satisfying the determined color condition from the text area image corresponding to each text line, and the specific manner of selecting the key text area of the text area image may include:
[0201] For each text line, the text area image corresponding to the text line is input into the text recognition model to obtain the text recognition result corresponding to the text line;
[0202] For each text line, a segmentation operation is performed on the text area image corresponding to the text line according to the text recognition result corresponding to the text line, so as to obtain a segmentation result corresponding to the text area image; the segmentation result corresponding to the text area image includes a character area corresponding to each character contained in the text line;
[0203] For each text line, at least one character region satisfying the determined region color condition is screened out from all character regions corresponding to the text line as a key character region of the text region image.
[0204] It can be seen that the device described in the implementation of this optional embodiment can also, for each text line, first input the text area image corresponding to the text line into the text recognition model to obtain the text recognition result of the text line, and then perform a segmentation operation on the text area image based on the text recognition result to obtain a segmentation result containing multiple character areas, and then filter out at least one key text area that meets the area color conditions, which can improve the segmentation accuracy of the character area, thereby improving the screening accuracy of the key text area, and further helps to improve the extraction accuracy of the key text.
[0205] In this optional embodiment, optionally, the text recognition result corresponding to each text line includes text information contained in the text line; the text information contained in each text line includes at least one character and the character type of each character;
[0206] For each text line, the extraction module 302 performs a segmentation operation on the text region image corresponding to the text line according to the text recognition result corresponding to the text line. The specific method of obtaining the segmentation result corresponding to the text region image may include:
[0207] Obtaining preset character span information; the character span information includes a preset span corresponding to each character type;
[0208] Determine the character span of each character according to the character type and character span information of each character;
[0209] According to the character span of each character, a segmentation operation is performed on the text area image corresponding to the text line to obtain a character area corresponding to each character contained in the text line.
[0210] It can be seen that the device described in implementing this optional embodiment can also determine the character span of different types of characters based on pre-set character span information, and segment the text area image based on this to obtain multiple character areas contained in the text line, which can improve the flexibility and accuracy of character area segmentation, thereby helping to reduce the situation where characters with smaller character spans are ignored, and further helping to improve the recognition accuracy of key texts.
[0211] In this optional embodiment, optionally, for each text line, the extraction module 302 selects at least one character region that meets the determined region color condition from all character regions corresponding to the text line, and a specific method of selecting the key text region of the text region image may include:
[0212] Count the pixel mean of each character area corresponding to the text line;
[0213] For each character region, determining whether the pixel mean value of the character region is within the determined region pixel value range;
[0214] For each character region, when it is determined that the pixel mean value of the character region is within the region pixel value range, the character region is determined to be a key character region;
[0215] For each character region, when it is determined that the pixel mean value of the character region is not within the region pixel value range, the character region is determined to be a non-key character region;
[0216] The key text area of the text area image corresponding to the text line includes all key character areas.
[0217] It can be seen that the device described in the implementation of this optional embodiment can also count the pixel mean of each character area corresponding to the text line. When it is determined that the pixel mean of the character area is within the regional pixel value range, the character area is determined to be a key character area. When it is determined that the pixel mean of the character area is not within the regional pixel value range, the character area is determined to be a non-key character area. The judgment accuracy of key character areas and non-key character areas can be improved, which is beneficial to improving the determination accuracy of key text areas, and further beneficial to improving the generation accuracy of key text images.
[0218] In another optional embodiment, the specific manner in which the extraction module 302 extracts the text area image corresponding to each text line from the image according to the text detection result may include:
[0219] For each text line, the image is cropped according to the text detection area corresponding to the text line to obtain a cropped image corresponding to the text line;
[0220] For each text line, based on the determined region extraction method, determine the background region in the cropped image corresponding to the text line; the region extraction method includes a contour extraction method or a connected domain extraction method;
[0221] For each text line, the background area is filtered from the cropped image corresponding to the text line to obtain a text area image corresponding to the text line; the text area image includes the text area corresponding to the text line.
[0222] It can be seen that the device described in the implementation of this optional embodiment can crop the image according to the text detection area corresponding to each text line to obtain a cropped image corresponding to the text line, and then determine the background area in the cropped image based on the contour extraction method or the connected domain extraction method to filter the background area to obtain the text area image corresponding to the text line, which can improve the cropping efficiency and cropping accuracy of the text line image, as well as improve the filtering flexibility and filtering accuracy of the background area, thereby improving the determination efficiency and determination accuracy of the text area image.
[0223] In this optional embodiment, optionally, the specific manner in which the extraction module 302 determines the background region in the cropped image corresponding to the text line based on the determined region extraction manner may include:
[0224] Performing grayscale value processing on the cropped image corresponding to the text line to obtain a cropped grayscale image corresponding to the text line;
[0225] When the determined region extraction method is a contour extraction method, the contour information of the cropped grayscale image corresponding to the text line is counted; the contour information includes at least one contour and a first number of pixels occupied by the enclosed area of each contour;
[0226] For each contour, according to the first number of pixels, calculate the first pixel ratio of the enclosed area of the contour in the cropped grayscale image;
[0227] For each contour, when the first pixel ratio is greater than the first preset pixel ratio, the enclosed area of the contour is determined as the background area; or,
[0228] When the determined region extraction method is a connected domain extraction method, connected domain information of the cropped grayscale image corresponding to the text line is determined according to pixel connectivity; the pixel connectivity includes four-connectivity of pixels or eight-connectivity of pixels; the connected domain information includes at least one connected domain, a connected domain identifier of each connected domain, and the number of second pixels occupied by each connected domain;
[0229] For each connected domain, according to the second pixel number, calculate the proportion of the second pixels of the connected domain in the cropped grayscale image;
[0230] For each connected domain, when the second pixel ratio is greater than the second preset pixel ratio, the connected domain is determined as a background area.
[0231] It can be seen that the device described in the implementation of this optional embodiment can also first perform grayscale value processing on the cropped image to obtain a cropped grayscale image corresponding to each text line. When the area extraction method is the contour extraction method, the contour information of the cropped grayscale image is counted, and then the first pixel ratio of the area surrounded by each contour is calculated. If the first pixel ratio is greater than the first preset pixel ratio, the area surrounded by the contour is determined as the background area; or when the area extraction method is the connected domain extraction method, the connected domain information of the cropped grayscale image is counted, and then the second pixel ratio of each connected domain is calculated. If the second pixel ratio is greater than the second preset pixel ratio, the connected domain is determined as the background area. This can improve the determination accuracy and determination flexibility of the background area in the image, thereby improving the filtering accuracy of the background area, which is beneficial to improving the determination accuracy of the text area, and is beneficial to further improving the determination accuracy of the text area image.
[0232] Embodiment 4
[0233] See also Fig. 9 , Fig. 9 FIG. 1 is a schematic diagram of the structure of another device for extracting key text from an image disclosed in an embodiment of the present invention. Fig. 9 As shown, the image key text extraction device may include:
[0234] A memory 401 storing executable program codes;
[0235] a processor 402 coupled to the memory 401;
[0236] The processor 402 calls the executable program code stored in the memory 401 to execute the steps in the method for extracting key text from an image described in the first embodiment of the present invention or the second embodiment of the present invention.
[0237] Embodiment 5
[0238] An embodiment of the present invention discloses a computer storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute the steps in the method for extracting key text from an image described in Embodiment 1 or Embodiment 2 of the present invention.
[0239] Embodiment 6
[0240] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute the steps in the method for extracting key text from an image described in Embodiment 1 or Embodiment 2.
[0241] The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
[0242] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or partly contributed to the prior art in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0243] Finally, it should be noted that the method and device for extracting key text from an image disclosed in the embodiments of the present invention disclose only the preferred embodiments of the present invention, which are only used to illustrate the technical solution of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, 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 invention.
Claims
1. A method for extracting key text from an image, characterized in that: The method comprises: Inputting the acquired image into a pre-trained text detection model to obtain a text detection result; the text detection result includes a text detection area corresponding to at least one text line contained in the image; Extracting a text area image corresponding to each text line from the image according to the text detection result; Extracting a key text image corresponding to each text line from the text area image corresponding to the text line; the key text image includes a key text area that meets the determined color condition; Each of the key text images is input into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image; the key text recognition result includes the key text information contained in the image.
2. The method for extracting key text from an image according to claim 1, characterized in that: The step of extracting a key text image corresponding to each text line from the text area image corresponding to the text line comprises: Filtering out an area satisfying the determined color condition from the text area image corresponding to each of the text lines as a key text area of the text area image; Based on the key text area of each of the text area images, a key text image corresponding to each of the text lines is determined.
3. The method for extracting key text from an image according to claim 2, characterized in that: The step of selecting an area satisfying the determined color condition from the text area image corresponding to each text line as a key text area of the text area image includes: For each of the text lines, inputting the text area image corresponding to the text line into the text recognition model to obtain a text recognition result corresponding to the text line; For each of the text lines, a segmentation operation is performed on the text area image corresponding to the text line according to the text recognition result corresponding to the text line, so as to obtain a segmentation result corresponding to the text area image; the segmentation result corresponding to the text area image includes a character area corresponding to each of the characters contained in the text line; For each of the text lines, at least one character area satisfying the determined area color condition is screened out from all the character areas corresponding to the text line as a key text area of the text area image.
4. The method for extracting key text from an image according to claim 3, characterized in that: The text recognition result corresponding to each of the text lines includes the text information contained in the text line; the text information contained in each of the text lines includes at least one character and the character type of each of the characters; Wherein, for each of the text lines, performing a segmentation operation on the text area image corresponding to the text line according to the text recognition result corresponding to the text line to obtain a segmentation result corresponding to the text area image includes: Acquire preset character span information; the character span information includes a preset span corresponding to each character type; Determining the character span of each of the characters according to the character type of each of the characters and the character span information; According to the character span of each of the characters, a segmentation operation is performed on the text area image corresponding to the text line to obtain a character area corresponding to each of the characters contained in the text line.
5. The method for extracting key text from an image according to claim 3, characterized in that: For each of the text lines, the step of selecting at least one character area satisfying the determined area color condition from all the character areas corresponding to the text line as a key text area of the text area image includes: Counting the pixel mean of each character area corresponding to the text line; For each of the character regions, determining whether the pixel mean value of the character region is within the determined region pixel value range; For each of the character regions, when it is determined that the pixel mean value of the character region is within the pixel value range of the region, the character region is determined to be a key character region; For each of the character regions, when it is determined that the pixel mean value of the character region is not within the pixel value range of the region, the character region is determined to be a non-key character region; The key text area of the text area image corresponding to the text line includes all the key character areas.
6. The method for extracting key text from an image according to any one of claims 1 to 5, characterized in that: The step of extracting a text area image corresponding to each text line from the image according to the text detection result includes: For each of the text lines, cropping the image according to the text detection area corresponding to the text line to obtain a cropped image corresponding to the text line; For each of the text lines, based on the determined region extraction method, determine the background region in the cropped image corresponding to the text line; the region extraction method includes a contour extraction method or a connected domain extraction method; For each of the text lines, the background area is filtered from the cropped image corresponding to the text line to obtain a text area image corresponding to the text line; the text area image includes the text area corresponding to the text line.
7. The method for extracting key text from an image according to claim 6, characterized in that: For each of the text lines, determining the background area in the cropped image corresponding to the text line based on the determined area extraction method includes: Performing grayscale value processing on the cropped image corresponding to the text line to obtain a cropped grayscale image corresponding to the text line; When the determined region extraction method is the contour extraction method, the contour information of the cropped grayscale image corresponding to the text line is counted; the contour information includes at least one contour and a first number of pixels occupied by the enclosed area of each contour; For each of the contours, calculating a first pixel ratio of an enclosed area of the contour in the cropped grayscale image according to the first number of pixels; For each of the contours, when the first pixel ratio is greater than a first preset pixel ratio, determining the enclosed area of the contour as a background area; or, When the determined region extraction method is the connected domain extraction method, the connected domain information of the cropped grayscale image corresponding to the text line is determined according to pixel connectivity; the pixel connectivity includes four-connectivity of pixels or eight-connectivity of pixels; the connected domain information includes at least one connected domain, a connected domain identifier of each of the connected domains, and the number of second pixels occupied by each of the connected domains; For each of the connected domains, calculating a second pixel ratio of the connected domain in the cropped grayscale image according to the second number of pixels; For each of the connected domains, when the second pixel ratio is greater than a second preset pixel ratio, the connected domain is determined as a background area.
8. A device for extracting key text from an image, characterized in that: The device comprises: An input module, used to input the acquired image into a pre-trained text detection model to obtain a text detection result; the text detection result includes a text detection area corresponding to at least one text line contained in the image; An extraction module, used for extracting a text area image corresponding to each text line from the image according to the text detection result; The extraction module is further used to extract a key text image corresponding to each text line from the text area image corresponding to the text line; the key text image includes a key text area that meets the determined color condition; The input module is also used to input each of the key text images into a pre-trained text recognition model to obtain a key text recognition result corresponding to the image; the key text recognition result includes the key text information contained in the image.
9. A device for extracting key text from an image, characterized in that: The device comprises: A memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the method for extracting key text from an image as described in any one of claims 1-7.
10. A computer storage medium, characterized in that: The computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the method for extracting key text from an image as described in any one of claims 1-7.
Citation Information
Patent Citations
Attention-based image character recognition method and device
CN112766051A
Method and device for determining text image region detection model
CN115082931A
Character information extraction device and its method, program and storage medium
JP2003058823A
Image processing apparatus, image processing method and image processing program
US20060104512A1
Business card content identification method, electronic device and storage medium
WO2017202232A1
Cited By
Engineering drawing calculation quantity extraction system and method
CN120976959A
