当前位置:   article > 正文

python实现图像识别水果_吴裕雄 python神经网络 水果图片识别(1)

基于pynq的水果种类识别

import os

import numpy as np

import matplotlib.pyplot as plt

from skimage import color,data,transform,io

labelList = os.listdir("F:\\MachineLearn\\ML-xiaoxueqi\\fruits\\Training")

allFruitsImageName = []

for i in range(len(labelList)):

allFruitsImageName.append(os.listdir("F:\\MachineLearn\\ML-xiaoxueqi\\fruits\\Training\\"+labelList[i]))

allsortImageName = []

for i in range(len(allFruitsImageName)):

oneClass = allFruitsImageName[i]

nr = []

r = []

r2 = []

for i in range(len(oneClass)):

if(oneClass[i].split("_")[0].isdigit()):

nr.append(int(oneClass[i].split("_")[0]))

else:

if(len(oneClass[i].split("_")[0])==1):

r.append(int(oneClass[i].split("_")[1]))

else:

r2.append(int(oneClass[i].split("_")[1]))

sortnr = sorted(nr)

sortnrImageName = []

for i in range(len(sortnr)):

sortnrImageName.append(str(sortnr[i])+"_100.jpg")

sortr = sorted(r)

sortrImageName = []

for i in range(len(sortr)):

sortrImageName.append("r_"+str(sortr[i])+"_100.jpg")

sortr2 = sorted(r2)

sortr2ImageName = []

for i in range(len(sortr2)):

sortr2ImageName.append("r2_"+str(sortr2[i])+"_100.jpg")

sortnrImageName.extend(sortrImageName)

sortnrImageName.extend(sortr2ImageName)

allsortImageName.append(sortnrImageName)

trainData = []

for i in range(len(allsortImageName)):

one = []

for j in range(len(allsortImageName[i])):

rgb=io.imread("F:\\MachineLearn\\ML-xiaoxueqi\\fruits\\Training\\"+labelList[i]+"\\" + allsortImageName[i][j]) #读取图片

gray=color.rgb2gray(rgb) #将彩色图片转换为灰度图片

dst=transform.resize(gray,(64,64)) #调整大小,图像分辨率为64*64

one.append(dst)

trainData.append(one)

print(np.shape(trainData))

trainLabelNum = []

for i in range(len(trainData)):

for j in range(len(trainData[i])):

trainLabelNum.append(i)

imageGray = trainData[i][j]

io.imsave("F:\\MachineLearn\\ML-xiaoxueqi\\fruits\\trainGrayImage\\"+str(i)+"_"+str(j)+".jpg",imageGray)

np.save("F:\\MachineLearn\\ML-xiaoxueqi\\fruits\\trainLabelNum",trainLabelNum)

print("图片处理完了")

testLabelList = os.listdir("F:\\MachineLearn\\ML-xiaoxueqi\\fruits\\Test")

testallFruitsImageName = []

for i in range(len(testLabelList)):

testallFruitsImageName.append(os.listdir("F:\\MachineLearn\\ML-xiaoxueqi\\fruits\\Test\\"+testLabelList[i]))

testallsortImageName = []

for i in range(len(testallFruitsImageName)):

oneClass = testallFruitsImageName[i]

nr = []

r = []

r2 =

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/140227?site
推荐阅读
相关标签
  

闽ICP备14008679号