Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ba4d509

Browse files
committed
ocr GetComponentImages
1 parent 2f8ef75 commit ba4d509

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2017年8月21日 14:49
3+
# @Author : play4fun
4+
# @File : GetComponentImages-example.py.py
5+
# @Software: PyCharm
6+
7+
"""
8+
GetComponentImages-example.py:
9+
"""
10+
11+
from PIL import Image
12+
from tesserocr import PyTessBaseAPI, RIL
13+
14+
with PyTessBaseAPI() as api:
15+
# image = Image.open('/usr/src/tesseract/testing/phototest.tif')
16+
image = Image.open('phototest.tif') # 图片有问题
17+
print(image.format, image.info, image.height, image.width)
18+
19+
api.SetImage(image)
20+
boxes = api.GetComponentImages(RIL.TEXTLINE, True)
21+
print('Found {} textline image components.'.format(len(boxes)))
22+
for i, (im, box, _, _) in enumerate(boxes):
23+
# im is a PIL image object
24+
# box is a dict with x, y, w and h keys
25+
api.SetRectangle(box['x'], box['y'], box['w'], box['h'])
26+
ocrResult = api.GetUTF8Text()
27+
conf = api.MeanTextConf()
28+
print(u"Box[{0}]: x={x}, y={y}, w={w}, h={h}, "
29+
"confidence: {1}, text: {2}").format(i, conf, ocrResult, **box)
100 KB
Binary file not shown.
37.8 KB
Binary file not shown.

‎my01-OCR文字识别/Tessract-OCR/tesserocr/tesserocr_demo3.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
from tesserocr import PyTessBaseAPI, PSM
1111

1212
with PyTessBaseAPI(psm=PSM.AUTO_OSD) as api:
13-
image = Image.open("/usr/src/tesseract/testing/eurotext.tif")#No such file
13+
# image = Image.open("/usr/src/tesseract/testing/eurotext.tif")#No such file
14+
# image = Image.open("eurotext.tif")
15+
image = Image.open('phototest.tif')
1416
api.SetImage(image)
1517
api.Recognize()
1618

@@ -20,3 +22,6 @@
2022
print("WritingDirection: {:d}".format(direction))
2123
print("TextlineOrder: {:d}".format(order))
2224
print("Deskew angle: {:.4f}".format(deskew_angle))
25+
#
26+
ocrResult = api.GetUTF8Text()
27+
print('result:\n',ocrResult)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /