当前位置:网站首页>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 !
边栏推荐
- [programmer 2 Civil Servant] IV. common problems
- Xinku online | cnopendata shareholder information data of A-share listed companies
- 【PyTorch】最常见的view的作用
- ACNet:用于图像超分的非对称卷积(附实现code)
- Talk about programmers learning English again
- Pads export Gerber file
- 【Unity入门计划】基本概念-预制件 Prefab
- Oracle19 adopts automatic memory management. The AWR report shows that the settings of SGA and PGA are too small?
- 9 best engineering construction project management systems
- Learn no when playing 9 | enterprise knowledge management is so simple because it uses
猜你喜欢

What if Oracle 19C migration encounters large lob tables?

纳米数据足球数据,足球赛事比分,体育数据api,卡塔尔世界杯

list的模拟实现

Paper reading: UNET 3+: a full-scale connected UNET for medical image segmentation

Day by day, month by month | Shenzhen potential technology released the extreme accelerated version of molecular docking engine uni docking

nanodet训练时出现问题:ModuleNotFoundError: No module named ‘nanodet‘的解决方法

First, how about qifujin

QT学习日记20——飞机大战项目
![[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

Problems during nanodet training: modulenotfounderror: no module named 'nanodet' solution
随机推荐
北京内推 | 微软STCA招聘NLP/IR/DL方向研究型实习生(可远程)
10 key points and 5 measures for good project management
【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial
Nailing the latest version, how to clear the login phone number history data
Paper reading: UNET 3+: a full-scale connected UNET for medical image segmentation
Ask the bosses: MySQL CDC stores configuration data, and Kafka has history
用VS Code搞Qt6:编译源代码与基本配置
What if Oracle 19C migration encounters large lob tables?
Design of workflow system
Problems during nanodet training: modulenotfounderror: no module named 'nanodet' solution
for循环与if判断语句的运用
Common cross domain scenarios
大佬秋招面经
leetcode刷题:动态规划06(整数拆分)
[unity introduction program] basic concepts -2d rigid body 2D
diagramscene工程难点分析
Summary of differences between data submission type request payload and form data
9 best engineering construction project management systems
What are runtimecompiler and runtimeonly
华为无线设备配置WPA2-802.1X-AES安全策略