【发布时间】:2020-07-22 19:05:33
【问题描述】:
我有一个 python 生成器,它从视频中输出 cv2 图像(帧),并使用concurrent.futures.ThreadPoolExecutor 对其进行处理。我看到 tqdm 挂起,直到发电机用完为止。但是,如果我从 gen_frames_dummy 提供执行程序,则 tqdm 会随着每个任务的完成而更新。
任何帮助将不胜感激。
def gen_frames(s):
for frame_num in frames_2_get:
# skip to frame in video
s.set(cv2.CAP_PROP_POS_FRAMES, frame_num-1)
res, frame = s.read()
if res:
yield frame
def gen_frames_dummy(s):
for frame_num in frames_2_get:
yield np.zeros((16,16,3))
def frame_op(f):
# process the frame
pass
with ThreadPoolExecutor() as executor:
frames_g = gen_frames(vid_capture)
list(tqdm(executor.map(frame_op, frames_g), total=len(frames2get))
【问题讨论】:
标签: python python-3.x multithreading opencv tqdm