Last week I organized a programming meetup in my town. The goal was to chat and show personnal projects, then to code small things for a couple hours, and share what we had at the end of the day.
I took the opportunity to try coding this simple demo I had in my head for some time:
This is a program that allows you to draw freehand shapes, and then tries to recognize them and “clean-up” your drawing. The idea is that it could be used in some kind of diagraming tool.
The nice part is that it works without any neural network or advanced “AI”, just good ol’ explainable math. The program tries to fit parametric shapes to the set of drawn points with a mean least squares error, using gradient descent. It then just selects the shape with the least error. The method is remarkably robust with regard to its simplicity. It is also pretty cheap.
Some things could be enhanced with additional heuristics, eg sometimes if a line is sufficiently bent it will better fit a circle than a line. We could impose a constraint relating the bounding box of the drawn shape to the bounding box of the guessed shape, to make sure it doesn’t select a very big circle instead of a more likely line. We could also look at the endpoints and decide to rule-out closed shapes if they are far apart. Etc. etc.