From c8987ecd7b2f2b773d869a8121ff45dd51f83e68 Mon Sep 17 00:00:00 2001 From: sipp11 Date: Fri, 1 Nov 2019 17:12:01 +0900 Subject: [PATCH] Updates --- src/draw_area.py | 38 ++++++++++++++++++++++++++++++++++++++ src/utils.py | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/draw_area.py diff --git a/src/draw_area.py b/src/draw_area.py new file mode 100644 index 0000000..a70791f --- /dev/null +++ b/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) + diff --git a/src/utils.py b/src/utils.py index eed8f26..f2c29c4 100755 --- a/src/utils.py +++ b/src/utils.py @@ -17,7 +17,7 @@ def area(a, b): AREAS = [ [ ("id", 1), - ("area", ((0, 40), (12, 129))), + ("area", ((0, 40), (120, 129))), ("target", ["car", "bus", "motorbike"]), ("next", [6]), ], @@ -70,7 +70,7 @@ AREAS = [ ], [ ("id", 9), - ("area", ((1047, 229), (112, 338))), + ("area", ((1047, 229), (1120, 338))), ("target", ["person", "wheelchair"]), ("next", [8]), ],