前言:
当前我们对“python抓取动画脚本”大致比较着重,同学们都需要分析一些“python抓取动画脚本”的相关资讯。那么小编也在网络上网罗了一些关于“python抓取动画脚本””的相关内容,希望看官们能喜欢,大家一起来学习一下吧!最近沉迷于Stable Diffusion,以前也没真正系统学过Python,不过现在有了Chatgpt问题迎刃而解感谢Ai带来的便利,有爱自取。
import cv2
from PIL import Image
import numpy as np
cap = cv2.VideoCapture("D:/00/热门音乐.mp4") # 获取视频对象
isOpened = cap.isOpened # 判断是否打开
# 视频信息获取
fps = cap.get(cv2.CAP_PROP_FPS)
imageNum = 0
sum=0
timef=30
while (isOpened):
sum+=1
(frameState, frame) = cap.read() # 记录每帧及获取状态
if frameState == True and (sum % timef==0):
# 格式转变,BGRtoRGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# 转变成Image
frame = Image.fromarray(np.uint8(frame))
frame = np.array(frame)
# RGBtoBGR满足opencv显示格式
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
imageNum = imageNum + 1
fileName = 'D:/005/in/' + str(imageNum) + '.jpg' # 存储路径
cv2.imwrite(fileName, frame, [cv2.IMWRITE_JPEG_QUALITY, 100])
print(fileName + " successfully write in") # 输出存储状态
elif frameState == False:
break
print('finish!')
cap.release()
标签: #python抓取动画脚本