def test_handle(): # handle=Handle_Rawjpg() # handle = Handle_Npyarr() # test #-# handle=Handle_Rawjpg() #-# imgID = 'n02690373_16' #-# imgpath = '/Users/shine/working/cvpr17pose/dataset/PASCAL3D/ImageData.Max500/aeroplane_imagenet/n02690373_16.jpg' handle = Handle_Rawpng() imgID = '1507795919477055' imgpath = '/Users/shine/Pictures/1507795919477055.png' # k, v = handle.pack(imgID, imgpath) # cv2.imshow('image-pack', handle.unpack(v)) cv2_wait() img_arr = cv2.imread(imgpath) k, v = handle.pack_from_npyarr(imgID, img_arr) # cv2.imshow('image-pack_from_npyarr', handle.unpack(v)) cv2_wait() print(len(v)) exit()
def _vis_minibatch(self, sample_batched): """Visualize a mini-batch for debugging.""" for i, (idx, label, a, e, t, data) in enumerate( zip( sample_batched['idx'], # note: these are tensors sample_batched['label'], sample_batched['a'], sample_batched['e'], sample_batched['t'], sample_batched['data'])): rcobj = self.recs[idx] print(idx, rcobj.obj_id) im = data.numpy().transpose((1, 2, 0)).copy() im = (im * self.roiloader_pascal3d.pxl_std ) + self.roiloader_pascal3d.pxl_mean if self.mode == 'torchmodel': im = (im * 255)[:, :, ::-1].astype(np.uint8) # RBG->BGR else: # caffemodel type im = im.astype(np.uint8) text = '%s %.1f' % (rcobj.category, a) cv2_putText(im, (0, 20), text, bgcolor=(255, 255, 255)) # text = ' a=%.1f,e=%.1f,t=%.1f' % (rcobj.gt_view.a, rcobj.gt_view.e, rcobj.gt_view.t) cv2_putText(im, (0, 40), text, bgcolor=(255, 255, 255)) # cv2.imshow('im', im) cv2_wait()
def test_read_db1(): imgdb = ImageData_lmdb( env.Home + '/working/cvpr17pose/dataset/PASCAL3D/ImageData.Max500.Rawjpg.lmdb') print(imgdb.keys[:10]) for imgID in imgdb.keys: img = imgdb[imgID] cv2.imshow('img', img) cv2_wait()
def test(visualize=True): datadb = ImageData_lmdb(db_path) print (datadb.keys) for k in datadb.keys: img = datadb[k] if visualize: # : cv2.imshow('real_img', img) cv2_wait()
def test_img_lmdb(): imgdb = ImageData_lmdb( env.Home + '/working/cvpr17pose/dataset/PASCAL3D/ImageData.Max500.Rawjpg.lmdb') #imgID = np.string_('n03693474_19496') # np.string_ #imgID = np.unicode_('n03693474_19496') # np.string_ #imgID = np.string_('n03693474_19496').tobytes() # np.bytes_ ? imgID = 'n03693474_19496' # str #imgID = b'n03693474_19496' # bytes im = imgdb[imgID] cv2.imshow('image', im) cv2_wait()
def test_lmdb(): # lmdb_env = lmdb.open(os.path.join(PASCAL3D_Dir,'ImageData.Max500.Rawjpg.lmdb'), map_size=map_size) lmdb_env = lmdb.open( env.Home + '/working/cvpr17pose/dataset/PASCAL3D/ImageData.Max500.Rawjpg.lmdb', map_size=10000) handle = Handle_Rawjpg() imgID = b'n03693474_19496' with lmdb_env.begin() as txn: raw_data = txn.get(imgID) #.tobytes()) #(b'00000000') cv2.imshow('image', handle.unpack(raw_data)) cv2_wait()
def vis(self, nr_row=5, nr_col=6, side=150, randshow=False, is_depth_img=False): # nr_per_row=6, # Iter by keys keys = self.keys if randshow: random.shuffle(keys) itkeys = iter(keys) if True: # with self.lmdb_env.begin() as txn: row_images = [] rows = [] # for key, raw_data in txn.cursor(): # assert raw_data is not None # pad_img = pad_as_squared_img(self.handle.unpack(raw_data), Side=side) # Iter by keys for key in itkeys: next_img = self[key] if is_depth_img: # [TODO] TO REMOVE this case. _max, _min = next_img.max(), next_img.min() next_img = (next_img.astype(np.float32) - _min) / ( _max - _min) # normalize [min,max] to [0,1] elif self.db_path.endswith( '.Rawpng.lmdb') and self.handle.remap is not None: _max, _min = self.handle.remap['max'], self.handle.remap[ 'min'] next_img = (next_img - _min) / (_max - _min) pad_img = pad_as_squared_img(next_img, Side=side) if len(row_images) < nr_col: row_images.append(pad_img) else: cat_imgs = np.concatenate(row_images, axis=1) row_images = [pad_img] # reset row_images if len(rows) < nr_row: rows.append(cat_imgs) else: cat_alls = np.concatenate(rows, axis=0) cv2.imshow('images', cat_alls) cv2_wait() rows = [cat_imgs] # reset rows
def _vis_minibatch(self, sample_batched): """Visualize a mini-batch for debugging.""" for i, (idx, label, quat, data) in enumerate( zip( sample_batched['idx'], # note: these are tensors sample_batched['label'], sample_batched['quat'], sample_batched['data'])): rc = self.recs[idx] # print idx im = data.numpy().transpose((1, 2, 0)).copy() im += self.cfg.PIXEL_MEANS im = im.astype(np.uint8) # xmin, ymax a, b, c, d = quat cv2_putText(im, (0, 20), rc.category, bgcolor=(255, 255, 255)) text = '%.1f %.1f %.1f %.1f' % (a, b, c, d) cv2_putText(im, (0, 40), text, bgcolor=(255, 255, 255)) cv2.imshow('im', im) cv2_wait()
def _vis_one(self, idx, data, norm, mask, flip): data = data.numpy() if isinstance(data, torch.Tensor) else data norm = norm.numpy() if isinstance(norm, torch.Tensor) else norm mask = mask.numpy() if isinstance(mask, torch.Tensor) else mask flip = flip.numpy() if isinstance(flip, torch.Tensor) else flip # _norm = norm.reshape(-1, 3) _mask = mask.astype(np.bool).reshape(-1) _norm = _norm[_mask] # if True: sampling = 0.01 _inds = np.arange(len(_norm)) sample_inds = np.random.choice(_inds, size=int(len(_inds) * sampling), replace=False) _nodes = _norm[sample_inds] nodes = np.zeros_like(_nodes) nodes[:, 0], nodes[:, 1], nodes[:, 2] = _nodes[:, 0], _nodes[:, 2], _nodes[:, 1] visualize3d(nodes) # im = data.transpose((1, 2, 0)).copy() im += caffe_mean_pxl # mean_pxl im = im.astype(np.uint8) # xmin, ymax # norm = ((norm + 1) * (2**7)).astype( np.uint8) # map from [-1,1] to [0,256] # mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR) # showim = np.concatenate([im, norm, mask], axis=1) cv2_putText(showim, (0, 20), "with_flip: %s " % flip.astype(np.bool)) cv2.imshow('im', showim) cv2_wait()