how to recognize simple handwriting shapes? [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
开发者_JS百科Closed 7 years ago.
Improve this questionI have a set of simple shapes (see following figure), and I want to recognize handwriting shape and figure out which shape it probably is in the set.
Is there any simple algorithm to do that? Or any open source lib?
BTW, my task is simple, so I don't use too complicated lib like OpenCV.
Thanks, in advance!!
It's an old project, but this may be along the lines of what you are looking for.
This one requires OpenCV, but as the commenter pointed out, it might be worth your while to learn it.
This is essentially line detection
It works only for shapes with straight lines, and is by no means simple.
Assume that your figure has k line segments in it, use the k-means algorithm to aggregate the points into lines.
First divide randomly the points into clusters.
For each of these clusters compute the line that the points are approximating. (A line for which the sum of all distances to the points is minimum)
The outliers (points most distant from line) should be reassigned to some other cluster where they fit better.
Repeat last step until a certain threshold is reached
If you don't reach the desired threshold then you could try a different value of K
If you do reach one then you can compute the intersection of those lines and extract other properties that you need to match the irregular shapes to the regular ones.
You could tell triangles from squares, and squares from parallelograms this way, but it's awfully complicated.
This "algorithm" could work for squiggly lines, dotted lines, or for shapes where the lines don't intersect, so it's fairly robust
I wouldn't know how to do it in C or C++, but the algorithm is simpl-ish. Note that the success rate diminishes with each angle added to the shape so it should be good for recognizing the basic shape set you gave above but not much else.
- Corner recognition. You'll need to recognize all sorts of corners, and that can be easy. If you aren't looking for an amazing shape-recognition algorithm, just a quick and easy one, simply look for groups of pixels where a line comes from one side and does not end on the opposite side. You could probably do this in about 10 to 20-pixel blocks, possibly more if some shapes may have really sloppy corners (like the bottom corner on your second handwriting shape). However, the larger the block size you use the less you can detect small shapes.
- Error checking. First of all, if you found less than 3 corners but more than zero you know there was a mistake. Otherwise, if you found zero, you might use another algorithm to determine if it is a circle or oval, and return that result. If you didn't, move on.
- Line straightening. First, we determine in what order the corners are connected (easy). Then you straighten the lines by comparing the differences in X and Y coordinates, eliminating the smallest of the two differences, or, if they are past a certain threshold, assume a diagonal line.
- Corner matching. Once you have that, it's easy to identify the shape by matching line characteristics like angles and distances (for example, start at any point and find horizontal-vertical-horizontal-vertical and you know you have a square or rectangle, which you can differentiate by comparing lengths).
Of course, totally accurate matching can never be possible. I can't even tell if your second example shape is a tilted parallelogram or a tilted square (or diamond or rectangle).
精彩评论