import cv2 as cv
import numpy as np
from PIL import Image
import pytesseract as tess
def recognize_text():
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
ret, open_out = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)
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)
src = cv.imread("1.png")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
recognize_text()
cv.waitKey(0)
python+openCV图像处理(三十)
最新推荐文章于 2024-01-31 01:03:19 发布