Return coordinates for bounding boxes Google's Object Detection API

前端 未结 2 1155
天命终不由人
天命终不由人 2021-01-14 12:03

How can i get the coordinates of the produced bounding boxes using the inference script of Google\'s Object Detection API? I know that printing boxes[0][i] returns the predi

2条回答
  •  孤独总比滥情好
    2021-01-14 12:31

    Google Object Detection API returns bounding boxes in the format [ymin, xmin, ymax, xmax] and in normalised form (full explanation here). To find the (x,y) pixel coordinates we need to multiply the results by width and height of the image. First get the width and height of your image:

    width, height = image.size
    

    Then, extract ymin,xmin,ymax,xmax from the boxes object and multiply to get the (x,y) coordinates:

    ymin = boxes[0][i][0]*height
    xmin = boxes[0][i][1]*width
    ymax = boxes[0][i][2]*height
    xmax = boxes[0][i][3]*width
    

    Finally print the coordinates of the box corners:

    print 'Top left'
    print (xmin,ymin,)
    print 'Bottom right'
    print (xmax,ymax)
    

提交回复
热议问题