deeplearning
deeplearning

Reputation: 469

Lag while Displaying images using opecv2 and Python

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.

Upvotes: 0

Views: 65

Answers (1)

Hao Li
Hao Li

Reputation: 1762

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?

Upvotes: 1

Related Questions