• 图片生成视频


    opencv-python · PyPI  https://pypi.org/project/opencv-python/

    nstallation and Usage

    1. If you have previous/other version of OpenCV installed (e.g. cv2 module in the root of Python’s site-packages), remove it before installation to avoid conflicts.
    • To further avoid conflicts and to make development easier, Python’s virtual environments are highly recommended for development purposes.
    1. If you have an existing opencv-contrib-python installation, run pip uninstall opencv-contrib-python
    2. Install this package:

    pip install opencv-python

    1. Import the package:

    import cv2

    注意 路径中英文

    '''
    python+opencv视频图像相互转换 - CSDN博客 https://blog.csdn.net/m0_37733057/article/details/79023693
    链接:https://www.zhihu.com/question/49558804/answer/343058915
    '''
    
    import cv2
    import glob
    import os, sys
    import ffmpeg
    
    os_sep = os.sep
    this_file_abspath = os.path.abspath(__file__)
    this_file_dirname, this_file_name = os.path.dirname(this_file_abspath), os.path.abspath(__file__).split(os_sep)[
        -1]
    base_dir = os.path.dirname(this_file_dirname)
    
    fps = 120  # 保存视频的FPS,可以适当调整
    fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')  # opencv3.0
    import time
    
    f_v = '{}{}'.format(int(time.time()), 'saveVideo.avi')
    imgs = glob.glob('C:\Users\sas\PycharmProjects\mypygame\mypng\*.jpg')
    for imgname in imgs:
        print(imgname)
        img = cv2.imread(imgname)
        img_size = (img.shape[1], img.shape[0])
        videoWriter = cv2.VideoWriter(f_v, fourcc, fps, img_size)
        frame = cv2.imread(imgname)
        videoWriter.write(frame)
    videoWriter.release()
    

      

    '''
    python+opencv视频图像相互转换 - CSDN博客 https://blog.csdn.net/m0_37733057/article/details/79023693
    链接:https://www.zhihu.com/question/49558804/answer/343058915
    '''
    
    import cv2
    import glob
    import os, sys
    import ffmpeg
    
    os_sep = os.sep
    this_file_abspath = os.path.abspath(__file__)
    this_file_dirname, this_file_name = os.path.dirname(this_file_abspath), os.path.abspath(__file__).split(os_sep)[
        -1]
    base_dir = os.path.dirname(this_file_dirname)
    
    fps = 100  # 保存视频的FPS,可以适当调整
    fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')  # opencv3.0
    import time
    
    f_v = '{}{}'.format(int(time.time()), 'saveVideo.avi')
    
    imgs = glob.glob('C:\Users\sas\PycharmProjects\mypygame\mypng\*.jpg')
    
    img = cv2.imread(imgs[0])
    img_size = (img.shape[1], img.shape[0])
    videoWriter = cv2.VideoWriter(f_v, fourcc, fps, img_size)
    
    for imgname in imgs:
        myinterval = 2
        this_time = time.time()
        while time.time() - this_time < 2:
            print(imgname)
            img = cv2.imread(imgname)
            frame = cv2.imread(imgname)
            videoWriter.write(frame)
    
    videoWriter.release()
    

      

  • 相关阅读:
    Vue --》this.$set()的神奇用法
    vue --》路由query 编程式导航传值与监听
    elementUI -->实现简单的购物车
    vue--》如何使用wacth监听对象的属性变化?
    laravel redis 删除指定前缀的 key
    php in_array 的一个坑
    laravel/lumen Command 的构造函数需要注意的地方
    git 合并连续的几个 commits
    盘点 php 里面那些冷门又实用的小技巧
    mockery expectation 覆盖
  • 原文地址:https://www.cnblogs.com/rsapaper/p/8744338.html
Copyright © 2020-2023  润新知