gpt4 book ai didi

python - "float"读取帧时对象无法解释为整数

转载 作者:行者123 更新时间:2023-12-01 08:18:59 24 4
gpt4 key购买 nike

我正在尝试使用 imageio API 读取帧。我有一个 reader 作为使用 imageio.get_reader(video_path,"ffmpeg") 收到的对象。我有以下帧阅读器功能

def read_frames(reader, frame_q, use_webcam):
if use_webcam:
time.sleep(15)
frame_cnt = 0
while True:
#if frame_cnt % 5 == 0:
# ret, frame = reader.read()
# cur_img = frame[:,:,::-1]
# frame_q.put(cur_img)
#else:
# ret, frame = reader.read()
ret, frame = reader.read()
cur_img = frame[:,:,::-1] # bgr to rgb from opencv reader
frame_q.put(cur_img)
if frame_q.qsize() > 100:
time.sleep(1)
else:
time.sleep(DELAY/1000.)

#print(cur_img.shape)

else:
#for cur_img in reader: # this is imageio reader, it uses rgb
nframes = reader.get_length() **#getting error here**
# if nframes == float('inf') or nframes ==float('-inf'):
# return float("nan")
# return int(nframes)

for ii in range(nframes):
while frame_q.qsize() > 500: # so that we dont use huge amounts of memory
time.sleep(1)
cur_img = reader.get_next_data()
frame_q.put(cur_img)
#shape = cur_img.shape
#noisy_img = np.uint8(cur_img.astype(np.float) + np.random.randn(*shape) * 20)
#frame_q.put(noisy_img)
if ii % 100 == 0:
print("%i / %i frames in queue" % (ii, nframes))
print("All %i frames in queue" % (nframes))

回溯:

    Traceback (most recent call last):
File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "multiprocess_detect_actions.py", line 67, in read_frames
for ii in range(nframes):
TypeError: 'float' object cannot be interpreted as an integer

我尝试使用代码中注释的float('inf'),但在这种情况下它没有用。我还尝试将浮点值转换为整数,但它显示相同的错误。我将不胜感激您对此的建议。谢谢。

最佳答案

在 imageio 2.5.0 版本的发行说明中,他们提到了对 ffmpeg 插件引入的一些更改:

“ffmpeg 插件的读取器现在始终将 inf 报告为帧数。使用 reader.count_frames() 获取实际数量,或根据元数据中的 fps 和持续时间估计它。”

https://imageio.readthedocs.io/en/stable/releasenotes.html#version-2-5-0-06-02-2019

这应该可以解决你的问题。

关于python - "float"读取帧时对象无法解释为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54800652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com