Search code examples
algorithmshapesidentification

How to identify if a set of lines is similar to a shape


Currently I have a program that allows the user to paint on it by capturing the mouse position every 0.05 seconds and drawing a line between a point and the next. With that setup I am looking for a way to identify shapes like a circle, a rectangle or the letter 'P'.

My current algorithm divides the screen on sections, then marks the sections with points recorded by the player and makes a matrix with the marked sections, then compares that matrix with every shape matrix.

This lacks any kind of support for rotations, sizes or positions. Also the control of the threshold is tricky returning in most cases fake results. I need an algorithm that allows to identify for example a ' P ' as a ' P '.

Note: My current application is running on a c++ framework so any libraries or tools are welcome but I am interested on the algorithm behind.

Edit: After thinking around the problem I have changed the current grid on the screen, instead of that I capture the points and shift them to resize the shape so it fits on a grid and over that grid compare with the known shapes.

Picture of the process

This solves the position and size problems while being fast enough, also rotating the input and then resizing in a loop may solve the rotation problem (seems though it would have an high cost and won't be very reliable)

I would gladly welcome alternative methods of handling shape comparison or the rotation.


Solution

  • After thinking around the problem I have changed the current grid on the screen, instead of that I capture the points and shift them to resize the shape so it fits on a grid and over that grid compare with the known shapes.

    Picture of the process

    This solves the position and size problems while being fast enough, also rotating the input and then resizing in a loop may solve the rotation problem (seems though it would have an high cost and won't be very reliable)