【问题标题】:Return coordinates that passes threshold value for bounding boxes Google's Object Detection API返回通过边界框阈值的坐标谷歌的对象检测 API
【发布时间】:2019-09-30 17:36:49
【问题描述】:

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

我找到了这个答案(这里是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”的边界框的值。

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

【问题讨论】:

    标签: tensorflow object-detection threshold object-detection-api


    【解决方案1】:

    更新: 前面函数返回的boxesscores 都是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)
    

    【讨论】:

    • 刚回来,这没有解决。 IndexError:标量变量的索引无效。行:ymin = true_boxes[0][i][0]*height.
    • 能否在true_boxes = boxes[0][scores[0] > min_score_thresh] 之后运行print(true_boxes.shape),然后将输出粘贴到此处
    • 输出是这样的:(11, 4)
    • 好的,刚刚更新了答案,(注意代码也更新了)帮助这次你得到想要的结果
    猜你喜欢
    • 2018-04-17
    • 2018-08-01
    • 1970-01-01
    • 2019-09-30
    • 2019-09-18
    • 2020-05-17
    • 2019-10-11
    • 2019-06-18
    • 1970-01-01
    相关资源
    最近更新 更多