Image text recognition method, device, computer equipment and storage medium
By globally optimizing the image and combining it with a convolutional neural network and a long-short-term memory network, the problem of inaccurate recognition caused by image blur and tilt and data diversity is solved, and the accuracy and efficiency of image text recognition are improved.
Patent Information
- Application Number
- CN201811599852.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-12-26
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2038-12-26
AI Technical Summary
In the existing technology, in image text recognition, the recognition is inaccurate due to image blur and tilt and the diversity of neural network model training data, which limits the performance and accuracy of the recognition system.
Through global optimization of the original image, including binarization, denoising and correction, a clearer and more standardized target image is generated, and a convolutional neural network and a long short-term memory neural network are combined for feature extraction and classification, using preset semantics The library accurately recognizes text.
It improves the accuracy and efficiency of image text recognition, reduces the difference in learning time of the recognition system, and enhances the recognition effect.
Smart Images

Figure CN109766898B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to an image text recognition method, device, computer equipment and storage medium. Background Art
[0002] In daily life, there are many times when we need to extract text content from images, such as identifying text information on images and converting it into editable text patterns. In most cases, neural network machine learning algorithms are used to recognize characters, and the characters on the image are recognized through trained neural network models.
[0003] However, in most cases, images carrying character information have problems such as blur and tilt, which will affect the clarity of the character information and limit the recognition effect; and in the neural network model, due to the diversity of the data set for training the neural network model, it will cause time differences in the learning of the neural network model, and there will be inaccurate recognition, which will greatly limit the performance of the recognition system, resulting in low recognition accuracy and unsatisfactory recognition effect. Summary of the invention
[0004] The embodiments of the present invention provide an image text recognition method, an apparatus, a computer device and a storage medium, which can improve the accuracy of image text recognition.
[0005] A method for image text recognition, comprising:
[0006] Acquire an original image, wherein the original image contains text to be recognized;
[0007] Performing global optimization processing on the original image to obtain a target image;
[0008] Inputting the target image into a convolutional neural network model to extract features, thereby obtaining a feature array of the target image;
[0009] Inputting the feature array of the target image into the long short-term memory neural network model, setting function parameters for image classification, classifying the target image, and obtaining a target classification result;
[0010] The recognition result of the target image is determined according to the target classification result, and a preset semantic library is queried based on the recognition result corresponding to the target image to obtain the target text corresponding to the to-be-recognized text.
[0011] An image character recognition device, comprising:
[0012] Acquire an original image, wherein the original image contains text to be recognized;
[0013] Performing global optimization processing on the original image to obtain a target image;
[0014] Inputting the target image into a convolutional neural network model to extract features, thereby obtaining a feature array of the target image;
[0015] Inputting the feature array of the target image into the long short-term memory neural network model, setting function parameters for image classification, classifying the target image, and obtaining a target classification result;
[0016] The recognition result of the target image is determined according to the target classification result, and a preset semantic library is queried based on the recognition result corresponding to the target image to obtain the target text corresponding to the to-be-recognized text.
[0017] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned image text recognition method when executing the computer program.
[0018] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned image text recognition method are implemented.
[0019] In the above-mentioned image text recognition method, device, computer equipment and storage medium, the target image is made clearer and more standardized by globally optimizing the original image, which is convenient for identifying and extracting the text to be identified; the feature of the target image is extracted by using a convolutional neural network model, and then the target image is classified by setting the functional parameters for image classification using a long short-term memory neural network model, so that the recognition of the target image is more accurate, the accuracy of image text recognition is improved, and the recognition efficiency is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0021] Figure 1 is a schematic diagram of an application environment of an image character recognition method in one embodiment of the present invention;
[0022] Figure 2 is a flow chart of an implementation of an image text recognition method provided in an embodiment of the present invention;
[0023] Figure 3is another implementation flow chart of the image text recognition method provided in an embodiment of the present invention;
[0024] Figure 4 is another implementation flow chart of the image text recognition method provided in an embodiment of the present invention;
[0025] Figure 5 is another implementation flow chart of the image text recognition method provided in an embodiment of the present invention;
[0026] Figure 6 is a schematic diagram of an image character recognition device in one embodiment of the present invention;
[0027] Figure 7 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] The image text recognition method provided by this application can be applied to Figure 1 In the application environment, the client communicates with the server through the network, the user uploads the original image through the client, and the server obtains the original image to perform text recognition on the original image. The client can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server can be implemented with an independent server or a server cluster consisting of multiple servers.
[0030] Figure 2 FIG. 2 is a flow chart of the image text recognition method in this embodiment. The image text recognition method is applied in the server to recognize text in the image and improve the accuracy of image text recognition. Figure 2 As shown, the image text recognition method includes the following steps:
[0031] S10: Acquire an original image, where the original image contains text to be recognized.
[0032] The original image refers to the image used for text recognition, and the text to be recognized refers to the text in the original image.
[0033] Specifically, the source of the original image can be diversified, which can be an image obtained from the Internet, an image taken by a user through a client, or an image frame of a moving object taken by a camera. The server transmits the image through an interface. The server obtains the original image by obtaining an image uploaded by a user from a client, or by specifying an image stored on the server or an image on the Internet as the original image.
[0034] S20: Perform global optimization processing on the original image to obtain a target image.
[0035] The target image refers to an image that is global optimized and is convenient for text recognition. Optionally, the text to be recognized is highlighted in the target image.
[0036] Specifically, the acquired original image will contain various background information, and the image quality is also uneven. Since the original image is acquired from various sources, the original image also contains various noises that affect the quality and clarity of the original image, and the position of the text to be recognized in the original image may be irregular, that is, the image may be distorted or tilted. Global optimization processing of the original image can include binarizing the acquired original image to reduce the complexity and information processing amount of the target image to highlight the text to be recognized in the target image; denoising the original image to improve the quality and clarity of the target image; and correcting the original image to make the target image more standardized. The target image after global optimization processing removes the complex background and contains a highlighted and standardized part of the text to be recognized.
[0037] Preferably, the binarization grayscale processing, denoising processing and correction processing in the global optimization processing are not limited in processing order and steps, and can be selected according to the actual situation of the original image. For example, if the position of the text to be recognized in the original image is originally standardized, the correction processing steps can be reduced.
[0038] S30: Input the target image into the convolutional neural network model for feature extraction to obtain a feature array of the target image.
[0039] Among them, the convolutional neural network model is a feature extraction model pre-trained based on the convolutional neural network. Convolutional Neural Network (CNN) is a feedforward neural network whose artificial neurons can respond to surrounding units within a part of the coverage range. It is used for large-scale image processing and is mainly used to identify two-dimensional graphics that are invariant to displacement, scaling and other forms of distortion. The convolutional neural network model has unique advantages in speech recognition and image processing due to its special structure of local weight sharing. The feature array is a data matrix of features in the target image, that is, the prominent features in the target image are represented in the form of a data matrix.
[0040] Specifically, the feature detection layer of the CNN model is learned through training data, so that when the CNN model detects the input target image, it extracts the features of the target image through feature detection to obtain the feature array of the target image. Furthermore, the weight sharing of the CNN model reduces the complexity of the network. For images with multi-dimensional input vectors, they can be directly input into the network, avoiding the complexity of data reconstruction in feature extraction.
[0041] S40: Inputting the feature array of the target image into the long short-term memory neural network model, setting function parameters for image classification, classifying the target image, and obtaining the target classification result.
[0042] Among them, the long short-term memory neural network model is a feature classification model pre-trained based on the long short-term memory neural network. The long short-term memory neural network is also called the recursive neural network (Long Short-Term Memory, referred to as LSTM). The LSTM model is a time recursive neural network model with time memory function. It is suitable for processing and predicting events with time series states, and can handle important events with relatively long time series intervals and delays. The functional parameters that can achieve accurate image classification refer to the parameters used to classify images in the LSTM model. Different functional parameters in the LSTM model can affect the image classification results. Setting the functional parameters for image classification can help the LSTM model to classify more accurately. The target classification result is the result of the classification probability of the text to be recognized after the target image is classified in the LSTM model.
[0043] Specifically, since many characters have similar characters with similar strokes, during the recognition process, the feature array of the target image is used to classify the characters to be recognized in the trained LSTM model, and the characters to be recognized are classified into their similar characters. After classification, the probability that the characters to be recognized in the target image correspond to their similar characters is set, and the function parameters for image classification are set to increase the probability of accurate classification of the characters to be recognized.
[0044] For example, the text to be recognized is "X Yang". According to the function parameters set to enable accurate image classification, after classification, the probability that "X" is the character "Tai" is 80%, the probability that it is the character "Da" is 15%, and the probability that it is the character "Tian" is 5%. The probability of similar characters is the classification result of the target image. The classification result with the highest probability in the classification results is selected as the target classification result. Further, the feature array of the target image is input into the LSTM model. The LSTM model controls the degree to which the feature array is forgotten by setting the parameters of the forget gate, controls the newly added feature array through the input gate and a tanh function, and controls how much new information is added through the output gate to filter the feature array. Based on the filtered feature array, the target image is classified to obtain the target classification result.
[0045] S50: Determine the recognition result of the target image according to the target classification result, and query the preset semantic library based on the recognition result corresponding to the target image to obtain the target text corresponding to the text to be recognized.
[0046] Among them, the recognition result refers to the maximum probability that the target image is recognized determined according to the target classification result. The preset semantic library refers to a word library that is preset based on the description of the semantic relationship between Chinese words by word frequency.
[0047] Specifically, determine the maximum probability that the target image is recognized according to the target classification result, that is, the recognition result of the target image. Based on the maximum probability of recognition corresponding to the target image, query the preset semantic library, and calculate the probability of the semantics corresponding to the target image according to the common semantic relationship in the semantic library. Take the maximum recognized probability as the recognition result. For example, for a text, the characters in the text are in a sequential order, such as "Hong X Yang". For the character "X", its meaning cannot be simply known, but by combining the pre-order semantics and post-order semantics of the entire text "Hong X Yang", the probability that the classification result of the word "X Yang" is "Taiyang" is 80%, and the probability that it is "Jiaoyang" is 20%. Determine that the maximum recognition probability is 80% for "Taiyang". Then, based on this recognition result, query the preset semantic library. If there are words in the semantic library that contain the semantic relationship of "Hongtaiyang", the target text corresponding to the text to be recognized can be accurately obtained.
[0048] In this embodiment, the original image is globally optimized to reduce the complexity and information processing of the target image, so that the target image is more standardized; the CNN model is used to extract features from the target image, and the weight sharing of the CNN model reduces the complexity of the network. The image of the multi-dimensional input vector can be directly input into the network, avoiding the complexity of data reconstruction in feature extraction; the LSTM model is used to classify the template image, and the difference in system learning time can be reduced based on the long-term memory ability of the LSTM model and the function of recognizing the time sequence state. The target text corresponding to the Chinese character to be recognized is obtained by combining the recognition results and the preset semantic library, which improves the recognition accuracy and further improves the accuracy of image text recognition.
[0049] In one embodiment, performing global optimization processing on the original image to obtain the target image specifically includes the following steps:
[0050] The original image is binarized to obtain a secondary processed image. The image binarization process refers to setting the grayscale value of the pixel on the image to 0 or 255, that is, the entire image presents an obvious black and white effect. The secondary processed image refers to the image after the binarization process.
[0051] Specifically, the original image is binarized to obtain a secondary processed image, including the following steps:
[0052] (1) Grayscale the original image to obtain the original grayscale image. Grayscale the original image means that the color image presents an obvious black and white effect. The color of each pixel in the color image is determined by the three components of R (red), G (green), and B (blue), and each component has 256 possible values (0 is the darkest and 255 is the brightest, which means white). Thus, a pixel can have a color range of more than 16 million (255*255*255). The grayscale image is a special color image with the same R, G, and B components and 256 brightness levels.
[0053] In one solution, the average value of the three components R, G, and B of each pixel is calculated, and then the average value is assigned to the three components of the pixel.
[0054] In another scheme, the calculation is performed according to the weighted average algorithm of YUV (a color encoding method adopted by the European television system). Among them, Y represents brightness (Luminance or Luma), that is, the grayscale value; while U and V represent chrominance (Chrominance or Chroma), which is used to describe the color and saturation of the image and is used to specify the color of the pixel. According to the change relationship between RGB and YUV color space, the correspondence between brightness Y and the three color components R, G, and B can be established: Y = 0.3R + 0.59G + 0.11B, and this brightness value is used to express the grayscale value of the image.
[0055] Grayscale processing is performed on the original image to obtain the original grayscale image, which can facilitate subsequent processing of the original grayscale image and reduce the complexity of the image and the amount of information processing.
[0056] (2) Binarize the original grayscale image to obtain a secondary processed image. The grayscale image with 256 brightness levels is selected by a preset threshold to obtain a binary image that can reflect the overall and local features of the image. The original image is converted into an m×n grayscale image, where m and n are the height and width of the image, that is, it is transformed into a two-dimensional grayscale matrix. The preset threshold is the grayscale resolution of the naked eye, 40.
[0057] The secondary processed image is subjected to noise removal to obtain a tertiary processed image. Specifically, the main noises in the image generally include: Gaussian noise, Rayleigh noise, gamma noise, salt and pepper noise, etc. Therefore, in this solution, the image to be identified needs to be denoised. Specifically, the median filter algorithm can be used to remove noise from the image.
[0058] Furthermore, the median filter is a nonlinear smoothing technique that sets the grayscale value of each pixel to the median of the grayscale values of all pixels in a certain neighborhood window of the point. Median filtering is a nonlinear signal processing technique based on sorting statistics theory that can effectively suppress noise. The basic principle of median filtering is to replace the value of a point in a digital image or digital sequence with the median of the values of each point in a neighborhood of the point, so that the surrounding pixel values are close to the true value, thereby eliminating isolated noise points. The method is to use a two-dimensional sliding template of a certain structure to sort the pixels in the board according to the size of the pixel value, and generate a monotonically rising (or falling) two-dimensional data sequence.
[0059] The median filter method is used to denoise the secondary processed image, and the grayscale value of each pixel of the secondary processed image is set to the median value of all pixels in its neighborhood window. Taking each pixel as the center pixel in turn means that in a given area, each pixel in the area is taken as the center pixel. For example, there are 15 pixels in the area, and these 15 pixels are taken as center pixels in turn, so there are 15 center pixels. When the boundary pixel is taken as the center pixel, the boundary pixel can be regarded as the center pixel by expanding the pixel, that is, the grayscale value of the pixel that does not exist in the neighborhood of the boundary pixel is set to be equal to the grayscale value of the boundary pixel. For example, the matrix of an image is:
[0060]
[0061] Among them, the grayscale value of the pixel in the first row and the first column is 22, and there are no pixels on its left and above. Therefore, when calculating the contrast, the grayscale values of the pixels on its left and above are set to the same grayscale values as the boundary pixels, that is, the grayscale values of the left and above are both 22.
[0062] In another solution, other methods may be used to denoise the secondary processed image, such as mean filtering algorithm, median filtering, Wiener filtering, etc., which are not specifically limited.
[0063] The three-level processed image is subjected to tilt correction processing to obtain the target image. Among them, the position of the text to be recognized in the original image may be irregular, that is, the image may be distorted or tilted. In order to standardize the obtained target image, the three-level processed image needs to be corrected.
[0064] Specifically, the three-level processed image is subjected to tilt correction processing to obtain the target image, which includes the following steps: (1) reading the original image height and width of the three-level processed image, dilating the three-level processed image, and connecting the discontinuous text into a straight line. The dilation operation is to convolve the image or a part of the image with the element structure to find the local maximum value. The element structure is convolved with the image, that is, the maximum value of the pixel points in the area covered by the element structure is calculated, and the maximum value is assigned to the pixel specified by the reference point, so that the highlight area in the image gradually increases. The processing process is to scan each pixel of the image with the structural element, and perform an "and" operation with the structural element and the binary image covered by it. If both are 0, the pixel of the image is 0, otherwise it is 1. The maximum value of the pixel points in the area covered by the element structure is calculated, and the maximum value is assigned to the pixel specified by the reference point. The dilation amplitude is set, and the image is dilated in the horizontal direction respectively. After the horizontal dilation, the vertical dilation is performed to connect the discontinuous text into a whole image, for example, a paragraph of text is connected into a straight line.
[0065] (2) Perform edge detection on the expanded image. The pixels of the expanded image are covered by the maximum value, and the text part is clearly distinguished from the blank background part. For a grayscale binary image, if the pixel value of the image is 1, the state of the pixel is on; if the pixel value is 0, the state of the pixel is off. In an image, if a pixel of the image meets the following two conditions: 1. The pixel state is on; 2. One or more pixels in the neighborhood of the pixel are off, then the pixel can be determined to be an edge pixel, and the difference between the edge pixel and the pixel neighborhood is used to detect its edge point.
[0066] (3) Perform Hough transform on the edge points to find the angle of the longest line segment. Hough transform is a feature detection technology used to identify features in an object. Compared with other methods, the method of finding straight lines and circles by Hough transform can better reduce noise interference. Specifically, based on the height and width of the expanded image, the edge points after edge detection are subjected to Hough transform, and the corresponding repeated points in the transform domain are accumulated. Based on the diagonal distance of the image, the longest straight line is found as an intermediate variable for comparison, and the longest straight line angle kmax is recorded, and the longest straight line distance pmax is recorded.
[0067] (4) Use the rotation function to rotate the image to obtain the target image. The longest straight line angle kmax of the image represents the tilt angle of the image, so the angle to which it should be rotated to correct it to the standard image is also kmax. The rotation function uses the RotateDIB(img, kmax) function. RotateDIB is a rotation function, img stores the original image data, and kmax is the rotation angle. Get the position coordinates of the original image, set the rotation angle to the longest straight line angle kmax, rotate the original image, and obtain the corrected target image.
[0068] In this embodiment, by performing binarization, noise removal and tilt correction processing on the original image, the quality of the image to be processed can be improved, including enhancing image contrast, retaining image details and removing noise, etc., which can reduce the complexity and information processing amount of the original image and improve the clarity of the original image, thereby making the details of the target image clearer, making the target image more standardized and easy to identify, and providing a certain guarantee for ensuring subsequent image and text recognition.
[0069] In one embodiment, if Figure 3 As shown, in step S30, the target image is input into the convolutional neural network model for feature extraction to obtain a feature array of the target image, which specifically includes the following steps:
[0070] S31: Get the image array of the target image.
[0071] Specifically, each pixel of the target image is traversed to obtain the RGB image data of each pixel, the image data is read in binary mode to store the image data in a two-dimensional array, and the image dot matrix is saved in the two-dimensional array to obtain an image array.
[0072] S32: Input the image array of the target image into the convolutional neural network model, perform feature extraction on the target image based on the convolution and pooling operations of the convolutional neural network model, and obtain a feature array of the target image.
[0073] Among them, Convolutional Neural Network (CNN) is a feedforward neural network whose artificial neurons can respond to surrounding units within a certain coverage area and can perform image processing and recognition. The main difference between Convolutional Neural Networks and general Deep Neural Networks (DNN) is that Convolutional Neural Networks include convolution layers and pooling layers, which provide important technical support for Convolutional Neural Networks to process and recognize images with text.
[0074] Specifically, the image array of the target image is input into the convolutional neural network model, and the feature map is obtained by calculating the dot product with the image array through the feature detector. By modifying the value of the feature detector before the convolution operation, different features can be detected from the image. The convolution layer of the convolutional neural network model extracts the features of the target image from the input image array and can preserve the spatial relationship between pixels. After the convolution operation, the rectified linear unit (ReLU) is used for operation. ReLU is a nonlinear, element-level operation that can be applied to each pixel and sets all pixel values less than 0 in the feature map to zero. The purpose of the ReLU operation is to introduce nonlinearity. Since convolution is a linear operation, it is necessary to introduce nonlinearity by using the nonlinear function ReLU. After the ReLU operation, the corrected feature map is obtained. Then the pooling operation is performed. The pooling operation is also called spatial pooling, which can reduce the dimension of each feature map but keep most of the important information. The pooling operation can include spatial maximum pooling or average pooling. This embodiment adopts the maximum pooling method. First, a spatial neighborhood (for example, a 2x2 window) is defined, and maximum pooling is used in the corrected feature map with a step size of 2x2. The largest element is taken from the corrected feature map in the window to extract useful features from the image array as the feature array of the target image.
[0075] In this embodiment, an image array of a target image is obtained and processed through a convolutional neural network model, so that useful features can be extracted from the target image, and a nonlinear function is introduced in the convolution operation to reduce the feature dimension while keeping these features invariant to a certain degree of scale change.
[0076] In one embodiment, in step S40, Figure 4 As shown, the feature array of the target image is input into the long short-term memory neural network model, the function parameters for image classification are set, the target image is classified, and the target classification result is obtained, which specifically includes the following steps:
[0077] S41: Input the feature array of the target image into the long short-term memory neural network model, set the weight matrix of the forget gate of the long short-term memory neural network model to [0.0-0.5], update the feature array of the target image, and obtain the target feature array output value.
[0078] Among them, the long short-term memory neural network model is a feature classification model pre-trained based on the long short-term memory neural network. The long short-term memory neural network is also called the recursive neural network (Long Short-Term Memory, referred to as LSTM). The LSTM model is a time recursive neural network model with time memory function. It is suitable for processing and predicting events with time series states, and can process important events with relatively long time series intervals and delays. The weight matrix of the forget gate is a weight index based on the classification feature, which is an indicator that controls the degree of forgetting of the feature array in the forget gate.
[0079] Specifically, the feature array of the target image is input into the LSTM model, and the weight matrix of the forget gate of the long short-term memory neural network model is set to [0.0-0.5]. The LSTM model consists of memory units and has a three-layer network structure of forget gate, input gate and output gate. The forget gate is a sigmoid function that takes the output of the previous unit and the input of this unit as input, and generates a value in [0,1] for each feature in the memory unit to control the degree to which the previous feature array is forgotten. The forget gate is one of the most important gates in the LSTM model. The size of the forget gate is a parameter, that is, the weight matrix of the forget gate, which is used as an indicator to be passed into the program to calculate the degree of forgetting. The feature array of the target image is used as the input of the LSTM, and the weight matrix of the forget gate is set to forget gate=0.0-0.5 by changing the parameter value of the forget gate to control the degree to which the feature array of the target image is forgotten. When the forget gate is set to 1.0 in the LSTM model, the loss will drop sharply but the loss is not ideal; if the forget gate is set to 0.0-0.5, the loss will be optimal. The input gate and a tanh function work together to control what new information is added. The tanh function generates a new candidate vector Ct~, and the input gate generates a value in [0,1] for each item in Ct~, controlling how much new information is added. The output gate is used to control how much of the current unit state is filtered out and the degree to which the unit state is filtered.
[0080] The weight matrix based on the forgetting gate is used to control the degree of forgetting of the previous unit. The output of the input gate is used to control the amount of new information added. The output of the output gate is used to control the degree to which the unit state is filtered. The unit state of the memory unit is updated according to the degree of forgetting, the new information added and the degree of filtering, that is, the feature array of the target image is updated to obtain the target feature array output value.
[0081] S42: According to the recognition dimension of the image array of the target image, a multi-dimensional function corresponding to the recognition dimension is selected as a classification function of the target feature array output value, and the target feature array output value is classified.
[0082] Specifically, the output value of the target feature array is a value represented by a vector, and the values in the vector range from 0 to 1. It can be understood that the output value of the target feature array is actually a classifier, which realizes the probability description of each value in the vector through the softmax function. In the selection of the softmax function, a multi-dimensional function can be selected to make the classification result more accurate. The multi-dimensional function refers to a system of multi-variable equations. When recognizing an image, there are many factors affecting the success of recognition, and the more factors there are, the more meta-variables are needed to adapt. According to the factors affecting the target image, select the corresponding multi-dimensional functions for these factors to make the softmax function more suitable for the current target image. Specifically, if there are X factors affecting the image recognition result, set a function variable for each factor and correspondingly set it as an X-dimensional function. For example, if the input target image needs to consider five factors: pixels, grayscale values, brightness, background color, and color saturation, the corresponding softmax function is selected as a five-dimensional function. According to the recognition dimension of the image array, select the corresponding multi-dimensional function, and based on the multi-dimensional function as the classification function of the output value of the target feature array, perform probability description for each output value of the target feature array respectively.
[0083] S43: Select the maximum output value from the output values of the target feature array, and obtain the target classification result according to the maximum output value.
[0084] Specifically, through the softmax function, probability description is performed on each value in the vector. The value with the largest value in the vector corresponds to the largest probability of a certain classification result. The maximum output value in the output values of the target feature array corresponds to the largest probability of its classification. The target classification result is obtained according to the maximum output value.
[0085] In real life, there are differences between the text to be recognized and the standard specification, but this difference is much smaller than the differences with other texts that do not conform to the standard specification. For example, there are differences in pixel distribution between the character "I" in the text to be recognized and the standard character "I", but this difference is significantly smaller than the difference between the character "you" in the text to be recognized and the standard character "I". It can be considered that even though there are certain differences between the text to be recognized and the corresponding standard specification characters, this difference is much smaller than the differences with non-corresponding standard specification characters. Therefore, the target classification result can be determined by the principle of the most similar (i.e., the smallest difference) with the maximum output value of the classification probability.
[0086] In the image text recognition method provided by the embodiments of the present invention, a long short-term memory neural network model is used to classify the feature array of the target image. By adjusting the weight matrix of the forgetting gate of the LSTM model and selecting a multi-dimensional function, the classification result can be made more accurate and the accuracy of image text recognition can be improved.
[0087] In one embodiment, if Figure 5 As shown, before step S41, that is, before the step of setting the weight matrix of the forget gate of the long short-term memory neural network model to [0.0-0.5], the following steps are also included:
[0088] S411: According to the calculation formula f_t=σ(W_f*[h_t-1,x_t]+b_f), adjust the size of the weight matrix W_f to the left or right according to the preset interval, and calculate the value of the output f_t at the current moment after each adjustment, where f_t is the value output at the current moment, W_f is the weight matrix of the forget gate, σ is the sigmoid function, h_t-1 is the output value of the long short-term memory neural network at the previous moment, x_t is the input value of the long short-term memory neural network at the current moment, [h_t-1,x_t] means connecting the two vectors into a longer vector, and b_f is the bias term of the forget gate.
[0089] Among them, the LSTM model is composed of memory units and has a three-layer network structure of forget gate, input gate and output gate. The forget gate is a sigmoid function that takes the output of the previous unit and the input of the current unit as input, and generates a value in [0,1] for each feature in the memory unit to control the degree of forgetting of the feature array. The forget gate determines how much of the unit state at the previous moment will be retained in the output at the current moment, that is, the value of the output f_t at the current moment. The weight matrix W_f is the weight index based on the classification feature in the forget gate, and is an index that controls the degree of forgetting of the feature array in the forget gate. The Sigmoid function has the properties of monotonically increasing and inverse monotonically increasing, and is used as the threshold function of the LSTM model to map variables between [0,1]. h_t-1 is the output value of the LSTM at the previous moment, x_t is the input value of the LSTM at the current moment, and [h_t-1,x_t] means connecting the two vectors into a longer vector as the input of the forget gate. b_f is the bias term of the forget gate.
[0090] Specifically, according to the calculation formula f_t=σ(W_f*[h_t-1,x_t]+b_f) output at the current moment, the size of the weight matrix W_f is adjusted to the left or right at predetermined intervals, and the value of each weight matrix W_f is substituted into the calculation formula output at the current moment to calculate the value of the output f_t at the current moment.
[0091] S412: Based on the value of each weight matrix W_f, obtain the change trajectory of the value of the current output f_t over time in real time, and generate a line graph;
[0092] Specifically, based on the value of each weight matrix W_f, the change trajectory of the value of the current output f_t over time is obtained in real time, and the image method is used to generate a line graph of the change trajectory of the value of the current output f_t over time. Furthermore, the line graph is a two-dimensional line graph with the value of the weight matrix W_f as the fixed term, the value of the current output f_t as the vertical coordinate, and time as the horizontal coordinate. After adjusting a large number of weight matrix W_f values, the line graph is analyzed according to the changes of a large number of current output f_t values over time. It can be seen that the change of the value of the current output f_t is in the form of a tangent function, and its change amplitude over time is related to W_f.
[0093] S413: Calculate the slope of the line graph, and select the value of the weight matrix W_f corresponding to the range of the slope that meets the preset result as the weight matrix of the forget gate of the long short-term memory neural network model.
[0094] Specifically, the slope of the line graph corresponding to the value of each weight matrix W_f is calculated to obtain the change in slope, and the value of the weight matrix W_f corresponding to the range of slopes that meets the preset results is selected as the optimal applicable range of the forget gate weight matrix, so as to serve as the weight matrix of the forget gate of the LSTM model. Furthermore, according to the calculation and analysis results of a large amount of data, the weight matrix of the forget gate of the LSTM model is [0.0, 0.5].
[0095] In this embodiment, by adjusting the size of the weight matrix W_f, the change trajectory of the value of the output f_t at the current moment under each weight matrix over time is obtained according to the calculation formula output at the current moment, and a line graph is generated for the change trajectory of the value of the output f_t at the current moment over time, and its slope is analyzed. Accurate results can be obtained according to specific training data, and the range of slopes that meet the preset results is selected as the weight matrix of the forget gate of the LSTM model, so that the range of the obtained forget gate weight matrix is more accurate, which can achieve accurate classification of images.
[0096] In one embodiment, in step S50, that is, after the step of inputting the feature array of the target image into the long short-term memory neural network model; and before the step of classifying the target image and obtaining the target classification result, the image text recognition method further includes the following steps:
[0097] An adaptive time estimation algorithm is used to iteratively update the network weights of the long short-term memory neural network model.
[0098] Among them, the Adaptive Moment Estimation (Adam algorithm) is an algorithm that performs first-order gradient optimization on a random objective function, which is based on adaptive low-order moment estimation. The Adam algorithm dynamically adjusts the learning rate for each parameter based on the first-order moment estimation and second-order moment estimation of the gradient of each parameter of the loss function. The Adam algorithm is also based on the gradient descent method, but the learning step size of each iteration parameter has a certain range, and will not cause a large learning step size due to a large gradient, and the parameter value is relatively stable.
[0099] Specifically, the Adam algorithm can calculate the adaptive learning rate of each parameter, which is used to iteratively update the network weights of the long short-term memory neural network model. Compared with other adaptive learning rate algorithms, it has faster convergence speed and more effective learning effect, which can improve the recognition accuracy. It can also correct problems such as learning rate disappearance, slow convergence or high variance parameter updates leading to large fluctuations in the loss function.
[0100] In this embodiment, an adaptive time estimation algorithm is used to iteratively update the network weights of the long short-term memory neural network model, which has a faster convergence speed and a more effective learning effect, thereby improving the accuracy of image text recognition.
[0101] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0102] In one embodiment, an image character recognition device is provided, and the image character recognition device corresponds to the image character recognition method in the above embodiment. Figure 6 As shown, the image text recognition device includes an original image acquisition module 10, an original image processing module 20, a target image feature extraction module 30, a target image classification module 40 and a target text acquisition module 50. The functional modules are described in detail as follows:
[0103] The original image acquisition module 10 is used to acquire the original image, which contains the text to be recognized;
[0104] The original image processing module 20 is used to perform global optimization processing on the original image to obtain a target image;
[0105] The target image feature extraction module 30 is used to input the target image into the convolutional neural network model for feature extraction to obtain a feature array of the target image;
[0106] The target image classification module 40 is used to input the feature array of the target image into the long short-term memory neural network model, set the function parameters for image classification, classify the target image, and obtain the target classification result;
[0107] The target text acquisition module 50 is used to determine the recognition result of the target image according to the target classification result, query the preset semantic library based on the recognition result corresponding to the target image, and obtain the target text corresponding to the text to be recognized.
[0108] Preferably, the target image feature extraction module 30 includes: an image array acquisition unit 31 and a feature array acquisition unit 32 .
[0109] An image array acquisition unit 31 is used to acquire an image array of a target image;
[0110] The feature array acquisition unit 32 is used to input the image array of the target image into the convolutional neural network model, perform feature extraction on the target image based on the convolution and pooling operations of the convolutional neural network model, and obtain the feature array of the target image.
[0111] Preferably, the target image classification module 40 comprises: a target feature array output value acquisition unit 41 , a target feature array output value classification unit 42 and a target classification result acquisition unit 43 .
[0112] The target feature array output value acquisition unit 41 is used to input the feature array of the target image into the long short-term memory neural network model, and set the weight matrix of the forget gate of the long short-term memory neural network model to [0.0-0.5], update the feature array of the target image, and obtain the target feature array output value;
[0113] The target feature array output value classification unit 42 is used to select a multi-dimensional function corresponding to the recognition dimension as a classification function of the target feature array output value according to the recognition dimension of the image array of the target image, and classify the target feature array output value;
[0114] The target classification result acquisition unit 43 is used to select the maximum output value among the output values of the target feature array, and acquire the target classification result according to the maximum output value.
[0115] Preferably, the image text recognition device further includes: a weight matrix adjustment module 411 , a current moment output recording module 412 and an optimal applicable range analysis module 413 .
[0116] The weight matrix adjustment module 411 is used to adjust the size of the weight matrix W_f to the left or right according to a preset interval according to the calculation formula f_t=σ(W_f*[h_t-1,x_t]+b_f), and calculate the value of the output f_t at the current moment after each adjustment, where f_t is the value output at the current moment, W_f is the weight matrix of the forget gate, σ is the sigmoid function, h_t-1 is the output value of the long short-term memory neural network at the previous moment, x_t is the input value of the long short-term memory neural network at the current moment, [h_t-1,x_t] means connecting two vectors into a longer vector, and b_f is the bias term of the forget gate;
[0117] The current moment output recording module 412 is used to obtain the change trajectory of the value of the current moment output f_t over time in real time based on the value of each weight matrix W_f, and generate a line graph;
[0118] The optimal applicable range analysis module 413 is used to calculate the slope of the line graph and select the value of the weight matrix W_f corresponding to the range of the slope that meets the preset result as the weight matrix of the forget gate of the long short-term memory neural network model.
[0119] Preferably, the image text recognition device further includes: an iterative update module 60 .
[0120] The iterative updating module 60 is used to iteratively update the network weights of the long short-term memory neural network model by adopting an adaptive time estimation algorithm.
[0121] For the specific definition of the image text recognition device, please refer to the definition of the image text recognition method above, which will not be repeated here. Each module in the above-mentioned image text recognition device can be implemented in whole or in part by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0122] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an image text recognition method is implemented.
[0123] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0124] Obtain an original image, which contains text to be recognized;
[0125] Perform global optimization processing on the original image to obtain the target image;
[0126] Input the target image into the convolutional neural network model for feature extraction to obtain the feature array of the target image;
[0127] Input the feature array of the target image into the long short-term memory neural network model, set the function parameters for image classification, classify the target image, and obtain the target classification result;
[0128] The recognition result of the target image is determined according to the target classification result, and the preset semantic library is queried based on the recognition result corresponding to the target image to obtain the target text corresponding to the text to be recognized.
[0129] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0130] Obtain an original image, which contains text to be recognized;
[0131] Perform global optimization processing on the original image to obtain the target image;
[0132] Input the target image into the convolutional neural network model for feature extraction to obtain the feature array of the target image;
[0133] Input the feature array of the target image into the long short-term memory neural network model, set the function parameters for image classification, classify the target image, and obtain the target classification result;
[0134] The recognition result of the target image is determined according to the target classification result, and the preset semantic library is queried based on the recognition result corresponding to the target image to obtain the target text corresponding to the text to be recognized.
[0135] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0136] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0137] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for image character recognition, characterized in that: include: Acquire an original image, wherein the original image contains text to be recognized; Performing global optimization processing on the original image to obtain a target image; Inputting the target image into a convolutional neural network model to extract features, thereby obtaining a feature array of the target image; According to the calculation formula f_t=σ(W_f*[h_t-1,x_t]+b_f), adjust the size of the weight matrix W_f to the left or right according to the preset interval, and calculate the value of the output f_t at the current moment after each adjustment, where f_t is the value output at the current moment, W_f is the weight matrix of the forget gate, σ is the sigmoid function, h_t-1 is the output value of the long short-term memory neural network at the previous moment, x_t is the input value of the long short-term memory neural network at the current moment, [h_t-1,x_t] means connecting the two vectors into a longer vector, and b_f is the bias term of the forget gate; Based on the value of each weight matrix W_f, obtain the change trajectory of the current output f_t value over time in real time and generate a line graph; Calculate the slope of the line graph, and select the value of the weight matrix W_f corresponding to the range of the slope that meets the preset result as the weight matrix of the forget gate of the long short-term memory neural network model; Inputting the feature array of the target image into the long short-term memory neural network model, setting the weight matrix of the forget gate of the long short-term memory neural network model to [0.0-0.5], updating the feature array of the target image, and obtaining a target feature array output value; According to the recognition dimension of the image array of the target image, a multi-dimensional function corresponding to the recognition dimension is selected as a classification function of the output value of the target feature array, and the output value of the target feature array is classified; Selecting the maximum output value among the output values of the target feature array, and obtaining a target classification result according to the maximum output value; The recognition result of the target image is determined according to the target classification result, and a preset semantic library is queried based on the recognition result corresponding to the target image to obtain the target text corresponding to the text to be recognized.
2. The image character recognition method according to claim 1, characterized in that: The step of inputting the target image into a convolutional neural network model for feature extraction to obtain a feature array of the target image specifically includes the following steps: Obtain an image array of the target image; The image array of the target image is input into the convolutional neural network model, and features of the target image are extracted based on the convolution and pooling operations of the convolutional neural network model to obtain a feature array of the target image.
3. The image character recognition method according to claim 1, characterized in that: After the step of inputting the feature array of the target image into the long short-term memory neural network model; Furthermore, before the step of classifying the target image and obtaining the target classification result, the image text recognition method further includes: An adaptive time estimation algorithm is used to iteratively update the network weights of the long short-term memory neural network model.
4. An image character recognition device, characterized in that: include: An original image acquisition module, used to acquire an original image, wherein the original image contains text to be recognized; The original image processing module is used to perform global optimization processing on the original image to obtain a target image; A target image feature extraction module, used for inputting the target image into a convolutional neural network model for feature extraction to obtain a feature array of the target image; The weight matrix adjustment module is used to adjust the size of the weight matrix W_f to the left or right according to the preset interval according to the calculation formula f_t=σ(W_f*[h_t-1,x_t]+b_f), and calculate the value of the output f_t at the current moment after each adjustment, where f_t is the value output at the current moment, W_f is the weight matrix of the forget gate, σ is the sigmoid function, h_t-1 is the output value of the long short-term memory neural network at the previous moment, x_t is the input value of the long short-term memory neural network at the current moment, [h_t-1,x_t] means connecting two vectors into a longer vector, and b_f is the bias term of the forget gate; The current moment output recording module is used to obtain the change trajectory of the current moment output f_t value over time in real time based on the value of each weight matrix W_f, and generate a line graph; The optimal applicable range analysis module is used to calculate the slope of the line graph, and select the value of the weight matrix W_f corresponding to the range of the slope that meets the preset result as the weight matrix of the forget gate of the long short-term memory neural network model; A target image classification module is used to input the feature array of the target image into the long short-term memory neural network model, set the weight matrix of the forget gate of the long short-term memory neural network model to [0.0-0.5], update the feature array of the target image, and obtain a target feature array output value; According to the recognition dimension of the image array of the target image, a multi-dimensional function corresponding to the recognition dimension is selected as a classification function of the output value of the target feature array, and the output value of the target feature array is classified; the maximum output value among the output values of the target feature array is selected, and a target classification result is obtained according to the maximum output value; The target text acquisition module is used to determine the recognition result of the target image according to the target classification result, query the preset semantic library based on the recognition result corresponding to the target image, and obtain the target text corresponding to the text to be recognized.
5. The image character recognition device according to claim 4, characterized in that: The target image feature extraction module comprises: An image array acquisition unit, used for acquiring an image array of the target image; A feature array acquisition unit is used to input the image array of the target image into the convolutional neural network model, perform feature extraction on the target image based on the convolution and pooling operations of the convolutional neural network model, and obtain the feature array of the target image.
6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the image text recognition method according to any one of claims 1 to 3 are implemented.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the image text recognition method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Text recognition method and device
CN106407971A
Recognition method for English words and digits in natural scene image
CN107368831A
Character model training method and device, character recognition method and device, equipment and medium
CN109063706A
Hybrid memory cell unit and recurrent neural network including hybrid memory cell units
US20180005107A1
Memory cell unit and recurrent neural network including multiple memory cell units
US20180005676A1
