def plot_dwell_heatmap(sess, xml_dir_extention=None): # make sure there is nothing still in the figure plt.cla() # get the scrolling data data, correct_doc = get_dwell_area(sess, xml_dir_extention=xml_dir_extention) if len(data) == 0: return # load an image of the file dst_img_path = 'parts_for_viz/resized-images/womens_suffrage_' dst_img_path += '1_B.png' if correct_doc.find('1') != -1 else '2_A.png' dst_img = Image.open(dst_img_path) width, height = dst_img.size # visualize image plt.imshow(dst_img) # plot data for x_left, x_right, y_top, y_bottom in data: # Create a Rectangle patch rect = patches.Rectangle((x_left, y_top), x_right - x_left, y_bottom - y_top, facecolor='b', alpha=1.0 / len(data)) plt.add_patch(rect) # scale the plot to fit over the image plt.xlim([0, width]) plt.ylim([height, 0]) # get rid of y ticks plt.yticks([], []) plt.xticks([], []) plt.savefig(sess.dir_name + os.sep + 'dwell_heatmap.png', dpi=800)
def draw_bot(self, plt, pose, color, alpha, size=0.03): arrow = mpatches.Arrow(pose[0], pose[1], size * np.cos(pose[2]), size * np.sin(pose[2]), color=color, width=size / 2, alpha=alpha) plt.add_patch(arrow)
def plot(self, mz=None, color='k', alpha=0.5, ax=None): from matplotlib.path import Path from matplotlib.patches import PathPatch #TODO: allow plotting to a 2D plot? # confine matplotlib imports to here, so this module works # even if matplotlib is not installed (e.g. on a server) path = self.as_poly(mz) ply = PathPatch(Path(path), facecolor=desaturate(color, 0.5), \ alpha=alpha, lw=0) if ax is None: import matplotlib.pyplot as plt plt.add_patch(ply) else: ax.add_patch(ply)
def plot(self, mz=None, color='k', alpha=0.5, ax=None): from matplotlib.path import Path from matplotlib.patches import PathPatch # TODO: allow plotting to a 2D plot? # confine matplotlib imports to here, so this module works # even if matplotlib is not installed (e.g. on a server) path = self.as_poly(mz) ply = PathPatch(Path(path), facecolor=desaturate(color, 0.5), alpha=alpha, lw=0) if ax is None: import matplotlib.pyplot as plt plt.add_patch(ply) else: ax.add_patch(ply)
def main(): m = -1 b = 3 lower = -20 upper = 20 num_points = 25 x1 = [random.randrange(start=1, stop=9) for i in range(num_points)] x2 = [random.randrange(start=1, stop=9) for i in range(num_points)] #y1 = [random.randrange(start=lower,stop=np.sqrt(1-x**2)) for x in x1] #y2 = [random.randrange(start=np.sqrt(1-x**2) ,stop=upper) for x in x2] c = plt.Circle((0, 0), radius=5) plt.gca() plt.add_patch(c) plt.axis('scaled') plt.show() #lt.scatter(x1,y1,c='blue') #plt.scatter(x2,y2,c='red') plt.show()
def plot_img_bbox(img, target, sub): # plot the image and bboxes # Bounding boxes are defined as follows: x-min y-min width height plt.subplot(sub) plt.axis('off') plt.imshow(img) for box in (target['boxes']): x, y, width, height = box[0], box[1], box[2] - box[0], box[3] - box[1] print(x, y, width, height) rect = patches.Rectangle((x, y), width, height, linewidth=2, edgecolor='r', facecolor='none') # Draw the bounding box on top of the image plt.add_patch(rect) return sub + 1
import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Rectangle x1 = np.array([0, 0, 1, 1]) y1 = np.array([0, 1, 0, 1]) xy = (0, 0) plt.figure() plt.show() plt.add_patch( Rectangle([0, 0], 0, 0, facecolor='None', edgecolor='black', linewidth=1.0))
def main(): anno_classes = ['alb', 'bet', 'dol', 'lag', 'other', 'shark', 'yft'] path = os.getcwd() download_annotations(path) # //get a list of all images and coordinates from bb_json = {} for c in anno_classes: if c == 'other': continue # no annotation file for "other" class f = '{}/annos/{}_labels.json'.format(path, c) j = json.load(open(f, 'r')) for l in j: if 'annotations' in l.keys() and len(l['annotations']) > 0: bb_json[l['filename'].split('/')[-1]] = sorted( l['annotations'], key=lambda x: x['height'] * x['width'])[-1] print(bb_json['img_04908.jpg']) files = [] files_and_sizes = [] import settings data_dir = os.path.join(path, settings.DATA) files_and_sizes.extend( get_files_and_sizes(data_dir, settings.TRAIN_FOLDER_NAME)) files_and_sizes.extend( get_files_and_sizes(data_dir, settings.VALIDATE_FOLDER_NAME)) files_and_sizes.extend( get_files_and_sizes(data_dir, settings.TEST_FOLDER_NAME)) # raw_filenames = [f[0].split('/')[-1] for f in dirs_and_files] empty_bbox = {'height': 0., 'width': 0., 'x': 0., 'y': 0.} # if we have a file that is not annotated then annotate it with an empty box for entry in files_and_sizes: if not entry[0] in bb_json.keys(): bb_json[entry[0]] = empty_bbox # now lets scale all images in data folders to 224x224 for entry in files_and_sizes: scale_boundingbox(bb_json, entry[0], entry[1]) bb = bb_json[entry[0]] #display a few images and bounding boxes for i in range(10): fn = files_and_sizes[i][0] fqn = files_and_sizes[i][2] bb = bb_json[fn] img = mpimg.imread(fqn) plt.imshow(img) # Create a Rectangle patch rect = patches.Rectangle((bb[0], bb[1]), bb[2], bb[3], linewidth=1, edgecolor='r', facecolor='none') plt.add_patch(rect)