当前位置:   article > 正文

使用OpenCV实现AI视频超分辨率_ffmpeg opencv 超分分辨率

ffmpeg opencv 超分分辨率
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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/502096
推荐阅读
相关标签
  

闽ICP备14008679号