質問編集履歴

1

追記

2021/12/01 06:45

投稿

Mercedes_Melvin
Mercedes_Melvin

スコア1

test CHANGED
File without changes
test CHANGED
@@ -91,3 +91,101 @@
91
91
  print(txt)
92
92
 
93
93
  ```
94
+
95
+ ###追記
96
+
97
+ 環境変数「TESSDATA_PREFIX」を設定しようと試みましたが
98
+
99
+ 改善の余地は見られませんでした。
100
+
101
+ 以下ソースコード
102
+
103
+ ```python
104
+
105
+ from PIL import Image
106
+
107
+ import sys
108
+
109
+ import os
110
+
111
+ import pyocr
112
+
113
+ import pyocr.builders
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+ TESSERACT_PATH = 'C:\Program Files (x86)\Tesseract-OCR'
122
+
123
+ TESSDATA_PATH = 'C:\Program Files (x86)\Tesseract-OCR\tessdata'
124
+
125
+
126
+
127
+ os.environ["PATH"] += os.pathsep +TESSERACT_PATH
128
+
129
+ os.environ["TESSDATA_PREFIX"] = TESSDATA_PATH
130
+
131
+
132
+
133
+ tools = pyocr.get_available_tools()
134
+
135
+ if len(tools) == 0:
136
+
137
+ print("p")
138
+
139
+ tool = tools[0]
140
+
141
+
142
+
143
+ print(tool)
144
+
145
+ picture = Image.open("test1.png")
146
+
147
+ txt = tool.image_to_string(
148
+
149
+ picture,
150
+
151
+ lang="jpn",
152
+
153
+ builder = pyocr.builders.TextBuilder(tesseract_layout = 3)
154
+
155
+ )
156
+
157
+ print(txt)
158
+
159
+
160
+
161
+ ```
162
+
163
+ 以下エラー内容
164
+
165
+ ```
166
+
167
+ <module 'pyocr.tesseract' from 'C:\Users\プライベート\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyocr\tesseract.py'>
168
+
169
+
170
+
171
+ Warning (from warnings module):
172
+
173
+ File "C:\Users\プライベート\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PIL\Image.py", line 975
174
+
175
+ warnings.warn(
176
+
177
+ UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
178
+
179
+ Traceback (most recent call last):
180
+
181
+ File "C:\Users\プライベート\Desktop\python\test.py", line 23, in <module>
182
+
183
+ txt = tool.image_to_string(
184
+
185
+ File "C:\Users\プライベート\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyocr\tesseract.py", line 369, in image_to_string
186
+
187
+ raise TesseractError(status, errors)
188
+
189
+ pyocr.error.TesseractError: (1, b'Error opening data file C:\Program Files (x86)\Tesseract-OCR\tessdata/jpn.traineddata\r\nPlease make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.\r\nFailed loading language \'jpn\'\r\nTesseract couldn\'t load any languages!\r\nCould not initialize tesseract.\r\n')
190
+
191
+ ```