重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

python实现图像识别功能-创新互联

本文实例为大家分享了python实现图像识别的具体代码,供大家参考,具体内容如下

创新互联长期为上1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为固原企业提供专业的网站制作、成都网站制作,固原网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。
#! /usr/bin/env python 
 
from PIL import Image 
import pytesseract 
 
url='img/denggao.jpeg' 
image=Image.open(url) 
#image=image.convert('RGB') # RGB 
image=image.convert('L') # 灰度 
image.load() 
text=pytesseract.image_to_string(image) 
print text 
#image.show() 
 
r'''''# 
zhongwen_url = 'img/zhongwen003.png' 
import os 
fn = "aaaa" 
# sudo apt-get install tesseract 
cmd = "tesseract " + zhongwen_url + " " + fn + " -l chi_sim" 
os.system(cmd) 
 
with open(fn+".txt", "r") as f: 
  print f 
 
 
ret=os.system('cat /etc/pam.conf') 
print ret 
print '----------------------' 
ret=os.popen('cat /etc/pam.conf') 
print ret''' 
 
r''''' 
import os 
import subprocess 
 
def image_to_string(img, cleanup=True, plus=''): 
  # cleanup为True则识别完成后删除生成的文本文件 
  # plus参数为给tesseract的附加高级参数 
  subprocess.check_output('tesseract ' + img + ' ' + 
              img + ' ' + plus, shell=True) # 生成同名txt文件 
  text = '' 
  with open(img + '.txt', 'r') as f: 
    text = f.read().strip() 
  if cleanup: 
    os.remove(img + '.txt') 
  return text 
# run >>> 
# print(image_to_string('./phototest.tif')) # 打印识别出的文本,删除txt文件 
# print(image_to_string('./phototest.tif', False)) # 打印识别出的文本,不删除txt文件 
# print(image_to_string('./phototest.tif', False, '-l eng')) # 打印识别出的文本,不删除txt文件,同时提供高级参数 
 
# PyTesser废弃... 
''' 

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


标题名称:python实现图像识别功能-创新互联
链接分享:http://cqcxhl.com/article/dccgop.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP