简体   繁体   English

如何找到手绘多边形的边和顶点

[英]How to find Edges and Vertices of a hand drawn polygon

I would like to make a shape recognition program that would trace a mouse and record it's location at each 1/2 second.我想制作一个形状识别程序,可以跟踪鼠标并每 1/2 秒记录一次鼠标的位置。 How could I use these points to find a rough polygon?我如何使用这些点来找到一个粗糙的多边形? In other words, if you just draw a shape resembling a triangle or square, it will more likely be a be a 50-100-gon, how can I simplify it to get the shape I were trying to draw?换句话说,如果你只是画一个类似三角形或正方形的形状,它很可能是 50-100 边形,我怎样才能简化它以获得我想要绘制的形状? I know that you could do a genetic algorithm, but do not know exactly how that would work, and I would like to know any alternatives.我知道你可以做一个遗传算法,但不知道它是如何工作的,我想知道任何替代方案。

edit: convex hulls will not work, concavity is needed to be preserved.编辑:凸包不起作用,需要保留凹面。

i'll give this a shot.我会试一试。

  1. lets call the position when the mouse click down event happens point START当鼠标点击事件发生点START时,让我们调用 position
  2. every interval take another position called CURR每个间隔采取另一个 position 称为CURR
  3. the lets call the previous CURR, PREV让我们调用以前的 CURR, PREV
  4. calculate the slope (delta y/delta x) between CURR and PREV,计算 CURR 和 PREV 之间的斜率 (delta y/delta x),
  5. calculate the slope of the line between CURR and START计算 CURR 和 START 之间的线的斜率
  6. define some threshold for a difference between the two slopes为两个斜率之间的差异定义一些阈值
  7. if the slope crosses the threshold,如果斜率超过阈值,
    1. store the line between START AND CURR as a SIDE将 START 和 CURR 之间的线存储为 SIDE
    2. define CURR as a new START将 CURR 定义为新的 START
  8. repeat until CURR is within a certain radius of the original START or crosses one of the previous sides重复直到 CURR 在原始 START 的某个半径内或穿过前面的一侧

you might be able to determine the shape simply by counting sides.您也许可以通过计算边数来确定形状。

For each point along the 100-agon, find the area of the tiny triangle formed by that point and the points on either side.对于沿 100 边形的每个点,找到由该点和两侧的点形成的小三角形的面积。 Remove the point that created the smallest triangle.删除创建最小三角形的点。 Repeat until the smallest triangle is larger than some threshold.重复直到最小的三角形大于某个阈值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM