【发布时间】:2021-05-12 11:00:38
【问题描述】:
我正在阅读视频文件并尝试将它们保存在 train 文件夹中,但我看不到任何输出。我不确定这里有什么问题?
测试文件夹中未生成帧,否则会引发任何错误。谁能告诉我怎么了?
我正在使用 collab 来运行此代码。
Inside this **test['video_name']**
0 ../content/drive/MyDrive/Second_model/data/noncrash/event_frame_80.mp4
1 ../content/drive/MyDrive/Second_model/data/noncrash/event_frame_98.mp4
2 ../content/drive/MyDrive/Second_model/data/crash/event_frame_117.mp4
3 ../content/drive/MyDrive/Second_model/data/noncrash/event_frame_65.mp4
存储训练视频中的帧
for i in tqdm(range(test.shape[0])):
count = 0
videoFile = test['video_name'][i]
cap = cv2.VideoCapture(' '+videoFile.split(' ')[0].split('/')[6]) # capturing the video from the given path
frameRate = cap.get(10) #frame rate
x=1
while(cap.isOpened()):
frameId = cap.get(1) #current frame number
ret, frame = cap.read()
if (ret != True):
break
if (frameId % math.floor(frameRate) == 0):
# storing the frames in a new folder named train_1
filename ='/content/drive/MyDrive/Second_model/test_1' + videoFile.split('/')[6].split(' ')[0] +"_frame%d.jpg" % count;count+=1
cv2.imwrite(filename, frame)
cap.release()
输出:
100%|██████████| 4/4 [00:00<00:00, 2412.78it/s]
【问题讨论】:
标签: python-3.x google-colaboratory opencv3.0 opencv-python