An OCR recognition method based on adaptive mapping and perceptual adjustment

Through the OCR recognition method of adaptive mapping and perceptual adjustment, the recognition accuracy and efficiency of traditional OCR systems under complex backgrounds and text deformation is solved, high-precision text classification and bounding box positioning are achieved, and the recognition ability of the OCR system in complex environments is improved.

CN120340050BActive Publication Date: 2025-09-02BEIJING ZHONGKE JINCAI TECH

Patent Information

Application Number
CN202510489692.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-18
Publication Date
2025-09-02
Estimated Expiration
2045-04-18

AI Technical Summary

Technical Problem

When traditional OCR systems deal with text of complex backgrounds, different sizes or densities, the recognition accuracy and efficiency are not high, especially in text deformation or high dynamic range environments, resulting in increased recognition error rate and inaccurate positioning of bounding boxes.

Method used

The OCR recognition method of adaptive mapping and perceptual adjustment is adopted to extract feature maps through neural network models, calculate the convolution kernel offset, adjust the receptive field size and shape, and combine morphological model and loss function optimization to achieve end-to-end text classification and regression.

Benefits of technology

It improves character classification accuracy and bounding box positioning accuracy, reduces dependence on complex post-processing steps, and enhances the adaptability and recognition efficiency of the model in complex environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120340050B_ABST
    Figure CN120340050B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of computer vision, and more particularly to an OCR recognition method based on adaptive mapping and perceptual adjustment. The method extracts the original feature map of the OCR image through a neural network. Next, by comparing the original feature map with a morphological model, the deviation is calculated to adjust the offset of the convolution kernel, thereby accurately locating feature points. When recognizing text regions, the text density and average spacing between characters in each region are calculated, and the size and shape of the receptive field are dynamically determined based on this. A target feature map is generated through this adaptive convolution process. Finally, the neural network model is trained specifically based on the target feature map and text density and spacing information to obtain an optimized OCR recognition model. By conducting in-depth analysis of text features, the present invention significantly improves the recognition accuracy and adaptability of OCR technology when processing diverse and complex documents.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer vision, and in particular to an OCR recognition method based on adaptive mapping and perceptual adjustment. Background Art

[0002] In traditional optical character recognition (OCR) systems, fixed receptive fields and standard convolutional networks are usually used to handle the task of text recognition in images.

[0003] The main problem faced by existing technologies is that recognition accuracy and efficiency are often low when dealing with text with complex backgrounds, different sizes or densities. In particular, when the text is deformed, distorted, or in an environment with a high dynamic range, fixed receptive fields and standard convolution processing methods have difficulty adapting to these changes, resulting in increased recognition error rates and inaccurate bounding box positioning. In addition, existing OCR systems often lack effective optimization mechanisms when co-processing classification and regression tasks, making it difficult to achieve high-precision character classification and accurate bounding box regression in practical applications, especially when the text size and spacing vary greatly. These problems limit the performance and practicality of traditional OCR technology in a wider range of application scenarios. Summary of the Invention

[0004] To this end, the present invention provides an OCR recognition method based on adaptive mapping and perceptual adjustment to overcome the problems of the prior art in processing text deformation, distortion and adaptability in dynamic environments, thereby significantly improving the character classification accuracy and bounding box positioning accuracy.

[0005] To achieve the above objectives, the present invention provides an OCR recognition method based on adaptive mapping and perceptual adjustment, comprising:

[0006] Step S1, obtaining an OCR image to be processed, extracting features of the OCR image using a neural network model to obtain an original feature map, and also obtaining historical OCR images as historical data;

[0007] Step S2, calculating the deviation between the original feature map and the predefined morphological model to adjust the offset of the convolution kernel, and adjusting the position of the feature point according to the offset;

[0008] Step S3, obtaining the text area of ​​the OCR image, and calculating the text density and the average spacing between characters according to each text area;

[0009] Step S4, calculating the receptive field size according to the text density, and adjusting the receptive field shape according to the average spacing;

[0010] Step S5, convolving the original feature map according to the receptive field size and the receptive field shape to obtain a target feature map;

[0011] Step S6: training the neural network model according to the target feature map, the text density and the average spacing to obtain a target OCR recognition model.

[0012] Furthermore, the process of calculating the deviation between the original feature map and the predetermined morphological model to adjust the offset of the convolution kernel includes:

[0013] Comparing the original feature map with the template in the morphological model to obtain a comparison result;

[0014] The deviation between the original feature map and the template is analyzed and calculated according to the comparison result to adjust the offset.

[0015] Furthermore, the process of analyzing and calculating the deviation between the original feature map and the template according to the comparison result to adjust the offset includes:

[0016] Offset(x,y)=σ(Conv(Input,W offset )+Bias)

[0017] Among them, Offset(x,y) represents the offset that the convolution kernel needs to adjust at the position of coordinate (x,y) on the original feature map. The Sigmoid function is used to map the convolution result to a target range. Conv(Input,W_offset) is a convolution operation performed on the OCR image Input using the weight matrix W_offset to calculate the offset. Bias is a bias term used to adjust the baseline of the offset.

[0018] Furthermore, the process of adjusting the position of the feature point according to the offset includes:

[0019] P adjusted (x,y)=Interpolation(P,x+Scale factor Δx,y+Scale factor ·Δy)

[0020] Among them, P_adjusted(x,y) represents the adjusted feature point position to obtain more accurate character boundaries, Interpolation(P,x',y') is the interpolation calculation of the original feature map P, x' and y' are the new coordinates after offset adjustment, Scale_factor is the scale factor, deltax and deltay are the specific values ​​​​obtained from the offset calculation, indicating the horizontal and vertical adjustments that need to be made on the original coordinates (x,y).

[0021] Furthermore, the process of step S3 includes:

[0022] performing binarization and denoising processing on the OCR image to obtain a processed image;

[0023] determining the edge of the processed image using edge detection to obtain an edge result;

[0024] Performing dilation, erosion, opening and closing operations on the edge result to obtain an operation result;

[0025] Performing contour detection on the operation result to obtain a detection result;

[0026] Filter the text region according to the detection result and determine the area of ​​the text region;

[0027] determining the number of text pixels based on the processed image;

[0028] The ratio of the number of text pixels to the area of ​​the text region to obtain the text density;

[0029] Determining character positions based on the text area using a vertical projection technique;

[0030] The distances between adjacent characters are measured according to the character positions to obtain distance results, and all the distances are averaged to obtain the average spacing.

[0031] Furthermore, the process of calculating the receptive field size according to the text density includes:

[0032] R dynamic =α·log(1+Density measure (P))·R initial

[0033] Among them, R_dynamic represents the size of the receptive field after dynamic adjustment, Alpha represents the adjustment coefficient, log(1+Density_measure(P)) represents the conversion of text density into a slowly growing logarithmic scale, Density_measure(P) represents the text density measurement function, and R_initial represents the initial receptive field size.

[0034] Furthermore, the process of adjusting the receptive field shape according to the average spacing includes:

[0035] If the character spacing is uniform, use a rectangular or square receptive field;

[0036] If the character spacing is uneven, use an elliptical or adaptive receptive field;

[0037] For a specific font or typography style, the shape of the receptive field is customized according to its characteristics.

[0038] Furthermore, the process of step S5 includes:

[0039] Generate a corresponding convolution kernel according to the receptive field size and the receptive field shape;

[0040] Traversing the convolution kernel over the position of the original feature map;

[0041] Calculating the dot product of the convolution kernel and the local area in the original feature map according to each of the positions, and adding the bias top to the dot product to obtain the element of the target feature map;

[0042] The elements of the target feature map are activated and pooled to obtain the target feature map.

[0043] Furthermore, the process of step S6 includes:

[0044] Dividing the historical data into a training set and a validation set;

[0045] Initialize loss weights lambda1 and lambda2 to balance classification loss and regression loss;

[0046] The weighted sum of the classification loss and the regression loss is defined as the total loss;

[0047] Training the neural network model according to the training set to calculate the total loss;

[0048] Updating the weights of the neural network model using gradient descent according to the total loss to obtain target weights;

[0049] The neural network model is verified according to the target weight and the verification set to obtain the target OCR recognition model.

[0050] Furthermore, the process of training the neural network model according to the training set to calculate the total loss includes:

[0051] Loss total =λ1·L cls(Softmax(Output cls ))+λ2·L reg (SmoothL1(Output reg ))

[0052] Among them, Los_total represents the total loss, L_cls represents the classification loss function, Softmax(Output_cls) represents the conversion of the original output of the classification task into a probability distribution through the Softmax function, L_reg represents the regression loss function, SmoothL1(Output_reg) represents the application of SmoothL1 loss to the output of the regression task, lambda1 and lambda2 are loss weights used to adjust the classification loss and regression loss.

[0053] Compared with the prior art, the beneficial effect of the present invention is that the present invention can more accurately capture the features of the text by adjusting the offset of the convolution kernel through adaptive mapping, thereby improving the accuracy of OCR recognition. The perceptual adjustment mechanism can dynamically adjust the receptive field according to the text density and character spacing, so that the model can better adapt to different text layouts and formats. By integrating these adaptive and perceptual adjustment mechanisms into the neural network model, it is possible to reduce the reliance on complex post-processing steps while maintaining a high recognition rate, thereby improving the efficiency of real-time OCR recognition. The adaptive adjustment of the feature map helps the model better focus on the text area and reduce the impact of background noise and other non-text elements.

[0054] In particular, by comparing the original feature map with the template in the morphological model, key features in the original feature map can be more accurately identified and located, helping to improve the accuracy of the feature extraction stage of the OCR system. Adjusting the offset of the convolution kernel based on the comparison results allows the feature extraction process to adapt to different types of text features and layouts. Accurate feature matching and extraction directly impacts the subsequent classification and recognition stages, thereby improving the overall OCR recognition rate.

[0055] In particular, by fine-tuning the convolution kernel offset, the model can more accurately locate text features, thereby improving feature extraction accuracy. Text in images may exhibit various deformations, such as tilt and distortion. Dynamically adjusting the convolution kernel offset helps the model better adapt to these deformations and improve recognition rates.

[0056] In particular, by fine-grained adjustments to feature point positions, the model can more precisely locate character boundaries and key features, improving feature extraction accuracy. In images with complex backgrounds or high noise levels, adjusting feature point positions allows the model to better focus on the text area and reduce background noise interference.

[0057] In particular, binarization and denoising reduce noise and interference in the image, improving image clarity. Binarization and denoising reduce noise and interference in the image, improving image clarity. Measuring the distance between adjacent characters and calculating the average spacing provides the model with important information about the text layout, helping to improve the model's adaptability to changes in text spacing. Measuring the distance between adjacent characters and calculating the average spacing provides the model with important information about the text layout, helping to improve the model's adaptability to changes in text spacing.

[0058] In particular, by adjusting the receptive field size based on text density, the model can more accurately capture the characteristics of text of varying densities, thereby improving recognition accuracy, especially in areas with dense or sparse text. Dynamic receptive fields help the model learn more general and robust features, rather than simply adapting to the specific text density in the training data, thereby reducing the risk of overfitting. Using smaller receptive fields in areas with sparse text reduces unnecessary computation, while using larger receptive fields in areas with dense text better captures complex features, thereby improving overall computational efficiency.

[0059] In particular, by using a receptive field shape that matches the spacing between characters, the model is able to more accurately segment adjacent characters, especially when the spacing between characters is uniform or uneven. In the case of uneven character spacing, using an elliptical or adaptively shaped receptive field can reduce misrecognition caused by varying character spacing. By using a receptive field that is more appropriate for character spacing and shape, unnecessary computation can be reduced, thereby speeding up the recognition process.

[0060] In particular, by designing an appropriate receptive field size and shape, the convolution kernel can efficiently extract key features from the image, improving the efficiency of feature extraction. By calculating the dot product between the convolution kernel and the original feature map and combining it with a bias term, the model can learn a richer and more representative feature representation, which helps improve recognition accuracy. The introduction of the activation function adds nonlinear characteristics to the feature map, allowing the model to capture more complex patterns and relationships, enhancing the model's generalization ability. The pooling operation reduces the spatial size of the feature map, reducing the computational complexity of the model while retaining the most important feature information, helping to prevent overfitting.

[0061] In particular, by dividing the data into training and validation sets, the model can verify its performance on independent data, which helps improve the model's generalization ability and reduce overfitting. By defining the total loss as the weighted sum of classification loss and regression loss, the model can simultaneously focus on both text classification and position regression tasks, thereby optimizing overall performance. Using the gradient descent algorithm to update the model weights based on the total loss can effectively optimize model parameters and reduce recognition errors. By transforming the complex optimization problem into a total loss minimization problem, the training process is simplified, making model training more efficient.

[0062] In particular, by simultaneously optimizing classification and regression losses, the model can more comprehensively learn data features, thereby accurately predicting the location of text while identifying the text category. This is particularly important in OCR applications. By combining classification and regression tasks in a single overall loss function, end-to-end training can be achieved, simplifying the training process and potentially improving training efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] Figure 1 A flowchart of an OCR recognition method based on adaptive mapping and perceptual adjustment provided by an embodiment of the present invention;

[0064] Figure 2 A schematic flow chart of step S3 in an OCR recognition method based on adaptive mapping and perceptual adjustment provided by an embodiment of the present invention;

[0065] Figure 3 A schematic flow chart of step S5 in an OCR recognition method based on adaptive mapping and perceptual adjustment provided by an embodiment of the present invention;

[0066] Figure 4 A schematic flow chart of step S6 in an OCR recognition method based on adaptive mapping and perceptual adjustment provided by an embodiment of the present invention; DETAILED DESCRIPTION

[0067] In order to make the objects and advantages of the present invention more clearly understood, the present invention is further described below in conjunction with embodiments; it should be understood that the specific embodiments described herein are merely used to explain the present invention and are not intended to limit the present invention.

[0068] The preferred embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.

[0069] It should be noted that, in the description of the present invention, terms such as "up", "down", "left", "right", "inside", and "outside" indicating directions or positional relationships are based on the directions or positional relationships shown in the accompanying drawings. This is only for the convenience of description and does not indicate or imply that the device or element must have a specific orientation, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the present invention.

[0070] Furthermore, it should be noted that, in the description of the present invention, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they may refer to fixed connections, detachable connections, or integral connections; mechanical connections or electrical connections; direct connections or indirect connections through an intermediate medium; and internal communication between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on specific circumstances.

[0071] See also Figure 1 As shown, an embodiment of the present invention provides an OCR recognition method based on adaptive mapping and perceptual adjustment, including:

[0072] Step S1, obtaining an OCR image to be processed, extracting features of the OCR image using a neural network model to obtain an original feature map, and also obtaining historical OCR images as historical data;

[0073] Step S2, calculating the deviation between the original feature map and the predefined morphological model to adjust the offset of the convolution kernel, and adjusting the position of the feature point according to the offset;

[0074] Step S3, obtaining the text area of ​​the OCR image, and calculating the text density and the average spacing between characters according to each text area;

[0075] Step S4, calculating the receptive field size according to the text density, and adjusting the receptive field shape according to the average spacing;

[0076] Step S5, convolving the original feature map according to the receptive field size and the receptive field shape to obtain a target feature map;

[0077] Step S6: training the neural network model according to the target feature map, the text density and the average spacing to obtain a target OCR recognition model.

[0078] Specifically, load the OCR image to be processed. Ensure that the image format, size, and resolution are suitable for neural network input. Use a pretrained neural network model (such as a CNN) to extract features from the OCR image. Obtain a raw feature map, which contains a high-level abstract representation of the image. Collect and annotate historical OCR image data. Preprocess the historical data to match the processing pipeline for the current OCR image. Calculate the difference between the feature map and the morphological model to obtain a deviation value. Adjust the offset of the convolution kernel based on the deviation value. Apply the adjusted convolution kernel to recalculate the feature point positions. Use image segmentation techniques (such as connected component analysis) to identify text regions in the OCR image. For each text region, calculate the ratio of pixels occupied by characters to the total area of ​​the region. Identify the spaces between characters and calculate and average these spaces. Determine the size of the receptive field based on the text density to accommodate text of varying densities. Adjust the shape of the receptive field based on the average inter-character spacing to ensure that the receptive field can accommodate characters of varying spacing. Perform a convolution operation on the raw feature map using the adjusted receptive field size and shape. Obtain a target feature map, which is more suitable for subsequent recognition tasks. Take the target feature map, text density, and average spacing as input data. Design a loss function that combines classification loss (such as cross entropy) and regression loss (such as SmoothL1). Set loss weights (lambda1 and lambda2) to balance the classification and regression tasks. Use backpropagation and an optimization algorithm (such as Adam) to update the weights. Monitor the performance on the validation set during training and perform hyperparameter tuning. Save the model parameters when the validation set performance reaches the optimal value.

[0079] Specifically, by adaptively mapping and adjusting the offset of the convolution kernel, the features of the text can be more accurately captured, thereby improving the accuracy of OCR recognition. The perceptual adjustment mechanism can dynamically adjust the receptive field based on text density and character spacing, allowing the model to better adapt to different text layouts and formats. By integrating these adaptive and perceptual adjustment mechanisms into the neural network model, it is possible to maintain high recognition rates while reducing reliance on complex post-processing steps, thereby improving the efficiency of real-time OCR recognition. The adaptive adjustment of the feature map helps the model better focus on the text area and reduce the influence of background noise and other non-text elements.

[0080] Specifically, the process of calculating the deviation between the original feature map and the predetermined morphological model to adjust the offset of the convolution kernel includes:

[0081] Comparing the original feature map with the template in the morphological model to obtain a comparison result;

[0082] The deviation between the original feature map and the template is analyzed and calculated according to the comparison result to adjust the offset.

[0083] Specifically, templates are defined within the morphological model. These templates represent patterns of different text features, such as lines, corners, and textures. The size of the templates is ensured to match the region in the original feature map to be compared. For each region in the original feature map, a sliding window comparison is performed using the templates. At each window position, the similarity between the template and the feature map region is calculated, using correlation coefficients, mutual information, or other similarity metrics. The comparison results for each window position are recorded to form a comparison result map, where each point represents the similarity between the template and the feature map. The comparison result map is analyzed to identify regions with low similarity, which may indicate deviations between the feature map and the template. The degree and direction of the deviations are determined, which can be achieved by calculating local gradients or using other image processing techniques. The resulting deviations are quantified into numerical values, which are used to adjust the offset of the convolution kernel. This deviation quantification can be a simple numerical mapping or a more complex regression analysis. The quantized deviation values ​​are mapped to adjustments to the convolution kernel offset. For example, if the deviation indicates that a text line in the feature map is shifted to the right, the convolution kernel offset is adjusted accordingly. Implementing offset adjustment in the neural network may involve generating dynamic convolution kernels or updating the parameters of existing convolution kernels in real time. Ensure that the adjusted convolution kernel can be correctly applied to the original feature map to capture the correct feature point locations.

[0084] Specifically, by comparing the original feature map with the template in the morphological model, key features in the original feature map can be more accurately identified and located, helping to improve the accuracy of the feature extraction stage of the OCR system. The convolution kernel offset is adjusted based on the comparison results, allowing the feature extraction process to adapt to different types of text features and layouts. Accurate feature matching and extraction directly impacts the subsequent classification and recognition stages, thereby improving the overall OCR recognition rate.

[0085] Specifically, the process of analyzing and calculating the deviation between the original feature map and the template according to the comparison result to adjust the offset includes:

[0086] Offset(x,y)=σ(Conv(Input,W offset )+Bias)

[0087] Among them, Offset(x,y) represents the offset that the convolution kernel needs to adjust at the position of coordinate (x,y) on the original feature map. The Sigmoid function is used to map the convolution result to a target range. Conv(Input,W_offset) is a convolution operation performed on the OCR image Input using the weight matrix W_offset to calculate the offset. Bias is a bias term used to adjust the baseline of the offset.

[0088] Specifically, the target range is typically -1 to 1. The sigmoid function makes the offset smoother and easier to control, and the bias ensures the offset's centrality and balance. During training, the weight matrix W_offset and the bias term Bias are updated via backpropagation. The goal is to minimize OCR recognition errors. Through multiple iterations, the model learns how to automatically adjust the convolution kernel's offset based on the characteristics of the input image.

[0089] Specifically, by fine-tuning the convolution kernel offset, the model can more accurately locate text features, thereby improving feature extraction accuracy. Text in images may exhibit various deformations, such as tilt and distortion. Dynamically adjusting the convolution kernel offset helps the model better adapt to these deformations and improve recognition rates.

[0090] Specifically, the process of adjusting the position of the feature point according to the offset includes:

[0091] P adjusted (x,y)=Interpolation(P,x+Scale factor Δx,y+Scale factor ·Δy)

[0092] Among them, P_adjusted(x,y) represents the adjusted feature point position to obtain more accurate character boundaries, Interpolation(P,x',y') is the interpolation calculation of the original feature map P, x' and y' are the new coordinates after offset adjustment, Scale_factor is the scale factor, deltax and deltay are the specific values ​​​​obtained from the offset calculation, indicating the horizontal and vertical adjustments that need to be made on the original coordinates (x,y).

[0093] Specifically, a scale factor is determined, which is used to control the degree of influence of the offset on the feature point position adjustment. The scale factor is usually a positive number less than 1 to avoid excessive adjustments. Using the offset formula calculated previously, the horizontal (Δx) and vertical (Δy) offsets are calculated for each feature point. For each feature point P(x,y) in the original feature map P, the adjusted coordinates (x',y') are calculated according to the following formula:

[0094] x'=x+Scale_factor*Δx; y'=y+Scale_factor*Δy.

[0095] Use interpolation methods (such as bilinear interpolation, bicubic interpolation, etc.) to calculate the value of the adjusted coordinate (x', y') on the original feature map P. This process can be expressed as:

[0096] P_adjusted(x,y)=Interpolation(P,x',y')

[0097] Bilinear interpolation steps: Determine the pixel grid where the adjusted coordinates (x', y') are located. Find the four adjacent pixels (i, j) in this pixel grid: the pixel at the upper left corner of the target coordinates. (i, j+1): the pixel at the upper right corner of the target coordinates. (i+1, j): the pixel at the lower left corner of the target coordinates. (i+1, j+1): the pixel at the lower right corner of the target coordinates. Where i and j are integers, representing the integer coordinates closest to x' and y', respectively.

[0098] Calculate the horizontal and vertical distances of the target coordinates (x', y') relative to its upper left corner pixel point (i, j), that is, the interpolation weights u and v:

[0099] u=x'-i;v=y'-j.

[0100] These weights represent the relative position of the target coordinates (x', y') within the pixel grid. Based on the interpolation weights and the values ​​of the adjacent pixels, the interpolation result is calculated:

[0101] P_adjusted(x',y')=(1-u)(1-v)P(i,j)+u(1-v)P(i,j+1)+(1-u)vP(i+1,j)+uvP(i+1,j+1)

[0102] This formula indicates that the interpolation result is obtained by weighted average of the values ​​of four adjacent pixels, where the weights (1-u) and (1-v) correspond to the horizontal and vertical distances within the pixel grid, respectively.

[0103] Specifically, by fine-grained adjustments to feature point positions, the model can more accurately locate character boundaries and key features, thereby improving feature extraction accuracy. In images with complex backgrounds or high noise levels, adjusting feature point positions allows the model to better focus on the text area and reduce background noise interference.

[0104] Specifically, if Figure 2 As shown, the process of step S3 includes:

[0105] Step S31, performing binarization and denoising processing on the OCR image to obtain a processed image;

[0106] Step S32, using edge detection to determine the edge of the processed image to obtain an edge result;

[0107] Step S33, performing expansion, erosion, opening and closing operations on the edge result to obtain an operation result;

[0108] Step S34, performing contour detection on the operation result to obtain a detection result;

[0109] Step S35, screening the text region according to the detection result and determining the area of ​​the text region, and determining the number of text pixels according to the processed image;

[0110] Step S36, calculating the ratio of the number of text pixels to the area of ​​the text region to obtain the text density;

[0111] Step S37, determining the character position based on the text area using vertical projection technology;

[0112] Step S38 : measuring the distances between adjacent characters according to the character positions to obtain distance results, and averaging all the distances to obtain the average spacing.

[0113] Specifically, the OCR image is read and converted into a grayscale image. A binarization algorithm, such as Otsu's method, is applied, and a threshold is selected to convert the grayscale image into a binary image. In a binary image, pixel values ​​are typically 0 (black) or 255 (white). Denoising of the binary image is performed using a median filter or a Gaussian filter to reduce noise introduced by scanning or photographing. A Gaussian filter is used to smooth the image to remove noise. The gradient magnitude and direction of each pixel in the image are calculated. Non-maximum suppression is applied to refine edges. Real and potential edges are determined using a double threshold. Edges are identified using edge tracking and hysteresis thresholding. A dilation operation is performed on the edge image using a structuring element to connect adjacent edges. An erosion operation is performed on the edge image using a structuring element to remove small noise points. Erosion followed by dilation removes small objects and smoothes the boundaries of larger objects. Erosion followed by erosion fills small holes or breaks and connects close objects. Contours are found in the morphologically processed image using the OpenCV findContours function. A contour is a continuous sequence of points, each with the same color or intensity. Filter out the outer contours and ignore the inner hole contours. Filter out the text areas based on the contour area, aspect ratio, shape and other features. Use the contourArea function to calculate the area of ​​each filtered contour. Iterate over each pixel in the binary image: if the pixel belongs to the text area (usually a white pixel), count it. Accumulate the total number of text pixels. Calculate the text density using the following formula:

[0114] Text density = number of text pixels / total area of ​​text area.

[0115] Perform a vertical projection on each text line and count the number of white pixels in each column. Peaks in the projection typically correspond to character locations. Based on the vertical projection results, determine the start and end positions of the characters. Calculate the distance between the centers of adjacent characters. Average the distances between all adjacent characters to obtain the average spacing.

[0116] Specifically, binarization and denoising reduce noise and interference in the image, improving image clarity. Binarization and denoising reduce noise and interference in the image, improving image clarity. Measuring the distance between adjacent characters and calculating the average spacing provides the model with important information about text layout, helping to improve the model's adaptability to changes in text spacing. Measuring the distance between adjacent characters and calculating the average spacing provides the model with important information about text layout, helping to improve the model's adaptability to changes in text spacing.

[0117] Specifically, the process of calculating the receptive field size according to the text density includes:

[0118] R dynamic =α·log(1+Density measure (P))·R initial

[0119] Among them, R_dynamic represents the size of the receptive field after dynamic adjustment, Alpha represents the adjustment coefficient, log(1+Density_measure(P)) represents the conversion of text density into a slowly growing logarithmic scale, Density_measure(P) represents the text density measurement function, and R_initial represents the initial receptive field size.

[0120] Specifically, the initial receptive field size (R_initial) is determined. This is the default receptive field size used by the model when no density information is available. The adjustment factor (α) is determined. This is a preset factor used to balance the magnitude of changes in the receptive field size, ensuring that the adjustment does not excessively affect other parts of the image. The measured text density values ​​are substituted into a logarithmic function to convert it to a slowly increasing logarithmic scale. This ensures that the adjustment of the receptive field size is smooth and gradual even with large changes in text density. The calculation formula is: log(1 + Density_measure(P)). The 1 here ensures that the logarithmic function remains defined when Density_measure(P) is 0 and avoids the undefined logarithmic function problem. The adjustment factor, the text density conversion result, and the initial receptive field size are combined to obtain a receptive field size adjusted for the current text density. The calculated R_dynamic is applied to the convolutional layer in the neural network to adjust its receptive field size. This can be achieved by changing the kernel size, stride, or using different kernel sizes.

[0121] Specifically, in areas with dense text, the system reduces the size of the receptive field. This is because in areas with dense characters, a smaller receptive field can more accurately capture the details of individual characters and avoid interference from adjacent characters. In areas with sparse text, the system increases the size of the receptive field. A larger receptive field helps the system capture more background information, which is particularly important for understanding the context of characters and improving character recognition accuracy.

[0122] Specifically, by adjusting the receptive field size based on text density, the model is able to more accurately capture the features of text of varying densities, thereby improving recognition accuracy, especially in areas with dense or sparse text. Dynamic receptive fields help the model learn more general and robust features, rather than simply adapting to the specific text density in the training data, thereby reducing the risk of overfitting. Using smaller receptive fields in areas with sparse text can reduce unnecessary computation, while using larger receptive fields in areas with dense text can better capture complex features, thereby improving overall computational efficiency.

[0123] Specifically, the process of adjusting the receptive field shape according to the average spacing includes:

[0124] If the character spacing is uniform, use a rectangular or square receptive field;

[0125] If the character spacing is uneven, use an elliptical or adaptive receptive field;

[0126] For a specific font or typography style, the shape of the receptive field is customized according to its characteristics.

[0127] Specifically, use the previously calculated average inter-character spacing to analyze the uniformity of character spacing. Spacing uniformity can be assessed by calculating the standard deviation or coefficient of variation of character spacing. Set a threshold to determine whether character spacing is uniform. If the standard deviation or coefficient of variation is less than the threshold, the character spacing is considered uniform; otherwise, it is considered uneven. If the character spacing is uniform, select a rectangular or square receptive field. A rectangular receptive field is suitable for situations where character heights and widths vary significantly, while a square receptive field is suitable for situations where character sizes are relatively consistent. Adjust the size of the receptive field to match the size of the characters. If the character spacing is uneven: Use an elliptical receptive field, whose long axis can better adapt to variations in character spacing. Alternatively, use an adaptive receptive field, whose shape dynamically adjusts to the actual shape and spacing of the characters. Analyze the characteristics of a specific font or typesetting style, such as font width, slant, and decorativeness. Design a customized receptive field shape based on these characteristics. For example, for slanted fonts, a parallelogram receptive field can be used. For fonts with more decorative elements, a more complex polygonal receptive field can be used. Parameterize the shape of the receptive field. For example, for an ellipse, this can be parameterized into the major axis, minor axis, and rotation angle. Develop an algorithm to adjust the receptive field based on the parameterized shape. The algorithm may include the following steps: Select a base shape (rectangle, square, ellipse, or custom shape) based on the results of character spacing analysis. Adjust the shape parameters based on character characteristics (such as size, spacing, and tilt). Apply the shape parameters to the convolution kernel to form the final receptive field.

[0128] Specifically, by using a receptive field shape that matches the spacing between characters, the model is able to more accurately segment adjacent characters, especially when the spacing between characters is uniform or uneven. In the case of uneven character spacing, using an elliptical or adaptively shaped receptive field can reduce misrecognition caused by varying character spacing. By using a receptive field that is more appropriate for character spacing and shape, unnecessary computation can be reduced, thereby speeding up the recognition process.

[0129] Specifically, if Figure 3 As shown, the process of step S5 includes:

[0130] Step S51, generating a corresponding convolution kernel according to the receptive field size and the receptive field shape;

[0131] Step S52, traversing the position of the original feature map with the convolution kernel;

[0132] Step S53, calculating the dot product of the convolution kernel and the local area in the original feature map according to each position, and adding the bias top to the dot product to obtain the element of the target feature map;

[0133] Step S54: activating and pooling the elements of the target feature map to obtain the target feature map.

[0134] Specifically, the size and shape of the convolution kernel are determined based on the calculated dynamic receptive field size and shape. The convolution kernel weights are randomly initialized or pre-trained. If necessary, the convolution kernel weights are further adjusted based on text density or character spacing to ensure that they effectively capture text features. An appropriate stride is selected to traverse the original feature map; the stride determines the distance the convolution kernel moves on the feature map. The convolution kernel is placed at the starting position of the original feature map. For the local area of ​​the original feature map covered by the convolution kernel, the dot product between the convolution kernel weights and the corresponding elements of the feature map is calculated. A bias term is added to the calculated dot product result. The bias term is a learnable parameter used to adjust the activation level of the output feature map. The result of the dot product plus the bias term is passed through a nonlinear activation function, such as ReLU, Sigmoid, or Tanh, to introduce nonlinear factors and enhance the expressive power of the model. Max pooling, average pooling, or other pooling methods can be selected as needed. A pooling operation is applied to the activated feature map to reduce the size of the feature map while retaining the most important information. The activated and pooled feature map elements are aggregated to form the target feature map.

[0135] Specifically, by designing an appropriate receptive field size and shape, the convolution kernel can efficiently extract key features from the image, improving the efficiency of feature extraction. By calculating the dot product between the convolution kernel and the original feature map and combining it with a bias term, the model can learn a richer and more representative feature representation, which helps improve recognition accuracy. The introduction of the activation function adds nonlinear characteristics to the feature map, allowing the model to capture more complex patterns and relationships, enhancing the model's generalization ability. The pooling operation reduces the spatial size of the feature map, reducing the computational complexity of the model while retaining the most important feature information, helping to prevent overfitting.

[0136] Specifically, if Figure 4 As shown, the process of step S6 includes:

[0137] Step S61, dividing the historical data into a training set and a validation set;

[0138] Step S62, initializing loss weights lambda1 and lambda2 to balance classification loss and regression loss;

[0139] Step S63, defining the weighted sum of the classification loss and the regression loss as the total loss;

[0140] Step S64, training the neural network model according to the training set to calculate the total loss;

[0141] Step S65, updating the weights of the neural network model using gradient descent according to the total loss to obtain a target weight;

[0142] Step S66: Verify the neural network model according to the target weight and the verification set to obtain the target OCR recognition model.

[0143] Specifically, a large amount of OCR recognition historical data is collected, including images and corresponding correct text labels. The historical data is divided into two main parts using a random partitioning method: a training set and a validation set. Typically, the training set accounts for 80%-90% of the total data, while the validation set accounts for the rest. Initialize two loss weights lambda1 and lambda2. These weights are used to balance the importance of classification loss and regression loss during training. For example, lambda1 can be set to 1 and lambda2 can be set to 0.5. The specific values ​​need to be adjusted according to the specific requirements of the task and experimental results. For each batch in the training set, forward propagation is performed through the network to calculate the predicted value. The classification loss Lcls and regression loss Lreg are calculated based on the predicted value and the actual label. Calculate the total loss for the current batch. Backpropagate the calculated total loss to calculate the gradient of the loss relative to the network parameters. Use a gradient descent algorithm (such as stochastic gradient descent SGD, Adam, etc.) to update the weights of the network based on the calculated gradient. This process can be expressed as:

[0144] weights=weights-learning_rate*gradient

[0145] Where weights represents the weights of the neural network, learning_rate represents the learning rate, and gradient represents the gradient. The model's performance is evaluated on the validation set, and the total loss and other relevant performance metrics (such as accuracy and F1 score) are calculated. Based on the performance feedback on the validation set, hyperparameters such as loss weights and learning rate are adjusted to optimize the model. The model weights that perform best on the validation set are selected as the final target weights for building the target OCR recognition model.

[0146] Specifically, by dividing the data into training and validation sets, the model can verify its performance on independent data, which helps improve the model's generalization ability and reduce overfitting. By defining the total loss as the weighted sum of classification loss and regression loss, the model can simultaneously focus on both text classification and position regression tasks, thereby optimizing overall performance. Using the gradient descent algorithm to update the model weights based on the total loss can effectively optimize model parameters and reduce recognition errors. By transforming the complex optimization problem into a total loss minimization problem, the training process is simplified, making model training more efficient.

[0147] Specifically, the process of training the neural network model according to the training set to calculate the total loss includes:

[0148] Loss total =λ1·L cls (SOftmax(Output cls ))+λ2·L reg (SmoothL1(Output reg ))

[0149] Among them, Los_total represents the total loss, L_cls represents the classification loss function, Softmax(Output_cls) represents the conversion of the original output of the classification task into a probability distribution through the Softmax function, L_reg represents the regression loss function, SmoothL1(Output_reg) represents the application of SmoothL1 loss to the output of the regression task, lambda1 and lambda2 are loss weights used to adjust the classification loss and regression loss.

[0150] Specifically, by simultaneously optimizing classification and regression losses, the model can more comprehensively learn data features, thereby accurately predicting the location of text while identifying the text category. This is particularly important in OCR applications. By combining classification and regression tasks in a single overall loss function, end-to-end training can be achieved, simplifying the training process and potentially improving training efficiency.

[0151] Thus far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art may make equivalent changes or substitutions to the relevant technical features, and the technical solutions after such changes or substitutions will fall within the scope of protection of the present invention.

[0152] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that the present invention is susceptible to various modifications and variations. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be within the scope of protection of the present invention.

Claims

1. An OCR recognition method based on adaptive mapping and perceptual adjustment, characterized in that: include: Step S1, obtaining an OCR image to be processed, extracting features of the OCR image using a neural network model to obtain an original feature map, and also obtaining historical OCR images as historical data; Step S2, calculating the deviation between the original feature map and the predefined morphological model to adjust the offset of the convolution kernel, and adjusting the position of the feature point according to the offset; Step S3, obtaining the text area of ​​the OCR image, and calculating the text density and the average spacing between characters according to each text area; Step S4, calculating the receptive field size according to the text density, and adjusting the receptive field shape according to the average spacing; Step S5, convolving the original feature map according to the receptive field size and the receptive field shape to obtain a target feature map; Step S6: training the neural network model according to the target feature map, the text density and the average spacing to obtain a target OCR recognition model.

2. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 1, characterized in that: The process of calculating the deviation between the original feature map and the predetermined morphological model to adjust the offset of the convolution kernel includes: Comparing the original feature map with the template in the morphological model to obtain a comparison result; The deviation between the original feature map and the template is analyzed and calculated according to the comparison result to adjust the offset.

3. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 2, characterized in that: The process of analyzing and calculating the deviation between the original feature map and the template according to the comparison result to adjust the offset includes: Offset(x,y)=σ(Conv(Input,W offset )+Bias) Among them, Offset(x,y) represents the offset that the convolution kernel needs to adjust at the position of coordinate (x,y) on the original feature map. The Sigmoid function is used to map the convolution result to a target range. Conv(Input,W_offset) is a convolution operation performed on the OCR image Input using the weight matrix W_offset to calculate the offset. Bias is a bias term used to adjust the baseline of the offset.

4. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 3, characterized in that: The process of adjusting the position of the feature point according to the offset includes: P adjusted (x,y)=Interpolation(P,x+Scale factor Δx,y+Scale factor ·Δy) where P_adjusted(x,y) represents the adjusted feature point position to obtain more accurate character boundaries, Interpolation(P,x',y') is the interpolation calculation of the original feature map P, x' and y' are the new coordinates after offset adjustment, Scale_factor is the scale factor, deltax and deltay are the specific values ​​obtained from the offset calculation, indicating the horizontal and vertical adjustments that need to be made to the original coordinates (x,y).

5. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 4, characterized in that: The process of step S3 includes: performing binarization and denoising processing on the OCR image to obtain a processed image; determining the edge of the processed image using edge detection to obtain an edge result; Performing dilation, erosion, opening and closing operations on the edge result to obtain an operation result; Performing contour detection on the operation result to obtain a detection result; Filter the text region according to the detection result and determine the area of ​​the text region; determining the number of text pixels based on the processed image; The ratio of the number of text pixels to the area of ​​the text region to obtain the text density; Determining character positions based on the text area using a vertical projection technique; The distances between adjacent characters are measured according to the character positions to obtain distance results, and all the distances are averaged to obtain the average spacing.

6. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 5, characterized in that: The process of calculating the receptive field size according to the text density includes: R dynamic =α·log(1+Density measure (P))·R initial Among them, R_dynamic represents the size of the receptive field after dynamic adjustment, Alpha represents the adjustment coefficient, log(1+Density_measure(P)) represents the conversion of text density into a slowly growing logarithmic scale, Density_measure(P) represents the text density measurement function, and R_initial represents the initial receptive field size.

7. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 6, characterized in that: The process of adjusting the shape of the receptive field according to the average spacing includes: If the character spacing is uniform, use a rectangular or square receptive field; If the character spacing is uneven, use an elliptical or adaptive receptive field; For a specific font or typography style, the shape of the receptive field is customized according to its characteristics.

8. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 7, characterized in that: The process of step S5 includes: Generate a corresponding convolution kernel according to the receptive field size and the receptive field shape; Traversing the convolution kernel over the position of the original feature map; Calculating the dot product of the convolution kernel and the local area in the original feature map according to each of the positions, and adding the bias top to the dot product to obtain the element of the target feature map; The elements of the target feature map are activated and pooled to obtain the target feature map.

9. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 8, characterized in that: The process of step S6 includes: Dividing the historical data into a training set and a validation set; Initialize loss weights lambda1 and lambda2 to balance classification loss and regression loss; The weighted sum of the classification loss and the regression loss is defined as the total loss; Training the neural network model according to the training set to calculate the total loss; Updating the weights of the neural network model using gradient descent according to the total loss to obtain target weights; The neural network model is verified according to the target weight and the verification set to obtain the target OCR recognition model.

10. The OCR recognition method based on adaptive mapping and perceptual adjustment according to claim 9, characterized in that: The process of training the neural network model according to the training set to calculate the total loss includes: Loss total =λ1·L cls (Softmax(Output cls ))+λ2·L reg (SmoothL1(Output reg )) Among them, Los_total represents the total loss, L_cls represents the classification loss function, Softmax(Output_cls) represents the conversion of the original output of the classification task into a probability distribution through the Softmax function, L_reg represents the regression loss function, SmoothL1(Output_reg) represents the application of SmoothL1 loss to the output of the regression task, lambda1 and lambda2 are loss weights used to adjust the classification loss and regression loss.

Citation Information

Patent Citations

  • OCR-based image analysis method, system and device, and medium

    CN111539412A

  • Text region determination method and device, electronic equipment and storage medium

    CN118887677A

Cited By

  • Table picture OCR (Optical Character Recognition) method and tool by utilizing Excel template

    CN121505625A