【发布时间】:2020-04-07 14:10:39
【问题描述】:
(图像名称)(边界框坐标)(类名称)
有没有其他方法可以让 COWC 数据集中的标注更容易?
提前致谢:)
【问题讨论】:
标签: image-processing keras deep-learning annotations retinanet
(图像名称)(边界框坐标)(类名称)
有没有其他方法可以让 COWC 数据集中的标注更容易?
提前致谢:)
【问题讨论】:
标签: image-processing keras deep-learning annotations retinanet
COWC 数据集带有注释,其中每辆汽车都标有一个点。 PNG 文件包含注释。以下是我在 PNG 文件中查找注释位置的方法。
import numpy as np
from PIL import Image
annotation_path = 'cowc/datasets/ground_truth_sets/Toronto_ISPRS/03553_Annotated_Cars.png'
im = Image.open(annotation_path)
data = np.asarray(im)
这里的问题是这两个值都将被索引为非零,但我们只需要其中一个。 COWC 数据集用红点标记汽车,用蓝点标记负数,我们不需要 alpha 通道,因此需要对新数组进行切片,这样我们就不会计算 alpha 通道并获得重复的索引值。
data = data[:,:,0:3]
y_ind, x_ind, rgba_ind = data.nonzero()
您现在有了注释文件中所有点的索引。 y_ind 对应于高度尺寸,x_ind 对应于宽度。这意味着在第一个 x、y 位置,我们应该看到一个类似于 [255, 0, 0] 的数组。这是我从索引中查找第一个 x、y 位置时得到的结果
>>> data[y_ind[0], x_ind[0]]
array([255, 0, 0], dtype=uint8)
Here 作者决定创建一个边长为 20 像素的边界框,以数据集中提供的注释为中心。要为此图像中的第一个注释创建单个边界框,您可以试试这个。
# define bbox given x, y and ensure bbox is within image bounds
def get_bbox(x, y, x_max, y_max):
x1 = max(0, x - 20) # returns zero if x-20 is negative
x2 = min(x_max, x + 20) # returns x_max if x+20 is greater than x_max
y1 = max(0, y - 20)
y2 = min(y_max, y + 20)
return x1, y1, x2, y2
x1, y1, x2, y2 = get_bbox(x_ind[0], y_ind[0], im.width, im.height)
您必须循环遍历所有 x、y 值来制作图像的所有边界框。这是为单个图像创建 csv 文件的粗略而肮脏的方法。
img_path = 'cowc/datasets/ground_truth_sets/Toronto_ISPRS/03553.png'
with open('anno.csv', 'w') as f:
for x, y in zip(x_ind, y_ind):
x1, y1, x2, y2 = get_bbox(x, y, im.width, im.height)
line = f'{img_path},{x1},{y1},{x2},{y2},car\n'
f.write(line)
我计划将一个巨大的图像分解成更小的图像,这将改变边界框的值。我希望这对您有所帮助,并且是一个很好的起点。
【讨论】: