Python rename renumber

 

# -*- coding: utf-8 -*-
import os
import numpy as np
import cv2

list_path = r"F:\project\cls\yanshen\20201209/"
g = os.walk(list_path)

test_dataset = ['%s/%s' % (i[0], j) for i in g for j in i[-1]]


for index,filename in enumerate(test_dataset):

    name = f'/{index:04d}.jpg'
    dir_name=os.path.dirname(filename)
    os.rename(filename,dir_name+name)

Filter images:

  g = os.walk(list_path)
        img_files = ['%s\\%s' % (i[0], j) for i in g if i[0].endswith('JPEGImages') for j in i[-1] if
                     j.endswith('jpg')]

 


Read More: