当前位置:网站首页>When deep learning makes data sets, it specifies how many frames to extract an image from the long video to the specified file path
When deep learning makes data sets, it specifies how many frames to extract an image from the long video to the specified file path
2022-07-25 07:34:00 【Saga】
Doing deep learning collection Data sets when , Record video first , Later, the video frames are extracted as data sets , It is a good way to prepare data sets efficiently , The code for saving a specified number of frames in a video frame to the specified file path is shown below :
# Export the video as several frames of pictures
DATA_DIR = "Video/1.avi" # Video storage path
SAVE_DIR = "Images/photo" # Save path of frame pictures
GAP = 30 # Export a picture every how many frames
import cv2 # OpenCV library
import os
def getphoto(video_in, video_save):
number = 0
cap = cv2.VideoCapture(video_in) # Open video file
n_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) # The number of frames in the video
fps = cap.get(cv2.CAP_PROP_FPS) # The frame rate of the video
dur = n_frames / fps # Time of video
num_frame = 0
judge = cap.isOpened()
while judge:
flag, frame = cap.read() # flag Is the read state ,frame The next frame
if cv2.waitKey(0) == 27:
break
if flag:
num_frame += 1
if num_frame % GAP == 0:
print(" Saving the %d A picture " % number)
cv2.imwrite(video_save + '/' + str(number) + '.jpg', frame) # cv2.imwrite(‘ route ’ + ‘ name ’ + ‘ suffix ’, Frames to save )
number += 1
else:
break
print(" Video duration : %d second " % dur)
print(" Total frames of video : %d The number of saved frames is : %d" % (n_frames, number))
print(" frame per second (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 # Video path
main_1(paht)
The above is how to quickly extract the number of frames between videos and save a frame to the specified file path , I hope I can help you , thank you !
边栏推荐
- QT6 with vs Code: compiling source code and basic configuration
- Oracle19采用自动内存管理,AWR报告显示SGA、PGA设置的过小了?
- [dynamic programming] - Knapsack model
- 集群聊天服务器:项目问题汇总
- 【论文笔记】Progressive Layered Extraction (PLE): A Novel Multi-Task Learning (MTL) Model for Personalized
- 【Unity入门计划】基本概念-2D刚体Rigidbody 2D
- GBase 8a中关于--skip-networking 问题
- Lidar construction map (overlay grid construction map)
- 【论文笔记】EFFICIENT CNN ARCHITECTURE DESIGN GUIDED BY VISUALIZATION
- 3. Promise
猜你喜欢

Oracle19采用自动内存管理,AWR报告显示SGA、PGA设置的过小了?

如何在KVM环境中使用网络安装部署多台虚拟服务器

Security compliance, non-stop discounts! High quality travel service, "enjoy the road" for you

Million level element optimization: real-time vector tile service based on PG and PostGIS

QT学习日记20——飞机大战项目

用VS Code搞Qt6:编译源代码与基本配置

Bingbing's learning notes: classes and objects (Part 1)
![[software testing] package resume from these points to improve the pass rate](/img/69/b27255c303150430df467ff3b5cd08.gif)
[software testing] package resume from these points to improve the pass rate

QT6 with vs Code: compiling source code and basic configuration

Line generation (matrix ')
随机推荐
NLP hotspots from ACL 2022 onsite experience
【Unity入门计划】界面介绍(2)-Games视图&Hierarchy&Project&Inspector
从ACL 2022 Onsite经历看NLP热点
Introduction to cesium
Alibaba cloud image address & Netease cloud image
[notes] search rotation sort array
Million level element optimization: real-time vector tile service based on PG and PostGIS
DJI内推码(一码一用,限时内推)
12 combination methods and risk interpretation of database architecture optimization (books available)
3. Promise
Configuring WAPI certificate security policy for Huawei wireless devices
List derivation
Incremental crawler in distributed crawler
Paddlepaddle 34 adjust the layer structure and forward process of the model (realize the addition, deletion, modification and forward modification of the layer)
如何在KVM环境中使用网络安装部署多台虚拟服务器
Xinku online | cnopendata shareholder information data of A-share listed companies
[programmer 2 Civil Servant] summary of some common problems about system research
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
About --skip networking in gbase 8A
[programmer 2 Civil Servant] I. Basic Knowledge