How can you read from that you draw

Hello! I making where you should draw different shapes to get points. So that is the question, how can i know if ive drawn triangle or circle etc.

This would be a pretty complex topic. Google has just recently opened up to the public a neural network AI for the purpose of trying to learn what people draw. Thats going to be the premium version of what you are attempting.

The exact answer you want might depend on what you need to do inside your program. How much detail is important? What is the goal being achieved by the user? I’ve seen solutions where the drawn image is converted into a bitmap shape that can be reference against a database. The user is drawing in high detail, but the conversion would change it to a much lower resolution.

Now even with a database you can’t just account for every permutation, you need some sort of algorithm to do comparisons to different variants and also work out what is most similar.

Extremely complex. Simplest way to do that is doing some image detection stuff to work out similarities between the graphic the person has drawn and the graphic you think it represents. A detection could be when the difference function value is less than a certain percentage of difference or something like that. It’s a heck of a lot of work and you’d be better off using a pre existing library for this kind of stuff.

So i just have some spells, that you can cast by drawing shapes, fireball - circle, triangle shield etc. What libraries can i use or are there any simple ways to do that?

It’s not all that complicated if you get to pick what the shapes are, and so can choose easily-distinguished shapes.

One way I’ve done it in the past is to

  • Find the bounding box around their drawing

  • Divide this into a 3x3 grid, like a tic-tac-toe board, with each grid cell labelled (maybe 1 to 9 like on a numeric keypad)

  • Find the string of grid cells their drawing path goes through, e.g. “78965123”

  • Look this up in a dictionary of valid paths.

In that final step, I actually used the Levenshtein distance to find the closest match in the dictionary, which makes this system quite robust to minor variations.

You can also easily make this a learning system, if you provide the user some way to enter what this particular pattern should be interpreted as. You simply add that to the dictionary. Learning is instantaneous; way faster than neural networks (and I say this as somebody who spent years studying neural networks).

If you need help implementing this, please PM me.

2 Likes

I would have approached it with a ton of if/else statements and checking for sudden angle changes etc… Your approach sounds a lot better. I’ll keep it in mind for when I ever need to implement something like that. Thanks for sharing!

1 Like

If you wish to cut some corners there is at least one gesture recognition plugin on the store that can identify shapes drawn.

Just spitballing here, but could you not track the movement vector of the touch, and then identify how many times the touch changed direction? Like a circle would end about where it started and would never change direction by a large amount. A triangle would change direction 2 times and end where it starts, The Z would change direction 2 times and end far from it’s start.

maybe add a third measure to keep track of, like finding the center point of the movement and seeing the furthest and closest the touch ever gets to the center. Circles and triangles would not stray too far from the center, but other shapes might.