找到一个有趣的程序码,改了一下,可截取Video画面,存成一张张图片。
进行中想要中断执行,可按 ESC 中断。
''' VideoToFrames.py
截取Video画面
'''
import cv2, keyboard, os, ctypes
# 要播的影片请自设
vidcap = cv2.VideoCapture('YourVideo.mp4')
#------------------
def getFrame(sec):
vidcap.set(cv2.CAP_PROP_POS_MSEC,sec*1000)
hasFrames,image = vidcap.read()
if hasFrames:
cv2.imwrite("media\\scrn"+str(count)+".jpg", image)
return hasFrames
#--- 主流程 --------
prompt = '即将开始Video画面截取,如进行中愈中断,可按Esc...'
ctypes.windll.user32.MessageBoxW(0,prompt, 'Video To Frames', 1)
if not os.path.isdir('media'):
os.mkdir('media')
#--- 每隔0.5秒截取一次画面-----
sec = 0
frameRate = 0.5
count = 1
success = getFrame(sec)
#--- 执行回圈,可按Esc中断
while success:
try:
count += 1
sec = sec + frameRate
sec = round(sec, 2)
print(f'sec: {sec}')
success = getFrame(sec)
if keyboard.is_pressed('Esc'):
print('quit')
success = False
break
except:
pass
<<: How to set video ringtone in mobile?
The Visitor design pattern represents an operation...
前言 为了能够更全面的去理解k8s的原理 今天主要从k8s 几个基础的元件开始介绍 Node &am...
github: https://github.com/wilsonsujames/webcam/tr...
Producer是讯息发送方, 他会对nsqd发送讯息, nsqd支援TCP(port:4150) ...
前言 今天要来实作 Run automated tasks with cron jobs 这个 Ta...