Skip to content

Commit 8c9bcc3

Browse files
authored
Merge pull request #183 from wenting-zhao/master
Make drawing bbox an option in showAnns.
2 parents e140a08 + 2e75dbf commit 8c9bcc3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

PythonAPI/pycocotools/coco.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def loadImgs(self, ids=[]):
230230
elif type(ids) == int:
231231
return [self.imgs[ids]]
232232

233-
def showAnns(self, anns):
233+
def showAnns(self, anns, draw_bbox=False):
234234
"""
235235
Display the specified annotations.
236236
:param anns (array of object): annotations to display
@@ -286,6 +286,14 @@ def showAnns(self, anns):
286286
plt.plot(x[sk],y[sk], linewidth=3, color=c)
287287
plt.plot(x[v>0], y[v>0],'o',markersize=8, markerfacecolor=c, markeredgecolor='k',markeredgewidth=2)
288288
plt.plot(x[v>1], y[v>1],'o',markersize=8, markerfacecolor=c, markeredgecolor=c, markeredgewidth=2)
289+
290+
if draw_bbox:
291+
[bbox_x, bbox_y, bbox_w, bbox_h] = ann['bbox']
292+
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]]
293+
np_poly = np.array(poly).reshape((4,2))
294+
polygons.append(Polygon(np_poly))
295+
color.append(c)
296+
289297
p = PatchCollection(polygons, facecolor=color, linewidths=0, alpha=0.4)
290298
ax.add_collection(p)
291299
p = PatchCollection(polygons, facecolor='none', edgecolors=color, linewidths=2)

0 commit comments

Comments
 (0)