nexclude_char_list])#print(text)returntextdefmain():#之别指定文件目录下的图片#图片存放目录figuresdir ='E://figures'correct_count =0#图片总数total_count =0#识别正确的图片数量# 遍历figures下的png,jpg文件forfileinos.listdir(dir):iffile.endswith('.png')orfile.endswith('.jpg'):# print(file)image_path ='%s/%s'%(dir,file)# 图片路径answer = file.split('.')[0]#图片名称,即图片中的正确文字recognizition = OCR_lmj(image_path)# 图片识别的文字结果 print((answer,recongizition))ifrecognizition == answer:#如果识别结果正确,则total_count加1correct_count +=1 total_count +=1print('Total count:%d,correct:%d.'%(total_count,correct_count)) ...# 单张图片识别image_path = 'E://figures/code (1).jpg' OCR_lmj(image_path) ...main()
运行结果如下:
我们可以看到图片识别的正确率为80%以上,其中数字类图片的识别正确率为100%.
我们可以在图片识别方面的算法再加改进,以提高图片识别的正确率。当然,以上算法并不是对所有验证码都适用,不同的验证码需要用不同的图片处理算法。