python实现图像识别功能
更新时间:2018年01月29日 10:28:32 作者:zoujm-hust12
这篇文章主要为大家详细介绍了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废弃...
'''
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
keras自定义回调函数查看训练的loss和accuracy方式
这篇文章主要介绍了keras自定义回调函数查看训练的loss和accuracy方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-05-05
TensorFlow的环境配置与安装教程详解(win10+GeForce GTX1060+CUDA 9.0+cuDNN7
这篇文章主要介绍了TensorFlow的环境配置与安装(win10+GeForce GTX1060+CUDA 9.0+cuDNN7.3+tensorflow-gpu 1.12.0+python3.5.5),本文通过图文并茂的形式给大家介绍的非常详细,需要的朋友可以参考下2020-06-06
Python操作csv文件之csv.writer()和csv.DictWriter()方法的基本使用
csv文件是一种逗号分隔的纯文本形式存储的表格数据,Python内置了CSV模块,可直接通过该模块实现csv文件的读写操作,下面这篇文章主要给大家介绍了关于Python操作csv文件之csv.writer()和csv.DictWriter()方法的基本使用,需要的朋友可以参考下2022-09-09
pycharm中代码回滚到指定版本的两种实现方法(附带截图展示)
在编写代码的时候,经常会出现写的代码存在一些问题,但是比较难以发现具体存在的问题在哪里,需要将带代码恢复到指定的版本,下面这篇文章主要给大家介绍了关于pycharm中代码回滚到指定版本的两种实现方法,需要的朋友可以参考下2022-06-06


最新评论