作者:权利阳成_278 | 来源:互联网 | 2023-08-18 16:33
Open CV系列学习笔记(二十五)数字验证码识别
OpenCV+Tesserct-OCR
OpenCV预处理
Tesserct-OCR验证码识别
Tesserct-OCR去 http://pythonware.com/products/pil/
https://pypi.python.org/pypi/pytesseract去年装必须的API
代码:
import cv2 as cv
import numpy as np
from PIL import Image
import tesseract as tessdef recognize_text():gray = cv.cvtColor(src,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",open_out)cv.bitwise_not(open_out,open_out)textImage = Image.fromarray(open_out)text = tess.image_to_string(textImage)print("识别结果:%s"%text)print("--------HEllow Python-------")
src = cv.imread("E:/picture/43.jpg")
cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)
cv.imshow("input image",src)
recognize_text()
cv.waitKey(0)cv.destroyAllWindows()
结果:
完结。