Character recognition method and device, storage medium and electronic equipment
Through local contrast enhancement and global binary processing technology, the problem of poor character recognition effect in low-quality images is solved, which significantly improves the text recall and recognition accuracy, and realizes effective separation and recognition of background and text.
Patent Information
- Application Number
- CN202411102009.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2024-12-13
AI Technical Summary
When existing text recognition technology processes low-quality images, especially when there are images with bottom gray and shadows, the text recall and recognition accuracy are low, and the effect needs to be improved.
Through local contrast enhancement processing, grayscale processing and global binarization processing, background and text are separated, and optical character recognition is performed. The specific steps include selecting a local window from the image to be identified, calculating the grayscale threshold and grayscale value, enhancing the contrast, and calculating the binarization threshold through the grayscale histogram for binary processing, eliminating the background to improve the recognition accuracy.
It effectively improves the text recall rate and recognition accuracy, significantly improves the text recognition effect of low-quality images, and improves the distinction between text and background.
Smart Images

Figure CN119131805A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a text recognition method, device, storage medium and electronic device. Background Art
[0002] The application of extracting text from images through optical character recognition (OCR) is becoming more and more widespread. In the current text recognition scheme, text is usually recognized directly from the image or simply processed after the image is processed, which has a good text recognition effect for certain specific images. However, under the current method, for low-quality images with gray background and shadows, the text recall rate and text recognition accuracy are often low, and the current text recognition effect needs to be further improved. Summary of the invention
[0003] The embodiment of the present application provides a text recognition solution, which can effectively improve the text recall rate and text recognition accuracy, and improve the text recognition effect.
[0004] The embodiments of the present application provide the following technical solutions:
[0005] According to one embodiment of the present application, a text recognition method includes: performing local contrast enhancement processing on an image to be recognized to obtain an enhanced image; performing grayscale processing on the enhanced image to obtain a grayscale image; performing global binarization processing on the grayscale image to obtain a background-eliminated image; and performing optical character recognition based on the background-eliminated image to obtain text in the image to be recognized.
[0006] In some embodiments of the present application, the local contrast enhancement processing of the image to be identified to obtain an enhanced image includes: selecting multiple local windows from the image to be identified; calculating according to the pixel data of the pixel points included in each of the local windows to obtain a grayscale threshold corresponding to each of the local windows; calculating according to the pixel data of each of the pixel points to obtain a grayscale value of each of the pixel points; and performing contrast enhancement on the pixel points in each of the local windows according to the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixel points in each of the local windows to obtain the enhanced image.
[0007] In some embodiments of the present application, the contrast of the pixels in each of the local windows is enhanced according to the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixels in each of the local windows to obtain the enhanced image, including: determining the brightness enhancement coefficient matched by each of the local windows, and obtaining a preset contrast enhancement coefficient; according to the grayscale threshold corresponding to each of the local windows, the grayscale value of each of the pixels, the brightness enhancement coefficient matched by each of the local windows, and the preset contrast enhancement coefficient, the contrast of the pixels in each of the local windows is enhanced to obtain the enhanced image.
[0008] In some embodiments of the present application, the contrast enhancement of the pixels in each local window is performed according to the grayscale threshold corresponding to each local window, the grayscale value of each pixel, the brightness enhancement coefficient matched by each local window, and the preset contrast enhancement coefficient to obtain the enhanced image, including: according to formula I new (i,j)=(I avg +C*(I old (i,j)-I avg ))*B performs contrast enhancement on the pixel points in each local window to obtain the enhanced image; wherein (i, j) is the coordinate of each pixel point, I new (i, j) is the new gray value of each pixel in the enhanced image, I old (i, j) is the grayscale value of each pixel, I avg is the grayscale threshold corresponding to each of the local windows, B is the brightness enhancement coefficient matched by each of the local windows, and C is the preset contrast enhancement coefficient.
[0009] In some embodiments of the present application, the determining of the brightness enhancement coefficient of each local window match includes: for each local window, if the saturation of the local window is greater than a first threshold and the brightness of the local window is greater than a second threshold, then determining the brightness enhancement coefficient of the local window match to be the first coefficient; otherwise, determining the brightness enhancement coefficient of the local window match to be 255 / I avg , where I avg is the grayscale threshold corresponding to the local window.
[0010] In some embodiments of the present application, the calculation is performed based on the pixel data of each pixel point to obtain the grayscale value of each pixel point, including: determining the weight coefficient corresponding to each color component; performing weighted summation based on multiple color components in the pixel data of each pixel point and the weight coefficient corresponding to each color component to obtain the grayscale value of each pixel point.
[0011] In some embodiments of the present application, the grayscale image is globally binarized to obtain a background-removed image, including: counting the grayscale histogram of the grayscale image; calculating the grayscale level that minimizes the inter-class variance based on the grayscale histogram to obtain a binarization threshold; reducing the binarization threshold based on the peak length at the left end of the grayscale histogram to obtain a new binarization threshold; and binarizing the grayscale image based on the new binarization threshold to obtain a background-removed image.
[0012] According to one embodiment of the present application, a text recognition device includes: an enhancement module, which is used to perform local contrast enhancement processing on an image to be recognized to obtain an enhanced image; a grayscale module, which is used to perform grayscale processing on the enhanced image to obtain a grayscale image; a binarization module, which is used to perform global binarization processing on the grayscale image to obtain a background-removed image; and a recognition module, which is used to perform optical character recognition based on the background-removed image to obtain text in the image to be recognized.
[0013] In some embodiments of the present application, the enhancement module is used to: select multiple local windows from the image to be identified; perform calculations based on the pixel data of the pixels included in each of the local windows to obtain a grayscale threshold corresponding to each of the local windows; perform calculations based on the pixel data of each of the pixel points to obtain a grayscale value of each of the pixel points; perform contrast enhancement on the pixels in each of the local windows based on the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixels in each of the local windows to obtain the enhanced image.
[0014] In some embodiments of the present application, the enhancement module is used to: determine the brightness enhancement coefficient matched by each of the local windows and obtain a preset contrast enhancement coefficient; perform contrast enhancement on the pixels in each of the local windows according to the grayscale threshold corresponding to each of the local windows, the grayscale value of each of the pixels, the brightness enhancement coefficient matched by each of the local windows and the preset contrast enhancement coefficient to obtain the enhanced image.
[0015] In some embodiments of the present application, the enhancement module is used to: new (i,j)=(I avg +C*(I old (i,j)-I avg ))*B performs contrast enhancement on the pixel points in each local window to obtain the enhanced image; wherein (i, j) is the coordinate of each pixel point, I new (i, j) is the new gray value of each pixel in the enhanced image, I old (i, j) is the grayscale value of each pixel, I avgis the grayscale threshold corresponding to each of the local windows, B is the brightness enhancement coefficient matched by each of the local windows, and C is the preset contrast enhancement coefficient.
[0016] In some embodiments of the present application, the enhancement module is used to: for each of the local windows, if the saturation of the local window is greater than a first threshold and the brightness of the local window is greater than a second threshold, determine that the brightness enhancement coefficient matched by the local window is the first coefficient; otherwise, determine that the brightness enhancement coefficient matched by the local window is 255 / I avg , where I avg is the grayscale threshold corresponding to the local window.
[0017] In some embodiments of the present application, the enhancement module is used to: determine the weight coefficient corresponding to each color component; perform weighted summation based on multiple color components in the pixel data of each pixel point and the weight coefficient corresponding to each color component to obtain the grayscale value of each pixel point.
[0018] In some embodiments of the present application, the binarization module is used to: count the grayscale histogram of the grayscale image; calculate the grayscale level that minimizes the inter-class variance based on the grayscale histogram to obtain a binarization threshold; reduce the binarization threshold based on the peak length at the left end of the grayscale histogram to obtain a new binarization threshold; binarize the grayscale image based on the new binarization threshold to obtain a background-eliminated image.
[0019] According to another embodiment of the present application, a storage medium stores a computer program thereon, and when the computer program is executed by a processor of a computer, the computer executes the method described in the embodiment of the present application.
[0020] According to another embodiment of the present application, an electronic device may include: a memory storing a computer program; and a processor reading the computer program stored in the memory to execute the method described in the embodiment of the present application.
[0021] According to another embodiment of the present application, a computer program product or a computer program includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method provided in various optional implementations described in the embodiments of the present application.
[0022] In an embodiment of the present application, the image to be identified is subjected to local contrast enhancement processing to obtain an enhanced image; the enhanced image is subjected to grayscale processing to obtain a grayscale image; the grayscale image is subjected to global binarization processing to obtain a background-eliminated image; and optical character recognition is performed based on the background-eliminated image to obtain text in the image to be identified.
[0023] In this way, the image to be recognized is subjected to local contrast enhancement processing, so that the background with gray and shadow in the image can be effectively distinguished from the text, and an enhanced image with effective distinction between the background and the text is obtained. Furthermore, the enhanced image is subjected to grayscale processing to obtain a grayscale image, and the grayscale image is subjected to global binarization processing, so that the segmented background is effectively eliminated to obtain a background-eliminated image. Optical character recognition is then performed based on the background-eliminated image, so that more text can be more accurately identified, effectively improving the text recall rate and the text recognition accuracy, and improving the text recognition effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 A flowchart of a text recognition method according to an embodiment of the present application is shown.
[0026] Figure 2 A local contrast enhancement flow chart according to an embodiment of the present application is shown.
[0027] Figure 3 A contrast enhancement flow chart according to an embodiment of the present application is shown.
[0028] Figure 4 A block diagram of a text recognition device according to an embodiment of the present application is shown.
[0029] Figure 5 A block diagram of an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0030] The present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the embodiments provided herein are only used to explain the present disclosure and are not intended to limit the present disclosure. In addition, the embodiments provided below are partial embodiments for implementing the present disclosure, rather than providing all embodiments for implementing the present disclosure. In the absence of conflict, the technical solutions recorded in the embodiments of the present disclosure can be implemented in any combination.
[0031] It should be noted that, in the embodiments of the present disclosure, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a method or apparatus including a series of elements includes not only the elements explicitly recorded, but also includes other elements not explicitly listed, or also includes elements inherent to the implementation of the method or apparatus. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the presence of other related elements in the method or apparatus including the element (such as a step in the method or a unit in the apparatus, for example, a unit may be a part of a circuit, a part of a processor, a part of a program or software, etc.).
[0032] For example, the text recognition method provided by the embodiment of the present disclosure includes a series of steps, but the text recognition method provided by the embodiment of the present disclosure is not limited to the recorded steps. Similarly, the text recognition device provided by the embodiment of the present disclosure includes a series of units, but the device provided by the embodiment of the present disclosure is not limited to including the units explicitly recorded, and can also include units required to obtain relevant information or perform processing based on the information.
[0033] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present disclosure belongs. The terms used herein are only for the purpose of describing specific embodiments and are not intended to limit the present disclosure.
[0034] Figure 1 The flowchart of a text recognition method according to an embodiment of the present application is schematically shown. The execution subject of the text recognition method can be any device or server with processing capabilities, where the device is such as a TV, a computer, a mobile phone, a smart watch, and a home appliance, and the server is such as a physical server or a cloud server.
[0035] like Figure 1 As shown, the text recognition method may include steps S110 to S140.
[0036] Step S110, performing local contrast enhancement processing on the image to be identified to obtain an enhanced image; step S120, performing grayscale processing on the enhanced image to obtain a grayscale image; step S130, performing global binarization processing on the grayscale image to obtain a background-removed image; step S140, performing optical character recognition based on the background-removed image to obtain text in the image to be identified.
[0037] In this way, based on steps S110 to S140, the image to be identified is subjected to local contrast enhancement processing, so that the background with gray background, shadows and the like in the image can be effectively distinguished from the text, and an enhanced image in which the background and text are effectively distinguished is obtained. Furthermore, the enhanced image is subjected to grayscale processing to obtain a grayscale image, and the grayscale image is subjected to global binarization processing, so that the segmented background is effectively eliminated to obtain a background-eliminated image. Optical character recognition is then performed based on the background-eliminated image, so that more text therein can be more accurately identified, thereby effectively improving the text recall rate and the text recognition accuracy, and improving the text recognition effect.
[0038] Described below Figure 1 When performing text recognition under the embodiment, the steps performed and the further optional specific embodiments under each step.
[0039] Step S110, performing local contrast enhancement processing on the image to be identified to obtain an enhanced image.
[0040] The image to be identified is an image including background and text. Contrast enhancement is a method of increasing the grayscale range of an image by contrast enhancement to make the image clearer. Local contrast enhancement processing is to select a local window in the image to be identified, and then perform contrast enhancement on the local window.
[0041] Performing local contrast enhancement on the image to be recognized can effectively distinguish the background with gray and shadow in the image from the text. Compared with the global contrast enhancement method, local contrast enhancement can obtain an enhanced image with more effective distinction between the background and text.
[0042] In one embodiment, see Figure 2 , the local contrast enhancement processing of the image to be identified to obtain an enhanced image may include: step S210, selecting multiple local windows from the image to be identified; step S220, calculating according to the pixel data of the pixel points included in each of the local windows to obtain the grayscale threshold corresponding to each of the local windows; step S230, calculating according to the pixel data of each of the pixel points to obtain the grayscale value of each of the pixel points; step S240, performing contrast enhancement on the pixel points in each of the local windows according to the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixel points in each of the local windows to obtain the enhanced image.
[0043] According to a predetermined window size (for example, a window size with a pixel value radius of 50), multiple local windows with a size of the window size can be selected from the image to be recognized, and each local window is a local image. Each local window can include multiple pixel points.
[0044] By calculating based on the pixel data of the pixel points included in each local window, the grayscale threshold corresponding to each local window can be obtained. For example, by calculating based on the pixel data of the pixel points included in local window 1, the grayscale threshold 1 corresponding to local window 1 can be obtained. By calculating based on the pixel data of the pixel points included in local window 2, the grayscale threshold 2 corresponding to local window 2 can be obtained.
[0045] For each pixel in the image to be identified, a calculation can be performed based on the pixel data of each pixel to obtain the grayscale value of each pixel, wherein the pixel data of each pixel may include three color components: red, green and blue.
[0046] According to the grayscale threshold corresponding to each local window and the grayscale value of the pixel in each local window, the contrast of the pixel in each local window is enhanced, and the enhanced image obtained by local contrast enhancement processing can be obtained. For example, according to the grayscale threshold 1 corresponding to local window 1 and the grayscale value of the pixel in local window 1, the contrast of the pixel in local window 1 can be enhanced; according to the grayscale threshold 2 corresponding to local window 2 and the grayscale value of the pixel in local window 2, the contrast of the pixel in local window 2 can be enhanced, and so on, the contrast of the pixel in each local window is enhanced, and the enhanced pixels constitute the enhanced image.
[0047] In one embodiment, calculation is performed based on the pixel data of the pixel points included in each of the local windows to obtain the grayscale threshold corresponding to each of the local windows, which may include: calculating the grayscale average value of the pixel points in each of the local windows based on the pixel data of the pixel points included in each of the local windows, and using the grayscale average value as the grayscale threshold.
[0048] For example, for a local window of n*n, we can use the formula Calculate and get the grayscale average value I of the pixels in the local window avg , where i and j are the horizontal and vertical coordinates of the pixel in the local window, respectively, n is the length or width of the local window (that is, the number of horizontal or vertical pixels in the local window), k = in, l = jn, k and l are the offsets of the pixel (i, j) relative to the upper left corner of the local window, and x(k, l) is the grayscale value of the pixel (i, j).
[0049] In one embodiment, the calculation based on the pixel data of each pixel point to obtain the grayscale value of each pixel point may include: determining the weight coefficient corresponding to each color component; performing weighted summation based on multiple color components in the pixel data of each pixel point and the weight coefficient corresponding to each color component to obtain the grayscale value of each pixel point.
[0050] The weight coefficient configuration is pre-set, and the weight coefficients set for different color components can be determined from the weight coefficient configuration. The gray value of each pixel is obtained by weighted summing the multiple color components in the pixel data of each pixel and the weight coefficients corresponding to each color component.
[0051] Specifically, the gray value of each pixel can be obtained by weighted summation according to the formula Gray(i,j)=M*B(i,j)+N*G(i,j)+Q*R(i,j), where Gray(i,j) is the gray value of the pixel (i,j), M, N, Q are the weight coefficients corresponding to the blue, green and red color components, B(i,j), G(i,j), R(i,j) are the blue, green and red color components of the pixel (i,j). In a specific example, M, N, Q are 0.11, 0.59 and 0.3 respectively.
[0052] In one embodiment, see Figure 3 , performing contrast enhancement on the pixels in each of the local windows according to the grayscale thresholds corresponding to the local windows and the grayscale values of the pixels in each of the local windows to obtain the enhanced image may include: step S310, determining the brightness enhancement coefficient matched by each of the local windows, and obtaining a preset contrast enhancement coefficient; step S320, performing contrast enhancement on the pixels in each of the local windows according to the grayscale thresholds corresponding to the local windows, the grayscale values of the pixels, the brightness enhancement coefficient matched by each of the local windows, and the preset contrast enhancement coefficient to obtain the enhanced image.
[0053] The brightness enhancement coefficient is a coefficient used to enhance brightness, and the preset contrast enhancement coefficient is a coefficient used to enhance contrast. According to the grayscale threshold corresponding to the local window, the grayscale value of each pixel in the local window, the brightness enhancement coefficient matched by the local window, and the preset contrast enhancement coefficient, the contrast of the pixels in the local window is enhanced to obtain an enhanced local window. Multiple enhanced local windows are combined to obtain the enhanced image.
[0054] In one embodiment, the determining of the brightness enhancement coefficient of each local window match may include: for each local window, if the saturation of the local window is greater than a first threshold and the brightness of the local window is greater than a second threshold, determining the brightness enhancement coefficient of the local window match to be the first coefficient; otherwise, determining the brightness enhancement coefficient of the local window match to be 255 / I avg , where I avg is the grayscale threshold corresponding to the local window.
[0055] Specifically, in one example, the formula:
[0056] Determine the brightness enhancement coefficient of each local window match, where S(i, j) is the saturation of the local window, p1 is the first threshold, V(i, j) is the brightness of the local window, and p2 is the second threshold.
[0057] In this example, if the saturation S(i,j) of the local window is greater than the first threshold p1 and the brightness V(i,j) of the local window is greater than the second threshold p2, the brightness enhancement coefficient B of the local window matching is determined to be the first coefficient 1.0. Otherwise, the brightness enhancement coefficient of the local window matching is 255 / I avg .
[0058] In one embodiment, the contrast enhancement of the pixels in each of the local windows is performed according to the grayscale threshold corresponding to each of the local windows, the grayscale value of each of the pixels, the brightness enhancement coefficient matched by each of the local windows, and the preset contrast enhancement coefficient to obtain the enhanced image, including:
[0059] According to formula I new (i,j)=(I avg +C*(I old (i,j)-I avg ))*B performs contrast enhancement on the pixel points in each local window to obtain the enhanced image; wherein (i, j) is the coordinate of each pixel point, I new (i, j) is the new gray value of each pixel in the enhanced image, I old (i, j) is the grayscale value of each pixel, I avg is the grayscale threshold corresponding to each of the local windows, B is the brightness enhancement coefficient matched by each of the local windows, and C is the preset contrast enhancement coefficient.
[0060] According to formula I new (i,j)=(I avg +C*(I old (i,j)-I avg ))*B performs contrast enhancement on the pixels in each local window to obtain an enhanced image. The contrast and brightness in each local area of the enhanced image will be significantly enhanced, and the text and background in the enhanced image will be more clearly separated. Therefore, the enhanced image can be used for subsequent further processing, which can further effectively improve the text recall rate and text recognition accuracy.
[0061] Step S120, performing grayscale processing on the enhanced image to obtain a grayscale image.
[0062] Gray scale image is an image with only one sampled color for each pixel. Such images are usually displayed as grayscale from the darkest black to the brightest white. The enhanced image is usually a color image. By grayscale processing the enhanced image, the enhanced image can be converted from a color image to a corresponding grayscale image. Since the enhanced image is obtained by performing local contrast enhancement processing on the image to be identified, the degree of separation between the background and the text is still good after the enhanced image is converted into a grayscale image.
[0063] Step S130, performing global binarization processing on the grayscale image to obtain a background-removed image.
[0064] The grayscale image is globally binarized, that is, a threshold is determined from the global dimension of the grayscale image, and the grayscale image is binarized based on the threshold to obtain a background-eliminated image with the background eliminated.
[0065] In one embodiment, the grayscale image is globally binarized to obtain a background-removed image, which may include: statistically calculating a grayscale histogram of the grayscale image; calculating a grayscale level that minimizes inter-class variance based on the grayscale histogram to obtain a binarization threshold; reducing the binarization threshold based on the peak length at the left end of the grayscale histogram to obtain a new binarization threshold; and binarizing the grayscale image based on the new binarization threshold to obtain a background-removed image.
[0066] The Otsu method can be used to statistically calculate the grayscale histogram of the grayscale image, and calculate the grayscale level that minimizes the inter-class variance based on the grayscale histogram. The grayscale level that minimizes the inter-class variance is the binarization threshold determined by the Otsu method.
[0067] Further, the binarization threshold determined by the Otsu method is reduced according to the peak length at the left end of the grayscale histogram, and the reduced binarization threshold is obtained as a new binarization threshold. Wherein, the binarization threshold determined by the Otsu method is reduced according to the peak length at the left end of the grayscale histogram, and the new binarization threshold is obtained by reducing the binarization threshold by a predetermined multiple, such as 10, 20, etc.
[0068] The grayscale image is binarized according to the new binarization threshold, and the pixels whose grayscale values are greater than the new binarization threshold can be set to black, while the pixels whose grayscale values are less than the new binarization threshold can be set to white, thereby obtaining a background-eliminated image and achieving the purpose of separating text from background.
[0069] Step S140, performing optical character recognition based on the background-removed image to obtain the text in the image to be recognized. Performing optical character recognition based on the background-removed image can obtain the text in the image to be recognized. Performing optical character recognition based on the background-removed image again can more accurately recognize more text in the image, effectively improve the text recall rate and text recognition accuracy, and improve the text recognition effect.
[0070] In order to better implement the text recognition method provided in the embodiment of the present application, the embodiment of the present application also provides a text recognition device based on the above text recognition method. The meanings of the nouns are the same as those in the above text recognition method, and the specific implementation details can refer to the description in the method embodiment. Figure 3 A block diagram of a text recognition device according to an embodiment of the present application is shown.
[0071] like Figure 4 As shown, the text recognition device 400 may include: an enhancement module 410 that can be used to perform local contrast enhancement processing on the image to be recognized to obtain an enhanced image; a grayscale module 420 that can be used to perform grayscale processing on the enhanced image to obtain a grayscale image; a binarization module 430 that can be used to perform global binarization processing on the grayscale image to obtain a background-removed image; and a recognition module 440 that can be used to perform optical character recognition based on the background-removed image to obtain text in the image to be recognized.
[0072] In some embodiments of the present application, the enhancement module is used to: select multiple local windows from the image to be identified; perform calculations based on the pixel data of the pixels included in each of the local windows to obtain a grayscale threshold corresponding to each of the local windows; perform calculations based on the pixel data of each of the pixel points to obtain a grayscale value of each of the pixel points; perform contrast enhancement on the pixels in each of the local windows based on the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixels in each of the local windows to obtain the enhanced image.
[0073] In some embodiments of the present application, the enhancement module is used to: determine the brightness enhancement coefficient matched by each of the local windows and obtain a preset contrast enhancement coefficient; perform contrast enhancement on the pixels in each of the local windows according to the grayscale threshold corresponding to each of the local windows, the grayscale value of each of the pixels, the brightness enhancement coefficient matched by each of the local windows and the preset contrast enhancement coefficient to obtain the enhanced image.
[0074] In some embodiments of the present application, the enhancement module is used to: new (i,j)=(I avg +C*(I old (i,j)-I avg))*B performs contrast enhancement on the pixel points in each local window to obtain the enhanced image; wherein (i, j) is the coordinate of each pixel point, I new (i, j) is the new gray value of each pixel in the enhanced image, I old (i, j) is the grayscale value of each pixel, I avg is the grayscale threshold corresponding to each of the local windows, B is the brightness enhancement coefficient matched by each of the local windows, and C is the preset contrast enhancement coefficient.
[0075] In some embodiments of the present application, the enhancement module is used to: for each of the local windows, if the saturation of the local window is greater than a first threshold and the brightness of the local window is greater than a second threshold, determine that the brightness enhancement coefficient matched by the local window is the first coefficient; otherwise, determine that the brightness enhancement coefficient matched by the local window is 255 / I avg , where I avg is the grayscale threshold corresponding to the local window.
[0076] In some embodiments of the present application, the enhancement module is used to: determine the weight coefficient corresponding to each color component; perform weighted summation based on multiple color components in the pixel data of each pixel point and the weight coefficient corresponding to each color component to obtain the grayscale value of each pixel point.
[0077] In some embodiments of the present application, the binarization module is used to: count the grayscale histogram of the grayscale image; calculate the grayscale level that minimizes the inter-class variance based on the grayscale histogram to obtain a binarization threshold; reduce the binarization threshold based on the peak length at the left end of the grayscale histogram to obtain a new binarization threshold; binarize the grayscale image based on the new binarization threshold to obtain a background-eliminated image.
[0078] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0079] In addition, the present application also provides an electronic device, such as Figure 5 As shown, Figure 5 A block diagram of an electronic device according to an embodiment of the present application is shown, specifically:
[0080] The electronic device may include components such as a processor 501 with one or more processing cores, a memory 502 with one or more computer-readable storage media, a power supply 503, and an input unit 504. Those skilled in the art will appreciate that Figure 5 The electronic device structure shown in the figure does not constitute a limitation of the electronic device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0081] in:
[0082] The processor 501 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 502 and calling data stored in the memory 502, it executes various functions of the computer device and processes data, thereby monitoring the electronic device as a whole. Optionally, the processor 501 may include one or more processing cores; preferably, the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user pages and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 501.
[0083] The memory 502 can be used to store software programs and modules. The processor 501 executes various functional applications and data processing by running the software programs and modules stored in the memory 502. The memory 502 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 502 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 502 may also include a memory controller to provide the processor 501 with access to the memory 502.
[0084] The electronic device also includes a power supply 503 for supplying power to each component. Preferably, the power supply 503 can be logically connected to the processor 501 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply 503 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.
[0085] The electronic device may further include an input unit 504, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0086] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 501 in the electronic device will load the executable files corresponding to the processes of one or more computer programs into the memory 502 according to the following instructions, and the processor 501 will run the computer program stored in the memory 502, thereby realizing various functions in the aforementioned embodiments of the present application, such as the processor 501 may perform the following steps:
[0087] The image to be identified is subjected to local contrast enhancement processing to obtain an enhanced image; the enhanced image is subjected to grayscale processing to obtain a grayscale image; the grayscale image is subjected to global binarization processing to obtain a background-eliminated image; optical character recognition is performed based on the background-eliminated image to obtain text in the image to be identified.
[0088] In some embodiments of the present application, the local contrast enhancement processing of the image to be identified to obtain an enhanced image includes: selecting multiple local windows from the image to be identified; calculating according to the pixel data of the pixel points included in each of the local windows to obtain a grayscale threshold corresponding to each of the local windows; calculating according to the pixel data of each of the pixel points to obtain a grayscale value of each of the pixel points; and performing contrast enhancement on the pixel points in each of the local windows according to the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixel points in each of the local windows to obtain the enhanced image.
[0089] In some embodiments of the present application, the contrast of the pixels in each of the local windows is enhanced according to the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixels in each of the local windows to obtain the enhanced image, including: determining the brightness enhancement coefficient matched by each of the local windows, and obtaining a preset contrast enhancement coefficient; according to the grayscale threshold corresponding to each of the local windows, the grayscale value of each of the pixels, the brightness enhancement coefficient matched by each of the local windows, and the preset contrast enhancement coefficient, the contrast of the pixels in each of the local windows is enhanced to obtain the enhanced image.
[0090] In some embodiments of the present application, the contrast enhancement of the pixels in each local window is performed according to the grayscale threshold corresponding to each local window, the grayscale value of each pixel, the brightness enhancement coefficient matched by each local window, and the preset contrast enhancement coefficient to obtain the enhanced image, including: according to formula I new (i,j)=(Iavg +C*(I old (i,j)-I avg ))*B performs contrast enhancement on the pixel points in each local window to obtain the enhanced image; wherein (i, j) is the coordinate of each pixel point, I new (i, j) is the new gray value of each pixel in the enhanced image, I old (i, j) is the grayscale value of each pixel, I avg is the grayscale threshold corresponding to each of the local windows, B is the brightness enhancement coefficient matched by each of the local windows, and C is the preset contrast enhancement coefficient.
[0091] In some embodiments of the present application, the determining of the brightness enhancement coefficient of each local window match includes: for each local window, if the saturation of the local window is greater than a first threshold and the brightness of the local window is greater than a second threshold, then determining the brightness enhancement coefficient of the local window match to be the first coefficient; otherwise, determining the brightness enhancement coefficient of the local window match to be 255 / I avg , where I avg is the grayscale threshold corresponding to the local window.
[0092] In some embodiments of the present application, the calculation is performed based on the pixel data of each pixel point to obtain the grayscale value of each pixel point, including: determining the weight coefficient corresponding to each color component; performing weighted summation based on multiple color components in the pixel data of each pixel point and the weight coefficient corresponding to each color component to obtain the grayscale value of each pixel point.
[0093] In some embodiments of the present application, the grayscale image is globally binarized to obtain a background-removed image, including: counting the grayscale histogram of the grayscale image; calculating the grayscale level that minimizes the inter-class variance based on the grayscale histogram to obtain a binarization threshold; reducing the binarization threshold based on the peak length at the left end of the grayscale histogram to obtain a new binarization threshold; and binarizing the grayscale image based on the new binarization threshold to obtain a background-removed image.
[0094] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by a computer program, or by controlling related hardware through a computer program. The computer program may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0095] To this end, an embodiment of the present application further provides a storage medium, in which a computer program is stored. The computer program can be loaded by a processor to execute the steps in any method provided in the embodiment of the present application.
[0096] The storage medium may be a computer-readable storage medium, and the storage medium may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0097] Since the computer program stored in the storage medium can execute the steps in any method provided in the embodiments of the present application, the beneficial effects that can be achieved by the method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0098] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the embodiments disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not disclosed in the present application.
[0099] It should be understood that the present application is not limited to the embodiments that have been described above and shown in the accompanying drawings, but various modifications and changes may be made without departing from the scope thereof.
Claims
1. A text recognition method, It is characterized in that include: Performing local contrast enhancement processing on the image to be identified to obtain an enhanced image; Performing grayscale processing on the enhanced image to obtain a grayscale image; Performing global binarization processing on the grayscale image to obtain a background-eliminated image; Optical character recognition is performed based on the background-eliminated image to obtain text in the image to be recognized.
2. The method according to claim 1, It is characterized in that The step of performing local contrast enhancement processing on the image to be identified to obtain an enhanced image includes: Selecting a plurality of local windows from the image to be recognized; Calculate according to the pixel data of the pixel points included in each of the local windows to obtain the grayscale threshold corresponding to each of the local windows; Calculating according to the pixel data of each pixel point to obtain the grayscale value of each pixel point; According to the grayscale threshold corresponding to each of the local windows and the grayscale value of the pixel in each of the local windows, contrast enhancement is performed on the pixel in each of the local windows to obtain the enhanced image.
3. The method according to claim 2, It is characterized in that The step of performing contrast enhancement on the pixels in each of the local windows according to the grayscale thresholds corresponding to the local windows and the grayscale values of the pixels in the local windows to obtain the enhanced image comprises: Determine the brightness enhancement coefficient of each local window match, and obtain a preset contrast enhancement coefficient; According to the grayscale threshold corresponding to each local window, the grayscale value of each pixel point, the brightness enhancement coefficient matched by each local window and the preset contrast enhancement coefficient, the contrast of the pixel points in each local window is enhanced to obtain the enhanced image.
4. The method according to claim 3, It is characterized in that According to the grayscale threshold corresponding to each of the local windows, the grayscale value of each of the pixels, the brightness enhancement coefficient matched by each of the local windows, and the preset contrast enhancement coefficient, contrast enhancement is performed on the pixels in each of the local windows to obtain the enhanced image, including: According to formula I new (i,j)=(I avg +C*(I old (i,j)-I avg ))*B performs contrast enhancement on the pixel points in each local window to obtain the enhanced image; wherein (i, j) is the coordinate of each pixel point, I new (i, j) is the new gray value of each pixel in the enhanced image, I old (i, j) is the grayscale value of each pixel, I avg is the grayscale threshold corresponding to each of the local windows, B is the brightness enhancement coefficient matched by each of the local windows, and C is the preset contrast enhancement coefficient.
5. The method according to claim 3, It is characterized in that The determining of the brightness enhancement coefficients of the local window matches includes: For each of the local windows, if the saturation of the local window is greater than a first threshold and the brightness of the local window is greater than a second threshold, the brightness enhancement coefficient matched by the local window is determined to be the first coefficient; otherwise, the brightness enhancement coefficient matched by the local window is determined to be 255 / I avg , where I avg is the grayscale threshold corresponding to the local window.
6. The method according to claim 2, It is characterized in that The step of calculating according to the pixel data of each pixel point to obtain the grayscale value of each pixel point includes: Determine the weight coefficient corresponding to each color component; A weighted sum is performed according to multiple color components in the pixel data of each pixel point and the weight coefficients corresponding to each color component to obtain the grayscale value of each pixel point.
7. The method according to claim 1, It is characterized in that The grayscale image is subjected to global binarization processing to obtain a background-eliminated image, including: Counting the grayscale histogram of the grayscale image; Calculate the gray level that minimizes the inter-class variance according to the gray histogram to obtain a binarization threshold; The binarization threshold is reduced according to the peak length at the left end of the grayscale histogram to obtain a new binarization threshold; The grayscale image is binarized according to the new binarization threshold to obtain a background-eliminated image.
8. A text recognition device, It is characterized in that include: An enhancement module, used for performing local contrast enhancement processing on the image to be identified to obtain an enhanced image; A grayscale module, used for performing grayscale processing on the enhanced image to obtain a grayscale image; A binarization module, used for performing global binarization processing on the grayscale image to obtain a background-eliminated image; The recognition module is used to perform optical character recognition based on the background-removed image to obtain the text in the image to be recognized.
9. A storage medium, It is characterized in that A computer program is stored thereon, and when the computer program is executed by a processor of a computer, the computer is caused to execute the method according to any one of claims 1 to 7.
10. An electronic device, It is characterized in that include: a memory storing a computer program; A processor reads a computer program stored in a memory to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Optical character recognition method based on digital image processing
CN103530625A
Character recognition method for underwater video images
CN104361336A
Infrared image denoising enhancement method, device and system based on local adaptive CLAHE, and computer readable storage medium
CN112365424A
Image local contrast enhancement method for optimizing CLAHE
CN114092361A
