返回通过边界框阈值的坐标谷歌的对象检测 API [英] Return coordinates that passes threshold value for bounding boxes Google's Object Detection API

查看:58
本文介绍了返回通过边界框阈值的坐标谷歌的对象检测 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Does anyone know how to get bounding box coordinates which only passes threshold value?

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

I found this answer (here's a link), so I tried using it and done the following:

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"的边界框的值.

But I noticed that by using answer provided in link - returns all the values. From all the bounding boxes detected by the classifier (which I do not want). What I want is only values from bounding boxes that passes "min_score_thresh".

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

I feel like this should be very simple, but I do lack knowledge in this area. If I'll find the answer, I'll be sure to post it right here, but if anyone else knows the answer and could save me some time - I would be grateful.

推荐答案

更新:前面函数返回的boxesscores都是numpy数组对象,因此可以使用boolean indexing来过滤出低于阈值的框.

Update: The boxes and scores returned by previous functions are both numpy array objects, therefore you can use boolean indexing to filter out boxes below the threshold.

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

This should give you the box that passes the threshold.

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)

这篇关于返回通过边界框阈值的坐标谷歌的对象检测 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆