回答編集履歴
1
追記
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
`conda`だと2.7しかないようですね。
|
2
|
-
```
|
2
|
+
```Bash
|
3
3
|
$ conda install -c auto pyocr
|
4
4
|
Solving environment: |
|
5
5
|
Warning: 2 possible package resolutions (only showing differing packages):
|
@@ -9,11 +9,45 @@
|
|
9
9
|
```
|
10
10
|
|
11
11
|
当方環境(Win10のWSL)にて`pip`にて3.6.x環境に導入でき、OCR動作しました。
|
12
|
-
```
|
12
|
+
```Bash
|
13
13
|
$ pip install pyocr
|
14
14
|
Collecting pyocr
|
15
15
|
Requirement already satisfied: six in ./anaconda3/lib/python3.6/site-packages (from pyocr) (1.11.0)
|
16
16
|
Requirement already satisfied: Pillow in ./anaconda3/lib/python3.6/site-packages (from pyocr) (5.1.0)
|
17
17
|
Installing collected packages: pyocr
|
18
18
|
Successfully installed pyocr-0.5.1
|
19
|
+
```
|
20
|
+
|
21
|
+
tesseract_test.py
|
22
|
+
```Python
|
23
|
+
from PIL import Image
|
24
|
+
import sys
|
25
|
+
import pyocr
|
26
|
+
import pyocr.builders
|
27
|
+
|
28
|
+
tools = pyocr.get_available_tools()
|
29
|
+
if len(tools) == 0:
|
30
|
+
print("No OCR tool found")
|
31
|
+
sys.exit(1)
|
32
|
+
tool = tools[0]
|
33
|
+
print("Will use tool '%s'" % (tool.get_name()))
|
34
|
+
|
35
|
+
langs = tool.get_available_languages()
|
36
|
+
print("Available languages: %s" % ", ".join(langs))
|
37
|
+
|
38
|
+
txt = tool.image_to_string( Image.open('tesseract.png'), lang='jpn', builder=pyocr.builders.TextBuilder())
|
39
|
+
print(txt)
|
40
|
+
```
|
41
|
+

|
42
|
+
|
43
|
+
実行結果
|
44
|
+
```Bash
|
45
|
+
$ python tesseract_test.py
|
46
|
+
Will use tool 'Tesseract (sh)'
|
47
|
+
Available languages: eng, jpn
|
48
|
+
d0g Cat
|
49
|
+
|
50
|
+
犬 猫
|
51
|
+
|
52
|
+
今日の天気は晴れです。
|
19
53
|
```
|