def testAcurrty(self): icbc = ICBCSegmentor() path = r'D:\projects\python\captchabreak\data\icbc_char\output' icbc.train(path) testdata = r'D:\projects\python\captchabreak\data\icbc_char\output' filebase = "%d_%d.jpg" right_count = 0. wrong_count = 0. for class_tag in range(27): for j in range(10, 15): sample_path = os.path.join(testdata, filebase % (class_tag, j)) res = icbc.classify(sample_path) if res[0] == class_tag: right_count += 1 else: wrong_count +=1 total = right_count+wrong_count print "total: %d, right: %d, wrong %d" % (total, right_count, wrong_count) print float(right_count/total)
print "total: %d, right: %d, wrong %d" % (total, right_count, wrong_count) print float(right_count/total) if __name__ == '__main__': #testaccury() datadir = r'D:\projects\python\captchabreak\data\icbc\icbcaudit' cc = Classifier(datadir, class_sample_num=20, model='knn') cc.train() imagedir = r'D:\projects\python\captchabreak\data\icbc\icbc1213' from icbc import ICBCSegmentor icbc = ICBCSegmentor() for root, dirs, files in os.walk(imagedir): for file in files: path = os.path.join(root, file) images = icbc.segment(path) result = [] count = 0 for img in images: count += 1 result.append(cc.classify_single_char(img)) cv.ShowImage("img%d"%count, img) print result cv.ShowImage('origin', cv.LoadImage(path, 0)) cv.WaitKey()