Digit recognition is a tough problem, especially when you don’t have any knowledge in the machine learning field. Some time ago, when I was struggling to understand neural networks, I got a brilliant idea that could solve this problem without the help of machine learning.

Recognizing a digit in an image seemed like an impossible task. So, to simplify the problem, I didn’t consider the image itself, but the stroke made while drawing the digit, as shown in the video below:

Doing this I reduced the image to an array of points, easier to deal with. The next idea that I had was to simplify the problem even further by replacing each pair of consecutive points with the angle they make, as shown in the video below:

Doing this we reduced the array of points to an array of values(angles). This new array can be plotted on a graph, as I did below:

The exact shape of the graph doesn’t really matter. It is important how this graph resembles the original stroke(a 3 in this case): it starts with a small angle from the upper tip of the 3, and the angle grows util it reaches the mid tip of the 3. Then the angle drops dramatically and starts growing again. The graph will look similar each time the stroke represents a 3: an increasing segment, a big drop and another increasing segment. This states for all digits. Take a look at graph of a 1.

The final step we need to make is splitting the graph into segments and choosing the digit with the same structure of segments. Also, we have to add a few more simple test to differentiate digits like 6 and 9. For shaking hands to not mess up the graph I smoothed the graph.

For code check the GitHub repository here. Also, here is the live demo.