Browse Source

Updates

dev
sipp11 5 years ago
parent
commit
c8987ecd7b
  1. 38
      src/draw_area.py
  2. 4
      src/utils.py

38
src/draw_area.py

@ -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)

4
src/utils.py

@ -17,7 +17,7 @@ def area(a, b):
AREAS = [ AREAS = [
[ [
("id", 1), ("id", 1),
("area", ((0, 40), (12, 129))), ("area", ((0, 40), (120, 129))),
("target", ["car", "bus", "motorbike"]), ("target", ["car", "bus", "motorbike"]),
("next", [6]), ("next", [6]),
], ],
@ -70,7 +70,7 @@ AREAS = [
], ],
[ [
("id", 9), ("id", 9),
("area", ((1047, 229), (112, 338))), ("area", ((1047, 229), (1120, 338))),
("target", ["person", "wheelchair"]), ("target", ["person", "wheelchair"]),
("next", [8]), ("next", [8]),
], ],

Loading…
Cancel
Save