在YOLOP上,我可以毫无问题地检测车道和可行驶区域。数据来自 Torch 模型,并存储为2D numpy数组,如下所示:
[[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
...
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]]
这个2D numpy数组只存储对应于非可驱动区域和可驱动区域的0和1。
我的问题在这里开始了。我必须将这3个不同的可行驶区域的车道分成单独的组(数组),这样我就可以使用所需的可行驶区域only. For example...
因此,当我决定只显示drivableLane[0]
时,应该会得到类似this.的输出
一开始我试着一个接一个地迭代整个2D数组并存储可行驶区域坐标,但这是一个坏主意,因为这个操作太慢了。我还想出了DBSCAN和BIRCH聚类算法,但最后,我搞砸了。
我会很感激听到一个想法!
1条答案
按热度按时间wlwcrazw1#
给出您提供的示例图像:
其中,我们将图像的RGB(A)值表示为
numpy
矩阵:你说的已经是
0
和1
的了(这很棒!甚至更容易),我们可以根据不重叠的可行驶区域的row
,column
索引来制作1
的矩阵。让我们在这里可视化它:
我们可以通过检查图像中的相邻位置是否也是可行驶区域(
1
)来区分边界:我们还可以区分图像中可驾驶区域的边界(
1
)(或者如果你想拥有图像中“背景”或不可驾驶区域的矩阵):例如,如果我们有
0
的a
矩阵,并用1
填充左上角:print(a)
:我们可以区分
1
和它们的邻居(0
)的位置:从
a
矩阵(0
的)或“image”数组中获取这个“正方形对象”(1
的)的位置(row
,column
):现在,如果
a
有多个可驱动区域:它看起来像
print(a)
:或
plt.imshow(a)
:我们想把这些
1
分割成单独的list
(这个例子使用嵌套的list
而不是矩阵更容易表达),我们可以使some_lists_in_dict
包含每个可驱动区域。(按顺序编号表示为str
在keys
中)和其values
为row
,column
list
s;作为一个字典,每个“新的”可驾驶区域将被插入作为一个新的列表,在它被区分的顺序,和row
,column
值将与所有可驾驶区域进行比较(附加到预先存在的list
s,如果它is_part_of
该可驾驶区域,或成为一个新的list
为一个新的可驾驶区域):并且
print(some_lists_in_dict)
向我们表明,它正确地区分了两个可行驶区域: