【问题标题】:Reading the characters from image - remove curve从图像中读取字符 - 删除曲线
【发布时间】:2021-02-18 05:48:54
【问题描述】:

我正在尝试从这张图片中读取字符。但两者之间的曲线阻碍了这个过程。有人可以帮我吗?如何从这些图像中提取字母?

img = cv2.imread('screenshot.png', 0)
ret, thresh_img = cv2.threshold(img, 125, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('grey image',thresh_img)
cv2.imwrite("result11.jpg", thresh_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

我尝试将其转换为灰度并去除波噪声。我做不到。请帮帮我。 OpenCV 新手。

【问题讨论】:

    标签: opencv ocr tesseract python-tesseract opencv-python


    【解决方案1】:

    您可以应用以下顺序:


    1-自适应阈值

    2-形态变换

    3-位运算

    第一步: Adaptive Threshold


    • 为同一图像的不同区域获取不同的阈值以获得更好的结果。

    • 结果:

    第二步:Morphological Transformation


    • 我们将申请:

      • 腐蚀后膨胀(开口)

      • 膨胀后腐蚀(关闭)

      • 结果:

    第三步: Bitwise operation

    • 对于提取图像的一部分很有用

    • 结果:

    现在如果我们从图像中读取,结果将是:

    dbdhm
    

    代码:


    import cv2
    import numpy as np
    import pytesseract
    
    img = cv2.imread("UzhPS.png")
    gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    flt = cv2.adaptiveThreshold(gry,
                                100, cv2.ADAPTIVE_THRESH_MEAN_C,
                                cv2.THRESH_BINARY, 13, 16)
    krn = np.ones((3, 3), np.uint8)
    opn = cv2.morphologyEx(flt, cv2.MORPH_OPEN, krn)
    cls = cv2.morphologyEx(opn, cv2.MORPH_CLOSE, krn)
    gry = cv2.bitwise_or(gry, cls)
    txt = pytesseract.image_to_string(gry)
    print(txt[2:])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-25
      • 2014-05-16
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多