zoukankan      html  css  js  c++  java
  • 17、OpenCV Python 数字验证码识别

    __author__ = "WSX"
    import cv2 as cv
    import numpy as np
    from PIL import Image
    import pytesseract
    #pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-ORC/tesseract'
    
    def recognize_text( img ):
        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)
        kernel = cv.getStructuringElement(cv.MORPH_RECT, (1, 2))
        bin1 = cv.morphologyEx(binary, cv.MORPH_OPEN, kernel)
        kernel = cv.getStructuringElement(cv.MORPH_RECT, (2, 1))
        open_out = cv.morphologyEx(bin1, cv.MORPH_OPEN, kernel)
        cv.imshow("binary-image", open_out)
        cv.bitwise_not(open_out, open_out)
        textImage = Image.fromarray(open_out)
        text = tess.image_to_string(textImage)
        print("识别结果: %s"%text)
    
    def main():
        img = cv.imread("111.png")
        cv.namedWindow("Show", cv.WINDOW_AUTOSIZE)
        cv.imshow("Show", img)
        recognize_text(img)
        cv.waitKey(0)
        cv.destroyAllWindows()
    
    main()
  • 相关阅读:
    java中的静态变量与实例变量
    Java中的关键字this
    继承和多类的基础(C++)
    11-1:(42)接雨水
    10-2
    10-1
    9-2
    9-1
    8-2
    8-1
  • 原文地址:https://www.cnblogs.com/WSX1994/p/9155547.html
Copyright © 2011-2022 走看看