本文整理汇总了Python中mmcv.imwrite方法的典型用法代码示例。如果您正苦于以下问题:Python mmcv.imwrite方法的具体用法?Python mmcv.imwrite怎么用?Python mmcv.imwrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mmcv
的用法示例。
在下文中一共展示了mmcv.imwrite方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump_frames
# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imwrite [as 别名]
def dump_frames(vid_item):
full_path, vid_path, vid_id = vid_item
vid_name = vid_path.split('.')[0]
out_full_path = osp.join(args.out_dir, vid_name)
try:
os.mkdir(out_full_path)
except OSError:
pass
vr = mmcv.VideoReader(full_path)
for i in range(len(vr)):
if vr[i] is not None:
mmcv.imwrite(
vr[i], '{}/img_{:05d}.jpg'.format(out_full_path, i + 1))
else:
print('[Warning] length inconsistent!'
'Early stop with {} out of {} frames'.format(i + 1, len(vr)))
break
print('{} done with {} frames'.format(vid_name, len(vr)))
sys.stdout.flush()
return True
示例2: test_imwrite
# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imwrite [as 别名]
def test_imwrite(self):
img = mmcv.imread(self.img_path)
out_file = osp.join(tempfile.gettempdir(), 'mmcv_test.jpg')
mmcv.imwrite(img, out_file)
rewrite_img = mmcv.imread(out_file)
os.remove(out_file)
self.assert_img_equal(img, rewrite_img)
ret = mmcv.imwrite(
img, './non_exist_path/mmcv_test.jpg', auto_mkdir=False)
assert ret is False
示例3: save
# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imwrite [as 别名]
def save(image, det_image, pred, name):
batch_size = pred.shape[0]
num_joints = pred.shape[1]
cimage = np.expand_dims(image, axis=0)
cimage = torch.from_numpy(cimage)
pred = torch.from_numpy(pred)
cimage = cimage.permute(0, 3, 1, 2)
pred_vis = torch.ones((batch_size, num_joints, 1))
ndrr = save_batch_image_with_joints(cimage, pred, pred_vis)
mask = ndrr[:, :, 0] == 255
mask = np.expand_dims(mask, axis=2)
out = ndrr * mask + det_image * (1 - mask)
mmcv.imwrite(out, name)
示例4: worker
# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import imwrite [as 别名]
def worker(video_file, index, detection_cfg, skeleton_cfg, skeleon_data_cfg,
device, result_queue):
os.environ["CUDA_VISIBLE_DEVICES"] = str(device)
video_frames = mmcv.VideoReader(video_file)
# load model
detection_model_file = detection_cfg.model_cfg
detection_checkpoint_file = get_mmskeleton_url(
detection_cfg.checkpoint_file)
detection_model = init_detector(detection_model_file,
detection_checkpoint_file,
device='cpu')
skeleton_model_file = skeleton_cfg.model_cfg
skeletion_checkpoint_file = skeleton_cfg.checkpoint_file
skeleton_model = init_twodimestimator(skeleton_model_file,
skeletion_checkpoint_file,
device='cpu')
detection_model = detection_model.cuda()
skeleton_model = skeleton_model.cuda()
for idx in index:
skeleton_result = dict()
image = video_frames[idx]
draw_image = image.copy()
bbox_result = inference_detector(detection_model, image)
person_bbox, labels = VideoDemo.bbox_filter(bbox_result,
detection_cfg.bbox_thre)
if len(person_bbox) > 0:
person, meta = VideoDemo.skeleton_preprocess(
image[:, :, ::-1], person_bbox, skeleon_data_cfg)
preds, maxvals = inference_twodimestimator(skeleton_model,
person.cuda(), meta,
True)
results = VideoDemo.skeleton_postprocess(preds, maxvals, meta)
if skeleon_data_cfg.save_video:
file = os.path.join(skeleon_data_cfg.img_dir,
'{}.png'.format(idx))
mmcv.imshow_det_bboxes(draw_image,
person_bbox,
labels,
detection_model.CLASSES,
score_thr=detection_cfg.bbox_thre,
show=False,
wait_time=0)
save(image, draw_image, results, file)
else:
preds, maxvals = None, None
if skeleon_data_cfg.save_video:
file = os.path.join(skeleon_data_cfg.img_dir,
'{}.png'.format(idx))
mmcv.imwrite(image, file)
skeleton_result['frame_index'] = idx
skeleton_result['position_preds'] = preds
skeleton_result['position_maxvals'] = maxvals
result_queue.put(skeleton_result)