TesseractError:(2,“用法:python pytesseract.py [-l lang] input_file”)

时间:2019-02-21 22:22:17

标签: python ocr tesseract python-tesseract

这是您如何开始使用Tesseract制作用于电表和水表读数的OCR引擎的基本实践

train_1=['F:\Misc\Meter Pics\mfaphotos\\'+ name for name in os.listdir('F:\Misc\Meter Pics\mfaphotos') if  os.path.isfile(os.path.join('F:\Misc\Meter Pics\mfaphotos', name))]
train_2=['F:\Misc\Meter Pics\mfa photos2\\' + name for name in os.listdir('F:\Misc\Meter Pics\mfa photos2') if os.path.isfile(os.path.join('F:\Misc\Meter Pics\mfa photos2', name))]
train=train_1 +train_2



for i in range(0,len(train)-1):
if train[i].split('.')[1]!='jpg':
    continue
img = cv2.resize(np.asarray(Image.open(train[i])) ,(300,300))
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Apply dilation and erosion to remove some noise
kernel = np.ones((1, 1), np.uint8)

img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
# Apply blur to smooth out the edges
img = cv2.GaussianBlur(img, (5, 5), 0)
# Apply threshold to get image with only b&w (binarization)
img = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
print(img)
# Save the filtered image in the output directory
type(Image.fromarray(img))
save_path = os.path.join('F:\Misc\Final_modified', train[i] + "_filter_" + ".jpg")
cv2.imwrite(save_path, img)

代码错误 -我们收到错误的代码

for i in range(0,len(train)-1):
save_path = os.path.join('F:\Misc\Final_modified', train[i] + "_filter_" + 
".jpg")
#Image.load(save_load)
result = pytesseract.image_to_string(Image.open(save_path), lang="eng")
results[save_path] = result

错误消息

TesseractError: (2, 'Usage: python pytesseract.py [-l lang] input_file')

问题-错误消息是什么意思?

0 个答案:

没有答案