Home > Software engineering >  tqdm progressbar for opencv videocapture going beyong 100%
tqdm progressbar for opencv videocapture going beyong 100%

Time:05-16

I am processing a video using Opencv in python and using tqdm to show the progressbar. However, the progress goes beyond 100%. Not really sure why is this happening.

I am new to opencv ,so it is possible I am passing wrong params to do what I is intended.

I have tried out a few ways. Listing them down.

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)
    

I have a counter called count which is basically to skip the video 5 secs.

CodePudding user response:

When using tqdm with manual updates you specify the step with which you increment not where you are currently.

From the manual

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

So what you should do is simply to have pbar.update(fps*5).

  • Related