本文介紹了從圖像中識別數字的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試從游戲截圖中提取數字.
I am to from in game .
我正在嘗試提取:
98
3430
5/10
98
3430
5/10
from PIL import Image
import pytesseract
image="D:/img/New folder (2)/1.png"
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
text = pytesseract.image_to_string(Image.open(image),lang='eng',config='--psm 5')
print(text)
輸出是亂碼
‘t hl) keteeeees
ek pSlaerenen
JU) pgrenmnreserenny
Rates B
d dali eas. 5
cle aM (Sores
|, S| pgranmrerererecons
a cee 3

pea 3
oS :
(geo eenee
ey
=
es A
推薦答案
好的,所以我嘗試將其更改為灰度、反向對比度或使用不同的閾值,但這似乎都相當不準確.問題似乎是傾斜和較小的數字.你沒有任何 hiher res 圖像嗎?我能得到的最準確的是以下代碼.
okay, so I tried it into , or use , but it all seems to be .The issue seems to be the and . You do not to have any hiher res image? Most I could get was the code.
import cv2
import pytesseract
import imutils
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread('D:/img/New folder (2)/1.png') #test.png is your original image
img = imutils.resize(img, width=1400)
crop = img[340:530, 100:400]

data = pytesseract.image_to_string(crop,config=' --psm 1 --oem 3 -c tessedit_char_whitelist=0123456789/')
print(data)
cv2.imshow('crop', crop)
cv2.waitKey()
否則我推薦其中一種方法python識別圖片中數字,如類似問題中所述或在這個.
I one of these as in the in this one.
這篇關于從圖像中識別數字的文章就介紹到這了python識別圖片中數字,希望我們推薦的答案對大家有所幫助,也希望大家多多支持IT屋!