Disclosure of Invention
The invention provides a method for realizing original handwriting, which ensures that the handwriting written by a user has a writing style as the handwriting written on traditional paper, ensures that the display speed of the handwriting follows the writing speed of the user and brings smooth writing experience to the user.
In order to solve the technical problems, the invention provides a method for realizing original handwriting, which comprises the following steps of:
determining the pen width: continuously sampling the handwriting, and detecting the position information and the actual pen width of a corresponding sampling point;
and (3) treatment: taking the front point of every two adjacent sampling points as a sampling starting point and the rear point as a sampling end point, taking a connecting line of the two points as a central line of the stroke between the two points, acquiring the position information of each point on the central line and the corresponding longitudinal stroke width, and determining the filling gray value of each pixel point in the stroke according to the position information of each point on the central line and the corresponding longitudinal stroke width of each point on the central line;
displaying: and filling and displaying corresponding pixel points according to the filling gray values.
In an embodiment of the present invention, the step of obtaining the longitudinal stroke width corresponding to each point on the central line includes:
the respective actual pen widths d of the sampling starting point and the sampling end point
1And d
nThe value of (a) is converted to the y-axis to obtain the corresponding longitudinal stroke width w
1And w
nAnd respectively make the width w of the longitudinal pen
1And w
nIs compared with the difference (x) of the x-coordinates of the sampling start point and the sampling end point
1-x
n) Comparing to obtain unit step length
Then theTaking the point corresponding to the sampling starting point on the x axis as a starting point, taking the point corresponding to the sampling end point on the x axis as an end point, and taking w on the y axis
1As an initial value, the vertical stroke width w of the corresponding point on the central line for every unit length of movement toward the end point on the x-axis
i+1The longitudinal stroke width w of the previous point
iAdding
In an embodiment of the present invention, the specific process of determining the filling gray value of each pixel point in the stroke includes:
calculating the distance e from the pixel point to the corresponding point on the central lineiAnd according to a straight line filling formula: max (0, min (1.0, 0.5 Xw)i-ei+0.5)) to obtain the filling gray value of the corresponding pixel point.
In one embodiment of the invention, the method further comprises the implementation steps of the stroke end points:
and (3) judging: judging whether the sampling point is a stroke end point of the stroke;
and (3) treatment: taking the center line endpoint k corresponding to the stroke endpoint as the circle center, and taking the actual pen width d corresponding to the center line endpoint kkDetermining a semicircle for the radius, wherein the starting point and the end point of the semicircle are both at the longitudinal pen width w corresponding to the circle centerkAnd then calculating the filling gray value of the pixel point determined by the semicircle.
In one embodiment of the present invention, the step of determining whether the sampling point is the stroke end point comprises: and judging whether the stroke is intersected with other strokes at the sampling point, if the stroke is not intersected with other strokes, the sampling point is the stroke end point.
In an embodiment of the present invention, the step of calculating the filling gray value of the pixel point determined according to the semicircle includes:
judging whether the stroke end point is a left end point or a right end point and whether the slope of the center line of the stroke is more than or equal to 0 or less than 0;
if the stroke end point is the right end point and the slope of the center line of the stroke is greater than or equal to 0, the longitudinal stroke width w below the center line, namely, at the center line end point k corresponding to the determined semicircle and the right end point
kThe filling gray value of the pixel point of the interface area is calculated by a straight line filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the right side of the point corresponding to the x-axis, the point is taken as the starting point, and the length is equal to
The line segment of (a) corresponds to the lower side of the extension line of the central line; wherein,
rounding up, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; filling gray values of other pixel points in the pixel points determined by the semi-circle are determined through a semi-circle filling formula: max (0, min (1.0, 0.5 xd)
k-e
k+0.5)) in which e is present
kThe distance from the corresponding pixel point to the center line endpoint k.
In an embodiment of the present invention, the step of calculating the filling gray value of the pixel point determined according to the semicircle includes:
judging whether the stroke end point is a left end point or a right end point and whether the slope of the center line of the stroke is more than or equal to 0 or less than 0;
if the stroke end point is the right end point and the slope of the center line of the stroke is less than 0, the longitudinal stroke width w above the center line, i.e. at the center line end point k corresponding to the determined semicircle and the right end point
kThe boundary region of (1), the pixel point ofFilling the gray value by a straight line filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the right side of the point corresponding to the x-axis, the point is taken as the starting point, and the length is equal to
The line segment of (a) corresponds to the upper side of the extension line of the central line; wherein,
rounding up, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; filling gray values of other pixel points in the pixel points determined by the semi-circle are determined through a semi-circle filling formula: max (0, min (1.0, 0.5 xd)
k-e
k+0.5)) in which e is present
kThe distance from the corresponding pixel point to the center line endpoint k.
In an embodiment of the present invention, the step of calculating the filling gray value of the pixel point determined according to the semicircle includes:
judging whether the stroke end point is a left end point or a right end point and whether the slope of the center line of the stroke is more than or equal to 0 or less than 0;
if the stroke end point is a left end point and the slope of the center line of the stroke is greater than or equal to 0, the longitudinal stroke width w above the center line, i.e. at the center line end point k corresponding to the semicircle and the left end point
kThe pixel filling gray value of the boundary area is determined by a straight line filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the end point, and the length is equal to
Is extended from the central lineThe area corresponding to the upper side; wherein,
rounding up, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; filling gray values of other pixel points in the pixel points determined by the semi-circle are determined through a semi-circle filling formula: max (0, min (1.0, 0.5 xd)
k-e
k+0.5)) in which e is present
kThe distance from the corresponding pixel point to the center line endpoint k.
In an embodiment of the present invention, the step of calculating the filling gray value of the pixel point determined according to the semicircle includes:
judging whether the stroke end point is a left end point or a right end point and whether the slope of the center line of the stroke is more than or equal to 0 or less than 0;
if the stroke end point is a left end point and the slope of the center line of the stroke is less than 0, the longitudinal stroke width w below the center line, i.e. at the center line end point k corresponding to the semicircle and the left end point
kThe pixel filling gray value of the boundary area is determined by a straight line filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the end point, and the length is equal to
The line segment of (a) corresponds to the lower side of the extension line of the central line; wherein,
rounding up, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; others of the semi-circle determined pixel pointsThe filling gray value of the pixel point is calculated by a semicircle filling formula: max (0, min (1.0, 0.5 xd)
k-e
k+0.5)) in which e is present
kThe distance from the corresponding pixel point to the center line endpoint k.
The present invention also provides an electronic device, comprising:
a handwriting screen: the display interface is used for providing a writing interface and displaying the written handwriting;
a sampling detector: the handwriting input device is used for sampling the touch points of the handwriting to obtain the position information and the actual pen width of the sampling points;
the microprocessor: the microprocessor comprises a handwriting original handwriting realization module, and the handwriting original handwriting realization module realizes the display of the handwriting original handwriting through the realization method.
The invention has the beneficial effects that: the method for realizing the original handwriting comprises the steps of sampling a contact in real time, acquiring the position information and the actual pen width of a sampling point, acquiring the central line of strokes between adjacent sampling points according to the position information and the actual pen width of the sampling point, acquiring the position information and the longitudinal pen width of each point on the central line, acquiring the filling gray value of a corresponding pixel point according to the position information and the longitudinal pen width of each point on the central line, and filling the corresponding pixel point to display the original handwriting with the pen point.
In addition, the method provided by the invention does not need to carry out complex curve drawing, directly operates the bottom layer graphic module, and constructs the handwriting into a bitmap which is sent to the bottom layer graphic module for display, thereby avoiding the graphic processing of the system, improving the processing speed of the original handwriting and bringing smooth writing experience to users. The method of the invention is simplified, and the system overhead is greatly reduced.
Detailed Description
Aiming at the problems that the handwriting processing method adopted by the existing handwriting input system, such as a tablet computer, cannot display the front of a user writing characters, and the display speed of the handwriting is lagged behind the writing speed of the user greatly when the front of the handwriting is processed, the invention provides a new original handwriting realization method.
The present invention will be described in further detail with reference to the following detailed description and accompanying drawings.
In the writing process, different pressures are usually applied when different strokes are written, such as heavier at the pen-down position and lighter at the pen-up position, and the thickness of the written strokes can be changed through the change of the pressures, so that the stroke effect is displayed. In this example, the implementation of the stroke front is explained by using a tablet computer as a carrier, all characters are broken into single strokes, and the relationship between the strokes is divided into the following two types: 1. a single stroke exists alone; 2. one stroke intersects another stroke. The strokes proposed by the embodiment refer to single strokes determined by adjacent sampling points, are not strokes referred to in Chinese character writing, and even Chinese character strokes such as bends, hooks and the like are also decomposed into a plurality of continuous single strokes determined by sampling starting points and sampling end points.
In view of the above situation, when a single stroke exists alone, the width of the stroke that changes in real time and two stroke end points of the stroke need to be processed, and when the strokes intersect, the intersection point of the intersecting strokes, i.e. the inflection point, also needs to be processed. The method comprises the following specific steps:
in the computer storage device, the corresponding relation between the pressure value and the pen width is stored in advance, and the corresponding pen width can be obtained according to the detected pressure value, wherein the pen width is the actual pen width; if the pressure is divided into 1024 levels, the corresponding relation between the pressure values and the pen width is established one by one, the expression form can be a function or a table, and then the corresponding actual pen width can be obtained according to the detected pressure values. For higher accuracy, the pressure may also be set to a higher level, such as 2048.
Then, the sampling frequency is set according to actual conditions, for example, when a regular script is written, because the writing speed is relatively slow, the lower sampling frequency can be selected to meet the requirement, for example, when the regular script or cursive script is written, the writing speed is fast, and the higher sampling frequency can be selected correspondingly to ensure the handwriting writing effect. The sampling frequency in this example is preferably 120 times per second to ensure the handwriting effect.
Sampling is carried out on a contact point when a user writes according to a selected sampling frequency, a stroke is determined at adjacent sampling points, the former sampling point can be determined as a sampling starting point according to a time sequence, the latter sampling point is determined as a sampling end point, if the sampling points acquired according to the time sequence are respectively 1, 2 and 3, the sampling points 1 and 2 are adjacent sampling points, when the stroke is determined, the sampling point 1 is the sampling starting point, the sampling point 2 is the sampling end point, the sampling points 2 and 3 are also adjacent sampling points, when the stroke is determined, the sampling point 2 is the sampling starting point, the sampling point 3 is the sampling end point, and so on. And then, obtaining the actual pen width d of the sampling point according to the pressure value of the sampling point, wherein in the example, the direction of the actual pen width d of the sampling point is defaulted to be vertical to the central line of the stroke determined by the sampling point. Obtaining the central line of the stroke determined by the adjacent sampling points, the position information of each point on the central line and the longitudinal stroke width according to the position information (such as coordinate information) of the sampling points and the actual stroke width d, wherein the longitudinal stroke width of the sampling points is the value corresponding to the y axis converted from the actual stroke width of the sampling points, and obtaining the filling gray value of each pixel point in the stroke according to the position information of each point on the central line and the longitudinal stroke width corresponding to each point on the central line; in this example, sampling points 1 and 2 are selected as examples for further explanation.
Referring to FIG. 1, the actual widths of sampling points 1 and 2 are d1And d2The coordinate values are respectively (x)1,y1) And (x)n,yn) The method comprises the steps of obtaining a central line L according to coordinate information of sampling points 1 and 2, dividing the central line L into an x main line or a y main line according to the slope of the L, dividing the L into the x main line when the slope of the L is smaller than or equal to 1, otherwise, dividing the L into the y main line, and switching an x axis and a y axis when the L is the y main line, namely converting the L into the x main line. Therefore, the present embodiment converts L into x main line without distinguishing x main line or y main line, please refer to fig. 1, and then according to the actual pen width d1And d2The longitudinal stroke width w of the sampling starting point 1 and the sampling end point 2 in the y-axis direction can be obtained1And w2According to (x)1,y1) And (x)n,yn) Coordinate information of each point on the central line can be obtained through a DDA algorithm, and in the DDA algorithm, the unit length of movement on the x axis can be one pixel point. Then, the longitudinal stroke width corresponding to each point on the central line is calculated as follows:
in fig. 1, the vertical stroke width of the sampling start point 1 is w
1Longitudinal stroke width w of sampling end point 2
2Is set as w
nW is to be
1And w
nIs compared with the difference (x) of the x-coordinates of the sampling start point 1 and the sampling end point 2
1-x
n) Comparing to obtain unit step length
Then taking the point corresponding to the sampling start point 1 on the x axis as a starting point, taking the point corresponding to the sampling end point 2 on the x axis as an end point, and taking w on the y axis
1As an initial value, the vertical stroke width w of a corresponding point on the center line for every unit length of movement toward the end point on the x-axis
i+1The longitudinal stroke width w of the previous point
iPlus unit step size
The unit length of movement on the x-axis when the longitudinal stroke width corresponding to each point on the center line is obtained is the same as the unit length of movement when the position information of each point on the center line is obtained, and is also a pixel point. Accordingly, when the unit step size is obtained as
When the pen is moved to the end point by one unit length on the x-axis, the pen width w of the corresponding point on the central line
i+1The longitudinal stroke width w of the previous point
iAdding
The method comprises the following specific steps: taking the sampling starting point 1 as a starting point and the longitudinal stroke width w
1For the initial value, the vertical stroke width w corresponding to the corresponding point on the central line is moved by one unit in the x-axis toward the sampling end point 2
i+1W of the previous point
iPlus unit step size
For example, taking a pixel point as a unit on the x-axis, the vertical stroke width at the next point of the sampling starting point 1 is:
and sequentially moving a pixel point downwards on the x axis according to the method until the sampling end point 2 is at the corresponding end point on the x axis, so as to obtain the longitudinal stroke width corresponding to each point on the central line.
When determining the filling gray value of the corresponding pixel point according to the obtained position information of each point on the center line and the corresponding longitudinal stroke width, first, the distance from the corresponding pixel point to the corresponding point on the center line needs to be determined, because in this example, when obtaining the position information of each point on the center line and the longitudinal stroke width, the unit of movement on the x-axis is one pixel point, and each point on the corresponding center line corresponds to a corresponding row of pixel points, therefore, the distance e from the center point of the pixel point to the corresponding point on the center lineiThe difference value between the coordinate value of the central point on the y axis and the coordinate value of the corresponding point on the central line is obtained, and therefore, the distance e from the central point of the pixel point to the corresponding point on the central line is obtainediIn the process, only simple addition and subtraction operation is needed, operations such as multiplication, division or root division are not needed, the calculation amount is greatly reduced, the calculation time and the system overhead are saved, the processing speed is increased, and the user experience is improved.
Calculating the distance e from the pixel point to the corresponding point i on the central lineiThen, max (0, min (1.0, 0.5 xw) is filled according to the straight line filling formulai-ei+0.5)) to obtain the corresponding filling gray value, where wiIs the longitudinal distance of the corresponding point i on the centerline. For example, when 0.5 xwi-eiWhen the value of (3) is 0.3, the obtained filling gray value of the pixel point is 0.8, when the value is 0.5 xwi-eiWhen the value of (a) is-0.5, the filling gray value of the pixel point is 0, when the value of (b) is 0.5 xwi-eiWhen the value of (1) is greater than the predetermined value, the filling gray value of the pixel point is 1, and the filling effect of the stroke line width is shown in fig. 2.
In this example, calculating the position information of a certain point on the central line, the vertical stroke width and the gray filling value of the pixel point corresponding to the point can be performed simultaneously, for example: obtaining the value y of a certain point on the central line on the y axis through the DDA algorithmiAccording toThe vertical stroke width of the dot can be obtained, and then the linear filling formula max (0, min (1.0, 0.5 xw) is usedi-ei+0.5) The gray filling value of the pixel point corresponding to the point can be obtained, and then the position information of the points above and below the center line, the longitudinal stroke width and the gray filling value of the corresponding pixel point are calculated in turn according to the above manner.
When processing the stroke, it needs to process the stroke end point of the stroke, when processing the stroke end point, firstly, it needs to judge and determine whether two sampling points of the stroke are the stroke end points of the stroke, i.e. judge whether the sampling points of the stroke intersect with other stroke, if not, the sampling points are the stroke end points of the stroke, then judge whether the slope of the center line of the stroke is greater than or equal to 0 or less than 0, and further judge whether the stroke end point is the left end point or the right end point of the stroke, then the center line end point k corresponding to the stroke end point is used as the center of a circle, and the actual pen width d corresponding to the center line end point k is used as the center of a circlekDetermining a semicircle for the radius, wherein the starting point and the end point of the semicircle are both at the longitudinal stroke width w corresponding to the endpoint k of the central linekThen, the filling gray value of the pixel point determined by the semicircle is calculated, which specifically includes the following steps:
if the stroke end point is the left end point and the slope of the center line of the stroke is greater than or equal to 0, the longitudinal stroke width w corresponding to the semicircle and the center line end point k is above the center line
kThe pixel filling gray value of the boundary area is determined by a straight line filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the end point, and the length is equal to
The line segment of (a) corresponds to the upper side of the extension line of the central line; wherein,
rounding upwards, e.g. when
When it is 1.2, takeA value of 2, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; in this example, the position information of each point on the extended line of the center line can be obtained by the DDA algorithm used in determining the position information of each point on the center line, and the width of each point on the extended line of the center line in the longitudinal direction is w in this example
sAre all taken as w
kAnd the filling gray values of the other pixel points at the left end point, namely the pixel points in other areas in the pixel points determined by the semi-circle, pass through a semi-circle filling formula: max (0, min (1.0, 0.5 xd)
k-e
k+0.5)) in which e is present
kIs a calculation formula for calculating the distance between two points. Due to e
kIs usually relatively small, so in this example, e in the semicircle filling formula
kThe operation speed can be optimized by establishing a direct value taking table which is calculated in advance.
If the stroke end point is the left end point and the slope of the center line of the stroke is less than 0, the longitudinal stroke width w corresponding to the semicircle and the center line end point k is below the center line
kThe pixel filling gray value of the boundary area is determined by a straight line filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the end point, and the length is equal to
The line segment of (a) corresponds to the lower side of the extension line of the central line; wherein,
rounding up, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; the filling gray values of the pixel points in other areas of the pixel points determined by the semicircle at the other pixel points at the left end point are determined by a semicircle filling formula:max(0,min(1.0,0.5×d
k-e
k+0.5)) in which e is present
kIs a calculation formula for calculating the distance between two points.
If the stroke end point is the right end point and the slope of the center line of the stroke is greater than or equal to 0, the stroke width w is below the center line, namely, in the determined semicircle and the longitudinal direction corresponding to the end point
kThe filling gray value of the pixel point of the boundary area is determined by the linear filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the right side of the point corresponding to the x-axis, the point is taken as the starting point, and the length is equal to
The line segment of (a) corresponds to the lower side of the extension line of the central line; wherein,
rounding up, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; the filling gray values of other pixel points at the right end point are calculated by a semicircle filling formula: max (0, min (1.0, 0.5 xd)
k-e
k+ 0.5)).
If the stroke end point is the right end point and the slope of the center line of the stroke is less than 0, the stroke end point is above the center line, i.e. the determined semicircle and the longitudinal stroke width w corresponding to the end point
kThe filling gray value of the pixel point of the boundary area is determined by the linear filling formula: max (0, min (1.0, 0.5 Xw)
s-e
s+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the right side of the point corresponding to the x-axis, the point is taken as the starting point, and the length is equal to
The line segment of (a) corresponds to the upper side of the extension line of the central line; wherein,
rounding up, w
sThe longitudinal width of the center line corresponding to each point on the extension line of the end, e
sThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; the filling gray values of other pixel points at the right end point are calculated by a semicircle filling formula: max (0, min (1.0, 0.5 xd)
k-e
k+ 0.5)).
For example, assuming that both ends of the stroke determined by sample 1 and sample 2 in fig. 1 are stroke end points, and the slope of the center line L of the stroke is greater than 0, when processing the left end point, the center of the stroke is taken as the center of the circle at sample 1, and d is taken as the center of the circle1The radius is made into a semicircle which is respectively connected with w1Are intersected at both ends of the semicircle1The filling gray value of the upper boundary region is determined by a straight line filling formula: max (0, min (1.0, 0.5 Xw)s-es+0.5)) is obtained, as shown in fig. 1, the intersection region is the point x corresponding to the sampling point 1 on the x-axis1Left side of (1), in x1Is a terminal point, and has a length ofLine segment L of1Pixel point corresponding to upper side of extension line of the end center line, and L1The position information of each point on the extension line of the corresponding central line L is obtained by the DDA algorithm adopted when the position information of each point on the central line L is obtained, and the longitudinal stroke width of each point is taken as w1And the filling gray values of the pixel points in other areas of the left end point can be obtained through a semicircle filling formula: max (0, min (1.0, 0.5 xd)1-e1+ 0.5)); when the right end point at the sampling point 2 is processed, the processing mode is opposite to that of the left end point, namely, the right end point is processed at the semicircle and the w2The filling gray value of the lower boundary region of (1) is represented by the linear filling formula max (0, min (1.0, 0.5 xw)s-es+ 0.5)); as shown in FIG. 1, the boundary region is a point x corresponding to the sampling point 2 on the x-axis2To the right side of (1), in x2As a starting point, has a length ofLine segment L of2The pixel points in the region corresponding to the lower side of the extension line of the end center line are the same as L2The position information of each point on the extension line of the corresponding central line L is obtained by the DDA algorithm adopted when the position information of each point on the central line L is obtained, and the longitudinal stroke width of each point is taken as w2The filling gray values of the pixel points in other areas are filled by a semicircle filling formula max (0, min (1.0, 0.5 × d)2-e2+ 0.5)).
It should be noted that when the slope of the center line L of the stroke is equal to 0, the actual stroke width d of the sampling point coincides with the longitudinal stroke width w, and d is equal to w, and at this time, the boundary area is 0, that is, no pixel point falls in the boundary area. At this time, the endpoint is processed only by using a semicircle processing filling formula.
When the strokes intersect with each other, the intersection point (i.e. inflection point) of the two intersecting strokes is also processed, and when the intersection point is processed, the actual stroke width, the longitudinal stroke width and the position information and the longitudinal stroke width of each point on the center line of the sampling point are detected through the steps, the method further comprises the following steps:
main line setting: taking a connecting line of a sampling starting point and a sampling end point as a central line of the stroke between the two points, and setting one of the central lines of the two intersected strokes as a main line in the x-axis direction;
judging and processing: calculating filling gray values of corresponding pixel points at the intersection points of the two intersecting strokes according to the position information and the longitudinal stroke width of each point on the central line of the two intersecting strokes, the slope of the central line of the two intersecting strokes and the trend of the two intersecting strokes;
displaying: and filling and displaying corresponding pixel points according to the obtained filling gray values.
In this example, the main line may be set by determining two intersected strokes as a first stroke and a second stroke respectively in time sequence, and setting the center line of the first stroke as the main line in the x-axis direction.
After the main line is set, it is determined whether the slope of the center line of the second stroke is smaller than a preset slope value a, where a is a compensation value, a is 0 to 0.5, i.e. the value range of a is greater than or equal to 1 and less than or equal to 1.5, and the specific value of a can be selected according to the thickness of the stroke and the requirement of the processing speed, in this example, considering that the processing speed of the stroke is increased as much as possible, the value of a is preferably 1.5, if the slope of the center line of the second stroke is less than 1.5, it is further determined whether the trend of the second stroke is the same as the trend of the first stroke, and if so, the longitudinal stroke width w corresponding to the intersection point of the center lines corresponding to the two intersecting strokes in the first stroke and the second stroke is calculatedjAnd wj', and obtaining an absolute value n ═ w of the difference thereofj-wj' |, according to the value of n and wjAnd wjThe size relationship of' performs smooth transition processing on the intersection point of the center lines, and then calculates the filling gray value of the corresponding pixel point at the intersection point of the center lines, in this example, the trend of the two intersecting strokes is whether the directions from the starting point to the end point of the two intersecting strokes point to the positive direction or the negative direction of the x axis, which is specifically as follows:
calculating the longitudinal stroke width w of the intersection point of the central lines of the first stroke and the second stroke in the first stroke and the second stroke
jAnd w
j' and then calculates the absolute value n ═ w of the difference
j-w
j'I', judging whether the n value is 0, if so, not processing the intersection point drawn by the two intersecting pens, otherwise, rounding the n value upwards, if 0 < n < 1, taking the n value as 1, and then obtaining the unit step length on the y axis as
Then taking corresponding points as a starting point and an end point on the x axis according to w
jAnd w
jThe magnitude relation of' carries out smooth transition processing on the intersection point of two intersecting strokes, which is concretely as follows:
determining a starting point and an end point: taking the point corresponding to the intersection point of the central lines on the x axis as the midpoint,to near the first stroke side
Or
The point is a starting point, with the first side near the second stroke
Or
Taking the point as a terminal point; when the value of n is an odd value, the second of the two sides is selected respectively
The points are a starting point and an end point, and when the value of n is an even value, the first points on two sides are respectively selected
The points are a start point and an end point.
Smoothing: judgment of w
jAnd w
j' size, in w
jIs an initial value, starting from a starting point on the x-axis when w
j<w
jWhen the stroke length is equal to the stroke length, the stroke length w of the corresponding point on the central line is equal to the stroke length w of the corresponding point on the central line
r+1The longitudinal stroke width w of the previous point
rAdding unit step length on the upper and lower sides of the central line
When w is
j>w
jWhen the stroke length is equal to the stroke length, the stroke length w of the corresponding point on the central line is equal to the stroke length w of the corresponding point on the central line
r+1The longitudinal stroke width w of the previous point
rRespectively reducing unit step length on the upper and lower sides of the central line
When w is
j=w
j', unit step size
Is 0.
Obtaining and filling the gray value of the corresponding pixel: obtaining the corresponding pixel point of the stroke width at the intersection point through the smooth transition processing, and filling the formula max (0, min (1.0, 0.5 xw) according to the straight liner-er+0.5)) to obtain the filling gray value of the corresponding pixel point, and then filling and displaying the corresponding pixel point according to the filling gray value, wherein wrA longitudinal stroke width of a corresponding point r on the center line, erAnd obtaining the position information of each point on the stroke central line when the position information of each point on the stroke central line is obtained for the distance from the corresponding pixel point to the point r.
If the slope of the center lines of the first stroke and the second stroke does not meet the condition or the slope of the center lines of the first stroke and the second stroke meets the condition, but the trends of the first stroke and the second stroke are different, at the intersection point of the two intersecting strokes, the intersection point of the center lines of the first stroke and the second stroke is taken as the center of a circle, and the actual pen width d of the intersection point of the center lines is taken as the actual pen width djDetermining a semicircle for the radius, and then calculating the filling gray value of the pixel point determined by the semicircle, wherein the filling gray value is as follows:
judging whether the absolute value of the slope of the center line of the second stroke is greater than or equal to a preset slope value A, wherein A is 1.5, if so, at the intersection point of the two intersecting strokes, taking the intersection point of the center lines of the two intersecting strokes as the center of a circle, and taking the actual pen width d corresponding to the intersection point of the center lines as the center of a circlejDetermining two semicircles for the radius in the direction of the outer end of the corresponding stroke and the extension line of the center line of the end, wherein the starting point and the end point of one semicircle are both in the longitudinal stroke width w of the first strokejThe starting point and the end point of the other semicircle are both in the longitudinal stroke width w of the second strokejAnd then, respectively calculating the filling gray values of the pixel points determined by the semi-circles.
In this example, if a certain pixel has a plurality of filling gray values, the maximum value of the gray values is selected to fill the certain pixel.
If the absolute value of the slope of the center line of the second stroke is judged to be smaller than a preset slope value A, namely smaller than 1.5, but the trend of the second stroke is different from the trend of the first stroke, the slope of the center line of the first stroke and the slope of the center line of the second stroke are further judged, and at the intersection point of the two intersected strokes, the intersection point of the center lines of the two intersected strokes is taken as the center of a circle, and the actual pen width d corresponding to the intersection point of the center lines is taken as the center of a circlejAnd determining a semicircle for the radius, wherein the starting point and the end point of the semicircle are both on the longitudinal stroke width of the stroke with the large slope at the intersection point, and then calculating the filling gray value of the pixel point determined by the semicircle.
The filling gray value of the pixel point determined by calculating the semicircle is specifically as follows: judging whether the stroke end with a semicircle drawn by the corresponding stroke is the left end point or the right end point of the stroke, further judging whether the slope of the center line of the stroke is more than or equal to 0 or less than 0, if the stroke end is the left end point of the stroke and the slope of the center line of the stroke is more than or equal to 0, then above the center line of the stroke, the intersection point of the semicircle and the center line is in the boundary area of the longitudinal stroke width in the stroke, and the pixel point filling gray value passes through a straight line filling formula: max (0, min (1.0, 0.5 Xw)
z-e
z+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the end point, and the length is the length
The line segment of (a) corresponds to the upper side of the extension line of the central line; wherein,
rounding up, w longitudinal stroke width of the centerline intersection in the stroke, d actual stroke width of the centerline intersection in the stroke, w
zThe longitudinal width of the center line corresponding to each point on the extension line of the end is w in the example
z=w,e
zThe distance from the corresponding pixel point to the corresponding point on the extension line of the end of the central line; determined in the semicircleFilling gray values of pixel points in other areas in the determined pixel points are determined through a semicircle filling formula: max (0, min (1.0, 0.5 xd)
j-e
j+0.5)) in which e is present
jThe distance of the corresponding pixel point to the intersection point, d
jThe actual pen width of the center point of intersection.
If the stroke end is the left end point of the stroke and the slope of the center line of the stroke is less than 0, the pixel point of the intersection area of the longitudinal stroke width w of the intersection point of the semicircle and the center line below the center line of the stroke is filled with the gray value through a straight line filling formula: max (0, min (1.0, 0.5 Xw)
z-e
z+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the end point, and the length is equal to
The line segment of (a) corresponds to the lower side of the extension line of the central line; wherein,
rounding upwards; filling gray values of pixel points in other areas in the pixel points determined by the semicircle are determined through a semicircle filling formula: max (0, min (1.0, 0.5 xd)
j-e
j+ 0.5)).
If the stroke end is the right end point of the stroke and the slope of the center line of the stroke is greater than or equal to 0, in a boundary area of the longitudinal stroke width w below the center line of the stroke and at the intersection point of the semicircle and the center line, the pixel point is filled with a gray value through a straight line filling formula: max (0, min (1.0, 0.5 Xw)
z-e
z+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the starting point, and the length is equal to
The line segment of (a) corresponds to the lower side of the extension line of the central line; wherein,
rounding upwards; filling gray values of pixel points in other areas in the pixel points determined by the semicircle are determined through a semicircle filling formula: max (0, min (1.0, 0.5 xd)
j-e
j+ 0.5)).
If the stroke end is the right end point of the stroke and the slope of the center line of the stroke is greater than or equal to 0, the pixel point of the intersection area of the semicircle and the center line and the longitudinal stroke width w above the center line of the stroke is filled with the gray value through a straight line filling formula: max (0, min (1.0, 0.5 Xw)
z-e
z+0.5)), the boundary area is on the x-axis, the sampling point corresponding to the end point is on the left side of the point corresponding to the x-axis, the point is taken as the starting point, and the length is equal to
The line segment of (a) corresponds to the upper side of the extension line of the central line; wherein,
rounding upwards; and filling gray values of pixel points in other areas in the pixel points determined by the semi-circle are determined through a semi-circle filling formula: max (0, min (1.0, 0.5 xd)
j-e
j+ 0.5)).
This is further illustrated in the case of fig. 3: the slope of the first stroke determined by the sampling points 1 and 2 is less than 1, the absolute value of the slope of the center line of the second stroke intersecting with the first stroke determined by the sampling points 1 and 2 is also less than 1, but the direction of the second stroke is different from the direction of the first stroke, therefore, it needs to further judge which of the absolute values of the slopes of the center lines of the first stroke and the second stroke is the largest, it can be known from fig. 3 that the slope of the center line of the first stroke is larger than the slope of the center line of the second stroke, and because the end of the sampling point 2 is the right end point of the first stroke, and the slope of the center line of the first stroke is larger than 0, therefore, the processing procedure of the intersection point, i.e. the inflection point, of the:
using sampling point 2 (i.e. central line intersection point 2) as the center of circle and d
2Drawing a semicircle for the radius, the starting point and the end point of the semicircle are both at w
2And then calculating the filling gray value of the pixel point determined by the semicircle, wherein the lower side L of the central line
2The filling gray value of the pixel points in the corresponding interface region passes through a linear filling formula max (0, min (1.0, 0.5 xw)
z-e
z+0.5)) in which w
z=w
2,L
2The corresponding boundary area is the point x corresponding to the sampling point 2 on the x-axis
2To the right side of (1), in x
2As a starting point, has a length of
Line segment L of
2Pixel points in the region corresponding to the lower side of the extension line of the end center line, and L
2The position information of each point on the extension line of the corresponding central line L is obtained according to a DDA algorithm adopted when the position information of each point on the central line L is obtained, and the filling gray value of pixel points in other areas in the pixel points determined by the semicircle is obtained through a semicircle filling formula: max (0, min (1.0, 0.5 xd)
2-e
2+ 0.5)).
The present invention also provides an electronic device, comprising:
a handwriting screen: the handwriting display interface is used for providing a writing interface and displaying writing;
a sampling detector: the handwriting input device is used for sampling the touch points of the handwriting to obtain the position information and the actual pen width of the sampling points; in the method, the sampling frequency of a sampling detector is set to be 120 times per second so as to ensure the handwriting effect, and then the sampling detector obtains the actual pen width of a sampling point according to the detected pressure value of the sampling point;
the microprocessor: the microprocessor comprises a handwritten original handwriting realization module, wherein the handwritten original handwriting realization module is used for processing strokes determined by sampling points according to the position information of the sampling points and the actual stroke width according to the method, the processing of the strokes comprises the steps of processing the linear stroke width of the strokes, the end points of the strokes and the intersection points of two intersected strokes in the method, then obtaining the filling gray values of corresponding pixel points according to the linear filling formula and the semicircular filling formula, in the example, when a certain pixel point has a plurality of filling gray values, the largest filling gray value is selected, finally, the corresponding pixel points are filled according to the obtained filling gray values, and the filling gray values are displayed by a handwriting screen.
The method provided by the invention converts the actual stroke width into one direction, and when the filling gray value of the corresponding pixel point is obtained, the distance from the corresponding pixel point to each point on the central line can be obtained only by simple addition and subtraction operation, so that the method greatly reduces the overhead of the system, improves the processing speed of the system and brings smooth writing experience to users while realizing the original handwriting with stroke front.
In addition, the method provided by the invention further determines the corresponding pixel points by drawing semi-circles on the end points and the intersection points of the strokes, divides the corresponding pixel points according to different actual conditions, and obtains the filling gray values of the corresponding pixel points at the end points and the intersection points through different filling formulas, so that the end points and the inflection points of the strokes are smooth and have no saw teeth, and the displayed stroke front has better and smoother effect.
Particularly, the electronic device related to the invention is a handwriting tablet computer, and handwriting input is performed through a handwriting pen.
The foregoing is a more detailed description of the invention that is presented in conjunction with specific embodiments, and the specific embodiments of the invention are not to be considered limited to these descriptions; therefore, for those skilled in the art to which the invention pertains, several simple deductions or substitutions can be made without departing from the spirit of the invention, and all should be considered as belonging to the protection scope of the invention.