A method and device for generating handwritten formulas
By obtaining the pending formula and determining the handwriting style, and using the character database to generate the target handwriting formula, the problem of insufficient handwriting formula samples in the prior art is solved, the method of generating handwriting formulas is realized, and data is provided for training machine learning models that recognize handwriting formulas.
Patent Information
- Application Number
- CN202111152754.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-29
- Publication Date
- 2025-05-30
- Estimated Expiration
- 2041-09-29
AI Technical Summary
There is a lack of sufficient samples of handwritten formulas in the prior art to train machine learning models for identifying handwritten formulas.
By obtaining the pending formula and determining the handwriting style, obtaining the character trajectory corresponding to each character, determining the matching character trajectory from the pre-stored character database, and generating the target handwriting formula.
It realizes the generation of handwritten formulas without a large number of handwritten formula samples, solves the problem of insufficient samples required to train machine learning models, and provides training data for identifying handwritten formulas.
Smart Images

Figure CN113885713B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and in particular, to a method and device for generating handwritten formulas. Background Art
[0002] In some scenarios, it is necessary to recognize handwritten formulas. For example, when a user inputs a formula using a handwriting input method, it is necessary to recognize the handwritten formula input by the user. Another example is that it is necessary to recognize the handwritten formula included in a picture. Currently, a machine learning model can be pre-trained and used to recognize handwritten formulas. However, training the machine learning model requires a large number of handwritten formulas as training samples, and there are not many handwritten formulas available for training this machine learning model currently.
[0003] Therefore, how to obtain a large number of handwritten formulas has become an urgent problem to be solved currently. Summary of the Invention
[0004] The technical problem to be solved by this application is how to generate handwritten formulas, and a method and device for generating handwritten formulas are provided.
[0005] In a first aspect, an embodiment of this application provides a method for generating a handwritten formula. The method includes:
[0006] Obtain a formula to be processed and determine a first handwriting style;
[0007] Obtain the character trajectories corresponding to each character in the formula to be processed in the first handwriting style;
[0008] Generate a target handwritten formula in the first handwriting style according to the character trajectories.
[0009] Optionally, obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style includes:
[0010] According to the index values corresponding to each character in the formula to be processed in the first handwriting style, determine the character trajectories corresponding to each character in the formula to be processed in the first handwriting style from a pre-stored character database; where:
[0011] The formula to be processed includes a first character, and the index of the first character in the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory corresponding to the first handwriting style of the first character, and the multiple character trajectories correspond to at least one handwriting style.
[0012] Optionally, the method further includes:
[0013] Obtain the character trajectories corresponding to each character of the first handwriting style;
[0014] According to the character trajectories corresponding to each character of the first handwriting style, determine, from the character database, the character trajectories that match the character trajectories corresponding to each character of the first handwriting style, and generate indexes for the character trajectories corresponding to each character of the first handwriting style.
[0015] Optionally, the determining, from the character database, the character trajectories that match the character trajectories corresponding to each character of the first handwriting style includes:
[0016] Match the trajectory images of the character trajectories corresponding to each character of the first handwriting style with the trajectory images of each character in the character database, and determine the character trajectories that match the character trajectories corresponding to each character of the first handwriting style;
[0017] Wherein:
[0018] Each character of the first handwriting style includes a second character. When the trajectory image of the second character matches the first trajectory image of the second character in the character database, determine the character trajectory corresponding to the first trajectory image as the character trajectory that matches the second character.
[0019] Optionally, the method further includes:
[0020] Obtain the character trajectories of each character, and generate trajectory images corresponding to each character according to the character trajectories of each character;
[0021] Cluster the trajectory images corresponding to each character, and divide the character trajectories of each character into at least one category, with each category corresponding to a handwriting style;
[0022] Correspondingly store the at least one category of character trajectories of each character, and the index values of each category of character trajectories in the at least one category of character trajectories of each character.
[0023] Optionally, the formula to be processed includes a first operand, and the first operand includes multiple characters. The generating the target handwritten formula of the first handwriting style according to the character trajectories includes:
[0024] Splice the character trajectories of the multiple characters included in the first operand according to a preset character splicing layout to obtain the first operand in the first handwriting style;
[0025] Obtain the target handwritten formula according to the first operand of the first handwriting style.
[0026] Optionally, splicing the character trajectories of multiple characters included in the first operand according to a preset character splicing format, including:
[0027] Splice each row of character trajectories in at least one row of character trajectories corresponding to the first operand respectively;
[0028] Splice each row of character trajectories obtained by splicing according to the character splicing format corresponding to the first operand.
[0029] Optionally, the method further includes:
[0030] Perform dot-adding resampling on the character trajectories of some characters in the formula to be processed;
[0031] The generating the target handwritten formula of the first handwriting style according to the character trajectories includes:
[0032] Generate the target handwritten formula according to the character trajectories after dot-adding resampling.
[0033] Optionally, the method further includes:
[0034] Generate a picture including the target handwritten formula.
[0035] Optionally, the determining the first handwriting style includes:
[0036] Output formulas of multiple handwriting styles;
[0037] In response to a selection operation triggered by the user for the first formula among the multiple formulas, determine the handwriting style corresponding to the first formula as the first handwriting style.
[0038] In a second aspect, an embodiment of the present application provides a device for generating handwritten formulas, where the device includes:
[0039] A first obtaining unit, configured to obtain a formula to be processed;
[0040] A first determining unit, configured to determine a first handwriting style;
[0041] A second obtaining unit, configured to obtain the character trajectories corresponding to each character in the formula to be processed in the first handwriting style;
[0042] A first generating unit, configured to generate the target handwritten formula of the first handwriting style according to the character trajectories.
[0043] Optionally, the second obtaining unit is configured to:
[0044] Based on the index values corresponding to each character in the formula to be processed corresponding to the first handwriting style, determine the character trajectories corresponding to each character in the formula to be processed in the character database stored in advance; wherein:
[0045] The formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory corresponding to the first handwriting style of the first character, and the multiple character trajectories correspond to at least one handwriting style.
[0046] Optionally, the device further includes:
[0047] A third obtaining unit, configured to obtain the character trajectories corresponding to each character corresponding to the first handwriting style;
[0048] A second determining unit, configured to determine, from the character database, the character trajectories that match the character trajectories corresponding to each character corresponding to the first handwriting style according to the character trajectories corresponding to each character corresponding to the first handwriting style;
[0049] A second generating unit, configured to generate indexes of the character trajectories corresponding to each character corresponding to the first handwriting style.
[0050] Optionally, the second determining unit is configured to:
[0051] Match the trajectory pictures of the character trajectories corresponding to each character corresponding to the first handwriting style with the trajectory pictures corresponding to each character in the character database, and determine the character trajectories that match the character trajectories corresponding to each character corresponding to the first handwriting style;
[0052] Wherein:
[0053] Each character corresponding to the first handwriting style includes a second character. When the trajectory picture of the second character matches the first trajectory picture of the second character in the character database, the character trajectory corresponding to the first trajectory picture is determined as the character trajectory that matches the second character.
[0054] Optionally, the device further includes:
[0055] A fourth obtaining unit, configured to obtain the character trajectories of each character and generate trajectory pictures corresponding to each character according to the character trajectories of each character;
[0056] A clustering unit, configured to cluster the trajectory pictures corresponding to each character, and divide the character trajectories of each character into at least one category, and each category corresponds to one handwriting style;
[0057] A storage unit for correspondingly storing at least one type of character trajectory of each character and index values of each type of character trajectory in the at least one type of character trajectory of each character.
[0058] Optionally, the formula to be processed includes a first operand, the first operand includes multiple characters, and the first generating unit is configured to:
[0059] Splice the character trajectories of the multiple characters included in the first operand according to a preset character splicing format to obtain the first operand in the first handwriting style;
[0060] Obtain the target handwritten formula according to the first operand in the first handwriting style.
[0061] Optionally, splicing the character trajectories of the multiple characters included in the first operand according to a preset character splicing format includes:
[0062] Splice each row of character trajectories in at least one row of character trajectories corresponding to the first operand respectively;
[0063] Splice each row of character trajectories obtained by splicing according to the character splicing format corresponding to the first operand.
[0064] Optionally, the device further includes:
[0065] A resampling unit for performing dot-adding resampling on the character trajectories of some characters in the formula to be processed;
[0066] The first generating unit is configured to generate the target handwritten formula according to the character trajectories after dot-adding resampling.
[0067] Optionally, the device further includes:
[0068] A third generating unit for generating a picture including the target handwritten formula.
[0069] Optionally, the first determining unit is configured to:
[0070] Output formulas in multiple handwriting styles;
[0071] In response to a selection operation triggered by a user for a first formula among the multiple formulas, determine the handwriting style corresponding to the first formula as the first handwriting style.
[0072] In a third aspect, an embodiment of the present application provides an apparatus for generating handwritten formulas, including a memory and one or more programs, where the one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for performing the following operations:
[0073] Obtain a formula to be processed and determine a first handwriting style;
[0074] Obtain the character trajectories corresponding to each character in the formula to be processed in the first handwriting style;
[0075] Generate a target handwritten formula in the first handwriting style according to the character trajectories.
[0076] Optionally, obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style includes:
[0077] According to the index values corresponding to each character in the formula to be processed corresponding to the first handwriting style, determine the character trajectories corresponding to each character in the formula to be processed in the first handwriting style from a pre-stored character database; where:
[0078] The formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory corresponding to the first character and the first handwriting style, and the multiple character trajectories correspond to at least one handwriting style.
[0079] Optionally, the operation further includes:
[0080] Obtain the character trajectories corresponding to each character corresponding to the first handwriting style;
[0081] According to the character trajectories corresponding to each character corresponding to the first handwriting style, determine the character trajectories matching the character trajectories corresponding to each character corresponding to the first handwriting style from the character database, and generate indexes of the character trajectories corresponding to each character corresponding to the first handwriting style.
[0082] Optionally, the determining, from the character database, the character trajectories matching the character trajectories corresponding to each character corresponding to the first handwriting style according to the character trajectories corresponding to each character corresponding to the first handwriting style includes:
[0083] Match the trajectory images of the character trajectories corresponding to each character of the first handwriting style with the trajectory images corresponding to each character in the character database, and determine the character trajectories that match the character trajectories corresponding to each character of the first handwriting style;
[0084] Among them:
[0085] Each character corresponding to the first handwriting style includes a second character. When the trajectory image of the second character matches the first trajectory image of the second character in the character database, the character trajectory corresponding to the first trajectory image is determined as the character trajectory that matches the second character.
[0086] Optionally, the operation further includes:
[0087] Obtain the character trajectories of each character, and generate trajectory images corresponding to each character according to the character trajectories of each character;
[0088] Cluster the trajectory images corresponding to each character, divide the character trajectories of each character into at least one category, and each category corresponds to a handwriting style;
[0089] Correspondingly store the at least one category of character trajectories of each character, and the index value of each category of character trajectories in the at least one category of character trajectories of each character.
[0090] Optionally, the formula to be processed includes a first operand, and the first operand includes multiple characters. Generating the target handwritten formula of the first handwriting style according to the character trajectories includes:
[0091] Splice the character trajectories of the multiple characters included in the first operand according to a pre-set character splicing layout to obtain the first operand of the first handwriting style;
[0092] Obtain the target handwritten formula according to the first operand of the first handwriting style.
[0093] Optionally, splicing the character trajectories of the multiple characters included in the first operand according to a pre-set character splicing layout includes:
[0094] Splice each row of character trajectories in at least one row of character trajectories corresponding to the first operand respectively;
[0095] Splice the character trajectories of each row obtained by splicing according to the character splicing layout corresponding to the first operand.
[0096] Optionally, the operation further includes:
[0097] Perform dot interpolation resampling on the character trajectories of some characters in the formula to be processed;
[0098] Said generating the target handwritten formula in the first handwritten style according to the character trajectory includes:
[0099] Generate the target handwritten formula according to the character trajectory after dot interpolation resampling.
[0100] Optionally, the operation further includes:
[0101] Generate a picture including the target handwritten formula.
[0102] Optionally, said determining the first handwritten style includes:
[0103] Output formulas in multiple handwritten styles;
[0104] In response to a selection operation triggered by a user for a first formula among the multiple formulas, determine the handwritten style corresponding to the first formula as the first handwritten style.
[0105] In a fourth aspect, an embodiment of the present application provides a computer-readable medium, on which instructions are stored, and when executed by one or more processors, cause the device to execute the method described in any item of the above first aspect.
[0106] Compared with the prior art, the embodiments of the present application have the following advantages:
[0107] An embodiment of the present application provides a method for generating a handwritten formula. Specifically: a formula to be processed can be obtained, and a first handwritten style can be determined. The first handwritten style is the style of the handwritten formula generated according to the formula to be processed. In the embodiment of the present application, for the formula to be processed, the character trajectories of each character in the formula to be processed can be obtained, and a target handwritten formula can be generated according to the character trajectories of each character in the formula to be processed. And, the character trajectories of each character correspond to the first handwritten style. Thus, it can be seen that using this solution, a target handwritten formula in the first handwritten style can be generated for the formula to be processed. Further, using this solution, a large number of handwritten formulas can be generated, so as to train a machine learning model for recognizing handwritten formulas using the handwritten formula. Description of the Drawings
[0108] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings described below are only some embodiments recorded in the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0109] Figure 1 Schematic flowchart of a method for generating handwritten formulas provided by an embodiment of the present application;
[0110] Figure 2 Schematic structural diagram of a device for generating handwritten formulas provided by an embodiment of the present application;
[0111] Figure 3 Schematic structural diagram of a client provided by an embodiment of the present application;
[0112] Figure 4 Schematic structural diagram of a server provided by an embodiment of the present application. Detailed implementation manners
[0113] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0114] The inventors of the present application have found through research that training a machine learning model for recognizing handwritten formulas requires a large number of handwritten formulas as training samples, but there are not many handwritten formulas available for training this machine learning model currently.
[0115] In one example, handwritten formulas can be generated to train the aforementioned machine learning model for recognizing handwritten formulas. Specifically, a machine learning model can be used to generate handwritten text. In one example, text can be generated through Generative Adversarial Networks (GAN). If handwritten text is to be generated, a large number of samples are required for learning the handwritten style. Moreover, GAN can be used to generate general handwritten Chinese and English text, but it is difficult to generate handwritten formulas.
[0116] Therefore, how to generate handwritten formulas is a problem yet to be solved currently.
[0117] To solve the above problems, the embodiments of the present application provide a method for generating handwritten formulas, which can generate handwritten formulas without training a machine learning model.
[0118] The following will describe in detail various non-limiting implementation manners of the present application with reference to the accompanying drawings.
[0119] Exemplary method
[0120] See Figure 1, This figure is a schematic flowchart of a method for generating handwritten formulas provided by an embodiment of the present application.
[0121] The method provided by the embodiments of the present application can be executed by a first device, for example. The first device mentioned here includes but is not limited to terminal devices and servers. The terminal device mentioned here can be a mobile terminal such as a smart phone or a tablet computer, or a terminal device such as a desktop computer.
[0122] Figure 1 The method shown can be implemented, for example, through the following S101 - S103.
[0123] S101: Obtain the formula to be processed and determine the first handwriting style.
[0124] In one example, the formula to be processed can be obtained from the network. In another example, the formula to be processed input by the user can be obtained. After obtaining the formula to be processed, the latex formula string corresponding to the formula to be processed can be further obtained.
[0125] In the embodiments of the present application, when generating a handwritten formula corresponding to the formula to be processed, a handwritten formula with a specific style can be generated. In one example, the first handwriting style can be determined, and the formula to be processed can be generated into a handwritten formula with the first handwriting style.
[0126] The embodiments of the present application do not specifically limit the specific implementation manner for determining the first handwriting style.
[0127] In one example, the first handwriting style can be a handwriting style randomly selected from multiple handwriting styles.
[0128] In another example, the first handwriting style can be the default handwriting style.
[0129] In another example, the first handwriting style can be selected by the user independently. For this case, in some embodiments, the first device can output formulas in multiple handwriting styles. For example, display the formulas in multiple handwriting styles, and the user can select one handwriting style from them. If the user triggers a selection operation for the first formula among the multiple formulas, the first device can determine the handwriting style corresponding to the first formula as the first handwriting style. In the embodiments of the present application, the formulas in multiple handwriting styles can be generated and stored in advance, and after obtaining the formula to be processed, the formulas in multiple handwriting styles can be output. Among them, the specific implementation manner for generating the formulas in multiple handwriting styles is similar to the implementation manner for generating the target handwritten formula, so it will not be elaborated here.
[0130] S102: Obtain the character trajectories corresponding to the respective characters in the formula to be processed in the first handwriting style.
[0131] It can be understood that if the formula to be processed is to be converted into a handwritten formula in the first handwriting style, then each character in the formula to be processed needs to be converted into a handwritten character corresponding to the first handwriting style. For example, for the formula to be processed y = a + b, for the five characters "y", "=", "a", "+", and "b" in this formula to be processed, they all need to be converted into handwritten characters corresponding to the first handwriting style.
[0132] In an embodiment of the present application, the character trajectories corresponding to the respective characters in the formula to be processed in the first handwriting style can be obtained, and then, further according to the character trajectories corresponding to the respective characters in the formula to be processed in the first handwriting style, a target handwritten formula is generated.
[0133] In an embodiment of the present application, a character database can be established in advance, and then, the character trajectories corresponding to the respective characters in the formula to be processed in the first handwriting style are determined from the character database. Regarding the specific implementation manner of establishing the character database in advance, reference can be made to the relevant description part below, and details are not described here.
[0134] Regarding the character database, it should be noted that the character database may include the character trajectories corresponding to each character, and for any one character, such as the first character included in the formula to be processed, multiple character trajectories may be included. These multiple character trajectories can be divided into M categories, one category corresponding to one handwriting style, where each category of character trajectories can correspond to an index value. For example, the character database may include the character a in M handwriting styles, and these M handwriting styles are numbered in sequence. The number of each category of character trajectories is its corresponding index value.
[0135] For the first handwriting style, the character trajectories corresponding to its respective characters can correspond to an index value, and this index value is used to determine the character trajectories corresponding to the first handwriting style from the character database. In other words, for the first handwriting style, it can correspond to an index sequence, and the index sequence may include multiple index values, and one index value corresponds to one character.
[0136] For example, the first handwriting style corresponds to the index sequence "a11b12c3…y22…=19", that is, for the character "a" of the first handwriting style: the corresponding character trajectory is the 11th type among the M types of character trajectories of the character "a" stored in the character database; for the character "b" of the first handwriting style: the corresponding character trajectory is the 12th type among the M types of character trajectories of the character "b" stored in the character database; for the character "c" of the first handwriting style: the corresponding character trajectory is the 3rd type among the M types of character trajectories of the character "c" stored in the character database; for the character "y" of the first handwriting style: the corresponding character trajectory is the 22nd type among the M types of character trajectories of the character "y" stored in the character database; for the character "=" of the first handwriting style: the corresponding character trajectory is the 19th type among the M types of character trajectories of the character "=" stored in the character database.
[0137] Therefore, when specifically implemented, S102 can determine the character trajectories corresponding to the first handwriting style of each character in the formula to be processed according to the index values corresponding to each character in the formula to be processed corresponding to the first handwriting style, from the character database stored in advance.
[0138] For example:
[0139] The first handwriting style corresponds to the index sequence "a11b12c3…y22…=19+18", and the formula to be processed is "y=a+b". Therefore, the character trajectory corresponding to the character "y" in the first handwriting style can be determined from the 22nd type of character trajectory among the M types of character trajectories of the character "y" stored in the character database, and so on. The character trajectory corresponding to the character "=" in the first handwriting style can be determined from the 19th type of character trajectory among the M types of character trajectories of the character "=" stored in the character database; the character trajectory corresponding to the character "a" in the first handwriting style can be determined from the 11th type of character trajectory among the M types of character trajectories of the character "a" stored in the character database; the character trajectory corresponding to the character "+" in the first handwriting style can be determined from the 18th type of character trajectory among the M types of character trajectories of the character "+" stored in the character database; the character trajectory corresponding to the character "b" in the first handwriting style can be determined from the 12th type of character trajectory among the M types of character trajectories of the character "b" stored in the character database.
[0140] It should be noted that for the first character in the formula to be processed, the character database may store the character trajectories of multiple first characters in the first handwriting style. These multiple first characters in the first handwriting style have the same style but have some differences in details. For such a situation, one character trajectory can be randomly selected from the character trajectories of the multiple first characters in the first handwriting style as the character trajectory used for generating the handwritten formula corresponding to the formula to be processed.
[0141] In the embodiments of the present application, the indexes of the character trajectories corresponding to each character in the first handwriting style can be determined and stored in advance. Regarding the implementation manner of "determining in advance the indexes of the character trajectories corresponding to each character in the first handwriting style", reference can be made to the relevant description part below, and details are not described here.
[0142] S103: Generate the target handwritten formula in the first handwriting style according to the character trajectory.
[0143] In the embodiments of the present application, after obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style, the obtained character trajectories can be spliced to generate the target handwritten formula.
[0144] In the embodiments of the present application, considering that for the formula to be processed, it may include operands and operators, and its operands may not be single characters but include multiple characters. For example, the operand For another example, the operand
[0145] In order to make the generated target handwritten formula conform to the handwriting characteristics, for the first operand including multiple characters in the formula to be processed, the character trajectories of the multiple characters included in the first operand can be spliced according to the preset character splicing format to obtain the first operand in the first handwriting style. Then, according to the first operand in the first handwriting style, the target handwritten formula is obtained. For example, the first operand in the first handwriting style is spliced with other operators and operands to obtain the target handwritten formula.
[0146] Regarding the preset character splicing format, it should be noted that the character splicing format may include complex upper and lower type structures in the formula.
[0147] Illustrate with examples:
[0148] The character splicing layout of a fraction is frac[a][b][c], where a is used to describe the relative length of the line in the middle of the fraction. The relative length represents the proportion of the middle line in the maximum length of the upper and lower expressions. b is used to describe the relative distance between the denominator and the middle line, and c is used to describe the relative distance between the numerator and the middle line.
[0149] Another example is as follows:
[0150] The character splicing layout of a radical is sqrt[a][b][c][d][e]. a represents the proportion of the height of the power index of the radical sign in the height of the text in the following line. If it is a square root, this parameter is invalid; b and c respectively represent the relative offsets of the center point of the superscript of the radical sign from the vertex of the radical sign on the horizontal and vertical axes. If it is a square root, this parameter is invalid; d and e respectively represent the relative offsets of the center point of the text in the following line of the radical sign from the vertex of the radical sign on the horizontal and vertical axes.
[0151] As described above, the character splicing layout can include complex upper and lower structures in the formula. Therefore, in one example, when "splicing the character trajectories of multiple characters included in the first operand according to a preset character splicing layout" is specifically implemented, the character trajectories of each line in the multiple lines of character trajectories corresponding to the first operand can be spliced first, and then, the character trajectories of each line obtained by splicing are spliced according to the character splicing layout corresponding to the first operand. Specifically:
[0152] First, the characters included in each line in the first operand can be determined according to the latex formula string corresponding to the formula to be processed, and then, the character trajectories of each line in at least one line of character trajectories corresponding to the first operand are spliced.
[0153] For example: For the operand The character "a" corresponds to one line, and the character "b" corresponds to one line. After splicing the character trajectory corresponding to the character "a" and the character trajectory corresponding to the character "b", the character trajectories of the first handwritten style character "a" and the first handwritten style character "b" obtained by splicing are spliced according to the character splicing layout of the fraction.
[0154] Another example is as follows: For the operand The character "a" corresponds to one line. After splicing the character trajectory corresponding to the character "a", the character trajectory of the first handwritten style character "a" obtained by splicing is spliced according to the character splicing layout of the radical.
[0155] Another example is as follows: For the operand The character "a*b" corresponds to one line, and the character "c" corresponds to one line. After splicing the character trajectory corresponding to the character "a*b" and the character trajectory corresponding to the character "c", the character trajectory of the first handwritten style character "a*b" and the character trajectory of the first handwritten style character "c" obtained by splicing are spliced according to the character splicing format of the fraction.
[0156] As can be seen from the above example, a certain line of the first operand may include multiple characters, such as the aforementioned "a*b", and the character heights of these multiple characters may be different. In order to make the spliced handwritten formula conform to the handwritten characteristics, for the characters in the same line, the character trajectory of the character with a lower character height can be stretched so that the character heights of multiple characters in the same line are the same. For example, for the character "a" and the character "M", the character trajectory of the character "a" can be stretched so that the height of the character "a" is the same as the height of the character "M".
[0157] In one example, if the character trajectory of some characters is stretched during the process of generating the target handwritten formula, the distribution of the trajectory points in the character trajectory of the character will be uneven. Therefore, in one example, it is also possible to perform point filling and resampling on the character trajectories of these characters. For example, after stretching the character trajectory of the character "a", perform point filling and resampling on the part of the character trajectory of the character "a" where the trajectory points are relatively sparse. And, use the character trajectory after point filling and resampling to generate the target handwritten formula. In this way, in the generated target handwritten formula, the trajectory points in the character trajectories of each character are evenly distributed. The embodiments of the present application do not specifically limit the algorithm used for point filling and resampling of the character trajectory. For example, a third-order Bezier interpolation algorithm can be used to perform point filling and resampling on the character trajectory.
[0158] As can be seen from the above description, using this solution, a target handwritten formula with the first handwritten style can be generated for the formula to be processed.
[0159] In addition, after generating the target handwritten formula, the embodiments of the present application can further generate a picture including the target handwritten formula. It can be understood that since the target handwritten formula in the picture is generated according to the character trajectory, even if the user zooms in or out on the picture, there will be no pixel loss. After generating the picture, in the embodiments of the present application, other processing can also be performed on the picture, for example, adding a background to the picture, which is not specifically limited in the embodiments of the present application.
[0160] Next, the "pre-establishing the character database" will be introduced.
[0161] In one example, the character database can be established through the following steps A1 - A3.
[0162] Step A1: Obtain the character trajectories of each character, and generate a trajectory image corresponding to each character according to the character trajectories of each character.
[0163] In the embodiment of the present application, the character trajectories of each character can be obtained from network resources. The character trajectories of each character can also be obtained from a specific database that pre-stores character trajectories. The embodiment of the present application does not make specific limitations.
[0164] After obtaining the character trajectories of each character, a trajectory image corresponding to each character can be generated. It can be understood that the trajectory image refers to an image including the character trajectory. The trajectory image is used to classify the character trajectories of each character by style. After generating the trajectory images corresponding to each character, the trajectory images can also be stored in the character database. Moreover, the corresponding relationship between the stored trajectory images and the character trajectories corresponding to the trajectory images is stored.
[0165] Step A2: Cluster the trajectory images corresponding to each character, and divide the character trajectories of each character into at least one category, and each category corresponds to a handwriting style.
[0166] In the embodiment of the present application, after obtaining the trajectory images corresponding to each character, the trajectory images corresponding to each character can be clustered, and the trajectory images corresponding to the same style are divided into one category, and one category can correspond to a handwriting style. It can be understood that since the corresponding relationship between the character trajectory and the trajectory image is stored, clustering the trajectory images actually clusters the character trajectories corresponding to the trajectory images.
[0167] In one example, the sizes of the trajectory images corresponding to each character can be first converted to the same size, such as 128*128. Then, the pixel point means of the trajectory images are obtained row by row, and the variance of each trajectory image is calculated. Then, a clustering algorithm (such as kmeans++) is used to cluster the variances of the trajectory images corresponding to each character, so as to divide the character trajectories of each character into at least one category. An example is as follows:
[0168] For 100 trajectory images of the character "a", the variances of these 100 trajectory images are calculated, and clustering is performed using the variances of these 100 trajectory images to obtain 5 categories, that is, 5 handwriting styles are obtained. Each handwriting style can correspond to multiple trajectory images. That is, for the character "a", the character database can include the character trajectories of 5 handwriting styles, and each style can include multiple character trajectories of the character "a" with similar writing styles.
[0169] Step A3: Correspondingly store at least one type of character trajectory of each character, and the index value of each type of character trajectory in at least one type of character trajectory of each character.
[0170] After dividing the character trajectories of each character among the respective characters into at least one type, it is possible to correspondingly store at least one type of character trajectory of each character, and the index value of each type of character trajectory in at least one type of character trajectory of each character. The index value mentioned here can be, for example, a number.
[0171] Illustrative example:
[0172] Based on 100 trajectory pictures of the character 'a', the 100 character trajectories of the character 'a' are divided into 5 types, with each type corresponding to 20 character trajectories. Then, it is possible to correspondingly store the first type of character trajectory and number 1, the second type of character trajectory and number 2, the third type of character trajectory and number 3, the fourth type of character trajectory and number 4, the fifth type of character trajectory and number 5. Each type of character trajectory includes 20 character trajectories.
[0173] Next, an introduction is given to 'pre - determining the index of the character trajectory corresponding to each character corresponding to the first handwriting style'.
[0174] In one example, the index of the character trajectory corresponding to each character corresponding to the first handwriting style can be determined through the following steps B1 - B2.
[0175] Step B1: Obtain the character trajectories corresponding to each character corresponding to the first handwriting style.
[0176] In the embodiments of the present application, for example, it is possible to obtain the character trajectories corresponding to each character handwritten by the first user, and determine the character trajectories corresponding to each character handwritten by the first user as the character trajectories corresponding to each character corresponding to the first handwriting style.
[0177] Step B2: According to the character trajectories corresponding to each character corresponding to the first handwriting style, determine, from the character database, the character trajectories that match the character trajectories corresponding to each character corresponding to the first handwriting style, and generate the index of the character trajectories corresponding to each character corresponding to the first handwriting style.
[0178] In one example, when specifically implemented, step B2 may match the character trajectories corresponding to the respective characters of the first handwriting style with the character trajectories corresponding to the respective characters stored in the character database, so as to determine the character trajectories that match the character trajectories corresponding to the respective characters of the first handwriting style. For example, for the second character of the first handwriting style, the second character may be matched with several character trajectories of the second character stored in the character database. If the second character of the first handwriting style matches the 5th type of character trajectory among the 10 types of character trajectories of the second character stored in the character database, then the 5th type of character trajectory is determined as the character trajectory corresponding to the second character of the first handwriting style. Among them, the second character of the first handwriting style matching the 5th type of character trajectory may be that the second character of the first handwriting style matches any one of the multiple character trajectories included in the 5th type of character trajectory.
[0179] In another example, when specifically implemented, step B2 may match the trajectory pictures of the character trajectories corresponding to the respective characters of the first handwriting style with the trajectory pictures corresponding to the respective characters in the character database, and determine the character trajectories that match the character trajectories corresponding to the respective characters of the first handwriting style. Taking the second character as an example, the trajectory picture of the second character may be matched with several trajectory pictures of the second character in the character database. If the trajectory picture of the second character matches the first trajectory picture of the second character in the character database, then the character trajectory corresponding to the first trajectory picture is determined as the character trajectory that matches the second character.
[0180] In some embodiments, considering that there are a large number of trajectory pictures of the second character stored in the character database, in order to reduce the computing resources consumed in implementing step B, when matching the trajectory picture of the second character with several trajectory pictures of the second character in the character database, some trajectory pictures may be randomly selected from the trajectory pictures of the second character stored in the character database. Then, the trajectory picture converted from the second character of the first handwriting style is matched with the randomly selected partial trajectory pictures.
[0181] After determining the character trajectories that match the character trajectories corresponding to the respective characters of the first handwriting style, an index of the character trajectories corresponding to the respective characters of the first handwriting style may be generated.
[0182] Taking the characters "a", "b", and "c" of the first handwriting style as examples:
[0183] For the character trajectory of the first handwritten style character "a", it matches the 11th type of character trajectory among the M types of character trajectories of the character "a" stored in the character database; for the character trajectory of the first handwritten style character "b", it matches the 12th type of character trajectory among the M types of character trajectories of the character "b" stored in the character database; for the character trajectory of the first handwritten style character "c", it matches the 3rd type of character trajectory among the M types of character trajectories of the character "c" stored in the character database. Then, the indexes of the character trajectories corresponding to each character of the first handwritten style can include "a11b12c3".
[0184] Exemplary device
[0185] Based on the method provided in the above embodiments, the embodiments of the present application further provide a device, which will be introduced below in conjunction with the accompanying drawings.
[0186] See Figure 2 , this figure is a schematic structural diagram of a device for generating a handwritten formula provided by the embodiments of the present application. The device 200 may specifically include, for example: a first acquisition unit 201, a first determination unit 202, a second acquisition unit 203, and a first generation unit 204.
[0187] The first acquisition unit 201 is configured to acquire a formula to be processed.
[0188] The first determination unit 202 is configured to determine a first handwritten style.
[0189] The second acquisition unit 203 is configured to acquire the character trajectories corresponding to each character of the formula to be processed in the first handwritten style.
[0190] The first generation unit 204 is configured to generate a target handwritten formula in the first handwritten style according to the character trajectories.
[0191] Optionally, the second acquisition unit 203 is configured to:[[]]
[0192] According to the index values corresponding to each character of the formula to be processed in the first handwritten style, determine the character trajectories corresponding to each character of the formula to be processed in the first handwritten style from a pre-stored character database; where:
[0193] The formula to be processed includes a first character, and the index of the first character corresponding to the first handwritten style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory corresponding to the first handwritten style of the first character, and the multiple character trajectories correspond to at least one handwritten style.
[0194] Optionally, the device further includes:
[0195] A third acquisition unit, configured to acquire the character trajectories corresponding to each character of the first handwriting style;
[0196] A second determination unit, configured to determine, from the character database, character trajectories that match the character trajectories corresponding to each character of the first handwriting style according to the character trajectories corresponding to each character of the first handwriting style;
[0197] A second generation unit, configured to generate indexes of the character trajectories corresponding to each character of the first handwriting style.
[0198] Optionally, the second determination unit is configured to:
[0199] Match the trajectory pictures of the character trajectories corresponding to each character of the first handwriting style with the trajectory pictures corresponding to each character in the character database, and determine the character trajectories that match the character trajectories corresponding to each character of the first handwriting style;
[0200] Wherein:
[0201] Each character of the first handwriting style includes a second character. When the trajectory picture of the second character matches the first trajectory picture of the second character in the character database, the character trajectory corresponding to the first trajectory picture is determined as the character trajectory that matches the second character.
[0202] Optionally, the apparatus further includes:
[0203] A fourth acquisition unit, configured to acquire the character trajectories of each character and generate trajectory pictures corresponding to each character according to the character trajectories of each character;
[0204] A clustering unit, configured to cluster the trajectory pictures corresponding to each character, divide the character trajectories of each character into at least one category, and each category corresponds to a handwriting style;
[0205] A storage unit, configured to correspondingly store the at least one category of character trajectories of each character and the index values of each category of character trajectories in the at least one category of character trajectories of each character.
[0206] Optionally, the formula to be processed includes a first operand, the first operand includes multiple characters, and the first generation unit 204 is configured to:
[0207] Splice the character trajectories of the multiple characters included in the first operand according to a preset character splicing format to obtain the first operand in the first handwriting style;
[0208] Obtain the target handwritten formula according to the first operand of the first handwriting style.
[0209] Optionally, splice the character trajectories of multiple characters included in the first operand according to a preset character splicing format, including:
[0210] Splice each line of character trajectories in at least one line of character trajectories corresponding to the first operand respectively;
[0211] Splice each line of character trajectories obtained by splicing according to the character splicing format corresponding to the first operand.
[0212] Optionally, the device further includes:
[0213] A resampling unit, configured to perform dot-adding resampling on the character trajectories of some characters in the formula to be processed;
[0214] The first generating unit 204 is configured to generate the target handwritten formula according to the character trajectories after dot-adding resampling.
[0215] Optionally, the device further includes:
[0216] A third generating unit, configured to generate a picture including the target handwritten formula.
[0217] Optionally, the first determining unit 202 is configured to:
[0218] Output formulas in multiple handwriting styles;
[0219] In response to a selection operation triggered by a user for a first formula among the multiple formulas, determine the handwriting style corresponding to the first formula as the first handwriting style.
[0220] Since the device 200 corresponds to the method provided in the above method embodiment, the specific implementation of each unit of the device 200 is based on the same concept as the above method embodiment. Therefore, for the specific implementation of each unit of the device 200, reference may be made to the description part of the above method embodiment, which will not be elaborated here.
[0221] The method provided in the embodiment of the present application can be executed by a client or a server. The client and the server that execute the above method will be described separately below.
[0222] Figure 3 A block diagram of a client 300 is shown. For example, the client 300 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0223] Reference Figure 3 , the client 300 may include one or more of the following components: a processing component 302, a memory 304, a power component 306, a multimedia component 308, an audio component 310, an input / output (I / O) interface 313, a sensor component 314, and a communication component 316.
[0224] The processing component 302 generally controls the overall operation of the client 300, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing element 302 may include one or more processors 320 to execute instructions to complete all or part of the steps of the above-described methods. In addition, the processing component 302 may include one or more modules to facilitate the interaction between the processing component 302 and other components. For example, the processing component 302 may include a multimedia module to facilitate the interaction between the multimedia component 308 and the processing component 302.
[0225] The memory 304 is configured to store various types of data to support the operation of the client 300. Examples of such data include instructions for any application or method operating on the client 300, contact data, phone book data, messages, pictures, videos, etc. The memory 304 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disk.
[0226] The power component 306 provides power to various components of the client 300. The power component 306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the client 300.
[0227] The multimedia component 308 includes a screen that provides an output interface between the client 300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of the touch or swipe actions but also detect the duration and pressure associated with the touch or swipe operation. In some embodiments, the multimedia component 308 includes a front camera and / or a rear camera. When the client 300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front camera and the rear camera can be a fixed optical lens system or have a focal length and optical zoom capabilities.
[0228] The audio component 310 is configured to output and / or input audio signals. For example, the audio component 310 includes a microphone (MIC) that is configured to receive external audio signals when the client 300 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory 304 or transmitted via the communication component 316. In some embodiments, the audio component 310 further includes a speaker for outputting audio signals.
[0229] The I / O interface provides an interface between the processing component 302 and a peripheral interface module, which can be a keyboard, a click wheel, buttons, etc. These buttons can include but are not limited to: a home button, a volume button, a power button, and a lock button.
[0230] The sensor component 314 includes one or more sensors for providing status assessments of various aspects of the client 300. For example, the sensor component 314 can detect the on / off state of the device 300, the relative positioning of components, such as the display and the keypad of the client 300. The sensor component 314 can also detect a change in the position of the client 300 or a component of the client 300, the presence or absence of user contact with the client 300, the orientation or acceleration / deceleration of the client 300, and the temperature change of the client 300. The sensor component 314 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor component 314 can also include a light sensor, such as a CMOS or a CCD image sensor, for use in imaging applications. In some embodiments, the sensor component 314 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0231] The communication component 316 is configured to facilitate communication between the client 300 and other devices in a wired or wireless manner. The client 300 can access a communication standard-based wireless network, such as WiFi, 2G, or 3G, or a combination thereof. In an exemplary embodiment, the communication component 316 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 316 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0232] In an exemplary embodiment, the client 300 can be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components for performing the following methods:
[0233] Obtain a formula to be processed and determine a first handwriting style;
[0234] Obtain the character trajectories corresponding to each character in the formula to be processed in the first handwriting style;
[0235] Generate a target handwritten formula in the first handwriting style according to the character trajectories.
[0236] Optionally, obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style includes:
[0237] According to the index values corresponding to each character in the formula to be processed in the first handwriting style, determine the character trajectories corresponding to each character in the formula to be processed in the first handwriting style from a pre-stored character database; where:
[0238] The formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine the character trajectory corresponding to the first handwriting style of the first character from multiple character trajectories of the first character stored in the character database, and the multiple character trajectories correspond to at least one handwriting style.
[0239] Optionally, the method further includes:
[0240] Obtain the character trajectories corresponding to each character corresponding to the first handwriting style;
[0241] Based on the character trajectories corresponding to each character of the first handwriting style, determine, from the character database, the character trajectories that match the character trajectories corresponding to each character of the first handwriting style, and generate an index for the character trajectories corresponding to each character of the first handwriting style.
[0242] Optionally, the determining, from the character database, the character trajectories that match the character trajectories corresponding to each character of the first handwriting style based on the character trajectories corresponding to each character of the first handwriting style includes:
[0243] Match the trajectory images of the character trajectories corresponding to each character of the first handwriting style with the trajectory images of each character in the character database, and determine the character trajectories that match the character trajectories corresponding to each character of the first handwriting style;
[0244] Wherein:
[0245] Each character corresponding to the first handwriting style includes a second character. When the trajectory image of the second character matches the first trajectory image of the second character in the character database, determine the character trajectory corresponding to the first trajectory image as the character trajectory that matches the second character.
[0246] Optionally, the method further includes:
[0247] Obtain the character trajectories of each character, and generate trajectory images corresponding to each character according to the character trajectories of each character;
[0248] Cluster the trajectory images corresponding to each character, divide the character trajectories of each character into at least one category, and each category corresponds to a handwriting style;
[0249] Correspondingly store the at least one category of character trajectories of each character and the index values of each category of character trajectories in the at least one category of character trajectories of each character.
[0250] Optionally, the formula to be processed includes a first operand, and the first operand includes multiple characters. The generating the target handwritten formula of the first handwriting style according to the character trajectories includes:
[0251] Splice the character trajectories of the multiple characters included in the first operand according to a preset character splicing format to obtain the first operand of the first handwriting style;
[0252] Obtain the target handwritten formula according to the first operand of the first handwriting style.
[0253] Optionally, splicing the character trajectories of multiple characters included in the first operand according to a preset character splicing format includes:
[0254] Splicing each line of character trajectories in at least one line of character trajectories corresponding to the first operand respectively;
[0255] Splicing each line of character trajectories obtained by splicing according to the character splicing format corresponding to the first operand.
[0256] Optionally, the method further includes:
[0257] Performing dot filling and resampling on the character trajectories of some characters in the formula to be processed;
[0258] The generating the target handwritten formula in the first handwritten style according to the character trajectories includes:
[0259] Generating the target handwritten formula according to the character trajectories after dot filling and resampling.
[0260] Optionally, the method further includes:
[0261] Generating a picture including the target handwritten formula.
[0262] Optionally, the determining the first handwritten style includes:
[0263] Outputting formulas in multiple handwritten styles;
[0264] In response to a selection operation triggered by the user for a first formula among the multiple formulas, determining the handwritten style corresponding to the first formula as the first handwritten style.
[0265] Figure 4 It is a schematic structural diagram of a server in an embodiment of the present application. The server 400 may vary greatly due to configuration or performance differences, and may include one or more central processing units (CPUs) 422 (for example, one or more processors) and a memory 432, and one or more storage media 430 (for example, one or more mass storage devices) for storing application programs 442 or data 444. Among them, the memory 432 and the storage media 430 may be transient storage or persistent storage. The program stored in the storage media 430 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Further, the central processing unit 422 may be configured to communicate with the storage media 430 and execute a series of instruction operations in the storage media 430 on the server 400.
[0266] Furthermore, the central processing unit 422 may execute the following method:
[0267] Obtain a formula to be processed and determine a first handwriting style;
[0268] Obtain the character trajectories corresponding to each character in the formula to be processed in the first handwriting style;
[0269] Generate a target handwritten formula in the first handwriting style according to the character trajectories.
[0270] Optionally, obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style includes:
[0271] According to the index values corresponding to each character in the formula to be processed in the first handwriting style, determine the character trajectories corresponding to each character in the formula to be processed in the first handwriting style from a pre-stored character database; where:
[0272] The formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory corresponding to the first handwriting style of the first character, and the multiple character trajectories correspond to at least one handwriting style.
[0273] Optionally, the method further includes:
[0274] Obtain the character trajectories corresponding to each character corresponding to the first handwriting style;
[0275] According to the character trajectories corresponding to each character corresponding to the first handwriting style, determine, from the character database, the character trajectories matching the character trajectories corresponding to each character corresponding to the first handwriting style, and generate indexes of the character trajectories corresponding to each character corresponding to the first handwriting style.
[0276] Optionally, the determining, from the character database, the character trajectories matching the character trajectories corresponding to each character corresponding to the first handwriting style according to the character trajectories corresponding to each character corresponding to the first handwriting style includes:
[0277] Match the trajectory pictures of the character trajectories corresponding to each character corresponding to the first handwriting style with the trajectory pictures of each character in the character database, and determine the character trajectories matching the character trajectories corresponding to each character corresponding to the first handwriting style;
[0278] Where:
[0279] Each character corresponding to the first handwriting style includes a second character. When the trajectory image of the second character matches the first trajectory image of the second character in the character database, the character trajectory corresponding to the first trajectory image is determined as the character trajectory matching the second character.
[0280] Optionally, the method further includes:
[0281] Obtain the character trajectories of each character, and generate trajectory images corresponding to each character according to the character trajectories of each character;
[0282] Cluster the trajectory images corresponding to each character, divide the character trajectories of each character among the characters into at least one category, and each category corresponds to a handwriting style;
[0283] Correspondingly store the at least one category of character trajectories of each character and the index value of each category of character trajectories in the at least one category of character trajectories of each character.
[0284] Optionally, the formula to be processed includes a first operand, and the first operand includes multiple characters. Generating the target handwritten formula in the first handwriting style according to the character trajectory includes:
[0285] Splice the character trajectories of the multiple characters included in the first operand according to a preset character splicing format to obtain the first operand in the first handwriting style;
[0286] Obtain the target handwritten formula according to the first operand in the first handwriting style.
[0287] Optionally, splicing the character trajectories of the multiple characters included in the first operand according to a preset character splicing format includes:
[0288] Splice each row of character trajectories in at least one row of character trajectories corresponding to the first operand respectively;
[0289] Splice the character trajectories of each row obtained by splicing according to the character splicing format corresponding to the first operand.
[0290] Optionally, the method further includes:
[0291] Perform dot complement resampling on the character trajectories of some characters in the formula to be processed;
[0292] Generating the target handwritten formula in the first handwriting style according to the character trajectory includes:
[0293] Generate the target handwritten formula according to the character trajectory after dot complement resampling.
[0294] Optionally, the method further includes:
[0295] Generating an image including the target handwritten formula.
[0296] Optionally, determining the first handwriting style includes:
[0297] Outputting formulas in multiple handwriting styles;
[0298] In response to a selection operation triggered by the user for a first formula among the multiple formulas, determining the handwriting style corresponding to the first formula as the first handwriting style.
[0299] The server 400 may further include one or more power supplies 426, one or more wired or wireless network interfaces 450, one or more input / output interfaces 456, one or more keyboards 456, and / or one or more operating systems 441, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, and so on.
[0300] The embodiments of the present application further provide a computer-readable medium, on which instructions are stored, and when executed by one or more processors, cause the device to execute the following method:
[0301] Obtaining a formula to be processed and determining a first handwriting style;
[0302] Obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style;
[0303] Generating a target handwritten formula in the first handwriting style according to the character trajectories.
[0304] Optionally, obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style includes:
[0305] According to the index values corresponding to each character in the formula to be processed corresponding to the first handwriting style, determining, from a pre-stored character database, the character trajectories corresponding to each character in the formula to be processed in the first handwriting style; where:
[0306] The formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory corresponding to the first handwriting style of the first character, and the multiple character trajectories correspond to at least one handwriting style.
[0307] Optionally, the method further includes:
[0308] Obtain the character trajectories corresponding to each character of the first handwriting style;
[0309] According to the character trajectories corresponding to each character of the first handwriting style, determine, from the character database, the character trajectories that match the character trajectories corresponding to each character of the first handwriting style, and generate indexes for the character trajectories corresponding to each character of the first handwriting style.
[0310] Optionally, the determining, from the character database, the character trajectories that match the character trajectories corresponding to each character of the first handwriting style includes:
[0311] Match the trajectory images of the character trajectories corresponding to each character of the first handwriting style with the trajectory images of each character in the character database, and determine the character trajectories that match the character trajectories corresponding to each character of the first handwriting style;
[0312] Wherein:
[0313] Each character of the first handwriting style includes a second character. When the trajectory image of the second character matches the first trajectory image of the second character in the character database, determine the character trajectory corresponding to the first trajectory image as the character trajectory that matches the second character.
[0314] Optionally, the method further includes:
[0315] Obtain the character trajectories of each character, and generate trajectory images corresponding to each character according to the character trajectories of each character;
[0316] Cluster the trajectory images corresponding to each character, and divide the character trajectories of each character into at least one category, with each category corresponding to a handwriting style;
[0317] Correspondingly store the at least one category of character trajectories of each character and the index values of each category of character trajectories in the at least one category of character trajectories of each character.
[0318] Optionally, the formula to be processed includes a first operand, and the first operand includes multiple characters. Generating the target handwritten formula of the first handwriting style according to the character trajectories includes:
[0319] Stitch the character trajectories of the multiple characters included in the first operand according to a preset character stitching layout to obtain the first operand of the first handwriting style;
[0320] Obtain the target handwritten formula according to the first operand of the first handwriting style.
[0321] Optionally, splicing the character trajectories of multiple characters included in the first operand according to a preset character splicing format, including:
[0322] Splice each line of character trajectories in at least one line of character trajectories corresponding to the first operand respectively;
[0323] Splice each line of character trajectories obtained by splicing according to the character splicing format corresponding to the first operand.
[0324] Optionally, the method further includes:
[0325] Perform dot-insertion resampling on the character trajectories of some characters in the formula to be processed;
[0326] The generating the target handwritten formula according to the character trajectories includes:
[0327] Generate the target handwritten formula according to the character trajectories after dot-insertion resampling.
[0328] Optionally, the method further includes:
[0329] Generate a picture including the target handwritten formula.
[0330] Optionally, the determining the first handwriting style includes:
[0331] Output formulas in multiple handwriting styles;
[0332] In response to a selection operation triggered by the user for a first formula among the multiple formulas, determine the handwriting style corresponding to the first formula as the first handwriting style.
[0333] Those skilled in the art will readily conceive of other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include known common knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and examples are only regarded as exemplary, and the true scope and spirit of the present application are pointed out by the following claims.
[0334] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.
[0335] The above are only the preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included within the protection scope of the present application.
Claims
1. A method for generating handwritten formulas, characterized in that, the method includes: obtaining a formula to be processed and determining a first handwriting style; obtaining the character trajectories corresponding to each character in the formula to be processed in the first handwriting style, including: according to the index values corresponding to each character in the formula to be processed corresponding to the first handwriting style, determining from a pre-stored character database the character trajectories corresponding to each character in the formula to be processed in the first handwriting style, wherein the formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory of the first character corresponding to the first handwriting style, and the multiple character trajectories correspond to at least one handwriting style; performing dot supplementation and resampling on the character trajectories of some characters in the formula to be processed; generating a target handwritten formula in the first handwriting style according to the character trajectories after dot supplementation and resampling; wherein, the formula to be processed includes a first operand, the first operand includes multiple characters, and generating the target handwritten formula in the first handwriting style according to the character trajectories after dot supplementation and resampling includes: determining the characters included in each row of the first operand according to the latex formula string corresponding to the formula to be processed; respectively splicing each row of character trajectories in at least one row of character trajectories corresponding to the first operand; splicing the spliced character trajectories of each row according to the character splicing layout corresponding to the first operand to obtain the first operand in the first handwriting style, the character splicing layout includes complex upper and lower type structures in the formula, the character splicing layout includes the character splicing layout of fractions and the character splicing layout of radicals, the character splicing layout of fractions is frac[a][b][c], where a is used to describe the relative length of the line in the middle of the fraction, the relative length represents the proportion of the middle line in the maximum length of the upper and lower expressions, b is used to describe the relative distance between the denominator and the middle line, and c is used to describe the relative distance between the numerator and the middle line, and the character splicing layout of radicals is sqrt[a][b][c][d][e], a represents the proportion of the height of the power mark of the square root in the height of the text in the following line, b and c respectively represent the relative offsets of the center point of the superscript of the square root from the vertex of the square root on the horizontal and vertical axes, and d and e respectively represent the relative offsets of the center point of the text in the following line of the square root from the vertex of the square root on the horizontal and vertical axes; obtaining the target handwritten formula according to the first operand in the first handwriting style.
2. The method according to claim 1, characterized in that, the method further includes: obtaining the character trajectories corresponding to each character corresponding to the first handwriting style; Based on the character trajectories corresponding to each character of the first handwriting style, from the character database, determine the character trajectories that match the character trajectories corresponding to each character of the first handwriting style, and generate an index for the character trajectories corresponding to each character of the first handwriting style.
3. The method according to claim 2, wherein, the step of determining, from the character database, the character trajectories that match the character trajectories corresponding to each character of the first handwriting style based on the character trajectories corresponding to each character of the first handwriting style includes: Matching the trajectory pictures of the character trajectories corresponding to each character of the first handwriting style with the trajectory pictures of each character in the character database to determine the character trajectories that match the character trajectories corresponding to each character of the first handwriting style; wherein: Each character corresponding to the first handwriting style includes a second character. When the trajectory picture of the second character matches the first trajectory picture of the second character in the character database, the character trajectory corresponding to the first trajectory picture is determined as the character trajectory that matches the second character.
4. The method according to claim 1, wherein, the method further includes: Obtaining the character trajectories of each character, and generating trajectory pictures corresponding to each character according to the character trajectories of each character; Clustering the trajectory pictures corresponding to each character, and dividing the character trajectories of each character into at least one category, with each category corresponding to a handwriting style; Correspondingly storing the at least one category of character trajectories of each character and the index values of each category of character trajectories in the at least one category of character trajectories of each character.
5. The method according to claim 1, wherein, the method further includes: Generating a picture including the target handwritten formula.
6. The method according to claim 1, wherein, the step of determining the first handwriting style includes: Outputting formulas in multiple handwriting styles; In response to a selection operation triggered by the user for the first formula among the multiple formulas, determining the handwriting style corresponding to the first formula as the first handwriting style.
7. A device for generating handwritten formulas, wherein, the device includes: A first acquisition unit for acquiring a formula to be processed; A first determination unit for determining a first handwriting style; A second acquisition unit, configured to acquire the character trajectories corresponding to the respective characters in the formula to be processed in the first handwriting style, including: determining, according to the index values corresponding to the respective characters in the formula to be processed corresponding to the first handwriting style, from a pre-stored character database, the character trajectories corresponding to the respective characters in the formula to be processed in the first handwriting style, where the formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory of the first character corresponding to the first handwriting style, and the multiple character trajectories correspond to at least one handwriting style; A resampling unit, configured to perform dot-adding resampling on the character trajectories of some characters in the formula to be processed; A first generation unit, configured to generate a target handwritten formula in the first handwriting style according to the character trajectories after dot-adding and resampling; wherein the formula to be processed includes a first operand, the first operand includes multiple characters, and the first generation unit is configured to: determine the characters included in each row of the first operand according to the latex formula string corresponding to the formula to be processed; perform splicing on each row of character trajectories in at least one row of character trajectories corresponding to the first operand respectively; perform splicing on the spliced character trajectories of each row according to the character splicing format corresponding to the first operand to obtain the first operand in the first handwriting style, the character splicing format includes complex upper and lower type structures in the formula, the character splicing format includes the character splicing format of a fraction and the character splicing format of a radical, the character splicing format of the fraction is frac[a][b][c], where a is used to describe the relative length of the line in the middle of the fraction, and the relative length represents the proportion of the middle line in the maximum length of the upper and lower expressions, b is used to describe the relative distance between the denominator and the middle line, and c is used to describe the relative distance between the numerator and the middle line, and the character splicing format of the radical is sqrt[a][b][c][d][e], a represents the proportion of the height of the power mark of the radical in the height of the text in the following line, b and c respectively represent the relative offsets of the center point of the superscript of the radical from the vertex of the radical on the horizontal and vertical axes, and d and e respectively represent the relative offsets of the center point of the text in the following line of the radical from the vertex of the radical on the horizontal and vertical axes; obtain the target handwritten formula according to the first operand in the first handwriting style.
8. The apparatus according to claim 7, wherein, the apparatus further includes: a third acquisition unit, configured to acquire the character trajectories corresponding to the respective characters corresponding to the first handwriting style; a second determination unit, configured to determine, from the character database, the character trajectories matching the character trajectories corresponding to the respective characters corresponding to the first handwriting style according to the character trajectories corresponding to the respective characters corresponding to the first handwriting style; a second generation unit, configured to generate indexes of the character trajectories corresponding to the respective characters corresponding to the first handwriting style.
9. The apparatus according to claim 7, It is characterized in that the device further comprises: a fourth acquisition unit, configured to acquire the character trajectories of each character, and generate a trajectory picture corresponding to each character according to the character trajectories of each character; a clustering unit, configured to cluster the trajectory pictures corresponding to each character, and divide the character trajectories of each character among the characters into at least one category, with each category corresponding to a handwriting style; a storage unit, configured to correspondingly store the at least one category of character trajectories of each character, and the index value of each category of character trajectories in the at least one category of character trajectories of each character.
10. A device for generating a handwritten formula It is characterized in that it includes a memory and one or more programs, where one or more programs are stored in the memory and are configured to be executed by one or more processors, and the one or more programs include instructions for performing the following operations: acquire a formula to be processed and determine a first handwriting style; acquire the character trajectories corresponding to the first handwriting style of each character in the formula to be processed, including: according to the index values corresponding to each character in the formula to be processed corresponding to the first handwriting style, determine, from a pre-stored character database, the character trajectories corresponding to the first handwriting style of each character in the formula to be processed, where the formula to be processed includes a first character, and the index of the first character corresponding to the first handwriting style is used to determine, from multiple character trajectories of the first character stored in the character database, the character trajectory corresponding to the first handwriting style of the first character, and the multiple character trajectories correspond to at least one handwriting style; perform dot filling and resampling on the character trajectories of some characters in the formula to be processed; generate a target handwritten formula in the first handwriting style according to the character trajectories after dot filling and resampling; wherein, the formula to be processed includes a first operand, the first operand includes multiple characters, and generating the target handwritten formula in the first handwriting style according to the character trajectories after dot filling and resampling includes: determine the characters included in each row of the first operand according to the latex formula string corresponding to the formula to be processed; concatenate each row of character trajectories corresponding to the first operand respectively; The character trajectories of each line obtained by splicing are spliced according to the character splicing format corresponding to the first operand, so as to obtain the first operand of the first handwriting style. The character splicing format includes complex upper and lower structures in a formula. The character splicing format includes the character splicing format of a fraction and the character splicing format of a radical. The character splicing format of the fraction is frac[a][b][c], where a is used to describe the relative length of the line in the middle of the fraction, and the relative length represents the proportion of the middle line in the maximum length of the upper and lower expressions. b is used to describe the relative distance between the denominator and the middle line, and c is used to describe the relative distance between the numerator and the middle line. The character splicing format of the radical is sqrt[a][b][c][d][e], where a represents the proportion of the height of the power mark of the square root in the height of the text in the following line. b and c respectively represent the relative offsets of the center point of the superscript of the square root from the vertex of the square root on the horizontal and vertical axes. d and e respectively represent the relative offsets of the center point of the text in the following line of the square root from the vertex of the square root on the horizontal and vertical axes; The target handwritten formula is obtained according to the first operand of the first handwriting style.
11. A computer-readable medium having instructions stored thereon that, when executed by one or more processors, cause the apparatus to perform the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for handwriting recognition
CN106339726A