def show_bboxes(axes, bboxes, labels=None, colors=None): def _make_list(obj, default_values=None): if obj is None: obj = default_values elif not isinstance(obj, (list, tuple)): obj = [obj] return obj labels = _make_list(labels) colors = _make_list(colors, ['b', 'g', 'r', 'm', 'c']) for i, bbox in enumerate(bboxes): color = colors[i % len(colors)] rect = d2l.bbox_to_rect(bbox.asnumpy(), color) axes.add_path(rect) if labels and len(labels) > i: text_color = 'k' if color == 'w' else 'w'
def show_bboxes(axes, bboxes, labels=None, colors=None): def _make_list(obj, default_values=None): if obj is None: obj = default_values elif not isinstance(obj, (list, tuple)): obj = [obj] return obj labels = _make_list(labels) colors = _make_list(colors, ['b', 'g', 'r', 'm', 'c']) for i, bbox in enumerate(bboxes): color = colors[i % len(colors)] rect = d2l.bbox_to_rect(bbox.asnumpy(), color) axes.add_patch(rect) if labels and len(labels) > i: text_color = 'k' if color == 'w' else 'w' axes.text(rect.xy[0], rect.xy[1], labels[i], va='center', ha='center', fontsize=9, color=text_color, bbox=dict(facecolor=color, lw=0))
import d2lzh as d2l from mxnet import image d2l.set_figsize() img = image.imread('../img/catdog.jpg').asnumpy() # d2l.plt.imshow(img) dog_bbox, cat_bbox = [60, 45, 378, 516], [400, 112, 655, 493] fig = d2l.plt.imshow(img) fig.axes.add_patch(d2l.bbox_to_rect(dog_bbox, 'blue')) fig.axes.add_patch(d2l.bbox_to_rect(cat_bbox, 'red')) d2l.plt.show()