如何将视频转换为多个 numpy 数组或单个数组,以便用于机器学习。只能找到处理图像的方法。
(高度, 宽度, 通道数)
。如果图片是RGB格式,则通道值为3,如果是灰度图像,则为1。(帧数, 高度, 宽度, 通道数)
。(1800, 256, 256, 3)
,其中1800是视频中的帧数:30(fps)*60(秒)。# Import the video and cut it into frames.
vid = cv2.VideoCapture('path/to/video/file')
frames = []
check = True
i = 0
while check:
check, arr = vid.read()
if not i % 20: # This line is if you want to subsample your video
# (i.e. keep one frame every 20)
frames.append(arr)
i += 1
frames = np.array(frames) # convert list of frames to numpy array