返回通过边界框阈值的坐标 Google 的对象检测 API

2023-11-29

有谁知道如何获取仅通过阈值的边界框坐标?

我找到了这个答案(这是link),所以我尝试使用它并完成了以下操作:

vis_util.visualize_boxes_and_labels_on_image_array(
    image,
    np.squeeze(boxes),
    np.squeeze(classes).astype(np.int32),
    np.squeeze(scores),
    category_index,
    use_normalized_coordinates=True,
    line_thickness=1,
    min_score_thresh=0.80)

for i,b in enumerate(boxes[0]):
    ymin = boxes[0][i][0]*height
    xmin = boxes[0][i][1]*width
    ymax = boxes[0][i][2]*height
    xmax = boxes[0][i][3]*width
    print ("Top left")
    print (xmin,ymin,)
    print ("Bottom right")
    print (xmax,ymax)

但我注意到,通过使用链接中提供的答案 - 返回所有值。来自分类器检测到的所有边界框(我不想要)。我想要的只是来自通过“min_score_thresh”的边界框的值。

我觉得这应该很简单,但我确实缺乏这方面的知识。 如果我能找到答案,我一定会将其发布在这里,但如果其他人知道答案并且可以节省我一些时间 - 我将不胜感激。


更新: 这boxes and scores前面的函数返回的都是numpy 数组对象,因此您可以使用布尔索引过滤掉低于阈值的框。

这应该会给你通过阈值的框。

true_boxes = boxes[0][scores[0] > min_score_thresh]

然后你可以做

for i in range(true_boxes.shape[0]):
    ymin = true_boxes[i,0]*height
    xmin = true_boxes[i,1]*width
    ymax = true_boxes[i,2]*height
    xmax = true_boxes[i,3]*width
    print ("Top left")
    print (xmin,ymin,)
    print ("Bottom right")
    print (xmax,ymax)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

返回通过边界框阈值的坐标 Google 的对象检测 API 的相关文章

随机推荐