c - 我可以使用什么策略对 Magic the Gathering 角文本进行 OCR?

标签 c algorithm go ocr

我需要识别 Magic the Gathering 纸牌(最后设计)左下角的文字。这里有一个例子:

enter image description here

如果文字是这样的 textocr 我想检索以下文本:

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 你得到

上半部分:

upper part

和下部:

enter image description here

而且 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/

相关文章:

c - vkCreateGraphicsPipelines 段错误在共享库中但不在静态库中

python - 通过循环创建二叉树

algorithm - 使用排序算法

csv - 始终引用 csv 值

c - Unix 套接字 C : Connecting from another network

c - 在公共(public)头文件中包含条件是否被认为是好的做法?

go - 如何将多个参数传递给 golang net rpc 调用

go - 在 OSX 上交叉编译 Go?

c - 需要帮助返回/传递多个数组

c# - 如何找到三次方程的所有正整数解?