本文主要是介绍基于keras 的车牌字符识别第一篇,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#数据预处理部分: #coding:utf-8 import os import numpy as np from PIL import Image#重新命名 def FileReName(DogType,FilePath):type_counter = 0 #狗的种类for type in DogType:file_counter = 0 #每一种狗有多少subfolder = os.listdir(FilePath+type) #Raw_img/哈士奇/for subclass in subfolder:#每一个文件file_counter +=1print(file_counter)print('Type_counter',type_counter)print(subclass)os.rename(FilePath+type+'/'+subclass, FilePath+type+'/'+str(type_counter)+'_'+str(file_counter)+'_'+subclass.split('.')[0]+'.jpg')type_counter += 1#重新图片尺寸def FileResize(Output_folder,DogType,FilePath,Width=100, Height=100):for type in DogType:for i in os.listdir(FilePath+type):img_open = Image.open(FilePath+type+'/'+i)conv_RGB = img_open.convert('RGB')Resized_img = conv_RGB.resize((Width,Height),Image.BILINEAR)Resized_img.save(os.path.join(Output_folder,os.path.basename(i)))#读取图片返回array数组 numpy array def ReadImage(filename,train_folder):img = Image.open (train_folder+filename)return np.array(img)#图片加载到列表 图像 和 标签 def DataSet(train_folder):Train_list_img = []Train_list_label = []for file_1 in os.listdir(train_folder):file_img_to_array = ReadImage(filename=file_1,train_folder=train_folder)#添加图片数组到主list里Train_list_img.append(file_img_to_array)# 添加标签数组到主list里Train_list_label.append(int(file_1.split('_')[0]))Train_list_img = np.array(Train_list_img)Train_list_label = np.array(Train_list_label)print(Train_list_img.shape) #X_train minstprint(Train_list_label.shape) #Y_train minstif __name__ == "__main__":DogType = ['0','1','2','3','4','5','6','7','8','9']# todo step 1 : 修改文件名#修改名字FileReName(DogType=DogType,FilePath='Raw_Img/') #需要处理的图片放在Raw_Img中#修改尺寸# FileResize(DogType=DogType, FilePath='Raw_Img/',Output_folder='train_img/')#准备好的数据#DataSet(train_folder='train_img/')# FileReName(DogType=DogType,FilePath='Raw_Img/')#修改尺寸# FileResize(DogType=DogType, FilePath='Raw_Img/',Output_folder='train_img/')#准备好的数据#DataSet(train_folder='train_img/')
这篇关于基于keras 的车牌字符识别第一篇的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!