class MatchTests: def __init__(self, samStart=11, samEnd=36): self.data = GetData(sampleStart=samStart, sampleEnd=samEnd) self.avgs = self.data.GetAveraged() self.samStart = samStart def ClassifyTests( self, testDir="/home/brian/PycharmProjects/firstAttempt/HandLetters/"): matches = [] testImages = [ (self.data.NormalizeImage(cv2.imread(testDir + "/" + j, 0)), j) for j in os.listdir(testDir) ] #tuble(img,name) for i in testImages: name = i[1] img = i[0] bestMatch = 0 print type(self.avgs[0]) errorArray = self.avgs[0].astype(np.float_) - img.astype(np.float_) errorArray = errorArray * errorArray minError = sum(sum(errorArray)) for j in xrange(len(self.avgs)): errorArray = self.avgs[j].astype(np.float_) - img.astype( np.float_) errorArray = errorArray * errorArray error = sum(sum(errorArray)) if error < minError: minError = error bestMatch = j matches.append(name + "was identified to be: " + self.data.GetLetters()[bestMatch + self.samStart]) return matches
def __init__(self, sampStart=11, sampEnd=36): data = GetData(sampleStart=sampStart, sampleEnd=sampEnd) self.sampStart = sampStart self.sampEnd = sampEnd self.imgs = data.GetListImgs() self.letters = data.GetLetters() avgs = data.GetAveraged() self.avgs = avgs[sampStart - 1:sampEnd] self.kguesses = np.array([list(j.flatten()) for j in avgs]) self.k = sampEnd - sampStart + 1 self.data = data