sipp11
5 years ago
2 changed files with 40 additions and 2 deletions
@ -0,0 +1,38 @@
|
||||
import argparse |
||||
import matplotlib.pyplot as plt |
||||
import matplotlib.patches as patches |
||||
from PIL import Image |
||||
import numpy as np |
||||
from utils import AREAS |
||||
from matplotlib.cm import get_cmap |
||||
|
||||
|
||||
ap = argparse.ArgumentParser() |
||||
ap.add_argument("-i", "--input", required=True, help="path to input iamge") |
||||
args = vars(ap.parse_args()) |
||||
|
||||
im = np.array(Image.open(args['input']), dtype=np.uint8) |
||||
|
||||
# Create figure and axes |
||||
fig, ax = plt.subplots(1) |
||||
|
||||
# Display the image |
||||
ax.imshow(im) |
||||
|
||||
for _area in AREAS: |
||||
a = dict(_area) |
||||
color = get_cmap('tab20')(a['id']) |
||||
x1, y1 = a['area'][0] |
||||
x2, y2 = a['area'][1] |
||||
w, h = x2 - x1, y2- y1 |
||||
# Create a Rectangle patch |
||||
rect = patches.Rectangle( |
||||
a['area'][0], w, h, linewidth=1, edgecolor=color, facecolor="none" |
||||
) |
||||
# Add the patch to the Axes |
||||
ax.add_patch(rect) |
||||
ax.text(x1, y1 - 5, f"AREA: {a['id']}", fontsize=5, color=color) |
||||
|
||||
|
||||
plt.savefig("test.jpg", dpi=300) |
||||
|
Loading…
Reference in new issue