python实现图像识别功能

发布时间:2020-09-25 18:12:05 作者:zoujm-hust12
来源:脚本之家 阅读:161

本文实例为大家分享了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废弃... 
''' 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

推荐阅读:
  1. 自动化中图像识别
  2. python实现计算器功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python 图像识别

上一篇:100多个基础常用JS函数和语法集合大全

下一篇:Android 使用手机NFC的读取NFC标签数据的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》