Reputation:
The RCNN Mask detect person add the bounding box and a shape approximation, my aim is to obtain only these How I can obtain only the shape approximation and the bounding box from RCNN Mask ?
Upvotes: 0
Views: 536
Reputation: 2368
Assuming you have a list of NumPy arrays with objects masks, you can try scikit-image's regionprops
function, which returns a list of corresponding bounding boxes (and other useful properties as well):
from skimage import measure
a = np.array([[0,0,0],[0,1,0],[0,1,0],[0,1,0],[0,0,0]])
b = measure.regionprops(a)
print(b[0].bbox)
Returns: (1, 1, 4, 2)
, which corresponds to (min_row, min_col, max_row, max_col)
. Note that as according to https://scikit-image.org/docs/dev/api/skimage.measure.html#regionprops , the intervals for bounding box coordinates are half-open (front-inclusive, back-exclusive) as follows: [min_row; max_row)
and [min_col; max_col)
.
Upvotes: 2