簡體   English   中英

如何使用 pytesseract 從圖像中檢測數字?

[英]How to detect digits from images using pytesseract?

我正在嘗試從圖像中檢測文本,但由於某些未知原因而失敗。

import pytesseract as pt
from PIL import Image
import re
image = Image.open('sample.jpg')
custom_config = r'--oem 3 --psm 7 outbase digits'
number = pt.image_to_string(image, config=custom_config)
print('Number: ', number)
Number:  0 50 100 200 250 # This is the output that I am getting.
Expected --> 0,0,0,0,0,1,0,8

在原始/原始圖像輸入上使用 tesseract 的 OCR 可能不會給您預期的結果。 對於給定的圖像,使用灰度轉換和閾值操作可以獲得更好的結果

在此處輸入圖像描述

要執行轉換和閾值操作,您可以使用ImageMagick ,如下所示:

$ convert input_image.jpg -colorspace gray grayscale_image.jpg
$ convert grayscale_image.jpg -threshold 45% thresholded_image.jpg
$ convert thresholded_image.jpg -morphology Dilate Rectangle:4,3 dilated_binary.jpg
$ python run_tesseract.py
 00000109

一種更強大的 OCR 方法是通過訓練此處討論的 tesseract 引擎

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM