本文實(shí)例為大家分享了python實(shí)現(xiàn)圖像識(shí)別的具體代碼,供大家參考,具體內(nèi)容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#! /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則識(shí)別完成后刪除生成的文本文件 # plus參數(shù)為給tesseract的附加高級(jí)參數(shù) 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')) # 打印識(shí)別出的文本,刪除txt文件 # print(image_to_string('./phototest.tif', False)) # 打印識(shí)別出的文本,不刪除txt文件 # print(image_to_string('./phototest.tif', False, '-l eng')) # 打印識(shí)別出的文本,不刪除txt文件,同時(shí)提供高級(jí)參數(shù) # PyTesser廢棄... ''' |
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:http://blog.csdn.net/shentong1/article/details/79108474