python实现图像识别功能

作者:zoujm-hust12 时间:2023-08-09 08:45:00 

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

来源:http://blog.csdn.net/shentong1/article/details/79108474

标签:python,图像识别
0
投稿

猜你喜欢

  • SQL游标原理和使用方法

    2008-12-22 10:50:00
  • pandas 时间格式转换的实现

    2021-03-23 13:09:01
  • pycharm设置注释颜色的方法

    2022-01-22 21:47:46
  • Python sublime安装及配置过程详解

    2021-07-06 19:57:47
  • 关于go-zero单体服务使用泛型简化注册Handler路由的问题

    2023-08-30 20:19:08
  • 教你隐藏ACCESS数据库的表名

    2008-05-09 19:45:00
  • Go 字符串格式化的实例代码详解

    2023-08-05 14:05:30
  • Go语言区别于其他语言的特性

    2023-06-26 02:52:10
  • PyTorch深度学习LSTM从input输入到Linear输出

    2022-04-03 23:11:32
  • 在TensorFlow中屏蔽warning的方式

    2023-05-08 10:54:19
  • python+rsync精确同步指定格式文件

    2023-09-18 06:51:26
  • asp中判断是否是手机浏览器以及手机类型

    2014-12-06 09:33:05
  • virtualenv实现多个版本Python共存

    2021-11-27 00:50:44
  • Python如何实现FTP功能

    2021-10-22 15:08:25
  • django创建自定义模板处理器的实例详解

    2022-07-29 19:50:00
  • python获取指定字符串中重复模式最高的字符串方法

    2021-03-25 14:59:25
  • python中plot实现即时数据动态显示方法

    2021-04-20 22:09:18
  • python解压TAR文件至指定文件夹的实例

    2023-09-29 04:00:18
  • Python利用公共键如何对字典列表进行排序详解

    2022-03-04 01:31:33
  • pycharm指定python路径过程详解

    2021-04-27 13:25:13
  • asp之家 网络编程 m.aspxhome.com