See if NSBezierPath(s) make a certain shape or pattern
-
26-05-2021 - |
Frage
Okay so I'm make a program where I will be universally accepting cocoa trackpad events, and I will map these events into NSBezierPaths. For example, I might have a NSBezierPath that is from just one finger, and it is circular(ish). Or the path might be in the shape of a right pointing arrow. Or it might actually be two vertical NSBezierPaths side by side. What I need to do is look at these NSBezierPaths and determine what/shape pattern they resemble most... Does anyone have any pointers?
Thanks
Lösung
These might help
shape recognition algorithms - stack overflow
Most of these take a bitmap and try and identify the shape - it's a complex area.
hth
Andere Tipps
This is probably late, but I just thought about this, and came up with something worth trying.
Define a set of shapes, each parameterized with a small number of parameters. For example, define a circle through it's middle point (two variables) and a radius (third variable), a line through two end points (four variables), an arrow as a line with additional parameter for the size of the head, and so on.
Now you can transform this into a minimization problem. For each point
i
on the path and each shape, determine the minimal distance to the shape as a function of the shape parameters,di(params)
. Now define a probability function that tells you how much the path looks like the shape. The default candidate is what is called "chi squared" in probability theory:
chi^2 (params) = sum_i ( di(params) )^2
The
chi^2
is a function of the parameters for each shape - therefore the next step is to minimize this quantity. Libraries are available for this usually, but a minimization routine can also be implemented by hand.After minimizing the
chi^2
for each shape, the shape that gets the smallestchi^2
is the one that resembles the path most. And you already have the parameters that fit best!
Now, getting this to work properly is hard and will take a lot of time and tweaking (finding more suitable probability functions, efficient minimization routines, a good set of base shapes, etc). Google finds much more detailed explanations - but this is how I would start if no other information was available.