Skip to content

Commit

Permalink
Merge pull request #183 from wenting-zhao/master
Browse files Browse the repository at this point in the history
Make drawing bbox an option in showAnns.
  • Loading branch information
tylin authored Feb 20, 2020
2 parents e140a08 + 2e75dbf commit 8c9bcc3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion PythonAPI/pycocotools/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def loadImgs(self, ids=[]):
elif type(ids) == int:
return [self.imgs[ids]]

def showAnns(self, anns):
def showAnns(self, anns, draw_bbox=False):
"""
Display the specified annotations.
:param anns (array of object): annotations to display
Expand Down Expand Up @@ -286,6 +286,14 @@ def showAnns(self, anns):
plt.plot(x[sk],y[sk], linewidth=3, color=c)
plt.plot(x[v>0], y[v>0],'o',markersize=8, markerfacecolor=c, markeredgecolor='k',markeredgewidth=2)
plt.plot(x[v>1], y[v>1],'o',markersize=8, markerfacecolor=c, markeredgecolor=c, markeredgewidth=2)

if draw_bbox:
[bbox_x, bbox_y, bbox_w, bbox_h] = ann['bbox']
poly = [[bbox_x, bbox_y], [bbox_x, bbox_y+bbox_h], [bbox_x+bbox_w, bbox_y+bbox_h], [bbox_x+bbox_w, bbox_y]]
np_poly = np.array(poly).reshape((4,2))
polygons.append(Polygon(np_poly))
color.append(c)

p = PatchCollection(polygons, facecolor=color, linewidths=0, alpha=0.4)
ax.add_collection(p)
p = PatchCollection(polygons, facecolor='none', edgecolors=color, linewidths=2)
Expand Down

0 comments on commit 8c9bcc3

Please sign in to comment.