import torch
import numpy as np
import cv2
import os
def enhance(img, net):
img = img / 255.
img = np.transpose(img, (2, 0, 1))
img = np.expand_dims(img, axis=0)
img = torch.from_numpy(img.astype(np.float32))
result = net(img)
result = np.squeeze(result.detach().numpy(), axis=0)
result = np.transpose(result, (1, 2, 0))
result = result * 255
result = result.astype(np.int)
result = result.astype(np.uint8)
return result
def main(video_path, model_path, target_file):
net = torch.load(model_path, map_location='cpu')
video = cv2.VideoCapture(video_path)
fps = video.get(cv2.CAP_PROP_FPS)
width, height = video.get(cv2.CAP_PROP_FRAME_WIDTH), video.get(cv2.CAP_PROP_FRAME_HEIGHT)
size = (int(width * 4), int(height * 4))
videoWrite = cv2.VideoWriter(target_file, cv2.VideoWriter_fourcc('m', 'p', '4', 'v'), fps, size)
success, frame = video.read()
cv2.imwrite('data/onepiece.jpg', frame)
exit()
while success:
print(frame.shape, frame.dtype)
result = enhance(frame, net)
print(result.shape, result.dtype)
videoWrite.write(result)
success, frame = video.read()
video.release()
if __name__ == '__main__':
video_file = 'data/onepiece_demo.mp4'
save_path = 'onepiece_demo.mp4'
pt_path = 'RealESRGAN_x4plus.pt'
main(video_file, pt_path, save_path)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
pytorch版realESRGAN模型权重和推理代码,已合并模型结构和权重参数,可以直接加载使用。4倍超分模型,推理代码包含图像推理和视频推理样例,方便快速体验图像超分效果或二次开发。ESRGAN是一种图像超分辨率算法,用于增加图像分辨率并生成更多图像细节,与传统的图像缩放算法不同的是,超分算法在放大图像的同时根据原图纹理生成更多细节,确保图像在放大后仍然有清晰的纹理细节。模型可用于修复老照片,解决胶卷相机拍摄照片因年代久远造成图像模糊、损坏等问题;缓解部分场景对焦不清晰或相机焦距不足导致照片模糊问题; 降低图像噪点,提升画质。
资源推荐
资源详情
资源评论
收起资源包目录
realESRGAN模型权重及推理代码.zip (3个子文件)
realESRGAN模型权重及推理代码
infer_video.py 1KB
infer_img.py 1KB
RealESRGAN_x4plus.pt 64.01MB
共 3 条
- 1
资源评论
TheMatrixs
- 粉丝: 7183
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功