pip install pytesseract pip install opencv-python python import cv2 import pytesseract python def preprocess_image(image_path): img = cv2.imread(image_path) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (5, 5), 0) thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] return thresh python def recognize_text(image_path): image = preprocess_image(image_path) result = pytesseract.image_to_string(image, lang='chi_sim') return result python result = recognize_text('path/to/image.jpg') print(result)


上一篇:
下一篇:
切换中文