0

I am displaying a bunch of image frames using this code snippet below:

import cv2 

from IPython import embed
import os
import glob

file_list = ['/home/Sep28',
'/home/Sep21', 
'/home/Sep29',
]

count = 0 
for i in file_list:
             file_names = glob.glob(i+"/kinect_rgb/*")
             file_names.sort()
             print "found"
             for j in file_names:
                img = cv2.imread(j)
                img = img[200:600,100:500]
                cv2.imshow("cropped",img)
                cv2.waitKey(50)
                count = count + 1 

Whenever I am displaying them, the video does not flow in order, it looks like once in three frames and older frame gets inserted. I am not sure as to what could be the reason.

  • My images look totally fine inside the folder
  • I print the file names and they don't seem to repeat as well.
deeplearning
  • 459
  • 4
  • 15
  • Problem is: `cv2.waitKey(50)` reduce 50 to, say, 1. That's the delay between each frame, you'll want to reduce that. – cs95 Oct 15 '17 at 23:41
  • Thank you. I set the cv2.waitKey(1) and the issue still persists. But why does the delay cause the frame lag though? Shouldn't it move to the next frame after 50ms or 1 ms? – deeplearning Oct 16 '17 at 00:16
  • Maybe you shouldn't sort the file names? – cs95 Oct 16 '17 at 00:18
  • I see what is happening there! If I don't sort it, then the images are showing up in some random haphazard manner. Is there any other in-built function that helps me sort the file? – deeplearning Oct 16 '17 at 00:40

1 Answers1

1

Don't use file_names.sort().

In [8]: filenames = [str(i) + ".png" for i in range(13)]

In [9]: filenames
Out[9]: 
['0.png',
 '1.png',
 '2.png',
 '3.png',
 '4.png',
 '5.png',
 '6.png',
 '7.png',
 '8.png',
 '9.png',
 '10.png',
 '11.png',
 '12.png']

In [10]: filenames.sort()

In [11]: filenames
Out[11]: 
['0.png',
 '1.png',
 '10.png',
 '11.png',
 '12.png',
 '2.png',
 '3.png',
 '4.png',
 '5.png',
 '6.png',
 '7.png',
 '8.png',
 '9.png']

Try this:How do you sort files numerically?

Hao Li
  • 1,593
  • 15
  • 27
  • I see what is happening there! If I don't sort it, then the images are showing up in some random haphazard manner. Is there any other in-built function that helps me sort the file? – deeplearning Oct 16 '17 at 00:40
  • try this:https://stackoverflow.com/questions/4623446/how-do-you-sort-files-numerically – Hao Li Oct 16 '17 at 00:43