from __future__ import absolute_import from __future__ import division from __future__ import print_function
import json import numpy as np import matplotlib.pyplot as plt import scipy.io as matio import os import cv2 import torch import matplotlib.patches as mpatches from skimage import io
defload_mat(path): with open(path) as f: mat = matio.loadmat(f) return mat
defcreate_patch(pos): xy = (pos[0], pos[1]) w = pos[2] - pos[0] h = pos[3] - pos[1] return mpatches.Rectangle(xy, w, h, alpha=0.7)
defcreate_circle(xy): x = xy[0] y = xy[1] return mpatches.Circle((x,y), radius=5)
defrescale_bbox(bbox): midx = (bbox[0] + bbox[2]) / 2.0 midy = (bbox[1] + bbox[3]) / 2.0 w = bbox[2] - bbox[0] h = bbox[3] - bbox[1] s = 1.25 w *= s h *= s return [midx - w / 2.0, midy - h / 2.0, midx + w / 2.0, midy + h / 2.0]