N parts of the picture cut to a folder named after the picture put n parts of the picture, and is named after the name of the picture cut to put the same name as the new folder, rename

import os
import shutil
import cv2
path = r’D:/cut_43/cut_D43_CODE/data/3/’
filelist = os.listdir(path)

for file in filelist :
# print(file)

adr = path + file
print(adr)
filelist1=os.listdir(adr)
# print(filelist1)

for j in filelist1:


    # if os.path.exists(r'D:/cut_43/cut_D43_CODE/data/2/' + str(os.path.splitext(j)[0])):
    #     shutil.rmtree(r'D:/cut_43/cut_D43_CODE/data/2/' + str(os.path.splitext(j)[0]))
    #
    # os.mkdir(r'D:/cut_43/cut_D43_CODE/data/2/' + str(os.path.splitext(j)[0]))

    image = cv2.imread(adr+'/'+j)


    # cv2.imwrite(r'D:/cut_43/cut_D43_CODE/data/2/' + str(os.path.splitext(j)[0]) + '/' + str(file+os.path.splitext(j)[0]) + '.jpg',
    #         image)
Published 41 original articles · won praise 7 · views 3681

Guess you like

Origin blog.csdn.net/weixin_43091087/article/details/103538775
Recommended