Handwriting generation method and device, computer device and readable medium
Patent Information
- Application Number
- CN202180004080.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2041-12-21
AI Technical Summary
目前,在手写笔迹生成方案中,还无法实现上述记号笔手写笔迹呈现效果
Smart Images

Figure CN116648686B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer application technology, and specifically relates to a method, apparatus, computer device, and readable medium for generating handwriting. Background Technology
[0002] In fields such as smart education, business offices, and smart healthcare, interactive whiteboards and similar devices serve as convenient tools that play a crucial role in information exchange and sharing. However, the quality of handwriting generated by the stylus pen on these devices represents a bottleneck in the user experience.
[0003] Because marker pen ink can transparently reveal the text it covers, it is widely used for marking important information. Currently, handwriting generation solutions cannot achieve the same effect as marker pen handwriting. Summary of the Invention
[0004] The present invention aims to at least solve one of the technical problems existing in the prior art, and to provide a method, apparatus, computer device and readable medium for generating handwriting with a marker pen effect.
[0005] In a first aspect, embodiments of the present invention provide a method for generating handwritten strokes. The method is used to generate marker handwriting based on handwritten strokes. The marker handwriting includes at least one stroke segment, wherein each stroke segment is generated in the following manner:
[0006] Obtain sampling points of the handwritten trajectory, and generate a handwritten trajectory curve based on the sampling points. The handwritten trajectory is the trajectory of a trajectory segment in a handwritten stroke.
[0007] Determine the arc length τ between interpolation points;
[0008] The position of the interpolation point on the handwritten trajectory curve is determined based on the arc length τ between the interpolation points, wherein the arc length between two adjacent interpolation points on the handwritten trajectory curve is the same as the arc length τ between the interpolation points.
[0009] Handwriting effect parameters are superimposed at the interpolation point to generate handwriting of a marker corresponding to the handwritten trajectory curve.
[0010] Secondly, embodiments of the present invention also provide a handwriting generation device for generating handwriting from a marker pen based on a handwriting trajectory. The handwriting from the marker pen includes at least one handwriting segment. The handwriting generation device includes a handwriting trajectory generation module, a first processing module, a second processing module, and a handwriting generation module.
[0011] The handwriting trajectory generation module is used to obtain sampling points of the handwriting trajectory and generate a handwriting trajectory curve based on the sampling points;
[0012] The first processing module is used to determine the arc length τ between interpolation points;
[0013] The second processing module is used to determine the position of the interpolation point on the handwritten trajectory curve according to the arc length τ between the interpolation points, wherein the arc length between two adjacent interpolation points on the handwritten trajectory curve is the same as the arc length τ between the interpolation points;
[0014] The handwriting generation module is used to overlay handwriting effect parameters at the position of the interpolation point to generate handwriting of a marker pen corresponding to the handwriting trajectory curve.
[0015] Thirdly, embodiments of the present invention also provide a computer device, comprising:
[0016] One or more processors;
[0017] A storage device on which one or more programs are stored;
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the handwriting generation method as described above.
[0019] Fourthly, embodiments of the present invention also provide a computer-readable medium having a computer program stored thereon, wherein the program, when executed, implements the handwriting generation method as described above. Attached Figure Description
[0020] Figure 1 This is a schematic diagram of the software architecture of an embodiment of the present invention;
[0021] Figure 2 This is a schematic diagram of the handwriting generation method according to an embodiment of the present invention;
[0022] Figure 3 This is a schematic diagram illustrating the generation of a second-order Bézier curve according to an embodiment of the present invention;
[0023] Figure 4a This is a schematic diagram of unequal arc length interpolation in related technologies;
[0024] Figure 4b This is a schematic diagram of equal arc length interpolation in an embodiment of the present invention;
[0025] Figure 5 This is a schematic diagram of the process for determining the position of interpolation points on the handwritten trajectory curve according to an embodiment of the present invention;
[0026] Figure 6 This is a schematic diagram of the process for calculating the t-value of an interpolation point on a handwritten trajectory curve according to an embodiment of the present invention;
[0027] Figure 7The iterative value t for calculating the value of t in this embodiment of the invention. j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 A flowchart illustrating the process.
[0028] Figure 8 This is a flowchart illustrating the process of calculating the approximate arc length L(1) of the handwritten trajectory curve according to an embodiment of the present invention;
[0029] Figure 9 This is a schematic diagram illustrating the effects of various brush parameters in an embodiment of the present invention;
[0030] Figure 10 This is a schematic diagram illustrating the various handwriting effect parameters presented in embodiments of the present invention;
[0031] Figure 11a This is a schematic diagram of the handwritten trajectory according to an embodiment of the present invention;
[0032] Figure 11b This is a schematic diagram illustrating the process of selecting interpolation points using equal arc length interpolation in a handwritten trajectory without superimposing handwriting effect parameters, according to an embodiment of the present invention.
[0033] Figure 11c In order to be in Figure 11b A diagram illustrating the effect of a marker pen stroke created by overlaying transparency.
[0034] Figure 12 This is a schematic diagram of the handwriting generation device according to an embodiment of the present invention;
[0035] Figure 13 This is a schematic diagram of the structure of the second processing module in an embodiment of the present invention. Figure 1 ;
[0036] Figure 14 This is a schematic diagram of the structure of the second processing module in an embodiment of the present invention. Figure 2 . Detailed Implementation
[0037] To enable those skilled in the art to better understand the technical solution of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0038] Unless otherwise defined, the technical or scientific terms used in this disclosure shall have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms “first,” “second,” and similar terms used in this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an,” “a,” or “the,” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The terms “including,” “comprising,” or “containing,” and similar terms mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. The terms “connected,” “linked,” or similar terms are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. The terms “upper,” “lower,” “left,” and “right,” etc., are used only to indicate relative positional relationships, and these relative positional relationships may change accordingly when the absolute position of the described objects changes.
[0039] This invention provides a method for generating handwriting, which is applied to a handwriting generation device, and the handwriting generation device is a functional module of a terminal device. Figure 1 This is a schematic diagram of the software architecture of an embodiment of the present invention, such as... Figure 1 As shown, the terminal device obtains handwriting effect parameters through the application layer module. After obtaining the sampling points and brush parameters of the handwriting trajectory, the application layer module sends them to the algorithm module through the JNI interface (Java Native Interface). The algorithm module generates the handwriting trajectory curve and determines the position of the interpolation point on the handwriting trajectory curve. Then, it sends the position of the interpolation point to the application module through the JNI interface. The application layer module then generates the handwriting of the marker pen corresponding to the handwriting trajectory curve. In this embodiment of the invention, the terminal device has a display function and may have, but is not limited to, a touch function. For example, the terminal device can be a large-size (generally 50 inches or more) intelligent touch display device such as a conference whiteboard or teaching whiteboard. By handwriting marking the text, images, tables, and other content on the terminal device, different shapes, colors, thicknesses, and transparency of marker pens can be presented, achieving superimposed effects in terms of transparency, handwriting width, patterns, and colors.
[0040] The handwriting generation method provided in this invention is used to generate marker pen handwriting based on handwritten strokes. The marker pen handwriting includes at least one handwriting segment, wherein each handwriting segment can be generated by... Figure 2 The steps shown are used to generate the product. Figure 2 As shown, the method for generating handwriting segments includes the following steps:
[0041] Step 1: Obtain sampling points for the handwritten trajectory and generate a handwritten trajectory curve based on the sampling points. The handwritten trajectory is the trajectory of a segment of the handwritten stroke.
[0042] Handwritten strokes can be the touch trajectories of a user on a terminal device's touchscreen. In this step, a trajectory segment of the handwritten stroke is sparsely sampled to obtain sampling points, and the handwritten trajectory curve of that trajectory segment is generated based on the sampling points.
[0043] It should be noted that the handwriting trajectory curve can also be a preset trajectory curve for handwriting smoothing, such as a Bézier curve; however, in the specific handwriting drawing process, sampling points need to be obtained to obtain a specific handwriting trajectory curve. For example, the obtained sampling points can be used as control points for the Bézier curve to generate a specific Bézier curve; however, it should be noted that the generated specific Bézier curve does not necessarily have to be displayed on the screen, but is used for subsequent interpolation point calculations.
[0044] Step 2: Determine the arc length τ between interpolation points.
[0045] The arc length τ between interpolation points is the arc length between two adjacent interpolation points on the handwritten trajectory curve. For the first interpolation point, the arc length τ between interpolation points is the arc length between the first interpolation point and the first sampling point on the handwritten trajectory curve.
[0046] Step 3: Determine the position of the interpolation point on the handwritten trajectory curve based on the arc length τ between the interpolation points. The arc length between two adjacent interpolation points on the handwritten trajectory curve is the same as the arc length τ between the interpolation points.
[0047] In this embodiment of the invention, equal arc length interpolation is performed on the handwritten trajectory curve. After interpolation, the arc length between any two adjacent interpolation points on the handwritten trajectory curve is the same. It should be noted that the same arc length here can be understood as being basically the same as the arc length τ between interpolation points. Considering that absolute equality is an ideal state, and that subsequent arc length calculation involves approximation, arc length convergence, and iterative calculation methods, the equal arc length interpolation mentioned here is not an absolutely equal arc length, but rather the arc length error is within a certain range. In some embodiments, this error range can be 20% or 30%.
[0048] Step 4: Overlay the handwriting effect parameters at the interpolation point to generate the handwriting of the marker pen corresponding to the handwritten trajectory curve.
[0049] In this step, handwriting effect parameters are superimposed at the interpolation points on the handwriting trajectory curve to achieve a marker pen effect for the handwriting trajectory. These handwriting effect parameters can be preset in the application layer module of the terminal device for user selection. By superimposing different types of handwriting effect parameters, marker pen handwriting with different display effects can be presented.
[0050] In some embodiments, due to the characteristics of the marker, the handwriting generated by the marker has a certain degree of transparency in order to mark content without affecting the presentation of the marked content. The handwriting effect parameter includes transparency. Overlaying the transparency handwriting effect parameter at the interpolation point can increase the transparency at that location. For example, the transparency before overlaying the handwriting effect parameter is 20%, and the transparency after overlaying the handwriting effect parameter becomes 40%. It should be noted that the handwriting effect parameter can be linearly or non-linearly overlaid at the interpolation point.
[0051] In some embodiments, handwriting effect parameters may include at least one of the following: color, thickness, and pattern. Figure 10 It shows the effect of overlapping strokes of different thicknesses, colors and patterns, such as hearts, leaves, butterflies and rainbows.
[0052] In some embodiments, generating the handwritten trajectory curve based on the sampling points (i.e., step 1) may include the following steps: generating the handwritten trajectory curve according to the Bézier curve algorithm. Correspondingly, determining the position of the interpolation point on the handwritten trajectory curve (i.e., step 3) includes the following steps: determining the position of the interpolation point on the handwritten trajectory curve using an iterative algorithm.
[0053] Bézier curves are widely used in graphic design and path planning. The shape of a Bézier curve is determined by control points. n control points generate a (n-1) order Bézier curve, which can be generated recursively.
[0054] Taking a second-order Bézier curve as an example, such as Figure 3 As shown, a second-order Bézier curve has three non-collinear control points P0, P1, and P2. The formula for a second-order Bézier curve is formula (1):
[0055] C2(t)=(1-t) 2 P0+2t(1-t)P10t 2 P2 (1)
[0056] Where C2 is P0”, t is the parameter scale of the Bézier curve, t∈[0,1].
[0057] In this embodiment of the invention, a second-order Bézier curve algorithm is used to generate the handwritten trajectory curve. Therefore, the application layer module sends three sampling points as control points to the algorithm module each time through the JNI interface.
[0058] In some embodiments, obtaining sampling points of the handwritten trajectory and generating a handwritten trajectory curve according to the Bézier curve algorithm (i.e., step 1) includes: obtaining three sampling points of the handwritten trajectory and generating a handwritten trajectory curve according to the three sampling points using the Bézier curve algorithm, wherein the middle sampling point is taken as the vertex and the line connecting two adjacent sampling points is taken as the side to form an angle, that is, the three sampling points are not collinear.
[0059] When the first included angle is greater than the second included angle, the number of interpolation points on the first handwritten trajectory curve is greater than the number of interpolation points on the second handwritten trajectory curve. The first handwritten trajectory curve is generated using the Bézier curve algorithm based on the three sampling points of the first group. The first included angle is the angle formed with the middle sampling point of the first group as the vertex and the line connecting any two adjacent sampling points in the first group as the side. The second handwritten trajectory curve is generated using the Bézier curve algorithm based on the three sampling points of the second group. The second included angle is the angle formed with the middle sampling point of the second group as the vertex and the line connecting any two adjacent sampling points in the second group as the side.
[0060] Combination Figure 3 As shown, for a second-order Bézier curve, the three sampling points are P0, P1, and P2. With P1 as the vertex and P0P1 and P2P1 as the sides, an angle θ is formed. The larger the angle θ, the longer the arc length of the second-order Bézier curve, and the more interpolation points are selected on that arc length.
[0061] After generating the handwritten trajectory curve using the Bézier curve algorithm, a common method in this field is to directly take t values from 0 to 1 arithmetic progressions (i.e., the difference between the t values corresponding to two adjacent interpolation points is equal), resulting in interpolation points such as... Figure 4a As shown, the interpolation points are unevenly distributed along the handwriting trajectory curve. The interpolation points are denser at the curve's bends and sparser where the curve is flat. With a small radius of curvature, the handwriting trajectory curve is more curved, and multiple interpolation points at bends may almost overlap. After superimposing the handwriting effect parameters, the resulting handwriting shows a rapid color darkening at bends, leading to uneven overall color, poor handwriting realism, and an unsatisfactory presentation. This invention aims to achieve... Figure 4b The interpolation points shown are evenly distributed on the handwriting trajectory curve. The even distribution of interpolation points on the entire handwriting trajectory curve can avoid the situation where multiple interpolation points overlap at the bend of the handwriting trajectory curve when the radius of curvature is small. After superimposing the handwriting effect parameters, the color of the handwriting at the bend is darker to a certain extent than the color at the flat area, but not too dark, and the realism of the handwriting is good, thereby improving the presentation effect.
[0062] The handwriting generation method provided in this invention targets a handwritten trajectory segment within a handwritten stroke. By performing equal arc length interpolation on the corresponding handwritten trajectory curve, with adjacent interpolation points having the same arc length, and superimposing handwriting effect parameters at the interpolation point positions, it can generate marker pen handwriting corresponding to the handwritten trajectory curve, enriching the presentation effect of handwriting. Moreover, the marker pen handwriting can present a handwriting superposition effect while transparently displaying the covered content. That is, at the overlapping positions of strokes, the handwriting effect parameters of different strokes are superimposed on each other. For example, the color at the overlapping position is darker than the color at the non-overlapping position, making the marker pen handwriting presentation effect more realistic.
[0063] In some embodiments, the iterative algorithm is the Newton-Raphson algorithm. The following uses the Newton-Raphson algorithm as an example to illustrate the scheme of the present invention.
[0064] In some embodiments, such as Figure 5 As shown, determining the position of the interpolation point on the handwritten trajectory curve based on the arc length τ between interpolation points (i.e., step 3) includes the following steps:
[0065] Step 31: For each interpolation point, calculate the t-value of the interpolation point on the handwritten trajectory curve using the Newton-Raphson iteration algorithm.
[0066] In this step, for each interpolation point, the iterative value t is... j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 Regarding the convergence of the arc length S between the interpolation point and the first sampling point in the handwritten trajectory curve, where j+1 is the current iteration number, 1≤j+1≤N, and N is the preset maximum iteration number. In other words, the convergence condition of Newton's iterative algorithm is: L(t j+1 )≈S. Where S is a multiple of the arc length τ between interpolation points. For example, the arc length between the first interpolation point and the first sampling point in the handwritten trajectory curve is S=τ, the arc length between the second interpolation point and the first sampling point in the handwritten trajectory curve is S=2τ, the arc length between the third interpolation point and the first sampling point in the handwritten trajectory curve is S=3τ, and so on.
[0067] Using the method described above, the t-values of each interpolation point on the handwritten trajectory curve can be calculated. These t-values are the t-values obtained by equal arc length interpolation that meets the convergence condition.
[0068] Step 32: Based on the t-value of the interpolation point on the handwritten trajectory curve, determine the position of the interpolation point on the handwritten trajectory curve using the Bézier curve algorithm.
[0069] In this step, the t values (converged t values) of each interpolation point calculated in step 31 are substituted into the second-order Bézier curve formula, i.e. formula (1), to obtain the position of the corresponding interpolation point on the handwritten trajectory curve.
[0070] In some embodiments, before calculating the t-value of the interpolation point on the handwritten trajectory curve using the Newton-Raphson iteration algorithm for each interpolation point (i.e., step 31), the handwritten stroke generation method may further include the following step: calculating the approximate arc length L(1) of the handwritten trajectory curve. The pen strokes correspond to the handwritten strokes, and the pen strokes include at least one stroke segment. Correspondingly, the handwritten strokes also include at least one trajectory segment. The pen stroke segments are generated segment by segment, and the stroke segments correspond one-to-one with the trajectory segments. The approximate arc length L(1) of the handwritten trajectory curve is the total arc length of the handwritten trajectory curve of the current trajectory segment, which is the arc length of the handwritten trajectory curve corresponding to t=1 in the current trajectory segment.
[0071] Accordingly, the step of calculating the t value of the interpolation point on the handwritten trajectory curve using the Newton iteration algorithm for each interpolation point (i.e., step 31) may include the following steps: for each interpolation point, within the approximate arc length L(1) of the handwritten trajectory curve, calculate the t value of the interpolation point on the handwritten trajectory curve using the Newton iteration algorithm.
[0072] In some embodiments, such as Figure 6 As shown, the t-value at each interpolation point on the handwritten trajectory curve can be calculated using the following steps:
[0073] Step 311: Calculate the initial t value t0 of the interpolation point.
[0074] Generally, due to the properties of spline curves like Bézier curves, there will be no steep curve between two interpolation points. The smoothness of the handwritten trajectory curve between two interpolation points can be ensured by increasing the number of interpolation points. Therefore, the t value can be considered to be close to the ratio of S to the approximate arc length L(1) of the handwritten trajectory curve. Therefore, in some embodiments, the initial t value of the interpolation point can be calculated by formula (2), thereby reducing the amount of computation:
[0075]
[0076] Where L(1) is the approximate arc length of the handwritten trajectory curve.
[0077] Step 312: Calculate the approximate arc length L(t0) corresponding to the initial t value t0 on the handwritten trajectory curve.
[0078] Step 313: Calculate the absolute value of the difference between the arc length S between the interpolation point and the first sampling point in the handwritten trajectory curve and the approximate arc length L(t0) corresponding to the initial t value t0 on the handwritten trajectory curve.
[0079] In this step, Δ = |SL(t0)| is calculated. The absolute value reflects the accuracy of the t value; the smaller the absolute value, the more accurate the t value. In some embodiments, Δ can be 0.0001 pixels.
[0080] Step 314: In response to the absolute value being greater than a preset first threshold, the t-value of the interpolation point is iteratively calculated using the Newton-Raphson iteration algorithm until the arc length S between the interpolation point and the first sampling point in the handwritten trajectory curve is iterated over to the t-value. j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 When the absolute value of the difference between t and j is less than or equal to the first threshold, the iteration stops. j+1 is the current iteration number, and t is the iteration value of t when the iteration stops. j+1 t is the value of the interpolation point.
[0081] In this step, if the absolute value is greater than the first threshold, it means that the current t value is inaccurate and equal arc length interpolation cannot be achieved according to this t value. Therefore, it is necessary to iteratively calculate the t value using the Newton iteration algorithm. If the absolute value is less than or equal to the first threshold, it means that the current t value is accurate and equal arc length interpolation can be achieved according to this t value without further iterative calculation.
[0082] The relationship between the arc length L of a second-order Bézier curve and t can be calculated in the following way:
[0083] Assume 0 = a = t1 < t2 < t3 < ... < t m =b=t, m is the total number of t, then the arc length of the handwritten trajectory curve can be approximated by the sum of the distances between the scattered points in the interval, resulting in formula (3):
[0084]
[0085] According to the mean value theorem, formula (3) can be transformed to obtain formula (4):
[0086]
[0087] in, It is the interval [t] j ,t j+1 A value in ] It is the point on the first derivative of the handwritten trajectory curve. The length.
[0088] When t j+1 -t j →0, the approximate relationship between the approximate arc length L of the handwritten trajectory curve and t becomes formula (5):
[0089]
[0090] Since the inverse function of formula (5) cannot be directly obtained, that is, given L = S, the value of t cannot be obtained. Only based on the value of t can the position of the interpolation point with arc length L = S be finally determined on the handwritten trajectory curve. Therefore, it is necessary to solve for the root of equation (10):
[0091] L(t)-S=0 (6)
[0092] The Newton-Raphson iteration algorithm starts with an initial point position (coordinates), draws a tangent line at that initial point, and obtains the position of the next iteration point by intersecting the X-axis with the tangent line. It then draws another tangent line at that position, and so on, until an approximate solution that meets the accuracy requirements is obtained.
[0093] In this embodiment of the invention, according to equation (6), let f(t) = L(t) - S, and let the first derivative of f(t) be f′(t), then the iterative equation is formula (7):
[0094]
[0095] The calculated t j+1 As the next t j Substituting into formula (7) and solving, the root of f(t) can be obtained after several iterations. Where j+1 is the current iteration number, 1≤j+1≤N, and N is the preset maximum iteration number; f′(t)=L′(t)=|C′(t)|, C′(t) is the first derivative of the second-order Bézier curve, which can be obtained by differentiating formula (1). The formula (8) for the first derivative of the second-order Bézier curve is as follows:
[0096] C′2(t)=2((1-t)(P1-P0)+t(P2-P1)) (8)
[0097] It should be noted that the derivative of a Bézier curve is the derivative of the coordinate point with respect to t, which includes both x and y dimensions. When calculating the derivative of the arc length, it is necessary to convert from x and y to the derivative of the arc length.
[0098] In some embodiments, such as Figure 7 As shown, in step 314, the iterative value t can be calculated through the following steps. j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 ):
[0099] Step 3141: Calculate the approximate arc length L' of the iteration difference. The approximate arc length L' of the iteration difference is the value t before the iteration. j The corresponding position on the handwritten trajectory curve and the iteration value t obtained in the next iteration. j+1 Approximate arc length between corresponding positions on the handwritten trajectory curve.
[0100] Step 3142, based on the value t before iteration t j The approximate arc length L(t) on the handwritten trajectory curve j Given the approximate arc length L' of the iteration difference, calculate the iterative value t of the next iteration. j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 ).
[0101] For example, suppose that in the process of calculating the t value of the current interpolation point, the t value obtained after five iterations is t5, i.e., j+1=5, and the iterative value of t obtained after four iterations is t4. The position corresponding to t5 on the handwritten trajectory curve is A5, and the position corresponding to t4 on the handwritten trajectory curve is A4. The first sampling point in the handwritten trajectory curve is O. When calculating the approximate arc length L(t5) corresponding to t5 on the handwritten trajectory curve, since L(t5)=OA5, we can first calculate the arc length A5A4 of the iteration difference between A5 and A4, i.e., L'=A5A4. Then, L(t5)=OA5=OA4±A5A4=L(t4)±L'. Since OA4=L(t4), and L(t4) has already been calculated when iterating t4, we can directly obtain the value of L(t4) and sum it with L' to obtain the approximate arc length L(t5) corresponding to t5 on the handwritten trajectory curve. This iterative value t for calculating the t value j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 The proposed solution eliminates the need for repetitive calculations, saving computing power and increasing processing speed.
[0102] It should be noted that, in the process of calculating the t-values of each interpolation point after the second interpolation point on the handwritten trajectory curve according to steps 311-314, taking the calculation of the t-value of the second interpolation point as an example, in step 312, in the process of calculating the approximate arc length corresponding to the initial t-value of the second interpolation point on the handwritten trajectory curve, it can be obtained by summing the arc length between the initial t-values of the first interpolation point and the initial t-values of the second interpolation point and the arc length between the first sampling point and the first interpolation point in the handwritten trajectory curve that has already been calculated, which can save computing power.
[0103] It should be noted that, since there is no analytical solution for the definite integral of formula (5) for Bézier curves, it is necessary to solve it by numerical integration. Therefore, for the handwritten trajectory curve generated by the Bézier curve algorithm, the accurate arc length cannot be obtained, but only the approximate arc length can be obtained.
[0104] In some embodiments, the approximate arc length can be calculated by the following steps: determining the t-values of the starting point and the ending point of the handwritten trajectory curve corresponding to the approximate arc length; and calculating the approximate arc length using the Simpson 3 / 8 algorithm based on the t-values of the starting point and the ending point.
[0105] In this embodiment of the invention, the approximate arc length includes: the approximate arc length L(1) of the handwritten trajectory curve, and the iterative value t of the t value. j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 ), the approximate arc length L(t0) corresponding to the initial t value t0 on the handwritten trajectory curve and the approximate arc length L' of the iteration difference.
[0106] When the approximate arc length is L(1) of the handwritten trajectory curve, the t value at the starting point is 0, and the t value at the ending point is 1; when the approximate arc length is the iterative value t of the t value... j+1 The approximate arc length L(t) on the handwritten trajectory curve j+1 When t is the starting point, the value of t is 0, and the value of t is the iterative value of t at the ending point. j+1 When the approximate arc length is L(t0) corresponding to the initial t value t0 on the handwritten trajectory curve, the t value at the starting point is 0, and the t value at the ending point is the initial t value t0; when the approximate arc length is L' of the iteration difference, the t value at the starting point is the t value before the iteration. j The endpoint t is the iteration value t obtained in the next iteration. j+1 .
[0107] For Bézier curves, the definite integral of the approximate relationship between the arc length L and t of the handwritten trajectory curve (i.e., formula (5)) is unsolvable and needs to be solved by numerical integration. For Bézier curves, the arc length needs to be obtained by integrating the derivative f(x) of the arc length, and the derivative of the arc length of the Bézier curve can be obtained by converting the derivative of the Bézier curve.
[0108] In some embodiments, the Simpson 3 / 8 algorithm can be used to approximate the curve to be integrated (i.e., f(x)) as a cubic curve: f(x) = a0 + a1x + a2x 2 +a3x 3 The value of the integral can be approximated as: Where x0 = a, x3 = b.
[0109] It should be noted that, due to the arbitrariness of the handwritten trajectory curve, for a given value of t, the corresponding approximate arc length L(t) needs to be calculated by approximately summing multiple curve segments divided according to Simpson's algorithm. Therefore, this embodiment of the invention adopts the idea of recursive integration to dynamically segment the handwritten trajectory curve.
[0110] The following combination Figure 8 Taking the approximate arc length of a handwritten trajectory curve as an example, this paper provides a detailed explanation of the process of calculating the approximate arc length using the Simpson algorithm.
[0111] In some embodiments, such as Figure 8 As shown, calculating the approximate arc length of the handwritten trajectory curve may include the following steps:
[0112] Step 81: Divide the handwritten trajectory curve between the starting point and the ending point into multiple curve segments, and calculate the first approximate arc length of each curve segment and the second approximate arc length of the handwritten trajectory curve.
[0113] In some embodiments, dividing the handwritten trajectory curve between the start point and the end point into multiple curve segments (i.e., step 81) may include: dividing the handwritten trajectory curve between the start point and the end point into two curve segments according to the t value.
[0114] Step 82: Calculate the difference between the sum of the first approximate arc lengths of each curve segment and the second approximate arc length of the handwritten trajectory curve.
[0115] The difference between the sum of the first approximate arc lengths of each curve segment and the second approximate arc length of the handwritten trajectory curve is denoted by Error, where Error = LL + LR - LT, LL and LR are the first approximate arc lengths of the two curve segments obtained in step 81, and LT is the second approximate arc length of the handwritten trajectory curve.
[0116] Step 83: In response to the difference being greater than or equal to a preset second threshold, for each curve segment, the curve segment is divided into multiple sub-curve segments until the difference between the sum of the first approximate arc lengths of the currently divided sub-curve segments and the second approximate arc length of the corresponding curve segment is less than the second threshold.
[0117] In this step, if Error ≥ the second threshold, it indicates that the current error is large and further recursive calculation is needed to obtain an accurate approximate arc length of the handwritten trajectory curve.
[0118] Step 84: Calculate the sum of the first approximate arc lengths of all current sub-curve segments to obtain the approximate arc length of the handwritten trajectory curve between the starting point and the ending point.
[0119] In this step, the first approximate arc length of each sub-curve segment obtained when the recursion stops is summed to obtain the approximate arc length of the handwritten trajectory curve.
[0120] The following example will be used to explain in detail the process of calculating the approximate arc length of the handwritten trajectory curve between the starting point and the ending point using Simpson's algorithm and the idea of recursive integration.
[0121] The approximate arc length of the handwritten trajectory curve between the starting point and the ending point is calculated by solving the above formula (5) using the Simpson algorithm.
[0122] For the integral to be solved:
[0123] The handwritten trajectory curve is divided into two curve segments according to the t value. The first approximate arc lengths LL and LR of the two curve segments and the second approximate arc length LT of the handwritten trajectory curve are calculated according to formula (9).
[0124] LL is calculated according to formula (10):
[0125] LR is calculated according to formula (11):
[0126] LT is calculated according to formula (12):
[0127] Where a = 0, b = t,
[0128] For LL, let a1 = a, b1 = mid, And the recursive result is calculated according to formulas (10)-(12): LL L '、LR L 'and LT L ';Calculate Error L '=LL L '+LR L '-LT L ', if Error L If the current error is less than the second threshold, the recursion stops, and LL can be calculated. L 'with LR L The sum of these values is used as the value of LL. It should be noted that if Error... L If the value is greater than or equal to the second threshold, it indicates that the current error is relatively large. Continue the recursive process described above, that is, further refine LL. L 'and LR L 'Segment into sections.'
[0129] For LR, let a2 = mid, b2 = b, And the recursive result is calculated according to formulas (10)-(12): LL R '、LR R 'and LTR ';Calculate Error R '=LL R '+LR R '-LT R ', if Error R If the current error is less than the second threshold, the recursion stops, and LL can be calculated. R 'with LR R The sum of these values is used as the value of LR. It should be noted that if Error... R If the value is greater than or equal to the second threshold, it indicates that the current error is relatively large. Continue the recursive process described above, that is, further refine LL. R 'and LR R 'Segment into sections.'
[0130] Summing the first approximate arc lengths of each sub-curve segment obtained when recursion stops, we get the approximate arc length L(1)=LL of the handwritten trajectory curve. L '+LR L '+LL R '+LR R '.
[0131] In some embodiments, the handwriting of the marker pen may include multiple handwriting segments, and correspondingly, the handwriting trajectory may also include multiple trajectory segments, with each handwriting segment generated sequentially according to the arrangement order of the trajectory segments.
[0132] The step of calculating the t value of the interpolation point on the handwritten trajectory curve using the Newton iteration algorithm within the approximate arc length L(1) of the handwritten trajectory curve may include the following steps: In response to the fact that the arc length S between the current interpolation point to be interpolated and the first sampling point in the handwritten trajectory curve is greater than the approximate arc length L(1) of the handwritten trajectory curve, and the current trajectory segment is not the last trajectory segment of the handwritten stroke, the previous interpolation point of the current interpolation point to be interpolated is taken as the first sampling point of the handwritten trajectory in the next trajectory segment. In other words, during the process of generating a marker pen stroke segment corresponding to a trajectory segment, if the trajectory segment is not the last trajectory segment of the handwritten stroke (i.e., there are other trajectory segments after this trajectory segment, and it is not the ending trajectory segment), and the current interpolation point to be interpolated is located outside the current trajectory segment, it means that the approximate arc length between the previous interpolation point of the current interpolation point and the last sampling point in the current trajectory segment is less than the arc length τ between interpolation points. In this way, the current interpolation point to be interpolated is discarded, and the previous interpolation point of the current interpolation point is taken as the last interpolation point of the current trajectory segment and replaces the first sampling point of the next trajectory segment. In this way, the arc length between the previous interpolation point of the current interpolation point to be interpolated and the last sampling point in the current trajectory segment is discarded to ensure equal arc length interpolation.
[0133] It should be noted that if the arc length S between the current interpolation point to be interpolated and the first sampling point in the handwritten trajectory curve is greater than the approximate arc length L(1) of the handwritten trajectory curve, and the current trajectory segment is the last trajectory segment of the handwritten stroke (i.e. the ending trajectory segment), then interpolation is performed on the interpolation point to be interpolated, that is, the arc length between the previous interpolation point of the current interpolation point to be interpolated and the last sampling point in the trajectory segment is retained and is no longer discarded.
[0134] In some embodiments, the handwriting of a marker may include multiple handwriting segments, and correspondingly, handwritten strokes may also include multiple trajectory segments, with each handwriting segment generated sequentially according to the arrangement order of the trajectory segments.
[0135] After calculating the approximate arc length L(1) of the handwritten trajectory curve, for each interpolation point, before calculating the t value of the interpolation point on the handwritten trajectory curve using the Newton iteration algorithm within the approximate arc length L(1) of the handwritten trajectory curve, the handwritten handwriting generation method may further include the following steps: calculate the approximate number P of interpolation points based on the approximate arc length L(1) of the handwritten trajectory curve and the arc length τ between interpolation points, and round down the approximate number P of interpolation points to obtain the number P' of interpolation points. Correspondingly, for each interpolation point, calculating the t value of the interpolation point on the handwritten trajectory curve using the Newton iteration algorithm within the approximate arc length L(1) of the handwritten trajectory curve includes the following steps: in response to the current interpolation point being the P'th interpolation point, and the current trajectory segment not being the last trajectory segment of the handwritten stroke, the P'th interpolation point is taken as the first sampling point of the handwritten trajectory in the next trajectory segment. In other words, during the process of generating a marker pen stroke segment corresponding to a trajectory segment, if the trajectory segment is not the last trajectory segment of the handwritten stroke (i.e. there are other trajectory segments after this trajectory segment, and it is not the ending trajectory segment), the number of interpolation points P' in the trajectory segment is first calculated. Since P' is obtained by rounding down, by taking the P'th interpolation point as the first sampling point of the handwritten trajectory in the next trajectory segment, the arc length between the P'th interpolation point in the current trajectory segment and the last sampling point in the trajectory segment is actually discarded to ensure equal arc length interpolation.
[0136] In some embodiments, determining the arc length τ between interpolation points (i.e., step 2) may include the following steps: determining the arc length τ between interpolation points based on the coefficient M and brush parameters, wherein the brush parameters may include the size of the brush, which may be the diameter of the circumcircle of the brush shape.
[0137] In some embodiments, the arc length τ between interpolation points can be calculated using formula (13):
[0138] τ=M*d (13)
[0139] Where M is a coefficient and d is the diameter of the circumcircle of the brush shape.
[0140] In some embodiments, the coefficient is determined based on the brush density set by the user; the higher the brush density, the smaller the coefficient; and the lower the brush density, the larger the coefficient.
[0141] In some embodiments, brush parameters may further include the shape of the brush. Figure 9 Four brush shapes are shown, from left to right: circle, square, bird's nest shape, and quasi-circular, with brush sizes increasing sequentially. Assuming the user sets the circle brush to have the lowest density and the quasi-circular brush to have the highest density, the circle brush has the highest coefficient (M=2), and the quasi-circular brush has the lowest coefficient (M=0.05).
[0142] In this embodiment of the invention, equal arc length interpolation is used to select interpolation points, and at least a transparency parameter is superimposed at the interpolation point location to achieve the effect of marker pen strokes. Combined with... Figures 11a-11c As shown, Figure 11a This is a diagram illustrating the handwritten trajectory. Figure 11b This is a schematic diagram illustrating the process of selecting interpolation points using equal arc length interpolation in a handwritten trajectory without overlaying handwriting effect parameters. Figure 11c In order to be in Figure 11b An illustration of the marker pen stroke effect created by overlaying transparency. (See diagram.) Figure 11c As shown, after overlaying transparency at the interpolation point selected by equal arc length interpolation, the resulting marker pen stroke effect is that the stroke color is darker at the overlapping positions of the strokes, which can realistically present the writing effect of the marker pen.
[0143] The handwriting generation method provided in this invention selects interpolation points using equal arc length interpolation and performs texture drawing at these points. This simulates the style of a marker on a drawing board, flexibly achieving different shapes, colors, thicknesses, and transparency of markers. This invention can be applied to large-size (generally 50 inches or larger) smart displays such as conference whiteboards and teaching whiteboards, marking handwritten text, images, tables, and other content on the whiteboard with a marker effect. This marking has the transparent marking characteristic of a marker, without covering the original content, making it more suitable for demonstration and presentation scenarios. Furthermore, personalized presentation effects such as patterns, colors, and stroke thickness can be additionally overlaid based on user selection.
[0144] Based on the same technical concept, embodiments of the present invention also provide a handwriting generation device for generating marker pen handwriting based on handwritten strokes, wherein the marker pen handwriting includes at least one stroke segment, such as... Figure 12As shown, the data caching device includes a handwriting trajectory generation module 101, a first processing module 102, a second processing module 103, and a handwriting generation module 104. The handwriting generation module 104 is an application layer module, while the handwriting trajectory generation module 101, the first processing module 102, and the second processing module 103 are algorithm modules.
[0145] The handwriting trajectory generation module 101 is used to acquire sampling points of the handwriting trajectory and generate a handwriting trajectory curve based on the sampling points, wherein the handwriting trajectory is the trajectory of a trajectory segment in a handwriting stroke.
[0146] The first processing module 102 is used to determine the arc length τ between interpolation points.
[0147] The second processing module 103 is used to determine the position of the interpolation point on the handwritten trajectory curve according to the arc length τ between the interpolation points, wherein the arc length between two adjacent interpolation points on the handwritten trajectory curve is the same as the arc length τ between the interpolation points.
[0148] The handwriting generation module 104 is used to superimpose handwriting effect parameters at the position of the interpolation point to generate handwriting of a marker pen corresponding to the handwriting trajectory curve.
[0149] In some embodiments, the handwriting trajectory generation module 101 is used to generate a handwriting trajectory curve according to the Bézier curve algorithm.
[0150] The second processing module 103 is used to determine the position of the interpolation point on the handwritten trajectory curve using an iterative algorithm.
[0151] like Figure 13 As shown, the second processing module 103 includes an interpolation point t-value calculation unit 1031 and an interpolation point position determination unit 1032. The interpolation point t-value calculation unit 1031 is used to calculate the t-value of the interpolation point on the handwritten trajectory curve for each interpolation point using an iterative algorithm, where t is the parameter ratio of the Bézier curve; wherein, the iterative value t is the interpolation point t0. j+1 The approximate arc length L(t) corresponding to the handwritten trajectory curve j+1 The arc length S between the interpolation point and the first sampling point in the handwritten trajectory curve converges, and S is a multiple of the arc length τ between the interpolation points.
[0152] The interpolation point position determination unit 1032 is used to determine the position of the interpolation point on the handwritten trajectory curve using the Bezier curve algorithm based on the t value of the interpolation point on the handwritten trajectory curve.
[0153] In some embodiments, such as Figure 14As shown, the second processing module 103 also includes an approximate arc length calculation unit 1033, which is used to calculate the approximate arc length L(1) of the handwritten trajectory curve.
[0154] The interpolation point t-value calculation unit 1031 is used to calculate the t-value of the interpolation point on the handwritten trajectory curve within the approximate arc length L(1) of the handwritten trajectory curve for each interpolation point using an iterative algorithm.
[0155] In some embodiments, the interpolation point t-value calculation unit 1031 is configured to calculate the t-value of each interpolation point on the handwritten trajectory curve in the following manner: calculate the initial t-value t0 of the interpolation point; calculate the approximate arc length L(t0) corresponding to the initial t-value t0 on the handwritten trajectory curve; calculate the absolute value of the difference between the arc length S between the interpolation point and the first sampling point in the handwritten trajectory curve and the approximate arc length L(t0) corresponding to the initial t-value t0 on the handwritten trajectory curve; in response to the absolute value being greater than a preset first threshold, iteratively calculate the t-value of the interpolation point using an iterative algorithm until the arc length S between the interpolation point and the first sampling point in the handwritten trajectory curve and the iterative value t of the t-value are calculated. j+1 The approximate arc length L(t) corresponding to the handwritten trajectory curve j+1 When the absolute value of the difference between t and j is less than or equal to the first threshold, the iteration stops. j+1 is the current iteration number, and t is the iteration value of t when the iteration stops. j+1 Let t be the value of the interpolation point.
[0156] In some embodiments, the interpolation point t-value calculation unit 1031 is used to calculate the initial t-value t0 of the interpolation point using the following formula: Where L(1) is the approximate arc length of the handwritten trajectory curve.
[0157] In some embodiments, the approximate arc length calculation unit 1033 is used to calculate the iterative value t of the value t in the following manner. j+1 The approximate arc length L(t) corresponding to the handwritten trajectory curve j+1 ): Calculate the approximate arc length L' of the iterative difference, where the approximate arc length L' of the iterative difference is the value t before the iteration. j The position corresponding to the handwritten trajectory curve and the iteration value t obtained in the next iteration j+1 The approximate arc length between corresponding positions on the handwritten trajectory curve; based on the t value t before iteration. j The approximate arc length L(t) corresponding to the handwritten trajectory curve j Given the approximate arc length L' of the iterative difference, calculate the iterative value t of the next iteration for the value of t. j+1 The approximate arc length L(t) corresponding to the handwritten trajectory curvej+1 ).
[0158] In some embodiments, the approximate arc length calculation unit 1033 is used to calculate the approximate arc length by: determining the t-values of the starting point and the ending point of the handwritten trajectory curve corresponding to the approximate arc length; calculating the approximate arc length using the Simpson algorithm based on the t-values of the starting point and the ending point; wherein, when the approximate arc length is the approximate arc length L(1) of the handwritten trajectory curve, the t-value of the starting point is 0, and the t-value of the ending point is 1; when the approximate arc length is the iteration value t of the t-value... j+1 The approximate arc length L(t) corresponding to the handwritten trajectory curve j+1 When t is the starting point, the value of t is 0, and the value of t is the iteration value t of the value of t at the ending point. j+1 When the approximate arc length is the approximate arc length L(t0) corresponding to the initial t value t0 on the handwritten trajectory curve, the t value of the starting point is 0, and the t value of the ending point is the initial t value t0; when the approximate arc length is the approximate arc length L' of the iteration difference, the t value of the starting point is the t value before the iteration. j The endpoint t value is the iteration value t obtained in the next iteration. j+1 .
[0159] In some embodiments, the approximate arc length calculation unit 1033 is configured to: divide the handwritten trajectory curve between the starting point and the ending point into multiple curve segments; calculate the first approximate arc length of each curve segment and the second approximate arc length of the handwritten trajectory curve; calculate the difference between the sum of the first approximate arc lengths of each curve segment and the second approximate arc length of the handwritten trajectory curve; in response to the difference being greater than or equal to a preset second threshold, divide each curve segment into multiple sub-curve segments until the difference between the sum of the first approximate arc lengths of the currently divided sub-curve segments and the second approximate arc length of the corresponding curve segment is less than the second threshold; calculate the sum of the first approximate arc lengths of all current sub-curve segments to obtain the approximate arc length of the handwritten trajectory curve between the starting point and the ending point.
[0160] In some embodiments, the approximate arc length calculation unit 1033 is used to divide the handwritten trajectory curve between the starting point and the ending point into two curve segments according to the t value.
[0161] In some embodiments, the handwriting of the marker pen includes multiple handwriting segments, and the handwritten strokes include multiple trajectory segments, with each handwriting segment being generated sequentially according to the arrangement order of the trajectory segments.
[0162] The interpolation point t-value calculation unit 1031 is used to, in response to the arc length S between the current interpolation point to be interpolated and the first sampling point in the handwritten trajectory curve being greater than the approximate arc length L(1) of the handwritten trajectory curve, and the current trajectory segment not being the last trajectory segment of the handwritten stroke, take the previous interpolation point of the current interpolation point to be interpolated as the first sampling point of the handwritten trajectory in the next trajectory segment.
[0163] In some embodiments, the handwriting of the marker pen includes multiple handwriting segments, and the handwritten strokes include multiple trajectory segments, with each handwriting segment being generated sequentially according to the arrangement order of the trajectory segments.
[0164] The interpolation point t-value calculation unit 1031 is further configured to, after the approximate arc length calculation unit 1033 calculates the approximate arc length L(1) of the handwritten trajectory curve, for each interpolation point, before calculating the t-value of the interpolation point on the handwritten trajectory curve using an iterative algorithm within the approximate arc length L(1) of the handwritten trajectory curve, in response to the current interpolation point to be interpolated being the P'th interpolation point and the current trajectory segment not being the last trajectory segment of the handwritten stroke, take the P'th interpolation point as the first sampling point of the handwritten trajectory in the next trajectory segment.
[0165] In some embodiments, the iterative algorithm is the Newton-Raphson iterative algorithm.
[0166] In some embodiments, the first processing module 102 is used to determine the arc length τ between interpolation points based on coefficients and brush parameters, wherein the brush parameters include the size of the brush.
[0167] In some embodiments, the coefficient is determined based on the brush density set by the user; the higher the brush density, the smaller the coefficient; and the lower the brush density, the larger the coefficient.
[0168] In some embodiments, the handwriting trajectory generation module 101 is used to obtain three sampling points of the handwriting trajectory, and generate a handwriting trajectory curve using the Bézier curve algorithm based on the three sampling points, wherein the middle sampling point is taken as the vertex and the line connecting two adjacent sampling points is taken as the side to form an angle.
[0169] When the first included angle is greater than the second included angle, the number of interpolation points on the first handwritten trajectory curve is greater than the number of interpolation points on the second handwritten trajectory curve; the first handwritten trajectory curve is a handwritten trajectory curve generated by the Bézier curve algorithm based on the three sampling points of the first group, and the first included angle is the angle formed with the middle sampling point of the first group as the vertex and the line connecting two adjacent sampling points in the first group as the side; the second handwritten trajectory curve is a handwritten trajectory curve generated by the Bézier curve algorithm based on the three sampling points of the second group, and the second included angle is the angle formed with the middle sampling point of the second group as the vertex and the line connecting two adjacent sampling points in the second group as the side.
[0170] In some embodiments, the handwriting effect parameters include at least one of the following: color, thickness, transparency, and pattern.
[0171] This invention also provides a computer device, which includes one or more processors and a storage device; wherein the storage device stores one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the handwriting generation method provided in the foregoing embodiments.
[0172] This disclosure also provides a computer-readable medium having a computer program stored thereon, wherein the computer program, when executed, implements the handwriting generation method as provided in the foregoing embodiments.
[0173] It is understood that the above embodiments are merely exemplary implementations used to illustrate the principles of the present invention, and the present invention is not limited thereto. For those skilled in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. A method for generating handwritten handwriting, characterized in that, The method is used to generate marker pen handwriting based on handwritten strokes, wherein the marker pen handwriting includes at least one handwriting segment, wherein each handwriting segment is generated in the following manner: Obtain sampling points of the handwritten trajectory, and generate a handwritten trajectory curve based on the sampling points using the Bézier curve algorithm. The handwritten trajectory is the trajectory of a segment of the handwritten stroke. Determine the arc length τ between interpolation points; The position of the interpolation point on the handwritten trajectory curve is determined based on the arc length τ between the interpolation points, wherein the arc length between two adjacent interpolation points on the handwritten trajectory curve is the same as the arc length τ between the interpolation points. Handwriting effect parameters are superimposed at the position of the interpolation point to generate the handwriting of a marker pen corresponding to the handwriting trajectory curve; Determining the position of the interpolation point on the handwritten trajectory curve based on the arc length τ between the interpolation points includes: For each interpolation point, an iterative algorithm is used to calculate the t-value of the interpolation point on the handwritten trajectory curve, where t is the parameter ratio of the Bézier curve; wherein, the iterative value of t is... The approximate arc length L corresponding to the handwritten trajectory curve ( Regarding the arc length between the interpolation point and the first sampling point in the handwritten trajectory curve. Convergence, the It is proportional to the arc length τ between the interpolation points; Based on the t-value of the interpolation point on the handwritten trajectory curve, the position of the interpolation point on the handwritten trajectory curve is determined using the Bézier curve algorithm.
2. The method as described in claim 1, characterized in that, Before calculating the t value of the interpolation point on the handwritten trajectory curve using an iterative algorithm for each interpolation point, the method further includes: calculating the approximate arc length L(1) of the handwritten trajectory curve; The step of calculating the t value of the interpolation point on the handwritten trajectory curve using an iterative algorithm for each interpolation point includes: for each interpolation point, within the approximate arc length L(1) of the handwritten trajectory curve, calculating the t value of the interpolation point on the handwritten trajectory curve using an iterative algorithm.
3. The method as described in claim 2, characterized in that, The t-value of each interpolation point on the handwritten trajectory curve is calculated in the following manner: Calculate the initial t value t0 of the interpolation point; Calculate the approximate arc length L(t0) corresponding to the initial t value t0 on the handwritten trajectory curve. Calculate the arc length between the interpolation point and the first sampling point in the handwritten trajectory curve. The absolute value of the difference between the initial t value t0 and the approximate arc length L(t0) corresponding to the handwritten trajectory curve; In response to the absolute value being greater than a preset first threshold, an iterative algorithm is used to iteratively calculate the t-value of the interpolation point until the arc length between the interpolation point and the first sampling point in the handwritten trajectory curve is reached. The iterative value of the t value The approximate arc length L corresponding to the handwritten trajectory curve ( When the absolute value of the difference between t and j is less than or equal to the first threshold, the iteration stops. j+1 is the current iteration number, and j is the iteration value of t when the iteration stops. Let t be the value of the interpolation point.
4. The method as described in claim 3, characterized in that, The initial t-value t0 of the interpolation point is calculated using the following formula: t0 ; Where L(1) is the approximate arc length of the handwritten trajectory curve.
5. The method as described in claim 3, characterized in that, The iterative value of t is calculated in the following manner. The approximate arc length L corresponding to the handwritten trajectory curve ( ): Calculate the approximate arc length L' of the iterative difference, where L' is the t value before the iteration. The corresponding position on the handwritten trajectory curve and the iteration value of t obtained in the next iteration The approximate arc length between corresponding positions on the handwritten trajectory curve; Based on the t value before iteration The approximate arc length L corresponding to the handwritten trajectory curve ( Given the approximate arc length L' of the iterative difference, calculate the iterative value of t obtained in the next iteration. The approximate arc length L corresponding to the handwritten trajectory curve ( ).
6. The method as described in claim 5, characterized in that, The approximate arc length is calculated in the following way: Determine the t-values of the starting point and the ending point of the handwritten trajectory curve corresponding to the approximate arc length; The approximate arc length is calculated using the Simpson algorithm based on the t value of the starting point and the t value of the ending point. Wherein, when the approximate arc length is the approximate arc length L(1) of the handwritten trajectory curve, the t value of the starting point is 0, and the t value of the ending point is 1; when the approximate arc length is the iterative value of the t value... The approximate arc length L corresponding to the handwritten trajectory curve ( When t is the starting point, the value of t is 0, and the value of t is the iteration value of the value of t. When the approximate arc length is the approximate arc length L(t0) corresponding to the initial t value t0 on the handwritten trajectory curve, the t value of the starting point is 0, and the t value of the ending point is the initial t value t0; when the approximate arc length is the approximate arc length L' of the iteration difference, the t value of the starting point is the t value before the iteration. The endpoint t value is the iteration value of the t value obtained in the next iteration. .
7. The method as described in claim 6, characterized in that, The calculation of the approximate arc length of the handwritten trajectory curve includes: The handwritten trajectory curve between the starting point and the ending point is divided into multiple curve segments, and the first approximate arc length of each curve segment and the second approximate arc length of the handwritten trajectory curve are calculated respectively. Calculate the difference between the sum of the first approximate arc lengths of each of the curve segments and the second approximate arc length of the handwritten trajectory curve; In response to the difference being greater than or equal to a preset second threshold, for each curve segment, the curve segment is divided into multiple sub-curve segments until the difference between the sum of the first approximate arc lengths of the currently divided sub-curve segments and the second approximate arc length of the corresponding curve segment is less than the second threshold. Calculate the sum of the first approximate arc lengths of all current sub-curve segments to obtain the approximate arc length of the handwritten trajectory curve between the starting point and the ending point.
8. The method as described in claim 7, characterized in that, The step of dividing the handwritten trajectory curve into multiple curve segments includes: dividing the handwritten trajectory curve between the starting point and the ending point into two curve segments based on the t value.
9. The method as described in claim 2, characterized in that, The marker pen's handwriting includes multiple handwriting segments, and the handwritten strokes include multiple trajectory segments. Each handwriting segment is generated sequentially according to the arrangement order of each trajectory segment. The step of calculating the t value of the interpolation point on the handwritten trajectory curve using an iterative algorithm within the approximate arc length L(1) of the handwritten trajectory curve includes: The response is to the arc length between the current interpolation point to be interpolated and the first sampling point in the handwritten trajectory curve. If the current trajectory segment is greater than the approximate arc length L(1) of the handwritten trajectory curve and is not the last trajectory segment of the handwritten stroke, the previous interpolation point of the current interpolation point to be interpolated is taken as the first sampling point of the handwritten trajectory in the next trajectory segment.
10. The method as described in claim 2, characterized in that, The marker pen's handwriting includes multiple handwriting segments, and the handwritten strokes include multiple trajectory segments. Each handwriting segment is generated sequentially according to the arrangement order of each trajectory segment. After calculating the approximate arc length L(1) of the handwritten trajectory curve, for each interpolation point, before calculating the t value of the interpolation point on the handwritten trajectory curve using an iterative algorithm within the approximate arc length L(1) of the handwritten trajectory curve, the following steps are also included: Based on the approximate arc length L(1) of the handwritten trajectory curve and the arc length τ between the interpolation points, calculate the approximate number P of the interpolation points, and round down the approximate number P of the interpolation points to obtain the number P' of the interpolation points; For each interpolation point, within the approximate arc length L(1) of the handwritten trajectory curve, the t-value of the interpolation point on the handwritten trajectory curve is calculated using an iterative algorithm, including: In response to the fact that the current interpolation point to be interpolated is the P'th interpolation point, and the current trajectory segment is not the last trajectory segment of the handwritten stroke, the P'th interpolation point is taken as the first sampling point of the handwritten trajectory in the next trajectory segment.
11. The method according to any one of claims 2-3 and 9-10, characterized in that, The iterative algorithm is Newton's iteration algorithm.
12. The method as described in claim 1, characterized in that, Determining the arc length τ between interpolation points includes: determining the arc length τ between interpolation points based on coefficients and brush parameters, wherein the brush parameters include the size of the brush.
13. The method as described in claim 12, characterized in that, The coefficient is determined based on the brush density set by the user. The higher the brush density, the smaller the coefficient; the lower the brush density, the larger the coefficient.
14. The method as described in claim 1, characterized in that, The process of acquiring sampling points for the handwritten trajectory and generating a handwritten trajectory curve based on the Bézier curve algorithm includes: Three sampling points of the handwritten trajectory are obtained, and the handwritten trajectory curve is generated using the Bézier curve algorithm based on the three sampling points, wherein the middle sampling point is taken as the vertex and the line connecting the two adjacent sampling points is taken as the side to form an angle. When the first included angle is greater than the second included angle, the number of interpolation points on the first handwritten trajectory curve is greater than the number of interpolation points on the second handwritten trajectory curve. The first handwritten trajectory curve is a handwritten trajectory curve generated by the Bézier curve algorithm based on the three sampling points of the first group. The first included angle is the angle formed with the middle sampling point of the first group as the vertex and the line connecting two adjacent sampling points in the first group as the side. The second handwritten trajectory curve is a handwritten trajectory curve generated by the Bézier curve algorithm based on the three sampling points of the second group. The second included angle is the angle formed with the middle sampling point of the second group as the vertex and the line connecting two adjacent sampling points in the second group as the side.
15. The method according to any one of claims 1-10 and 12-14, characterized in that, The handwriting effect parameters include at least one of the following: color, thickness, transparency, and pattern.
16. A handwriting generation device, characterized in that, The device is used to generate handwriting from pen strokes, wherein the handwriting from the pen strokes includes at least one stroke segment, and the handwriting generation device includes a handwriting trajectory generation module, a first processing module, a second processing module, and a handwriting generation module. The handwriting trajectory generation module is used to obtain sampling points of the handwriting trajectory and generate a handwriting trajectory curve based on the sampling points using the Bézier curve algorithm. The handwriting trajectory is the trajectory of a trajectory segment in a handwriting stroke. The first processing module is used to determine the arc length τ between interpolation points; The second processing module is used to determine the position of the interpolation point on the handwritten trajectory curve based on the arc length τ between the interpolation points, wherein the arc length between two adjacent interpolation points on the handwritten trajectory curve is the same as the arc length τ between the interpolation points; wherein, for each interpolation point, an iterative algorithm is used to calculate the t value of the interpolation point on the handwritten trajectory curve, where t is the parameter ratio of the Bézier curve; wherein, the iterative value of t is... The approximate arc length L corresponding to the handwritten trajectory curve ( Regarding the arc length between the interpolation point and the first sampling point in the handwritten trajectory curve. Convergence, the The value of the interpolation point is proportional to the arc length τ between the interpolation points; the position of the interpolation point on the handwritten trajectory curve is determined using the Bézier curve algorithm based on the t value of the interpolation point on the handwritten trajectory curve. The handwriting generation module is used to overlay handwriting effect parameters at the position of the interpolation point to generate handwriting of a marker pen corresponding to the handwriting trajectory curve.
17. A computer device, comprising: One or more processors; A storage device on which one or more programs are stored; When the one or more programs are executed by the one or more processors, the one or more processors implement the handwriting generation method as described in any one of claims 1-15.
18. A computer-readable medium having a computer program stored thereon, wherein, When the program is executed, it implements the handwriting generation method as described in any one of claims 1-15.
Citation Information
Patent Citations
Handwriting generating method for electronic writing brush
CN102521858A
Method for beautifying handwriting in real time and electronic equipment
CN102937849A