python实现图像识别功能
本文实例为大家分享了python实现图像识别的具体代码,供大家参考,具体内容如下
#!/usr/bin/envpython
fromPILimportImage
importpytesseract
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)
printtext
#image.show()
r'''''#
zhongwen_url='img/zhongwen003.png'
importos
fn="aaaa"
#sudoapt-getinstalltesseract
cmd="tesseract"+zhongwen_url+""+fn+"-lchi_sim"
os.system(cmd)
withopen(fn+".txt","r")asf:
printf
ret=os.system('cat/etc/pam.conf')
printret
print'----------------------'
ret=os.popen('cat/etc/pam.conf')
printret'''
r'''''
importos
importsubprocess
defimage_to_string(img,cleanup=True,plus=''):
#cleanup为True则识别完成后删除生成的文本文件
#plus参数为给tesseract的附加高级参数
subprocess.check_output('tesseract'+img+''+
img+''+plus,shell=True)#生成同名txt文件
text=''
withopen(img+'.txt','r')asf:
text=f.read().strip()
ifcleanup:
os.remove(img+'.txt')
returntext
#run>>>
#print(image_to_string('./phototest.tif'))#打印识别出的文本,删除txt文件
#print(image_to_string('./phototest.tif',False))#打印识别出的文本,不删除txt文件
#print(image_to_string('./phototest.tif',False,'-leng'))#打印识别出的文本,不删除txt文件,同时提供高级参数
#PyTesser废弃...
'''
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。