按条件进行多边形平滑

发布于 2025-01-06 02:27:41 字数 252 浏览 1 评论 0原文

我有由点序列给出的多边形 我需要应用以下规则:

  • 角度必须为 180、90、45 度;
  • 如果线平行,则线之间的距离大于 minValue;
  • 多边形的方向有水平和垂直。

(如果最接近特定问题,那么我在 OpenCV 中找到对象的轮廓,那么它们应该很好画)

我需要做这样的事情: 示例

I have polygon given by the points sequence
I need to apply follow rules:

  • angles must be 180,90,45 degrees;
  • if lines parallel then distanse beetwen the lines greater then minValue;
  • orientation of polygon is horizontal and vertical.

(If the closest to a specific problem, then I find the contours of objects in OpenCV, then they should be nice to draw)

I need to do somthing like this:
Example

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国际总奸 2025-01-13 02:27:41

我会使用 DP 点减少来解决这个问题。这个例程有几种不同的风格,最常见的并不是最适合你想要做的事情,但最终这种方法将带来最好的质量。

经典的 DP 运算采用一系列点来形成多段线,并删除任何不会破坏形状超出特定因素的点。该系数是基于您的数据的测量单位,因此在您的情况下,它可能以像素为单位。正如您可以想象的那样,选择因子是使用 DP 中最困难的部分,除非您只想从多边形中删除可以轻松量化的点,这些点并不重要。

在你的情况下,以及我的很多时间,你想要删除对多边形形状影响最小的点。您应该能够采用 DP 的典型递归示例,并在第一次迭代点后使其中断,以便一次删除一个点。然后,您会对您的形状进行评分,看看它是否满足您的要求。如果得分不完美,您将删除另一分并重新得分,直到达到完美分数或只剩下三分。如果没有完美的分数,您可以采用得分最高的形状,并且可能有第二个算法来强制它满足要求。

http://en.wikipedia.org/wiki/Ramer %E2%80%93Douglas%E2%80%93Peucker_algorithm

I would approach this problem using DP point reduction. There are several different flavors of this routine and the most common isn't the best for what you are trying to do but in the end this approach will result in the best quality.

The classic DP operation takes an array of points that forms a poly-line and removes any points that won't corrupt the shape beyond a certain factor. This factor is a unit of measure based on your data so in your case it would probably be in pixels. As you can imagine, picking the factor is the most difficult part of using DP unless you just want to remove points from the polygon that you can easily quantify aren't important.

In your case, and mine a lot of time, you want to remove the point that is contributing to the shape of the polygon the least. You should be able to take the typical recursive examples of DP and get it to break after the first iteration through the points so it removes one point at a time. You would then score your shape to see if it meets the requirements you have. If it doesn't score perfect you remove another point and re-score until it does or you only have three points left. If there is no perfect score you can take the shape with the best score and maybe have a 2nd algorithm that forces it to meet the requirements.

http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm

源来凯始玺欢你 2025-01-13 02:27:41

你所问的问题似乎并不简单,而且定义也不明确。需要更多背景信息。

我会尝试两种方法:

  • 在多边形上覆盖方形网格并保留充分填充的正方形。

  • 对形状进行骨架化(http://en.wikipedia.org/wiki/Topological_sculpture)、清理并将骨架分成大部分水平/垂直的部分;然后用真正的水平/垂直笔画替换这些片段。

What you are asking seems non trivial, and not so well defined. More context is required.

I would try two approaches:

  • overlay a square grid on the polygon and keep the squares that are sufficiently filled.

  • skelettonize the shape (http://en.wikipedia.org/wiki/Topological_skeleton), cleanup, and break the skeleton into mostly horizontal/vertical segments; then replace these segments by truly horizontal/vertical strokes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文