[英]Tesseract unable to recognize numbers from a simple image
這是圖像,我正在嘗試提取“3158”
這是代碼
import cv2 import tesseract img = cv2.imread('cropped.png') convert_to_string = pytesseract.image_to_string(img) print (convert_to_string)
但不幸的是它沒有打印任何東西
我試過了
pytesseract.image_to_string(img,config=' --psm 1 --oem 3)
和
pytesseract.image_to_string(img,config=' --psm 6)
但仍然沒有運氣
嘗試先對圖像進行二值化,如果字體不能從背景中清晰地突出,則 Tesseract 無法正常工作。 由於背景中有漸變,因此您可能會通過自適應閾值預處理獲得一些初步的好結果:
import cv2
import pytesseract
img = cv2.imread('cropped.png')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_bin = cv2.adaptiveThreshold(
img_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 10
)
img_bin = cv2.cvtColor(img_bin, cv2.COLOR_GRAY2BGR)
convert_to_string = pytesseract.image_to_string(img_bin)
print(convert_to_string)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.