Return coordinates that passes threshold value for bounding boxes Google's Object Detection API

陌路散爱 提交于 2019-12-31 03:55:25

问题


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)

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.


回答1:


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]

And then you can do

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)


来源:https://stackoverflow.com/questions/56117765/return-coordinates-that-passes-threshold-value-for-bounding-boxes-googles-objec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!