我想识别在屏幕上绘制的圆形,三角形和矩形等形状。我的主要目的是用户在屏幕上绘制形状,我需要一个代码来识别该形状。我该如何解决这个问题?
What you are trying to achieve can be quite tricky, but I happened to implement something similar a while ago, and here is the approach that I used:
a) if it has an aspect ratio close to a square, then simply crop the white space around it and enlarge it such that it has the same size as your database images
b) Otherwise, it will most likely have one dimension about two times larger than the other one, in which case you crop the white space, rotate it to have the height as it's biggest dimension, enlarge it to 256x128 and then add on both sides 64 px of white space.
Given that the above algorithm is a bit of a resource hog, you might consider having a server somewhere, which can do the actual comparisons, especially if you want to add many images to your database. Since I already implemented this algorithm for a demo application, I can already tell you that you're going to have to do a lot of pixel operations. Also, rotating images with the Android SDK can be annoying, because it changes the image dimensions...
If you are feeling adventurous, here are a couple of papers describing state of the art algorithms for tackling this problem: " Shape contexts enable efficient retrieval of similar shapes " by Greg Mori, Serge Belongie and Jitendra Malik (2001) and " Shape Matching: Similarity Measures and Algorithms " by Remco C. Veltkamp (2001). The maths might be a bit heavy, though.
You should look into GestureOverlayView. A good tutorial is: http://www.vogella.com/articles/AndroidGestures/article.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.