【问题标题】:I cannot draw bounding box correctly我无法正确绘制边界框
【发布时间】:2021-11-22 22:41:46
【问题描述】:

我无法正确绘制边界框。

img = Image.open("/content/drive/MyDrive/58125_000893_Sideline_frame298.jpg").convert('RGB')
convert_tensor = torchvision.transforms.ToTensor()

img=convert_tensor(img)
width=15
top=456
height=16
left=1099
img=img*255
boxs=[left,top,top+width,left+height]
print(boxs)
boxs=torch.tensor(boxs,dtype=torch.int)
a=torch.tensor(img,dtype=torch.uint8)
a=torchvision.utils.draw_bounding_boxes(image=a,boxes=boxs.unsqueeze(0),width=2,colors=(0,0,255))
a=a.permute(1,2,0)
plt.imshow(a)
plt.show()

我需要为玩家的头盔画一个边界框。但是边界是在不同的位置绘制的。我从 CSV 文件中获取边界属性。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: python matplotlib pytorch torch


    【解决方案1】:

    您使用的是左上角坐标系,而 PyTorch 使用x: 水平左->右和y: 垂直下-> 上。提供给torchvision.utils.draw_bounding_boxes 的绑定框定义为(xmin, ymin, xmax, ymax)

    因此,您的映射应该是:

    xmin = left
    ymin = top + height
    xmax = left + width
    ymax = top
    

    【讨论】:

    • 好的。我还有一个疑问。我需要绘制多个边界框。那么我可以使用张量还是 for 循环?
    • 是的,您可以使用 for 循环并多次应用 torchvision.utils.draw_bounding_boxes
    • @18BCM061JoshuaJennySibbu 这对你有用吗?
    • 好的,谢谢。
    • @18BCM061JoshuaJennySibbu 点击左侧的绿色复选标记,考虑接受答案为有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    相关资源
    最近更新 更多