当前位置:网站首页>深度学习制作数据集时,从长视频中指定每隔多少帧提取一张图像到指定文件路径的方法
深度学习制作数据集时,从长视频中指定每隔多少帧提取一张图像到指定文件路径的方法
2022-07-25 07:24:00 【佐咖】
在做深度学习采集数据集时,先录制视频,后期将视频帧提取出来作为数据集,是一种高效准备数据集的好方法,关于将视频帧中指定多少帧保存一帧到指定文件路径的代码见下:
# 将视频导出为若干帧图片
DATA_DIR = "Video/1.avi" # 视频存放路径
SAVE_DIR = "Images/photo" # 帧图片保存路径
GAP = 30 # 每隔多少帧导出一张图片
import cv2 # OpenCV库
import os
def getphoto(video_in, video_save):
number = 0
cap = cv2.VideoCapture(video_in) # 打开视频文件
n_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) # 视频的帧数
fps = cap.get(cv2.CAP_PROP_FPS) # 视频的帧率
dur = n_frames / fps # 视频的时间
num_frame = 0
judge = cap.isOpened()
while judge:
flag, frame = cap.read() # flag是读取状态,frame下一帧
if cv2.waitKey(0) == 27:
break
if flag:
num_frame += 1
if num_frame % GAP == 0:
print("正在保存第%d张照片" % number)
cv2.imwrite(video_save + '/' + str(number) + '.jpg', frame) # cv2.imwrite(‘路径’ + ‘名字’ + ‘后缀’, 要存的帧)
number += 1
else:
break
print("视频时长: %d 秒" % dur)
print("视频共有帧数: %d 保存帧数为: %d" % (n_frames, number))
print("每秒的帧数(FPS): %.1lf" % fps)
def main_1(path):
video_in = path
video_save = SAVE_DIR
getphoto(video_in, video_save)
if __name__ == '__main__':
paht = DATA_DIR # 视频路径
main_1(paht)
以上就是快速提取视频中间隔多少帧保存一帧到指定文件路径的方法,希望能帮助到你,谢谢!
边栏推荐
- 分布式爬虫中的增量爬虫
- RPC通信原理与项目技术选型
- Leave the factory and sell insurance
- 如何在KVM环境中使用网络安装部署多台虚拟服务器
- Configuring WAPI certificate security policy for Huawei wireless devices
- 批量导入数据,一直提示 “失败原因:SQL解析失败:解析文件失败::null”怎么回事?
- 第一启富金怎么样
- When importing data in batches, you always prompt "failure reason: SQL parsing failure: parsing file failure:: null". What's the matter?
- 微信小程序switchTab传参以及接收参数
- Purpose of SQL square brackets
猜你喜欢

RPC communication principle and project technology selection

Nailing the latest version, how to clear the login phone number history data

Vscode saves setting configuration parameters to the difference between users and workspaces

Devops has been practiced for many years. What is the most painful thing?

Box horse "waist cut", blame Hou Yi for talking too much?

New tea, start "fighting in groups"

Leave the factory and sell insurance

First, how about qifujin

Openatom xuprechain open source biweekly report | 2022.7.11-2022.7.22
![[computer explanation] NVIDIA released geforce RTX Super Series graphics cards, and the benefits of game players are coming!](/img/11/24f92b4362026ec2c01492d195560b.png)
[computer explanation] NVIDIA released geforce RTX Super Series graphics cards, and the benefits of game players are coming!
随机推荐
LeetCode118. 杨辉三角
DJI内推码(一码一用,限时内推)
Cluster chat server: summary of project problems
【刷题笔记】搜索插入位置(二分法的活用)
When importing data in batches, you always prompt "failure reason: SQL parsing failure: parsing file failure:: null". What's the matter?
论文阅读:UNET 3+: A FULL-SCALE CONNECTED UNET FOR MEDICAL IMAGE SEGMENTATION
js无法获取headers中Content-Disposition
The application of for loop and if judgment statement
Luo min's backwater battle in qudian
Security compliance, non-stop discounts! High quality travel service, "enjoy the road" for you
[pytorch] the most common function of view
Price reduction, game, bitterness, etc., vc/pe rushed to queue up and quit in 2022
list的模拟实现
Matlab self programming series (1) -- angular distribution function
Robot Framework移动端自动化测试----01环境安装
First, how about qifujin
【PyTorch】最常见的view的作用
Devops has been practiced for many years. What is the most painful thing?
Elasticserach里delete_by_query的机制是什么?
NLP hotspots from ACL 2022 onsite experience