【问题标题】:How to help Tesseract identify the character in this simple image?如何帮助 Tesseract 识别这个简单图像中的角色?
【发布时间】:2016-06-26 07:03:38
【问题描述】:

这是我要处理的原始图像的链接:-

http://imgur.com/KpreCiZ

使用 opencv2 处理图像后,我得到以下结果:-

http://imgur.com/UbgUxFY

但即使使用上面的图像,Tesseract 也无法识别图像中的字符。这发生在许多与上述示例具有相同样式的图像中。

欢迎任何关于如何提高图像质量或使用其他 Tesseract 模式的建议。

此外,如果上述技术不起作用,请提出替代方案,例如训练 Tesseract 或使用其他 OCR 或方法?

谢谢

编辑:我也包含代码

        # Read the image
        im = cv2.imread("image.jpg")
        # Convert to grayscale and apply Gaussian filtering
        im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
        im_gray = cv2.GaussianBlur(im_gray, (5, 5), 0)
        # Threshold the image
        ret, im_th = cv2.threshold(im_gray, 90, 255, cv2.THRESH_BINARY_INV)

        # Find contours in the image
        ctrs, hier = cv2.findContours(im_th.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

        # Get rectangles contains each contour
        rects = [cv2.boundingRect(ctr) for ctr in ctrs]
        for rect in rects:
            # Only consider rects which are bigger than a certain area
            if rect[3]*rect[2] > 300:
                # Draw the rectangles
                    cv2.rectangle(im, (rect[0], rect[1]), (rect[0] + rect[2], rect[1] + rect[3]), (0, 255, 0), 3) 
                    # Make the rectangular region around the digit
                    leng = int(rect[3] * 1.6)
                    pt1 = int(rect[1] + rect[3] // 2 - leng // 2)
                    pt2 = int(rect[0] + rect[2] // 2 - leng // 2)
                    if pt2 < 0:
                        pt2 = rect[0] + rect[2]
                    roi = im_th[pt1:pt1+leng, pt2:pt2+leng]
                    # Invert the image such that the text is black and background is white
                    roi = (255-roi)
                    # roi is the final processed image
                    try:
                        cv2.imwrite("test.jpg", roi)
                        # call the terminal command: tesseract test.jpg out -psm 10
                        call(["tesseract", "test.jpg", "out", "-psm", "10"])
                        file = open('out.txt', 'rb+')
                        text = file.read()
                        file.close()
                        if text:
                            print text
                    except:
                        pass

【问题讨论】:

  • 我已经包含了代码..

标签: ocr tesseract


【解决方案1】:

我建议使用这种新字体来训练 tesseract,因为有些字符可以正常工作,有些则不能。假设您正在识别英文字母“e”,我猜想连接到“e”底部的向上部分正在抛弃结果。如果您按照文档创建一个新的 .traineddata 文件,训练过程相对简单,这基本上涉及添加示例字符,例如这个,并指定该字符实际上是 .box 文件中的“e”。

您也可以访问 Tesseracts 页面向Improve Quality提出建议

【讨论】:

    猜你喜欢
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2023-03-14
    • 2017-06-03
    • 1970-01-01
    相关资源
    最近更新 更多