我需要识别 Magic the Gathering 纸牌(最后设计)左下角的文字。这里有一个例子:
198/280 U
M20 EN
(我不需要卡片作者姓名 - 在这个例子中是 Lake Hurwitz)
我可以使用什么 OCR 库?我在没有任何调整的情况下尝试使用 Tesseract,但结果不正确。有任何建议或指向已经执行此操作的项目的链接吗?
最佳答案
您可以通过稍微清理图像来使用 tesseract (3.04.01) 制作它 就像下面的代码
import numpy as np
import cv2
def prepro(zone, prefix):
filename = 'stackmagic.png'
oriimg = cv2.imread(filename)
#keep the interesting part
(a,b,c,d) = zone
text_zone = oriimg[a:b, c:d]
height, width, depth = text_zone.shape
#resize it to be bigger (so less pixelized)
H = 50
imgScale = H/height
newX,newY = text_zone.shape[1]*imgScale, text_zone.shape[0]*imgScale
newimg = cv2.resize(text_zone,(int(newX),int(newY)))
#binarize it
gray = cv2.cvtColor(newimg, cv2.COLOR_BGR2GRAY)
th, img = cv2.threshold(gray, 130, 255, cv2.THRESH_BINARY);
#erode it
kernel = np.ones((1,1),np.uint8)
erosion = cv2.erode(img,kernel,iterations = 1)
cv2.imwrite(prefix+'_ero.png', erosion)
cv2.imshow("Show by CV2",erosion)
cv2.waitKey(0)
prepro((16,27, 6,130), 'upzone')
prepro((27,36, 6,130), 'downzone')
来自您的 cropped image 你得到
上半部分:
和下部:
而且 tesseract 似乎确实能够提取
xx$ tesseract upzone_ero.png stdout
198/ 280 U
xx$ tesseract downzone_ero.png stdout
M20 ~ EN Duluu Hun-nu
请注意,我们无法提取 Luke,但希望您对他/它不感兴趣 :)
还有其他工具,但那是广告内容并且是主观的..
关于c - 我可以使用什么策略对 Magic the Gathering 角文本进行 OCR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58450168/