下面的脚本可以满足您的需求。您可以将它的一部分分成函数。
下面的代码不检查错误,特别是生产代码将检查每个
frame*变量是否大于零。
import cv2import numpy as npcap = cv2.VideoCapture('test.mp4')frameCount = int(cap.get(cv2.CAP_PROP_frame_COUNT))frameWidth = int(cap.get(cv2.CAP_PROP_frame_WIDTH))frameHeight = int(cap.get(cv2.CAP_PROP_frame_HEIGHT))buf = np.empty((frameCount, frameHeight, frameWidth, 3), np.dtype('uint8'))fc = 0ret = Truewhile (fc < frameCount and ret): ret, buf[fc] = cap.read() fc += 1cap.release()cv2.namedWindow('frame 10')cv2.imshow('frame 10', buf[9])cv2.waitKey(0)


