本篇博客实现通过python中的cv2模块读取显示视频,并通过键盘按键保存视频帧。
import cv2 import string, random def id_generator(size=6, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) cap = cv2.VideoCapture("Minions_banana.mp4") while cap.isOpened(): ret, frame = cap.read() print('frame.shape:', frame.shape) cv2.imshow('frame', frame) key = cv2.waitKey(delay=1) if key == ord('q'): break elif key == ord('s'): cv2.imwrite(id_generator() + '.jpg', frame) cap.release() cv2.destroyAllWindows()
欢迎关注我的公众号:
编程技术与生活(ID:hw_cchang)