提交 0e618588 编写于 作者: C cjt222 提交者: SunGaofeng

fix error while loading cv2.VideoCapture (#2344)

* test=develop fix error while loading cv2.VideoCapture

* test=develop
fix bug of index out of range in SampleFrames

* fix bug
上级 020d7573
......@@ -14,6 +14,7 @@
import os
import sys
import cv2
import math
import random
import functools
......@@ -386,7 +387,6 @@ def video_loader(frames, nsample, seglen, mode):
def mp4_loader(filepath, nsample, seglen, mode):
cap = cv2.VideoCapture(filepath)
videolen = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
average_dur = int(videolen / nsample)
sampledFrames = []
for i in range(videolen):
ret, frame = cap.read()
......@@ -395,7 +395,7 @@ def mp4_loader(filepath, nsample, seglen, mode):
continue
img = frame[:, :, ::-1]
sampledFrames.append(img)
average_dur = int(len(sampledFrames) / nsample)
imgs = []
for i in range(nsample):
idx = 0
......@@ -417,7 +417,7 @@ def mp4_loader(filepath, nsample, seglen, mode):
idx = i
for jj in range(idx, idx + seglen):
imgbuf = sampledFrames[int(jj % videolen)]
imgbuf = sampledFrames[int(jj % len(sampledFrames))]
img = Image.fromarray(imgbuf, mode='RGB')
imgs.append(img)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册