Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Python
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"
Posted
Comments
[no name] 14-Jun-14 13:28pm    
http://stackoverflow.com/questions/8949252/python-attribute-error-nonetype-object-has-no-attribute-something

1 solution

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:
Python
img = cv2.imread(img)
im3 = img.copy()
Becomes

Python
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900