Python/Opencv - 如何找到多边形的左下顶点

发布于 2025-01-13 11:40:47 字数 399 浏览 0 评论 0原文

早上好,

我是 OpenCV 和 numpy 的新手,我正在尝试找到一种方法来获取多边形的一个顶点。我需要提取形状的左下顶点。

我将多边形作为无序的 numpy 数组获取,假设

 [[348 778]
 [313 856]
 [200 621]
 [235 558]]

我需要找到左下顶点,如图所示

在此处输入图像描述

我应该选择 [778, 348]

有没有办法获取这个顶点?

Good morning,

i'm new to OpenCV and numpy and i'm trying to find a way to get one of the vertex of a polygon. I need to extract che bottom left vertex of the shape.

I get the polygon as a not ordered numpy array, let's say

 [[348 778]
 [313 856]
 [200 621]
 [235 558]]

i need to find the bottom left vertex, as in the image

enter image description here

i should select [778, 348]

Is there a way to get this vertex?

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

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

发布评论

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

评论(1

时光清浅 2025-01-20 11:40:47

要获得左下点,您应该获得 y 值最大的两个点,它们代表底部。然后,你应该得到对应x最低的点,它代表左下角的点。使用 [y,x] 中表示的点,您可以使用以下代码:

arr_list = [[348,778], [313,856], [200,621], [235,558]]

# Sorting the points to get the greatest 2 y values
sorted_list = sorted(arr_list, reverse=True)

# If x of the greatest y is lower, return it. Else, return the other point.
if sorted_list[0][1] < sorted_list[1][1]:
    point = sorted_list[0]
else:
    point = sorted_list[1]

To get your lower-left point, you should get the two points with the greatest y values, which represent the bottom. Then, you should get the point with the lowest corresponding x, which represents the point in the bottom left. Using your points that are represented in [y,x], you can use the following code:

arr_list = [[348,778], [313,856], [200,621], [235,558]]

# Sorting the points to get the greatest 2 y values
sorted_list = sorted(arr_list, reverse=True)

# If x of the greatest y is lower, return it. Else, return the other point.
if sorted_list[0][1] < sorted_list[1][1]:
    point = sorted_list[0]
else:
    point = sorted_list[1]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文