#refer to https://www.jianshu.com/p/f57165f34839 import cv2 import pytesseract # 读取身份证图像 image = cv2.imread('/Users/wangvivi/Desktop/Code/ocrtest/images/id_card.JPG') # 将图像转换为灰度 gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # 使用Tesseract进行文字识别 text = pytesseract.image_to_string(gray, lang='chi_sim') # 打印识别的文字 print(text)