回答編集履歴

1

追記

2018/07/04 05:05

投稿

can110
can110

スコア38266

test CHANGED
@@ -1,6 +1,6 @@
1
1
  `conda`だと2.7しかないようですね。
2
2
 
3
- ```.bash
3
+ ```Bash
4
4
 
5
5
  $ conda install -c auto pyocr
6
6
 
@@ -20,7 +20,7 @@
20
20
 
21
21
  当方環境(Win10のWSL)にて`pip`にて3.6.x環境に導入でき、OCR動作しました。
22
22
 
23
- ```.bash
23
+ ```Bash
24
24
 
25
25
  $ pip install pyocr
26
26
 
@@ -35,3 +35,71 @@
35
35
  Successfully installed pyocr-0.5.1
36
36
 
37
37
  ```
38
+
39
+
40
+
41
+ tesseract_test.py
42
+
43
+ ```Python
44
+
45
+ from PIL import Image
46
+
47
+ import sys
48
+
49
+ import pyocr
50
+
51
+ import pyocr.builders
52
+
53
+
54
+
55
+ tools = pyocr.get_available_tools()
56
+
57
+ if len(tools) == 0:
58
+
59
+ print("No OCR tool found")
60
+
61
+ sys.exit(1)
62
+
63
+ tool = tools[0]
64
+
65
+ print("Will use tool '%s'" % (tool.get_name()))
66
+
67
+
68
+
69
+ langs = tool.get_available_languages()
70
+
71
+ print("Available languages: %s" % ", ".join(langs))
72
+
73
+
74
+
75
+ txt = tool.image_to_string( Image.open('tesseract.png'), lang='jpn', builder=pyocr.builders.TextBuilder())
76
+
77
+ print(txt)
78
+
79
+ ```
80
+
81
+ ![イメージ説明](46eb7caa681311e3d05b6cf55a65d9ee.png)
82
+
83
+
84
+
85
+ 実行結果
86
+
87
+ ```Bash
88
+
89
+ $ python tesseract_test.py
90
+
91
+ Will use tool 'Tesseract (sh)'
92
+
93
+ Available languages: eng, jpn
94
+
95
+ d0g Cat
96
+
97
+
98
+
99
+ 犬 猫
100
+
101
+
102
+
103
+ 今日の天気は晴れです。
104
+
105
+ ```