0.源码:
import cv2 as cv
from PIL import Image
import pytesseract as tess
def recognize_demo(images):
gray = cv.cvtColor(images, cv.COLOR_BGR2GRAY)
ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)
cv.bitwise_not(binary, binary)
textImage = Image.fromarray(binary)
text = tess.image_to_string(textImage, lang='chi_sim')
print("识别结果为:", text)
cv.imshow("recognize_demo", binary)
if __name__ == "__main__":
images = cv.imread("../images/zhongwen.png")
cv.imshow("yuan_tu", images)
recognize_demo(images)
cv.waitKey(0)
cv.destroyAllWindows()