WO2019232843A1 - 手写模型训练、手写图像识别方法、装置、设备及介质 - Google Patents
手写模型训练、手写图像识别方法、装置、设备及介质 Download PDFInfo
- Publication number
- WO2019232843A1 WO2019232843A1 PCT/CN2018/094168 CN2018094168W WO2019232843A1 WO 2019232843 A1 WO2019232843 A1 WO 2019232843A1 CN 2018094168 W CN2018094168 W CN 2018094168W WO 2019232843 A1 WO2019232843 A1 WO 2019232843A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- image
- training
- term
- neural network
- short
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V30/00—Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
- G06V30/10—Character recognition
- G06V30/14—Image acquisition
- G06V30/148—Segmentation of character regions
- G06V30/153—Segmentation of character regions using recognition of characters or words
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/21—Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
- G06F18/214—Generating training patterns; Bootstrap methods, e.g. bagging or boosting
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/20—Image preprocessing
- G06V10/26—Segmentation of patterns in the image field; Cutting or merging of image elements to establish the pattern region, e.g. clustering-based techniques; Detection of occlusion
- G06V10/267—Segmentation of patterns in the image field; Cutting or merging of image elements to establish the pattern region, e.g. clustering-based techniques; Detection of occlusion by performing operations on regions, e.g. growing, shrinking or watersheds
Definitions
- the present application relates to the field of image recognition, and in particular, to a method, a device, a device, and a medium for handwriting model training and handwriting image recognition.
- a handwriting model training method includes:
- the original handwriting recognition model is tested by using the training single font image in the test set, and when the test accuracy is greater than a preset accuracy rate, a target handwriting recognition model is obtained.
- a handwriting model training device includes:
- Training handwritten Chinese image acquisition module for acquiring training handwritten Chinese images
- a training handwritten Chinese image division module configured to divide the trained handwritten Chinese image into a training set and a test set according to a preset ratio
- a training single font image acquisition module configured to use a vertical projection method to perform single font cutting on the training handwritten Chinese image to obtain a training single font image
- the original handwriting recognition model acquisition module is used to sequentially label the training single font images in the training set, and input the labeled single font images into the long-term and short-term memory neural network for training.
- the network parameters of the long-term and short-term memory neural network are updated to obtain the original handwriting recognition model
- a target handwriting recognition model acquisition module is configured to test the original handwriting recognition model using a training single font image in the test set, and obtain a target handwriting recognition model when a test accuracy rate is greater than a preset accuracy rate.
- a computer device includes a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor.
- the processor executes the computer-readable instructions, the following steps are implemented:
- the original handwriting recognition model is tested by using the training single font image in the test set, and when the test accuracy is greater than a preset accuracy rate, a target handwriting recognition model is obtained.
- One or more non-volatile readable storage media storing computer-readable instructions, which when executed by one or more processors, cause the one or more processors to perform the following steps:
- the original handwriting recognition model is tested by using the training single font image in the test set, and when the test accuracy is greater than a preset accuracy rate, a target handwriting recognition model is obtained.
- a handwritten image recognition method includes:
- the image of the to-be-recognized word is input to a target handwriting recognition model for recognition, and a handwritten Chinese character corresponding to each of the to-be-recognized image is obtained; wherein the target handwriting recognition model is obtained by using the handwriting model training method.
- a handwritten image recognition device includes:
- a to-be-recognized image acquisition module configured to obtain an to-be-recognized image, where the to-be-recognized image includes handwritten Chinese characters and a background picture;
- An original image acquisition module configured to preprocess the image to be identified to obtain an original image
- a target image acquisition module configured to process the original image by using a kernel density estimation algorithm, remove the background picture, and obtain a target image including the handwritten Chinese character;
- a to-be-recognized single-word image acquisition module configured to use a vertical projection method to perform single-font cutting on the target image to obtain the to-be-recognized single-word image;
- a handwritten Chinese character acquisition module is configured to input an image of a single character to be recognized into a target handwriting recognition model for recognition, and obtain a handwritten Chinese character corresponding to each of the single character images to be recognized; wherein the target handwriting recognition model uses the handwriting model Obtained by the training method.
- a computer device includes a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor.
- the processor executes the computer-readable instructions, the following steps are implemented:
- the image of the to-be-recognized word is input to a target handwriting recognition model for recognition, and a handwritten Chinese character corresponding to each of the to-be-recognized image is obtained; wherein the target handwriting recognition model is obtained by using the handwriting model training method.
- One or more non-volatile readable storage media storing computer-readable instructions, which when executed by one or more processors, cause the one or more processors to perform the following steps:
- the image of the to-be-recognized word is input to a target handwriting recognition model for recognition, and a handwritten Chinese character corresponding to each of the to-be-recognized image is obtained; wherein the target handwriting recognition model is obtained by using the handwriting model training method.
- FIG. 1 is an application scenario diagram of a handwriting model training method or a handwriting image recognition method according to an embodiment of the present application
- FIG. 2 is a flowchart of a handwriting model training method according to an embodiment of the present application
- FIG. 3 is a specific flowchart of step S14 in FIG. 2;
- FIG. 4 is a schematic diagram of a handwriting model training device according to an embodiment of the present application.
- FIG. 5 is a flowchart of a handwritten image recognition method according to an embodiment of the present application.
- step S22 in FIG. 5 is a specific flowchart of step S22 in FIG. 5;
- FIG. 7 is a specific flowchart of step S23 in FIG. 5;
- step S234 in FIG. 7 is a specific flowchart of step S234 in FIG. 7;
- FIG. 9 is a schematic diagram of a handwritten image recognition device according to an embodiment of the present application.
- FIG. 10 is a schematic diagram of a computer device according to an embodiment of the present application.
- the handwriting model training method provided in the embodiment of the present application can be applied in the application environment as shown in FIG. 1.
- the application environment of the handwriting model training method includes a server and a computer device, wherein the computer device communicates with the server through a network, and the computer device is a device that can interact with a user, including, but not limited to, a computer, a smartphone, and a tablet. .
- the handwriting model training method provided in the embodiment of the present application is applied to a server.
- a handwriting model training method is provided.
- the method is applied to the server in FIG. 1 as an example for description, and includes the following steps:
- the training handwritten Chinese image is a sample image collected from an open source library for model training in advance.
- the training handwritten Chinese image includes N (N is a positive integer) handwriting samples corresponding to each Chinese in the Chinese secondary word library.
- the Chinese secondary character library is a very useful Chinese character library that is coded in the order of radical strokes of Chinese characters. Specifically, N handwriting samples handwritten by different people in the open source library are collected to enable the server to obtain training handwritten Chinese images. Because different users have different writing habits, N handwriting samples (that is, training handwritten Chinese images) are used for Training greatly improves the generalization of the model.
- S12 Use a vertical projection method to perform single font cutting on the training handwritten Chinese image to obtain a training single font image.
- the vertical projection method refers to a method of vertically projecting each line of handwritten Chinese characters to obtain a vertical projection histogram.
- the vertical projection histogram refers to the number of pixels reflecting the target image in the vertical direction.
- using a vertical projection method to perform single font cutting on the training handwritten Chinese image specifically includes the following steps: the server scans at least one row of handwritten Chinese characters in the training handwritten Chinese image line by line, and obtains the pixel value corresponding to each line of handwritten Chinese characters.
- the vertical projection histogram corresponding to one pixel value is used to obtain the number of pixels corresponding to different pixel values.
- the training handwritten Chinese image is cyclically cut to obtain a training single font image. Understandably, the pixel value corresponding to each handwritten Chinese character is relatively concentrated, and the pixel value corresponding to the gap between the Chinese character and the Chinese character is relatively sparse.
- the density of the corresponding pixel value is reflected in the corresponding vertical projection histogram.
- the number of pixels corresponding to pixel values with Chinese characters is relatively high, and the number of pixels corresponding to pixel values without Chinese characters is relatively low.
- the vertical projection method can effectively perform single font cutting on the training handwritten Chinese image to obtain a training list. Font image, easy to implement and improve training efficiency.
- the training set is a learning sample data set, which is to establish a classifier by matching some parameters, that is, training the machine learning model using the target training text data in the training set to determine the parameters of the machine learning model.
- a test set is used to test the discrimination capabilities of a trained machine learning model, such as accuracy.
- the preset ratio is a preset ratio for dividing the training handwritten Chinese image.
- the training single font image may be divided according to a ratio of 9: 1, that is, 90% of the training single font image is used as the training set, and the remaining 10% of the training single font image is used as the test set.
- S14 sequentially label the training single font images in the training set, and input the labeled training single font images into the long-term and short-term memory neural network for training, and use a batch gradient descent algorithm to update the network parameters of the long-term and short-term memory neural network. To get the original handwriting recognition model.
- the original handwriting recognition model is a model obtained through multiple iterations of long-term and short-term memory neural networks.
- Long-short-term memory neural (LSTM) network is a kind of time-recursive neural network, which is suitable for processing and predicting important events with time series and time series with relatively long intervals and delays.
- the server performs labeling according to the chronological order of the training single font images, and inputs the labeled training single font images into the target handwriting recognition model for training to obtain the original handwriting recognition model.
- each training single font image is arranged in order.
- the original image is "I am very happy today”
- each training single font image can be labeled with Arabic numerals from left to right, that is, "present (1) Day (2) Very (3) Open (4) Heart (5) ", so that the training single font image has timeliness, so that the original handwriting recognition model can be trained in connection with the context and improve the accuracy of the model.
- the batch gradient descent algorithm is to update all the samples in the training set (training font image) every time the network parameters are updated, which can obtain the global optimal solution and improve the accuracy of the model.
- the network parameters are the weights and offsets between the layers of the long- and short-term memory neural network.
- the long-term and short-term memory neural network has the function of time memory, so it is used to process the training single font image carrying the time series state.
- the long-short-term memory neural network has a network structure of an input layer, at least one hidden layer, and an output layer.
- the input layer is the first layer of the long-term and short-term memory neural network, which is used to receive external signals, that is, it is responsible for receiving training single font images.
- the output layer is the last layer of the long-term and short-term memory neural network, which is used to output signals to the outside world, that is, it is responsible for outputting the calculation results of the long-term and short-term memory neural network.
- Hidden layers are layers other than the input layer and the output layer in the long-term and short-term memory neural network, which are used to process the training single font image and obtain the calculation results of the long-term and short-term memory neural network.
- the use of long-term and short-term memory neural networks for model training increases the timeliness of the training single font image, so that the training single font image is trained according to the context, thereby improving the accuracy of the target handwriting recognition model.
- the output layer of the long-term and short-term memory neural network uses Softmax (regression model) for regression processing, and is used to classify the output weight matrix.
- Softmax regression model
- Softmax is a classification function commonly used in neural networks. It maps the output of multiple neurons into the [0,1] interval, which can be understood as a probability. It is simple and convenient to calculate, so as to perform multi-classification. Output to make its output more accurate.
- step S14 the training single font image is sequentially labeled, and the labeled single font image is input to a long-term and short-term memory neural network for training to obtain target handwriting recognition.
- the model includes the following steps:
- the training single font image is processed by using the first activation function to obtain a neuron carrying an activation state identifier.
- each neuron in the hidden layer of the long-term and short-term memory neural network includes three gates, which are an input gate, a forgetting gate, and an output gate, respectively.
- the forget gate determines the past information to be discarded in the neuron.
- the input gate determines the information to be added to the neuron.
- the output gate determines the information to be output in the neuron.
- the first activation function is a function for activating a neuron state.
- the state of the neuron determines the information discarded, added, and output by each gate (ie, input gate, forget gate, and output gate).
- the activation status flag includes a pass flag and a fail flag.
- the identifiers corresponding to the input gate, the forget gate, and the output gate in this embodiment are i, f, and o, respectively.
- the Sigmoid (S-shaped growth curve) function is specifically selected as the first activation function.
- the Sigmoid function is a S-shaped function common in biology. In information science, due to its single increase and inverse function single increase In other properties, the Sigmoid function is often used as a threshold function for neural networks, mapping variables between 0 and 1.
- the calculation formula for the first activation function is Among them, z represents the output value of the forget gate.
- the forgetting gate includes a forgetting threshold.
- a neuron carrying an activation state identifier as a pass identifier is obtained.
- F t represents the forgetting threshold (that is, the activation state)
- W f represents the weight matrix of the forgetting gate
- b f represents the weight bias term of the forgetting gate
- h t-1 represents the output of the neuron at the previous moment
- x t represents The input data at the current time (that is, the training single font image)
- t represents the current time
- t-1 represents the previous time.
- the forgetting gate also includes the forgetting threshold.
- the calculation of the font image of the training single through the calculation formula of the forgetting gate will obtain a scalar in the range of 0-1. This scalar determines the past information received by the neuron based on the comprehensive judgment of the current state and the past state. To achieve data reduction, reduce the amount of calculation, and improve training efficiency.
- a second activation function is used to process the neurons carrying the identification of the activation state to obtain the output value of the hidden layer of the long-term and short-term memory neural network.
- the output value of the hidden layer of the long-term and short-term memory neural network includes the output value of the input gate, the output value of the output gate, and the state of the neuron.
- a second activation function is used to carry the activation state identifier to perform calculation through the identified neurons to obtain the output value of the hidden layer.
- a tanh (hyperbolic tangent) function is used as the activation function of the input gate (ie, the second activation function).
- Non-linear factors can be added to make the trained target handwriting recognition model Able to solve more complex problems.
- the activation function tanh has the advantage of fast convergence speed, which can save training time and increase training efficiency.
- the output value of the input gate is calculated by a calculation formula of the input gate.
- the input gate also includes an input threshold.
- the calculation of the font image of the training single through the calculation formula of the input gate will obtain a 0-1 interval scalar (that is, the input threshold). This scalar controls the nerve. Yuan judges the proportion of the received current information, that is, the proportion of newly input information, according to the comprehensive evaluation of the current state and the past state, so as to reduce the calculation amount and improve the training efficiency.
- the calculation formula of the state of the neuron is adopted.
- W c represents the weight matrix for calculating the unit state
- b c represents the bias term for the unit state
- C t represents the state of the neuron at the current moment.
- a batch gradient descent algorithm is used to update the network parameters of the long-term and short-term memory neural network to obtain a target handwriting recognition model.
- the network parameters of the long-term and short-term memory neural network refer to the weights and offsets between the layers of the long-term and short-term memory neural network.
- the formula of the batch gradient descent algorithm is: with Among them, J ( ⁇ ) is the loss function, m is the number of single font images in the training set, ⁇ j is the network parameter of the j-th layer of the short-term memory neural network, and h ⁇ (x) is the number of hidden layers of the short-term memory neural network.
- the output value, (x i , y i ) represents the i-th training single font image.
- a target handwriting recognition model can be obtained.
- each weight in the target handwriting recognition model implements the functions of the target handwriting recognition model to decide which old information to discard, which new information to add, and which information to output.
- the output layer of the target handwriting recognition model will eventually output a probability value, which refers to the probability of the corresponding Chinese character being recognized by the training single font image. It can be widely used in handwriting recognition to accurately recognize the training single font image. purpose.
- step S15 all the training single font images in the test set are input to the original handwriting recognition model for testing, and the test accuracy rate is obtained (that is, the number of accurate prediction results of all original handwriting recognition models is divided by all training single font images in the training set quantity). Then judge whether the test accuracy rate is greater than the preset accuracy rate. If the test accuracy rate is greater than the preset accuracy rate, the original handwriting recognition model is deemed to be more accurate, and the original handwriting recognition model is used as the target handwriting recognition model; otherwise, If the test accuracy rate is not greater than the preset accuracy rate, the prediction result of the original handwriting recognition model is deemed to be inaccurate. It is still necessary to use steps S11-S14 for training, and then test again until the test accuracy rate reaches the preset accuracy rate. , Stop training, and further improve the accuracy of the target handwriting recognition model.
- a training handwritten Chinese image is first obtained, a single font cutting is performed on the training handwritten image using a vertical projection method, a training single font image is obtained, and the training single font image is divided into a training set and a test set according to a preset ratio, In order to sequentially label the training single font images in the training set, so that the training single font images have timing.
- the labeled training single font image is input into the long-term and short-term memory neural network for training.
- the long-term and short-term memory neural network trains the training single-font image according to the context.
- the network parameters of the long and short-term memory neural network are updated to obtain the original handwriting recognition model, thereby improving the accuracy of the model.
- the original handwriting recognition model is tested with the training single font image in the test set. When the test accuracy is greater than the preset accuracy rate, the target handwriting recognition model is obtained, which further improves the accuracy of the target handwriting recognition model.
- a handwriting model training device corresponds to the handwriting model training method in the above embodiment.
- the handwriting model training device includes a training handwritten Chinese image acquisition module 11, a training handwritten Chinese image division module 12, a training single font image acquisition module 13, an original handwriting recognition model acquisition module 14 and a target handwriting recognition model.
- the acquisition module 15 is detailed as follows:
- a training handwritten Chinese image division module 12 for dividing the trained handwritten Chinese image into a training set and a test set according to a preset ratio
- a training single font image acquisition module 13 is configured to use a vertical projection method to perform single font cutting on a training handwritten Chinese image to obtain a training single font image;
- the original handwriting recognition model acquisition module 14 is used to sequentially label the training single font images in the training set, and input the labeled single font images to the long-term and short-term memory neural network for training.
- the network parameters of the memory neural network are updated to obtain the original handwriting recognition model;
- the target handwriting recognition model acquisition module 15 is used to test the original handwriting recognition model using a training single font image in a test set. When the test accuracy is greater than a preset accuracy rate, the target handwriting recognition model is obtained.
- the original handwriting recognition model acquisition module 14 includes an activation state neuron acquisition unit 141, a hidden layer output value acquisition unit 142, and a target recognition model acquisition unit 143.
- the activation state neuron acquisition unit 141 is configured to process the training single font image by using a first activation function in a hidden layer of the long-term and short-term memory neural network to acquire a neuron carrying an activation state identifier.
- the hidden layer output value obtaining unit 142 is configured to process the neuron carrying the activation state identifier in the hidden layer of the long-term and short-term memory neural network to obtain the output value of the hidden layer of the long-term and short-term memory neural network.
- the target recognition model acquisition unit 143 is configured to update the network parameters of the long-term and short-term memory neural network by using a batch gradient descent algorithm according to the output value of the hidden layer of the long-term and short-term memory neural network to obtain a target handwriting recognition model.
- the formula of the batch gradient descent algorithm is: with Among them, J ( ⁇ ) is the loss function, m is the number of single font images in the training set, ⁇ j is the network parameter of the j-th layer of the short-term memory neural network, and h ⁇ (x) is the number of hidden layers of the short-term memory neural network.
- the output value, (x i , y i ) represents the i-th training single font image.
- Each module in the above handwriting model training device may be implemented in whole or in part by software, hardware, and a combination thereof.
- the above-mentioned modules may be embedded in the hardware in or independent of the processor in the computer device, or may 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.
- a computer device is provided.
- the computer device may be a server, and its internal structure diagram may be as shown in FIG. 10.
- the computer device includes a processor, a memory, a network interface, and a database connected through a system bus.
- 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, computer-readable instructions, and a database.
- the internal memory provides an environment for the operation of the operating system and computer-readable instructions in a non-volatile storage medium.
- the database of the computer device is used to store data generated or obtained during the execution of the training method of the handwriting model, such as the target handwriting recognition model.
- the network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer-readable instructions are executed by one or more processors, the one or more processors are executed to implement a handwriting model training method.
- a computer device which includes a memory, a processor, and computer-readable instructions stored on the memory and executable on the processor.
- the processor executes the computer-readable instructions, the processor implements the following steps: obtaining training Handwritten Chinese images; using the vertical projection method to perform single font cutting on the training handwritten Chinese images to obtain training single font images; dividing the training single font images into training sets and test sets according to a preset ratio; and performing training single font images on the training set.
- Sequential labeling and input the labeled training single font image into the long-term and short-term memory neural network for training.
- the batch gradient descent algorithm is used to update the network parameters of the long-term and short-term memory neural network to obtain the original handwriting recognition model.
- the test set is used.
- the training single font image tests the original handwriting recognition model. When the test accuracy is greater than a preset accuracy rate, the target handwriting recognition model is obtained.
- the hidden layer of the long-term and short-term memory neural network uses the first activation function to process the training single font image to obtain a neuron carrying an activation state identifier;
- the second activation function is used to process the neurons carrying the identification of the activation state to obtain the output value of the hidden layer of the long-term and short-term memory neural network.
- the batch gradient descent algorithm updates the network parameters of the long-term and short-term memory neural network to obtain the target handwriting recognition model.
- the formula of the batch gradient descent algorithm is: with Among them, J ( ⁇ ) is the loss function, m is the number of single font images in the training set, ⁇ j is the network parameter of the j-th layer of the short-term memory neural network, and h ⁇ (x) is the number of hidden layers of the short-term memory neural network.
- the output value, (x i , y i ) represents the i-th training single font image.
- a non-volatile storage medium on which computer-readable instructions are stored, and the computer-readable instructions, when executed by one or more processors, cause the one or more processes to be processed.
- the following steps are performed during the execution of the device: obtaining a training handwritten Chinese image; using a vertical projection method to perform single font cutting on the training handwritten Chinese image to obtain a training single font image; dividing the training single font image into a training set and a test set according to a preset ratio; Sequentially label the training single font images in the training set, and input the labeled training single font images into the long-term and short-term memory neural network for training.
- the batch gradient descent algorithm is used to update the network parameters of the long-term and short-term memory neural network to obtain The original handwriting recognition model; the original handwriting recognition model is tested with the training single font image in the test set, and the target handwriting recognition model is obtained when the test accuracy is greater than a preset accuracy rate.
- the execution of the one or more processors further implements the following steps: a first layer is used in the hidden layer of the short-term memory neural network;
- the activation function processes the training single font image to obtain the neurons carrying the identification of the active state; in the hidden layer of the short-term memory neural network, the second activation function is used to process the neurons carrying the identification of the active state to obtain the long-term memory neural network.
- the output value of the hidden layer based on the output value of the hidden layer of the long-term and short-term memory neural network, the batch gradient descent algorithm is used to update the network parameters of the long-term and short-term memory neural network to obtain the target handwriting recognition model.
- the formula of the batch gradient descent algorithm is: with Among them, J ( ⁇ ) is the loss function, m is the number of single font images in the training set, ⁇ j is the network parameter of the j-th layer of the short-term memory neural network, and h ⁇ (x) is the number of hidden layers of the short-term memory neural network.
- the output value, (x i , y i ) represents the i-th training single font image.
- a handwritten image recognition method is provided.
- the method is applied to the server in FIG. 1 as an example for description, and includes the following steps:
- S21 Acquire an image to be identified.
- the image to be identified includes handwritten Chinese characters and a background picture.
- the image to be identified is an unprocessed image containing handwritten Chinese characters collected by an acquisition module on a computer device.
- the image to be recognized includes handwritten Chinese characters and background pictures.
- the background picture is a noise picture other than handwritten Chinese characters in the image to be identified. Noise pictures are pictures that interfere with handwritten Chinese characters.
- a user may collect an image to be identified containing handwritten Chinese characters and upload it to a server through a collection module on a computer device, so that the server obtains the image to be identified.
- the acquisition module includes but is not limited to camera shooting and local upload.
- the original image is an image obtained by pre-processing the image to be identified and excluding interference factors.
- the image to be identified may contain multiple interference factors, such as multiple colors, it is not conducive to subsequent identification. Therefore, the image to be identified needs to be pre-processed to obtain the original image that excludes interference factors.
- the original image can be understood as the image obtained after the background image is excluded from the image to be identified.
- step S22 the image to be identified is pre-processed to obtain the original image, which specifically includes the following steps:
- S221 Enlarge and grayscale the image to be identified to obtain a grayscale image.
- the grayscale image is a grayscale image obtained after the image to be identified is enlarged and processed for grayscale processing.
- the grayed image includes a matrix of pixel values.
- the pixel value matrix refers to a matrix containing pixel values corresponding to each pixel in an image to be identified.
- the server uses the imread function to read the pixel value of each pixel in the image to be identified, and performs enlargement and grayscale processing on the image to be identified to obtain a grayscale image.
- the imread function is a function in computer language for reading pixel values in an image file.
- the pixel value is a value assigned by the computer when the original image is digitized.
- the image to be identified may contain multiple colors, and the color itself is very susceptible to factors such as light. There are many changes in the color of similar objects, so it is difficult for the color itself to provide key information. Therefore, graying processing is required for the image to be identified. In order to eliminate interference, reduce the complexity of the image and the amount of information processing. However, if the size of the handwritten Chinese characters in the image to be identified is small, if the grayscale processing is directly performed, the thickness of the strokes of the handwritten Chinese characters will be too small and will be excluded as interference items. Therefore, in order to increase the thickness of the text strokes, Enlarge the image to be identified, and then perform grayscale processing to avoid the grayscale processing directly, which leads to the problem that the thickness of strokes of handwritten Chinese characters is too small and excluded as interference items.
- the server enlarges the original image according to the following formula: x ⁇ x r , where x represents an element in the matrix M, r is the number of times, and the changed element x r is replaced with x in the pixel value matrix M.
- the gradation process is a process in which the image to be identified presents a noticeable black and white effect.
- performing grayscale processing on the enlarged image includes: the color of each pixel in the image to be identified is determined by three components of R (red), G (green), and B (blue), and each Each component has 256 values from 0 to 255 (0 is the darkest, and 255 is the brightest, white).
- the grayscale image is a special color image with the same three components of R, G, and B.
- the server can directly use the imread function to read the image to be identified, and the specific values of the three components of R, G, and B corresponding to each pixel in the grayscale image can be obtained.
- the standardization process refers to a process of performing a standard transformation process on a grayscale image to transform it into a fixed standard form. Specifically, because the pixel values of each pixel in the grayscale image are scattered, the magnitude of the data is not uniform, which will affect the accuracy of subsequent model recognition. Therefore, the grayscale image needs to be standardized to uniformize the magnitude of the data. .
- the server standardizes the grayscale image by using a formula for normalization processing to avoid the problem that the pixel values in the grayscale image are scattered and the order of data is not uniform.
- the standardization formula is X is the pixel value of the grayed image M
- X ′ is the pixel value of the original image
- M min is the smallest pixel value in the grayed image M
- M max is the largest pixel value in the grayed image M.
- S23 Use the kernel density estimation algorithm to process the original image, remove the background image, and obtain a target image including handwritten Chinese characters.
- the kernel density estimation algorithm is a non-parametric method that studies the data distribution characteristics from the data sample itself to estimate the probability density function.
- the target image refers to an image that contains only handwritten Chinese characters by processing the original image using a kernel density estimation algorithm.
- the server uses a kernel density estimation algorithm to process the original image to eliminate background image interference and obtain a target image including handwritten Chinese characters.
- K (.) Is the kernel function
- h is the pixel value range
- x is the pixel value of the pixel whose probability density is to be estimated
- x i is the i-th pixel value in the h range
- n is the pixel value x in the h range.
- step S23 the original image is processed by using a kernel density estimation algorithm to remove the background image to obtain a target image including handwritten Chinese characters, which specifically includes the following steps:
- S231 Perform statistics on pixel values in the original image to obtain a histogram of the original image.
- the original image histogram is a histogram obtained by statistically calculating pixel values in the original image.
- Histogram is a kind of statistical report diagram that represents the distribution of data by a series of vertical stripes or line segments of varying heights.
- the horizontal axis of the histogram of the original image represents pixel values
- the vertical axis represents the appearance frequency corresponding to the pixel values.
- the server obtains the histogram of the original image by counting the pixel values in the original image, so that it can intuitively see the distribution of the pixel values in the original image, and provides technical support for subsequent Gaussian kernel density estimation algorithms.
- the original image histogram is processed by using a Gaussian kernel density estimation algorithm to obtain at least one frequency maximum and at least one frequency minimum corresponding to the original image histogram.
- the Gaussian kernel density estimation algorithm refers to a kernel density estimation method in which the kernel function is a Gaussian kernel function.
- the formula of the Gaussian kernel function is Among them, K (x) refers to a Gaussian kernel function whose pixels (independent variables) are x, x refers to the pixel value in the original image, and e and ⁇ are constants.
- Frequency maxima refer to the maxima at different frequency intervals in the frequency distribution histogram.
- the frequency minimum value refers to the minimum value corresponding to the frequency maximum value in the same frequency interval in the frequency distribution histogram.
- a Gaussian kernel density function estimation method is used to perform Gaussian smoothing on the frequency distribution histogram corresponding to the original image, and obtain a Gaussian smooth curve corresponding to the frequency distribution histogram. Based on the frequency maxima and frequency minima on the Gaussian smooth curve, obtain the pixel values on the horizontal axis corresponding to the frequency maxima and frequency minima in order to subsequently based on the obtained frequency maxima and frequency minima Corresponding pixel values are convenient for hierarchical segmentation of the original image to obtain a layered image.
- S233 Perform hierarchical segmentation processing on the original image based on the frequency maximum and frequency minimum to obtain a layered image.
- the layered image is an image obtained by performing layered segmentation processing on the original image based on the maximum and minimum values.
- the server first obtains the pixel values corresponding to the maximum frequency value and the minimum frequency value, and processes the original image according to the pixel values corresponding to the maximum frequency value. How many frequency maximum values are in the original image, the corresponding original image The number of pixel values is divided into classes; then the pixel value corresponding to the minimum frequency value is used as the boundary value between the classes, and the original image is layered according to the class and the boundary between the classes to obtain the layering image.
- the pixel values corresponding to the frequency maximum in the original image are 11, 53, 95, 116, and 158, and the pixel values corresponding to the minimum frequency are 21, 63, 105, and 135, respectively.
- the number of frequency maxima in the original image it can be determined that the pixel values of the original image can be divided into 5 categories, the original image can be divided into 5 layers, and the pixel values corresponding to the frequency minima are used as the Boundary value, because the minimum pixel value is 0 and the maximum pixel value is 255.
- a layered image with a pixel value of 11 can be determined, and the pixel value corresponding to the layered image is [ 0,21); a layered image with a pixel value of 53 and the corresponding pixel value is [21,63); a layered image with a pixel value of 95 and the corresponding pixel value is [ 63,105); a layered image with a pixel value of 116 and the corresponding pixel value is [105,135); a layered image with a pixel value of 158 and the corresponding layer value is [135,255].
- S234 Obtain a target image including handwritten Chinese characters based on the layered image.
- the server After obtaining the layered image, the server performs binarization, erosion, and superposition processing on the layered image to obtain a target image including handwritten Chinese characters.
- the binarization process refers to a process in which the pixel value of a pixel on a layered image is set to 0 (black) or 1 (white), and the entire layered image presents an obvious black and white effect.
- the binarized layered image is corroded to remove the background image part and retain the handwritten Chinese characters on the layered image. Because the pixel values on each layered image are pixel values belonging to different ranges, after the layered image is corroded, each layered image needs to be superimposed to generate a target image containing only handwritten Chinese characters.
- the superimposing process refers to a process of superimposing a layered image with only a handwritten portion into an image, thereby achieving the purpose of obtaining a target image containing only handwritten Chinese characters.
- the layered image is superimposed using the imadd function to obtain a target image containing only handwritten Chinese characters.
- the imadd function is a function in computer language for superimposing layered images.
- step S234 that is, based on the layered image, obtaining a target image including handwritten Chinese characters, specifically includes the following steps:
- a binarized image refers to an image obtained by binarizing a sub-image. Specifically, after the server obtains the layered image, it compares the sampled pixel value of the layered image with a preselected threshold, and sets the pixel value greater than or equal to the threshold to 1 and the pixel value less than the threshold to 0. process.
- the sampled pixel value is the pixel value corresponding to each pixel point in the layered image.
- the size of the threshold value will affect the effect of the binarization process of the layered image. When the threshold value is selected properly, the effect of the binarization process on the layered image is better; when the threshold value is not selected properly, the effect of the binarization process of the layered image will be affected. effect.
- the threshold in this embodiment is determined by the developer based on experience. Binarize the layered image to facilitate subsequent corrosion treatment.
- S2342 Detect pixels in the binarized image to obtain a connected area corresponding to the binarized image.
- the connected area refers to an area surrounded by adjacent pixels around a specific pixel.
- a connected region means that the neighboring pixels around it are all 0, and a specific pixel and the neighboring pixel are 1, for example, a particular pixel is 0, and the surrounding neighboring pixels are 1, and the neighboring pixels are surrounded.
- the resulting area is used as the connected area.
- the binarized image corresponds to a pixel matrix, which includes rows and columns.
- Detecting pixels in a binarized image specifically includes the following processes: (1) Scan the pixel matrix line by line, group consecutive white pixels in each line into a sequence called a cluster, and note its starting point, End point and line number.
- the etching process is an operation for removing the content of a part of an image in morphology.
- the built-in imerode function is used to etch the connected areas of the binary image.
- etching the connected region corresponding to the binarized image includes the following steps: First, an n ⁇ n structural element is selected. In this embodiment, the value of 8 elements adjacent to each element in the pixel matrix is used as The connected region of this element is, therefore, the selected structural element is a 3 ⁇ 3 pixel matrix.
- the structural element is an n ⁇ n pixel matrix, where the matrix elements include 0 or 1.
- the binarized image is filtered based on the preset anti-corrosion capability range of the hand-written region. Partial deletion of the binary image that is not within the anti-corrosion capability of the hand-written region is obtained to obtain the anti-corrosion capability of the hand-written region in the binary image Within the range.
- the target pixel image containing only handwritten Chinese characters can be obtained by superimposing the pixel matrix corresponding to each binarized image portion that fits the range of the corrosion resistance of the handwritten area.
- the anti-corrosion ability of the hand-written area can adopt the formula: Calculated, s 1 represents the total area after being corroded in the binarized image, s 2 represents the total area before being corroded in the binarized image, and p is the corrosion resistance of the handwritten area.
- the preset anti-corrosion range of the handwriting area is [0.01, 0.5], according to the formula Calculate the ratio p between the total area of each binarized image and the total area before the binarized image.
- the ratio p of the total area after erosion to the total area before erosion in the binarized image which is not in the range of the anti-corrosion capability of the handwritten area, it means that the binarized image of the area is a background image instead of Write by hand and need to be etched to remove the background image.
- the ratio p of the total area after erosion to the total area before erosion in the binarized image is in the range of [0.01, 0.5], it means that the binarized image of the region is a handwritten Chinese character and needs to be retained.
- the pixel matrix corresponding to the retained binary image is superimposed to obtain a target image containing handwritten Chinese characters.
- the binarized image is binarized to obtain a binarized image, and then pixels in the binarized image are detected and labeled to obtain a connected area corresponding to the binarized image.
- the elements in the identical pixel matrix all become 0, the binarized image with element 0 is black, and the black part is the corroded part of the binarized image.
- the total area of the binarized image is calculated by calculating And the ratio of the total area of the binarized image before being eroded, to determine whether the ratio is within the preset anti-corrosion range of the handwriting area, in order to remove the background image in each layered image, retain the handwritten Chinese characters, and finally replace each A layered image is superimposed to achieve the purpose of obtaining the target image.
- S24 Single-font cutting is performed on the target image using a vertical projection method to obtain a single-word image to be recognized.
- the cutting process of single font cutting of the target image by the vertical projection method is the same as step S12. To avoid repetition, details are not described herein again.
- the single character image to be recognized is a single font image used for input model recognition.
- S25 Input the single character image to be recognized into the target handwriting recognition model for recognition, and obtain a handwritten Chinese character corresponding to each single character image to be recognized.
- the target handwriting recognition model is acquired using a handwriting model training method.
- the server inputs the to-be-recognized word image into the target handwriting recognition model for recognition, so that the target handwriting recognition model can contact the context for recognition, obtain handwritten Chinese characters corresponding to each to-be-recognized word image, and improve recognition accuracy.
- a user may collect an image to be identified containing handwritten Chinese characters and upload it to a server through a collection module on a computer device, so that the server obtains the image to be identified. Then, the server preprocesses the to-be-recognized image and obtains an original image that excludes interference factors. Kernel density estimation algorithm is used to process the original image, remove the background image, and obtain the target image containing only handwritten Chinese characters to further eliminate interference. The vertical projection method is used to cut the single font of the target image to obtain the single character image to be recognized, which is easy to implement.
- the server inputs the to-be-recognized word image into the target handwriting recognition model based on the long-term and short-term memory neural network for recognition, so that the to-be-recognized word image has timeliness, so that the target handwriting recognition model can contact the context for recognition and obtain each Recognize handwritten Chinese characters corresponding to single-word images, and improve the accuracy of recognition.
- a handwritten image recognition device corresponds to the handwritten image recognition method in the above embodiment in a one-to-one correspondence.
- the handwritten image recognition device includes an image acquisition module 21, an original image acquisition module 22, a target image acquisition module 23, a single character image acquisition module 24, and a handwritten Chinese character acquisition module 25.
- the detailed description of each function module is as follows:
- the to-be-recognized image acquisition module 21 is configured to obtain the to-be-recognized image, where the to-be-recognized image includes a handwritten Chinese character and a background picture.
- the original image obtaining module 22 is configured to preprocess the image to be identified to obtain an original image.
- a target image acquisition module 23 is configured to process the original image by using a kernel density estimation algorithm, remove a background picture, and obtain a target image including handwritten Chinese characters.
- the to-be-recognized single-word image acquisition module 24 is configured to perform single-font cutting on the target image by using a vertical projection method to obtain the to-be-recognized single-word image.
- a handwritten Chinese character acquisition module 25 is configured to input an image of a to-be-recognized character into a target handwriting recognition model for recognition, and obtain a handwritten Chinese character corresponding to each image of the to-be-recognized word; wherein the target handwriting recognition model adopts Obtained by the model training method.
- the original image acquisition module 22 includes a grayscale image acquisition unit 221 and an original image acquisition unit 222.
- a grayscale image acquisition unit 221 is configured to perform enlargement and grayscale processing on an original image to obtain a grayscale image.
- the original image obtaining unit 222 is configured to perform normalization processing on the grayscale image to obtain the original image.
- the formula of the normalization processing is: X is the pixel value of the grayed image M, X ′ is the pixel value of the original image, M min is the smallest pixel value in the grayed image M, and M max is the largest pixel value in the grayed image M.
- the target image acquisition module 23 includes an original image histogram acquisition unit 231, a frequency extreme value acquisition unit 232, a layered image acquisition unit 233, and a target image acquisition unit 234.
- the original image histogram obtaining unit 231 is configured to perform statistics on pixel values in the original image to obtain a histogram of the original image.
- a frequency extreme value acquisition unit 232 is configured to process a histogram of the original image by using a Gaussian kernel density estimation algorithm, and obtain at least one frequency maximum value and at least one frequency extreme value acquisition unit corresponding to the histogram of the original image. Small value.
- a layered image acquisition unit 233 is configured to perform layered segmentation processing on the original image based on the frequency maximum and frequency minimum to obtain a layered image.
- the target image acquisition unit 234 is configured to acquire a target image including a handwritten Chinese character based on the layered image.
- the target image acquisition unit 234 includes a binarized image acquisition subunit 2341, a connected region acquisition subunit 2342, and a target image acquisition subunit 2343.
- a binarized image acquisition subunit 2341 is configured to perform binarization processing on the layered image to obtain a binarized image.
- the connected region acquisition subunit 2342 is configured to detect pixels in the binarized image and obtain a connected region corresponding to the binarized image.
- a target image acquisition subunit 2343 is configured to perform erosion and superposition processing on the connected areas corresponding to the binary image, and acquire a target image including handwritten Chinese characters.
- Each module in the above-mentioned handwritten image recognition device may be implemented in whole or in part by software, hardware, and a combination thereof.
- the above-mentioned modules may be embedded in the hardware in or independent of the processor in the computer device, or may 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.
- a computer device is provided.
- the computer device may be a server, and its internal structure diagram may be as shown in FIG. 10.
- the computer device includes a processor, a memory, a network interface, and a database connected through a system bus.
- 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, computer-readable instructions, and a database.
- the internal memory provides an environment for the operation of the operating system and computer-readable instructions in a non-volatile storage medium.
- the database of the computer device is used to store data generated or obtained during the execution of the handwritten image recognition method, such as handwritten Chinese characters.
- the network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer-readable instructions are executed by one or more processors, the one or more processors are executed to implement a handwritten image recognition method.
- a computer device including a memory, a processor, and computer-readable instructions stored on the memory and executable on the processor.
- the processor executes the computer-readable instructions, the processor implements the following steps: Recognize the image, the image to be recognized includes handwritten Chinese characters and background pictures; preprocess the image to be recognized to obtain the original image; use the kernel density estimation algorithm to process the original image, remove the background image, and obtain the target image including the handwritten Chinese characters; use vertical projection Method to perform single font cutting on the target image to obtain the to-be-recognized word image; input the to-be-recognized word image to the target handwriting recognition model for recognition, and obtain handwritten Chinese characters corresponding to each to-be-recognized word image; of which the target handwriting recognition model It was acquired using handwriting model training methods.
- the processor executes the computer-readable instructions, the following steps are further implemented: the pixel values in the original image are counted to obtain the original image histogram; the Gaussian kernel density estimation method is used to process the original image histogram to obtain At least one frequency maximum and at least one frequency minimum corresponding to the original image histogram; performing hierarchical segmentation processing on the original image based on the frequency maximum and frequency minimum to obtain a layered image; based on the layered image To get the target image including handwritten Chinese characters.
- the processor when the processor executes the computer-readable instructions, the following steps are further implemented: binarizing the layered image to obtain a binarized image; detecting pixels in the binarized image to obtain a kernel density
- the estimation algorithm corresponds to the connected area of the binary image; the connected area of the binary image is corroded and superimposed to obtain a target image including handwritten Chinese characters.
- one or more non-volatile readable storage media storing computer-readable instructions are provided, and when the computer-readable instructions are executed by one or more processors, the one or more The processor executes the following steps: obtaining an image to be identified, the image to be identified includes handwritten Chinese characters and a background image; preprocessing the image to be identified to obtain the original image; processing the original image using a kernel density estimation algorithm to remove the background image, Obtain the target image including handwritten Chinese characters; use the vertical projection method to cut the single image of the target image to obtain the image of the single character to be recognized; input the image of the single character to be recognized into the target handwriting recognition model to obtain the corresponding image of each single character
- the handwritten Chinese character recognition model is obtained by using the handwriting model training method; the target handwriting recognition model is obtained by using the handwriting model training method.
- the execution of the one or more processors further implements the following steps: performing statistics on pixel values in the original image to obtain the original Image histogram; Gaussian kernel density estimation method is used to process the original image histogram to obtain at least one frequency maximum and at least one frequency minimum corresponding to the original image histogram; based on the frequency maximum and frequency minimum
- the original image is subjected to layered segmentation processing to obtain a layered image; based on the layered image, a target image including handwritten Chinese characters is obtained.
- the execution of the one or more processors further implements the following steps: binarizing the layered image to obtain two Digitized image; detect and mark the pixels in the binarized image to obtain the connected area corresponding to the kernel density estimation algorithm binarized image; etch and overlay the connected area corresponding to the binarized image to obtain handwritten Chinese characters The target image.
- Non-volatile memory may 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.
- RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Multimedia (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Evolutionary Computation (AREA)
- Evolutionary Biology (AREA)
- General Engineering & Computer Science (AREA)
- Bioinformatics & Computational Biology (AREA)
- Artificial Intelligence (AREA)
- Life Sciences & Earth Sciences (AREA)
- Character Discrimination (AREA)
- Image Analysis (AREA)
Abstract
本申请公开一种手写模型训练、手写图像识别方法、装置、设备及介质,该手写模型训练方法包括:获取训练手写中文图像;采用垂直投影法对训练手写中文图像进行单字体切割,获取训练单字体图像;将训练单字体图像按预设比例划分成训练集和测试集;对训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;采用测试集中的训练单字体图像对原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。该手写模型训练方法具有训练效率高且识别精度高的优点。
Description
本专利申请以2018年6月4日提交的申请号为201810564693.5,名称为“手写模型训练、手写图像识别方法、装置、设备及介质”的中国发明专利申请为基础,并要求其优先权。
本申请涉及图像识别领域,尤其涉及一种手写模型训练、手写图像识别方法、装置、设备及介质。
随着信息时代的发展,人工智能技术作为核心技术越来越多的被用来解决人们生活中的具体问题。目前,在对手写汉字图像进行识别时,由于汉字的结构比较复杂,比如“魍、魉”,并且汉字中存在着较多的结构相似的字,比如“今和令”,会出现识别准确率较低的情况。对标准的、书写简单且规范的句子,采用OCR(光学字符识别)技术可以识别,但是对于手写字组成的句子,由于每个人的书写习惯不相同且不是标准的汉字,当采用OCR技术识别时,会降低识别的准确率,影响手写汉字的识别效果。
发明内容
基于此,有必要针对上述技术问题,提供一种手写模型训练、手写图像识别方法、装置、设备及介质。
一种手写模型训练方法,包括:
获取训练手写中文图像;
采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;
将所述训练单字体图像按预设比例划分成训练集和测试集;
对所述训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;
采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
一种手写模型训练装置,包括:
训练手写中文图像获取模块,用于获取训练手写中文图像;
训练手写中文图像划分模块,用于将所述训练手写中文图像按预设比例划分成训练集和测试集;
训练单字体图像获取模块,用于采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;
原始手写字识别模型获取模块,用于对所述训练集中的训练单字体图像进行顺序标注,并将标注好的单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;
目标手写字识别模型获取模块,用于采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,所述处理器执行所述计算机可读指令时实现如下步骤:
获取训练手写中文图像;
采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;
将所述训练单字体图像按预设比例划分成训练集和测试集;
对所述训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;
采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:
获取训练手写中文图像;
采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;
将所述训练单字体图像按预设比例划分成训练集和测试集;
对所述训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;
采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
一种手写图像识别方法,包括:
获取待识别图像,所述待识别图像包括手写汉字和背景图片;
对所述待识别图像进行预处理,获取原始图像;
采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;
采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;
将所述待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用所述手写模型训练方法获取的。
一种手写图像识别装置,包括:
待识别图像获取模块,用于获取待识别图像,所述待识别图像包括手写汉字和背景图片;
原始图像获取模块,用于对所述待识别图像进行预处理,获取原始图像;
目标图像获取模块,用于采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;
待识别单字图像获取模块,用于采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;
手写汉字获取模块,用于将待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用所述手写模型训练方法获取的。
一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,所述处理器执行所述计算机可读指令时实现如下步骤:
获取待识别图像,所述待识别图像包括手写汉字和背景图片;
对所述待识别图像进行预处理,获取原始图像;
采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;
采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;
将所述待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别 单字图像对应的手写汉字;其中,目标手写字识别模型是采用所述手写模型训练方法获取的。
一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:
获取待识别图像,所述待识别图像包括手写汉字和背景图片;
对所述待识别图像进行预处理,获取原始图像;
采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;
采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;
将所述待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用所述手写模型训练方法获取的。
本申请的一个或多个实施例的细节在下面的附图及描述中提出。本申请的其他特征和优点将从说明书、附图以及权利要求书变得明显。
为了更清楚地说明本申请实施例的技术方案,下面将对本申请实施例的描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1是本申请一实施例中手写模型训练方法或手写图像识别方法的一应用场景图;
图2是本申请一实施例中手写模型训练方法的一流程图;
图3是图2中步骤S14的一具体流程图;
图4是本申请一实施例中手写模型训练装置的一示意图;
图5是本申请一实施例中手写图像识别方法的一流程图;
图6是图5中步骤S22的一具体流程图;
图7是图5中步骤S23的一具体流程图;
图8是图7中步骤S234的一具体流程图;
图9是本申请一实施例中手写图像识别装置的一示意图;
图10是本申请一实施例中计算机设备的一示意图。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
本申请实施例提供的手写模型训练方法,可应用在如图1的应用环境中。该手写模型训练方法的应用环境包括服务器和计算机设备,其中,计算机设备通过网络与服务器进行通信,计算机设备是可与用户进行人机交互的设备,包括但不限于电脑、智能手机和平板等设备。本申请实施例提供的手写模型训练方法应用于服务器。
在一实施例中,如图2所示,提供一种手写模型训练方法,以该方法应用在图1中的服务器为例进行说明,包括如下步骤:
S11:获取训练手写中文图像。
其中,训练手写中文图像是预先从开源库中采集的用于进行模型训练的样本图像。该训练手写中文图像包括中文二级字库中每一中文对应的N(N为正整数)张手写字样本。 中文二级字库是按汉字的部首笔划顺序编码的非常用汉字库。具体地,采集开源库中的不同人手写的N张手写字样本,以使服务器获取训练手写中文图像,由于不同用户的书写习惯不同,因此采用N张手写字样本(即训练手写中文图像)进行训练,极大的提高了模型的泛化性。
S12:采用垂直投影法对训练手写中文图像进行单字体切割,获取训练单字体图像。
其中,垂直投影法是指将每一行手写汉字进行垂直方向的投影,获取垂直投影直方图的方法。垂直投影直方图是指反映目标图像在垂直方向上的像素个数。
具体地,采用垂直投影法对训练手写中文图像进行单字体切割具体包括如下步骤:服务器对训练手写中文图像中的至少一行手写汉字逐行进行扫描,获取每一行手写汉字对应的像素值,根据每一像素值对应的垂直投影直方图,获取不同像素值对应的像素数量,按照垂直投影直方图中的极小值,对训练手写中文图像进行循环切割,获取训练单字体图像。可以理解地,每一个手写汉字对应的像素值是比较集中的,汉字与汉字之间的间隙对应的像素值是比较稀疏的,对应的像素值的密集程度反应在对应的垂直投影直方图中,则在垂直投影直方图中有汉字的像素值对应的像素数量比较高,没有汉字的像素值对应的像素数量比较低,通过垂直投影法能够有效对训练手写中文图像进行单字体切割,获取训练单字体图像,实现简单,提高训练效率。
S13:将训练单字体图像按预设比例划分成训练集和测试集。
其中,训练集(training set)是学习样本数据集,是通过匹配一些参数来建立分类器,即采用训练集中的目标训练文本数据来训练机器学习模型,以确定机器学习模型的参数。测试集(test set)是用于测试训练好的机器学习模型的分辨能力,如准确率。预设比例是预先设置的用于对训练手写中文图像进行划分的比例。本实施例中,可按照9:1的比例对训练单字体图像进行划分,即可将90%的训练单字体图像作为训练集,剩余10%的训练单字体图像作为测试集。
S14:对训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型。
其中,原始手写字识别模型是经过长短时记忆神经网络多次迭代所得到的模型。长短时记忆神经(long-short term memory,简称LSTM)网络是一种时间递归神经网络,适合于处理和预测具有时间序列,且时间序列间隔和延迟相对较长的重要事件。
具体地,服务器按照训练单字体图像的时间顺序进行标注,并将标注好的训练单字体图像输入到目标手写字识别模型中进行训练,获取原始手写字识别模型。可以理解地,每个训练单字体图像都是按顺序排列的,例如原始图像为“今天很开心”,则可按照从左到右以***数字对每个训练单字体图像进行标注,即“今(1)天(2)很(3)开(4)心(5)”,以使训练单字体图像具备时序性,使得原始手写字识别模型能够联系上下文进行训练,提高模型的准确率。
批量梯度下降算法是每次在更新网络参数时,采用训练集中的所有样本(训练单字体图像)来进行更新,能够得到全局最优解,提高模型准确率。网络参数是长短时记忆神经网络的各层之间的权值和偏置。长短时记忆神经网络具有时间记忆功能,因而用来处理携带时序状态的训练单字体图像。
长短时记忆神经网络具有一输入层、至少一个隐藏层和一输出层的网络结构。其中,输入层是长短时记忆神经网络的第一层,用于接收外界信号,即负责接收训练单字体图像。输出层是长短时记忆神经网络的最后一层,用于向外界输出信号,即负责输出长短时记忆神经网络的计算结果。隐藏层是长短时记忆神经网络中除输入层和输出层之外的各层,用于对训练单字体图像进行处理,获取长短时记忆神经网络的计算结果。可以理解地,采用长短时记忆神经网络进行模型训练增加了训练单字体图像的时序性,以便根据上下文对训 练单字体图像进行训练,从而提高了目标手写字识别模型的准确率。本实施例中,长短时记忆神经网络的输出层采用Softmax(回归模型)进行回归处理,用于分类输出权值矩阵。Softmax(回归模型)是一种常用于神经网络的分类函数,它将多个神经元的输出,映射到[0,1]区间内,可以理解成概率,计算起来简单方便,从而来进行多分类输出,使其输出结果更准确。
在一实施例中,如图3所示,步骤S14中,即对训练单字体图像进行顺序标注,并将标注好的单字体图像输入到长短时记忆神经网络中进行训练,获取目标手写字识别模型,具体包括如下步骤:
S141:在长短时记忆神经网络的隐藏层采用第一激活函数对训练单字体图像进行处理,获取携带激活状态标识的神经元。
其中,长短时记忆神经网络的隐藏层中的每个神经元包括三个门,其分别为输入门、遗忘门和输出门。遗忘门决定了在神经元中所要丢弃的过去的信息。输入门决定了在神经元中所要增加的信息。输出门决定了在神经元中所要输出的信息。第一激活函数是用于激活神经元状态的函数。神经元状态决定了各个门(即输入门、遗忘门和输出门)的丢弃、增加和输出的信息。激活状态标识包括通过标识和不通过标识。本实施例中的输入门、遗忘门和输出门对应的标识分别为i、f和o。
本实施例中,具体选用Sigmoid(S型生长曲线)函数作为第一激活函数,Sigmoid函数是一个在生物学中常见的S型的函数,在信息科学中,由于其单增以及反函数单增等性质,Sigmoid函数常被用作神经网络的阈值函数,将变量映射到0,1之间。第一激活函数的计算公式为
其中,z表示遗忘门的输出值。
具体地,遗忘门中包括遗忘门限,通过计算每一神经元(训练单字体图像)的激活状态,以获取携带激活状态标识为通过标识的神经元。其中,采用遗忘门的计算公式f
t=σ(W
f·[h
t-1,x
t]+b
f)计算遗忘门哪些信息被接收(即只接收携带激活状态标识为通过标识的神经元),f
t表示遗忘门限(即激活状态),W
f表示遗忘门的权重矩阵,b
f表示遗忘门的权值偏置项,h
t-1表示上一时刻神经元的输出,x
t表示当前时刻的输入数据(即训练单字体图像),t表示当前时刻,t-1表示上一时刻。遗忘门中还包括遗忘门限,通过遗忘门的计算公式对训练单字体图像进行计算会得到一个0-1区间的标量,此标量决定了神经元根据当前状态和过去状态的综合判断所接收过去信息的比例,以达到数据的降维,减少计算量,提高训练效率。
S142:在长短时记忆神经网络的隐藏层采用第二激活函数对携带激活状态标识的神经元进行处理,获取长短时记忆神经网络隐藏层的输出值。
其中,长短时记忆神经网络隐藏层的输出值包括输入门的输出值、输出门的输出值和神经元状态。具体地,在长短时记忆神经网络的隐藏层中的输入门中,采用第二激活函数携带激活状态标识为通过标识的神经元进行计算,获取隐藏层的输出值。本实施例中,由于线性模型的表达能力不够,因此采用tanh(双曲正切)函数作为输入门的激活函数(即第二激活函数),可加入非线性因素使得训练出的目标手写字识别模型能够解决更复杂的问题。并且,激活函数tanh(双曲正切)具有收敛速度快的优点,可以节省训练时间,增加训练效率。
具体地,通过输入门的计算公式计算输入门的输出值。其中,输入门中还包括输入门限,输入门的计算公式为i
t=σ(W
i·[h
t-1,x
t]+b
i),其中,W
i为输入门的权值矩阵,i
t表 示输入门限,b
i表示输入门的偏置项,,通过输入门的计算公式对训练单字体图像进行计算会得到一个0-1区间的标量(即输入门限),此标量控制了神经元根据当前状态和过去状态的综合判断所接收当前信息的比例,即接收新输入的信息的比例,以减少计算量,提高训练效率。
然后,采用神经元状态的计算公式
和
计算当前神经元状态;其中,W
c表示计算单元状态的权重矩阵,b
c表示单元状态的偏置项,
表示上一时刻的神经元状态,C
t表示当前时刻神经元状态。通过将神经元状态和遗忘门限(输入门限)进行点乘操作,以便模型只输出所需的信息,提高模型学习的效率。
最后,采用输出门的计算公式o
t=σ(W
o[h
t-1,x
t]+b
o)计算输出门中哪些信息被输出,再采用公式h
t=o
t*tanh(C
t)计算当前时刻神经元的输出值,其中,o
t表示输出门限,W
o表示输出门的权重矩阵,b
o表示输出门的偏置项,h
t表示当前时刻神经元的输出值。
S143:根据长短时记忆神经网络隐藏层的输出值,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取目标手写字识别模型。
其中,长短时记忆神经网络的网络参数是指长短时记忆神经网络各层之间的权值和偏置。批量梯度下降算法的公式具体为:
和
其中,J(θ)为损失函数,m表示训练集中训练单字体图像的数量,θ
j为第j层长短时记忆神经网络的网络参数,h
θ(x)表示长短时记忆神经网络隐藏层的输出值,(x
i,y
i)表示第i个训练单字体图像。
首先,根据损失函数构建公式
构建损失函数。通过公式
对损失函数进行求偏导运算,以更新网络参数即更新各层之间的权值和偏置,将获取的更新后的各层的权值和偏置,应用到长短时记忆神经网络中即可获取目标手写字识别模型。
进一步地,该目标手写字识别模型中的各权值实现了目标手写字识别模型决定丢弃哪些旧信息、增加哪些新信息以及输出哪些信息的功能。在目标手写字识别模型的输出层最终会输出概率值,该概率值是指训练单字体图像识别出对应的汉字的概率,可广泛应用于手写字识别方面,以达到准确识别训练单字体图像的目的。
S15:采用测试集中的训练单字体图像对原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
具体地,步骤S15中,将测试集中所有训练单字体图像输入原始手写字识别模型进行 测试,获取测试准确率(即将所有原始手写字识别模型预测结果准确的数量除以训练集中所有训练单字体图像的数量)。再判断测试准确率是否大于预设准确率,若测试准确率大于预设准确率,则认定该原始手写字识别模型较准确,以将该原始手写字识别模型作为目标手写字识别模型;反之,若测试准确率不大于预设准确率,则认定该原始手写字识别模型的预测结果不够准确,仍需再采用步骤S11-S14进行训练后,再次进行测试,直至测试准确率达到预设准确率,停止训练,进一步提高目标手写字识别模型准确率。
本实施例中,先获取训练手写中文图像,采用垂直投影法对训练手写字图像进行单字体切割,获取训练单字体图像,并按预设比例将训练单字体图像划分成训练集和测试集,以便对训练集中的训练单字体图像进行顺序标注,以使训练单字体图像具备时序性。将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,根据训练单字体图像的时序性,以便长短时记忆神经网络根据上下文对训练单字体图像进行训练,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型,从而提高了模型准确率。最后,采用测试集中的训练单字体图像对原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型,进一步提高了目标手写字识别模型的准确率。
在一实施例中,提供一种手写模型训练装置,该手写模型训练装置与上述实施例中手写模型训练方法一一对应。如图4所示,该手写模型训练装置包括训练手写中文图像获取模块11、训练手写中文图像划分模块12、训练单字体图像获取模块13、原始手写字识别模型获取模块14和目标手写字识别模型获取模块15,各功能模块详细说明如下:
训练手写中文图像获取模块11,用于获取训练手写中文图像;
训练手写中文图像划分模块12,用于将训练手写中文图像按预设比例划分成训练集和测试集;
训练单字体图像获取模块13,用于采用垂直投影法对训练手写中文图像进行单字体切割,获取训练单字体图像;
原始手写字识别模型获取模块14,用于对训练集中的训练单字体图像进行顺序标注,并将标注好的单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;
目标手写字识别模型获取模块15,用于采用测试集中的训练单字体图像对原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
具体地,原始手写字识别模型获取模块14包括激活状态神经元获取单元141、隐藏层输出值获取单元142和目标识别模型获取单元143。
激活状态神经元获取单元141,用于在长短时记忆神经网络的隐藏层采用第一激活函数对训练单字体图像进行处理,获取携带激活状态标识的神经元。
隐藏层输出值获取单元142,用于在长短时记忆神经网络的隐藏层采用第二激活函数对携带激活状态标识的神经元进行处理,获取长短时记忆神经网络隐藏层的输出值。
目标识别模型获取单元143,用于根据长短时记忆神经网络隐藏层的输出值,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取目标手写字识别模型。
具体地,批量梯度下降算法的公式具体为:
和
其中,J(θ)为损失函数,m表示训练集中训练单字体图像的数量,θ
j为第j层长短时记忆神经网络的网络参数,h
θ(x)表示长短时记忆神经网络隐藏层的输出值,(x
i,y
i)表示第i个训练单字体图像。
关于手写模型训练装置的具体限定可以参见上文中对于手写模型训练方法的限定,在此不再赘述。上述手写模型训练装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。
在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图10所示。该计算机设备包括通过***总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作***、计算机可读指令和数据库。该内存储器为非易失性存储介质中的操作***和计算机可读指令的运行提供环境。该计算机设备的数据库用于用于存储执行手写模型训练方法过程中生成或获取的数据,如目标手写字识别模型。该计算机设备的网络接口用于与外部的终端通过网络连接通信。所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行时以实现一种手写模型训练方法。
在一个实施例中,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机可读指令,处理器执行计算机可读指令时实现以下步骤:获取训练手写中文图像;采用垂直投影法对训练手写中文图像进行单字体切割,获取训练单字体图像;将训练单字体图像按预设比例划分成训练集和测试集;对训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;采用测试集中的训练单字体图像对原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
在一个实施例中,处理器执行计算机可读指令时还实现以下步骤:在长短时记忆神经网络的隐藏层采用第一激活函数对训练单字体图像进行处理,获取携带激活状态标识的神经元;在长短时记忆神经网络的隐藏层采用第二激活函数对携带激活状态标识的神经元进行处理,获取长短时记忆神经网络隐藏层的输出值;根据长短时记忆神经网络隐藏层的输出值,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取目标手写字识别模型。
具体地,批量梯度下降算法的公式具体为:
和
其中,J(θ)为损失函数,m表示训练集中训练单字体图像的数量,θ
j为第j层长短时记忆神经网络的网络参数,h
θ(x)表示长短时记忆神经网络隐藏层的输出值,(x
i,y
i)表示第i个训练单字体图像。
在一个实施例中,提供了一种非易失性存储介质,其上存储有计算机可读指令,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行时实现以下步骤:获取训练手写中文图像;采用垂直投影法对训练手写中文图像进行单字体切割,获取训练单字体图像;将训练单字体图像按预设比例划分成训练集和测试集;对训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;采用测试集中的训练单字体图像对原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
在一个实施例中,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或 多个处理器执行时还实现以下步骤:在长短时记忆神经网络的隐藏层采用第一激活函数对训练单字体图像进行处理,获取携带激活状态标识的神经元;在长短时记忆神经网络的隐藏层采用第二激活函数对携带激活状态标识的神经元进行处理,获取长短时记忆神经网络隐藏层的输出值;根据长短时记忆神经网络隐藏层的输出值,采用批量梯度下降算法对长短时记忆神经网络的网络参数进行更新,获取目标手写字识别模型。
具体地,批量梯度下降算法的公式具体为:
和
其中,J(θ)为损失函数,m表示训练集中训练单字体图像的数量,θ
j为第j层长短时记忆神经网络的网络参数,h
θ(x)表示长短时记忆神经网络隐藏层的输出值,(x
i,y
i)表示第i个训练单字体图像。
在一实施例中,如图5所示,提供一种手写图像识别方法,以该方法应用在图1中的服务器为例进行说明,包括如下步骤:
S21:获取待识别图像,待识别图像包括手写汉字和背景图片。
其中,待识别图像是由计算机设备上的采集模块采集到的未经处理的包含手写汉字的图像。该待识别图像包括手写汉字和背景图片。背景图片是待识别图像中除手写汉字之外的噪声图片。噪声图片是对手写汉字造成干扰的图片。本实施例中,用户可通过计算机设备上的采集模块采集包含手写汉字的待识别图像上传到服务器,以使服务器获取待识别图像。该采集模块包括但不限于相机拍摄和本地上传。
S22:对待识别图像进行预处理,获取原始图像。
其中,原始图像是对待识别图像进行预处理后得到的排除干扰因素的图像。具体地,由于待识别图像中可能包含多种干扰因素,如色彩繁多,不利于后续的识别。因此需要对待识别图像进行预处理,以获取排除干扰因素的原始图像,该原始图像可以理解为待识别图像排除背景图片后获取的图片。
在一实施例中,如图6所示,步骤S22中,即对待识别图像进行预处理,获取原始图像,具体包括如下步骤:
S221:对待识别图像进行放大和灰度化处理,获取灰度化图像。
其中,灰度化图像是对待识别图像进行放大和灰度化处理后获取的灰度化图像。该灰度化图像包括一像素值矩阵。像素值矩阵是指包含待识别图像中每个像素对应的像素值的矩阵。本实施例中,服务器采用imread函数读取待识别图像中每个像素的像素值,并对待识别图像进行放大和灰度化处理,获取灰度化图像。imread函数是计算机语言中的一个函数,用于读取图像文件中的像素值。像素值是原始图像被数字化时由计算机赋予的值。
由于待识别图像中可能包含多种颜色,而颜色本身,非常容易受到光照等因素的影响,同类的物体颜色有很多变化,所以颜色本身难以提供关键信息,因此需要对待识别图像进行灰度化处理,以排除干扰,减少图像的复杂度和信息处理量。但由于待识别图像中的手写汉字的尺寸较小时,若直接进行灰度化处理,会导致手写汉字的笔画的厚度过小,会被当成干扰项排除,因此为了增加文字笔画的厚度,需先将待识别图像进行放大处理,再进行灰度化处理,以避免直接进行灰度化处理,导致手写汉字的笔画的厚度过小被当成干扰项排除的问题。
具体地,服务器按照如下公式对原始图像进行放大处理:x→x
r,其中,x代表矩阵M中的元素,r为次数,将变化后的元素x
r替换像素值矩阵M中x。
灰度化处理是将待识别图像呈现出明显的黑白效果的处理。具体地,对放大后的图像进行灰度化处理包括:待识别图像中的每个像素的颜色都是通过R(红)、G(绿)和B(蓝)三个分量决定的,而每个分量有0-255这256种值可取(0最暗表示黑色,255最亮表示白色)。而灰度化图像是R、G和B三个分量相同的一种特殊的彩色图像。本实施例中,服务器可直接采用imread函数读取待识别图像,即可获取灰度化图像中每个像素对应的R、G和B三个分量的具体数值。
S222:对灰度化图像进行标准化处理,获取原始图像。
其中,标准化处理是指对灰度化图像进行标准的变换处理,使之变换为一固定标准形式的处理。具体地,由于灰度化图像中每个像素的像素值比较分散,导致数据的数量级不统一,会影响后续模型识别的准确率,因此需要将灰度化图像进行标准化处理,以统一数据的数量级。
具体地,服务器采用标准化处理的公式对灰度化图像进行标准化处理,以避免灰度化图像中像素值较分散,导致数据的数量级不统一的问题。其中,标准化处理的公式为
X是灰度化图像M的像素值,X′是原始图像的像素值,M
min是灰度化图像M中最小的像素值,M
max是灰度化图像M中最大的像素值。
S23:采用核密度估计算法对原始图像进行处理,去除背景图片,获取包括手写汉字的目标图像。
其中,核密度估计算法(kernel density estimation)是一种从数据样本本身出发研究数据分布特征,用于估计概率密度函数的非参数方法。目标图像是指采用核密度估计算法对原始图像进行处理获取只包含手写汉字的图像。具体地,服务器采用核密度估计算法对原始图像进行处理,以排除背景图片干扰,获取包括手写汉字的目标图像。
在一实施例中,如图7所示,步骤S23中,即采用核密度估计算法对原始图像进行处理,去除背景图片,获取包括手写汉字的目标图像,具体包括如下步骤:
S231:对原始图像中的像素值进行统计,获取原始图像直方图。
其中,原始图像直方图是对原始图像中的像素值进行统计所获取的直方图。直方图(Histogram)是由一系列高度不等的纵向条纹或线段表示数据分布的情况的一种统计报告图。本实施例中,原始图像直方图的横轴表示像素值,纵轴表示像素值对应的出现频率。服务器通过对原始图像中的像素值进行统计,获取原始图像直方图,以便能够直观的看到原始图像中像素值的分布情况,为后续高斯核密度估计算法进行估计提供技术支持。
S232:采用高斯核密度估计算法对原始图像直方图进行处理,获取与原始图像直方图对应的至少一个频率极大值和至少一个频率极小值。
其中,高斯核密度估计算法是指核密度估计算法中的核函数为高斯核函数的核密度估计方法。高斯核函数的公式为
其中,K
(x)指像素(自变量)为x的高斯 核函数,x指原始图像中的像素值,e和π为常数。频率极大值指在频率分布直方图中,不同频率区间上的极大值。频率极小值指在频率分布直方图中,在同一频率区间上与频率极大值相对应的极小值。
具体地,采用高斯核密度函数估算方法对原始图像对应的频率分布直方图进行高斯平滑处理,获取该频率分布直方图对应的高斯平滑曲线。基于该高斯平滑曲线上的频率极大值和频率极小值,获取频率极大值和频率极小值对应横轴上的像素值,以便后续基于获取到的频率极大值和频率极小值对应的像素值便于对原始图像进行分层切分处理,获取分层图像。
S233:基于频率极大值和频率极小值对原始图像进行分层切分处理,获取分层图像。
其中,分层图像是基于极大值和极小值对原始图像进行分层切分处理所获取的图像。服务器先获取频率极大值和频率极小值对应的像素值,根据频率极大值对应的像素值对原始图像进行分层处理,原始图像中有多少个频率极大值,则对应的原始图像的像素值就被划分为多少类;然后以频率极小值对应的像素值作为类之间的边界值,根据类及类之间的边界,对该原始图像进行分层处理,以获取分层图像。
如原始图像中的频率极大值对应的像素值分别为11、53、95、116和158,频率极小值对应的像素值分别为21、63、105和135。根据原始图像中的频率极大值的个数可以确定该原始图像的像素值可以被分为5类,该原始图像可以被分为5层,频率极小值对应的像素值作为类之间的边界值,由于最小的像素值为0,最大的像素值为255,因此,根据类之间的边界值则可以确定以像素值为11的分层图像,该分层图像对应的像素值为[0,21);以像素值为53的分层图像,该分层图像对应的像素值为[21,63);以像素值为95的分层图像,该分层图像对应的像素值为[63,105);以像素值为116的分层图像,该分层图像对应的像素值为[105,135);以像素值为158的分层图像,该分层图像对应的像素值为[135,255]。
S234:基于分层图像,获取包括手写汉字的目标图像。
服务器在获取分层图像后,对分层图像进行二值化、腐蚀和叠加处理,以获取包括手写汉字的目标图像。其中,二值化处理是指将分层图像上的像素点的像素值设置为0(黑色)或1(白色),将整个分层图像呈现出明显的黑白效果的处理。对分层图像进行二值化处理后,对二值化处理后的分层图像进行腐蚀处理,去除背景图片部分,保留分层图像上的手写汉字部分。由于每个分层图像上的像素值是属于不同范围的像素值,因此,对分层图像进行腐蚀处理后,还需要将每个分层图像叠加,生成仅含有手写汉字的目标图像。其中,叠加处理指将分层后的仅保留有手写字部分的图像叠加成一个图像的处理过程,从而实现获取只包含手写汉字的目标图像的目的。本实施例中,采用imadd函数对分层图像进行叠加处理,以获取只包含手写汉字的目标图像。imadd函数是计算机语言中的一个函数,用于对分层图像进行叠加。
在一个实施例中,如图8所示,步骤S234中,即基于分层图像,获取包括手写汉字的目标图像,具体包括如下步骤:
S2341:对分层图像进行二值化处理,获取二值化图像。
二值化图像指对分图像进行二值化处理获取的图像。具体地,服务器获取分层图像后,基于分层图像的采样像素值和预先选取的阈值进行比较,将采样像素值大于或等于阈值的像素值设置为1,小于阈值的像素值设置为0的过程。采样像素值是分层图像中每一像素点对应的像素值。阈值的大小会影响分层图像二值化处理的效果,阈值选取合适时,对分层图像进行二值化处理的效果较好;阈值选取不合适时,会影响分层图像二值化处理的效果。为了方便操作,简化计算过程,本实施例中的阈值是由开发人员根据经验确定。对分层图像进行二值化处理,方便后续进行腐蚀处理。
S2342:对二值化图像中的像素进行检测标记,获取二值化图像对应的连通区域。
其中,连通区域是指某一特定像素周围的邻接像素所围成的区域。在二值化图像中连通区域是指其周围的邻接像素均为0,某一特定像素与邻接像素为1,例如某特定像素为0,其周围的邻接像素为1,则将邻接像素所围成的区域作为连通区域。
具体地,二值化图像对应一像素矩阵,其中包含行和列。对二值化图像中的像素进行检测标记具体包括如下过程:(1)对像素矩阵进行逐行扫描,把每一行中连续的白色像素组成一个序列称为一个团,并记下它的起点、终点以及所在的行号。(2)对于除了第一行外的所有行里的团,如果它与前一行中的所有团都没有重合区域,则给它一个新的标号;如果它仅与上一行中一个团有重合区域,则将上一行的那个团的标号赋给它;如果它与上一行的2个以上的团有重合区域,则给当前团赋一个相关联团的最小标号,并将上一行的这几个团中的标记写入等价对,说明它们属于一类。例如,若第二行中与上一行有2个团(1和2)有重合区域,则赋予该团上一行的2个团中的最小标号即1,并将上一行的这几个团中的标记写入等价对即将(1,2)记为等价对。等价对是指互相连通的两个团的标记,例如(1,2)表示标记1的团与标记2的团互相连通即为一个连通区域。本实施例中是以像素矩阵中某个特定像素相邻的8个邻接像素作为该元素的连通区域。
S2343:对二值化图像对应的连通区域进行腐蚀和叠加处理,获取包括手写汉字的目标图像。
其中,腐蚀处理是用于形态学中去除图像的某部分的内容的操作。采用MATLAB中内置的imerode函数对二值化图像的连通区域进行腐蚀处理。具体地,对二值化图像对应的连通区域进行腐蚀处理包括如下步骤:首先,选取一个n×n的结构元素,本实施例中是以像素矩阵中每个元素相邻的8个元素值作为该元素的连通区域的,因此,选取的结构元素为3×3的像素矩阵。结构元素是一个n×n的像素矩阵,其中的矩阵元素包括0或1。对分层二值化图像的像素矩阵进行扫描,获取像素值为1的像素点,比较该像素点相邻的8个邻接像素是否全为1,若全为1,则保持不变;若不全为1,则像素矩阵中该像素点相邻的8个邻接像素都变为0(黑色)。该变为0部分则为分层二值化图像被腐蚀的部分。Matlab是在数学科技应用领域中数值计算方面的应用软件。
基于预先设置的手写字区域抗腐蚀能力范围对二值化图像进行筛选,对于不在手写字区域抗腐蚀能力范围内的二值化图像部分删除,获取二值化图像中在手写字区域抗腐蚀能力范围内的部分。对筛选出的符合手写字区域抗腐蚀能力范围的每个二值化图像部分对应的像素矩阵进行叠加,就可以获取到仅含有手写汉字的目标图像。其中,手写字区域抗腐蚀能力可以采用公式:
计算,s
1表示二值化图像中被腐蚀后的总面积,s
2表示二值化图像中被腐蚀前的总面积,p为手写字区域抗腐蚀能力。
例如,预先设置的手写字区域抗腐蚀能力范围为[0.01,0.5],根据公式
计算每个二值化图像被腐蚀后的总面积和二值化图像被腐蚀前的总面积的比值p。通过计算二值化图像中某区域腐蚀后的总面积和腐蚀前的总面积的比值p不在预先设置的手写字区域抗腐蚀能力范围内,则表示该区域的二值化图像是背景图像而不是手写字,需进行腐蚀处理,以去除该背景图像。若二值化图像中的某区域腐蚀后的总面积和腐蚀前的总面积的比值p在[0.01,0.5]范围内,则表示该区域的二值化图像是手写汉字,需保留。对保留下的二值化图像对应的像素矩阵进行叠加处理,获取含有手写汉字的目标图像。
步骤S2341-S2343中,对分层图像进行二值化处理,获取二值化图像,然后对二值化图像中的像素进行检测标记,获取二值化图像对应的连通区域,对与结构元素不完全一致的像素矩阵中的元素都变为0,元素为0的二值化图像为黑色,该黑色部分则是二值化图像被腐蚀的部分,通过计算二值化图像被腐蚀后的总面积和二值化图像被腐蚀前的总面积 的比值p,判断该比值是否在预先设置的手写字区域抗腐蚀能力范围,以便去除每一分层图像中的背景图像,保留手写汉字,最后将每一分层图像进行叠加,达到获取目标图像的目的。
S24:采用垂直投影法对目标图像进行单字体切割,获取待识别单字图像。
其中,垂直投影法对目标图像进行单字体切割的切割过程与步骤S12相同,为避免重复,在此不再赘述。待识别单字图像是用于输入模型进行识别的单字体图像。
S25:将待识别单字图像输入到目标手写字识别模型中进行识别,获取每一待识别单字图像对应的手写汉字。
其中,目标手写字识别模型是采用手写模型训练方法获取的。具体地,服务器将待识别单字图像输入到目标手写字识别模型中进行识别,使得目标手写字识别模型能够联系上下文进行识别,获取每一待识别单字图像对应的手写汉字,提高识别的准确率。
本实施例中,用户可通过计算机设备上的采集模块采集包含手写汉字的待识别图像上传到服务器,以使服务器获取待识别图像。然后,服务器对待识别图像进行预处理,获取排除干扰因素的原始图像。采用核密度估计算法对原始图像进行处理,去除背景图片,获取只包含手写汉字的目标图像,进一步排除干扰。采用垂直投影法对目标图像进行单字体切割,获取待识别单字图像,容易实现。服务器将待识别单字图像输入到基于长短时记忆神经网络的目标手写字识别模型中进行识别,以使待识别单字图像具备时序性,使得目标手写字识别模型能够联系上下文进行识别,获取每一待识别单字图像对应的手写汉字,提高识别的准确率。
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
在一实施例中,提供一种手写图像识别装置,该手写图像识别装置与上述实施例中手写图像识别方法一一对应。如图9所示,该手写图像识别装置包括待识别图像获取模块21、原始图像获取模块22、目标图像获取模块23、待识别单字图像获取模块24和手写汉字获取模块25。各功能模块详细说明如下:
待识别图像获取模块21,用于获取待识别图像,待识别图像包括手写汉字和背景图片。
原始图像获取模块22,用于对待识别图像进行预处理,获取原始图像。
目标图像获取模块23,用于采用核密度估计算法对原始图像进行处理,去除背景图片,获取包括手写汉字的目标图像。
待识别单字图像获取模块24,用于采用垂直投影法对目标图像进行单字体切割,获取待识别单字图像。
手写汉字获取模块25,用于将待识别单字图像输入到目标手写字识别模型中进行识别,获取每一待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用上述实施例中手写模型训练方法获取的。
具体地,原始图像获取模块22包括灰度化图像获取单元221和原始图像获取单元222。
灰度化图像获取单元221,用于对原始图像进行放大和灰度化处理,获取灰度化图像。
原始图像获取单元222,用于对灰度化图像进行标准化处理,获取原始图像,其中,标准化处理的公式为
X是灰度化图像M的像素值,X′是原始图像的像素值,M
min是灰度化图像M中最小的像素值,M
max是灰度化图像M中最大的像素值。
具体地,目标图像获取模块23包括原始图像直方图获取单元231、频率极值获取单元232、分层图像获取单元233和目标图像获取单元234。
原始图像直方图获取单元231,用于对原始图像中的像素值进行统计,获取原始图像 直方图。
频率极值获取单元232,用于采用高斯核密度估计算法对原始图像直方图进行处理,获取与原始图像直方图对应的至少一个频率极大值和至少一个频率极值获取单元,用于频率极小值。
分层图像获取单元233,用于基于频率极大值和频率极小值对原始图像进行分层切分处理,获取分层图像。
目标图像获取单元234,用于基于分层图像,获取包括手写汉字的目标图像。
具体地,目标图像获取单元234包括二值化图像获取子单元2341、连通区域获取子单元2342和目标图像获取子单元2343。
二值化图像获取子单元2341,用于对分层图像进行二值化处理,获取二值化图像。
连通区域获取子单元2342,用于对二值化图像中的像素进行检测标记,获取二值化图像对应的连通区域。
目标图像获取子单元2343,用于对二值化图像对应的连通区域进行腐蚀和叠加处理,获取包括手写汉字的目标图像。
关于手写图像识别装置的具体限定可以参见上文中对于手写图像识别方法的限定,在此不再赘述。上述手写图像识别装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。
在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图10所示。该计算机设备包括通过***总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作***、计算机可读指令和数据库。该内存储器为非易失性存储介质中的操作***和计算机可读指令的运行提供环境。该计算机设备的数据库用于用于存储执行手写图像识别方法过程中生成或获取的数据,如手写汉字。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行时以实现一种手写图像识别方法。
在一个实施例中,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机可读指令,处理器执行计算机可读指令时实现以下步骤:获取待识别图像,待识别图像包括手写汉字和背景图片;对待识别图像进行预处理,获取原始图像;采用核密度估计算法对原始图像进行处理,去除背景图片,获取包括手写汉字的目标图像;采用垂直投影法对目标图像进行单字体切割,获取待识别单字图像;将待识别单字图像输入到目标手写字识别模型中进行识别,获取每一待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用手写模型训练方法获取的。
在一个实施例中,处理器执行计算机可读指令时还实现以下步骤:对原始图像中的像素值进行统计,获取原始图像直方图;采用高斯核密度估算方法对原始图像直方图进行处理,获取与原始图像直方图对应的至少一个频率极大值和至少一个频率极小值;基于频率极大值和频率极小值对原始图像进行分层切分处理,获取分层图像;基于分层图像,获取包括手写汉字的目标图像。
在一个实施例中,处理器执行计算机可读指令时还实现以下步骤:对分层图像进行二值化处理,获取二值化图像;对二值化图像中的像素进行检测标记,获取核密度估计算法二值化图像对应的连通区域;对二值化图像对应的连通区域进行腐蚀和叠加处理,获取包括手写汉字的目标图像。
在一个实施例中,提供一个或多个存储有计算机可读指令的非易失性可读存储介质, 所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行:时实现以下步骤:获取待识别图像,待识别图像包括手写汉字和背景图片;对待识别图像进行预处理,获取原始图像;采用核密度估计算法对原始图像进行处理,去除背景图片,获取包括手写汉字的目标图像;采用垂直投影法对目标图像进行单字体切割,获取待识别单字图像;将待识别单字图像输入到目标手写字识别模型中进行识别,获取每一待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用手写模型训练方法获取的;其中,目标手写字识别模型是采用手写模型训练方法获取的。
在一个实施例中,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行时还实现以下步骤:对原始图像中的像素值进行统计,获取原始图像直方图;采用高斯核密度估算方法对原始图像直方图进行处理,获取与原始图像直方图对应的至少一个频率极大值和至少一个频率极小值;基于频率极大值和频率极小值对原始图像进行分层切分处理,获取分层图像;基于分层图像,获取包括手写汉字的目标图像。
在一个实施例中,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行时还实现以下步骤:对分层图像进行二值化处理,获取二值化图像;对二值化图像中的像素进行检测标记,获取核密度估计算法二值化图像对应的连通区域;对二值化图像对应的连通区域进行腐蚀和叠加处理,获取包括手写汉字的目标图像。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机可读指令来指令相关的硬件来完成,所述的计算机可读指令可存储于一非易失性计算机可读取存储介质中,该计算机可读指令在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。
Claims (20)
- 一种手写模型训练方法,其特征在于,包括:获取训练手写中文图像;采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;将所述训练单字体图像按预设比例划分成训练集和测试集;对所述训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
- 如权利要求1所述的手写模型训练方法,其特征在于,所述将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型,包括:在长短时记忆神经网络的隐藏层采用第一激活函数对所述训练单字体图像进行处理,获取携带激活状态标识的神经元;在所述长短时记忆神经网络的隐藏层采用第二激活函数对所述携带激活状态标识的神经元进行处理,获取长短时记忆神经网络隐藏层的输出值;根据所述长短时记忆神经网络隐藏层的输出值,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取所述目标手写字识别模型。
- 一种手写图像识别方法,其特征在于,包括获取待识别图像,所述待识别图像包括手写汉字和背景图片;对所述待识别图像进行预处理,获取原始图像;采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;将所述待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用权利要求1-3任意一项所述手写模型训练方法获取的。
- 如权利要求4所述的手写图像识别方法,其特征在于,所述采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像,包括:对所述原始图像中的像素值进行统计,获取原始图像直方图;采用高斯核密度估算方法对所述原始图像直方图进行处理,获取与原始图像直方图对应的至少一个频率极大值和至少一个频率极小值;基于所述频率极大值和频率极小值对所述原始图像进行分层切分处理,获取分层图像;基于所述分层图像,获取包括所述手写汉字的目标图像。
- 如权利要求5所述的手写图像识别方法,其特征在于,所述基于所述分层图像,获取包括所述手写汉字的目标图像,包括:对所述分层图像进行二值化处理,获取二值化图像;对所述二值化图像中的像素进行检测标记,获取所述二值化图像对应的连通区域;对所述二值化图像对应的连通区域进行腐蚀和叠加处理,获取所述包括所述手写汉字的目标图像。
- 一种手写模型训练装置,其特征在于,包括:训练手写中文图像获取模块,用于获取训练手写中文图像;训练手写中文图像划分模块,用于将所述训练手写中文图像按预设比例划分成训练集和测试集;训练单字体图像获取模块,用于采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;原始手写字识别模型获取模块,用于对所述训练集中的训练单字体图像进行顺序标注,并将标注好的单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;目标手写字识别模型获取模块,用于采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
- 一种手写图像识别装置,其特征在于,包括:待识别图像获取模块,用于获取待识别图像,待识别图像包括手写汉字和背景图片;原始图像获取模块,用于对所述待识别图像进行预处理,获取原始图像;目标图像获取模块,用于采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;待识别单字图像获取模块用于,采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;手写汉字获取模块,用于将所述待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用权利要求1-3任意一项所述手写模型训练方法获取的。
- 一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,其特征在于,所述处理器执行所述计算机可读指令时实现如权利下步骤:获取训练手写中文图像;采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;将所述训练单字体图像按预设比例划分成训练集和测试集;对所述训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
- 如权利要求9所述的计算机设备,其特征在于,所述将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型,包括:在长短时记忆神经网络的隐藏层采用第一激活函数对所述训练单字体图像进行处理,获取携带激活状态标识的神经元;在所述长短时记忆神经网络的隐藏层采用第二激活函数对所述携带激活状态标识的 神经元进行处理,获取长短时记忆神经网络隐藏层的输出值;根据所述长短时记忆神经网络隐藏层的输出值,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取所述目标手写字识别模型。
- 一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,其特征在于,所述处理器执行所述计算机可读指令时实现如权利下步骤:获取待识别图像,所述待识别图像包括手写汉字和背景图片;对所述待识别图像进行预处理,获取原始图像;采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;将所述待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用权利要求1-3任意一项所述手写模型训练方法获取的。
- 如权利要求12所述的计算机设备,其特征在于,所述采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像,包括:对所述原始图像中的像素值进行统计,获取原始图像直方图;采用高斯核密度估算方法对所述原始图像直方图进行处理,获取与原始图像直方图对应的至少一个频率极大值和至少一个频率极小值;基于所述频率极大值和频率极小值对所述原始图像进行分层切分处理,获取分层图像;基于所述分层图像,获取包括所述手写汉字的目标图像。
- 如权利要求13所述的计算机设备,其特征在于,所述基于所述分层图像,获取包括所述手写汉字的目标图像,包括:对所述分层图像进行二值化处理,获取二值化图像;对所述二值化图像中的像素进行检测标记,获取所述二值化图像对应的连通区域;对所述二值化图像对应的连通区域进行腐蚀和叠加处理,获取所述包括所述手写汉字的目标图像。
- 一个或多个存储有计算机可读指令的非易失性可读存储介质,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:获取训练手写中文图像;采用垂直投影法对所述训练手写中文图像进行单字体切割,获取训练单字体图像;将所述训练单字体图像按预设比例划分成训练集和测试集;对所述训练集中的训练单字体图像进行顺序标注,并将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型;采用所述测试集中的训练单字体图像对所述原始手写字识别模型进行测试,在测试准确率大于预设准确率时,获取目标手写字识别模型。
- 如权利要求15所述的非易失性可读存储介质,其特征在于,所述将标注好的训练单字体图像输入到长短时记忆神经网络中进行训练,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取原始手写字识别模型,包括:在长短时记忆神经网络的隐藏层采用第一激活函数对所述训练单字体图像进行处理,获取携带激活状态标识的神经元;在所述长短时记忆神经网络的隐藏层采用第二激活函数对所述携带激活状态标识的神经元进行处理,获取长短时记忆神经网络隐藏层的输出值;根据所述长短时记忆神经网络隐藏层的输出值,采用批量梯度下降算法对所述长短时记忆神经网络的网络参数进行更新,获取所述目标手写字识别模型。
- 一个或多个存储有计算机可读指令的非易失性可读存储介质,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:获取待识别图像,所述待识别图像包括手写汉字和背景图片;对所述待识别图像进行预处理,获取原始图像;采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像;采用垂直投影法对所述目标图像进行单字体切割,获取待识别单字图像;将所述待识别单字图像输入到目标手写字识别模型中进行识别,获取每一所述待识别单字图像对应的手写汉字;其中,目标手写字识别模型是采用权利要求1-3任意一项所述手写模型训练方法获取的。
- 如权利要求18所述的非易失性可读存储介质,其特征在于,所述采用核密度估计算法对所述原始图像进行处理,去除所述背景图片,获取包括所述手写汉字的目标图像,包括:对所述原始图像中的像素值进行统计,获取原始图像直方图;采用高斯核密度估算方法对所述原始图像直方图进行处理,获取与原始图像直方图对应的至少一个频率极大值和至少一个频率极小值;基于所述频率极大值和频率极小值对所述原始图像进行分层切分处理,获取分层图像;基于所述分层图像,获取包括所述手写汉字的目标图像。
- 如权利要求19所述的非易失性可读存储介质,其特征在于,所述基于所述分层图像,获取包括所述手写汉字的目标图像,包括:对所述分层图像进行二值化处理,获取二值化图像;对所述二值化图像中的像素进行检测标记,获取所述二值化图像对应的连通区域;对二值化图像对应的连通区域进行腐蚀和叠加处理,获取包括手写汉字的目标图像。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810564693.5 | 2018-06-04 | ||
CN201810564693.5A CN108985297A (zh) | 2018-06-04 | 2018-06-04 | 手写模型训练、手写图像识别方法、装置、设备及介质 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2019232843A1 true WO2019232843A1 (zh) | 2019-12-12 |
Family
ID=64540015
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2018/094168 WO2019232843A1 (zh) | 2018-06-04 | 2018-07-03 | 手写模型训练、手写图像识别方法、装置、设备及介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN108985297A (zh) |
WO (1) | WO2019232843A1 (zh) |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111190576A (zh) * | 2019-12-17 | 2020-05-22 | 平安医疗健康管理股份有限公司 | 基于文字识别的组件集展示方法、装置和计算机设备 |
CN111325205A (zh) * | 2020-03-02 | 2020-06-23 | 北京三快在线科技有限公司 | 文档图像方向识别方法、装置及模型的训练方法、装置 |
CN111612081A (zh) * | 2020-05-25 | 2020-09-01 | 深圳前海微众银行股份有限公司 | 识别模型的训练方法、装置、设备及存储介质 |
CN112131834A (zh) * | 2020-09-24 | 2020-12-25 | 云南民族大学 | 一种西波字体生成和识别方法 |
CN113434491A (zh) * | 2021-06-18 | 2021-09-24 | 深圳市曙光信息技术有限公司 | 面向深度学习ocr识别的字模数据清洗方法、***及介质 |
WO2023001112A1 (zh) * | 2021-07-19 | 2023-01-26 | 维沃移动通信有限公司 | 文字美化方法、装置、可读存储介质和电子设备 |
CN118155284A (zh) * | 2024-03-20 | 2024-06-07 | 飞虎互动科技(北京)有限公司 | 签字动作检测方法、装置、电子设备及可读存储介质 |
Families Citing this family (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111339803B (zh) * | 2018-12-19 | 2023-10-24 | 新方正控股发展有限责任公司 | 字体识别方法、装置、设备及计算机可读存储介质 |
CN110033052A (zh) * | 2019-04-19 | 2019-07-19 | 济南浪潮高新科技投资发展有限公司 | 一种ai识别手写字体的自训练方法及自训练平台 |
CN110942004A (zh) * | 2019-11-20 | 2020-03-31 | 深圳追一科技有限公司 | 基于神经网络模型的手写识别方法、装置及电子设备 |
CN111242840A (zh) * | 2020-01-15 | 2020-06-05 | 上海眼控科技股份有限公司 | 手写体字符生成方法、装置、计算机设备和存储介质 |
CN113378609B (zh) * | 2020-03-10 | 2023-07-21 | ***通信集团辽宁有限公司 | 代理商代签名的识别方法及装置 |
CN113765957B (zh) * | 2020-06-04 | 2022-09-16 | 华为技术有限公司 | 一种模型更新方法及装置 |
CN112686881B (zh) * | 2020-11-25 | 2023-06-06 | 西安石油大学 | 基于影像统计特征和lstm复合网络的颗粒物料混合均匀性检测方法 |
CN113128486B (zh) * | 2021-03-31 | 2022-12-27 | 河北师范大学 | 手写数学公式样本库的构建方法、装置及终端设备 |
CN113361666B (zh) * | 2021-06-15 | 2023-10-10 | 浪潮金融信息技术有限公司 | 一种手写字符识别方法、***及介质 |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105512692A (zh) * | 2015-11-30 | 2016-04-20 | 华南理工大学 | 基于blstm的联机手写数学公式符号识别方法 |
CN107302433A (zh) * | 2016-04-15 | 2017-10-27 | 平安科技(深圳)有限公司 | 电子签名的校验方法、校验服务器及用户终端 |
-
2018
- 2018-06-04 CN CN201810564693.5A patent/CN108985297A/zh not_active Withdrawn
- 2018-07-03 WO PCT/CN2018/094168 patent/WO2019232843A1/zh active Application Filing
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105512692A (zh) * | 2015-11-30 | 2016-04-20 | 华南理工大学 | 基于blstm的联机手写数学公式符号识别方法 |
CN107302433A (zh) * | 2016-04-15 | 2017-10-27 | 平安科技(深圳)有限公司 | 电子签名的校验方法、校验服务器及用户终端 |
Non-Patent Citations (2)
Title |
---|
WEI, XIAOXIN: "Long Short Term Memory Recurrent Neural Network Application to Handwritten Recognition", CHINESE MASTER'S THESES FULL-TEXT DATABASE, 15 January 2015 (2015-01-15), ISSN: 1674-0246 * |
ZHU, LEI: "Research on Image Segmentation Algorithms about Ancient Handwritten Chinese Characters", CHINESE DOCTORAL DISSERTATIONS FULL-TEXT DATABASE, 15 December 2011 (2011-12-15), pages 39, ISSN: 1674-022X * |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111190576A (zh) * | 2019-12-17 | 2020-05-22 | 平安医疗健康管理股份有限公司 | 基于文字识别的组件集展示方法、装置和计算机设备 |
CN111190576B (zh) * | 2019-12-17 | 2022-09-23 | 深圳平安医疗健康科技服务有限公司 | 基于文字识别的组件集展示方法、装置和计算机设备 |
CN111325205A (zh) * | 2020-03-02 | 2020-06-23 | 北京三快在线科技有限公司 | 文档图像方向识别方法、装置及模型的训练方法、装置 |
CN111325205B (zh) * | 2020-03-02 | 2023-10-10 | 北京三快在线科技有限公司 | 文档图像方向识别方法、装置及模型的训练方法、装置 |
CN111612081A (zh) * | 2020-05-25 | 2020-09-01 | 深圳前海微众银行股份有限公司 | 识别模型的训练方法、装置、设备及存储介质 |
CN111612081B (zh) * | 2020-05-25 | 2024-04-02 | 深圳前海微众银行股份有限公司 | 识别模型的训练方法、装置、设备及存储介质 |
CN112131834A (zh) * | 2020-09-24 | 2020-12-25 | 云南民族大学 | 一种西波字体生成和识别方法 |
CN112131834B (zh) * | 2020-09-24 | 2023-12-29 | 云南民族大学 | 一种西波字体生成和识别方法 |
CN113434491A (zh) * | 2021-06-18 | 2021-09-24 | 深圳市曙光信息技术有限公司 | 面向深度学习ocr识别的字模数据清洗方法、***及介质 |
CN113434491B (zh) * | 2021-06-18 | 2022-09-02 | 深圳市曙光信息技术有限公司 | 面向深度学习ocr识别的字模数据清洗方法、***及介质 |
WO2023001112A1 (zh) * | 2021-07-19 | 2023-01-26 | 维沃移动通信有限公司 | 文字美化方法、装置、可读存储介质和电子设备 |
CN118155284A (zh) * | 2024-03-20 | 2024-06-07 | 飞虎互动科技(北京)有限公司 | 签字动作检测方法、装置、电子设备及可读存储介质 |
Also Published As
Publication number | Publication date |
---|---|
CN108985297A (zh) | 2018-12-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2019232843A1 (zh) | 手写模型训练、手写图像识别方法、装置、设备及介质 | |
WO2019232853A1 (zh) | 中文模型训练、中文图像识别方法、装置、设备及介质 | |
CN108710866B (zh) | 汉字模型训练方法、汉字识别方法、装置、设备及介质 | |
WO2019232852A1 (zh) | 手写字训练样本获取方法、装置、设备及介质 | |
WO2019232850A1 (zh) | 手写汉字图像识别方法、装置、计算机设备及存储介质 | |
WO2019232872A1 (zh) | 手写字模型训练方法、汉字识别方法、装置、设备及介质 | |
WO2019232873A1 (zh) | 文字模型训练方法、文字识别方法、装置、设备及介质 | |
CN108171209B (zh) | 一种基于卷积神经网络进行度量学习的人脸年龄估计方法 | |
WO2019238063A1 (zh) | 文本检测分析方法、装置及设备 | |
US10977524B2 (en) | Classification with segmentation neural network for image-based content capture | |
WO2019232849A1 (zh) | 汉字模型训练方法、手写字识别方法、装置、设备及介质 | |
WO2021238455A1 (zh) | 数据处理方法、设备及计算机可读存储介质 | |
WO2017020723A1 (zh) | 一种字符分割方法、装置及电子设备 | |
CN110619274A (zh) | 基于***和签名的身份验证方法、装置和计算机设备 | |
CN110705233B (zh) | 基于文字识别技术的笔记生成方法、装置和计算机设备 | |
CN109086654B (zh) | 手写模型训练方法、文本识别方法、装置、设备及介质 | |
WO2019232870A1 (zh) | 手写字训练样本获取方法、装置、计算机设备及存储介质 | |
US11144799B2 (en) | Image classification method, computer device and medium | |
Vanetti et al. | Gas meter reading from real world images using a multi-net system | |
CN110705489B (zh) | 目标识别网络的训练方法、装置、计算机设备和存储介质 | |
CN112270317A (zh) | 一种基于深度学习和帧差法的传统数字水表读数识别方法 | |
CN116596875B (zh) | 晶圆缺陷检测方法、装置、电子设备及存储介质 | |
CN112766218A (zh) | 基于非对称联合教学网络的跨域行人重识别方法和装置 | |
JP2019153293A (ja) | 人工ニューラルネットワークを用いたocrシステムのための、線認識最大−最小プーリングを用いたテキスト画像の処理 | |
CN113780145A (zh) | ***形态检测方法、装置、计算机设备和存储介质 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 18921547 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
32PN | Ep: public notification in the ep bulletin as address of the adressee cannot be established |
Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 11/03/2021) |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 18921547 Country of ref document: EP Kind code of ref document: A1 |