You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
9 months ago
|
'''
|
||
|
安装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('heipishu.txt', 'w', encoding='utf-8')
|
||
|
imgpath = './heipi/'
|
||
|
for num in range(1, 48):
|
||
|
fnum = format_number(num, 3)
|
||
|
img_path = f'{imgpath}1ff4059a-c814-46c4-b52b-fefd8b1de64c-{fnum}.png'
|
||
|
image = cv2.imread(img_path)
|
||
|
#cropped_img = image[:int(image.shape[0] * 0.80), :]
|
||
|
print(image)
|
||
|
result = ocr.ocr(image, 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()
|