From 2e75dbf4c52c6625d7f43e513ec824e62d80719f Mon Sep 17 00:00:00 2001
From: Wenting Zhao <wenting.zhao@outlook.com>
Date: Thu, 28 Jun 2018 16:07:16 +0800
Subject: [PATCH] Make drawing bbox an option in showAnns.

---
 PythonAPI/pycocotools/coco.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/PythonAPI/pycocotools/coco.py b/PythonAPI/pycocotools/coco.py
index dc9972ba..9b038b16 100644
--- a/PythonAPI/pycocotools/coco.py
+++ b/PythonAPI/pycocotools/coco.py
@@ -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
@@ -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)