-2

I'm trying to sorting the jpgs (ascending numerically) in my directory to generate a video for opencv, but I'm having a a hard time finding a solution:

images = []
for f in os.listdir('.'):
    if f.endswith('.jpg'):
        images.append(f)

images[]:

['img_0.jpg', 'img_1.jpg', 'img_10.jpg', 'img_100.jpg', 'img_101.jpg', 'img_102.jpg', ... 'img_99.jpg']
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
ddgg007
  • 7
  • 5

2 Answers2

0
import cv2
vidcap = cv2.VideoCapture('big_buck_bunny_720p_5mb.mp4')
success,image = vidcap.read()
count = 0
success = True
while success:
 cv2.imwrite("frame%d.jpg" % count, image)     # save frame as JPEG file      
 success,image = vidcap.read()
 print('Read a new frame: ', success)
 count += 1
DeCastroAj
  • 30
  • 7
0

You can use Os:

from os import listdir
from os.path import isfile, join
jpgfiles = [f for f in listdir('.') if isfile(join('.', f)) and f.endswith(".txt")]
jpgfiles.sort()
Rehan Azher
  • 1,340
  • 1
  • 9
  • 17