facebookresearch / facebookresearch/segment-anything
Bounding Box not surrounding Mask
- Dominant language
- Jupyter Notebook
- Stars
- 54.9k
- Forks
- 6.4k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I had an image of shape(1024,1024,3), I used SAMAutomaticMaskGenerator to segment everything , I am using below code to plot bounding box around generated masks but bounding boxes are not surrounding masks , the bbox's size is also different from that of object. Can someone help understand why this is happening?
```
results = mask_generator.generate(image_rgb)
#print(results)
# masks = [(mask['segmentation'],mask['bbox'])for mask in sorted(results, key=lambda x: x['area'], reverse=True)]
for res in results:
mask = res['segmentation']*255
bbox = res['bbox']
print(bbox)
x1 = bbox[0] - (bbox[2]/2)
y1 = bbox[1] - (bbox[3]/2)
x2 = bbox[0] + (bbox[2]/2)
y2 = bbox[1] + (bbox[3]/2)
image = mask.astype('uint8').copy()
cv2.rectangle(image,(int(x1),int(y1)),(int(x2),int(y2)),(255,0,0),2)
plt.imshow(image,cmap="gray")
plt.show()
```
Contributor guide
Research direction
Start with the SAMAutomaticMaskGenerator.generate(image_rgb) results and compare each segmentation mask with its bbox values. Check the coordinate and size conventions used by the returned fields and by cv2.rectangle; done means explaining the mismatch and identifying the correct plotting interpretation. No repository file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, opencv, python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100