質問編集履歴

8

試したことの追記

2023/04/07 14:14

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -84,6 +84,11 @@
84
84
  の箇所はきちんとtesseract.exeの絶対パスを指定しています。
85
85
  (anaconda prompt にて where tesseractで表示された絶対パスが同じであることを確認済)
86
86
 
87
+ anaconda promptにて、
88
+ set TESSDATA_PREFIX=C:\Users\ユーザー名\anaconda3\pkgs\tesseract-5.3.0-...........\share\tessdata
89
+ を実行後、再度コードを実行。
90
+ →試してうまくいかないので追記。
91
+
87
92
 
88
93
  # 環境
89
94
  ・PyCharm Community Edition

7

全体の一部を修正

2023/04/05 14:49

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -85,4 +85,8 @@
85
85
  (anaconda prompt にて where tesseractで表示された絶対パスが同じであることを確認済)
86
86
 
87
87
 
88
+ # 環境
89
+ ・PyCharm Community Edition
90
+ ・anaconda3
91
+ ・windows10
88
92
 

6

環境項目の修正

2023/04/05 14:48

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -85,8 +85,4 @@
85
85
  (anaconda prompt にて where tesseractで表示された絶対パスが同じであることを確認済)
86
86
 
87
87
 
88
- # 環境
89
- ・PyCharm Community Edition
90
- ・anaconda3
91
- ・windows10
92
88
 

5

エラー表記の修正、他微細な調整。

2023/04/04 14:55

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -40,14 +40,14 @@
40
40
  ・anaconda promptにてtesseract versionからtesseract --list-langsから言語を確認
41
41
  → jpnとjpn_vertの両方を確認
42
42
 
43
- ・試しに日本語がはっきり書かれている画像をカレントディレクトリに置きテキストを読み取らせる
43
+ ・試しに日本語がはっきり書かれている画像をカレントディレクトリに置き下記のコードでテキストを読み取らせる
44
44
 
45
45
  ```python
46
46
  from PIL import Image
47
47
  import sys
48
48
 
49
49
  import pyocr
50
- import pyocr.build
50
+ import pyocr.builders
51
51
  pyocr.tesseract.TESSERACT_CMD = r'<full_path_to_your_tesseract.exe>'
52
52
  (pyocr.tesseract.TESSERACT_CMD = r'<full_path_to_your_pytesseract.exe>'としても同じ結果)
53
53
  tools = pyocr.get_available_tools()
@@ -61,21 +61,28 @@
61
61
  print(txt)
62
62
  ```
63
63
  環境変数などの設定は行っていません。
64
- TESSERACT_CMDの行抜きですと下記のようにエラーが出ました
64
+ 実行の際TESSERACT_CMDの行抜きですと下記のようにエラーが出ました
65
+
65
66
  ```python
67
+ C:\Users\ユーザ名\anaconda3\python.exe C:\Users\fユーザ名\PycharmProjects\PysimpleGUI\....\....\XXX.py
68
+ Will use tool 'Tesseract (sh)'
66
- line 15, in <module>
69
+ Traceback (most recent call last):
70
+ File "C:\Users\ユーザ名\PycharmProjects\PysimpleGUI\....\....\XXX.py", line 15, in <module>
67
71
  txt = tool.image_to_string(Image.open('test.png'),lang="jpn",builder=pyocr.builders.TextBuilder(tesseract_layout=6))
72
+ File "C:\Users\ユーザ名\anaconda3\lib\site-packages\pyocr\tesseract.py", line 372, in image_to_string
73
+ raise TesseractError(status, errors)
68
74
  pyocr.error.TesseractError: (1, b'Error opening data file ./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')
75
+
76
+ プロセスは終了コード 1 で終了しました
77
+
69
78
  ```
79
+ 行を入れた際はNo OCR tool found と出ます。
80
+ 未使用の import ステートメント 'import pyocr'
81
+ 'imported module pyocr' の参照 'tesseract' が見つかりませんと表示される。
70
82
 
71
83
  また、r'<full_path_to_your_tesseract.exe>'
72
84
  の箇所はきちんとtesseract.exeの絶対パスを指定しています。
73
- (where tesseractで絶対パスが同じであることを確認済)
85
+ anaconda prompt にて where tesseractで表示された絶対パスが同じであることを確認済)
74
-
75
- →No OCR tool found と出る。
76
- 未使用の import ステートメント 'import pyocr'
77
- 'imported module pyocr' の参照 'tesseract' が見つかりません
78
- とのこと(conda forge経由でtesseract,pyocrでダウンロードを確認済)
79
86
 
80
87
 
81
88
  # 環境

4

追記

2023/04/04 14:39

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -3,8 +3,7 @@
3
3
  動作確認のため下記のコードを実行したのですが
4
4
 
5
5
  Will use tool 'Tesseract (sh)'
6
- Available languages:
7
- Traceback (most recent call last):
6
+ Available languages: Traceback (most recent call last):
8
7
  File "C:\Users\.....\PycharmProjects\PysimpleGUI\XXXX.py", line 18, in <module>
9
8
  lang = langs[0]
10
9
  IndexError: list index out of range
@@ -62,13 +61,21 @@
62
61
  print(txt)
63
62
  ```
64
63
  環境変数などの設定は行っていません。
65
- TESSERACT_CMDの行抜きでも同様のエラーが出ましたし、r'<full_path_to_your_tesseract.exe>'
64
+ TESSERACT_CMDの行抜きですと下記ようにエラーが出ました
65
+ ```python
66
+ line 15, in <module>
67
+ txt = tool.image_to_string(Image.open('test.png'),lang="jpn",builder=pyocr.builders.TextBuilder(tesseract_layout=6))
68
+ pyocr.error.TesseractError: (1, b'Error opening data file ./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')
69
+ ```
70
+
71
+ また、r'<full_path_to_your_tesseract.exe>'
66
72
  の箇所はきちんとtesseract.exeの絶対パスを指定しています。
73
+ (where tesseractで絶対パスが同じであることを確認済)
67
74
 
68
75
  →No OCR tool found と出る。
69
76
  未使用の import ステートメント 'import pyocr'
70
77
  'imported module pyocr' の参照 'tesseract' が見つかりません
71
- とのこと
78
+ とのこと(conda forge経由でtesseract,pyocrでダウンロードを確認済)
72
79
 
73
80
 
74
81
  # 環境

3

コード修正および追記

2023/04/03 15:56

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -43,6 +43,7 @@
43
43
 
44
44
  ・試しに日本語がはっきり書かれている画像をカレントディレクトリに置きテキストを読み取らせる
45
45
 
46
+ ```python
46
47
  from PIL import Image
47
48
  import sys
48
49
 
@@ -59,7 +60,10 @@
59
60
 
60
61
  txt = tool.image_to_string(Image.open('test.png'),lang="jpn",builder=pyocr.builders.TextBuilder(tesseract_layout=6))
61
62
  print(txt)
63
+ ```
62
- 環境変数などの設定は行っていない
64
+ 環境変数などの設定は行っていません
65
+ TESSERACT_CMDの行抜きでも同様のエラーが出ましたし、r'<full_path_to_your_tesseract.exe>'
66
+ の箇所はきちんとtesseract.exeの絶対パスを指定しています。
63
67
 
64
68
  →No OCR tool found と出る。
65
69
  未使用の import ステートメント 'import pyocr'

2

コード修正

2023/04/03 15:52

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -13,8 +13,7 @@
13
13
  色々調べましたがごちゃごちゃになってわからないので解決策を教えてほしいです。
14
14
 
15
15
 
16
-
16
+ ```python
17
-
18
17
  from PIL import Image
19
18
  import sys
20
19
 
@@ -25,20 +24,15 @@
25
24
  if len(tools) == 0:
26
25
  print("No OCR tool found")
27
26
  sys.exit(1)
28
- #The tools are returned in the recommended order of usage
29
27
  tool = tools[0]
30
28
  print("Will use tool '%s'" % (tool.get_name()))
31
- #Ex: Will use tool 'libtesseract'
29
+
32
30
 
33
31
  langs = tool.get_available_languages()
34
32
  print("Available languages: %s" % ", ".join(langs))
35
33
  lang = langs[0]
36
34
  print("Will use lang '%s'" % (lang))
37
- #Ex: Will use lang 'fra'
38
- #Note that languages are NOT sorted in any way. Please refer
39
- #to the system locale settings for the default language
40
- #to use.
35
+ ```
41
-
42
36
 
43
37
  # 試したこと
44
38
  ・anaconda promptにてconda listにてPytesseract,tesseract,pyocrをインストールされているか、バージョンが最新かの確認

1

文法の修正

2023/04/01 15:31

投稿

Rance1119
Rance1119

スコア2

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  プログラミング勉強中の初心者です。
2
2
  anaconda環境のPycharmにてconda経由でPytesseract,tesseract,pyocrをインストールし、
3
- 動作確認のため下記のコードを実行したが
3
+ 動作確認のため下記のコードを実行したのです
4
4
 
5
5
  Will use tool 'Tesseract (sh)'
6
6
  Available languages: