infinity length after using get_length() . How to tackle the infinity images situation?

96 views
Skip to first unread message

Prashant

unread,
Feb 21, 2019, 9:28:32 PM2/21/19
to imageio

In the else loop I have the nframe object as infinity. What is the way I should handle this case so that I can run the for loop. 
Is there a way I can handle this condition in imageio? I would appreciate your advice. 

I have a reader object
 reader = imageio.get_reader(vidoe.mp4,"ffmpeg")

Now  I have this frame reader function :
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()
       print("#####",nframes) ### prints "inf" >> not abble to handle this condition to
        ###run the for loop below
       #if nframes == float('inf') or nframes ==float('-inf'):
       #return float("nan")
       # continue
        #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))


Reply all
Reply to author
Forward
0 new messages