Search

CN-121999505-A - Text extraction method, electronic device and storage medium

CN121999505ACN 121999505 ACN121999505 ACN 121999505ACN-121999505-A

Abstract

The embodiment of the application provides a text extraction method, electronic equipment and a storage medium, and relates to the technical field of image processing. The method comprises the steps of obtaining a plurality of text lines corresponding to an original image, determining attribute information corresponding to each text line, wherein the attribute information comprises at least one of a gray value and an inclination angle value, determining watermark text lines in the text lines according to the attribute information, removing the watermark text lines in the text lines to obtain text lines, and extracting texts in the text lines to obtain text. The method and the device can accurately identify the watermark text line, automatically remove the watermark text line, eliminate the need of manually removing the watermark text by a user, effectively avoid the user from deleting important information in the text carelessly, and improve the accuracy of text extraction. And the method does not need manual intervention of a user, improves the speed and efficiency of text extraction, saves a great amount of time and improves user experience.

Inventors

  • FU JUAN
  • LIU SHILEI

Assignees

  • 荣耀终端股份有限公司

Dates

Publication Date
20260508
Application Date
20241104

Claims (18)

  1. 1. A method of text extraction, the method comprising: Acquiring a plurality of text lines corresponding to an original image; determining attribute information corresponding to each text line, wherein the attribute information comprises at least one of a gray value and an inclination angle value; Determining watermark text lines in the text lines according to the attribute information; Removing the watermark text lines in the text lines to obtain text lines; And extracting the text in the text line of the body text to obtain the body text.
  2. 2. The method of claim 1, wherein when the attribute information includes the gray value, the determining a watermark text line of the plurality of text lines according to the attribute information includes: and determining the text line and the watermark text line according to the text line when detecting that the gray value of the text line belongs to a discrete value.
  3. 3. The method of claim 1, wherein when the attribute information includes the tilt angle value, the determining a watermark text line of the plurality of text lines based on the attribute information comprises: And determining the text line and the watermark text line according to each text line when detecting that the inclination angle value of the text line is larger than a preset angle threshold value.
  4. 4. The method of claim 1, wherein when the attribute information includes the gray level value and the inclination angle value, the determining a watermark text line from the plurality of text lines according to the attribute information includes: And determining the text line to be the watermark text line when detecting that the gray value of the text line belongs to a discrete value and the inclination angle value of the text line is larger than a preset angle threshold value aiming at each text line.
  5. 5. The method according to claim 2 or 4, characterized in that the method further comprises: And for each text line, when detecting that the gray value of the text line is not in the gray threshold range, determining that the gray value of the text line belongs to the discrete value.
  6. 6. The method of claim 5, wherein the method further comprises: according to the gray value of each text line, determining the average gray value and standard deviation corresponding to the plurality of text lines; and determining the gray threshold range according to the average gray value and the standard deviation.
  7. 7. The method according to claim 2 or 4, characterized in that the method further comprises: sequencing the text lines according to the sequence from big to small of the gray values of the text lines to obtain sequencing results; According to the sequencing result, calculating the difference value of gray values between every two adjacent text lines; When a target difference value larger than a preset difference value is detected for the first time, determining a first text row and a second text row corresponding to the target difference value, wherein the difference value between the gray value of the first text row and the gray value of the second text row is the target difference value, and the gray value of the second text row is smaller than the gray value of the first text row; it is determined that the gray value of the text line ordered before the second text line belongs to a discrete value.
  8. 8. A method according to any one of claims 1 to 7, wherein the watermark text line has a tilt angle value of (0 °,90 °) or (90 °,180 °).
  9. 9. The method according to claim 8, wherein when the attribute information includes the inclination angle value, the determining attribute information corresponding to each text line includes: determining a text box corresponding to each text line; Determining vertex coordinates corresponding to each text box; And determining the inclination angle value corresponding to each text line according to the vertex coordinates corresponding to each text box.
  10. 10. The method of claim 9, wherein the vertex coordinates include four vertex coordinates, and wherein determining the tilt angle value for each text line based on the vertex coordinates for each text box comprises: determining a group of midpoint coordinates corresponding to each text box according to the four vertex coordinates corresponding to each text box; determining a center line corresponding to each text box based on a set of center point coordinates corresponding to each text box; and determining an angle value between a central line corresponding to each text box and a preset horizontal reference line to obtain an inclination angle value corresponding to each text line.
  11. 11. The method according to any one of claims 1 to 10, wherein the acquiring a plurality of text lines corresponding to the original image includes: And inputting the original image into an optical character recognition detection model for processing to obtain a plurality of text lines corresponding to the original image.
  12. 12. The method according to claim 1, wherein the attribute information further comprises a preset area comprising a bottom left area and/or a bottom right area in the original image.
  13. 13. The method of claim 12, wherein when the attribute information includes the preset area, the method further comprises: if the existence of text lines in a preset area in the original image is detected, judging that the text lines in the preset area are watermarked; and removing the watermark text line in the preset area.
  14. 14. The method of claim 12, wherein when the attribute information includes the preset area, the method further comprises: If the existence of text lines in a preset area in the original image is detected, and the number of the text lines in the preset area is smaller than the preset number, judging that all the text lines in the preset area are watermarked; And removing all watermark text lines in the preset area.
  15. 15. The method according to any one of claims 1 to 14, wherein said extracting text in said body text line to obtain body text comprises: highlighting text in the body text line; and extracting the highlighted text to obtain the main text.
  16. 16. An electronic device comprising one or more processors and memory coupled with the one or more processors, the memory to store computer program code comprising computer instructions that the one or more processors invoke to cause the electronic device to perform the method of any of claims 1-15.
  17. 17. A computer readable storage medium comprising instructions that, when run on an electronic device, cause the electronic device to perform the method of any one of claims 1 to 15.
  18. 18. A computer program product, characterized in that the computer program product comprises computer program code which, when run, causes the method of any one of claims 1 to 15 to be performed.

Description

Text extraction method, electronic device and storage medium Technical Field The present application relates to the field of image processing technologies, and in particular, to a text extraction method, an electronic device, and a storage medium. Background With the rapid development of the electronic information industry, the information volume has been explosively increased, resulting in an increasing demand for automated information processing technology by users. For example, automatically extracting text from images containing textual information is a typical example of such a need. Currently, images containing text information are typically analyzed using optical character recognition (optical character recognition, OCR) to automatically extract text. However, the accuracy of the OCR recognition text results in this way is not high at present, resulting in inaccuracy of the extracted text. Disclosure of Invention The application provides a text extraction method, electronic equipment and a storage medium, which solve the technical problem that watermark text is mistakenly recognized as text when OCR is adopted to recognize the text in an image in the related technology. The application provides a text extraction method, which comprises the steps of obtaining a plurality of text lines corresponding to an original image, determining attribute information corresponding to each text line, determining watermark text lines in the text lines according to the attribute information, removing the watermark text lines in the text lines to obtain text lines, and extracting texts in the text lines to obtain text. Alternatively, the attribute information of the text line may include at least one of a gray value, a tilt angle value, a coordinate value, a line interval, a color, a language type, an affiliated paragraph, a line in the affiliated paragraph, a font size, a font type, a height of the text line, a width of the text line, and the like. In the implementation manner, by utilizing the characteristic that the attribute information of the text lines is different from the attribute information of the watermark text lines, the watermark text lines are accurately screened from a plurality of text lines through the attribute information of the text lines, such as gray values, inclination angle values and the like, so as to obtain accurate text lines, and then texts in the text lines are extracted, so that the accurate text is obtained. And because the watermark text line is automatically removed, the user does not need to manually remove the watermark text again, the user can be effectively prevented from deleting important information in the text carelessly, and the accuracy of text extraction is improved. Furthermore, manual intervention of a user is not needed, the speed and efficiency of text extraction can be improved, a large amount of time is saved, and user experience is improved. With reference to the first aspect, in some implementations of the first aspect, when the attribute information includes a gray value, determining a watermark text line in the plurality of text lines according to the attribute information includes determining, for each text line, that the gray value of the text line belongs to a discrete value, the text line is watermarked. In the implementation mode, the watermark text line can be rapidly and accurately screened according to the gray value of the text line by utilizing the characteristic that the gray value of the text line is different from the gray value of the watermark text line, so that the watermark text line can be conveniently removed later, and the accuracy of text extraction is improved. With reference to the first aspect, in some implementations of the first aspect, when the attribute information includes an inclination angle value, determining a watermark text line in the plurality of text lines according to the attribute information includes determining, for each text line, that the text line is watermarked when the inclination angle value of the text line is detected to be greater than a preset angle threshold. In the implementation mode, the characteristic that the inclination angle value of the text line is different from the inclination angle value of the watermark text line is utilized, the watermark text line can be rapidly and accurately screened out according to the inclination angle value of the text line, the watermark text line can be conveniently removed subsequently, and the accuracy of text extraction is improved. With reference to the first aspect, in some implementations of the first aspect, when the attribute information includes a gray value and a tilt angle value, determining a watermark text line in a plurality of text lines according to the attribute information includes determining, for each text line, that the gray value of the text line belongs to a discrete value and that the tilt angle value of the text line is greater than a preset angle t