Skip to content

Instantly share code, notes, and snippets.

@wookayin
Created August 31, 2015 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wookayin/cec7deb6c0353c34b0a5 to your computer and use it in GitHub Desktop.
Save wookayin/cec7deb6c0353c34b0a5 to your computer and use it in GitHub Desktop.
def im_drawbox(window, color='r', class_name='', score=0.0):
"""
Add a detection window (bounding box) into the current plot image.
window: tuple-like of length 4 (xmin, ymin, xmax, ymax)
"""
import matplotlib.pyplot as plt
xmin, ymin, xmax, ymax = window
coords = (ymin, xmin), ymax - ymin, xmax - xmin
currentAxis = plt.gca()
currentAxis.add_patch(
plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=3)
)
currentAxis.text(ymin, xmin - 5,
'{:s} ({:.3f})'.format(str(class_name), score),
bbox=dict(facecolor=color, alpha=0.5),
fontsize=12, color='white')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment