当前位置:网站首页>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 !
边栏推荐
- Lidar construction map (overlay grid construction map)
- Kubernetes monitoring component metrics server deployment
- "Game illustrated book": a memoir dedicated to game players
- 【程序员2公务员】三、资源搜集
- 2-6.自动化采集
- 使用CycleGAN训练自己制作的数据集,通俗教程,快速上手
- 【程序员2公务员】关于体制调研的一些常见问题总结
- cesium简介
- diagramscene工程难点分析
- About gbase automatically closing the connection
猜你喜欢

JS cannot get content disposition in headers

How to use network installation to deploy multiple virtual servers in KVM environment

Oracle19 adopts automatic memory management. The AWR report shows that the settings of SGA and PGA are too small?

Nano data, football data, football match scores, sports data API, Qatar world cup

Lidar construction map (overlay grid construction map)

QT learning diary 20 - aircraft war project

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

Alibaba cloud image address & Netease cloud image

Completely replace the redis+ database architecture, and JD 618 is stable!

MATLAB自编程系列(1)---角分布函数
随机推荐
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
Configuring WAPI certificate security policy for Huawei wireless devices
【程序员2公务员】三、资源搜集
Polling, interrupt, DMA and channel
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
Analysis of common classes of Servlet
Practical skills -- some solutions to small problems
Leetcode118. Yanghui triangle
Leetcode skimming: dynamic programming 06 (integer splitting)
The idea of the regular crawler of the scratch
js无法获取headers中Content-Disposition
[unity entry plan] interface Introduction (1) -scene view
分布式爬虫中的增量爬虫
【程序员2公务员】关于体制调研的一些常见问题总结
Use cyclegan to train self-made data sets, popular tutorials, and get started quickly
The application of for loop and if judgment statement
Cluster chat server: summary of project problems
Completely replace the redis+ database architecture, and JD 618 is stable!
[ES6] function parameters, symbol data types, iterators and generators