OpenCVを使用してAIビデオ超解像度を実現

import cv2
from cv2 import dnn_superres

trained_model_path = r'F:/SuperResolution/TF-ESPCN/export/ESPCN_x2.pb'  # 训练好的ESPCN_x2模型的存储路径

sr = dnn_superres.DnnSuperResImpl_create()  # 实例化对象
sr.readModel(trained_model_path)  # 读取ESPCN_x2模型
sr.setModel('espcn', 2)  # 设置超分图像放大比例(与训练模型的超分倍数一致),放大图像

video = cv2.VideoCapture(r'F:/SuperResolution/test_video_720p.mp4')  # 读取720p视频

save_path = r'F:/SuperResolution/result_video_2k.mp4'
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
fps = video.get(cv2.CAP_PROP_FPS)
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))

out = cv2.VideoWriter(save_path, fourcc, fps, (2*width, 2*height))

while True:
    ret, frame = video.read()

    if not ret:
        break

    result = sr.upsample(frame)  # 上采样,超分

    out.write(result)

video.release()
out.release()
cv2.destroyAllWindows()

おすすめ

転載: blog.csdn.net/weixin_48158964/article/details/131632542