当前位置:   article > 正文

Python使用opencv获取视频每帧的图片_python opencv获取视频每一帧的图片

python opencv获取视频每一帧的图片

上代码!

import os

import cv2

cap = cv2.VideoCapture('视屏路径')

while (1):
    ret, frame = cap.read()
    if ret == False:
        break
    frame_index = 0
    frame_count = 0
    if cap.isOpened():
        success = True
    else:
        success = False
    while (success):
        success, frame = cap.read()
        print("---> 正在读取第%d帧:" % frame_index, success)
        if frame_index % 1 == 0 and success:
            resize_frame = cv2.resize(frame, (1920, 1080), interpolation=cv2.INTER_AREA)
            cv2.imwrite('./save_path' + "%d.jpg" % frame_count, resize_frame)
            frame_count += 1
        frame_index += 1
    cap.release()
  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/649173
推荐阅读
相关标签
  

闽ICP备14008679号