1. Introduction
Human communication modes have evolved from drawings to patterns such as letters or symbols; we have seen the representation of these patterns in stone, paper, and nowadays in digital systems. One of the most common ways of communication is through handwriting, which is nothing more than a set of letters or patterns that together encode a message, making it possible for people who know this code to receive and recognize it. Currently, with the growing use of information technologies, there is a need to digitize messages to make them reach a broader number of people, and it is also necessary to have a way to analyze what is digitized. Two essential concepts appear when discussing this handwriting analysis: online (recognition in real time) and offline (recognition in non-real time). There are various efforts to improve the online handwriting systems to reproduce faithfully the strokes of the pen movement [
1,
2,
3,
4,
5,
6,
7,
8], and these models are based on known and efficient data analysis methodologies. However, they require prior knowledge of the patterns; that is, they need to know in advance what the patterns should be like in order to reconstruct them, and in some other cases, it is necessary to have the trajectory of the stroke to perfect it. The works [
1,
2,
3,
4,
5,
6,
7,
8] use deep learning algorithms that insert the electrical characteristics of the sensors; in other cases, the focus is on optimizing the traces already made on a surface.
Although it is a simple task, handwriting is a highly complicated skill. It is necessary to have a mental picture or memory of what each letter looks like and then develop a motion plan to create it as it is stored in our memory. The development of higher-level handwriting skills (letter formation, sizing, spacing, alignment, and more) all begins with being able to copy simple shapes (prewriting shapes) [
9,
10,
11].
From these prewriting shapes (i.e., horizontal lines, circles, vertical lines), it is time to move on to the letter drawing (how the letters are represented) and construction (how each letter is produced). Efficient construction typically leads to better legibility and speed. Widely known online writing systems have a fixed reference system, either through an artificial vision sensor, which establishes the usual order of a matrix in rows and columns and correlates them with the position in the viewing angle vision of the person who writes [
12], or through a finite-dimensional tablet and a pen, establishing fixed references with an orthogonal Cartesian coordinate frame according to the tablet. This work intends to generate a trace as faithful as possible to a path made by the user without depending on a fixed surface or being in a specific vision area. The main idea is to establish a digital writing system with two-dimensional strokes that do not require a support surface; this is writing on the fly.
It is worth mentioning that the goal of the methods proposed in this work is online handwriting recognition without a fixed inertial frame of reference, like a screen, tablet, or any other reference surface. Given the above, we do not count on a fixed reference to establish a coordinate system, so the proposed methods must not rely on a fixed reference frame; this is the main differentiator against classic online handwriting recognition methods and devices, and quaternions are a popular and efficient alternative to solving this problem and creating orientation systems using IMUs [
13,
14,
15,
16,
17,
18,
19,
20,
21,
22]. However, their use implies a more complex mathematical model than the one presented here.
The present work focuses on generating patterns with defined shapes from geometric characteristics, representing the information of the letters in two formats: the points in Cartesian coordinates to graph the strokes directly or the polar coordinates of the stroke that allow the generating of normalized vector features instantly. Furthermore, the methods presented here do not require prior knowledge of the patterns; they trace them on the fly. Finally, this work seeks to generate high-quality patterns to guarantee better performance in future processing using an artificial intelligence system, as mentioned in [
23,
24,
25]. The quality of a prediction system’s results is largely based on the quality of the input data.
The system developed for the experimentation comprises three parts: the perception system, consisting of a three-axis IMU (Inertial Measurement Unit), a data acquisition and processing board, and a delivery system for the trace display.
2. Materials and Methods
The hardware of the digital writing system comprises an IMU, a data acquisition and processing system, a 3D printed case and a workstation. A pictorial representation of the inertial system and the IMU’s inner axis are shown in
Figure 1; the IMU used is the MPU6050 module, of which the 3-axis accelerometer and the 3-axis gyroscope are used, and an Arduino UNO board is used for data acquisition, information processing, and communication to the workstation, the latter being the one that allows viewing the reconstructed trace according to the proposed mathematical models (see
Figure 2).
A simple user-friendly case for the prototype was made with a 3D printer, with the components placed inside and aligned in the desired position (see
Figure 1) for the proper operation of the device, as shown in
Figure 3. The IMU is fixed to the casing so the user can draw freely, always maintaining the sensing plane between the pen’s tip and the sensor. In this way, although the velocity and acceleration vectors are three-dimensional, only the axes of the sensor plane perpendicular to the pen are sensed.
An algorithm is proposed to reproduce cursive handwriting strokes, using only the IMU data and without a fixed reference frame. In the cursive (often referenced as italic) handwriting style, letters are mainly constructed based on curved shapes, unlike the block letter style. Cursive handwriting has a greater dominance of curvatures, and several characters are usually embedded in a single continuous line. The hypothesis is that any cursive trace can be reproduced by linking a multiplicity of circular sections one after another, by knowing the variation of the slope concerning the arc the trace describes between any given pair of consecutive points
and
(see
Figure 4), that is, its curvature
(Equation (1)).
For the practical calculation of the curvature
an angle
, defined between the tangents to the trace at
and
, it is calculated first by means of two consecutive data points obtained from the IMU, then the arc length
between
and
is calculated from the same consecutive data points, and then the quotient between the angle τ and the arc length
gives the curvature of the piece of trace between
and
.
where
For the reconstruction of the trace, once the curvature between and is known, a curvature radius is calculated, along with its corresponding center. As the hypothesis is that the trace can be reconstructed by circular sections, once the radius and center of curvature are known, the angular section of the corresponding circle between the two points and is calculated based on the arc length previously calculated. All the data are acquired and processed in the Arduino UNO board, and then send to the workstation.
Finally, with all the above data, the circular sections a are plotted through any suitable software in the workstation.
Two different approaches to the proposed algorithm were developed and implemented, called method one and method two. For method one the velocity of the trace is used as the input data, as the selected IMU gives out a rotational velocity. First, this velocity must be transformed to a linear velocity, and for this transformation a turning radius equal to the distance from the tip of the pen to the center of the IMU is assumed. On the other hand, method two uses the linear accelerations directly from the IMU, unlike method one, without any transformation, which reduces the error in the trace reconstruction as it eliminates any assumption regarding any parameter used in the calculations, in addition to allowing the reconstruction of straight lines.
Method one is based only on circular sections, and it works in the way described below. First, suppose that a reconstructed trace is known from the respective in-plane trace velocities; considering the curvature measurement at point
of a curve (Equation (2)), we have
where
Then, under the hypothesis that the trace can be considered as a multiplicity of linked circular sections, the mean arc curvature (the curvature in the section between
and
) can be expressed as in Equation (3), where the change in the tangent vector (Equation (4)) to the curve to be reconstructed is the difference in linear speeds (
) between the points
and
of the trace; this is assumed to be true, since the tangent vector and linear velocity vector are analogous, as long as the linear velocity component which is tangent to the trajectory is considered. Also, the trace is assumed to be in a plane, so the velocity of the trace can be decomposed into two
and
components (Equation (7)).
where
Then the
curvature and the
radius of curvature at the point
are given by Equations (8) and (9), respectively.
And for the
iteration:
where
is the two-dimensional rotation matrix and
is the center of the circle of radius
(see
Figure 5 and
Figure 6).
In a circle, the arc length is given as the product of the radius and its respective angle in radians, hence we have
Since we are dealing with plane curves, it turns out that the curvature has a sign that indicates whether the curve turns to the left or to the right. Such a sign is defined as 1 if the unit tangent vector and the unit normal vector at a point on the curve, both considered to be the base of the plane, coincide with the orientation of the canonical base of the plane, which is the base with unit vectors
and
; otherwise, the value of the sign is −1. One can calculate the sign either by calculating the determinant of the base change matrix, or by calculating the inner product of the unit normal vector with
(of the IMU inner axis). Thus, we introduce
as the sign of the rotation angle, and it is defined as follows:
So that, if the rotation is performed in a clockwise direction, then ; otherwise, when the rotation is performed in counterclockwise direction, we obtain . In the case where no rotation is being performed.
Figure 6.
Three successive points describing a trace.
Figure 6.
Three successive points describing a trace.
The Equation (11) can be rewritten in terms of Cartesian coordinates as Equation (15), where
is the angle between two successive points and
,
) are the Cartesian coordinates of the center of the circle (see
Figure 5)
Following the construction of letters, it is crucial to recognize that another shape prevails mainly, in addition to the curves; this is the straight line. As mentioned above, efficient construction of the letters generally leads to better legibility and speed, so it is essential to add straight lines to the curves in the process of handwriting generation, since this gives a better projection of the image stored in human memory of what each letter looks like. According to this, the method considering only circular sections can be modified so it can reproduce straight lines, and this modification was called method two.
Method two is based on circular sections and straight lines; assuming a reconstructed trace, knowing its accelerations in the plane and considering the measurement of curvature at point
of a curve (Equation (17)), we have
where
is a vector defining a point, given by
In addition, the radius of curvature
of the vector
is
The known data are the
accelerations (
) of point
, obtained in the plane of movement of the trace, and the time difference
between the values obtained for accelerations in the plane. Assuming initial conditions of zero, we have
Then, if we rewrite Equation (19) in Cartesian coordinates, we obtain
Next, the center of the circle is
where
is the unit normal vector to the curve at
and is expressed in Cartesian coordinates as
The angle of rotation
is
Observe that the condition in Equation (25) is sufficient to guarantee the existence of . Otherwise, given in Equation (21) is undefined and so is .
4. Discussion
The main objective of this work is to demonstrate that it is possible to generate a non-inertial frame online cursive-handwriting system from curvature models, since this is the predominant form in this type of writing.
In the comparison made between the two proposed methods, we can highlight the fact that both show that it is possible to construct letters from linking multiple circular sections and that the patterns obtained are very similar to what is recognized. However, the legibility between one and the other is far from equal, since our understanding is much closer to forming letters when they are made up of curves and straight lines. Even in cursive writing, after all, the notes that only include straight lines or simple curves are the first that the human mind can identify.
That said, the method that uses circular sections and straight lines is the most complete in reconstructing cursive letters and for the generation of online handwriting with a non-inertial frame of reference. This work obtains an object focused on feature engineering based on differential geometry, prioritizing the shapes that the patterns present and not the dimension or accuracy of the position of the points, since it is aiming to be used in machine learning algorithms where it is necessary to vectorize the normalized feature.
Making a qualitative visual comparison with the results previously reported in the literature [
5,
8], it is possible to affirm that the results obtained with method two are comparable in terms of the fidelity of tracking the fundamental shape of the stroke. It is worth noting that, in contrast to the methods reported in [
5] and [
8], the method proposed in this work does not rely on an exhaustive preprocessing of the data in order to obtain the reported results.
The movement of the pen could be performed in three dimensions. However, this work assumes that the strokes made by the person are limited to an imaginary plane mentally set to write in the air. Both methods can be expanded to the idea of tracing in three dimensions; however, reading three-dimensional traces could be unpractical.