如何从右到左、从上到下排列对象检测边界框列表?

发布于 2025-01-14 01:12:33 字数 438 浏览 0 评论 0原文

我正在尝试从右到左、从上到下对对象检测后获得的边界框列表进行排序。 下面是边界框位置,

bbox = [(637, 207, 681, 207),  (679, 99, 726, 99), (747, 497, 798, 497), (829, 124, 892, 124), (1002, 131, 1059, 131),  (1010, 656, 1071, 656)] 

我根据 xmin 值对此列表进行排序,如下图

sorted(bbox,key=lambda x:x[2][0])

所示,我最终得到了边界框排列,如下图所示 [![示例图片][1]][1]

序列不按顺序排列,序列应从左到右、从上到下开始,如下图所示 [![sample2][2]][2]

任何实现这一目标的建议或指南将受到高度赞赏

I'm trying to sort the list of bounding boxes obtained after object detection from right to left and top to down.
Below are the bounding box locations

bbox = [(637, 207, 681, 207),  (679, 99, 726, 99), (747, 497, 798, 497), (829, 124, 892, 124), (1002, 131, 1059, 131),  (1010, 656, 1071, 656)] 

I sorted this list based on xmin value as below

sorted(bbox,key=lambda x:x[2][0])

I ended up getting bounding box arrangement as shown in the below image
[![sample image][1]][1]

the sequence is not in order , the sequence should start from left to right and top to bottom as shown in below image
[![sample2][2]][2]

any suggestion or guide to achieve this will be highly appreciated

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

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

发布评论

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

评论(1

蹲在坟头点根烟 2025-01-21 01:12:33

您想要按最接近左上角的点排序吗?
如果是这样,您需要计算距该角的距离,然后排序:

import numpy as np

bbox = [(637, 207, 681, 207),  (679, 99, 726, 99), (747, 497, 798, 497), (829, 124, 892, 124), (1002, 131, 1059, 131),  (1010, 656, 1071, 656)]
arr = np.array(bbox)
r = (arr[:, 0]**2 + arr[:, 1] **2)**0.5
print(np.argsort(r))

这将打印出点的顺序。
我假设每个点的前 2 个坐标是 x 和 y,原点位于左上角。

You want the points sorted by closest to the upper-left corner?
If so you need to calculate the distance from that corner and only then sort:

import numpy as np

bbox = [(637, 207, 681, 207),  (679, 99, 726, 99), (747, 497, 798, 497), (829, 124, 892, 124), (1002, 131, 1059, 131),  (1010, 656, 1071, 656)]
arr = np.array(bbox)
r = (arr[:, 0]**2 + arr[:, 1] **2)**0.5
print(np.argsort(r))

This will print out the order of the points.
I assumed the first 2 coordinates in each point are the x and y and that the origin is in the upper-left corner.

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