macos m2 百度paddleocr文字识别 python

创建了一个虚拟环境:conda create -n orc python==3.11.7

进入虚拟环境后执行2条命令

bash 复制代码
pip install paddleocr -i https://pypi.tuna.tsinghua.edu.cn/simple  

pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple​
​

安装好后,在网上找了一段识别图片的代码,文字识别的精度还挺高的

python 复制代码
######################1.文字识别#########################
from paddleocr import PaddleOCR, draw_ocr
# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True,# 设置使用方向分类器识别180度旋转文字,处理一些不是正放的文字
                use_gpu=True,#使用gpu
                lang="ch"#中文识别
                )
img_path = 'orc1.jpg'
result = ocr.ocr(img_path, cls=True)#进行识别
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)

#######################2.生成目标检测的图片,用检测框框选文字#########################
# 显示结果
# 如果本地没有simfang.ttf,可以在doc/fonts目录下下载
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='Songti.ttc') #字体文件可引用路径,或复制到目录下
im_show = Image.fromarray(im_show)
im_show.save('resultx.jpg')

效果

各库版本

bash 复制代码
(orc) mwj@mwjdeMac-mini orcBD % pip list
Package                Version
---------------------- -----------
anyio                  4.4.0
astor                  0.8.1
attrdict               2.0.1
Babel                  2.15.0
bce-python-sdk         0.9.17
beautifulsoup4         4.12.3
blinker                1.8.2
cachetools             5.3.3
certifi                2024.6.2
charset-normalizer     3.3.2
click                  8.1.7
contourpy              1.2.1
cssselect              1.2.0
cssutils               2.11.1
cycler                 0.12.1
Cython                 3.0.10
decorator              5.1.1
et-xmlfile             1.1.0
fire                   0.6.0
Flask                  3.0.3
flask-babel            4.0.0
fonttools              4.53.0
future                 1.0.0
h11                    0.14.0
httpcore               1.0.5
httpx                  0.27.0
idna                   3.7
imageio                2.34.2
imgaug                 0.4.0
itsdangerous           2.2.0
Jinja2                 3.1.4
kiwisolver             1.4.5
lazy_loader            0.4
lmdb                   1.5.1
lxml                   5.2.2
MarkupSafe             2.1.5
matplotlib             3.9.0
more-itertools         10.3.0
networkx               3.3
numpy                  1.26.0
opencv-contrib-python  4.6.0.66
opencv-python          4.6.0.66
opencv-python-headless 4.10.0.84
openpyxl               3.1.5
opt-einsum             3.3.0
packaging              24.1
paddleocr              2.7.3
paddlepaddle           2.6.1
pandas                 2.2.2
pdf2docx               0.5.8
pillow                 10.3.0
pip                    24.0
premailer              3.10.0
protobuf               5.27.2
psutil                 6.0.0
pyclipper              1.3.0.post5
pycryptodome           3.20.0
PyMuPDF                1.24.7
PyMuPDFb               1.24.6
pyparsing              3.1.2
python-dateutil        2.9.0.post0
python-docx            1.1.2
pytz                   2024.1
PyYAML                 6.0.1
rapidfuzz              3.9.3
rarfile                4.2
requests               2.32.3
scikit-image           0.24.0
scipy                  1.14.0
setuptools             70.1.1
shapely                2.0.4
six                    1.16.0
sniffio                1.3.1
soupsieve              2.5
termcolor              2.4.0
tifffile               2024.6.18
tqdm                   4.66.4
typing_extensions      4.12.2
tzdata                 2024.1
urllib3                2.2.2
visualdl               2.5.3
Werkzeug               3.0.3
wheel                  0.43.0
(orc) mwj@mwjdeMac-mini orcBD % 

经过测试在win环境下同样适用

相关推荐
m0_748554813 小时前
golang如何实现用户订阅偏好管理_golang用户订阅偏好管理实现总结
jvm·数据库·python
smj2302_796826523 小时前
解决leetcode第3911题.移除子数组元素后第k小偶数
数据结构·python·算法·leetcode
阿正呀4 小时前
Redis怎样实现本地缓存的高效失效通知
jvm·数据库·python
九转成圣4 小时前
Java 性能优化实战:如何将海量扁平数据高效转化为类目字典树?
java·开发语言·json
SmartRadio4 小时前
ESP32-S3 双模式切换实现:兼顾手机_路由器连接与WiFi长距离通信
开发语言·网络·智能手机·esp32·长距离wifi
2501_901200534 小时前
mysql如何设置InnoDB引擎参数_优化innodb_buffer_pool
jvm·数据库·python
laowangpython4 小时前
Rust 入门:GitHub 热门内存安全编程语言
开发语言·其他·rust·github
我叫汪枫4 小时前
在后台管理系统中,如何递归和选择保留的思路来过滤菜单
开发语言·javascript·node.js·ecmascript
_.Switch4 小时前
东方财富股票数据JS逆向:secids字段和AES加密实战
开发语言·前端·javascript·网络·爬虫·python·ecmascript
软件技术NINI4 小时前
webkit简介及工作流程
开发语言·前端·javascript·udp·ecmascript·webkit·yarn