将视频转换成图片帧
def save_image(image, addr, num):
- image:要保存的图片名字
- addr:图片地址与相片名字的前部分
- num:相片,名字的后缀 int 类型
New script - 51cto.com.user.js:25 # 导入所需要的库
import cv2
# 定义保存图片函数
def save_image(image, addr, num):
address = addr + str(num) + '.jpg'
cv2.imwrite(address, image)
# 读取视频文件
videoCapture = cv2.VideoCapture("20210713100825.mp4")
#读帧
success, frame = videoCapture.read()
i = 0
timeF = 12
j = 0
while success:
i = i + 1
if (i % timeF == 0):
j = j + 1
save_image(frame, 'output', j)
print('save image:', i)
success, frame = videoCapture.read()