def cvts(root, fm1='dng', fm2='jpg', num_worker=3): dir1, dir2 = osp.join(root, fm1), osp.join(root, fm2) ls1 = os.listdir(dir1) mkdir(dir2) outputs = bj(dir2, be(ls1, fm2)) inputs = bj(dir1, ls1) with Pool(num_worker) as p: p.starmap_async(convert, zip(inputs, outputs))
def bcrop2(root, in_dir='jpg16', out_dir="jpg16c"): in_dir, out_dir = osp.join(root, in_dir), osp.join(root, out_dir) ls = os.listdir(in_dir) if not os.path.exists(out_dir): os.makedirs(out_dir) inputs = bj(in_dir, ls) outputs = bj(out_dir, ls) with Pool(16, initialize_bds, (root, )) as p: p.starmap_async(crop, zip(inputs, outputs))
def check_shape(root,fm1='jpgc',fm2='pngc'): dir1,dir2=osp.join(root,fm1),osp.join(root,fm2) ls1,ls2=bj(dir1,sorted(os.listdir(dir1))),bj(dir2,sorted(os.listdir(dir2))) for f1,f2 in zip(ls1,ls2): im1=imread(f1) im2=imread(f2) print(im2.max(),end='\r') if im1.shape[:2] != im2.shape[:2]: print(im1.shape,im2.shape) return
def tbnails(root, in_dir='jpg', out_dir='jpg16'): in_dir, out_dir = osp.join(root, in_dir), osp.join(root, out_dir) ls = os.listdir(in_dir) if not os.path.exists(out_dir): os.makedirs(out_dir) inputs = bj(in_dir, ls) outputs = bj(out_dir, ls) with Pool(3) as p: p.starmap_async(scale, zip(inputs, outputs))
def get_bb(root): df = get_trip(root) gts = pd.unique(df["gt"].map(lambda x: x + '.jpg')) inputs = bj(osp.join(root, 'jpg16'), gts) bbs = [] for i in inputs: img = imageio.imread(i) h, w, _ = img.shape plt.imshow(img) plt.draw() # plt.imshow(img) pts = plt.ginput(2) print(pts) if len(pts) < 2: break (x0, y0), (x1, y1) = pts bbs.append([y0 / h, y1 / h, x0 / w, x1 / w]) bbs = np.array(bbs) print(bbs) bb = [ np.max(bbs[:, 0]), np.min(bbs[:, 1]), np.max(bbs[:, 2]), np.min(bbs[:, 3]) ] print(bb) with open(osp.join(root, 'bb.csv'), 'a') as f: f.write(','.join([str(b) for b in bb]))
def batch_rotate(root, fm1='png', num_worker=16): dir1 = osp.join(root, fm1) ls1 = os.listdir(dir1) inputs = bj(dir1, ls1) with Pool(num_worker) as p: p.map(inplace_rotate, inputs)