def classify_singlechar(): singlechardir = r'D:\projects\python\captchabreak\data\icbc\icbc1213_output' outputdir = r'D:\projects\python\captchabreak\data\icbc\icbc_c_output' try: os.mkdir(outputdir) except: pass traindata = r'D:\projects\python\captchabreak\data\icbc\icbcaudit' cc = Classifier(traindata, class_sample_num=20, size = 20) cc.train() count =0 for subdir in cc.classify_map: try: os.mkdir(os.path.join(outputdir, subdir)) except: pass for root, dirs, files in os.walk(singlechardir): for file in files: path = os.path.join(root, file) img = cv.LoadImage(path, 0) response = cc.classify_single_char(img) outputfile = os.path.join(outputdir, response, 'icbc_%d.jpg'%count) cv.SaveImage(outputfile, img) count += 1
def main(): traindata = r'D:\projects\python\captchabreak\data\doubanaudit' douban = Classifier(traindata, 5) douban.train() testdata = r'D:\projects\python\captchabreak\data\doubanseg' outputdir = r'D:\projects\python\captchabreak\data\doubanoutput' count =0 for subdir in douban.classify_map: try: os.mkdir(os.path.join(outputdir, subdir)) except: pass for root, dirs, files in os.walk(testdata): for file in files: path = os.path.join(root, file) img = cv.LoadImage(path, 0) response = douban.classify_single_char(img) outputfile = os.path.join(outputdir, response, 'douban_%d.jpg'%count) cv.SaveImage(outputfile, img) count += 1