1. 程式人生 > >圖片資料集讀取

圖片資料集讀取

import os
import cv2
import numpy as np
from tqdm import tqdm

def read_image(path):
    '''讀取路徑下所有子資料夾中的圖片並存入list'''
    img_list = []
    label_list = []
    dir_counter = 0
    
    for child_dir in os.listdir(path):
        child_path = os.path.join(path, child_dir)      
        for dir_image in
tqdm(os.listdir(child_path)): img = cv2.imread(child_path+"\\"+dir_image,cv2.IMREAD_COLOR) # img =cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) img_list.append(img) label_list.append(dir_counter) dir_counter += 1 return img_list,label_list,dir_counter