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脚本筛选出两个文件中重复的行数,供大家参考,具体内容如下 ''' 查找A文件中,与B文件中内容不重复的内容 ''' #!usr/bin/python...

python DataFrame获取行数、列数、索引及第几行第几列的值方法

1、df=DataFrame([{‘A':'11','B':'12'},{‘A':'111','B':'121'},{‘A':'1111','B':'1211'}]) print d...

Python2和Python3.6环境解决共存问题

Linux下安装Python3.6和第三方库 /post/150478.htm 如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依...

Python 字符串大小写转换的简单实例

①所有字母都转换为大写 # -*- coding:utf-8 -*- if __name__ == "__main__":     a = 'hello,...

Tensorflow 实现分批量读取数据

之前的博客里使用tf读取数据都是每次fetch一条记录,实际上大部分时候需要fetch到一个batch的小批量数据,在tf中这一操作的明显变化就是tensor的rank发生了变化,我目前...