Calligraphy font data enhancement method and device, terminal and storage medium
By optimizing the calligraphy font image and training neural network model, the generator and discriminator models imitate writing fonts and evaluate similarity, the problem of limited expansion of traditional data enhancement methods is solved, and more efficient and accurate calligraphy works are achieved Authenticity detection.
Patent Information
- Application Number
- CN202311029123.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-16
- Publication Date
- 2025-02-21
AI Technical Summary
The traditional data augmentation method has limited expansion in calligraphy font detection and cannot meet the requirements of large model training for data sets.
By obtaining the original calligraphy font image for optimization, including grayscale processing, filtering processing and binarization processing, it reduces noise background interference and makes the font outline more obvious. Then use neural network to train the generator and discriminator model, imitate the writing font and evaluate its similarity, delete the low-similar data, and further optimize the model.
Through the above methods, the generated data sets are richer and the neural network model is more optimized, which can improve the efficiency and accuracy of authenticity detection of calligraphy works and realize intelligent and efficient detection functions.
Smart Images

Figure CN119495105A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of calligraphy font authenticity detection, and in particular to a calligraphy font data enhancement method, device, terminal and storage medium. Background Art
[0002] At present, deep learning neural network training requires a large number of data sets as training sets, and a large number of calligraphers' works are needed in the data collection, which requires a lot of data collection work. Traditional data enhancement methods include rotating, scaling, adding background, etc., and the expansion of data enhancement is limited. For network models that use artificial intelligence deep learning networks for calligraphy font detection, a large amount of data is required for training to achieve better results. Traditional data enhancement methods can no longer meet the requirements of large model training for data sets. Summary of the invention
[0003] The technical problem to be solved by the present invention is that the traditional data enhancement method is to rotate, scale, add background, etc. to the image, and the expansion of data enhancement is limited and cannot meet the requirements of large model training for data sets. In view of the above-mentioned defects of the prior art, a method, device, terminal and storage medium for calligraphy font data enhancement are provided.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0005] A calligraphy font data enhancement method is constructed, characterized by comprising:
[0006] Obtain the original calligraphy font image for subsequent neural network training set;
[0007] The acquired calligraphy font image is optimized to make the font outline of the image more obvious;
[0008] Use a neural network to train the data training set;
[0009] The optimized model is obtained by comparing the iteration values during the training process.
[0010] Preferably, after obtaining the optimized model according to the comparison of the iteration values in the training process, the method further includes:
[0011] The neural network training obtains the optimized model and generates a generator model at the same time. The generator model imitates writing according to the font of the training set.
[0012] Preferably, after obtaining the optimized model according to the comparison of the iteration values in the training process, the method further includes:
[0013] The neural network training obtains the optimized model and generates a discriminator model at the same time. The discriminator model determines the similarity between the handwriting imitated by the generator model and the original font.
[0014] Preferably, the discriminator model determines the similarity between the handwriting imitated by the generator model and the original font, and at the same time, the discriminator model determines the similarity between the handwriting imitated by the generator model and the original font and scores it.
[0015] Preferably, after the discriminator model determines the similarity between the handwriting font imitated by the generator model and the original font, it also includes:
[0016] The fonts imitated by the generator model with similarity lower than the set value are deleted, and the fonts imitated by the generator model with similarity higher than the set value are added to the training data set for training.
[0017] Preferably, the acquired calligraphy font image is optimized to make the font outline of the image more obvious, including:
[0018] The calligraphy font image is gray-scaled, and then the gray-scaled image is filtered, and finally the filtered image is binarized to obtain single-channel calligraphy font image data.
[0019] Preferably, obtaining the original calligraphy font image for subsequent neural network training set includes:
[0020] Convert the acquired calligraphy font image into ndarray format image data;
[0021] When using a neural network to train a data training set, the total number of network parameters in the data set is not less than 20 million, and the number of iterations for each data is not less than 5,000.
[0022] A calligraphy font data enhancement device is constructed, the device comprising: a graphics processing module, used for pre-processing a calligraphy work image input by a user, so as to perform subsequent model training;
[0023] Model training module, used to obtain optimized model through neural network training;
[0024] The stroke extraction module is used to select the data generated by the optimization model to obtain the optimal model.
[0025] A smart terminal is constructed, which includes a memory, a processor, and a calligraphy font data enhancement program stored in the memory and executable on the processor. When the calligraphy font data enhancement program is executed by the processor, the steps of the calligraphy font data enhancement method described above are implemented.
[0026] A computer-readable storage medium is constructed, on which a calligraphy font data enhancement program is stored. When the calligraphy font data enhancement program is executed by a processor, the steps of the calligraphy font data enhancement method described above are implemented.
[0027] The beneficial effect of the present invention is that by gray-scale processing the acquired calligraphy font image, filtering processing, and finally binarization processing, the noise background interference of the font image is reduced, and the outline of the font image is made more obvious, and then an optimized model is obtained as a data training set. Then, the generator model and discriminator model generated during the neural network training are used to input the data of the original data set into the generator model, so as to imitate the trained font for writing, and then the discriminator is used to judge the similarity score between the writing font and the original font, and the imitation writing data below the set score is deleted, and the imitation writing data above the set score is put into the original data training set for training again to further optimize the model. The model obtained by the above neural network training is applied to the calligraphy work authenticity detection method and system, which can automatically detect the calligraphy works of calligraphy works and improve the detection efficiency and accuracy; thereby realizing an intelligent and efficient calligraphy and painting authenticity detection function to meet the market demand for calligraphy works. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the present invention will be further described below in conjunction with the accompanying drawings and embodiments. The drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work:
[0029] Figure 1 A flowchart of a method for enhancing calligraphy font data according to a preferred embodiment of the present invention;
[0030] Figure 2 It is a structural schematic diagram of a calligraphy font data enhancement device according to a preferred embodiment of the present invention;
[0031] Figure 3 A schematic diagram of a font training generator of a calligraphy font data enhancement method according to a preferred embodiment of the present invention;
[0032] Figure 4 The figure is a block diagram of the internal structure principle of the intelligent terminal according to the preferred embodiment of the present invention. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the following will be described clearly and completely in combination with the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are partial embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work belong to the protection scope of the present invention.
[0034] The calligraphy font data enhancement method of the preferred embodiment of the present invention; Figure 1 As shown, it is a flow chart of a calligraphy font data enhancement method provided by an embodiment of the present invention. The method can be executed by a device, and the device can be implemented by software and / or hardware.
[0035] Specifically, in this embodiment, the calligraphy font data enhancement method includes:
[0036] S11: Acquire calligraphy work images from files;
[0037] The preferred embodiment of the present invention can obtain calligraphy work images in various ways, such as importing calligraphy work images from a local computer, obtaining calligraphy work images from the Internet, obtaining calligraphy work images from image devices, etc. The image devices include cameras, scanners, etc. The calligraphy work images obtained are in various formats. The calligraphy work image data obtained in the present invention is in the commonly used JPG image format, and image formats such as PNG, GIF, and BMP may also be used.
[0038] After the calligraphy work image file is obtained, it is loaded into the software system for processing to modify the image data format.
[0039] In the embodiment of the present invention, the opencv imdecode function is used to load the calligraphy work image file into the software system so as to process the image in the next step. The image data is loaded into the software system through opencv to obtain the calligraphy work image file of the ndarray format image data, so that the calligraphy work image format is converted.
[0040] S12: Optimizing the acquired calligraphy work image to generate a data set;
[0041] In a preferred embodiment of the present invention, since the acquired calligraphy work image may be written in various colors and the background paper also has different colors, directly using it will cause large noise, so the acquired calligraphy work image needs to be processed for noise first. First, the acquired calligraphy work image is grayscale processed to filter its color, then filtering is performed to reduce the noise of the calligraphy work image, and finally binarization is performed to further reduce noise background interference, thereby turning the image into an image with only black and white, and obtaining image data with only a single channel.
[0042] In the present invention, the specific implementation method is to use the opencv cv2.cvtColor (img, cv.COLOR_BGR2GRAY) function to convert the acquired color calligraphy work image into a grayscale image, then use cv2.medianBlur (img, 3) to perform median filtering, and finally use the cv2.threshold (img, 60, 255, cv2.THRESH_BINARY) function to binarize the grayscale image to generate a black and white calligraphy work image with only 0 and 255 pixel values. The advantage of the binary image is to reduce the noise background interference, make the font outline of the image more obvious, and generate a data set with the optimized image.
[0043] S13: Use neural network to train the data set;
[0044] In order to enable the neural network to imitate the calligraphy of the original author, it is necessary to train the neural network on the optimized data set. After the training is completed, it can imitate the calligraphy of the original author.
[0045] The specific implementation method of neural network training is to use the GAN network to generate network training for the collected data set. In order to make the neural network training model more accurate, the total number of network parameters in the data set is no less than 20 million, and each data is iterated no less than 5,000 times in the neural network training model.
[0046] S14: Save the optimized model obtained through training;
[0047] In the process of model training on the training data set, the loss value in the later stage of model training will basically tend to be stable, but it will still fluctuate within a range. In order to obtain the optimized model, it is necessary to record the loss value output by each iteration process in each training process, and compare the loss value of the current iteration value with the saved loss value. If the current loss value is less than the saved loss value, the current iteration is saved in the optimized model.
[0048] Since it takes a certain amount of time to save the neural network training model, you can start saving the optimized model in the later stage of model training to speed up model training and save model training time.
[0049] S15: Generate data using the generator of the optimization model;
[0050] After the neural network is trained to obtain an optimized model, the neural network will generate a model file of a generator model. The generator model is used to generate fonts based on the input calligraphy work file. The generator model can generate a large number of data sets based on the input work file fonts. Each time a random file is given to the generator model, it can imitate the trained fonts to write, such as Figure 3 shown.
[0051] S16: Use the discriminator to score the generated data;
[0052] After the neural network is trained to obtain an optimized model, the neural network generates a model file for the generator model and also generates a model file for the discriminator model. The discriminator model is used to determine the similarity between the font written by the generator model and the original font.
[0053] For the similarity of the font written by the generator model to the original character, the discriminator model is used to score the font written by the generator model. The discriminator model comprehensively judges the similarity between the font written by the generator model and the original character based on the font features learned in the trained optimization model. The discriminator model gives a score of 0.0 to 1.0. The higher the score, the higher the similarity between the generated font and the original character.
[0054] S17: Screen the generated data and delete the data with low scores to obtain the optimal model;
[0055] In order to further improve the accuracy of the optimization model, when using the generator model for data generation, as the fonts of the random calligraphy works input are different, some low scores may appear, indicating that the generated fonts are not very similar to the original characters. At this time, the low-scoring fonts need to be deleted. Generally, the discriminator model determines that the fonts with scores lower than 0.9 can be deleted. In this way, the generated fonts are highly similar to the original fonts and are added to the original characters as a data set for style training, which further optimizes the training model and obtains the optimal model of the neural network.
[0056] In the present invention, a training data set is trained by using a neural network, and the total number of data set parameters and the number of iterations are increased, thereby obtaining an optimization model. When the optimization model is generated, a generator model and a discriminator model are generated at the same time. The generator model writes the font according to the input calligraphy font, and uses the discriminator to judge the score of the generator writing font, and deletes the data that does not meet the set score, thereby obtaining the optimization model.
[0057] Using the above method, the data is first used to establish a neural network data model, and the generator and discriminator further optimize the model to obtain the optimal model, so as to facilitate the subsequent use of neural networks to automatically detect the authenticity of calligraphy works, improve detection efficiency and accuracy; realize intelligent and efficient authenticity detection function of calligraphy and painting works, and meet the market demand for calligraphy works.
[0058] Corresponding to the calligraphy font data enhancement method, the embodiment of the present invention further provides a calligraphy font data enhancement device, specifically, as follows Figure 2 As shown, the calligraphy font data enhancement device includes: an image processing module 100, a model training module 200 and a data generation module 300.
[0059] The graphic processing module 100 is used to pre-process the calligraphy work image input by the user so as to facilitate subsequent model training.
[0060] Specifically, the calligraphy work image is obtained by a variety of methods, and after the calligraphy work image file is obtained, it is loaded into the software system for processing to modify the image data format.
[0061] Since the acquired calligraphy images may usually be written in various colors, and the background paper also has different colors, it is necessary to process the acquired calligraphy images for noise first because the noise is large if it is used directly. First, the acquired calligraphy images are grayscale processed to filter the colors, and then filtered to reduce the noise of the calligraphy images. Finally, the noise background interference is further reduced by binarization, so that the image is changed to a black and white image, and the image data of the training data set with only a single channel is obtained. The advantage of the binarized image is to reduce the noise background interference, making the font outline of the calligraphy image more obvious, and then used as the data set for training the neural network model.
[0062] A model training module 200 is used to obtain an optimized model through neural network training;
[0063] In order to enable the neural network to imitate the calligraphy of the original author, it is necessary to train the neural network on the optimized data set. After the training is completed, it can imitate the calligraphy of the original author.
[0064] In the process of model training on the training data set, the loss value in the later stage of model training will basically tend to be stable, but it will still fluctuate within a range. In order to obtain the optimized model, it is necessary to record the loss value output by each iteration process in each training process, and compare the loss value of the current iteration value with the saved loss value. If the current loss value is less than the saved loss value, the current iteration is saved in the optimized model.
[0065] A generation module 300 is used to select data generated by the optimization model to obtain an optimization model;
[0066] After the neural network is trained to obtain an optimized model, the neural network will generate two model files, one is a generator model, and the other is a discriminator model. The generator model is used to generate fonts based on the input calligraphy work files to form a large number of data sets, so that the generator can imitate the trained fonts for writing. The discriminator is used to determine the similarity between the font written by the generator model and the original font. The discriminator model comprehensively determines the similarity between the font written by the generator model and the original font based on the font features learned in the trained optimization model. The discriminator model gives a score of 0.0 to 1.0. The higher the score, the higher the similarity between the generated font and the original font.
[0067] When using the generator model for data generation, as the fonts of the random calligraphy works input are different, some low scores may appear, indicating that the generated fonts are not very similar to the original characters. At this time, the fonts with low scores need to be deleted. Generally, fonts with scores lower than 0.9 determined by the discriminator model can be deleted. In this way, the generated fonts are highly similar to the original fonts and are added to the original characters as a data set for style training, which further optimizes the training model and obtains the optimal model of the neural network.
[0068] Based on the above embodiments, the present invention further provides an intelligent terminal, whose principle block diagram is as follows: Figure 4 As shown, the above-mentioned intelligent terminal includes a processor, a memory, a network interface and a display screen connected through a system bus. The processor of the intelligent terminal is used to provide computing and control capabilities. The memory of the intelligent terminal includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a calligraphy font data enhancement program. The memory provides an environment for the operation of the operating system and the calligraphy font data enhancement program in the non-volatile storage medium. The network interface of the intelligent terminal is used to communicate with an external terminal through a network connection. When the calligraphy font data enhancement program is executed by the processor, the steps of any one of the above-mentioned calligraphy font data enhancement methods are implemented. The display screen of the intelligent terminal can be a liquid crystal display screen or other display screens.
[0069] Those skilled in the art will understand that Figure 4 The principle block diagram shown in the figure is only a block diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the smart terminal to which the scheme of the present invention is applied. The specific smart terminal may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0070] In an embodiment of the present invention, a smart terminal is provided. The smart terminal includes a memory, a processor, and a calligraphy font data enhancement program stored in the memory and executable on the processor. When the calligraphy font data enhancement program is executed by the processor, the following operation instructions are performed:
[0071] Get the original calligraphy font image from the target file;
[0072] Optimizing the acquired calligraphy font image;
[0073] Use neural network to train the data set;
[0074] Save the optimized model obtained through training;
[0075] The generator of the optimization model is used for data generation;
[0076] Use a discriminator to score the generated data;
[0077] The generated data is screened and the data with low scores are deleted to obtain the optimized model.
[0078] An embodiment of the present invention further provides a computer-readable storage medium, on which a calligraphy font data enhancement program is stored. When the calligraphy font data enhancement program is executed by a processor, the steps of any one of the calligraphy font data enhancement methods provided in the embodiments of the present invention are implemented.
[0079] It should be understood that the present invention is described by some embodiments, and those skilled in the art will appreciate that various changes or equivalent substitutions may be made to these features and embodiments without departing from the spirit and scope of the present invention. In addition, under the teachings of the present invention, these features and embodiments may be modified to adapt to specific circumstances and materials without departing from the spirit and scope of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application are within the scope of protection of the present invention.
Claims
1. A calligraphy font data enhancement method, characterized in that: include: Obtain the original calligraphy font image for subsequent neural network training set; The acquired calligraphy font image is optimized to make the font outline of the image more obvious; Use a neural network to train the data training set; The optimized model is obtained by comparing the iteration values during the training process.
2. The calligraphy font data enhancement method according to claim 1, characterized in that: After the optimized model is obtained based on the size comparison of the iteration value in the training process, it also includes: The neural network is trained to obtain an optimized model and a generator model is generated at the same time. The generator model imitates writing according to the fonts of the training set.
3. The calligraphy font data enhancement method according to claim 2, characterized in that: After the optimized model is obtained based on the size comparison of the iteration value in the training process, it also includes: The neural network training obtains the optimized model and generates a discriminator model at the same time. The discriminator model determines the similarity between the handwriting font imitated by the generator model and the original font.
4. The calligraphy font data enhancement method according to claim 3, characterized in that: The discriminator model determines the similarity between the handwriting imitated by the generator model and the original font, and at the same time, the discriminator model determines the similarity between the handwriting imitated by the generator model and the original font and scores it.
5. The calligraphy font data enhancement method according to claim 3, characterized in that: After the discriminator model determines the similarity between the handwriting font imitated by the generator model and the original font, it also includes: The fonts imitated by the generator model with similarity lower than the set value are deleted, and the fonts imitated by the generator model with similarity higher than the set value are added to the training data set for training.
6. The calligraphy font data enhancement method according to any one of claims 1 to 5, characterized in that: The step of optimizing the acquired calligraphy font image to make the font outline of the image more obvious includes: The calligraphy font image is subjected to grayscale processing, and then the grayscale processed image is subjected to filtering processing, and finally the filtered image is subjected to binarization processing to obtain single-channel calligraphy font image data.
7. The calligraphy font data enhancement method according to claim 1, characterized in that: The method of obtaining the original calligraphy font image for a subsequent neural network training set includes: Convert the acquired calligraphy font image into ndarray format image data; In the process of training the data training set using the neural network, the total number of network parameters in the data set is not less than 20 million, and the number of iterations for each data is not less than 5000 times.
8. A calligraphy font data enhancement device, characterized in that: The device comprises: A graphics processing module is used to pre-process the calligraphy work image input by the user for subsequent model training; Model training module, used to obtain optimized model through neural network training; The stroke extraction module is used to select the data generated by the optimization model to obtain the optimal model.
9. Intelligent terminal, characterized in that: The intelligent terminal includes a memory, a processor, and a calligraphy font data enhancement program stored in the memory and executable on the processor. When the calligraphy font data enhancement program is executed by the processor, the steps of the calligraphy font data enhancement method as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a calligraphy font data enhancement program, and when the calligraphy font data enhancement program is executed by the processor, the steps of the calligraphy font data enhancement method according to any one of claims 1 to 7 are implemented.