|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Stubborn 于 2019-4-14 04:14 编辑
安装说明的走百度吧。这个可以收藏,嗯嗯,据说本来识别不出的验证,经过设置识别率可以提高75%
- # -*- coding: utf-8 -*-
- # @Time : 2019-04-10 02:32
- # @Author : Ein
- # @File : tessercor-图片识别.py
- # @Software: PyCharm
- import locale
- locale.setlocale(locale.LC_ALL,'C')
- #为 MAC而设置,不是可以无视
- import pytesseract,os
- from PIL import Image,ImageEnhance
- def yzm_file_path():
- currrent_path = os.path.realpath(__file__) # 文件绝对路径
- current_dir = os.path.split(currrent_path)[0]
- return current_dir + r"/png/ZD26.jpg"
- #图片路径
- path = yzm_file_path()
- #打开图片
- image = Image.open(path)
- image = image.convert('RGB')
- enhancer = ImageEnhance.Color(image)
- enhancer = enhancer.enhance(0)
- enhancer = ImageEnhance.Brightness(enhancer)
- enhancer = enhancer.enhance(2)
- enhancer = ImageEnhance.Contrast(enhancer)
- enhancer = enhancer.enhance(8)
- enhancer = ImageEnhance.Sharpness(enhancer)
- image = enhancer.enhance(20)
- #转化灰度图片
- image = image.convert('L')
- #展示
- #image.show()
- #二值化处理
- threshold = 140
- table = []
- for i in range(256):
- if i < threshold:
- table.append(0)
- else:
- table.append(1)
- out = image.point(table,"1")
- #展示
- #out.show()
- #识别图片
- print(pytesseract.image_to_string(image))
复制代码 |
|