博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python视频批量按照文件名创建文件夹然后保存为图片
阅读量:4303 次
发布时间:2019-05-27

本文共 1401 字,大约阅读时间需要 4 分钟。

# -*- coding: utf-8 -*-   import os import cv2import csvimport numpy as npdef GetImgNameByEveryDir(file_dir,videoProperty):      FileNameWithPath = []     FileName         = []    FileDir          = []    # videoProperty=['.png','jpg','bmp']    for root, dirs, files in os.walk(file_dir):          for file in files:              if os.path.splitext(file)[1] in videoProperty:                  FileNameWithPath.append(os.path.join(root, file))  # 保存图片路径                FileName.append(file)                              # 保存图片名称                FileDir.append(root[len(file_dir):])               # 保存图片所在文件夹    return FileName,FileNameWithPath,FileDir# 以视频文件名创建文件夹,然后保存图像到对应文件夹def AVI_To_Img_And_save(video_file,save_dir):	if os.path.exists(save_dir)==False:		os.makedirs(save_dir)	cap = cv2.VideoCapture(video_file)	rval = cap.isOpened()	framenum=0	while rval:		rval, frame  = cap.read()		if rval==False:			continue		if framenum%25!=0:			framenum+=1			continue		Img_savename = save_dir + '/' + 'image_' + '%07d'%framenum +'.jpg'		if rval:			if os.path.exists(Img_savename)==False:				cv2.imwrite(Img_savename, frame,[int(cv2.IMWRITE_JPEG_QUALITY), 100]) 		else:			break		framenum+=1	cap.release()videoDir = './videoProperty = ['.mp4]FileName,FileNameWithPath,FileDir = GetImgNameByEveryDir(videoDir,videoProperty)for k in range(len(FileName)):	AVI_To_Img_And_save(FileNameWithPath[k],FileName[k][:-4])

 

转载地址:http://puhws.baihongyu.com/

你可能感兴趣的文章
mysql查询某一个字段是否包含中文字符
查看>>
Java中equals和==的区别
查看>>
JVM内存管理及GC机制
查看>>
Java:按值传递还是按引用传递详细解说
查看>>
Java中Synchronized的用法
查看>>
阻塞队列
查看>>
linux的基础知识
查看>>
接口技术原理
查看>>
五大串口的基本原理
查看>>
PCB设计技巧与注意事项
查看>>
linux进程之间通讯常用信号
查看>>
main函数带参数
查看>>
PCB布线技巧
查看>>
关于PCB设计中过孔能否打在焊盘上的两种观点
查看>>
PCB反推理念
查看>>
京东技术架构(一)构建亿级前端读服务
查看>>
git 提示:error: unable to rewind rpc post data - try increasing http.postBuffer
查看>>
php 解决json_encode中文UNICODE转码问题
查看>>
LNMP 安装 thinkcmf提示404not found
查看>>
PHP empty、isset、innull的区别
查看>>