Text region determination method and device, electronic equipment and storage medium
By conducting image sample training and posterior probability analysis on the convolutional neural network model, combining conditional random field model and multi-level histogram, the problem of inaccurate text area recognition in the existing technology is solved, and high under complex backgrounds is achieved Accuracy text area recognition.
Patent Information
- Application Number
- CN202410941593.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-11-01
AI Technical Summary
Existing optical character recognition techniques are difficult to accurately identify the location of text areas in images under complex backgrounds or different font sizes.
By training the recognition of text areas on the image sample on the preset convolutional neural network model, the prediction deviation and posterior probability are obtained, and the convolutional neural network is continued to be trained to improve the recognition accuracy, and combined with the conditional random field model and multi-level histogram Perform preprocessing and feature extraction to determine the exact location of the text area.
It significantly improves the accuracy of text areas recognition, and can accurately identify text areas locations in images under complex backgrounds and varied fonts.
Smart Images

Figure CN118887677A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text region determination, and in particular to a method, device, electronic device and storage medium for determining a text region. Background Art
[0002] In the era of digitalization and informatization, there is a growing demand for extracting text information from images. Whether in document analysis, content retrieval, scene understanding or assisting the visually impaired, accurately identifying the location of text areas in images is crucial. Although existing OCR (Optical Character Recognition) technologies can recognize text in images to a certain extent, they are often not accurate enough in text positioning, especially in complex backgrounds or with different font sizes. Therefore, it is very necessary to develop a method that can accurately identify the location of text areas in images. Summary of the invention
[0003] A text area determination method, device, electronic device and storage medium of the present invention can accurately identify the location of the text area in an image, thereby improving the accuracy of text area determination.
[0004] The embodiment of the present invention provides the following solution:
[0005] In a first aspect, an embodiment of the present invention provides a method for determining a text region, the method comprising:
[0006] Performing recognition training on the text area on the image sample on the preset convolutional neural network model to obtain the prediction deviation of the convolutional neural network model in recognizing the text area;
[0007] Perform semantic recognition on the text on the image sample to obtain the posterior probability that the image features on the image sample belong to the text;
[0008] Based on the prediction deviation and posterior probability, the convolutional neural network continues to be trained to identify the text area;
[0009] When the continued training result of the convolutional neural network reaches a preset target, the target image of the text area to be predicted is input into the convolutional neural network model;
[0010] According to the output results of the convolutional neural network model, the text area of the target image is determined.
[0011] In an optional embodiment, a preset convolutional neural network model is trained to recognize text regions on image samples to obtain a prediction deviation of the convolutional neural network model for recognizing text regions, including:
[0012] Input the image samples with the marked text area into the convolutional neural network model for text area recognition training to obtain the predicted boundary of the text area;
[0013] According to the deviation between the predicted boundary and the actual boundary of the text area, a boundary area deviation and a boundary position deviation are obtained;
[0014] The boundary area deviation and the boundary position deviation are determined as the prediction deviation.
[0015] In an optional embodiment, after inputting the image sample with the labeled text area into the convolutional neural network model for text area recognition training to obtain the predicted boundary of the text area, the method further includes:
[0016] According to the convolutional neural network model, the predicted boundaries and actual boundaries of the text area on the image sample are identified based on different groups of convolution kernels, and the prediction error of identifying the text area under each group of convolution kernels is obtained;
[0017] The prediction boundary of the convolution kernel corresponding to the minimum prediction error is determined as the prediction boundary of the text area recognized by the convolutional neural network model.
[0018] In an optional embodiment, the predicted boundary and the actual boundary of the text area on the image sample are identified based on different groups of convolution kernels according to the convolution neural network model, and the prediction error of identifying the text area under each group of convolution kernels is obtained, including:
[0019] According to the formula:
[0020]
[0021] Get the prediction error K of each group of convolution kernels ce ,in, are the first partial derivative, the second partial derivative, the third partial derivative, and the fourth partial derivative, respectively. N is the number of anchor boxes of the predicted boundary, and x i is the horizontal coordinate of the predicted boundary, x is the horizontal coordinate of the actual boundary, y is i is the ordinate of the predicted boundary, y is the ordinate of the predicted boundary, w i is the height of the predicted boundary, w is the height of the actual boundary, and h i is the width of the predicted boundary, and h is the width of the actual boundary.
[0022] In an optional embodiment, semantic recognition is performed on text on an image sample to obtain a posterior probability that an image feature on the image sample belongs to the text, including:
[0023] The normalization factor is configured for the preset conditional random field model so that the sum of the probabilities of the labeled sequences during semantic recognition is 1;
[0024] The conditional random field model is trained for semantic recognition according to the graph cut energy function until the semantic recognition result meets the preset conditions;
[0025] The image sample is input into the conditional random field model whose semantic recognition result meets the preset conditions to obtain the posterior probability that the image feature on the image sample belongs to the text.
[0026] In an optional embodiment, before inputting the target image of the text area to be predicted into the convolutional neural network model, the method further includes:
[0027] Performing noise reduction processing on the target image to obtain a target image after noise reduction processing;
[0028] The image features on the target image after noise reduction are subjected to contrast enhancement processing according to the multi-level histogram to obtain the target image after preprocessing.
[0029] In an optional embodiment, before inputting the target image of the text area to be predicted into the convolutional neural network model, the method further includes:
[0030] According to a preset detection response model, determining the detection response value of the convolutional neural network model for detection templates of different sizes;
[0031] According to the detection requirements of different image features on the image to be identified, a mapping relationship between the detection response value and the corresponding image feature is obtained;
[0032] The parameters of the trained convolutional neural network model are configured according to the mapping relationship.
[0033] In a second aspect, an embodiment of the present invention further provides a device for determining a text area, the device comprising:
[0034] A training acquisition module is used to perform recognition training of text regions on image samples on a preset convolutional neural network model to obtain a prediction deviation of the convolutional neural network model for recognizing text regions;
[0035] The recognition acquisition module is used to perform semantic recognition on the text on the image sample to obtain the posterior probability that the image feature on the image sample belongs to the text;
[0036] The recognition training module is used to continue the recognition training of the convolutional neural network for text regions based on the prediction deviation and the posterior probability;
[0037] An input module, used for inputting a target image of a text area to be predicted into a convolutional neural network model when the continued training result of the convolutional neural network reaches a preset target;
[0038] The first determination module is used to determine the text area of the target image according to the output result of the convolutional neural network model.
[0039] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a processor and a memory, wherein the memory is coupled to the processor and stores instructions, and when the instructions are executed by the processor, the electronic device executes the steps of any one of the methods in the first aspect.
[0040] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any one of the methods in the first aspect.
[0041] Compared with the prior art, the text area determination method, device, electronic device and storage medium of the present invention have the following advantages:
[0042] The technical solution of the present invention obtains the prediction deviation of the convolutional neural network model in recognizing the text area on the image sample by performing recognition training on the preset convolutional neural network model; performs semantic recognition on the text on the image sample to obtain the posterior probability that the image feature on the image sample belongs to the text; in order to make the convolutional neural network model more accurately trained, the convolutional neural network is continuously trained for recognizing the text area according to the prediction deviation and the posterior probability; when the continued training result of the convolutional neural network reaches the preset target, it indicates that the convolutional neural network model can accurately identify the text area, and the target image of the text area to be predicted is input into the convolutional neural network model; according to the output result of the convolutional neural network model, the text area of the target image is determined. The scheme enables the convolutional neural network model to continuously converge on the text features of the text area during continued training through the prediction deviation and the posterior probability, and can more accurately identify the location of the text area in the image, thereby improving the accuracy of determining the text area. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 The process of the method for determining the text area provided by the embodiment of the present invention Figure 1 ;
[0045] Figure 2 The process of the method for determining the text area provided by the embodiment of the present invention Figure 2 ;
[0046] Figure 3A schematic diagram of the structure of a device for determining a text region provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0047] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention belong to the scope of protection of the embodiments of the present invention.
[0048] See also Figure 1 , Figure 1 This is a flowchart of a method for determining a text area provided by an embodiment of the present invention. The method can be applied to a mobile terminal device, a computer device or a server to implement the determination of a text area on an image. It only needs to be able to run the method, and no specific limitation is made here. The method includes:
[0049] S11. Performing recognition training on text regions on image samples on a preset convolutional neural network model to obtain a prediction bias of the convolutional neural network model for recognizing text regions.
[0050] Specifically, the convolutional neural network model can be configured as a fully connected structure, and the model training is implemented after the text area is annotated on the image sample. The image samples can be divided into a training set and a test set. After the convolutional neural network model is trained based on the training set, the convolutional neural network model is tested through the test set. The predicted boundary of the text area is obtained based on the test result, and the deviation between the predicted boundary and the actual boundary of the text area is determined as the prediction deviation. The prediction deviation can be used to characterize the prediction accuracy of the convolutional neural network model after the image sample training. It should be noted that the prediction deviation can be characterized as the centroid coordinate deviation between the predicted boundary and the actual boundary, and can also be characterized as the area difference between the predicted boundary and the actual boundary.
[0051] In practical applications, the single-dimensional deviation measurement method for characterizing prediction deviation has the problem of insufficient accuracy. Based on this, in a specific implementation, step S11 includes sub-steps S11-1 to S11-3, which are specifically described as follows:
[0052] S11-1. Input the image sample with the marked text area into the convolutional neural network model to perform text area recognition training to obtain the predicted boundary of the text area.
[0053] The convolutional neural network model can extract features from image samples, aiming to accurately extract text features from complex image backgrounds. The feature extraction model can be formalized as the following mathematical expression:
[0054]
[0055] Where F(x) represents the extracted feature vector; σ represents a nonlinear activation function, such as a rectified linear unit (ReLU) or a hyperbolic tangent function (tanh); N1 is the number of convolution kernels in the feature extraction module; W i and b i Respectively represent the weight and bias of the i-th group of convolution kernels; g i (x) represents the feature map of the input image x in the i-th region; * represents the convolution operation. The specific description of the parameters is as follows:
[0056] F(x) is the extracted feature vector, which contains the information related to the text area in the image.
[0057] σ is a nonlinear activation function used to increase the nonlinearity of the model. ReLU or tanh can be used.
[0058] N1 is the number of convolution kernel groups, indicating that multiple convolution layers are used in the entire feature extraction process.
[0059] W i is the weight of the i-th group of convolution kernels, which is used to extract features in the convolution operation.
[0060] b i is the bias of the i-th group of convolution kernels, which is used to adjust the output of feature extraction.
[0061] g i (x) is the feature map of the input image x in the i-th region, that is, the local feature.
[0062] * is the convolution operator, which means the point-by-point product of the convolution kernel and the image features and then the summation.
[0063] In order to improve the accuracy of the convolutional neural network model in identifying text areas, the embodiment of the present invention configures its classifier as follows, using a deep learning classifier module, which includes but is not limited to target detection algorithms such as Faster R-CNN and YOLO. The classifier module performs high-dimensional space classification operations on the feature vectors output by the image feature extraction results to determine whether each area in the image contains text. The specific classifier model can be designed as follows:
[0064]
[0065] Where C(F(x)) represents the classification result of the classifier for the image feature F(x), indicating whether the image area is a text area; Z is a normalization constant used to ensure that the probability sum of the classification result is 1; M is the number of fully connected layer neurons used for classification in the classifier, indicating the number of weight combinations used for decision-making in the classifier; w and v jThey represent the weight and bias of the jth neuron respectively. The weight determines the contribution of the neuron to the classification result, and the bias is used to adjust the output of the neuron. j (F(x)) represents the mapping of feature F(x) on the jth neuron.
[0066] It can be understood that the embodiment of the present invention achieves efficient detection of text regions by accurately extracting image features and applying a deep learning classifier module. This approach not only retains the basic framework of the original algorithm, but also improves the accuracy and robustness of text region recognition by introducing a more complex mathematical model.
[0067] Since the convolutional neural network model is based on the continuous training and convergence of different groups of convolution kernels during the training process, the traditional training method needs to be implemented based on a large number of image samples, resulting in the training process taking up a lot of time and energy. Based on this, in a specific implementation, after completing sub-step S11-1, the determination method further includes:
[0068] According to the convolutional neural network model, the predicted boundary and actual boundary of the text area on the image sample are identified based on different groups of convolution kernels, and the prediction error of identifying the text area under each group of convolution kernels is obtained. The representation method of the prediction error can be selected based on actual needs, for example, the area difference between the predicted boundary and the actual boundary of the text area identified by each group of convolution kernels is used as the prediction error.
[0069] For example, it can be calculated according to the formula:
[0070]
[0071] Get the prediction error K of each group of convolution kernels ce ,in, are the first partial derivative, the second partial derivative, the third partial derivative, and the fourth partial derivative, respectively. N is the number of anchor boxes of the predicted boundary, and x i is the horizontal coordinate of the predicted boundary, x is the horizontal coordinate of the actual boundary, y is i is the ordinate of the predicted boundary, y is the ordinate of the predicted boundary, w i is the height of the predicted boundary, w is the height of the actual boundary, and h i is the width of the predicted boundary, and h is the width of the actual boundary.
[0072] The predicted boundary of the convolution kernel corresponding to the minimum prediction error is determined as the predicted boundary of the text area recognized by the convolutional neural network model. The above method uses the nonlinear least squares method combined with the Gauss-Newton method to accurately fit the boundary coordinates based on the generation of the recognized text area under each group of convolution kernels. By constructing the objective function and iteratively optimizing the position coordinates of the predicted boundary, the prediction result with the minimum prediction error is determined as the predicted boundary.
[0073] S11-2. According to the deviation between the predicted boundary and the actual boundary of the text area, the boundary area deviation and the boundary position deviation are obtained. The boundary area deviation can be directly represented as the difference between the predicted boundary and the actual boundary, or as the ratio of the area intersection and the area union between the two. Similarly, the boundary position deviation can be represented as the deviation of the centroid position between the predicted boundary and the actual boundary, or as the maximum offset distance between the two areas. The boundary area deviation and the boundary position deviation can represent the difference between the two from different dimensions, and no specific limitation is made here.
[0074] S11-3, determining the boundary area deviation and the boundary position deviation as the prediction deviation. The prediction deviation can be represented by the boundary area deviation and the boundary position deviation as two different data; of course, the prediction deviation can also be represented as a specific quantitative value by performing quantization processing based on the boundary area deviation and the boundary position deviation, such as the overlap degree between the two boundaries.
[0075] The convolutional neural network model extracts image features based on anchor boxes to improve the accuracy and robustness of text region detection. In this way, the algorithm can more accurately find and recognize text in images, even if the text is small or has a strange shape. The design of anchor boxes follows the following general distribution rules:
[0076] Anchor i =(x i ,y i ,w i ,h i ), where i = 1, 2, ..., N2; N2 is the total number of anchor boxes. (x i ,y i ) is the center coordinate of the anchor box, w i With h i are the width and height of the anchor box respectively. The embodiment of the present invention introduces an asymmetric penalty factor λ to solve the skew problem of the predicted boundary of the text area. The degree of overlap is calculated by the following formula:
[0077]
[0078] D max =max(w gt ,h gt )
[0079] Among them, U modified Used to evaluate the overlap between the predicted boundary and the actual boundary; A intersection With A union They represent the intersection area and union area between the predicted boundary and the actual boundary respectively; (x gt ,y gt ,w gt ,hgt ) is the parameter of the actual boundary, x gt is the horizontal coordinate of the centroid of the actual boundary, y gt is the centroid ordinate of the actual boundary, w gt is the actual border width, h gt is the height of the actual boundary; (x pred ,y pred ,w pred ,h pred ) is the parameter of the predicted bounding box, x pred is the horizontal coordinate of the centroid of the predicted boundary, y pred is the centroid ordinate of the predicted boundary, w pred is the width of the prediction boundary, h pred is the height of the predicted boundary; λ is the asymmetric penalty factor, which is used to adjust the impact of the skewness. offset is the offset of the predicted boundary center point relative to the actual boundary box center point; D max is the maximum side length of the actual boundary.
[0080] So far, the prediction deviation of the convolutional neural network during the training process has been obtained.
[0081] S12. Perform semantic recognition on the text on the image sample to obtain the posterior probability that the image feature on the image sample belongs to the text.
[0082] Specifically, the posterior probability can be used to determine whether the corresponding image feature belongs to text. For example, after semantic recognition of the image feature on the image sample, the semantic meaning of the feature is "today's weather is sunny", but "sunny" is disturbed by the image background, resulting in uncertainty in the recognition process. The posterior probability obtained through semantic recognition can determine that the image feature is text, so it is determined that the image feature belongs to the text area. The posterior probability can be used to further verify whether the image feature is text to improve the accuracy of determining the text area.
[0083] Exemplarily, step S12 includes sub-steps S12-1 to S12-3, which are specifically described as follows:
[0084] S12-1. A normalization factor is configured for the preset conditional random field model so that the sum of the probabilities of the marked sequences during semantic recognition is 1.
[0085] The Conditional Random Field (CRF) model deeply integrates multi-dimensional contextual information to fine-tune the positioning and optimization of the initially recognized text area. Specifically, the designed contextual information fusion model can be expressed as a Markov random field in a multi-dimensional feature space, which uses more information to help the computer better understand the text in the image, so as to find the location of the text more accurately.
[0086] The normalization factor Z(x) ensures that the sum of the probabilities of all possible tag sequences is 1 and is calculated as:
[0087]
[0088] Among them, E(y|x) is the energy function, which consists of n characteristic functions E i (y|x), each feature function describes different types of context information. i is the characteristic function E i The weight of (y|x) determines the importance of the feature in the energy function.
[0089] S12-2. Perform semantic recognition training on the conditional random field model according to the graph cut energy function until the semantic recognition result meets the preset conditions. For the training and optimization of the above-mentioned conditional random field model, the embodiment of the present invention introduces an optimization strategy based on the graph cut algorithm. The graph cut energy function is used here to effectively solve the maximum a posteriori probability (MAP) estimation problem, thereby optimizing the model parameters. The specific steps are as follows:
[0090] (1) Constructing a graph model: The text region localization problem is transformed into a graph model, where nodes represent pixels or text fragments and edges represent the dependencies between adjacent pixels or fragments.
[0091] (2) Define the graph cut energy function: By expanding the energy function in the conditional random field model, the graph cut energy function is defined as follows:
[0092]
[0093] Among them, EGC i (y|x) is the function calculation result, which is used to minimize the overall cost of label assignment; D i,j (y i ,y j ) indicates label y i With y j Discontinuity penalty between adjacent nodes (pixels or text fragments) describing the labels y i and j The penalty term for inconsistency between i (y i |x i ) indicates label y i For the observation x i The data item penalty reflects the consistency between the label and the observed data; α i,j and β i are the corresponding weights, which are used to adjust the relative importance of different types of penalties in the total energy.i (y|x) is used to make structured predictions on the label y given the observed data x. The goal is to find the i (y|x) minimum label y.
[0094] (3) Optimization algorithm design: Using the graph cut algorithm to minimize the energy function E GC (y|x), by alternately iteratively optimizing label assignment and weight update, the accuracy of text region positioning can be improved.
[0095] (4) Model regularization: During the training process, the L2 regularization term is introduced to avoid overfitting and ensure the generalization ability of the model.
[0096] S12-3, input the image sample into the conditional random field model whose semantic recognition result meets the preset conditions, so as to obtain the posterior probability that the image feature on the image sample belongs to the text. The posterior probability of the image feature on the image sample is represented by the following formula:
[0097]
[0098] Where P(y|x) represents the posterior probability distribution of the labeled sequence y given the observed sequence x; Z(x) is the normalization factor to ensure that the sum of the probabilities is 1; E(y|x) is the energy function, which is composed of n weighted feature functions E i (y|x), each feature function corresponds to different types of context information and is expressed by the parameter λ i When context information is fused and recognized, the location of the text area is optimized through the improved conditional random field model.
[0099] It can be understood that the above method can calculate the values of part-of-speech features, context features, and dependency features for each prediction boundary. The values of all feature functions are weighted and summed to obtain the energy function. The sum of the energy function values of all possible label sequences is calculated to obtain the normalization factor. Substitute the energy function value into the formula to calculate the posterior probability distribution of the output label sequence under the condition of a given input image. According to the posterior probability distribution, the most likely label sequence is selected as the recognition result and marked on the image.
[0100] At this point, the posterior probability that the image features on the image sample belong to the text is obtained.
[0101] S13. Based on the prediction deviation and posterior probability, continue to train the convolutional neural network to recognize text areas.
[0102] Specifically, the prediction deviation can be used to obtain the recognition error of the convolutional neural network model during the initial training process, and the posterior probability can further determine whether the image feature on the image sample is text. Therefore, in the continued training process of the convolutional neural network model, the model can be made to converge more accurately and achieve the purpose of accurately identifying the text area in the image sample.
[0103] Furthermore, the text has various forms of expression in images, for example, fonts, distributions, and backgrounds all have multiple forms. In order to further improve the accuracy of convolutional neural network model training, the embodiment of the present invention expands the image samples. Specifically, the expansion of complex backgrounds and variable fonts is implemented through the following steps.
[0104] (1) Use the pre-trained deep learning model for feature extraction and combine it with the transfer learning method to apply the pre-trained model to the text recognition task.
[0105] (2) Use data augmentation models, including rotation, scaling, cropping, color transformation, etc., to increase the diversity of image samples.
[0106] (3) The sample weights are calculated using the following formula to improve the model’s generalization ability for complex backgrounds and variable fonts:
[0107]
[0108] Among them, (xi,yi) represents the coordinates of the training samples, μ and σ are the mean and standard deviation of the sample coordinates respectively, wi represents the sample weight; μ represents the mean of the sample coordinates; σ represents the standard deviation of the sample coordinates; wi represents the calculated sample weight.
[0109] It can be understood that the above formula is used to calculate the sample weight wi of the pixel (xi, yi). The sample weight wi reflects the feature importance of the pixel (xi, yi), which is used to adjust the response value of the pixel at different scales in multi-scale detection and adaptive scale scaling technology. For each pixel (xi, yi) in the image, calculate its sample weight wi at the current scale. The sample weight wi is the value of the Gaussian function, which reflects the degree of difference between the pixel (xi, yi) and its average value μ. By calculating the sample weights at different scales, targets of different sizes can be detected. Weight adjustment makes the image features more prominent at different scales, thereby improving the adaptability of the recognition algorithm.
[0110] S14. When the continued training result of the convolutional neural network reaches a preset target, the target image of the text area to be predicted is input into the convolutional neural network model.
[0111] Specifically, the convolutional neural network model that has completed continued training can be tested using a test set of image samples. The test results are characterized by the accuracy of the text area. When the accuracy is greater than a preset threshold, it means that the continued training results have achieved the preset goals, and the convolutional neural network model is able to implement accurate text area recognition. The target image is then input into the convolutional neural network model.
[0112] In practical applications, since the target image may be obtained by shooting with a terminal device, it may be affected by the shooting environment, the terminal device, etc., resulting in a large number of noise points on the target image. Based on this, in a specific implementation, before inputting the target image of the text area to be predicted into the convolutional neural network model, the method for determining the text area also includes:
[0113] The target image is preprocessed, and the preprocessing methods include removing noise, enhancing contrast, adjusting lighting, etc. The preprocessing can make the target image clearer and the text more prominent. The noise reduction process can be based on the grayscale value of each pixel of the target image. Median filtering; of course, other noise reduction processing methods can also be used. The embodiment of the present invention is an adaptive complex structure noise elimination algorithm based on local features. Based on the traditional median filtering, the algorithm introduces the local variance and spatial frequency information of the image to dynamically determine the size and shape of the filter window, thereby achieving adaptive suppression of different types and distributions of noise, just like using an eraser to erase stains on paper. This method can help remove dirty spots or interference on the picture. The mathematical expression of the algorithm is as follows:
[0114]
[0115] Among them, f(x,y) represents the pixel value of the output image; MED represents the median operation on the pixel values in the set; Φ is a structured noise evaluation function that combines the local standard deviation σ(x,y) of the image and the spatial frequency information; W represents the adaptively adjusted filter window set; ω(k,l) represents the weight of the pixel point (xk,yl) in the filter window, which is determined by the following formula:
[0116]
[0117] in, is the average value of the pixels within the filter window.
[0118] It should be noted that the adaptively adjusted filter window set dynamically adjusts the filter window and denoising algorithm according to the local variance and spatial frequency information of the image. For areas with high noise levels, a larger filter window is used for smoothing to remove noise. For areas with low noise levels, a smaller filter window is used to retain image details. For edge and texture areas, specific filter windows and algorithms are used to avoid blurring edge and texture details. By processing in the above manner, the target image can be better denoised.
[0119] After the noise of the target image is removed, the image features on the target image after the noise reduction process are contrast enhanced according to the multi-level histogram to obtain the target image after the preprocessing.
[0120] Specifically, the target image may be difficult to read due to uneven lighting or insufficient contrast. Through contrast enhancement, the target image can be divided into a foreground layer (text area) and a background layer (background area). The foreground layer is enhanced using the Retinex theory to increase the contrast of the text area and make the text clearer. The background layer is enhanced using multi-level histogram equalization technology to expand the dynamic range of the background layer and increase the contrast of the background area. When processing based on the multi-level histogram, the target image is divided into multiple levels, and histogram equalization is performed on each level to make the pixel distribution of each level more uniform. The equalized levels are merged to obtain the final enhanced image.
[0121] The embodiment of the present invention combines the multi-level histogram equalization technology with the Retinex theory, and proposes a multi-level dynamic range compression and detail contrast enhancement model. This model not only expands the dynamic range of the image, but also effectively enhances the visual saliency of the text area. This method is like "adjusting" the bright and dark parts of the photo, making the bright areas less glaring and the dark areas less dark. In this way, all the details in the photo, especially the text part, look clearer. The model is described as follows:
[0122]
[0123] Among them, I(x,y) represents the pixel value of the enhanced image; N is the number of decomposition layers; α i is the weight factor of the i-th layer, which is used to control the enhancement effect of different frequency bands; S(x,y) is the pixel value of the original image; R i (x,y) represents the reflectance image of the i-th layer, which is calculated by the following formula:
[0124]
[0125] Among them, β i , γ i ,λi are the first adjustment parameter, the second adjustment parameter and the third adjustment parameter of the i-th layer, respectively, which are used to control the local adaptability of the reflectance image; S max is the maximum pixel value of the original image. The pixel value is determined based on the actual type of the target image. For example, when the target image is a grayscale image, the pixel value is the grayscale value of the pixel.
[0126] At this point, the target image to be input into the convolutional neural network model has been preprocessed.
[0127] Before inputting the target image of the text area to be predicted into the convolutional neural network model, the method for determining the text area also includes configuring the convolutional neural network model with a mapping relationship between the detection response value and the corresponding image feature. The specific description is as follows:
[0128] The first step is to determine the detection response value of the convolutional neural network model in detection templates of different sizes based on the preset detection response model. Based on the feature extraction requirements of the target image, multiple sets of detection templates of different scales can be designed, and the detection template scale range is (smin, smax). The detection response value at each scale is calculated using the following formula:
[0129]
[0130] Among them, R(s) is the detection response value; I(x i ,y i ) means the image is in (x i ,y i ) at the pixel value; W(x i ,y i ) represents the corresponding weight of the detection template; s represents the current scale, that is, the detection template scale; n is the total number of pixels.
[0131] The second step is to obtain the mapping relationship between the detection response value and the corresponding image feature according to the detection requirements of different image features on the image to be identified. Different image features require different scaling ratios. According to the response value, the best scale is selected for detection. The mapping relationship can be set based on the relationship between the detection response value and the image feature. Use the following adaptive scaling formula to adjust the detection window size:
[0132]
[0133] Among them, s new Indicates the new detection window size; s current represents the current detection window scale, d represents the difference between the text area height and the detection window height, and N is the scaling factor.
[0134] If R(s) is used for image fusion, if you need to highlight the details of certain areas, then you need a smaller detection template s to increase the weight of these areas. If R(s) is used for edge detection, if you need to reduce the impact of noise, then you may need a larger detection template s to reduce the weight of pixels outside the edge area.
[0135] The third step is to configure the parameters of the trained convolutional neural network model according to the mapping relationship. After completing the parameter configuration, the convolutional neural network model can select the appropriate detection template for feature recognition based on the detection requirements of image features, and improve the adaptability to the recognition of different types and sizes of fonts.
[0136] S15. Determine the text area of the target image according to the output result of the convolutional neural network model.
[0137] Specifically, the output result can be the coordinate data of the text area. The convolutional neural network model combines mathematical morphology to refine the predicted boundary of the text area to obtain the precise outline of the text area. The predicted boundary outline is mapped into a coordinate matrix using the coordinate mapping relationship. Of course, the centroid coordinates of the text area can also be output at the same time. The centroid coordinates (Xc, Yc) of the text area are calculated using the following mathematical formula:
[0138]
[0139] Among them, (xi,yi) represents the point coordinates of each point on the predicted boundary of the text region, Si represents the area of each point on the predicted boundary, and n represents the number of points on the predicted boundary. Xc and Yc represent the centroid coordinates of the text region.
[0140] The following embodiment of the present invention will generally explain how to implement the determination of text areas after the convolutional neural network model is trained. Figure 2 , Figure 2 Flow of the method for determining the text area Figure 2 , including:
[0141] S201, image preprocessing: Preprocess the target image of the text area to be determined, including image denoising, contrast enhancement, etc.
[0142] S202, image feature extraction: The convolutional neural network model extracts image features based on detection models of different sizes.
[0143] S203: Text region recognition: A preliminary text region is determined through image feature recognition.
[0144] S204: Positioning the text area: Positioning the initially determined text area.
[0145] S205, positioning position optimization: semantic recognition is performed based on the conditional random field model, and the position of the located text area is optimized.
[0146] S206: Output prediction results. Output the optimized text area data, including the coordinate matrix of the prediction boundary and the centroid coordinates.
[0147] The text area determination method provided in the embodiment of the present invention can be applied in image recognition scenarios involving multiple languages and fonts. This method can accurately identify and locate each text area, and perform pre-processing in combination with the text extraction requirements on the image to provide accurate location information for subsequent OCR recognition or other image analysis tasks.
[0148] Based on the same technical concept as the determination method, the embodiment of the present invention also provides a device for determining a text area, see Figure 3 , Figure 3 The structural diagram of the determination device is shown in FIG. The determination device includes:
[0149] The training acquisition module 301 is used to perform recognition training of text regions on image samples on a preset convolutional neural network model to obtain a prediction deviation of the convolutional neural network model for recognizing text regions;
[0150] The recognition acquisition module 302 is used to perform semantic recognition on the text on the image sample to obtain the posterior probability that the image feature on the image sample belongs to the text;
[0151] The recognition training module 303 is used to continue to perform recognition training of the convolutional neural network on the text area according to the prediction deviation and the posterior probability;
[0152] An input module 304, used to input the target image of the text area to be predicted into the convolutional neural network model when the continued training result of the convolutional neural network reaches a preset target;
[0153] The first determination module 305 is used to determine the text area of the target image according to the output result of the convolutional neural network model.
[0154] In an optional embodiment, the training acquisition module includes:
[0155] The first acquisition submodule is used to input the image sample of the labeled text area into the convolutional neural network model to perform recognition training of the text area to obtain the predicted boundary of the text area;
[0156] The second obtaining submodule is used to obtain a boundary area deviation and a boundary position deviation according to the deviation between the predicted boundary and the actual boundary of the text area;
[0157] The first determination submodule is used to determine the boundary area deviation and the boundary position deviation as the prediction deviation.
[0158] In an optional embodiment, the training acquisition module further includes:
[0159] A third obtaining submodule is used to identify predicted boundaries and actual boundaries of text regions on image samples based on different groups of convolution kernels according to the convolution neural network model, and obtain prediction errors for identifying text regions under each group of convolution kernels;
[0160] The second determination submodule is used to determine the prediction boundary of the convolution kernel corresponding to the minimum prediction error as the prediction boundary of the text area recognized by the convolutional neural network model.
[0161] In an optional embodiment, the third obtaining submodule includes:
[0162] Get the unit for use according to the formula:
[0163]
[0164] number, second partial derivative, third partial derivative and fourth partial derivative, N is the number of anchor boxes of the predicted boundary, x i is the horizontal coordinate of the predicted boundary, x is the horizontal coordinate of the actual boundary, y is i is the ordinate of the predicted boundary, y is the ordinate of the predicted boundary, w i is the height of the predicted boundary, w is the height of the actual boundary, and h i is the width of the predicted boundary, and h is the width of the actual boundary.
[0165] In an optional embodiment, the identification obtaining module includes:
[0166] A configuration submodule is used to configure a normalization factor for the preset conditional random field model so that the sum of the probabilities of the marked sequences during semantic recognition is 1;
[0167] A training submodule is used to perform semantic recognition training on the conditional random field model according to the graph cut energy function until the semantic recognition result meets the preset conditions;
[0168] The fourth acquisition submodule is used to input the image sample into a conditional random field model whose semantic recognition result meets preset conditions, so as to obtain the posterior probability that the image feature on the image sample belongs to the text.
[0169] In an optional embodiment, the determining device further includes:
[0170] The first processing and obtaining module is used to perform noise reduction processing on the target image to obtain the target image after noise reduction processing;
[0171] The second processing acquisition module is used to perform contrast enhancement processing on the image features on the target image after noise reduction processing according to the multi-level histogram to obtain the target image after preprocessing.
[0172] In an optional embodiment, the determining device further includes:
[0173] A second determination module is used to determine the detection response value of the convolutional neural network model for detection templates of different sizes according to a preset detection response model;
[0174] An acquisition module, used to obtain a mapping relationship between a detection response value and a corresponding image feature according to detection requirements of different image features on the image to be identified;
[0175] A data configuration module is used to configure parameters of the trained convolutional neural network model according to the mapping relationship.
[0176] Based on the same technical concept as the determination method, an embodiment of the present invention also provides an electronic device, including a processor and a memory, wherein the memory is coupled to the processor and stores instructions, and when the instructions are executed by the processor, the electronic device executes the steps of any one of the methods in the determination method.
[0177] Based on the same technical concept as the determination method, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the steps of any one of the determination methods are implemented.
[0178] The technical solution provided in the embodiments of the present invention has at least the following technical effects or advantages:
[0179] By training the preset convolutional neural network model to identify the text area on the image sample, the prediction deviation of the convolutional neural network model in identifying the text area is obtained; the semantic recognition of the text on the image sample is performed to obtain the posterior probability that the image feature on the image sample belongs to the text; in order to make the convolutional neural network model more accurately trained, the convolutional neural network is continued to be trained for text area recognition according to the prediction deviation and posterior probability; when the convolutional neural network continues to train the result to reach the preset goal, it means that the convolutional neural network model can accurately identify the text area, and the target image of the text area to be predicted is input into the convolutional neural network model; according to the output result of the convolutional neural network model, the text area of the target image is determined. This scheme enables the convolutional neural network model to continuously converge on the text features of the text area during continued training through the prediction deviation and posterior probability, and can more accurately identify the location of the text area in the image, thereby improving the accuracy of determining the text area.
[0180] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0181] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (modules, systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0182] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0183] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0184] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0185] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for determining a text area, It is characterized in that The method comprises: Performing recognition training on a preset convolutional neural network model for a text region on an image sample to obtain a prediction deviation of the convolutional neural network model for recognizing the text region; Performing semantic recognition on the text on the image sample to obtain a posterior probability that the image feature on the image sample belongs to the text; Continue to perform text region recognition training on the convolutional neural network according to the prediction deviation and the posterior probability; When the continued training result of the convolutional neural network reaches a preset target, inputting the target image of the text area to be predicted into the convolutional neural network model; According to the output result of the convolutional neural network model, the text area of the target image is determined.
2. The method for determining a text area according to claim 1, It is characterized in that The performing recognition training on the preset convolutional neural network model for the text area on the image sample to obtain the prediction deviation of the convolutional neural network model for recognizing the text area includes: Inputting the image sample with the marked text area into the convolutional neural network model to perform text area recognition training to obtain the predicted boundary of the text area; Obtaining a boundary area deviation and a boundary position deviation according to a deviation between the predicted boundary and an actual boundary of the text area; The boundary area deviation and the boundary position deviation are determined as the prediction deviation.
3. The method for determining a text area according to claim 2, It is characterized in that After inputting the image sample of the labeled text area into the convolutional neural network model for text area recognition training to obtain the predicted boundary of the text area, the method further includes: Identifying predicted boundaries and actual boundaries of text regions on the image samples based on different groups of convolution kernels according to a convolutional neural network model, and obtaining prediction errors for identifying text regions under each group of convolution kernels; The prediction boundary of the convolution kernel corresponding to the minimum prediction error is determined as the prediction boundary of the text area identified by the convolutional neural network model.
4. The method for determining a text area according to claim 3, It is characterized in that The method of identifying the predicted boundary and the actual boundary of the text area on the image sample based on different groups of convolution kernels according to the convolution neural network model, and obtaining the prediction error of identifying the text area under each group of convolution kernels, includes: According to the formula: Get the prediction error K of each group of convolution kernels ce ,in, are the first partial derivative, the second partial derivative, the third partial derivative and the fourth partial derivative respectively, N is the number of anchor boxes of the predicted boundary, x i is the horizontal coordinate of the predicted boundary, x is the horizontal coordinate of the actual boundary, y is i is the ordinate of the predicted boundary, y is the ordinate of the predicted boundary, and w i is the height of the predicted boundary, w is the height of the actual boundary, h i is the width of the predicted boundary, and h is the width of the actual boundary.
5. The method for determining a text area according to claim 1, It is characterized in that The performing semantic recognition on the text on the image sample to obtain the posterior probability that the image feature on the image sample belongs to the text includes: The normalization factor is configured for the preset conditional random field model so that the sum of the probabilities of the labeled sequences during semantic recognition is 1; Performing semantic recognition training on the conditional random field model according to the graph cut energy function until the semantic recognition result meets the preset conditions; The image sample is input into a conditional random field model whose semantic recognition result satisfies preset conditions, so as to obtain the posterior probability that the image feature on the image sample belongs to the text.
6. The method for determining a text area according to claim 1, It is characterized in that Before inputting the target image of the text area to be predicted into the convolutional neural network model, the method further includes: Performing noise reduction processing on the target image to obtain a target image after noise reduction processing; The image features on the target image after noise reduction are subjected to contrast enhancement processing according to the multi-level histogram to obtain the target image after preprocessing.
7. The method for determining a text area according to claim 1, It is characterized in that Before inputting the target image of the text area to be predicted into the convolutional neural network model, the method further includes: Determining the detection response value of the convolutional neural network model for detection templates of different sizes according to a preset detection response model; According to the detection requirements of different image features on the image to be identified, a mapping relationship between the detection response value and the corresponding image feature is obtained; The parameters of the trained convolutional neural network model are configured according to the mapping relationship.
8. A device for determining a text area, It is characterized in that The device comprises: A training acquisition module, used for performing recognition training of text regions on image samples on a preset convolutional neural network model to obtain a prediction deviation of the convolutional neural network model in recognizing the text region; An identification and acquisition module, used for performing semantic recognition on the text on the image sample to obtain a posterior probability that the image feature on the image sample belongs to the text; A recognition training module, used for continuing to perform recognition training of text regions on the convolutional neural network according to the prediction deviation and the posterior probability; An input module, used for inputting a target image of a text area to be predicted into the convolutional neural network model when the continued training result of the convolutional neural network reaches a preset target; The first determination module is used to determine the text area of the target image according to the output result of the convolutional neural network model.
9. An electronic device, It is characterized in that The electronic device comprises a processor and a memory, wherein the memory is coupled to the processor and stores instructions, and when the instructions are executed by the processor, the electronic device executes the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Text region detection model training method and device, electronic device and storage medium
CN110610166A
Computer Vision Systems and Methods for Information Extraction from Text Images Using Evidence Grounding Techniques
US20210192201A1
Cited By
OCR (Optical Character Recognition) method based on adaptive mapping and perception adjustment
CN120340050A
An OCR recognition method based on adaptive mapping and perceptual adjustment
CN120340050B
