def _rot90(parent_dir, image_dir): imgs_path = os.path.join(parent_dir, image_dir) imgs_out_path = os.path.join(parent_dir, '{}{}'.format(image_dir, '_with_rot90')) io_utils.delete_file_folder(imgs_out_path) io_utils.mkdir(imgs_out_path) images = [os.path.join(imgs_path, s) for s in os.listdir(imgs_path)] for image_file in images: try: img = cv2.imread(image_file) width = img.shape[0] height = img.shape[1] if width > height: image = np.array(np.rot90(img, 1)) image = image.copy() else: image = img name = image_file.split('/')[-1] save_path = os.path.join(imgs_out_path, name) # don't need resize # image = cv2.resize(image, (int(image.shape[1] * 0.5), int(image.shape[0]*0.5)), interpolation=cv2.INTER_CUBIC) # print('resize:{}'.format(image.shape)) cv2.imwrite(save_path, image) print(save_path) except Exception as e: print('Exception in pascal_voc_parser: {}'.format(e)) continue return imgs_out_path
def read_image_bgr(path): try: image = np.asarray(Image.open(path).convert('RGB')) except Exception as ex: print(path) io_utils.delete_file_folder(path) return None return image[:, :, ::-1].copy()
def rename_suffix_image(input_path): data_dir = os.path.join(input_path, 'all_data/JPEGImages') imgs_rename_path = '{}_rename'.format(data_dir) io_utils.delete_file_folder(imgs_rename_path) io_utils.mkdir(imgs_rename_path) for s in os.listdir(data_dir): old = os.path.join(data_dir, s) name = s.split('.')[0] new = os.path.join(imgs_rename_path, '{}.jpg'.format(name)) io_utils.rename(old, new)
def _rename_image(parent_dir, image_dir_name, str_date): # image_dir_name = 'JPEGImages' data_dir = os.path.join(parent_dir, image_dir_name) data_rename_dir = os.path.join(parent_dir, '{}_rename'.format(image_dir_name)) io_utils.delete_file_folder(data_rename_dir) io_utils.mkdir(data_rename_dir) prefix = 'train' idx = 1000 cur_date = datetime.datetime.now() # str_date = '{year}{month}{day}'.format(year=cur_date.year, month=cur_date.month, day=cur_date.day) for s in os.listdir(data_dir): old = os.path.join(data_dir, s) new = os.path.join(data_rename_dir, '{}_{}_{}.jpg'.format(prefix, str_date, idx)) io_utils.copy(old, new) idx = idx + 1 return data_rename_dir
def rename_image(input_path): # data_path = os.path.join(input_path, 'from_internet') data_path = input_path # imgs_path = os.path.join(data_path, 'wwsp-wznn-hz-yw-125ml') # imgs_rename_path = os.path.join(data_path, 'wwsp-wznn-hz-yw-125ml_rename') # imgs_path = os.path.join(data_path, 'yl-ylcnn-pz-yw-250ml') # imgs_rename_path = os.path.join(data_path, 'yl-ylcnn-pz-yw-250ml_rename') data_paths = [os.path.join(data_path, s) for s in ['all_data']] for data_dir in data_paths: # prefix = data_dir.split('-')[1] prefix = 'train' imgs_rename_path = '{}_rename'.format(data_dir) io_utils.delete_file_folder(imgs_rename_path) io_utils.mkdir(imgs_rename_path) idx = 1000 for s in os.listdir(data_dir): old = os.path.join(data_dir, s) new = os.path.join(imgs_rename_path, '{}_20180319_{}.jpg'.format(prefix, idx)) io_utils.rename(old, new) idx = idx + 1