Python+OpenCV读取视频常见坑

Python 专栏收录该内容
4 篇文章 0 订阅
# coding=utf-8

import os
from os import path
import cv2

VIDEO_PATH = "video"

for game_name in os.listdir(VIDEO_PATH):
    for video_name in os.listdir(path.join(VIDEO_PATH, game_name)):
        video_path = path.join(VIDEO_PATH, game_name, video_name)
        video_instance = cv2.VideoCapture(video_path)
        if not video_instance.isOpened():
            print(video_path, "读取失败")
        else:
            i_total_frame_num = video_instance.get(cv2.CAP_PROP_FRAME_COUNT)
            i_frame_index = 0
            while i_frame_index < i_total_frame_num:
                #set need capture frame index
                video_instance.set(cv2.CAP_PROP_POS_FRAMES, i_frame_index)
                #get current index frame
                b_is_success, current_frame = video_instance.read()
                assert b_is_success, "读取视频异常!"
                #get the frame width,heigth,and channel num
                (i_frame_height, i_frame_width, i_channel_num) = current_frame.shape

                for i_width in range(0, i_frame_width):
                    for i_height in range(0, i_frame_height):
                        #read color pixel by index [height, width]
                        current_color_list = current_frame[i_height, i_width]
                        print(current_color_list)

 

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 自定义皮肤 设计师:听听那冷雨~ 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值