Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to know the size of bounding box in object-detection api

I have used the API

(https://github.com/tensorflow/models/tree/master/object_detection)

And then,

How would I know the length of bounding box?

I have used Tutorial IPython notebook on github in real-time.

But I don't know use which command to calculate the length of boxes.

like image 614
SUN JIAWEI Avatar asked Sep 12 '17 05:09

SUN JIAWEI


2 Answers

Just to extend Beta's answer:

You can get the predicted bounding boxes from the detection graph. An example for this is given in the Tutorial IPython notebook on github. This is where Beta's code snipped comes from. Access the detection_graph and extract the coordinates of the predicted bounding boxes from the tensor:

By calling np.squeeze(boxes) you reshape them to (m, 4), where m denotes the amount of predicted boxes. You can now access the boxes and compute the length, area or what ever you want.

But remember that the predicted box coordinates are normalized! They are in the following order:

[ymin, xmin, ymax, xmax]

So computing the length in pixel would be something like:

def length_of_bounding_box(bbox):
    return bbox[3]*IMG_WIDTH - bbox[1]*IMG_WIDTH
like image 52
ITiger Avatar answered Sep 17 '22 15:09

ITiger


I wrote a full answer on how to find the bounding box coordinates here and thought it might be useful to someone on this thread too.

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)
like image 28
Gal_M Avatar answered Sep 18 '22 15:09

Gal_M