openCVとPythonで画像からテキストを読み込むための基本的なスクリプトを作成しています。Python:Image to text
今、私はこのエラーを打ち明けましたが、ファイルが見つかりませんでした。問題はこのトレースバックを理解できません。どのファイルがありませんか?ライブラリやその他の問題 これはthresh.pngとremovednoise.pngを書いています。
私はPython 3.6で作業していますが、互換性の問題があれば教えてください。 詳細情報が必要な場合は、私にお知らせください。
私は指示に指向して助けてください。事前に感謝
私のコードです。
import cv2
import numpy as np
import pytesseract
from PIL import Image
#src_path ="D:/python'/practice"
def get_string(img_path):
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1, 1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
cv2.imwrite("removed_noise.png", img)
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
cv2.imwrite("thres.png", img)
result = pytesseract.image_to_string(Image.open("thres.png"))
return result
print ('------------TEXT------------')
print (get_string("imag1.png"))
エラーメッセージ:
D:\python'\practice>python OCR_text.py
------------TEXT------------
Traceback (most recent call last):
File "OCR_text.py", line 25, in <module>
print (get_string("imag1.png"))
File "OCR_text.py", line 18, in get_string
result = pytesseract.image_to_string(Image.open("thres.png"))
File "D:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "D:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "D:\Python\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "D:\Python\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
私はtesseractをC:ddirectoryにインストールしていて、D:directoryにpythonとpytestesseractを実行しているため、Tesseractがインストールされている可能性があります。 –
その問題のみでした。私はCディレクトリからTesseractをアンインストールし、Dディレクトリにインストールしました。ありがとう兄貴 –