The coordinates in the boxes
array ([ymin, xmin, ymax, xmax]
) are normalized. Therefore, you have to multiply them with the images width / height to obtain the original values.
To achieve this, you can do something like the following:
for box in np.squeeze(boxes):
box[0] = box[0] * heigh
box[1] = box[1] * width
box[2] = box[2] * height
box[3] = box[3] * width
Then you can save the boxes to your csv using the numpy.savetxt() method:
import numpy as np
np.savetxt('yourfile.csv', boxes, delimiter=',')
Edit:
As pointed out in the comments, the approach above gives a list of box coordinates. This is due to the fact, that the boxes tensor holds the coordinates of every detected region. One quick fix for me is the following, assuming that you use the default confidence acceptance threshold of 0.5:
for i, box in enumerate(np.squeeze(boxes)):
if(np.squeeze(scores)[i] > 0.5):
print("ymin={}, xmin={}, ymax={}, xmax{}".format(box[0]*height,box[1]*width,box[2]*height,box[3]*width))
This should print you the four values, and not four boxes. Each of the values represents one corner of the bounding box.
If you use another confidence acceptance threshold you have to adjust this value. Maybe you can parse the model configuration for this parameter.
To store the coordinates as CSV, you can do something like:
new_boxes = []
for i, box in enumerate(np.squeeze(boxes)):
if(np.squeeze(scores)[i] > 0.5):
new_boxes.append(box)
np.savetxt('yourfile.csv', new_boxes, delimiter=',')