• pytesseract简单尝试


    安装tesseract可参考在线中文字符识别网站(前后端分离 REST)
    安装pytesseract模块来使用tesseract

    pip install pytesseract
    

    识别本地图片字符

    中文英文据可以,但要清晰,指的是图片上只有文字,不然就要进行相关处理

    from PIL import Image				#导入图像模块
    import pytesseract					#导入识别模块
    text = pytesseract.image_to_string(Image.open(r'09	est2.png'), lang='chi_sim')	#引用图片转字符方法
    print(text)							#输出结果
    # image_to_string(Image.open('路径'))
    

    识别在线字符

    网址就是验证码随机生成的网址,需自己去找

    import pytesseract
    from urllib import request
    from PIL import Image
    import time
    
    for i in  range(20):
    	captchaUrl = "https://passport.lagou.com/vcode/create"
    	request.urlretrieve(captchaUrl,'captcha.png') 
    	image = Image.open('captcha.png')
    	text = pytesseract.image_to_string(image,lang='eng') # 如果未指定,则默认为eng!多语言示例:lang='eng+fra'
    	print(text)
    	time.sleep(2)
    
    
    

    这里需注意

    from urllib import request
    request.urlretrieve(1,2)
    参数1,2均为字符串类型,参数1是url,参数2是保存的文件名 
    一般是保存在运行环境的当前目录
    

    进行灰度处理

    from PIL import Image							#加载image模块
    image = Image.open(r"091.jpg")						#打开当前目录的1.jpg
    image = image.convert('L')						#转化为灰度图像
    image.show()									#显示图像
    

    进行二进值处理

    二进值话就是图像上只有黑白两色,一般在使用灰度处理之后还无法识别,可进行二进值话

    from PIL import Image
    from numpy.lib.type_check import imag							#加载image模块
    image = Image.open(r"091.jpg")						#打开当前目录的1.jpg
    image = image.convert('L')						#转化为灰度图像
    image = image.convert('1')
    image.show()									#显示图像
    
    努力拼搏吧,不要害怕,不要去规划,不要迷茫。但你一定要在路上一直的走下去,尽管可能停滞不前,但也要走。
  • 相关阅读:
    使用frp工具实现内网穿透以及配置多个ssh和web服务
    axios下载pdf
    itextpdf freemarker渲染
    腾讯云函数免费搭建onedrive网盘
    Ajax请求携带Cookie
    GitHub通过access token来clone代码
    web网页动态分享facebook和twitter
    python smtplib在linux上发送邮件失败解决方式
    java如何关闭钩子(ShutdownHook)
    VS Code运行SpringBoot项目
  • 原文地址:https://www.cnblogs.com/wkhzwmr/p/15487375.html
Copyright © 2020-2023  润新知