Two-stage handwriting display method based on eight-direction graph
By splitting the handwriting recovery task into two subtasks: prediction of the eight-way graph and predicting the trajectory based on the eight-way graph, and using the eight-way graph as an intermediate representation, the problem of low display accuracy of handwriting recovery in the existing technology is solved, and a higher accuracy is achieved. Handwriting recovery accuracy.
Patent Information
- Application Number
- CN202410459667.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-17
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-04-17
AI Technical Summary
Due to the huge modal difference between the image and the handwriting point sequence in the existing handwriting recovery and display methods, the depth model fitting and mapping process is difficult, which limits the accuracy of handwriting recovery.
A two-stage handwriting display method based on the eight-way graph is used to split the handwriting recovery task into two subtasks: eight-way graph prediction and trajectory prediction based on the eight-way graph. By introducing the eight-way graph as an intermediate product, the difficulty of the two subtasks is reduced. , thereby improving the accuracy of handwriting recovery display.
Through the intermediate representation of the eight-way graph, the accuracy of handwriting recovery display is successfully improved, the difficulty of the two subtasks is reduced, and the overall accuracy of handwriting recovery is improved.
Smart Images

Figure CN118096987B
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of deep learning and image processing, and in particular to a two-stage handwriting display method based on an eight-directional graph. Background Art
[0002] The goal of the handwriting restoration task is to generate a sequence of handwriting points corresponding to the input text based on a given text image by analyzing information such as image features and text morphology. These handwriting point sequences can represent the writing trajectory, speed and other properties of the text, thereby restoring the writing process and characteristics of the original document. This task plays an important role in document identification and verification, digital forensics, personal identity verification, and handwritten text recognition and automated processing.
[0003] Current handwriting restoration and display methods are basically one-stage methods, that is, using a visual encoder to extract image visual features and using a sequence decoder to decode the image visual features into sequence points. However, the difference between the two modalities of image and handwriting point sequence is huge, and it is difficult to use a deep model to directly fit the mapping process of these two modalities, which will limit the accuracy of current handwriting restoration methods. How to improve the accuracy of handwriting restoration is still a problem that needs to be solved in this field. Summary of the invention
[0004] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention discloses a two-stage handwriting display method based on an eight-directional graph. The method can restore the writing trajectory of a text image based on the image and display it. Compared with the existing method, the method innovatively splits the handwriting restoration task into two subtasks: eight-directional graph prediction and trajectory prediction based on the eight-directional graph. The eight-directional graph is a picture containing stroke direction information. By introducing the eight-directional graph as an intermediate product, the difficulty of the two subtasks is reduced, which can improve the accuracy of handwriting restoration display.
[0005] The object of the present invention is achieved through the following technical solution, a two-stage handwriting display method based on an eight-directional graph, the method comprising:
[0006] Step 1, constructing a handwriting restoration model, including an eight-way graph restoration module and a handwriting restoration module;
[0007] Step 2, rendering a text map and a text eight-direction map according to the handwriting point sequence;
[0008] Step 3, input the text image into the eight-direction image recovery module to obtain the predicted eight-direction image;
[0009] Step 4, calculating an eight-directional graph recovery loss function for the predicted eight-directional graph and the text eight-directional graph, and optimizing an eight-directional graph recovery module using the eight-directional graph recovery loss function;
[0010] Step 5, input the eight-direction graph of the text into the handwriting recovery module to obtain a predicted handwriting point sequence;
[0011] Step 6, calculating a sequence prediction loss function for the predicted handwriting point sequence and the handwriting point sequence, and using the sequence prediction loss function to optimize the handwriting restoration module;
[0012] Step 7: Use the optimized handwriting restoration model to restore the handwriting and display the restored handwriting.
[0013] The method of rendering a text image and a text eight-direction image according to a handwriting point sequence includes the following steps:
[0014] Step 201: Render a text image based on the handwriting point sequence ; The expression of the handwriting point sequence is:
[0015] ;
[0016] in, represents the sequence of handwriting points, n represents the total number of handwriting points, represents the horizontal and vertical coordinates of the i-th handwriting point, is a three-dimensional vector used to represent the state of the pen point, and the expression is:
[0017] ;
[0018] Create a blank image and render it according to the following rules to get a text image :
[0019] ① and , connect the i-th point and the i+1-th point; ② and , connect the i-th point and the i+1-th point; ③ and , there is no line between the i-th point and the i+1-th point;
[0020] Step 202: Rendering an eight-directional graph of the text based on the handwriting point sequence ; Create 8 blank images, and render the kth blank image according to the following rules: ① and and , connect the i-th point and the i+1-th point; ② and and , connect the i-th point and the i+1-th point; ③ and , there is no line between the i-th point and the i+1-th point;
[0021] Among them, the function The expression is:
[0022] ;
[0023] At this point, you can get the text map and text eight-way graph .
[0024] The step of inputting the text graph into the eight-direction graph recovery module to obtain the predicted eight-direction graph comprises the following steps:
[0025] Change the number of output channels of the last deconvolution layer of the segmentation network U-Net to 8, and Input into U-Net to get the predicted eight-direction graph, the expression is:
[0026] ;
[0027] in, represents the prediction eight-way graph, , is the image width, is the image height.
[0028] The eight-directional graph restoration loss function is calculated for the predicted eight-directional graph and the text eight-directional graph, and the eight-directional graph restoration loss function is used to optimize the eight-directional graph restoration module, including the following steps:
[0029] Eight-way graph for prediction and text eight-way graph Calculate the eight-direction graph recovery loss function, the expression is:
[0030] ;
[0031] in, Represents the eight-way graph recovery loss function, using the Adam optimizer for Optimize and train an eight-directional graph recovery module, which can predict a text eight-directional graph based on a text graph.
[0032] The step of inputting the eight-direction graph of characters into the handwriting recovery module to obtain a predicted handwriting point sequence comprises the following steps:
[0033] Step 501, using ResNet to extract the visual feature vector of the text eight-direction graph; Input into ResNet to obtain the visual feature map of the text eight-direction graph, the expression is:
[0034] ;
[0035] in, is the visual feature map of the text eight-direction graph, is the image width, is the image height, Represents the ResNet hidden layer dimension;
[0036] right Perform average pooling to obtain the visual feature vector of the text eight-directional graph ;
[0037] Step 502: convert the visual feature vector of the text eight-direction graph Input the fully connected layer to obtain the initial hidden layer features, the expression is:
[0038] ;
[0039] ;
[0040] in, and represents the initial hidden layer features, and The learnable parameters of the fully connected layers, is the activation function;
[0041] Step 503: Initial hidden layer features and Input LSTM to obtain the predicted handwriting point sequence, , predict the coordinates and state of the i-th point, the expression is:
[0042] ;
[0043] in, Represents the coordinates and state of the predicted i-th point, represents the hidden layer output of the i-th step, is 0, is 0, for , and represents the initial hidden layer features, Represents the hidden layer features for predicting the output of the i-1th point; during model training, Represents the coordinates and features of the i-1th point in the real handwriting point sequence. During model inference, use Assign values;
[0044] At this point, the predicted handwriting point sequence is obtained, and the expression is:
[0045] ;
[0046] Where Y represents the predicted handwriting point sequence.
[0047] The method of calculating the sequence prediction loss function for the predicted handwriting point sequence and the handwriting point sequence, and optimizing the handwriting restoration module with the sequence prediction loss function, comprises the following steps:
[0048] Step 601, calculate the i-th point in the predicted handwriting point sequence and the i-th point in the handwriting point sequence The loss function; the mathematical expression is:
[0049] ;
[0050] in, represents the loss function of predicting the i-th point in the handwriting point sequence and the i-th point in the handwriting point sequence, Indicates the state of the i-th point in the handwriting point sequence The jth element of The jth element representing the handwriting point state of the i-th point in the predicted handwriting point sequence;
[0051] Step 602, calculate the sequence prediction loss function; the mathematical expression is:
[0052] ;
[0053] in, is the sequence prediction loss function, n is the number of trajectory points;
[0054] Step 603, use the Adam optimizer to Optimize and train the handwriting restoration module so that the handwriting restoration module can restore the handwriting point sequence according to the input eight-way graph.
[0055] Compared with the existing methods, the advantages of the method of the present invention are: the present technology provides a two-stage handwriting display method based on an eight-directional graph. The present method innovatively splits the handwriting restoration and display task into two subtasks: eight-directional graph prediction and trajectory prediction based on the eight-directional graph. By introducing the eight-directional graph as an intermediate product, the difficulty of the two subtasks is reduced, thereby improving the accuracy of handwriting restoration and display. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 A schematic diagram of a flow chart of an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0058] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0059] In this embodiment, suppose we want to use data enhancement on text data to assist in the training of the text recognition model. Directly enhancing the text image may cause it to deform irregularly, which is not helpful for the text recognition model. Therefore, we can first map it to the handwriting point modality, perform data enhancement on it in the handwriting point modality, and restore the text image to the handwriting points in the process of using a two-stage handwriting display method based on an eight-way graph.
[0060] Therefore, if Figure 1 As shown, a two-stage handwriting display method based on an eight-directional graph comprises:
[0061] Step 1, constructing a handwriting restoration model, including an eight-way graph restoration module and a handwriting restoration module;
[0062] Step 2, rendering a text map and a text eight-direction map according to the handwriting point sequence;
[0063] Step 3, input the text image into the eight-direction image recovery module to obtain the predicted eight-direction image;
[0064] Step 4, calculating an eight-directional graph recovery loss function for the predicted eight-directional graph and the text eight-directional graph, and optimizing an eight-directional graph recovery module using the eight-directional graph recovery loss function;
[0065] Step 5, input the eight-direction graph of the text into the handwriting recovery module to obtain a predicted handwriting point sequence;
[0066] Step 6, calculating a sequence prediction loss function for the predicted handwriting point sequence and the handwriting point sequence, and using the sequence prediction loss function to optimize the handwriting restoration module;
[0067] Step 7: Use the optimized handwriting restoration model to restore the handwriting and display the restored handwriting.
[0068] The method of rendering a text image and a text eight-direction image according to a handwriting point sequence includes the following steps:
[0069] Step 201: Render a text image based on the handwriting point sequence ; The expression of the handwriting point sequence is:
[0070] ;
[0071] in, represents the sequence of handwriting points, n represents the total number of handwriting points, represents the horizontal and vertical coordinates of the i-th handwriting point, is a three-dimensional vector used to represent the state of the pen point, and the expression is:
[0072] ;
[0073] Create a blank image and render it according to the following rules to get a text image :
[0074] ① and , connect the i-th point and the i+1-th point; ② and , connect the i-th point and the i+1-th point; ③ and , there is no line between the i-th point and the i+1-th point;
[0075] Step 202: Rendering an eight-directional graph of the text based on the handwriting point sequence ; Create 8 blank images, and render the kth blank image according to the following rules: ① and and , connect the i-th point and the i+1-th point; ② and and , connect the i-th point and the i+1-th point; ③ and , there is no line between the i-th point and the i+1-th point;
[0076] Among them, the function The expression is:
[0077] ;
[0078] At this point, you can get the text map and text eight-way graph .
[0079] The step of inputting the text graph into the eight-direction graph recovery module to obtain the predicted eight-direction graph comprises the following steps:
[0080] Change the number of output channels of the last deconvolution layer of the segmentation network U-Net to 8, and Input into U-Net to get the predicted eight-direction graph, the expression is:
[0081] ;
[0082] in, represents the prediction eight-way graph, , is the image width, is the image height.
[0083] U-Net is a deep learning network architecture for image segmentation tasks. Its design is inspired by the needs of the medical image segmentation field and is particularly suitable for processing images with structural features, such as biomedical images and natural images.
[0084] The structure of U-Net consists of a symmetrical encoder and decoder, which are connected by skip connections. The entire network is U-shaped, hence the name U-Net.
[0085] The encoder part consists of a series of convolutional layers and pooling layers, which are used to gradually extract the features of the input image and reduce the spatial size. This can capture semantic information at different levels. At the same time, the encoder connects the feature map of each layer to the corresponding layer of the decoder through skip connections, so that higher-level features can be used for reconstruction in the decoder.
[0086] The decoder part consists of a series of upsampling layers and convolutional layers, which are used to upsample and reconstruct the features extracted by the encoder part. The upsampling operation restores the spatial size of the feature map to the size of the original input image through methods such as deconvolution (transposed convolution) or interpolation. This can gradually restore the detail information and generate a segmentation prediction result with the same size as the input image.
[0087] The eight-directional graph restoration loss function is calculated for the predicted eight-directional graph and the text eight-directional graph, and the eight-directional graph restoration loss function is used to optimize the eight-directional graph restoration module, including the following steps:
[0088] Eight-way graph for prediction and text eight-way graph Calculate the eight-direction graph recovery loss function, the expression is:
[0089] ;
[0090] in, Represents the eight-way graph recovery loss function, using the Adam optimizer for Optimize and train an eight-directional graph recovery module, which can predict a text eight-directional graph based on a text graph.
[0091] The step of inputting the eight-direction graph of characters into the handwriting recovery module to obtain a predicted handwriting point sequence comprises the following steps:
[0092] Step 501, using ResNet to extract the visual feature vector of the text eight-direction graph; Input into ResNet to obtain the visual feature map of the text eight-direction graph, the expression is:
[0093] ;
[0094] in, is the visual feature map of the text eight-direction graph, is the image width, is the image height, Represents the ResNet hidden layer dimension;
[0095] right Perform average pooling to obtain the visual feature vector of the text eight-directional graph ;
[0096] ResNet (Residual Neural Network) is a deep convolutional neural network structure, which is designed to solve the gradient disappearance and gradient explosion problems in deep neural networks in order to build deeper networks.
[0097] Traditional deep neural networks have the problem of vanishing gradients, that is, during the back-propagation process, the gradient gradually becomes smaller, resulting in unclear updates of the parameters of the deeper network and difficulty in training. To solve this problem, ResNet introduced the concept of residual learning.
[0098] In ResNet, the basic unit of the network is the "residual block", which contains a skip connection and a residual mapping. The skip connection allows the gradient to propagate directly through one or more layers, thereby alleviating the problem of gradient disappearance. The residual mapping changes the learning objective of the network from direct fitting to fitting the residual by adding the input features to the learned residual.
[0099] Step 502: convert the visual feature vector of the text eight-direction graph Input the fully connected layer to obtain the initial hidden layer features, the expression is:
[0100] ;
[0101] ;
[0102] in, and represents the initial hidden layer features, and The learnable parameters of the fully connected layers, is the activation function;
[0103] Step 503: Initial hidden layer features and Input LSTM to obtain the predicted handwriting point sequence, , predict the coordinates and state of the i-th point, the expression is:
[0104] ;
[0105] in, Represents the coordinates and state of the predicted i-th point, represents the hidden layer output of the i-th step, is 0, is 0, for , and represents the initial hidden layer features, Represents the hidden layer features for predicting the output of the i-1th point; during model training, Represents the coordinates and features of the i-1th point in the real handwriting point sequence. During model inference, use Assign values;
[0106] At this point, the predicted handwriting point sequence is obtained, and the expression is:
[0107] ;
[0108] Where Y represents the predicted handwriting point sequence.
[0109] The method of calculating the sequence prediction loss function for the predicted handwriting point sequence and the handwriting point sequence, and optimizing the handwriting restoration module with the sequence prediction loss function, comprises the following steps:
[0110] Step 601, calculate the i-th point in the predicted handwriting point sequence and the i-th point in the handwriting point sequence The loss function; the mathematical expression is:
[0111] ;
[0112] in, represents the loss function of predicting the i-th point in the handwriting point sequence and the i-th point in the handwriting point sequence, Indicates the state of the i-th point in the handwriting point sequence The jth element of The jth element representing the handwriting point state of the i-th point in the predicted handwriting point sequence;
[0113] Step 602, calculate the sequence prediction loss function; the mathematical expression is:
[0114] ;
[0115] in, is the sequence prediction loss function, n is the number of trajectory points;
[0116] Step 603, use the Adam optimizer to Optimize and train the handwriting restoration module so that the handwriting restoration module can restore the handwriting point sequence according to the input eight-way graph.
[0117] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
Claims
1. A two-stage handwriting display method based on an eight-direction graph, characterized in that: The method comprises: Step 1, constructing a handwriting restoration model, including an eight-way graph restoration module and a handwriting restoration module; Step 2, rendering a text map and a text eight-direction map according to the handwriting point sequence; Step 3, input the text image into the eight-direction image recovery module to obtain the predicted eight-direction image; Step 4, calculating an eight-directional graph recovery loss function for the predicted eight-directional graph and the text eight-directional graph, and optimizing an eight-directional graph recovery module using the eight-directional graph recovery loss function; Step 5, input the eight-direction graph of the text into the handwriting recovery module to obtain a predicted handwriting point sequence; Step 6, calculating a sequence prediction loss function for the predicted handwriting point sequence and the handwriting point sequence, and using the sequence prediction loss function to optimize the handwriting restoration module; Step 7, using the optimized handwriting restoration model to restore the handwriting, and displaying the restored handwriting; The method of rendering a text image and a text eight-direction image according to a handwriting point sequence includes the following steps: Step 201: Render a text image based on the handwriting point sequence ; The expression of the handwriting point sequence is: ; in, represents the sequence of handwriting points, n represents the total number of handwriting points, represents the horizontal and vertical coordinates of the i-th handwriting point, is a three-dimensional vector used to represent the state of the pen point, and the expression is: ; Create a blank image and render it according to the following rules to get a text image :① and , connect the i-th point and the i+1-th point; ② and , connect the i-th point and the i+1-th point; ③ and , there is no line between the i-th point and the i+1-th point; Step 202: Rendering an eight-directional graph of the text based on the handwriting point sequence ; Create 8 blank images, and render the kth blank image according to the following rules: ① and and , connect the i-th point and the i+1-th point; ② and and , connect the i-th point and the i+1-th point; ③ and , there is no line between the i-th point and the i+1-th point; Among them, the function The expression is: , so far, you can get the text map and text eight-way graph .
2. The two-stage handwriting display method based on eight-direction graph according to claim 1 is characterized in that: The step of inputting the text graph into the eight-direction graph recovery module to obtain the predicted eight-direction graph comprises the following steps: Change the number of output channels of the last deconvolution layer of the segmentation network U-Net to 8, and Input into U-Net to get the predicted eight-direction graph, the expression is: ; in, represents the prediction eight-way graph, , is the image width, is the image height.
3. The two-stage handwriting display method based on eight-direction graph according to claim 2 is characterized in that: The eight-directional graph restoration loss function is calculated for the predicted eight-directional graph and the text eight-directional graph, and the eight-directional graph restoration loss function is used to optimize the eight-directional graph restoration module, including the following steps: Eight-way graph for prediction and text eight-way graph Calculate the eight-direction graph recovery loss function, the expression is: ; in, Represents the eight-way graph recovery loss function, using the Adam optimizer for Optimize and train an eight-directional graph recovery module, which can predict a text eight-directional graph based on a text graph.
4. The two-stage handwriting display method based on eight-direction graph according to claim 1 is characterized in that: The step of inputting the eight-direction graph of characters into the handwriting recovery module to obtain a predicted handwriting point sequence comprises the following steps: Step 501, using ResNet to extract the visual feature vector of the text eight-direction graph; Input into ResNet to obtain the visual feature map of the text eight-direction graph, the expression is: ; in, is the visual feature map of the text eight-direction graph, is the image width, is the image height, Represents the ResNet hidden layer dimension; right Perform average pooling to obtain the visual feature vector of the text eight-directional graph ; Step 502: convert the visual feature vector of the text eight-direction graph Input the fully connected layer to obtain the initial hidden layer features, the expression is: ; ; in, and represents the initial hidden layer features, , , and The learnable parameters of the fully connected layers, is the activation function; Step 503: Initial hidden layer features and Input LSTM to obtain the predicted handwriting point sequence, , predict the coordinates and state of the i-th point, the expression is: ; in, Represents the coordinates and state of the predicted i-th point, represents the hidden layer output of the i-th step, is 0, is 0, for , and represents the initial hidden layer features, Represents the hidden layer features for predicting the output of the i-1th point; during model training, Represents the coordinates and features of the i-1th point in the real handwriting point sequence. During model inference, use Assign values; At this point, the predicted handwriting point sequence is obtained, and the expression is: ; Where Y represents the predicted handwriting point sequence.
5. The two-stage handwriting display method based on eight-direction graph according to claim 4 is characterized in that: The method of calculating the sequence prediction loss function for the predicted handwriting point sequence and the handwriting point sequence, and optimizing the handwriting restoration module with the sequence prediction loss function, comprises the following steps: Step 601, calculate the i-th point in the predicted handwriting point sequence and the i-th point in the handwriting point sequence The loss function; the mathematical expression is: ; in, represents the loss function of predicting the i-th point in the handwriting point sequence and the i-th point in the handwriting point sequence, Indicates the state of the i-th point in the handwriting point sequence The jth element of The jth element representing the handwriting point state of the i-th point in the predicted handwriting point sequence; Step 602, calculate the sequence prediction loss function; the mathematical expression is: ; in, is the sequence prediction loss function, n is the number of trajectory points; Step 603, use the Adam optimizer to Optimize and train the handwriting restoration module so that the handwriting restoration module can restore the handwriting point sequence according to the input eight-way graph.
Citation Information
Patent Citations
Air handwritten character track recovery method based on feature space deep adversarial learning
CN110197224A
Method and equipment for recovering writing tracks of handwritten Chinese character images
CN111027451A
Training method of network model for recovering writing track
CN111046771A
Character image writing track recovery method based on double-flow coding
CN114463760A
Character image writing track recovery effect discrimination method
CN114511853A
