Skip to content

Instantly share code, notes, and snippets.

@neerajadsul
Created April 19, 2023 12:10
Show Gist options
  • Save neerajadsul/5d12af633b8075b62238ae959a195398 to your computer and use it in GitHub Desktop.
Save neerajadsul/5d12af633b8075b62238ae959a195398 to your computer and use it in GitHub Desktop.
Crop Bounding Box and Show Object Detection Result
def imshow_od_bbox(image_file, bbox_voc, object_class, labelmap_dict):
import matplotlib.pyplot as plt
from PIL import Image
xmin,ymin,xmax,ymax = bbox_voc
right = xmin + (xmax - xmin)
bottom = ymin + (ymax - ymin)
image = Image.open(image_file)
detected_object = image.crop((xmin, ymin, right, bottom))
plt.imshow(detected_object)
plt.title(f'{object_class} : {labelmap_dict[object_class]}')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment