您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python实现图像识别功能

5b51 2022/1/14 8:15:25 python 字数 3519 阅读 313 来源 www.jb51.cc/python

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

概述

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

#! /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废弃... 
''' 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

以上是编程之家为你收集整理的python实现图像识别功能全部内容,希望文章能够帮你解决python实现图像识别功能所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶