OCR image processing method and device
Through the pixel unit discrimination and processing in the filter core, watermark interference is effectively removed, the accuracy of OCR recognition and layout recovery effect is improved, and the problem of watermark affecting recognition in the prior art is solved.
Patent Information
- Application Number
- CN202510339507.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-07-08
AI Technical Summary
When using images containing watermarks, it is difficult to effectively remove grayscale watermarks and watermarks with high degree of fusion with the background, resulting in a decrease in recognition accuracy and the watermark text may be incorrectly inserted into the text text.
By passing through a plurality of pixel units arranged in rows and columns in the filter core, the grayscale thresholds of the first and second pixel units are determined based on the text layout of the image to be identified, and the interference pixel is determined and changed to the background pixel value to generate a target image.
It improves the removal effect of watermarks and other interference factors, improves the accuracy of OCR recognition, avoids the misidentification of watermark text, and improves the quality of layout recovery.
Smart Images

Figure CN120279562A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular, to a method and apparatus for processing OCR images. Background Art
[0002] Optical Character Recognition (OCR) technology is used to perform optical image recognition on the text in a picture to achieve the recognition and extraction of the text information in the picture. However, since there are usually some interference factors in the picture (such as watermarks and noise pollution introduced during the picture shooting or document scanning of graphics and pictures), these interference factors will affect the OCR recognition accuracy. For example, when performing OCR recognition and layout restoration on a picture containing a watermark, the watermark may affect the detection and recognition accuracy of layout recognition, chart recognition, table recognition, and text recognition, and during the recognition process, text containing a watermark (or other cloud-like interference noise pixels) may also be recognized as a graph or table, and the text in the watermark (such as a company logo icon graph) may be incorrectly inserted into the recognized text sequence of the main text.
[0003] Currently, it is possible to remove the watermark by recognizing and utilizing the color difference between the watermark and the background area, but the method of removing the watermark based on the color difference has a poor removal effect on grayscale watermarks without color and watermarks with a high degree of fusion with the background. Summary of the Invention
[0004] The present application provides a method and apparatus for processing OCR images, which can remove interference factors such as watermarks in the image to be recognized through multiple pixel units arranged in rows and columns in the filter kernel, and improve the removal effect of interference factors such as watermarks in the image to be recognized.
[0005] In a first aspect of the present application, there is provided a method for processing an OCR image, including:
[0006] Obtain an image to be recognized, and based on the respective grayscale values of the pixels to be processed in the image to be recognized and the respective grayscale thresholds of the pixel units in the corresponding filter kernel, determine the pixels to be processed corresponding to the first pixel unit to obtain a determination result; wherein, the filter kernel is determined based on the text layout in the image to be recognized, the filter kernel includes a first pixel unit and a second pixel unit, and the first grayscale threshold corresponding to the first pixel unit is greater than the second grayscale threshold corresponding to the second pixel unit;
[0007] If the determination result indicates that the pixel to be processed is an interference pixel, change the pixel value of the pixel to be processed to the background pixel value;
[0008] When the discrimination of all the to-be-processed pixels is completed, a target image is obtained.
[0009] In some embodiments,
[0010] Based on the gray values of the to-be-processed pixels in the to-be-recognized image and the gray thresholds of the pixel units in the corresponding filter kernel, discriminating the to-be-processed pixel corresponding to the first pixel unit to obtain a discrimination result, including:
[0011] Using the filter kernel as a sliding window to traverse the multiple to-be-processed pixels;
[0012] If the gray value of the target to-be-processed pixel in the sliding window of the sliding window is greater than the first gray threshold corresponding to the first pixel unit, determining the magnitude relationship between the gray values of the multiple neighboring to-be-processed pixels in the sliding window and the second gray thresholds corresponding to the multiple second pixel units; wherein, the target to-be-processed pixel corresponds to the first pixel unit, and the neighboring to-be-processed pixels correspond to the second pixel units;
[0013] Based on the magnitude relationship between the gray value of the neighboring to-be-processed pixel and the second gray threshold, determining the discrimination result corresponding to the target to-be-processed pixel.
[0014] In some embodiments, the determining the discrimination result corresponding to the target to-be-processed pixel based on the magnitude relationship between the gray value of the neighboring to-be-processed pixel and the second gray threshold includes:
[0015] If there is a first to-be-processed pixel among the multiple neighboring to-be-processed pixels, determining that the discrimination result indicates that the target to-be-processed pixel is the interference pixel; wherein, the gray value of the first to-be-processed pixel is greater than the second gray threshold.
[0016] In some embodiments, the method further includes:
[0017] Generating the filter kernel based on the text layout in the to-be-recognized image, determining at least one of the first pixel units from the multiple pixel units in the filter kernel, and determining the other pixel units except the first pixel unit among the multiple pixel units as the second pixel units.
[0018] In some embodiments, the determining at least one of the first pixel units from the multiple pixel units in the filter kernel includes:
[0019] Determining the geometric center of the multiple pixel units, and determining the pixel unit corresponding to the geometric center as the first pixel unit.
[0020] In some embodiments, the first grayscale threshold is the sum of the minimum value among the grayscale values corresponding to multiple interfering pixels in the image to be recognized and an adjustment parameter; wherein, the adjustment parameter is less than the difference between the maximum value and the minimum value among the grayscale values corresponding to the multiple interfering pixels.
[0021] In some embodiments, the second grayscale threshold is greater than or equal to the minimum value among the target grayscale values corresponding to multiple target pixels in the image to be recognized, and less than or equal to the first grayscale threshold.
[0022] In some embodiments, the method further includes:
[0023] If the grayscale value of the target pixel to be processed in the sliding window of the sliding window is less than or equal to the first grayscale threshold, or the grayscale value of the target pixel to be processed in the sliding window of the sliding window is greater than the first grayscale threshold, and the first pixel to be processed does not exist among the neighboring pixels to be processed, then the discrimination result is that the target pixel to be processed is a target pixel, and the target pixel to be processed is retained.
[0024] In some embodiments, the method further includes:
[0025] Recognize the target image to obtain a recognition result.
[0026] In a second aspect of the present application, there is provided a processing device for OCR images, including:
[0027] An acquisition module, configured to acquire an image to be recognized;
[0028] A discrimination module, configured to discriminate the pixel to be processed corresponding to the first pixel unit based on the grayscale value of each pixel to be processed in the image to be recognized and the grayscale threshold of each pixel unit in the corresponding filter kernel, to obtain a discrimination result; wherein, the filter kernel is determined based on the text layout in the image to be recognized, the filter kernel includes a first pixel unit and a second pixel unit, and the first grayscale threshold corresponding to the first pixel unit is greater than the second grayscale threshold corresponding to the second pixel unit;
[0029] A processing module, configured to change the pixel value of the pixel to be processed to the background pixel value if the discrimination result indicates that the pixel to be processed is an interfering pixel; when the discrimination of multiple pixels to be processed is completed, a target image is obtained.
[0030] In a third aspect of the present application, there is provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the program, the steps of the method according to any one of the above embodiments are implemented.
[0031] In a fourth aspect of the present application, there is provided a non-transitory computer-readable storage medium storing a computer program thereon, characterized in that when the computer program is executed by a processor, the steps of the method according to any one of the above embodiments are implemented.
[0032] An embodiment of the present application provides a method for processing an OCR image, including: obtaining an image to be recognized, and based on the respective gray values of the pixels to be processed in the image to be recognized and the respective gray thresholds of the pixel units in the corresponding filter kernel, discriminating the pixels to be processed corresponding to the first pixel unit to obtain a discrimination result; wherein, the filter kernel is determined based on the text layout in the image to be recognized, the filter kernel includes a first pixel unit and a second pixel unit, and the first gray threshold corresponding to the first pixel unit is greater than the second gray threshold corresponding to the second pixel unit; if the discrimination result indicates that the pixel to be processed is an interfering pixel, changing the pixel value of the pixel to be processed to the background pixel value; when the discrimination of multiple pixels to be processed is completed, obtaining a target image; thus, by using multiple pixel units arranged in rows and columns in the filter kernel to remove interfering factors such as watermarks in the image to be recognized, the removal effect of interfering factors such as watermarks in the image to be recognized can be improved, and further the subsequent recognition accuracy can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required to be used in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention, and those of ordinary skill in the art can also obtain other drawings based on these drawings without creative efforts.
[0034] Figure 1 It is a schematic flowchart of a method for processing an OCR image provided by an embodiment of the present application;
[0035] Figure 2 It is a schematic structural diagram of a filter kernel provided by an embodiment of the present application;
[0036] Figure 3 It is a schematic structural diagram of another filter kernel provided by an embodiment of the present application;
[0037] Figure 4 It is a schematic flowchart of yet another method for processing an OCR image provided by an embodiment of the present application;
[0038] Figure 5 It is a schematic structural diagram of an OCR image processing device provided by an embodiment of the present application;
[0039] Figure 6 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0040] To make the objectives, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below with reference to the accompanying drawings in this application.
[0041] Optical Character Recognition (OCR) technology is used to perform optical image recognition on the text in pictures to achieve the recognition and extraction of the text information in the pictures. However, since there are usually some interference factors in pictures (such as watermarks and noise pollution introduced during the picture shooting or document scanning process of graphics and pictures), these interference factors will affect the OCR recognition accuracy. For example, when performing OCR recognition and layout restoration on pictures containing watermarks, the watermarks may affect the detection and recognition accuracy of layout recognition, chart recognition, table recognition, and text recognition. Moreover, during the recognition process, the text containing watermarks (or other cloud-shaped interference noise pixels) may be recognized as a picture or a table, and the text in the watermark (such as the company logo icon graphics) may be incorrectly inserted into the recognized text sequence of the main text.
[0042] Currently, watermarks can be removed by recognizing and utilizing the color difference between the watermark and the background area. Also, based on the texture information in the image, by extracting the texture features of the watermark area and the background, and using the feature matching algorithm to recognize the unique texture structure of the watermark. Then, new content for filling the watermark position is generated according to the background texture features, so that the repaired area seamlessly connects with the original background to achieve a natural transition visually, thereby removing the watermark. The image containing the watermark can also be divided into two major parts: the watermark area and the background area. After that, these two parts are processed independently. For example: first, accurately locate the watermark boundary through algorithms such as threshold segmentation and edge detection, and then selectively change the gray value of the watermark area or directly fill the background data to remove the watermark trace.
[0043] However, in the above methods, the method of removing watermarks based on color difference has a poor removal effect on gray watermarks without color and watermarks with a high degree of fusion with the background; the method of removing watermarks based on texture features is only effective for watermarks with significant texture features, and has a poor effect on single-color or low-frequency changing watermarks; the method of removing watermarks based on image segmentation is usually not applicable to the scenario where the boundary between the watermark and the main content of the image is blurred. Moreover, since the watermarks and the main text in the document are usually deeply intertwined, this method not only cannot guarantee the image quality after removing the watermark, but also is not applicable to the elimination of watermarks and similar interference pixels.
[0044] To solve the above technical problems, the present application provides a method for processing OCR images, which can remove interference factors such as watermarks in the image to be recognized through multiple pixel units arranged in rows and columns in the filter kernel. In this way, the removal effect of interference factors such as watermarks in the image to be recognized can be improved.
[0045] Figure 1 A schematic flowchart of a method for processing OCR images is provided. Refer to Figure 1 In an embodiment of the present application, a method for processing OCR images is provided, including S101 - S103.
[0046] S101. Obtain the image to be recognized, and based on the respective gray values of the pixels to be processed in the image to be recognized and the respective gray thresholds of the pixel units in the corresponding filter kernel, discriminate the pixels to be processed corresponding to the first pixel unit to obtain a discrimination result.
[0047] Among them, the filter kernel is determined based on the text layout in the image to be recognized. The filter kernel includes a first pixel unit and a second pixel unit, and the first gray threshold corresponding to the first pixel unit is greater than the second gray threshold corresponding to the second pixel unit.
[0048] In some embodiments, the image to be recognized is an image including a watermark and body text. Among them, the image to be recognized can be a color image or a black - and - white image, and the embodiments of the present application do not limit this. In the following embodiments, the image to be recognized is taken as an example of a black - and - white image for illustrative purposes.
[0049] In some embodiments, the discrimination result at least includes that the target pixel to be processed is a target pixel and that the target pixel to be processed is an interference pixel.
[0050] Exemplarily, the interference pixel refers to the pixel corresponding to an interference element such as a watermark in the image to be recognized; the target pixel refers to the non - interference pixel in the image to be recognized, that is, the pixel in the image to be recognized other than the pixel corresponding to the interference element such as the watermark.
[0051] It should be noted that the gray value of the interference pixel (G w ) corresponding to the watermark in the image to be recognized usually has a certain difference (d w =) from the background pixel (d w ) corresponding to the background in the image to be recognized, that is, d w =|G w -G b |; among them, the text pixels corresponding to the body text in the image to be recognized include typical pixels and non - typical pixels, and the gray - level difference between the typical pixels and the background will be larger than d wLarge, the grayscale of non - typical pixels is close to that of interfering pixels, resulting in poor performance in distinguishing interfering pixels and non - typical pixels in text pixels by pixel grayscale. However, since the distance between non - typical pixels and typical pixels is closer than the distance between interfering pixels and typical pixels, that is, the distance between non - typical pixels and typical pixels is less than the distance between interfering pixels and typical pixels, it can be determined that there are differences in the spatial correlation between non - typical pixels in the body text and interfering pixels and typical pixels in the body text respectively. In some scenarios, the minimum grayscale of interfering pixels is usually less than the minimum grayscale of text pixels, and some of the pixel grayscales in interfering pixels usually coincide with the pixel grayscales of the body text. However, the pixels in text pixels that coincide with the grayscale of interfering pixels are usually located at the outer edge and inner edge of the text in the body text, that is, the interfering pixels are geometrically adjacent to text pixels with lower grayscale. Therefore, a filter kernel can be determined based on the spatial geometric distance difference and grayscale difference between interfering pixels and text pixels, that is, the filter kernel can be determined according to the text layout in the image to be recognized.
[0052] In some embodiments, the filter kernel includes a plurality of pixel units, and each pixel unit corresponds to a grayscale threshold. The discrimination of each pixel to be processed in the image to be recognized can be determined based on the grayscale thresholds corresponding to the plurality of pixel units in the filter kernel, so as to determine whether each pixel to be processed in the image to be recognized is an interfering pixel. Among them, the plurality of pixel units can be arranged according to the text layout in the image to be recognized to form a filter kernel, that is, the arrangement shape of the plurality of pixel units (which can also be called the shape of the filter kernel) can be determined according to the text layout in the image to be recognized. For example, the shape of the filter kernel can be rectangular or fan - shaped. The embodiments of the present application do not limit this. In the following embodiments, the shape of the filter kernel is taken as an example of a rectangle for exemplary illustration.
[0053] Exemplarily, Figure 2 shows a schematic structural diagram of a filter kernel. As Figure 2 shown, the plurality of pixel units 21 in the filter kernel 20 can be arranged in rows and columns, so that the shape of the filter kernel 20 is rectangular.
[0054] In some embodiments, the size of the filter kernel can be determined according to the text layout in the image to be recognized. For example, when the shape of the filter kernel is rectangular, the size of the filter can be m by n. Among them, m and n can be equal or not equal. The embodiments of the present application do not limit the size of the filter kernel either.
[0055] Exemplarily, as Figure 2 shown, the size of the filter can be 3×3 (as shown in a of Figure 2 ), that is, both m and n are 3, and the size of the filter can also be 5×4 (as shown in b of Figure 2 ).
[0056] It should be noted that, as shown by b in Figure 2 , when m > n, it is possible to improve the protection effect on the strokes of the body text characters appearing in the form of rows, thereby improving the recognition accuracy.
[0057] In some application scenarios, in order to improve the discrimination accuracy of the pixels to be processed and improve the recognition accuracy of the image to be recognized, it is possible to make multiple pixel units in the filter kernel correspond to at least two gray thresholds. That is, according to actual requirements, a first pixel unit and a second pixel unit can be respectively determined among the multiple pixel units in the filter kernel, where the first pixel unit corresponds to a first gray threshold, the second pixel unit corresponds to a second gray threshold, and the first gray threshold is different from the second gray threshold.
[0058] In some embodiments, based on the text layout in the image to be recognized, a filter kernel is generated, and at least one first pixel unit is determined from the multiple pixel units in the filter kernel, and the other pixel units except the first pixel unit among the multiple pixel units are determined as second pixel units.
[0059] Exemplarily, after generating the filter kernel based on the text layout in the image to be recognized, at least one first pixel unit can be determined from the multiple pixel units in the filter kernel according to actual requirements; for example, the geometric center of the filter kernel is determined as the first pixel unit. The other pixel units except the first pixel unit among the multiple pixel units are determined as second pixel units. The embodiments of the present application do not limit the positions of the first pixel unit and the second pixel unit in the filter kernel.
[0060] It should be noted that the number of first pixel units can be one or multiple. The embodiments of the present application do not limit this. In the following embodiments, an example is given with the number of first pixel units being one.
[0061] In some embodiments, determining at least one first pixel unit from the multiple pixel units in the filter kernel includes: determining the geometric center of the multiple pixel units, and determining the pixel unit corresponding to the geometric center as the first pixel unit. The pixel units except the geometric center among the multiple pixel units are determined as second pixel units.
[0062] In some embodiments, the gray threshold corresponding to each pixel unit in the filter kernel can be determined according to the gray value of the interfering pixels in the image to be recognized and the gray value of the text pixels in the body text. The embodiments of the present application do not limit this.
[0063] In some embodiments, the first grayscale threshold is the sum of the minimum value among the grayscale values corresponding to multiple interfering pixels in the image to be recognized and an adjustment parameter. The adjustment parameter is less than the difference between the maximum value and the minimum value among the grayscale values corresponding to the multiple interfering pixels. The second grayscale threshold is greater than or equal to the minimum value among the multiple target grayscale values corresponding to the multiple target pixels in the image to be recognized and less than or equal to the first grayscale threshold.
[0064] Exemplarily, Figure 3 A schematic structural diagram of another filter kernel is shown, as Figure 3 shown. The first grayscale threshold corresponding to the first pixel unit in the filter kernel can be G ts , and the second grayscale threshold corresponding to the second pixel unit can be G ta . Let the grayscale value of the background pixel in the image to be recognized be G b , and the background grayscale threshold of the background pixel be G B ; let the grayscale value of the interfering pixel in the image to be recognized be G w , the minimum grayscale value among the interfering pixels be G wm , and the maximum grayscale value among the interfering pixels be G wM ; let the grayscale value of the text pixel in the image to be recognized be G c , the minimum grayscale value among the text pixels be G cm , and the maximum grayscale value among the text pixels be G cM . Among them, the grayscale value G b of the background pixel in the image to be recognized is ≥G B , the grayscale value G w of the interfering pixel in the image to be recognized ∈[G wm , G wM , and the grayscale value G c of the text pixel in the image to be recognized ∈[G cm , G cM . In the scenario where the image to be recognized has a white background and black text, generally G cm <G wm <G wM <G B ≤G b , G cm <G wm <G cM . In this scenario, the first grayscale threshold G ts corresponding to the first pixel unit in the filter kernel = G wm +δ, and G ts <G wM where δ is the adjustment parameter, δ≥0; the second grayscale threshold G ta corresponding to the second pixel unit ∈[G cm , G ts .
[0065] It should be noted that the adjustment parameter δ is a preset value, which can be determined according to actual needs, and the embodiments of the present application do not limit this.
[0066] It can be understood that the introduction of the adjustment parameter δ can improve the flexibility of the first gray-scale threshold, thereby increasing the dynamic range and error tolerance range when recognizing the image to be recognized, and further improving the subsequent recognition effect. In addition, in the embodiments of the present application, the differences between the pixels representing different contents in the image to be recognized are utilized to filter out interfering pixels, and the spatial correlation differences are also used to protect the quality of the text pixels in the main body from loss, so as to improve the effectiveness of removing interfering pixels. Moreover, through the complementary setting and collaborative work of threshold parameters such as the first gray-scale threshold and the second gray-scale threshold, the detection rate of interfering pixels and the retention rate of text pixels in the main body can be improved, and further the subsequent recognition accuracy can be improved.
[0067] In some embodiments, based on the respective gray-scale values of the pixels to be processed in the image to be recognized and the respective gray-scale thresholds of the pixel units in the corresponding filter kernel, the pixels to be processed corresponding to the first pixel unit are discriminated, and the discrimination results include: first, taking the filter kernel as a sliding window and traversing multiple pixels to be processed; then, if the gray-scale value of the target pixel to be processed in the sliding window of the sliding window is greater than the first gray-scale threshold corresponding to the first pixel unit, determining the magnitude relationship between the gray-scale values of multiple neighboring pixels to be processed in the sliding window and the second gray-scale thresholds corresponding to multiple second pixel units; where the target pixel to be processed corresponds to the first pixel unit, and the neighboring pixels to be processed correspond to the second pixel unit; based on the magnitude relationship between the gray-scale values of the neighboring pixels to be processed and the second gray-scale thresholds, determining the discrimination result corresponding to the target pixel to be processed.
[0068] Exemplarily, the filter kernel can be taken as a sliding window to traverse the image to be recognized, so as to obtain the pixel block corresponding to the image of the same size from the image to be recognized according to the filter kernel size, that is, the pixel block corresponding to the image in the sliding window area of the sliding window is taken from the image to be recognized. Among them, the pixel corresponding to the first pixel unit in the pixel block is the target pixel to be processed, and the pixel corresponding to the second pixel unit is the neighboring pixel to be processed. Comparing the gray-scale value of the target pixel to be processed with the first gray-scale threshold corresponding to the first pixel unit, if the gray-scale value of the target pixel to be processed is greater than the first gray-scale threshold corresponding to the first pixel unit, then comparing the gray-scale value corresponding to the neighboring pixel to be processed with the second gray-scale threshold corresponding to the second pixel unit to determine the magnitude relationship between the gray-scale values of multiple neighboring pixels to be processed in the sliding window and the second gray-scale thresholds corresponding to multiple second pixel units. Finally, based on the magnitude relationship between the gray-scale values of the neighboring pixels to be processed and the second gray-scale thresholds, determining the discrimination result corresponding to the target pixel to be processed.
[0069] In some embodiments, the image to be processed in the image to be recognized can be discriminated according to Formula 1 shown below:
[0070]
[0071] Formula 1 can be simplified to Formula 2 shown below:
[0072]
[0073] Wherein, P S is the pixel value of the target pixel to be processed, P b is the background pixel value, G s is the gray value of the target pixel to be processed, G a is the gray value of the neighboring pixel to be processed, G ts is the first gray threshold corresponding to the first pixel unit in the filter kernel, G ta is the second gray threshold corresponding to the second pixel unit in the filter kernel.
[0074] In some embodiments, based on Formula 2, it can be known that, based on the magnitude relationship between the gray value of the neighboring pixel to be processed and the second gray threshold, determining the discrimination result corresponding to the target pixel to be processed includes: if there is a first pixel to be processed among multiple neighboring pixels to be processed, it is determined that the discrimination result indicates that the target pixel to be processed is an interfering pixel. If the gray value of the target pixel to be processed in the sliding window of the sliding window is less than or equal to the first gray threshold, or, the gray value of the target pixel to be processed in the sliding window of the sliding window is greater than the first gray threshold and there is no first pixel to be processed among the neighboring pixels to be processed, the discrimination result is that the target pixel to be processed is a target pixel and the target pixel to be processed is retained.
[0075] Wherein, the first pixel to be processed is any pixel to be processed among multiple neighboring pixels to be processed, and the gray value of the first pixel to be processed is greater than the second gray threshold.
[0076] Exemplarily, the target pixel to be processed is the pixel to be discriminated currently. Assume that the gray value of the target pixel to be processed is G s , and the gray values of the neighboring pixels to be processed are all G a . When G s >G ts , it means that the target pixel to be processed may be an interfering pixel or may be a pixel in the overlapping part of the gray level between the text area and the watermark area in the image to be recognized. Therefore, it is necessary to further determine whether there is a pixel of G a >G a among the neighboring pixels to be processed G ta . If G a >G ta, it means that there is a first pixel to be processed among the neighboring pixels to be processed. At this time, it is determined that the target pixel to be processed is not within the text area of the image to be recognized, and the target pixel to be processed is an interference pixel, that is, it is determined that the discrimination result indicates that the target pixel to be processed is an interference pixel. If G a ≤G ta , it means that there is no first pixel to be processed among the neighboring pixels to be processed. At this time, it is determined that the target pixel to be processed is within the text area of the image to be recognized, and the target pixel to be processed is a target pixel, that is, it is determined that the discrimination result is that the target pixel to be processed is a target pixel, and the target pixel to be processed is retained.
[0077] S102. If the discrimination result indicates that the pixel value of the pixel to be processed is an interference pixel, then change the pixel value of the pixel to be processed to the background pixel value.
[0078] Exemplarily, if the discrimination result indicates that the pixel value of the target pixel to be processed is an interference pixel, then change the pixel value of the target pixel to be processed to the background pixel value. For example, assume that the pixel value of the target pixel to be processed is P s , and the background pixel value is P b . Then, when the gray value G s >G ts , and there is a pixel in the neighboring pixels to be processed G a where G a >G ta , it is determined that the pixel value of the target pixel to be processed is an interference pixel. And change the pixel value P s of the target pixel to be processed to the background pixel value P b .
[0079] S103. When the discrimination of multiple pixels to be processed is completed, the target image is obtained.
[0080] In some embodiments, the target image refers to the image to be recognized from which interference elements such as watermarks have been removed.
[0081] Exemplarily, when the discrimination of multiple pixels to be processed is completed, that is, when the image to be recognized is traversed, the image to be recognized from which interference elements such as watermarks have been removed will be obtained, that is, the target image is obtained.
[0082] In some embodiments, the OCR image processing method provided by the embodiments of the present application further includes: recognizing the target image to obtain a recognition result.
[0083] Exemplarily, after obtaining the target image, the target image can be recognized to obtain a recognition result.
[0084] In some embodiments, the target image can be recognized by Optical Character Recognition (OCR) technology to obtain a recognition result.
[0085] It can be understood that performing S101 - S102 before OCR recognition can remove interference elements such as watermarks in the image to be recognized, improve the detection and recognition accuracy of OCR - recognized text lines, and thus improve the recognition accuracy of OCR text. Moreover, this can also avoid the influence of factors such as incorrect layout recognition of the image to be recognized, the mixing of recognized watermark text in the body text, missed detection and recognition of body text lines, and incorrect recognition of body text on the layout restoration effect, thereby improving the restoration accuracy of the text layout.
[0086] It should be noted that during the execution of S101 - S102, operations such as convolution and multiplication are avoided, which can reduce the computing power requirements for hardware devices. And S101 - S102 is not only applicable to the removal of interference elements such as watermarks, but also can be applied to other application scenarios, such as: suppression of interference noise. The embodiments of the present application do not limit this. In the above - mentioned embodiments, S101 - S102 is taken as an example in the image recognition scenario for illustrative description.
[0087] In some embodiments, as Figure 4 shown, the OCR image processing method provided by the embodiments of the present application can include S401 -
[0088] S401: Input the image to be recognized.
[0089] S402: Remove the interference elements in the image to be recognized to obtain an image with interference elements removed (i.e., the target image).
[0090] Among them, the interference elements include watermarks.
[0091] In some embodiments, after reading m recognized pixel blocks from the image to be recognized based on the size of the filter kernel, the filter kernel is used as a sliding window to act on the pixel blocks to obtain an image with interference elements removed.
[0092] Exemplarily, S402 can be implemented through the following pseudo - code:
[0093]
[0094]
[0095] S403: Perform OCR recognition on the image with interference elements removed.
[0096] S404: Obtain the OCR recognition result.
[0097] Corresponding to the embodiments of the foregoing OCR image processing method, the present application also provides embodiments of an OCR image processing apparatus.
[0098] Referring to Figure 5 , an embodiment of the present application provides an OCR image processing apparatus, including:
[0099] An acquisition module 501, configured to acquire an image to be recognized;
[0100] A discrimination module 502, configured to respectively discriminate multiple pixels to be processed in the image to be recognized based on the gray values corresponding to multiple pixel units in a filter kernel, and obtain a discrimination result; wherein, the multiple pixel units are arranged in rows and columns; the gray value of a first pixel unit among the multiple pixel units is a first gray threshold, and the gray values of other pixel units except the first pixel unit are second gray thresholds; the first gray threshold is greater than the second gray threshold;
[0101] A processing module 503, configured to, if the discrimination result indicates that the pixel to be processed is an interference pixel, change the pixel value of the pixel to be processed to a background pixel value; when the discrimination of multiple pixels to be processed is completed, obtain a target image.
[0102] In some embodiments, the discrimination module 502 is further configured to use the filter kernel as a sliding window to traverse the multiple pixels to be processed; if the gray value of a target pixel to be processed in the sliding window of the sliding window is greater than the first gray threshold corresponding to the first pixel unit, determine the magnitude relationship between the gray values of multiple neighboring pixels to be processed in the sliding window and the second gray thresholds corresponding to multiple second pixel units; wherein, the first pixel unit is any one of the multiple pixel units, and the second pixel unit is any one of the other pixel units except the first pixel unit among the multiple pixel units; based on the magnitude relationship between the gray value of the neighboring pixel to be processed and the second gray threshold, determine the discrimination result corresponding to the target pixel to be processed.
[0103] In some embodiments, the discrimination module 502 is further configured to, if there is a first pixel to be processed among the multiple neighboring pixels to be processed, determine that the discrimination result indicates that the target pixel to be processed is the interference pixel; wherein, the gray value of the first pixel to be processed is greater than the second gray threshold.
[0104] In some embodiments, the discrimination module 502 is further configured to generate the filter kernel based on the text layout in the image to be recognized, determine at least one of the first pixel units from the multiple pixel units in the filter kernel, and determine the other pixel units except the first pixel unit among the multiple pixel units as second pixel units.
[0105] In some embodiments, the discrimination module 502 is further configured to determine the geometric centers of the multiple pixel units, and determine the pixel unit corresponding to the geometric center as the first pixel unit.
[0106] In some embodiments, the first gray-scale threshold is the sum of the minimum value of the gray-scale values corresponding to multiple interfering pixels in the image to be recognized and an adjustment parameter; wherein, the adjustment parameter is less than the difference between the maximum value and the minimum value of the gray-scale values corresponding to the multiple interfering pixels.
[0107] In some embodiments, the second gray-scale threshold is greater than or equal to the minimum value of the target gray-scale values corresponding to multiple target pixels in the image to be recognized, and less than or equal to the first gray-scale threshold.
[0108] In some embodiments, the discrimination module 502 is further configured to, if the gray-scale value of the target pixel to be processed in the sliding window of the sliding window is less than or equal to the first gray-scale threshold, or the gray-scale value of the target pixel to be processed in the sliding window of the sliding window is greater than the first gray-scale threshold, and the first pixel to be processed does not exist among the neighboring pixels to be processed, then the discrimination result is that the target pixel to be processed is a target pixel, and the target pixel to be processed is retained.
[0109] In some embodiments, the processing device for the OCR image further includes a recognition module, configured to recognize the target image to obtain a recognition result.
[0110] As Figure 6 shown, an electronic device provided by an embodiment of the present application may include: a processor 510, a communication interface 1020, a memory 1030, and a communication bus 1040. Among them, the processor 1010, the communication interface 1020, and the memory 1030 complete mutual communication through the communication bus 1040. The processor 1010 may call logical instructions in the memory 1030 to execute the above-mentioned various methods.
[0111] In addition, when the logical instructions in the above-mentioned memory 1030 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the mechanical state monitoring method of the switching device described in various embodiments of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.
[0112] In another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it is implemented to execute the above-mentioned various methods.
[0113] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative labor.
[0114] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment 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 technical solution, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disks, optical discs, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments or some parts of the embodiments.
[0115] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for processing OCR images, characterized in that, Including: Obtain an image to be recognized, and based on the gray values of the pixels to be processed in the image to be recognized and the gray thresholds of the pixel units in the corresponding filter kernel respectively, discriminate the pixels to be processed corresponding to the first pixel unit to obtain a discrimination result; wherein, the filter kernel is determined based on the text layout in the image to be recognized, the filter kernel includes a first pixel unit and a second pixel unit, and the first gray threshold corresponding to the first pixel unit is greater than the second gray threshold corresponding to the second pixel unit; If the discrimination result indicates that the pixel to be processed is an interfering pixel, change the pixel value of the pixel to be processed to the background pixel value; When the discrimination of multiple pixels to be processed is completed, obtain a target image.
2. The method according to claim 1, wherein The step of discriminating the pixels to be processed corresponding to the first pixel unit based on the gray values of the pixels to be processed in the image to be recognized and the gray thresholds of the pixel units in the corresponding filter kernel respectively to obtain a discrimination result includes: Use the filter kernel as a sliding window to traverse the multiple pixels to be processed; If the gray value of the target pixel to be processed in the sliding window of the sliding window is greater than the first gray threshold corresponding to the first pixel unit, determine the magnitude relationship between the gray values of the multiple neighboring pixels to be processed in the sliding window and the second gray thresholds corresponding to the multiple second pixel units; wherein, the target pixel to be processed corresponds to the first pixel unit, and the neighboring pixels to be processed correspond to the second pixel units; Based on the magnitude relationship between the gray value of the neighboring pixel to be processed and the second gray threshold, determine the discrimination result corresponding to the target pixel to be processed.
3. The method according to claim 2, wherein The step of determining the discrimination result corresponding to the target pixel to be processed based on the magnitude relationship between the gray value of the neighboring pixel to be processed and the second gray threshold includes: If there is a first pixel to be processed among the multiple neighboring pixels to be processed, determine that the discrimination result indicates that the target pixel to be processed is the interfering pixel; wherein, the gray value of the first pixel to be processed is greater than the second gray threshold.
4. The method according to claim 2, characterized in that The method further includes: Generate the filter kernel based on the text layout in the image to be recognized, determine at least one of the first pixel units from the multiple pixel units in the filter kernel, and determine the other pixel units except the first pixel unit among the multiple pixel units as the second pixel units.
5. The method according to claim 4, characterized in that, The step of determining at least one of the first pixel units from the multiple pixel units in the filter kernel includes: Determine the geometric center of the multiple pixel units, and determine the pixel unit corresponding to the geometric center as the first pixel unit.
6. The method according to claim 2, wherein The first gray threshold is the sum of the minimum value of the multiple gray values corresponding to the multiple interfering pixels in the image to be recognized and an adjustment parameter; wherein, the adjustment parameter is less than the difference between the maximum value and the minimum value of the multiple gray values corresponding to the multiple interfering pixels.
7. The method according to claim 2, characterized in that The second gray threshold is greater than or equal to the minimum value of the multiple target gray values corresponding to the multiple target pixels in the image to be recognized and less than or equal to the first gray threshold.
8. The method according to claim 3, characterized in that, The method further includes: If the gray value of the target pixel to be processed in the sliding window of the sliding window is less than or equal to the first gray threshold, or, the gray value of the target pixel to be processed in the sliding window of the sliding window is greater than the first gray threshold, and the first pixel to be processed does not exist among the neighboring pixels to be processed, then the discrimination result is that the target pixel to be processed is a target pixel, and the target pixel to be processed is retained.
9. The method according to claim 1, characterized in that, The method further includes: Performing recognition on the target image to obtain a recognition result.
10. An OCR image processing device, characterized in that, It includes: An acquisition module, configured to acquire an image to be recognized; A discrimination module, configured to respectively discriminate multiple pixels to be processed in the image to be recognized based on the gray values corresponding to multiple pixel units in a filter kernel, so as to obtain a discrimination result; wherein, the multiple pixel units are arranged in rows and columns; the gray value of the first pixel unit among the multiple pixel units is the first gray threshold, and the gray values of other pixel units except the first pixel unit are the second gray threshold; the first gray threshold is greater than the second gray threshold; A processing module, configured to change the pixel value of the pixel to be processed to the background pixel value if the discrimination result is that the pixel to be processed is an interference pixel; and obtain a target image when the discrimination of multiple pixels to be processed is completed.