Handwriting sample generation method, device, computer equipment and storage medium
Through the automated handwriting sample generation method, preset fonts and corpora are used to generate rich handwriting samples, which solves the problem of low handwriting sample collection efficiency and improves the recognition accuracy of the handwritten text recognition model.
Patent Information
- Application Number
- CN201811084484.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-09-18
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2038-09-18
AI Technical Summary
The existing handwriting sample collection efficiency is low, which makes it difficult to train the handwritten text recognition model and affects the recognition accuracy.
By obtaining preset handwriting input method font files and text corpus files, handwriting sample pictures are automatically drawn, and combined with the preset font library and corpus database, samples containing various handwriting fonts are generated to realize automated collection and enrichment of the sample library.
The cost of collecting handwritten samples is reduced, the collection efficiency and sample quantity are improved, and the recognition accuracy of the handwritten text recognition model is enhanced.
Smart Images

Figure CN109522975B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a handwriting sample generation method, device, computer equipment and storage medium. Background Art
[0002] In the research on handwritten text recognition, a large number of handwritten samples need to be prepared to support the model training of the handwritten text recognition model.
[0003] However, current handwriting samples are often collected manually. Due to the wide variety of handwriting samples, the workload of manually collecting handwriting samples is large. At the same time, it takes a lot of time to clean up errors in the collected handwriting samples, resulting in low efficiency in collecting handwriting samples. In addition, the number of manually collected samples is limited, which cannot well support the model training of the handwriting text recognition model, causing model training difficulties, which in turn affects the recognition accuracy of the model. Summary of the invention
[0004] The embodiments of the present invention provide a handwriting sample generation method, device, computer equipment and storage medium to solve the current problem of high cost and low collection efficiency of handwriting samples, which affects the recognition accuracy of handwritten text recognition models.
[0005] A handwriting sample generation method, comprising:
[0006] Obtaining a font file in a preset handwriting input method, and saving the font file in a preset font library;
[0007] Obtaining a text corpus file, and saving the text corpus file in a preset corpus database;
[0008] Draw a canvas according to a preset image size and set the background color of the canvas;
[0009] According to a preset selection method, extracting corpus text from the preset corpus database, and selecting a target font file from the preset font library;
[0010] Using the target font file, converting the corpus text into handwritten text corresponding to the target font file;
[0011] Determining a text size of the handwritten text according to the canvas size and the handwritten text;
[0012] Drawing the handwritten text on the canvas according to the text size of the handwritten text to obtain a handwritten sample image;
[0013] The handwriting sample image and the corpus text are taken as handwriting samples and saved in a preset handwriting sample data set.
[0014] A handwriting sample generating device, comprising:
[0015] A font acquisition module, used to acquire a font file in a preset handwriting input method and save the font file in a preset font library;
[0016] A corpus acquisition module is used to acquire a text corpus file and save the text corpus file in a preset corpus database;
[0017] A canvas drawing module, used to draw a canvas according to a preset picture size and set the background color of the canvas;
[0018] A selection module, used to extract corpus text from the preset corpus database and select a target font file from the preset font library according to a preset selection method;
[0019] A conversion module, used to convert the corpus text into handwritten text corresponding to the target font file using the target font file;
[0020] A size calculation module, used to determine the text size of the handwritten text according to the canvas size and the handwritten text;
[0021] A synthesis module, used for drawing the handwritten text on the canvas according to the text size of the handwritten text to obtain a handwritten sample image;
[0022] The saving module is used to save the handwriting sample image and the corpus text as handwriting samples into a preset handwriting sample data set.
[0023] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned handwriting sample generation method when executing the computer program.
[0024] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the handwriting sample generation method are implemented.
[0025] In the above-mentioned handwriting sample generation method, device, computer equipment and storage medium, on the one hand, by obtaining the font file in the preset handwriting input method and the text corpus file, the handwriting font corresponding to the font file in the handwriting input method is used to draw the corpus text extracted from the text corpus file on the canvas to obtain a handwriting sample image, thereby realizing automatic collection of handwriting samples, without the need for manual collection of handwriting samples, thereby reducing the collection cost of handwriting samples and improving the collection efficiency of handwriting samples; on the other hand, by selecting a target font file from a preset font library and extracting corpus text from a preset corpus database, combining the target font file and the expected text, and using the target font file to convert the corpus text into the handwriting text corresponding to the target font file, it is possible to automatically generate a handwriting sample image containing handwriting texts in various different handwriting fonts, so that the collection of handwriting samples has strong flexibility, can greatly enrich the number of handwriting sample samples, and lay a foundation for the subsequent training and tuning of the handwriting text recognition model, thereby effectively improving the recognition accuracy of the handwriting text recognition model. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0027] Figure 1 is a flow chart of a method for generating a handwriting sample in one embodiment of the present invention;
[0028] Figure 2 is a flow chart of expanding a handwriting sample in a handwriting sample generating method according to an embodiment of the present invention;
[0029] Figure 3 is a flow chart of step S8 in the handwriting sample generation method in one embodiment of the present invention;
[0030] Figure 4 is a flow chart of step S83 in the handwriting sample generation method in one embodiment of the present invention;
[0031] Figure 5 is a schematic diagram of a handwriting sample generating device in one embodiment of the present invention;
[0032] Figure 6 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0034] The handwriting sample generation method provided in the present application can be applied to a server, and the server can be implemented by an independent server or a server cluster composed of multiple servers.
[0035] In one embodiment, if Figure 1 As shown, a handwriting sample generation method is provided, which is described in detail as follows:
[0036] S1: Obtain a font file in a preset handwriting input method, and save the font file in a preset font library.
[0037] The preset handwriting input method is specifically a handwriting input method provided by a third-party platform on the Internet. The handwriting input method contains font files of various handwriting fonts. The server pre-sets the handwriting input method that needs to obtain the font file. The setting method can be to provide a configuration channel for the user, and the user configures the required handwriting input method.
[0038] Specifically, the server downloads the font file of the handwriting font in the preset handwriting input method from the Internet. The file format of the font file includes but is not limited to ttf, otf, ttc, etc. It can be understood that there can be multiple font files, each of which defines the format of a handwriting font. The server saves the downloaded font file in a preset font library. The preset font library is used to store font files of various handwriting fonts.
[0039] S2: Obtain a text corpus file and save the text corpus file in a preset corpus database.
[0040] Specifically, the server obtains the text corpus file through a preset acquisition method. The content of the text corpus file includes but is not limited to news, novels, stories, etc., and the file format of the text corpus file includes but is not limited to txt, doc, etc.
[0041] It should be noted that the preset acquisition method can specifically be searching and downloading on the Internet through crawler software, or obtaining from a preset file database, or other acquisition methods that can obtain text text. It can be specifically set according to the needs of actual application and is not limited here.
[0042] It is understandable that there may be multiple text corpus files. The server saves the acquired text corpus files into a preset corpus database.
[0043] Furthermore, the server classifies the text corpus files according to a preset classification method, and according to the classification result, stores the text corpus files in a corpus database according to the categories to which they belong.
[0044] Among them, the preset classification method can be classification according to fields, for example, chemistry, literature and other different fields, or classification according to text attributes, for example, news, novels and other different attributes. The specific classification method can be set according to the needs of actual applications.
[0045] S3: Draw a canvas according to the preset image size and set the background color of the canvas.
[0046] Specifically, the image size may include length and width, and the unit may be pixels. The preset image size is the image size of the handwriting sample image, and its specific size may be preset according to the needs of the actual application. The server draws the canvas according to the image size.
[0047] The server can directly use the preset function component of creating a canvas to draw a canvas of a specified size, and can further use the preset function component of setting the canvas color to set the background color of the canvas.
[0048] For example, you can use the imagecreate() function in the GD2 function library to create a canvas, and the imagecolorallocate() function to set the background color of the canvas.
[0049] Assuming that the preset image size is 500*400, that is, the length of the canvas is 500 pixels, the width is 300 pixels, and the RGB value of the background color of the canvas is (211, 126, 29), the specific implementation is as follows:
[0050] $im = imagecreate(500, 400); / / Create a canvas with a picture size of 500*400 $im
[0051] $white = imagecolorallocate($im, 211, 126, 29); / / Set the background color of canvas $im to the color corresponding to the RGB value (211, 126, 29).
[0052] It should be noted that there is no necessary order of execution among step S1, step S2 and step S3, and they can be executed in parallel, which is not limited here.
[0053] S4: extracting corpus text from a preset corpus database according to a preset selection method, and selecting a target font file from a preset font library.
[0054] Specifically, the preset selection methods include a text corpus file selection method, a corpus text selection method, and a font selection method. Among them, the text corpus file selection method can be to randomly select a text corpus file, or to select a specific category of text corpus files according to the needs of model training; the corpus text selection method can specifically be to randomly select a character, a sentence, a word, or a randomly combined line of characters, etc.; the font selection method can be to randomly select one or more fonts, or to select each font in a loop, or to select a specific font according to the needs of model training.
[0055] It should be noted that the method of selecting text corpus files, the method of selecting corpus texts and the method of selecting fonts can all be set according to the needs of actual applications and are not limited here.
[0056] For example, if the text corpus files in the preset corpus database are classified and stored according to the categories of the scientific fields they belong to, when the model training is targeted at the chemistry field, corpus files with the category of chemistry can be extracted from the preset corpus database.
[0057] S5: Use the target font file to convert the corpus text into handwritten text corresponding to the target font file.
[0058] Specifically, the target font file obtained in step S4 can be one or more, and the corpus text can also be one or more. Therefore, the target font file and the corpus text are combined, and each combination method contains a target font file and a corpus text. The corpus text in each combination method is converted into the handwritten text corresponding to the target font file in the combination method.
[0059] It should be noted that corpus text refers to text in standard fonts, and handwritten text refers to text written using the target font file.
[0060] For example, if there are three target font files and ten corpus texts obtained in step S4, there are 30 combinations in total, that is, each corpus text is converted using three handwritten fonts to obtain 30 different handwritten texts.
[0061] S6: Determine the text size of the handwritten text according to the canvas size and the handwritten text.
[0062] In this embodiment, the canvas size is the image size preset in step S3, and the text size of the handwritten text is the size of the rectangular image area occupied by the handwritten text. It can be understood that there is a font size correspondence between the handwritten font and font size of each character in the handwritten text and the size of the rectangular image area occupied by the character. The font size correspondence can be reflected by the formula P=f(a, c), wherein a is the handwritten font of the character, c is the font size of the character, P is the size of the rectangular image area occupied by the character, and f is a mapping function for obtaining the size of the rectangular image area occupied by the character according to the handwritten font and font size of the character.
[0063] Specifically, since the image sizes of the rectangular image areas occupied by corpus texts of the same font size are different when using different handwritten fonts, that is, the text sizes of the handwritten texts are different, the server needs to determine the text size of the handwritten text according to the canvas size and the handwritten text obtained in step S5, and specifically the following two methods can be used:
[0064] (1) According to the handwritten text obtained in step S5, the number of characters contained in the handwritten text is counted, and the font size of each character in the handwritten text is calculated based on the correspondence between the canvas size and the font size, so that the text size of the handwritten text is less than or equal to the canvas size.
[0065] (2) According to the handwritten text obtained in step S5, the number of characters contained in the handwritten text is counted, and the text size of the handwritten text is calculated according to the preset initial font size and the corresponding relationship between the number of characters and the font size. If the text size is larger than the canvas size, the font size is gradually reduced according to the preset units based on the initial font size until the text size of the handwritten text is less than or equal to the canvas size.
[0066] Taking the second method as an example, assuming that the corpus text obtained in step S4 is "AI Technological Innovation Exploration Process", the number of characters contained in the corpus text is counted as 10, and the image size of the rectangular image area occupied by "AI Technological Innovation Exploration Process" is calculated according to the initial font size of 64. If the image size is larger than the canvas size of 36*280, reduce the font size by 1 and recalculate, that is, recalculate the image size of the rectangular image area occupied by "AI Technological Innovation Exploration Process" according to the font size of 63. If the obtained image size is still larger than 36*280, continue to reduce the font size by 1 and recalculate until the image size of the rectangular image area occupied by "AI Technological Innovation Exploration Process" is less than or equal to 36*280.
[0067] S7: Draw the handwritten text on the canvas according to the text size of the handwritten text to obtain a handwritten sample image.
[0068] Specifically, according to the text size of the handwritten text determined in step S6, the handwritten text is drawn on the canvas created in step S3 to obtain a handwritten sample image.
[0069] For example, you can use the gdImageStringFT() function in the GD2 function library to draw handwritten text.
[0070] Furthermore, when drawing handwritten text on the canvas, you can also set the position of the handwritten text on the canvas and the font color of the handwritten text. For example, by passing the position coordinates and font color of the handwritten text as parameters to the gdImageStringFT() function, you can draw the handwritten text of the specified color at the specified position on the canvas.
[0071] Preferably, the handwritten text is drawn at the center of the canvas.
[0072] S8: The handwriting sample images and corpus texts are taken as handwriting samples and saved into a preset handwriting sample dataset.
[0073] Specifically, the handwriting sample image obtained in step S7 and the corpus text corresponding to the handwriting text contained in the handwriting sample image are taken as a handwriting sample, that is, the handwriting sample image and the corpus text are correspondingly saved in the handwriting sample data set.
[0074] In this embodiment, on the one hand, by obtaining a font file in a preset handwriting input method and a text corpus file, a handwriting font corresponding to the font file in the handwriting input method is used, and the corpus text extracted from the text corpus file is drawn on a canvas to obtain a handwriting sample image, thereby realizing automatic collection of handwriting samples, without the need for manual collection of handwriting samples, thereby reducing the cost of collecting handwriting samples and improving the efficiency of collecting handwriting samples; on the other hand, by selecting a target font file from a preset font library and extracting corpus text from a preset corpus database, combining the target font file and the expected text, and using the target font file to convert the corpus text into the handwriting text corresponding to the target font file, a handwriting sample image containing handwriting texts in various different handwriting fonts can be automatically generated, so that the collection of handwriting samples has strong flexibility, and the number of handwriting samples can be greatly enriched, thereby laying a foundation for subsequent training and tuning of a handwriting text recognition model, thereby effectively improving the recognition accuracy of the handwriting text recognition model.
[0075] In one embodiment, after step S2 and before step S3, the handwriting sample generation method further includes the following steps:
[0076] The content of the text corpus file is screened according to a preset text dictionary, and the text content in the text corpus file that does not belong to the text dictionary is deleted from the text corpus file.
[0077] In this embodiment, the preset text dictionary is a basic text set, and the basic text set contains the basic texts required for training a handwritten text recognition model. Further, the basic texts can be classified according to a preset classification method, and the preset classification method corresponds to the classification method of the text corpus files in the preset corpus database. For example, if the text corpus files in the preset corpus database are classified and stored according to the categories of the scientific fields to which they belong, the basic texts in the text dictionary are also classified according to the categories of the scientific fields to which they belong.
[0078] Specifically, for each text corpus file, the server detects whether each character in the text corpus file exists in the text dictionary. If it exists, the character is retained in the text corpus file; if it does not exist, the character is deleted from the text corpus file.
[0079] For example, assume that the basic texts included in the text dictionary are: 0123456789abcdefghijklmn. If the content of the text corpus file is: "一二三123四五六abc", then after deleting the content "一二三四五六" that does not exist in the text dictionary, the content of the updated text corpus file obtained is: "123abc".
[0080] In this embodiment, the server screens the content of the text corpus file according to the preset text dictionary, and deletes the text content in the text corpus file that does not belong to the preset text dictionary, so as to delete in advance the corpus texts that are not suitable for training the handwritten text recognition model from the text corpus file, avoiding the subsequent construction of handwritten samples for the corpus texts that are not suitable for training the handwritten text recognition model. While improving the collection efficiency of handwritten samples, it can make the training and optimization of the handwritten text recognition model more targeted when using the constructed handwritten samples, thus contributing to improving the recognition accuracy of the handwritten text recognition model.
[0081] In one embodiment, as Figure 2 shown, after step S8, the method for generating handwritten samples further includes an expansion process for the handwritten samples, which is described in detail as follows:
[0082] S9: Process the handwritten sample image according to a preset image effect processing method to obtain an updated image.
[0083] Specifically, the server processes the handwritten sample image according to a preset image effect processing method, and uses the obtained new image as the updated image corresponding to the handwritten sample image. Among them, the preset image effect processing method is to perform a transformation of the graphic effect on the handwritten sample image, or to perform a transformation of the character form on the handwritten text in the handwritten sample image.
[0084] For example, the image effect processing method can be to use a random Gaussian blur algorithm to blur the handwritten text in the handwriting sample image, or to use a random angle tilt method to adjust the angle of the handwritten text in the handwriting sample image, or to add a watermark to the handwriting sample image, add a border, add a background pattern, or change the background color of the canvas.
[0085] It should be noted that the image effect processing method can be specifically set according to the needs of the actual application and is not limited here.
[0086] S10: The updated image and corpus text are taken as new handwriting samples and saved in the handwriting sample dataset.
[0087] Specifically, the server takes the updated image corresponding to the handwriting sample image obtained in step S9 and the corpus text corresponding to the handwriting sample image as a new handwriting sample, that is, saves the updated image and the corpus text correspondingly into the handwriting sample data set.
[0088] In this embodiment, the handwriting sample image is processed by a preset image effect processing method to obtain a new image, and the new image and the corpus text corresponding to the handwriting sample image are used as new handwriting samples and saved in a handwriting sample data set, thereby achieving effective expansion of the handwriting samples and further improving the efficiency of handwriting sample collection.
[0089] In one embodiment, if Figure 3 As shown, in step S9, the handwriting sample image is processed according to a preset image effect processing method to obtain an updated image, which specifically includes the following steps:
[0090] S91: Obtain the pixel value of each pixel in the handwriting sample image.
[0091] Specifically, according to the size of the handwriting sample image, that is, the preset image size, each pixel point in the handwriting sample image is traversed, and the pixel value of each pixel point is obtained.
[0092] S92: Randomly select N pixel points from the image area where the handwritten text is located in the handwriting sample image to obtain N target pixel points, where N is a positive integer.
[0093] Specifically, the position of the handwritten text on the canvas determined when drawing the handwritten text on the canvas in step S7 is the image area where the handwritten text is located, and the server randomly selects N pixel points from the image area to obtain N target pixel points.
[0094] S93: Perform Gaussian blur processing on the pixel value of each target pixel to obtain a target pixel value of each target pixel.
[0095] Specifically, according to the pixel value of each pixel point obtained in step S91, the pixel value of each target pixel point obtained in step S92 is determined, and the pixel value of each target pixel point is Gaussian blurred, and the pixel value after Gaussian blurred processing is used as the target pixel value of each target pixel point.
[0096] Among them, Gaussian Blur processing, also known as Gaussian smoothing processing, is a commonly used image effect processing method in image processing, which is often used to reduce image noise and reduce the level of detail. The Gaussian Blur processing process of an image is the process of convolution calculation between the image and the normal distribution, which is equivalent to a low-pass filter.
[0097] It is understandable that when Gaussian blur processing is performed on the pixel value of the target pixel point, random Gaussian blur processing can be performed on the pixel values of the three RGB channels of the target pixel point respectively.
[0098] S94: Replace the pixel value of the target pixel point with the target pixel value of the target pixel point to obtain an updated image.
[0099] Specifically, after the server modifies the pixel value of each target pixel point in the handwriting sample image to the target pixel value of the target pixel point obtained in step S83, the new handwriting sample image obtained is the updated image.
[0100] In this embodiment, N target pixel points are randomly selected from the image area where the handwritten text is located in the handwritten sample image, and Gaussian blur processing is performed on the pixel value of each target pixel point, and the obtained target pixel value is used to replace the original pixel value, so as to obtain an updated image, thereby achieving effective expansion of the handwritten sample image. In addition, the display effect of the handwritten text is changed by using Gaussian blur processing, which is beneficial to enhance the training effect of the handwritten text recognition model when training the handwritten text recognition model, thereby improving the recognition accuracy of the handwritten text recognition model.
[0101] In one embodiment, if Figure 4 As shown, in step S93, Gaussian blur processing is performed on the pixel value of each target pixel to obtain the target pixel value of each target pixel, which specifically includes the following steps:
[0102] S931: Taking the target pixel as the center, the target pixel and K pixels around the target pixel form a weight region, where K is a positive integer.
[0103] Specifically, with the position of the target pixel as the center, K pixels around the target pixel are selected, and the pixel area formed by the target pixel and the K pixels is used as the weight area.
[0104] For example, when K is equal to 8, 8 pixels adjacent to the target pixel can be selected around the target pixel, and the 8 pixels and the target pixel form a 3*3 pixel matrix area, and the 3*3 pixel matrix area is the weight area.
[0105] S932: Calculate the weight value of each pixel in the weight area according to the following formula:
[0106]
[0107]
[0108] Among them, (x i ,y i ) is the position coordinate of the i-th pixel in the weight area, P 0 (x i ,y i ) is the probability density of the i-th pixel in the weighted area, P(x i ,y i ) is the weight value of the i-th pixel in the weight area, σ is the preset Gaussian parameter, i∈[1,K+1].
[0109] Specifically, the position of the target pixel is taken as the coordinate origin, and the position coordinates (x i ,y i ), for example, the position coordinates of the pixel point that is right adjacent to the target pixel point in the weight area are (1,0).
[0110] Using the above formula Calculate the pixel (x i ,y i ) conforms to the probability density of the normal distribution, and continues to use the above formula Calculate the pixel (x i ,y i ) weight value P(x i ,y i ) so that the sum of the weight values of K+1 pixels is 1.
[0111] The preset Gaussian parameter may specifically be the standard deviation of the normal distribution.
[0112] S933: Multiply the pixel value of each pixel in the weight area by the weight value of the pixel, and add the obtained K+1 products to obtain the target pixel value of the target pixel.
[0113] Specifically, according to the weight value of each pixel in the weight area determined in step S932, the pixel value of each pixel is multiplied by the weight value of the pixel to obtain K+1 products, and then the obtained K+1 products are accumulated, and the accumulated sum is the target pixel value of the target pixel.
[0114] In this embodiment, with the target pixel as the center, the target pixel and K pixels around the target pixel constitute a weight area, the weight value of each pixel in the weight area is calculated, and after multiplying the pixel value of each pixel in the weight area by the weight value of the pixel, the obtained K+1 products are accumulated, and the accumulated sum is used as the target pixel value of the target pixel. The Gaussian blur processing method is used to adjust the pixel value of the target pixel, so that the updated image achieves the blur effect of the area where the handwritten text is located, which is beneficial to enhance the training effect of the handwritten text recognition model when training the handwritten text recognition model, thereby improving the recognition accuracy of the handwritten text recognition model.
[0115] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0116] In one embodiment, a handwriting sample generating device is provided, and the handwriting sample generating device corresponds to the handwriting sample generating method in the above embodiment. Figure 5 As shown, the handwriting sample generation device includes a font acquisition module 51, a corpus acquisition module 52, a canvas drawing module 53, a selection module 54, a conversion module 55, a size calculation module 56, a synthesis module 57 and a storage module 58. The functional modules are described in detail as follows:
[0117] The font acquisition module 51 is used to acquire a font file in a preset handwriting input method and save the font file in a preset font library;
[0118] The corpus acquisition module 52 is used to acquire a text corpus file and save the text corpus file in a preset corpus database;
[0119] A canvas drawing module 53, used to draw a canvas according to a preset picture size and set the background color of the canvas;
[0120] A selection module 54 is used to extract corpus text from a preset corpus database and select a target font file from a preset font library according to a preset selection method;
[0121] A conversion module 55, used to convert the corpus text into handwritten text corresponding to the target font file using the target font file;
[0122] A size calculation module 56, used to determine the text size of the handwritten text according to the canvas size and the handwritten text;
[0123] A synthesis module 57, used for drawing the handwritten text on a canvas according to the text size of the handwritten text to obtain a handwritten sample image;
[0124] The saving module 58 is used to save the handwriting sample image and the corpus text as handwriting samples into a preset handwriting sample data set.
[0125] Furthermore, the handwriting sample generating device further comprises:
[0126] The corpus screening module is used to screen the content of the text corpus file according to a preset text dictionary, and delete the text content in the text corpus file that does not belong to the text dictionary from the text corpus file.
[0127] Furthermore, the handwriting sample generating device further comprises:
[0128] An effect processing module, used to process the handwriting sample image according to a preset image effect processing method to obtain an updated image;
[0129] The update module is used to save the updated images and corpus text as new handwriting samples into the handwriting sample dataset.
[0130] Furthermore, the effect processing module includes:
[0131] The pixel value acquisition submodule is used to obtain the pixel value of each pixel in the handwriting sample image;
[0132] The pixel selection submodule is used to randomly select N pixel points from the image area where the handwritten text is located in the handwritten sample image to obtain N target pixel points, where N is a positive integer;
[0133] A fuzzy processing submodule is used to perform Gaussian fuzzy processing on the pixel value of each target pixel point to obtain the target pixel value of each target pixel point;
[0134] The pixel value updating submodule is used to replace the pixel value of the target pixel point with the target pixel value of the target pixel point to obtain an updated image.
[0135] Furthermore, the fuzzy processing submodule includes:
[0136] A region determination unit, configured to take a target pixel as the center and form a weight region with the target pixel and K pixels around the target pixel, wherein K is a positive integer;
[0137] The weight calculation unit is used to calculate the weight value of each pixel in the weight area according to the following formula:
[0138]
[0139]
[0140] Among them, (x i ,y i ) is the position coordinate of the i-th pixel in the weight area, P 0 (x i ,y i ) is the probability density of the i-th pixel in the weighted area, P(x i ,y i ) is the weight value of the i-th pixel in the weight area, σ is the preset Gaussian parameter, i∈[1,K+1];
[0141] The target pixel value calculation unit is used to multiply the pixel value of each pixel point in the weight area by the weight value of the pixel point, and add the obtained K+1 products to obtain the target pixel value of the target pixel point.
[0142] For the specific definition of the handwriting sample generation device, please refer to the definition of the handwriting sample generation method above, which will not be repeated here. Each module in the above-mentioned handwriting sample generation device can be implemented in whole or in part by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0143] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store handwriting samples. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a handwriting sample generation method is implemented.
[0144] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the handwriting sample generation method of the above embodiment are implemented, for example Figure 1Alternatively, when the processor executes the computer program, the functions of each module / unit of the handwriting sample generating device in the above embodiment are realized, for example, Figure 5 The functions of modules 51 to 58 are shown in Figure 5. To avoid repetition, they will not be described here.
[0145] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the handwriting sample generation method in the above method embodiment is implemented, or when the computer program is executed by a processor, the functions of each module / unit in the handwriting sample generation device in the above device embodiment are implemented. To avoid repetition, it will not be described here.
[0146] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. 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 may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0147] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0148] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A handwriting sample generation method, It is characterized in that The handwriting sample generation method comprises: Obtaining a font file in a preset handwriting input method, and saving the font file in a preset font library; Obtaining a text corpus file, and saving the text corpus file in a preset corpus database; Draw a canvas according to a preset image size and set the background color of the canvas; According to a preset selection method, extracting corpus text from the preset corpus database, and selecting a target font file from the preset font library; Using the target font file, converting the corpus text into handwritten text corresponding to the target font file; Determine the text size of the handwritten text according to the canvas size and the handwritten text; count the number of characters contained in the handwritten text, and calculate the text size of the handwritten text according to the preset initial font size and the corresponding relationship between the number of characters and the font size; if the text size is larger than the canvas size, gradually reduce the font size according to the preset unit on the basis of the initial font size until the text size of the handwritten text is smaller than or equal to the canvas size; Drawing the handwritten text on the canvas according to the text size of the handwritten text to obtain a handwritten sample image; The handwriting sample image and the corpus text are taken as handwriting samples and saved in a preset handwriting sample data set; After the step of acquiring a text corpus file and saving the text corpus file in a preset corpus database, and before the step of drawing a canvas according to a preset picture size and setting a background color of the canvas, the handwriting sample generation method further includes: The content of the text corpus file is screened according to a preset text dictionary, and the text content in the text corpus file that does not belong to the text dictionary is deleted from the text corpus file.
2. The handwriting sample generation method according to claim 1, It is characterized in that After the step of taking the handwriting sample image and the corpus text as handwriting samples and saving them in a preset handwriting sample data set, the handwriting sample generation method further includes: Processing the handwriting sample image according to a preset image effect processing method to obtain an updated image; The updated image and the corpus text are taken as new handwriting samples and saved in the handwriting sample dataset.
3. The handwriting sample generation method according to claim 2, It is characterized in that The step of processing the handwriting sample image according to a preset image effect processing method to obtain an updated image includes: Obtaining the pixel value of each pixel in the handwriting sample image; Randomly select N pixel points from the image area where the handwritten text is located in the handwritten sample image to obtain N target pixel points, where N is a positive integer; Performing Gaussian blur processing on the pixel value of each target pixel point to obtain a target pixel value of each target pixel point; The pixel value of the target pixel point is replaced by the target pixel value of the target pixel point to obtain the updated image.
4. The handwriting sample generation method according to claim 3, It is characterized in that The performing Gaussian blur processing on the pixel value of each target pixel point to obtain the target pixel value of each target pixel point comprises: Taking the target pixel as the center, the target pixel and K pixels around the target pixel constitute a weight region, where K is a positive integer; The weight value of each pixel in the weight area is calculated according to the following formula: in, is the position coordinate of the i-th pixel in the weight area, is the probability density of the i-th pixel in the weighted area, is the weight value of the i-th pixel in the weight area, is the preset Gaussian parameter, ; The pixel value of each pixel point in the weight area is multiplied by the weight value of the pixel point, and the obtained K+1 products are added to obtain the target pixel value of the target pixel point.
5. A handwriting sample generating device, It is characterized in that The handwriting sample generating device comprises: A font acquisition module, used to acquire a font file in a preset handwriting input method and save the font file in a preset font library; A corpus acquisition module is used to acquire a text corpus file and save the text corpus file in a preset corpus database; A canvas drawing module, used to draw a canvas according to a preset picture size and set the background color of the canvas; A selection module, used to extract corpus text from the preset corpus database and select a target font file from the preset font library according to a preset selection method; A conversion module, used to convert the corpus text into handwritten text corresponding to the target font file using the target font file; A size calculation module, used to determine the text size of the handwritten text according to the canvas size and the handwritten text; count the number of characters contained in the handwritten text, and calculate the text size of the handwritten text according to the corresponding relationship between the number of characters and the font size according to the preset initial font size; if the text size is larger than the canvas size, then gradually reduce the font size according to the preset unit on the basis of the initial font size until the text size of the handwritten text is less than or equal to the canvas size; A synthesis module, used for drawing the handwritten text on the canvas according to the text size of the handwritten text to obtain a handwritten sample image; A saving module, used to save the handwriting sample image and the corpus text as handwriting samples into a preset handwriting sample data set; The handwriting sample generating device further comprises: The corpus screening module is used to screen the content of the text corpus file according to a preset text dictionary, and delete the text content in the text corpus file that does not belong to the text dictionary from the text corpus file.
6. The handwriting sample generating device according to claim 5, It is characterized in that The handwriting sample generating device further comprises: An effect processing module, used to process the handwriting sample image according to a preset image effect processing method to obtain an updated image; The updating module is used to save the updated image and the corpus text as new handwriting samples into the handwriting sample data set.
7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the steps of the handwriting sample generation method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the steps of the handwriting sample generation method according to any one of claims 1 to 4 are implemented.
