Image character recognition method and device, computer device and storage medium
By performing character recognition and semantic segmentation on images, the location information of spaces is determined, which solves the problem of inaccurate space character recognition in traditional OCR models in multilingual scenarios and achieves higher recognition accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 湖南四方天箭信息科技有限公司
- Filing Date
- 2023-04-23
- Publication Date
- 2026-06-30
Smart Images

Figure CN116469114B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence optical character recognition technology, and particularly relates to an image character recognition method, device, computer equipment, and storage medium. Background Technology
[0002] Optical character recognition (OCR) is a branch of computer vision research, essentially involving character recognition in images. In real-world social production and daily life, there is a wide range of applications for OCR recognition in complex scenarios, such as street view text, advertising text, and movie subtitles. Among these applications, a special type of character recognition is the space character (including spaces and tabs).
[0003] In traditional OCR models, spaces in the training corpus are treated as ordinary characters during training. This approach can solve the space recognition problem effectively in a single scenario, with relatively good results. However, because characters differ across language contexts, additional interference can occur, causing the recognition performance to drop significantly when switching scenarios due to these differences. This reduces the accuracy of recognition across multiple scenarios. Summary of the Invention
[0004] Therefore, it is necessary to provide an image character recognition method, apparatus, computer equipment, and storage medium that can improve recognition accuracy in multiple scenarios to address the aforementioned technical problems.
[0005] This invention provides an image character recognition method, comprising:
[0006] The images to be recognized are subjected to character recognition and semantic segmentation respectively to obtain text information and mask images;
[0007] The space width and pixel height sequence of the text are determined based on the text information and the Mask image, and the space position information is obtained based on the space width and pixel height sequence.
[0008] The image character recognition result is obtained based on the text information and the space position information.
[0009] In one embodiment, determining the space width and pixel height sequence of the text based on the text information and the Mask image, and obtaining space position information based on the space width and pixel height sequence, includes:
[0010] In the Mask image, pixels with vertical and horizontal spacing less than a distance threshold are connected and a pixel height sequence is calculated. The average character height is then determined based on the pixel height sequence.
[0011] The language type of the text in the image to be recognized is determined based on the text information, and the space width threshold is determined based on the language type.
[0012] The product of the average height of the character and the space width threshold is used as the space width;
[0013] The space position information is obtained based on the pixel height sequence and the space width.
[0014] In one embodiment, the step of concatenating pixels in the Mask image whose vertical and horizontal spacing is less than a distance threshold, calculating a pixel height sequence, and determining the average character height based on the pixel height sequence includes:
[0015] Add a black background edge of preset height to the top and bottom edges of the Mask image to obtain a second Mask image;
[0016] The second Mask image is dilated and eroded using convolution kernels to obtain the third Mask image;
[0017] Calculate the pixel height sequence based on the third mask image, and determine the average character height of the text in the image to be recognized based on the pixel height sequence.
[0018] In one embodiment, the step of calculating a pixel height sequence based on the third Mask image and determining the average character height of the text in the image to be recognized based on the pixel height sequence includes:
[0019] Create a matrix of the same shape as the third Mask image, with all initial values of the matrix being 0;
[0020] Traverse the pixels in the third Mask image, and when the pixel value of the pixel is the pixel threshold, set the value at the same position in the same matrix to 1;
[0021] The pixel height sequence is obtained by summing the columns of the same type matrix. The average value of a preset number of values in the pixel height sequence from largest to smallest is taken as the average character height.
[0022] In one embodiment, obtaining the space position information based on the pixel height sequence and the space width includes:
[0023] Traverse the values in the pixel height sequence from left to right and extract the subsequence of consecutive 0 values;
[0024] The starting position of the subsequence whose length is greater than the width of the space is recorded as the space position information.
[0025] In one embodiment, obtaining the image character recognition result based on the text information and the space position information includes:
[0026] The relative positions of the space and the characters are determined based on the space position information and the position information of each character in the text information;
[0027] The space is inserted into the character according to the relative position to obtain the image character recognition result.
[0028] In one embodiment, inserting the space into the character according to the relative position to obtain the image character recognition result includes:
[0029] When it is determined based on the relative position that the space and the character do not overlap, the space is inserted into the middle of the character according to the relative position;
[0030] When it is determined from the relative position that the space and the character overlap and the left half of the space overlaps with the character, the space is inserted after the overlapping character;
[0031] When it is determined based on the relative position that the space and the character overlap and the right half of the space overlaps with the character, the space is inserted in front of the overlapping character.
[0032] An image character recognition device, comprising:
[0033] The model processing module is used to perform character recognition and semantic segmentation on the image to be recognized, respectively, to obtain text information and mask image;
[0034] The space determination module is used to determine the space width and pixel height sequence of the text based on the text information and the Mask image, and to obtain the space position information based on the space width and pixel height sequence.
[0035] The result determination module is used to obtain the image character recognition result based on the text information and the space position information.
[0036] The present invention also provides a computer device, the computer device including a processor and a memory, the memory storing a computer program, the processor executing the computer program to implement the steps of the image character recognition method described in any of the above claims.
[0037] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the image character recognition method described in any of the preceding claims.
[0038] The aforementioned image character recognition method, apparatus, computer device, and storage medium, after performing character recognition and semantic segmentation on the image to be recognized to obtain text information and a mask image, further determine the space width and pixel height sequence of the text based on the text information and the mask image. Then, based on the space width and pixel height sequence, obtain the space position information, and finally obtain the image character recognition result based on the text information and space position information. This method, by further determining the space position information from the text and mask image obtained through character recognition and semantic segmentation and combining it with the space information to obtain the character recognition result, starts from the space itself. Even when facing character recognition in different scenarios, it can accurately obtain the corresponding spaces first, thereby reducing the impact of differences in space characters in different scenarios and improving the accuracy of recognition. Attached Figure Description
[0039] Figure 1 This is an application environment diagram of an image character recognition method in one embodiment.
[0040] Figure 2 This is a flowchart illustrating an image character recognition method in one embodiment.
[0041] Figure 3 This is a schematic diagram of a semantic segmentation mask image in one embodiment.
[0042] Figure 4 This is a schematic diagram of the OCR character recognition result in one embodiment.
[0043] Figure 5 This is a schematic diagram of the second and third mask images in one embodiment.
[0044] Figure 6 This is a structural block diagram of an image character recognition device in one embodiment. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0046] The image character recognition method provided in this application can be applied to, for example... Figure 1 In the application environment shown, the application environment involves a terminal 102 and a server 104. The terminal 102 communicates with the server 104 via a network. The terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices, and the server 104 can be implemented as a standalone server or a server cluster consisting of multiple servers.
[0047] When terminal 102 receives a character recognition instruction, it can implement the image character recognition instruction method independently. Alternatively, terminal 102 can send the character recognition instruction to the communicating server 104, which will then implement the image character recognition instruction method. Taking server 104 as an example, specifically, server 104 performs character recognition and semantic segmentation on the image to be recognized, obtaining text information and a mask image; server 104 determines the space width and pixel height sequence of the text based on the text information and the mask image, and obtains the space position information based on the space width and pixel height sequence; server 104 obtains the image character recognition result based on the text information and the space position information.
[0048] In one embodiment, such as Figure 2 As shown, an image character recognition method is provided, and the method is illustrated using a server as an example. The method includes the following steps:
[0049] Step S201: Perform character recognition and semantic segmentation on the image to be recognized to obtain text information and mask image.
[0050] Specifically, upon receiving an image character recognition instruction, the image to be recognized, Img, is acquired. Then, semantic segmentation processing is performed on the image to be recognized to obtain the corresponding Mask image, MaskImg. The resulting Mask image, MaskImg, is the same size as the original image to be recognized, Img, and is an image with a black background and white text outlines; except for the white text lines, the rest is black, such as... Figure 3 The diagram illustrates a semantic segmentation method for masked images. Semantic segmentation can utilize a pre-trained semantic segmentation model, which can employ any existing framework, such as PidNet, Mask R-CNN, Mask2Former, Unet, etc. This embodiment, considering speed and accuracy, preferably uses the Unet version to train the semantic segmentation model. Simultaneously with semantic segmentation, character recognition is performed on the image to be recognized to obtain the recognized text, text position, and confidence level as text information, such as... Figure 4 The diagram shown illustrates an OCR character recognition result. Figure 4 The following is shown Figure 3 The image Img shown is an OCR recognition result. Character recognition can be performed by processing the CTC sequence using a trained OCR recognition model, and then decoding the CTC sequence to obtain the text information. The OCR model framework can be flexibly selected, but it must be a recognition model based on CTC decoding, such as CRNN, Deep, etc. In this embodiment, Deep training is preferred as the OCR recognition model.
[0051] In addition, to train semantic segmentation and OCR recognition models, diverse background images, various fonts, and OCR word / sentence corpora can be utilized. Specifically, first, an image is randomly selected from a diverse background image library, and a preset size (e.g., 320×32 pixels wide × high) is randomly cropped from the background image as the background image. A pure black image of the same size as the background image is created using OpenCV as the mask background image. A font color is selected based on the background, and a font and suitable text corpus are randomly chosen and written onto the generated background image as the OCR image corpus. A white font color is selected, and the same font and text corpus are chosen and written onto the generated mask background image as the mask image corpus. The OCR image corpus and the mask image corpus should be completely identical in all aspects (text, position, font size) except for the background and color. Then, the above process is repeated to obtain sufficient OCR image corpus and mask image corpus as training data for OCR and semantic segmentation.
[0052] Step S202: Determine the sequence of space width and pixel height of the text based on the text information and the Mask image, and obtain the space position information based on the sequence of space width and pixel height.
[0053] Here, the space width refers to the width of the space character in the image to be recognized, the pixel height sequence is the sequence used to represent the pixel height in the image to be recognized, that is, the height of the text character in the image to be recognized, and the space position information is the information used to indicate the position of the space in the text.
[0054] Specifically, after obtaining the text information and the mask image, to accurately determine the position information of spaces in the text and ensure accurate character recognition, the space width and pixel height sequences are first obtained using the text information and the mask image. Then, the space position information is obtained based on the correspondence between the space width and pixel height sequences.
[0055] In one embodiment, step S202 includes: connecting pixels in the Mask image whose vertical and horizontal spacing is less than a distance threshold and then calculating a pixel height sequence; determining the average character height based on the pixel height sequence; determining the language type of the text in the image to be recognized based on the text information; determining a space width threshold based on the language type; using the product of the average character height and the space width threshold as the space width; and obtaining space position information based on the pixel height sequence and the space width.
[0056] Specifically, firstly, pixels in the mask image with vertical and horizontal spacing less than a distance threshold are connected together. This makes the pixels of the same character more compact without changing the character height or connecting pixels that are too far apart horizontally. Then, a pixel height sequence is calculated based on the mask image after pixel connection. This sequence can be obtained by treating the image as a matrix and each pixel as a matrix value. The average character height (MeanHeight) is then calculated based on the average of the values in the pixel height sequence. Simultaneously, the language type of the text in the image to be recognized is determined based on the text information. Different language types have different space width thresholds. The space width threshold is set based on the actual language type; generally, if the text contains Chinese, the language type is considered Chinese; otherwise, it is English. The space width threshold for Chinese is 0.5, and for English it is 0.3. Finally, the product of the average character height and the space width threshold is used as the space width (ThresHold), i.e., ThresHold = 0.5 × MeanHeight for Chinese and 0.3 × MeanHeight for English. The space position information is then obtained based on the pixel height sequence and the space width.
[0057] In one embodiment, after connecting pixels in the Mask image whose vertical and horizontal spacing is less than a distance threshold, a pixel height sequence is calculated, and the average character height is determined based on the pixel height sequence, the process includes: adding a black background edge of preset height to the top and bottom edges of the Mask image to obtain a second Mask image; performing dilation and erosion on the second Mask image using a convolution kernel to obtain a third Mask image; calculating a pixel height sequence based on the third Mask image; and determining the average character height of the text in the image to be recognized based on the pixel height sequence.
[0058] Specifically, for the obtained Mask image MaskImg, a black background edge of preset height is added to the top and bottom edges of the image. In this embodiment, the preset height is preferably 16 pixels high, meaning a 16-pixel-high black background edge is added to the top and bottom edges of the image to obtain the second Mask image MaskImg2. Taking a width × height of 320 × 32 as an example, adding 16 pixels results in a width and height of 320 × 64. Then, a 16 × 3 convolutional kernel is used to first dilate the second Mask image MaskImg2, and then erode it to obtain the third Mask image MaskImg3, thereby connecting pixels that are close in both the vertical and horizontal directions. Figure 5The diagram illustrates a second mask image and a third mask image. Finally, the average character height (MeanHeight) is determined by calculating the pixel height sequence based on the third mask image (MaskImg3).
[0059] In one embodiment, calculating a pixel height sequence based on a third mask image and determining the average character height of text in the image to be recognized based on the pixel height sequence includes: creating a matrix of the same shape as the third mask image, with the initial values of the matrix all being 0; traversing the pixels in the third mask image, and when the pixel value of a pixel is a pixel threshold, setting the value at the same position in the matrix to 1; summing the matrix column-wise to obtain a pixel height sequence, and taking the average of a preset number of values in the pixel height sequence from largest to smallest as the average character height.
[0060] Specifically, when calculating the average height of characters in the third Mask image (MaskImg3), a matrix (matrix) of the same type as MaskImg3 is first created, with all values in the matrix initialized to 0. Then, for all pixels in MaskImg3, their pixel values are determined. If a pixel value is greater than a pixel threshold of 127 (this threshold is the target pixel value in the semantic segmentation result, i.e., the semantic segmentation trained in this embodiment; values greater than 127 represent text targets, and values less than 127 represent background), the corresponding pixel value in the matrix is set to 1. Finally, the matrix is summed column-wise to obtain the pixel height sequence PixHeightSeq. The average value of the 10% largest values in the pixel height sequence PixHeightSeq is then taken as the average character height MeanHeight. That is, the number of values taken from the pixel height sequence is 10% of its total length, and these 10% of the sequence values are the largest values. For example, assuming 10% of the pixels contain 8 values, it is equivalent to arranging the values in the sequence from largest to smallest, taking the first 8 values, and then calculating the average of these 8 values as the character's average height (MeanHeight).
[0061] In one embodiment, obtaining the space position information based on the pixel height sequence and the space width includes: traversing the values in the pixel height sequence from left to right and extracting a subsequence with consecutive 0 values; and recording the starting position of the subsequence with a length greater than the space width as the space position information.
[0062] Specifically, the process extracts subsequences with consecutive 0 values from the pixel height sequence. Taking the pixel height sequence PixHeightSeq={12,12,11,1,0,0,0,0,0,0,0,19,19,0,0,0,0,0,6} as an example, the extracted subsequences include {0,0,0,0,0,0,0} and {0,0,0,0,0}. Then, the width of the space is compared with the length of the subsequence. A subsequence with a length greater than the space width is considered a space, and its starting position information is recorded as the space position information SpaceInfo. All SpaceInfo values are grouped into a set SpaceInfoList=[SpaceInfo1, SpaceInfo2, ...]. In other words, for the obtained pixel height sequence PixHeightSeq, the number of consecutive 0 values (ZeroNum) is calculated from left to right. If ZeroNum is greater than the space width ThresHold, it indicates that this consecutive 0 subsequence is a space, and the starting position information of the subsequence is recorded and saved as SpaceInfo.
[0063] Step S203: Obtain the image character recognition result based on the text information and space position information.
[0064] Specifically, once the space position information is obtained, the position of the space in the text can be determined based on the position of the characters and the space position information in the text information. Then, the space is inserted into the corresponding position in the recognized text to obtain the image character recognition result.
[0065] In one embodiment, step S203 includes: determining the relative position of the space and the character based on the space position information and the position information of each character in the text information; inserting the space into the character according to the relative position to obtain the image character recognition result.
[0066] Specifically, for each space position information, the relative position of the character and the space is determined among the character positions included in the text information. Then, the positional relationship between the character and the space is determined based on the relative position, and the space is inserted into the recognized text to obtain the final character recognition result ResTextInfoListList.
[0067] In one embodiment, the relative positions of spaces and characters include overlapping and non-overlapping. Therefore, inserting spaces into characters based on their relative positions yields image character recognition results as follows: when the relative positions determine that spaces and characters do not overlap, the space is inserted in the middle of the character; when the relative positions determine that spaces and characters overlap and the left half of the space overlaps with the character, the space is inserted after the overlapping character; when the relative positions determine that spaces and characters overlap and the right half of the space overlaps with the character, the space is inserted before the overlapping character.
[0068] Specifically, relative positioning mainly includes two cases: one is that the character and space positions overlap, and the other is that they do not overlap. If there is no overlap, the space is inserted in the middle of the characters according to their positional relationship. If the character and space overlap, there are two further cases: if the overlapping part is on the left half of the space character area, the space is inserted after the overlapping character on the left half; if the overlapping part is on the right half of the space character area, the space is inserted before the overlapping character on the right half, thus obtaining the final character recognition result ResTextInfoListList.
[0069] The aforementioned image character recognition method, after performing character recognition and semantic segmentation on the image to be recognized to obtain text information and a mask image, further determines the space width and pixel height sequence of the text based on the text information and the mask image. Then, it obtains the space position information based on the space width and pixel height sequence, and finally obtains the image character recognition result based on the text information and space position information. This method, by further determining the space position information from the text and mask images obtained through character recognition and semantic segmentation and combining this information with the space information to obtain the character recognition result, starts from the space itself. Even when facing character recognition in different scenarios, it can accurately obtain the corresponding spaces first, thereby reducing the impact of differences in space characters in different scenarios and improving the accuracy of recognition.
[0070] It should be understood that, although Figure 2 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 At least some of the steps in the process may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but may be executed at different times. The execution order of these steps or stages is not necessarily sequential, but may be executed in turn or alternately with other steps or at least some of the steps or stages in other steps.
[0071] In one embodiment, such as Figure 6 As shown, an image character recognition device is provided, comprising:
[0072] The model processing module 601 is used to perform character recognition and semantic segmentation on the image to be recognized to obtain text information and mask image.
[0073] The space determination module 602 is used to determine the space width and pixel height sequence of the text based on the text information and the mask image, and to obtain the space position information based on the space width and pixel height sequence.
[0074] The result determination module 603 is used to obtain the image character recognition result based on the text information and the space position information.
[0075] In one embodiment, the space determination module 602 is further configured to: connect pixels in the Mask image whose vertical and horizontal spacing is less than a distance threshold; calculate a pixel height sequence; determine the average character height based on the pixel height sequence; determine the language type of the text in the image to be recognized based on the text information; determine a space width threshold based on the language type; use the product of the average character height and the space width threshold as the space width; and obtain the space position information based on the pixel height sequence and the space width.
[0076] In one embodiment, the space determination module 602 is further configured to add a black background edge of preset height to the top and bottom edges of the Mask image to obtain a second Mask image; to dilate and erode the second Mask image using a convolution kernel to obtain a third Mask image; to calculate a pixel height sequence based on the third Mask image, and to determine the average character height of the text in the image to be recognized based on the pixel height sequence.
[0077] In one embodiment, the space determination module 602 is further configured to create a similar matrix of the third Mask image, the initial values of which are all 0; traverse the pixels in the third Mask image, and when the pixel value of a pixel is a pixel threshold, set the value at the same position in the similar matrix to 1; sum the similar matrix column by column to obtain a pixel height sequence, and take the average of a preset number of values in the pixel height sequence from largest to smallest as the average character height.
[0078] In one embodiment, the space determination module 602 is further configured to traverse the values in the pixel height sequence from left to right, extract the subsequence with consecutive 0 values, and record the starting position of the subsequence with a length greater than the space width as the space position information.
[0079] In one embodiment, the result determination module 603 is used to determine the relative position of the space and the character based on the space position information and the position information of each character in the text information; and insert the space into the character according to the relative position to obtain the image character recognition result.
[0080] In one embodiment, the result determination module 603 is further configured to: insert the space into the middle of the character according to the relative position when it is determined that the space and the character do not overlap according to the relative position; insert the space after the overlapping character when it is determined that the space and the character overlap according to the relative position and the left half of the space overlaps with the character; and insert the space before the overlapping character when it is determined that the space and the character overlap according to the relative position and the right half of the space overlaps with the character.
[0081] Specific limitations regarding the image character recognition device can be found in the limitations of the image character recognition method described above, and will not be repeated here. Each module in the aforementioned image character recognition device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the above-described image character recognition method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms.
[0082] In one embodiment, a computer device is provided, which may be a server, including a processor, memory, and a network interface. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements an image character recognition method. Exemplarily, the computer program may be divided into one or more modules, one or more of which are stored in memory and executed by the processor to complete the present invention. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the computer device.
[0083] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the computer device, connecting various parts of the computer device via various interfaces and lines.
[0084] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the computer device by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0085] Those skilled in the art will understand that the computer device structure shown in this embodiment is only a partial structure related to the present invention and does not constitute a limitation on the computer device to which the present invention is applied. A specific computer device may include more or fewer components, or combine certain components, or have different component arrangements.
[0086] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the image character recognition method described in any of the above embodiments.
[0087] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the image character recognition method described in any of the above embodiments.
[0088] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0089] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0090] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. An image character recognition method, characterized by, include: The images to be recognized are subjected to character recognition and semantic segmentation respectively to obtain text information and mask images; The space width and pixel height sequence of the text are determined based on the text information and the Mask image, and the space position information is obtained based on the space width and pixel height sequence. Obtaining image character recognition results based on the text information and the space position information includes: determining the relative position of the space and the character based on the space position information and the position information of each character in the text information; inserting the space into the character according to the relative position to obtain the image character recognition result; specifically including: when it is determined based on the relative position that the space and the character do not overlap, inserting the space into the middle of the character according to the relative position; when it is determined based on the relative position that the space and the character overlap and the left half of the space overlaps with the character, inserting the space after the overlapping character; when it is determined based on the relative position that the space and the character overlap and the right half of the space overlaps with the character, inserting the space before the overlapping character.
2. The method according to claim 1, characterized in that, The step of determining the space width and pixel height sequence of the text based on the text information and the Mask image, and obtaining the space position information based on the space width and pixel height sequence, includes: In the Mask image, pixels with vertical and horizontal spacing less than a distance threshold are connected and a pixel height sequence is calculated. The average character height is then determined based on the pixel height sequence. The language type of the text in the image to be recognized is determined based on the text information, and the space width threshold is determined based on the language type. The product of the average height of the character and the space width threshold is used as the space width; The space position information is obtained based on the pixel height sequence and the space width.
3. The method according to claim 2, characterized in that, The step of connecting pixels in the Mask image whose vertical and horizontal spacing is less than a distance threshold, calculating a pixel height sequence, and determining the average character height based on the pixel height sequence includes: Add a black background edge of preset height to the top and bottom edges of the Mask image to obtain a second Mask image; The second Mask image is dilated and eroded using convolution kernels to obtain the third Mask image; Calculate the pixel height sequence based on the third mask image, and determine the average character height of the text in the image to be recognized based on the pixel height sequence.
4. The method according to claim 3, characterized in that, The step of calculating the pixel height sequence based on the third Mask image and determining the average character height of the text in the image to be recognized based on the pixel height sequence includes: Create a matrix of the same shape as the third Mask image, with all initial values of the matrix being 0; Traverse the pixels in the third Mask image, and when the pixel value of the pixel is the pixel threshold, set the value at the same position in the same matrix to 1; The pixel height sequence is obtained by summing the columns of the same type matrix. The average value of a preset number of values in the pixel height sequence from largest to smallest is taken as the average character height.
5. The method according to claim 2, characterized in that, The step of obtaining the space position information based on the pixel height sequence and the space width includes: Traverse the values in the pixel height sequence from left to right and extract the subsequence of consecutive 0 values; The starting position of the subsequence whose length is greater than the width of the space is recorded as the space position information.
6. An image character recognition device, characterized in that, include: The model processing module is used to perform character recognition and semantic segmentation on the image to be recognized, respectively, to obtain text information and mask image; The space determination module is used to determine the space width and pixel height sequence of the text based on the text information and the Mask image, and to obtain the space position information based on the space width and pixel height sequence. The result determination module is used to obtain an image character recognition result based on the text information and the space position information. Specifically, it is used to determine the relative position of the space and the character based on the space position information and the position information of each character in the text information, and insert the space into the character according to the relative position to obtain the image character recognition result. Further, it is used to insert the space into the middle of the character according to the relative position when it is determined that the space and the character do not overlap; when it is determined that the space and the character overlap and the left half of the space overlaps with the character, it inserts the space after the overlapping character; and when it is determined that the space and the character overlap and the right half of the space overlaps with the character, it inserts the space before the overlapping character.
7. A computer device comprising a processor and a memory, wherein the memory stores a computer program, characterized in that, The processor is used to execute the computer program to implement the image character recognition method according to any one of claims 1-5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the image character recognition method according to any one of claims 1-5.
Citation Information
Patent Citations
A device and method for performing optical character recognition
CN106687992A
Method and device for recognizing text in image, computer equipment and computer storage medium
CN111291629A