![](/img/trans.png)
[英]issues with char recognition in pytesseract/tesseract-OCR. Recognize '+' as '4'
[英]Problem With Char Recognition pytesseract/tesseract-OCR/ Won't Recognize
如標題中所述,我無法識別字符,正方體無法識別任何數字。 我如何解決這個問題?
圖片:
代碼:
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\\Tesseract-OCR\tesseract.exe'
img = cv2.imread('img002.png')
img = cv2.resize(img, None, fx=3, fy=3, interpolation=cv2.INTER_CUBIC)
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thr = cv2.threshold(gry, 100, 128, cv2.THRESH_BINARY_INV)[1]
cv2.imshow('Show', thr)
cv2.waitKey(0)
cmd = pytesseract.image_to_string(thr)
xx = pytesseract.image_to_boxes(thr)
print(cmd)
print(xx)
我的 Output
ann
a 8 0 34 0 0
n 50 0 75 0 0
n 92 0 118 0 0
對於第一張和第三張圖像,您可以找到包括OTSU 閾值的數字。
thresh = cv2.threshold(grey, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
該技術對第二個圖像沒有用:
我們需要改變閾值方法
thresh = cv2.threshold(crop, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
如果我們逐行
不幸的是, 8
未被識別。 您需要應用不同的組合來查找8
。
代碼:
import cv2
import pytesseract
names = ["C2GJJ.png", "GKH7k.png", "neIWN.png"]
for name in names:
image = cv2.imread(name)
(height, width) = image.shape[:2]
image = cv2.resize(image, (width*4, height*4))
grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(grey, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
text = pytesseract.image_to_string(thresh, config="--psm 6 digits")
print(text)
cv2.imshow("result", thresh)
cv2.waitKey(0)
second_image = cv2.imread("GKH7k.png")
(height, width) = second_image.shape[:2]
second_image = cv2.resize(second_image, (width * 4, height * 4))
second_grey = cv2.cvtColor(second_image, cv2.COLOR_BGR2GRAY)
start = 0
end = int(height/2) + 20
for _ in range(0, 3):
crop = second_grey[start:end, 0:width]
(height_crop, width_crop) = crop.shape[:2]
crop = cv2.resize(crop, (width_crop*2, height_crop*2))
second_thresh = cv2.threshold(crop, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
second_text = pytesseract.image_to_string(second_thresh,
config="--psm 6 digits")
print(second_text)
start = end
end = start + int(height/2) + 40
cv2.imshow("second_thresh", second_thresh)
cv2.waitKey(0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.