AttributeError:'NoneType'对象没有属性'copy'为什么? [英] AttributeError: 'NoneType' object has no attribute 'copy' why?
本文介绍了AttributeError:'NoneType'对象没有属性'copy'为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import cv2
import numpy as np
from datetime import datetime
import os
from PIL import Image
import hashlib, os, math, time
import Image
#from PIL import Image
import ImageEnhance
from pytesser import *
from urllib import urlretrieve
import math
import random
iconset = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
samples=np.empty((0,100))
responses =[]
for letter in iconset:
for img in os.listdir('iconset/%s/'%(letter)):
#for j in range(1,10):
#for i in range(1,10):
#n= str(j)+str(i)+'.jpg'
img = cv2.imread(img)
im3 = img.copy()
height, width, depth = im3.shape
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
thresh = cv2.adaptiveThreshold(blur,255,1,1,11,2)
roi = thresh[0:height, 0:width]
roismall = cv2.resize(roi,(10,10))
responses.append(j)
sample = roismall.reshape((1,100))
samples = np.append(samples,sample,0)
print "training complete"
推荐答案
您确定每个目录都已填充吗?
如果不是,你可以通过检查img存在/不是none修复代码,如果没有则打破循环。
Are you sure each directory is populated?
If they are not, you can fix your code by checking that img exists/ is not none and breaking the loop if it is none.
Quote:
img = cv2.imread(img)
im3 = img.copy()
成为
Becomes
img = cv2.imread(img)
if img is None:
break
im3 = img.copy()
中断将终止内循环而不是外循环,允许你转到下一个目录。
The break will kill the inner loop but not the outer loop, allowing you to go to the next directory.
这篇关于AttributeError:'NoneType'对象没有属性'copy'为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文