Method for adaptively enhancing OCR (Optical Character Recognition) of low-quality text image based on reinforcement learning

The optimal image preprocessing strategy is automatically determined through reinforcement learning and deep Q network, which solves the time-consuming problem of manually formulating strategies in low-quality text image processing, improves OCR output quality, and adapts to diverse and complex image processing.

CN118629050APending Publication Date: 2024-09-10CHONGQING TELECOMM PLAN & DESIGN INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410765009.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

In the existing technology, formulating the optimal preprocessing strategy for low-quality text images requires manual formulation, which is time-consuming and requires professional knowledge, and cannot meet the image processing needs of all situations.

Method used

Using a method based on reinforcement learning, by constructing a deep Q network, the state, action and reward are determined, the learning and training of image preprocessing operation combinations are performed, and the optimal image preprocessing strategy is automatically determined, including grayscale, binarization, and denoising. For other operations, use the preset OCR model and BERT model to conduct quality assessment and select the highest quality strategy.

Benefits of technology

It achieves adaptive enhancement of low-quality text images, improves the quality of OCR output, avoids the time-consuming and professional knowledge requirements of manually formulating pre-processing processes, and adapts to various image quality changes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118629050A
    Figure CN118629050A
Patent Text Reader

Abstract

The invention provides a method for adaptively enhancing OCR (Optical Character Recognition) of a low-quality text image based on reinforcement learning, and the method comprises the following steps: S1, obtaining an image preprocessing task, and determining an application environment; s2, constructing a deep Q network, and determining three reinforcement learning elements, namely a state, an action and an award, for a current application environment; wherein the state is histogram statistics of the low-quality image, the action is image preprocessing operation, and the reward is a preset reward function; and S3, continuously performing image preprocessing operation combination through the deep Q network for learning training to obtain an optimal image preprocessing strategy, preprocessing the low-quality image based on the optimal image preprocessing strategy, and processing the preprocessed low-quality image through a preset OCR model to obtain an optimal OCR output text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of optical character recognition, and in particular to a method for adaptively enhancing OCR of low-quality text images based on reinforcement learning. Background Art

[0002] The widespread application of optical character recognition (OCR) technology has brought changes to many industries, making it possible to extract text information from images or scanned documents; however, in practical applications, especially when dealing with a large number of scanned or photographed documents, the quality of images often varies greatly; low-quality text images, such as those with noise, blur, tilt, non-uniform lighting or complex backgrounds, pose a huge challenge to OCR technology. Traditional image preprocessing methods, such as denoising, binarization, and histogram equalization, can improve the effect of OCR in some situations, but due to the diversity and complexity of images, fixed preprocessing steps and parameters often cannot meet all situations; for low-quality text images, more sophisticated preprocessing strategies are required to ensure high-quality OCR output; the existing optimal preprocessing strategies for low-quality text images are often manually formulated, and manually formulating the optimal preprocessing process is time-consuming and requires professional knowledge. Summary of the invention

[0003] In view of the deficiencies in the prior art, the present invention provides a method for adaptively enhancing OCR of low-quality text images based on reinforcement learning, which solves the problem in the prior art that the optimal preprocessing strategy for low-quality text images is often formulated manually, and the manual formulation of the optimal preprocessing process is time-consuming and requires professional knowledge.

[0004] According to an embodiment of the present invention, a method for adaptively enhancing OCR of low-quality text images based on reinforcement learning comprises the following steps:

[0005] S1: Obtain image preprocessing tasks and determine the application environment;

[0006] S2: Build a deep Q network and determine the three elements of reinforcement learning for the current application environment: state, action, and reward; where the state is the histogram statistics of low-quality images, the action is the image preprocessing operation, and the reward is the preset reward function;

[0007] S3: The deep Q network is used to continuously perform image preprocessing operation combinations for learning and training to obtain the optimal image preprocessing strategy. The low-quality images are preprocessed based on the optimal image preprocessing strategy. The preprocessed low-quality images are processed through a preset OCR model to obtain the optimal OCR output text.

[0008] As an embodiment of the present invention, the image preprocessing operations include: grayscale, binarization, global threshold, adaptive threshold, denoising, sharpening, resizing, morphological operations, histogram equalization, illumination correction, dewarping, background removal, and line and frame removal.

[0009] As an embodiment of the present invention, the deep Q network continuously performs image preprocessing operation combinations for learning and training to obtain an optimal image preprocessing strategy, including:

[0010] S31: The deep Q network performs learning training on the image preprocessing operation combination for a preset number of times to obtain several image preprocessing strategies;

[0011] S32: The deep Q network preprocesses the low-quality image according to a number of image preprocessing strategies to obtain a number of preprocessed low-quality images;

[0012] S33: inputting a plurality of preprocessed low-quality images into a preset OCR model to obtain a plurality of OCR output texts;

[0013] S34: Perform quality assessment on several OCR output texts through the pre-trained BERT model to obtain several quality assessment results;

[0014] S35: Based on the multiple quality assessment results, select the image preprocessing strategy with the highest quality assessment result as the optimal image preprocessing strategy.

[0015] As an embodiment of the present invention, the training strategy of the learning training includes: experience replay, ε-greedy strategy and updating Q value;

[0016] Experience replay includes: creating a buffer to store experience <D,Y,J,D * >, where D is the histogram statistics of low-quality visualization, Y is the image preprocessing action, J is the reward, and D * is the histogram statistics of the low-quality image after preprocessing.

[0017] As an embodiment of the present invention, step S34 includes:

[0018] S341: Obtain an OCR output text, randomly select a preset number of words in the OCR output text, and obtain a number of word data to be compared;

[0019] S342: masking data of some words to be compared in the OCR output text, and predicting the masked words to be compared by using the pre-trained BERT model to obtain some real text data;

[0020] S343: Matching a plurality of real text data with a plurality of word data to be compared one by one and calculating text similarity to obtain a plurality of text similarity results;

[0021] S344: Calculate the average value of several text similarity results to obtain a quality assessment result of an OCR output text;

[0022] S355: Repeat S341 to S344 until all OCR output texts are traversed to obtain several quality assessment results.

[0023] As an embodiment of the present invention, the deep Q network architecture includes: an input layer, a hidden layer and an output layer;

[0024] Among them, the hidden layers include: convolutional layer and fully connected layer.

[0025] Compared with the prior art, the present invention has the following beneficial effects: the optimal image preprocessing strategy is adaptively given through the deep Q network, and the low-quality image is processed according to the optimal image preprocessing strategy and then recognized through the OCR technology, thereby improving the quality of the OCR reading results and avoiding the need to manually formulate the optimal preprocessing strategy for low-quality text images. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 A schematic diagram of a flow chart of an embodiment of the present invention;

[0027] Figure 2 FIG. 4 is a flow chart of another embodiment of the present invention. DETAILED DESCRIPTION

[0028] The technical solution of the present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0029] like Figure 1 to Figure 2 As shown, the embodiment of the present invention proposes a method for adaptively enhancing OCR of low-quality text images based on reinforcement learning, comprising the following steps:

[0030] S1: Obtain image preprocessing tasks and determine the application environment;

[0031] S2: Build a deep Q network and determine the three elements of reinforcement learning for the current application environment: state, action, and reward; where the state is the histogram statistics of low-quality images, the action is the image preprocessing operation, and the reward is the preset reward function;

[0032] S3: The deep Q network is used to continuously perform image preprocessing operation combinations for learning and training to obtain the optimal image preprocessing strategy. The low-quality images are preprocessed based on the optimal image preprocessing strategy. The preprocessed low-quality images are processed through a preset OCR model to obtain the optimal OCR output text.

[0033] The image preprocessing operations include: grayscale, binarization, global threshold, adaptive threshold, denoising, sharpening, resizing, morphological operations, histogram equalization, illumination correction, dewarping, background removal, and line and frame removal;

[0034] The deep Q network continuously performs image preprocessing operation combinations for learning and training to obtain the optimal image preprocessing strategy, including:

[0035] S31: The deep Q network performs learning training on the image preprocessing operation combination for a preset number of times to obtain several image preprocessing strategies;

[0036] S32: The deep Q network preprocesses the low-quality image according to a number of image preprocessing strategies to obtain a number of preprocessed low-quality images;

[0037] S33: inputting a plurality of preprocessed low-quality images into a preset OCR model to obtain a plurality of OCR output texts;

[0038] S34: Perform quality assessment on several OCR output texts through the pre-trained BERT model to obtain several quality assessment results;

[0039] S35: selecting, based on the multiple quality assessment results, an image preprocessing strategy with the highest quality assessment result as the optimal image preprocessing strategy;

[0040] The training strategies of the learning training include: experience replay, ε-greedy strategy and updating Q value;

[0041] Create a buffer to store experience <D,Y,J,D * >, where D is the histogram statistics of low-quality visualization, Y is the image preprocessing action, J is the reward, and D * It is the histogram statistics of the low-quality image after preprocessing;

[0042] The step S34 comprises:

[0043] S341: Obtain an OCR output text, randomly select a preset number of words in the OCR output text, and obtain a number of word data to be compared;

[0044] S342: masking data of some words to be compared in the OCR output text, and predicting the masked words to be compared by using the pre-trained BERT model to obtain some real text data;

[0045] S343: Matching a plurality of real text data with a plurality of word data to be compared one by one and calculating text similarity to obtain a plurality of text similarity results;

[0046] S344: Calculate the average value of several text similarity results to obtain a quality assessment result of an OCR output text;

[0047] S355: repeat S341 to S344 until all OCR output texts are traversed to obtain several quality assessment results;

[0048] The deep Q network architecture includes: an input layer, a hidden layer and an output layer;

[0049] Among them, the hidden layers include: convolutional layer and fully connected layer;

[0050] The working principle of the above technical solution is as follows: in actual use, by obtaining the image preprocessing task, the preprocessing task is defined as the application environment in reinforcement learning; the image preprocessing operation is defined as the action of the intelligent agent (deep Q network) in reinforcement learning, and the histogram statistics of the low-quality image are defined as the state of the intelligent agent in reinforcement learning;

[0051] The operations of image preprocessing include: Grayscale Conversion: Convert color images to grayscale images, which can simplify subsequent processing; Binarization: Used to convert images into binary format (i.e. black and white); Global Thresholding: Select a threshold to convert all pixels to black or white; Adaptive Thresholding: Select a threshold based on the local area of ​​the image, which is useful for images with non-uniform lighting; Denoising: Median Filtering: Locally process the image to remove noise; Gaussian Filtering: Use a Gaussian kernel to reduce random variations in pixels; Non-local Mean: An efficient method for removing noise, especially for repeated noise patterns; Sharpening: Used to enhance edges in images to make text clearer. Common methods include Laplace sharpening; Deskewing: used to correct the slant of text in an image; Rescaling: changing the size of an image according to the requirements of the OCR engine or other subsequent tasks; Morphological Operations: such as dilation, erosion, opening and closing operations, used to enhance or reduce specific structures in an image; Histogram Equalization: used to increase the contrast of an image; Illumination Correction: for problems where parts of an image are too dark or too bright due to uneven lighting, illumination correction can be used; Dewarping: for pages scanned from books or magazines, this can help correct deformations caused by the curve of the page; Background Removal: for images with noisy or irrelevant backgrounds, this method can be used; Line and Border Removal: for scanned tables or other documents with lines, this method can remove these distractions and make the text more visible;

[0052] After the low-quality image is preprocessed by the preprocessing strategy, the preprocessed low-quality image is obtained, and the preprocessed low-quality image is input into the preset OCR model to obtain the OCR output text; the quality of the OCR output text is evaluated by the pre-trained BERT model to obtain the quality evaluation result, and the quality evaluation result is defined as the reward of the intelligent agent; the accuracy of the pre-processed OCR is checked, and the pre-trained BERT model such as bert-base-uncased is used to evaluate the text quality of the OCR; the evaluation method is: randomly select a word from the OCR output text and mask it, use the masked word as the word data to be compared, use BERT to predict the masked word, and obtain the real text data. If the word predicted by BERT is As the real text, the real text data is compared with the word data to be compared, and the text similarity is calculated to obtain a text similarity result. The preset number of times is repeated to obtain several text similarity results. The average of the several text similarity results is calculated to obtain a quality evaluation result. The higher the quality evaluation result, the higher the text similarity, which indicates that the quality of the OCR output text is higher. Based on the several quality evaluation results, the image preprocessing strategy with the highest quality evaluation result is selected as the optimal image preprocessing strategy. Among them, the text similarity is the embedding (embeddings) of the data predicted by BERT as the real text data and the words blocked in the OCR output text as the word data to be compared. The cosine similarity or other distance indicators between the two embeddings are calculated.

[0053] The Deep Q Network (DQN) architecture includes: input layer: representation of the state, hidden layer: composed of convolutional layers and fully connected layers, output layer: each node represents a preprocessing operation;

[0054] Experience Replay: Storage <D,Y,J,D * > for training; use the ε-greedy strategy to explore and exploit at the same time; update the Q value: based on the Bellman equation, use the experience replay data to update the Q value; where D is the histogram statistics of low-quality images, Y is the image preprocessing strategy, J is the quality assessment result, and D * It is the histogram statistics of the low-quality image after preprocessing;

[0055] Initialize experience playback: create a buffer to store experience (D, Y, J, D *>, ε-greedy strategy: define the ε-greedy strategy to balance exploration and exploitation, select a random action with probability ε; otherwise select the best action in the Q network, training loop: collect experience from the environment; store these experiences in experience replay, randomly extract a batch of experience from the experience replay, calculate the target Q value of the extracted experience, and use the loss between the predicted Q value and the target Q value to train the Q network, adjust ε: gradually reduce ε over time to transition from exploration to exploitation;

[0056] Update Q value: Based on the Bellman equation, use the experience replay data to update the Q value;

[0057] In the process of learning and training the combination of image preprocessing operations by the deep Q network, the deep Q network selects an image preprocessing operation according to the training strategy to process the low-quality image, obtains the preprocessed low-quality image and calculates the corresponding quality evaluation result, and continuously cycles until the number of image preprocessing operations reaches a first preset value, or the difference between the current quality evaluation result and the previous quality evaluation result for a consecutive times is less than a second preset value, and an image preprocessing strategy is obtained to avoid excessive preprocessing of low-quality images; wherein, during the training process, the quality evaluation result of the low-quality image that has completed an image preprocessing operation is input into the preset reward function for judgment to determine whether the quality evaluation result is greater than the preset value; if greater, a positive reward is given to the intelligent agent; if not greater, a negative reward is given to the intelligent agent;

[0058] In order to better evaluate and optimize low-quality images, staff can adjust the parameters and structure of DQN to obtain better performance, such as the upper limit of the number of image preprocessing operations during training; thus, for new images, input into the DQN network and determine the best preprocessing combination to improve the accuracy of OCR recognition of low-quality text;

[0059] The beneficial effects of the above technical solution: Through the above technical solution, the optimal image preprocessing strategy is adaptively given through the deep Q network, and the low-quality image is processed according to the optimal image preprocessing strategy and then recognized through OCR technology, which improves the quality of OCR reading results and avoids the need to manually formulate the optimal preprocessing strategy for low-quality text images.

[0060] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution of the present invention, which should be included in the scope of the claims of the present invention.

Claims

1. A method for adaptively enhancing OCR of low-quality text images based on reinforcement learning, characterized in that: The following steps are involved: S1: Obtain image preprocessing tasks and determine the application environment; S2: Build a deep Q network and determine the three elements of reinforcement learning for the current application environment: state, action, and reward; where the state is the histogram statistics of low-quality images, the action is the image preprocessing operation, and the reward is the preset reward function; S3: The deep Q network is used to continuously perform image preprocessing operation combinations for learning and training to obtain the optimal image preprocessing strategy. The low-quality images are preprocessed based on the optimal image preprocessing strategy. The preprocessed low-quality images are processed through a preset OCR model to obtain the optimal OCR output text.

2. The method for adaptively enhancing OCR of low-quality text images based on reinforcement learning as claimed in claim 1, characterized in that: The image preprocessing operations include: grayscale, binarization, global threshold, adaptive threshold, denoising, sharpening, resizing, morphological operations, histogram equalization, illumination correction, dewarping, background removal, and line and frame removal.

3. The method for adaptively enhancing OCR of low-quality text images based on reinforcement learning as claimed in claim 1, characterized in that: The deep Q network continuously performs image preprocessing operation combinations for learning and training to obtain the optimal image preprocessing strategy, including: S31: The deep Q network performs learning training on the image preprocessing operation combination for a preset number of times to obtain several image preprocessing strategies; S32: The deep Q network preprocesses the low-quality image according to a number of image preprocessing strategies to obtain a number of preprocessed low-quality images; S33: inputting a plurality of preprocessed low-quality images into a preset OCR model to obtain a plurality of OCR output texts; S34: Perform quality assessment on several OCR output texts through the pre-trained BERT model to obtain several quality assessment results; S35: Based on the multiple quality assessment results, select the image preprocessing strategy with the highest quality assessment result as the optimal image preprocessing strategy.

4. The method for adaptively enhancing OCR of low-quality text images based on reinforcement learning as claimed in claim 1, characterized in that: include: The training strategies of the learning training include: experience replay, ε-greedy strategy and updating Q value; Experience replay includes: creating a buffer to store experience <D,Y,J,D * >, where D is the histogram statistics of low-quality visualization, Y is the image preprocessing action, J is the reward, and D * is the histogram statistics of the low-quality image after preprocessing.

5. The method for adaptively enhancing OCR of low-quality text images based on reinforcement learning as claimed in claim 3, characterized in that: The step S34 comprises: S341: Obtain an OCR output text, randomly select a preset number of words in the OCR output text, and obtain a number of word data to be compared; S342: masking data of some words to be compared in the OCR output text, and predicting the masked words to be compared by using the pre-trained BERT model to obtain some real text data; S343: Matching a plurality of real text data with a plurality of word data to be compared one by one and calculating text similarity to obtain a plurality of text similarity results; S344: Calculate the average value of several text similarity results to obtain a quality assessment result of an OCR output text; S355: Repeat S341 to S344 until all OCR output texts are traversed to obtain several quality assessment results.

6. The method for adaptively enhancing OCR of low-quality text images based on reinforcement learning as claimed in claim 1, characterized in that: The deep Q network architecture includes: an input layer, a hidden layer and an output layer; Among them, the hidden layers include: convolutional layer and fully connected layer.