python实现视频读取和转化图片

yipeiwu_com6年前Python基础

1)视频读取

import cv2

cap = cv2.VideoCapture('E:\\Video\\20000105_224116.dav') #地址

while(True):

  ret,frame = cap.read()

  if(ret):

    # gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

    cv2.imshow('input',frame)

  else:

    break

  if cv2.waitKey(1)==27:

    break

cap.release()

cv2.destroyAllWindows()

2)转化图片

# -*- coding: utf-8 -*-
"""
Created on Mon Nov 5 15:21:15 2018

@author: chenjin10
"""

import cv2
vc = cv2.VideoCapture('E:\\Video\\binggan.dav')
c=0
rval=vc.isOpened()

while rval:
  c = c + 1
  rval, frame = vc.read()
  if rval:
    cv2.imwrite('E:\\Video\\binggan\\'+'camera1_binggan'+str(c) + '.jpg', frame) #命名方式
    print(c)
  else:
    break
vc.release()

以上这篇python实现视频读取和转化图片就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python编程之序列操作实例详解

Python编程之序列操作实例详解

本文实例讲述了Python编程之序列操作。分享给大家供大家参考,具体如下: #coding=utf8 ''''' 序列类型有着相同的访问模式:它的每一个元素可以通过指定一个偏移量的方...

python实现百度语音识别api

本文实例为大家分享了python实现百度语音识别的具体代码,供大家参考,具体内容如下 详细百度语音识别api文档 先下载python用SDK,可以用python setup.py ins...

Python实现多级目录压缩与解压文件的方法

本文实例讲述了Python实现多级目录压缩与解压文件的方法。分享给大家供大家参考,具体如下: 咱向来就是拿来主意,也发个东西供同行“拿来”使用吧 咱信奉的就是少量的代码完成大量的工作,虽...

Python datetime包函数简单介绍

Python datetime包函数简单介绍

一、datetime包(上接连载7内容) 1.函数:datetime (1)用法:输入一个日期,来返回一个datetime类​ (2)格式:datetime.datetime...

Python 实现异步调用函数的示例讲解

async_call.py #coding:utf-8 from threading import Thread def async_call(fn): def wrapper...