提取文件中的每一个mask,并将mask命名为文件名字

import cv2 as cv
import random
import glob
import os
from PIL import Image
import shutil


def get_samples(foldername, savePath):
    print('savePath:', savePath)
    if os.path.exists(savePath) is False:
        os.makedirs(savePath)

    filenames = os.listdir(foldername)

    for filename in filenames:
        full_path = os.path.join(foldername, filename)
        new_name = filename[:-5] + '.png'
        label_png = os.listdir(full_path)[2]
        # os.rename(os.path.join(filename, label_png),os.path.join(filename, name))
        shutil.copy(os.path.join(full_path, label_png), os.path.join(savePath, label_png))
        os.rename(os.path.join(savePath, label_png), os.path.join(savePath, new_name))
        # print(os.listdir(filename))

savePath = 'C:/Users/Desktop/978/'
get_samples('C:/Users/Desktop/978/', savePath)

 

posted @ 2019-09-21 15:13  apan008  阅读(420)  评论(0编辑  收藏  举报