import cv2 as cv
import pytesseract
from PIL import Image
def recognize_text(image):
dst = cv.pyrMeanShiftFiltering(image, sp=10, sr=150)
gray = cv.cvtColor(dst, cv.COLOR_BGR2GRAY)
ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)
erode = cv.erode(binary, None, iterations=2)
dilate = cv.dilate(erode, None, iterations=1)
cv.imshow('dilate', dilate)
cv.bitwise_not(dilate, dilate)
cv.imshow('binary-image', dilate)
test_message = Image.fromarray(dilate)
text = pytesseract.image_to_string(test_message)
print(f'识别结果:{text}')
src = cv.imread(r"C:\img\1.png")
cv.imshow('input image', src)
recognize_text(src)
cv.waitKey(0)
cv.destroyAllWindows()
报错
OSError: [WinError 193] %1 不是有效的 Win32 应用程序。
想要实现
输出图片数字(验证码)