''' 安装paddlepaddle cpu pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple gpu pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple 知乎上的答案 python -m pip install paddlepaddle==2.3.2 -i https://pypi.tuna.tsinghua.edu.cn/simple pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paddleocr 还是失败 pip install swig pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paddleocr --user ''' from paddleocr import PaddleOCR import paddle import cv2 def format_number(number, width): return f'{number:0{width}}' # 启动GPU paddle.set_device("gpu") ocr = PaddleOCR(use_angle_cls=True, lang='ch') f = open('huanbu.txt', 'w', encoding='utf-8') imgpath = './huanbu/' for num in range(1, 331): fnum = format_number(num, 3) img_path = f'{imgpath}{fnum}.png' image = cv2.imread(img_path) cropped_img = image[:int(image.shape[0] * 0.80), :] result = ocr.ocr(cropped_img, cls=True) # 只需运行一次即可下载模型并将其加载到内存中 for idx in range(len(result)): res = result[idx] for line in res: print(line[1][0]) f.write(f'{line[1][0]}') f.write('\n') f.close()