python中ocr软件pytesseract使用

首先要看原版的参考

https://github.com/madmaze/pytesseract

直接上代码,

import pytesseract
from PIL import Image
image = Image.open(r'D:\xingjinzi\5.jfif')
result =pytesseract.image_to_string(image,config='--psm 8 -c tessedit_char_whitelist=abceefghigklmnopqrstuvwxyz')
print(result)

 

# result =pytesseract.image_to_string (image,)   #英文
# result =pytesseract.image_to_string (image,) #简体中文
result =pytesseract.image_to_string(image,config='--psm 12 -c tessedit_char_whitelist=1234567890abceefghigklmnopqrstuvwxyz')
tessedit_char_whitelist=abceefghigklmnopqrstuvwxyz  相当于白名单,集可以有哪些字符
--psm 是一个识别方向引导的内容,参考

Page segmentation modes:

0 Orientation and script detection (OSD) only.

1 Automatic page segmentation with OSD.

2 Automatic page segmentation, but no OSD, or OCR.

3 Fully automatic page segmentation, but no OSD. (Default)

4 Assume a single column of text of variable sizes.

5 Assume a single uniform block of vertically aligned text.

6 Assume a single uniform block of text.

7 Treat the image as a single text line.

8 Treat the image as a single word.

9 Treat the image as a single word in a circle.

10 Treat the image as a single character.

11 Sparse text. Find as much text as possible in no particular order.

12 Sparse text with OSD.

13 Raw line. Treat the image as a single text line,

对应的中文如下

页面分割模式:

0仅限方向和脚本检测(OSD)。

1使用OSD自动分页。

2自动页面分割,但没有OSD或OCR。

3全自动页面分割,但没有OSD。 (默认)

4假设一列可变大小的文本。

5假设一个垂直对齐文本的统一块。

6假设一个统一的文本块。

7将图像视为单个文本行。

8将图像视为单个单词。

9将图像视为圆形中的单个单词。

10将图像视为单个字符。

11稀疏文字。 找到尽可能多的文本,没有特定的顺序。

12带OSD的稀疏文本。

13原始线。 将图像视为单个文本行

总得来说还不错的

1.语言库地址:https://github.com/tesseract-ocr/tessdata

2.语言库列表

库名语言
afrAfrikaans(南非荷兰语)
amhAmharic(阿姆哈拉语)
araArabic(阿拉伯语)
asmAssamese(阿萨姆)
azeAzerbaijani(阿塞拜疆)
aze_cyrlAzerbaijani - Cyrilic(阿塞拜疆-Cyrilic)
belBelarusian(白俄罗斯)
benBengali(孟加拉)
bodTibetan(西藏)
bosBosnian(波斯尼亚)
bulBulgarian(保加利亚语)
catCatalan; Valencian(加泰罗尼亚语; 巴伦西亚)
cebCebuano(宿务)
cesCzech(捷克)
chi_simChinese - Simplified(中国-简体)
chi_traChinese - Traditional(中国-繁体)
chrCherokee(切诺基)
cymWelsh(威尔士)
danDanish(丹麦)
dan_frakDanish - Fraktur(丹麦-Fraktur)
deuGerman(德国)
deu_frakGerman - Fraktur(德国-Fraktur)
dzoDzongkha(不丹文)
ellGreek, Modern (1453-)(希腊,现代(1453-))
engEnglish(英语)
enmEnglish, Middle (1100-1500)(英语,中东(1100-1500))
epoEsperanto(世界语)
equMath / equation detection module(数学/方程式检测模块)
estEstonian(爱沙尼亚)
eusBasque(巴斯克)
fasPersian(波斯)
finFinnish(芬兰)
fraFrench(法语)
frkFrankish(法兰克)
frmFrench, Middle (ca.1400-1600)(法国,中东(ca.1400-1600))
gleIrish(爱尔兰)
glgGalician(加利西亚)
grcGreek, Ancient (to 1453)(希腊语,古(到1453年))
gujGujarati(古吉拉特语)
hatHaitian; Haitian Creole(海天; 海地克里奥尔语)
hebHebrew(希伯来语)
hinHindi(印地文)
hrvCroatian(克罗地亚)
hunHungarian(匈牙利)
ikuInuktitut(因纽特语)
indIndonesian(印尼)
islIcelandic(冰岛)
itaItalian(意大利语)
ita_oldItalian - Old(意大利语-旧)
javJavanese(爪哇)
jpnJapanese(日本)
kanKannada(卡纳达语)
katGeorgian(格鲁吉亚)
kat_oldGeorgian - Old(格鲁吉亚-旧)
kazKazakh(哈萨克斯坦)
khmCentral Khmer(中央高棉)
kirKirghiz; Kyrgyz(柯尔克孜; 吉尔吉斯)
korKorean(韩国)
kurKurdish(库尔德人)
laoLao(老挝)
latLatin(拉丁)
lavLatvian(拉脱维亚)
litLithuanian(立陶宛)
malMalayalam(马拉雅拉姆语)
marMarathi(马拉)
mkdMacedonian(马其顿)
mltMaltese(马耳他)
msaMalay(马来文)
myaBurmese(缅甸)
nepNepali(尼泊尔)
nldDutch; Flemish(荷兰; 佛兰芒语)
norNorwegian(挪威)
oriOriya(奥里亚语)
osdOrientation and script detection module(定位及脚本检测模块)
panPanjabi; Punjabi(旁遮普语; 旁遮普语)
polPolish(波兰)
porPortuguese(葡萄牙语)
pusPushto; Pashto(普什图语; 普什图语)
ronRomanian; Moldavian; Moldovan(罗马尼亚; 摩尔多瓦; 摩尔多瓦)
rusRussian(俄罗斯)
sanSanskrit(梵文)
sinSinhala; Sinhalese(僧伽罗语; 僧伽罗语)
slkSlovak(斯洛伐克)
slk_frakSlovak - Fraktur(斯洛伐克- Fraktur)
slvSlovenian(斯洛文尼亚)
spaSpanish; Castilian(西班牙语; 卡斯蒂利亚)
spa_oldSpanish; Castilian - Old(西班牙语; 卡斯蒂利亚-老)
sqiAlbanian(阿尔巴尼亚)
srpSerbian(塞尔维亚)
srp_latnSerbian - Latin(塞尔维亚语-拉丁语)
swaSwahili(斯瓦希里语)
sweSwedish(瑞典)
syrSyriac(叙利亚)
tamTamil(泰米尔)
telTelugu(泰卢固语)
tgkTajik(塔吉克斯坦)
tglTagalog(菲律宾语)
thaThai(泰国)
tirTigrinya(提格雷语)
turTurkish(土耳其)
uigUighur; Uyghur(维吾尔族; 维吾尔)
ukrUkrainian(乌克兰)
urdUrdu(乌尔都语)
uzbUzbek(乌兹别克斯坦)
uzb_cyrlUzbek - Cyrilic(乌兹别克斯坦- Cyrilic)
vieVietnamese(越南语)
yidYiddish(意第绪语)