opencv 视频捕获的 tqdm 进度条超过 100%

tqdm progressbar for opencv videocapture going beyong 100%

我正在 python 中使用 Opencv 处理视频并使用 tqdm 显示进度条。但是,进度超过 100%。不太确定为什么会这样。

我是 opencv 的新手,所以我可能传递了错误的参数来执行我想要的操作。

我尝试了几种方法。列出来。

cam = cv2.VideoCapture("path")
fps = cam.get(cv2.CAP_PROP_FPS)
total_frame_count = int(cam.get(cv2.CAP_PROP_FRAME_COUNT))
length = total_frame_count/fps

pbar = tqdm(total = total_frame_count)
count = 0
while(True):
    ret,frame = cam.read()
    pbar.update(count)
    # process(frame)
    count += fps*5 
    cam.set(cv2.CAP_PROP_POS_FRAMES, count)
    

我有一个叫做 count 的计数器,基本上是跳过视频 5 秒。

当使用带有手动更新的 tqdm 时,您指定递增的步骤,而不是当前所在的位置。

来自manual

with tqdm(total=100) as pbar:
    for i in range(10):
        sleep(0.1)
        pbar.update(10)

所以你应该做的就是 pbar.update(fps*5).