栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python npy转png png转mp4

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python npy转png png转mp4

npy转png png转mp4

def npy2jpg(dir, dest_dir):
    if os.path.exists(dir) == False:
        os.makedirs(dir)
    if os.path.exists(dest_dir) == False:
        os.makedirs(dest_dir)
    file = dir + 'npy.npy'
    arrList = np.load(file)
    arrList = arrList * 255
    for row in arrList:  #注意本例是多图 5行40列 480 560
        for arr in row:
            arr = np.reshape(arr, (1, 480, 560))
            r = Image.fromarray(arr[0]).convert("L")
            r.save(dest_dir + str(count) + ".png")

def png2video():
    fsp = 5
    fourcc = cv2.VideoWriter_fourcc(*'avc1')
    video_path = "D:/train.mp4"  # 修改视频存放路径
    video_out = cv2.VideoWriter(video_path, fourcc, fsp, (560, 480)) 
    # 路径不能含中文
    img_path = "D:/"  # 图片存放地址
    for i in range(1218, 4584, 1):  # 这里需设置图片数量
        filename = img_path+"radar_3" + str(i) + ".png"
        if os.path.exists(filename):
            frame = cv2.imread(filename)  # 改 ⑤
            video_out.write(frame)
            print(filename + "已录入")
    video_out.release()


if __name__ == '__main__':
    dir = "D:/"  # npy文件路径
    dest_dir = "D:/" # 图片存储路径
    npy2jpg(dir, dest_dir)
    png2video()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/953513.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号