Slick Forums

Painting and recognizing shapes
Page 1 of 1

Author:  shiroto [ Wed Mar 09, 2011 10:18 pm ]
Post subject:  Painting and recognizing shapes

Hi guys (and girls?), I dont rly know where to post this but I guess this is the right choice.
I had an idea today: I want to make motions with my mouse and the computer to recognize what ive drawn there. Easy enough: I create a path object and say path.lineTo(current mouse position). Then I have some predesigned figures that I can compare the path with and say which it fits. Thats the whole concept.
Nows my question: how do I organize this?
Heres what I have so far:
It works but im not entirely satisfied with the class design. As you can see(if you opened my project) I have a class "Line"(I rly need a better name for this), which is the base for all "Figures". Every Figure consists of multiple Lines that are arranged in some way. Each Figure has a method matches(ArrayList<Path> paths) that checks if the given paths form that figure and then returns true or false.
Now ive made these Factory-classes which contain methods like createCross(), that obviously create the figure that the method says. This whole factory thing works, but I dont really like it oO maybe someone has a better idea to design this?
I also want to make a class like "BiggerFigures" which consists of figures instead of lines to make even "Bigger Figures" recognizable.
So im looking for design suggestions. I want to keep the systems flexibility to a max but I currently have no good ideas :/

A short introduction to the program i created:
The figures that can be drawn are at the bottom of the window: a vertical line, a horizontal line, a cross and a "日"(hi, jap. for sun or day). Booleans at the left for you to see what youve drawn there. A timer above them(You have 10s to draw something, if thats too short just change it lol) and at the top right the mouse position.
To start drawing press the "e"-key. To draw press the left mousebutton and move the mouse. When you release it and press it again a new path will be started. Press e again to stop drawing or wait for the time to run out.

The cross as no strokeorder, so you can start drawing wherever you want. When you want to draw 日 you have to make the strokes in the right order and direction. Its not yet 100% accurate tho. The correct order would be this:

So there are 4 strokes total. But you have to seperate the 2nd stroke into 2 (means: release the left mousebutton when you hit the upper right corner and press again, then move down). So there are 5 strokes, simply because i havent implemented edges or curves yet.

If you guys have any ideas how to organize this better or how to improve a algorithm or simply have a better name for something, let me here it :)

Author:  Tommy [ Thu Mar 10, 2011 10:25 am ]
Post subject: 

I didn't look at your source code (yet) but just googled for "mouse gesture recognition java" and first found this wikipedia entry:

The Smardec link
has a short API description here:

The most interesting concept idea I found there is the following:
a gesture is always a single stroke thing (clicking the mouse button, drawing something, releasing mouse button).
And the "drawing something" is described as movements up, down, right or left.
So every gesture could be described as a simple string.

So your gesture 1 would be "D" for down, 2 would be "URD" for up, right, down, 3 could be something like "UURDLRD" to draw the symbol in a single stroke and 4 could be "UURDDLUR".

But maybe you just download some of those libs (many are open source) and see if you can get some ideas/inspiration from them :wink:

Author:  shiroto [ Thu Mar 10, 2011 11:31 am ]
Post subject: 

omg, of course i didnt think of googling this xD well thanks, ill look into it.

Author:  mantax [ Fri Mar 11, 2011 10:59 am ]
Post subject: 

Have a look at neural networks! they fit your problem really well because they are able to learn and can recognize patterns. imo a very interesting topic :)


Author:  shiroto [ Fri Mar 11, 2011 2:15 pm ]
Post subject: 

mantax wrote:
Have a look at neural networks! they fit your problem really well because they are able to learn and can recognize patterns. imo a very interesting topic :)


wow thats amazing! ill definitly look into that more. thanks for the link

edit:now that i think of it; i will have "basics of neural networks" this semester lol but thats not rly what i was looking for, though interesting.
my 2nd approach was more like: give the perfect sample of an image and let the system calculate relations between lines and degrees and so on. then when you put something handmade into it it can compare the values.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group