Created
July 23, 2019 05:55
-
-
Save YimianDai/65a232dc2cb76448eaeb17f5ff398e2d to your computer and use it in GitHub Desktop.
Show BBox on Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from data import IcebergDetDataset | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as patches | |
import platform, os | |
####################################################### | |
################## Hyper-Parameter #################### | |
####################################################### | |
if platform.system() == "Darwin": | |
data_root = os.path.join('~', 'Nutstore Files', 'Dataset', 'Iceberg') | |
elif platform.system() == "Linux": | |
data_root = os.path.join('~', 'datasets', 'Iceberg') | |
else: | |
raise ValueError('Notice Dataset Path') | |
train_dataset = IcebergDetDataset(preload_label=False) | |
width, height = 512, 512 | |
for i, data in enumerate(train_dataset): | |
img = data[0].asnumpy() | |
label = data[1] | |
print(label.shape) | |
fig, ax = plt.subplots(1) # Create figure and axes | |
ax.imshow(img) # Display the image | |
for j in range(label.shape[0]): | |
xmin, ymin, xmax, ymax = label[j][0], label[j][1], label[j][2], label[j][3] | |
width, height = xmax - xmin, ymax - ymin | |
# Create a Rectangle patch | |
rect = patches.Rectangle((xmin, ymin), width, height, linewidth=1, | |
edgecolor='r', facecolor='none') | |
ax.add_patch(rect) # Add the patch to the Axes | |
plt.show() | |
break | |
# Reference | |
# https://stackoverflow.com/questions/37435369/matplotlib-how-to-draw-a-rectangle-on-image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment