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去重,一个由dict组成的list的去重示例

背景:有一个list,里面的每一个元素都是dict,根据某一个key进行去重,在这里,key代表question #!/usr/bin/env python # -*- coding...

Python 仅获取响应头, 不获取实体的实例

Python 仅获取响应头, 不获取实体的实例

Python Just get Response Headers, not get content. 1. Use HEAD method >>> import r...

python获取当前文件路径以及父文件路径的方法

python获取当前文件路径以及父文件路径的方法

#当前文件的路径 pwd = os.getcwd() #当前文件的父路径 father_path=os.path.abspath(os.path.dirname(pwd)+os.p...

python的set处理二维数组转一维数组的方法示例

for splitValue in set(dataset[:, featureIndex].tolist()): 首先set是一个无序,无重复的数据结构,所以很多时候使用它来进行去重;...

Python深入学习之装饰器

装饰器(decorator)是一种高级Python语法。装饰器可以对一个函数、方法或者类进行加工。在Python中,我们有多种方法对函数和类进行加工,比如在Python闭包中,我们见到函...