Text character segmentation method and system based on OCR recognition
Through the method based on OCR recognition, the index and confidence information are used for text character segmentation, which solves the problem of poor segmentation effect in the existing technology, achieves fast and accurate segmentation of text characters, and improves the accuracy of information extraction.
Patent Information
- Application Number
- CN202111429302.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-11-29
AI Technical Summary
Existing text character segmentation methods have deficiencies in accuracy and precision, which affects the subsequent extraction of hidden information.
Using a method based on OCR recognition, missing recognized characters are added through index, content and confidence information, position adjustment is performed based on neural network and pixel information, the segmentation position is calculated, and noise is removed through frame information to achieve accurate segmentation of text characters.
It achieves fast and accurate segmentation of text characters, avoids omissions, improves the accuracy of segmentation positions, and improves the accuracy of hidden information extraction.
Smart Images

Figure CN113989485B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text processing, and in particular to a text character segmentation method and system based on OCR recognition. Background Art
[0002] OCR (Optical Character Recognition) refers to the process in which an electronic device (such as a scanner or digital camera) examines characters printed on paper, determines their shapes by detecting dark and light patterns, and then uses character recognition methods to translate the shapes into computer text; that is, for printed characters, an optical method is used to convert the text in a paper document into a black and white dot matrix image file, and recognition software is used to convert the text in the image into a text format for further editing and processing by word processing software.
[0003] OCR technology is very mature. For example, the paper Detecting Text in Natural Image with Connectionist Text Proposal Network (Zhi Tian, Weilin Huang, Tong He, Pan He, Yu Qiao, ECCV (8) 2016: 56-72) discloses a classic text detection algorithm. When performing text character recognition, any text detection line is divided into multiple small boxes of a certain width, and the content in each small box is template matched. During the recognition process, the index, content and confidence information of each small box are output, and then the text is recognized and output based on this information. Moreover, more people have made improvements on this basis, providing more reliable and effective algorithms, making the text character recognition technology more mature.
[0004] Invisible watermarking technology for text has gradually matured in recent years. Its basic principle is to slightly deform characters. This deformation is difficult to distinguish with the naked eye, but the deformation information can be accurately extracted by computer. The deformation information in the characters can be used in multiple scenarios such as information hiding, copyright tracking, and leak tracing. In order to accurately extract the deformation information of characters, it is very important to accurately segment the characters in the text. The actual segmentation effect of the existing text character segmentation methods is not very ideal, which directly affects the accuracy of the subsequent extraction of hidden information. Summary of the invention
[0005] The object of the present invention is to provide a text character segmentation method and system based on OCR recognition, which can segment characters in a text very quickly and accurately.
[0006] To achieve the above purpose, the technical solution adopted by the present invention is: a text character segmentation method based on OCR recognition, comprising the following steps: S100, using the OCR algorithm to recognize the text to obtain index, content and confidence information; S200, for any text detection line, adding the missed recognition characters according to the content and confidence information of the index and then recording the index position where the confidence of the non-empty content is the largest; S300, processing the above index position to obtain the position information {x1, x2, ..., x n}; S400, according to the character content, the character position information of the symbol content is offset adjusted, and the adjusted position information is {x′1, x′2, ..., x′ n}; S500, according to the position information x′ i and x′ i+1 Calculate the split position y i , where i∈{1, 2, ..., n-1}; S600, according to the row start position y0, the row end position y n and the segmentation position y calculated in step S400 i The characters in the row are segmented and trimmed to obtain the frame information of each character; S700, noise points are removed according to the confidence information of each character and the size of the frame, and the remaining characters are correctly segmented.
[0007] Compared with the prior art, the present invention has the following technical effects: the OCR algorithm in the prior art is very mature, but it can only output the recognized character content. Here, a series of processing is performed based on the output results of the existing mature algorithm to achieve accurate segmentation of the characters in the text. No characters will be missed during segmentation and the segmentation position is very precise. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 This is a schematic diagram of the output information after OCR recognition;
[0009] Figure 2 It is a schematic diagram of the process of the present invention;
[0010] Figure 3 It is a schematic diagram of segmentation position calculation;
[0011] Figure 4 is a system block diagram of the present invention;
[0012] Figure 5 It is an effect diagram after character segmentation in the prior art;
[0013] Figure 6 It is the effect diagram after segmenting characters in the present invention. DETAILED DESCRIPTION
[0014] Combine the following Figures 1 to 6 , the present invention is further described in detail.
[0015] See also Figure 1 and Figure 2 , a text character segmentation method based on OCR recognition, comprising the following steps:
[0016] S100, using an OCR algorithm to recognize the text to obtain index, content and confidence information; Figure 1 What is shown in is the information output by the OCR algorithm after recognizing the text, wherein the index starts from 0 and increases gradually, and the content is the specific character recognized in the small box corresponding to the index. Generally speaking, the OCR algorithm encodes Chinese characters into numbers of about 0-3000, and each character corresponds to a number. The general output content is a number, that is, the label value of the Chinese character. For us, the label value and the character are one-to-one corresponding, so the present invention does not distinguish between the label value and the character, and it can be considered that they represent the same information. Confidence refers to the match between the recognized character and the template. For some rare characters that are not in the OCR template library, they are generally recognized as empty and have a low confidence. It should be noted that in the present invention, Figure 1 and Figure 3 It is just a schematic diagram for your understanding. In actual processing, the actual pixel size of Chinese characters, the small box, and the weight position are not in the proportion shown in the figure.
[0017] S200. For any text detection line, add the missing characters according to the index content and confidence information, and then record the index position of the non-empty content with the maximum confidence. We also need to segment the missing characters, so we need to add the missing characters first. Generally, we select some areas with continuously low confidence. For example, if there are a consecutive index positions with confidences lower than the set threshold, it is determined to be a missing character. After adding the missing characters, all non-empty contents are character areas. For any character, record the index position of the maximum confidence among the multiple confidences corresponding to the character, and the position of each character is equivalent to being marked.
[0018] S300, process the above index positions to obtain the position information of each character {x1, x2, ..., x n}, because we are detecting a line of text, the position information here corresponds to the horizontal coordinate; when the OCR algorithm recognizes characters in the text, the output is the index position. When we perform segmentation, we generally segment according to the coordinate information, because we need to convert the index position into specific position information. The actual position coordinates corresponding to each index can be converted according to the pixel width of each small box when the OCR algorithm is performing recognition. Specifically, in the step S300, the feature inverse calculation is performed according to the time length of the neural network LSTM and the size information of the text detection line, the index position is enlarged to form a mapping relationship with the size information of the correction image after the text detection line image is transformed, and the index position is processed into character position information according to the mapping relationship. The image transformation here can be a perspective transformation or an affine transformation.
[0019] S400: offset and adjust the position information of the character whose content is a symbol according to the character content, and the adjusted position information is {x′1, x′2, ..., x′ n}; In many Chinese fonts, the symbol is usually located at the lower left corner, which makes the position of the character closer to the previous character and farther from the next character. When we perform segmentation later, we need to take the position between the two segmentation positions. The existence of the character will cause the position between the middle and left to shift, so the position of the character needs to be corrected. For normal characters, no adjustment is required.
[0020] See also Figure 3 , S500, according to the position information x′ i and x′ i+1 Calculate the split position y i , where i∈{1, 2, ..., n-1}; through the position of each character, we can easily calculate the segmentation position between characters. Specifically, the step S500 includes the following steps: S510, according to the position information x′ i and x′ i+1 Calculate the center position Z i,0 ; S520, record Z i,0 Towards x′ i The offset positions on one side are {Z i,-1 , Z i,-2 , ..., Z i,-m}, Z i,0 Towards x′ i+1 The offset positions on one side are {Z i,1, Z i,2 , ..., Z i,m}; S530, calculate all Z i,j The proportion of blank pixels in a column of pixels at position P i,j, where j∈{-m,-m+1,...,-1,m}; S540, P i,j The position corresponding to the maximum value is the split position y i ; Generally speaking, the segmentation position of two adjacent characters is located between the two characters. In order to more accurately pick out the middle position, the pixel points of the middle position and multiple positions offset to both sides of the middle are calculated here. If a column has the most blank pixels, it can be considered as the accurate segmentation position.
[0021] Furthermore, in order to make the segmentation more accurate, weights are introduced here, and the ratio P is no longer the only i,j To determine the segmentation position, the step S540 is replaced by the following steps: S550, for each position Z i,j Set the weight, the weight gradually decreases from the middle to both sides, and each position Z i,j P i,j Multiply by the weight; S560, the position corresponding to the maximum value of the product is the segmentation position y i After introducing weights, the best split position can be found more accurately. When setting weights, you can set them according to your needs. Generally, the weight in the middle is heavy, and the weights on both sides gradually decrease. Therefore, the weight of the center position can be set to 100%.
[0022] Furthermore, in step S520, the offset positions are set at equal intervals, the minimum interval is 1pix, the maximum interval is x′ i and x′ i+1 5% of the pixel width between two adjacent characters. 1pix is 1 pixel. The maximum value is set to ensure that enough segmentation positions can be selected between two adjacent characters to screen out the best segmentation position.
[0023] According to the line start position y0, line end position y n and the segmentation position y calculated in step S400 i The characters in the row are segmented and trimmed to obtain the border information of each character; with the segmentation position, we can naturally and easily obtain the border information of the character. This border is the minimum circumscribed rectangle that can frame the character and the four sides of the rectangle are arranged vertically and horizontally.
[0024] Specifically, the step S600 includes the following steps: S610, for the jth character, the segmentation position y on the left side j-1 Move right and determine whether the number of black pixels in the column of pixels at each move is greater than the set threshold. If so, record the current position as y j-left ; S620, the segmentation position y on the right side of the jth character iMove to the left and determine whether the number of black pixels in the column of pixels at each move is greater than the set threshold. If so, record the current position as y j-right ; S630, similarly, the segmentation positions of the upper and lower sides of the j-th character are moved downward and upward respectively to obtain the position and y j-up and j-down ; S640, according to the above four positions y j-left ,y j-right ,y j-up and j-down The border information of the jth character can be obtained; let j∈{1, 2, ..., n} execute the above steps respectively to obtain the border information of all characters in the row. j-left and j-right The corresponding horizontal coordinate, y j-up and j-down The corresponding coordinate is the vertical coordinate, and the final border information can be the coordinate position of the upper left corner and the lower right corner of the border.
[0025] S700, remove noise points according to the confidence information and border size of each character, and the remaining ones are the correctly segmented characters. Since in most cases, the text photos taken need to be segmented, noise points often appear when the pictures are taken and processed. Objects with small borders and low confidence are all noise points and need to be removed. The OCR algorithm in the prior art is very mature, but it can only output the recognized character content. Here, a series of processing is performed based on the output results of the existing mature algorithm to achieve accurate segmentation of the characters in the text, so that no characters will be missed during segmentation and the segmentation position is very accurate.
[0026] See also Figure 4 The present invention also discloses a text character segmentation system based on OCR recognition, including an OCR recognition module for recognizing text to obtain index, content and confidence information; a missed character detection module for adding missed characters according to the content and confidence information of the index; a first adjustment module for obtaining the index position of each character at the middle; a conversion module for converting the index information of each character into position information; a second adjustment module for adjusting the position information of the symbol; a segmentation module for segmenting and trimming the characters according to the adjusted position information to obtain the border information of each character; and a denoising module for removing noise points according to the confidence and border information of each character. By setting these modules, the segmentation of characters in a text file can be easily realized.
[0027] Figure 5 The figure shows the effect of segmenting characters in the prior art. It can be seen that the segmentation is not ideal in some places. Figure 6This is the effect diagram after character segmentation using the segmentation method of the present invention. It can be seen that the segmentation effect is much better. It should be noted that Figure 6 In the effect diagram shown in FIG. 1 , when executing step S600, for the jth character, y j-left and j-right At most x′ is searched j That is, it stops, so the search for the right side of the symbol stops at the middle position.
[0028] Furthermore, the present invention also discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, any of the above-mentioned methods for text character segmentation based on OCR recognition is implemented. The present invention discloses an electronic device, including a memory, a processor, and a computer program stored in the memory, and when the processor executes the computer program, any of the above-mentioned methods for text character segmentation based on OCR recognition is implemented.
[0029] In the present invention, before character segmentation is performed on the photographed text photo, the image is generally binarized to highlight the text part and the background part. Furthermore, before step S100 described in the present invention, the text is binarized according to the following steps: A. Convert the image into a grayscale image; B. Traverse all pixels and execute steps C and D for each pixel to obtain a binarized image; C. Determine the threshold value based on the grayscale value of the pixel and other pixels in a certain area around it; D. Compare the grayscale value of the pixel with the threshold obtained in step C. If the grayscale value of the pixel is less than or equal to the threshold, set the pixel to black, otherwise set it to white. The more detailed steps of this binarization process have been submitted for patent application before, and will not be repeated here.
Claims
1. A text character segmentation method based on OCR recognition, characterized in that: The steps include: S100, using an OCR algorithm to recognize the text to obtain index, content and confidence information; S200, for any text detection line, add the missing characters according to the index content and confidence information and then record the index position where the confidence of the non-empty content is the maximum; S300, process the above index positions to obtain the position information of each character {x1, x2, ..., x n }; S400: offset and adjust the position information of the character whose content is a symbol according to the character content, and the adjusted position information is {x′1, x′2, ..., x′ n }; S500, according to the position information x′ i and x′ i+1 Calculate the split position y i , where i∈{1, 2, ..., n-1}, includes the following steps: S510, according to the position information x′ i and x i+1 Calculate the center position z i,0 ; S520, remember i,0 Towards x′ i The offset positions on one side are {z i,-1 , z i,-2 , ..., z i,-m }, z i,0 Towards x′ i+1 The offset positions on one side are {z i,1 , z i,2 , ..., z i,m }; S530, calculate the proportion P of blank position pixels in a column of pixels at all zi,j positions i,j , where j∈{-m,-m+1,...,m-1,m}; S540、P i,j The position corresponding to the maximum value is the split position y i ; S600, according to the line start position y0, line end position y n and the segmentation position y calculated in step S400 i Segment and trim the characters in the row to obtain the border information of each character; S700: Remove noise points according to the confidence information and border size of each character, and the remaining characters are correctly segmented characters.
2. The text character segmentation method based on OCR recognition as claimed in claim 1, characterized in that: In the step S200: if there are a consecutive index positions whose confidences are all lower than the set threshold, it is determined to be a missed recognition character; for any character, the index position with the maximum confidence among the multiple confidences corresponding to the character is recorded.
3. The text character segmentation method based on OCR recognition as claimed in claim 1, characterized in that: In the step S300, feature inverse calculation is performed based on the time length of the neural network LSTM and the text detection line size information, the index position is enlarged to form a mapping relationship with the size information of the correction image after the text detection line image is transformed, and the index position is processed into character position information based on the mapping relationship.
4. The text character segmentation method based on OCR recognition as claimed in claim 1, characterized in that: The step S540 is replaced by the following steps: S550, for each position z i,j Set the weight, the weight gradually decreases from the middle to both sides, and each position z i,j P i,j Multiply by weight; S560, the position corresponding to the maximum value of the product is the segmentation position y i .
5. The text character segmentation method based on OCR recognition as claimed in claim 1, characterized in that: In step S520, the offset positions are set at equal intervals, with a minimum interval of 1pix and a maximum interval of x. i and x i+1 5% of the pixel width between them.
6. The text character segmentation method based on OCR recognition as claimed in claim 1, characterized in that: The center position z i,0 The weight at is 100%.
7. The text character segmentation method based on OCR recognition as claimed in claim 1, characterized in that: The step S600 includes the following steps: S610: For the j-th character, set the split position y on the left side j-1 Move right and determine whether the number of black pixels in the column of pixels at each move is greater than the set threshold. If so, record the current position as y j-left ; S620: Set the segmentation position y on the right side of the jth character i Move to the left and determine whether the number of black pixels in the column of pixels at each move is greater than the set threshold. If so, record the current position as y j-right ; S630, similarly, the segmentation positions of the upper and lower sides of the j-th character are moved downward and upward respectively to obtain the position and y j-up and j-down ; S640, according to the above four positions y j-left ,y j-rigkt ,y j-up and j-down The border information of the jth character can be obtained; Let j∈{1, 2, ..., n} execute the above steps respectively to obtain the border information of all characters in the row.
8. A text character segmentation system based on OCR recognition, characterized by: The text character segmentation method based on OCR recognition as described in any one of claims 1 to 7 is adopted, comprising: OCR recognition module, used to recognize text and obtain index, content and confidence information; A missed character detection module adds missed characters according to the index content and confidence information; The first adjustment module is used to obtain the index position of the middle of each character; A conversion module, used for converting the index information of each character into position information; A second adjustment module, used for adjusting the position information of the symbol; The segmentation module segments and trims the characters according to the adjusted position information to obtain the border information of each character; The denoising module removes noise points based on the confidence and border information of each character.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the text character segmentation method based on OCR recognition as described in any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory. When the processor executes the computer program, the method for text character segmentation based on OCR recognition as described in any one of claims 1 to 7 is implemented.
