从视频中每隔固定帧进行提取图片
import cv2 as cv
def video_demo():
"""
打开视频
"""
capture = cv.VideoCapture("./pic/video/double_one.MP4") #修改为自己路径
flag = 1
while True:
ret, frame = capture.read()
if ret is True:
flag = flag + 1
if flag % 60 == 0 and ret is True:
cv.imshow("frame", frame)
if ret is True:
cv.imwrite("./pic/double_one_frame/20200918" + str(flag) + ".png", frame) # 修改为自己路径
c = cv.waitKey(50)
if c == 27:
break
cv.namedWindow("frame", 0)
video_demo()
cv.destroyAllWindows()