美文网首页
27、数字验证码识别

27、数字验证码识别

作者: BigBigGuy | 来源:发表于2019-01-09 17:13 被阅读0次

1、opencv外加上PIL和 pytesseract 两个包
2、安转tesserac还需要安转OCR引擎
sudo apt-get install tesseract-ocr

需要额外用的pil和tesseract
import cv2 as cv
from PIL import Image
import pytesseract as tess


def recongnize_text(image):
    blur = cv.GaussianBlur(image,(55,55),0)
    gray = cv.cvtColor(blur, cv.COLOR_BGR2GRAY)
    ret, binary= cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)

    kernel = cv.getStructuringElement(cv.MORPH_RECT, (8, 8))
    bin = cv.morphologyEx(binary, cv.MORPH_OPEN, kernel)
    cv.imshow("binary_image", bin)

    cv.bitwise_not(bin, bin) #变成白色背景
    cv.imshow("binary_image2", bin)
    textImage = Image.fromarray(bin)
    text = tess.image_to_string(textImage)
    print("识别结果:%s" % text)

image.png

相关文章

网友评论

      本文标题:27、数字验证码识别

      本文链接:https://www.haomeiwen.com/subject/xqsgrqtx.html