当前位置:网站首页>C#测试调用PaddleSharp模块识别图片文字
C#测试调用PaddleSharp模块识别图片文字
2022-04-23 05:16:00 【gc_2299】
PaddleSharp是PaddleInference C API的C#封装版本,支持在 Windows(x64)、NVIDIA GPU和Linux(Ubuntu-20.04 x64)中使用。PaddleShare主要包括PaddleOCR 和PaddleDetection,其中PaddleOCR 支持14种语言的文字,支持识别多种旋转角度的文字,PaddleDetection支持PPYolo检测模型和PicoDet模型(关于PaddleSharp的详细介绍见参考文献1)。
可以通过NuGet管理器下载PaddleSharp相关的包,最开始以为包名是以PaddleSharp开头,结果在NuGet管理器中什么都搜不到,在GitHub的PaddleSharp主页中,列出了PaddleSharp相关的包清单(如下图所示),其都以Sdcb开头,这些包在NuGet管理器中都可以搜索安装。
本文主要测试用C#调用PaddleSharp的PaddleOCR进行图片文字识别,参考文献2的PaddleOCR使用说明中列出了要安装的包清单,在VS中安装以下包(最初不想装这么多,就只安装了Sdcb.PaddleOCR,虽然程序可以编译通过,也可以运行,但是识别图片文字过程中会一直提示缺少下拉包清单中的某些,最终要想正常识别图片文字,还是需要把下面这些包都装全)。
Sdcb.PaddleInference
Sdcb.PaddleInference.runtime.win64.mkl
Sdcb.PaddleOCR
Sdcb.PaddleOCR.KnownModels
OpenCvSharp4
OpenCvSharp4.runtime.win
参照参考文献2中的示例代码进行功能测试(详细代码请到文献中查看,这里就不贴出来了),其代码顺序主要是加载模型->加载图片->识别文字->显示结果。这里主要说一下跟使用PaddleOCRSharp的不同点,由于都是简单测试,说的都是比较简单的。
PaddleOCRSharp和PaddleSharp都是其它语言编写的ocr功能的C#封装版本,相比之下PaddleOCRSharp封装的更简单一些。通过NuGet安装PaddleOCRSharp,会把依赖文件自动下载并关联到项目上,而PaddleSharp需要手动安装所有需要的包。
PaddleOCRSharp执行所需的模型在安装包时同步下载并关联到项目上,而PaddleSharp,从测试代码来看,其默认从C:\Users\HP\AppData\Roaming\paddleocr-models\ppocr-v2文件夹中读取所需的模型,如果不存在,则实时从网上下载的,OCRModel对象中记录了各类模型的下载路径(实际执行过程中,由于下载速度一般,直接用迅雷手动下载并复制到对应文件夹中)。
OCRModel model = KnownOCRModel.PPOcrV2;
await model.EnsureAll();
还有就是识别图片文字时,PaddleOCRSharp封装了一下,只需在程序中指定图片路径、图片字节数组或Image对象即可,而PaddleSharp识别图片的函数,PaddleOcrAll.Run,需要将图片转成指定的Mat对象。
PaddleSharp识别的结果包括两类,PaddleOcrResult.Text中将识别出的所有文字合并为一个字符串,PaddleOcrResult.Regions中保存识别出的每个文本块。
文本块类型为PaddleOcrResultRegion,其中Rect(类型为RotatedRect)保存包含文本的矩形位置信息(该矩形可能是非水平或垂直的)。RotatedRect类的定义如下图所示,其中BoundingRect函数返回包含旋转矩形的矩形。以下面的图片为例PaddleOcrResultRegion.Rect为红色矩形,而BoundingRect()返回的是紫色矩形。同时RotatedRect类的Points函数返回旋转矩形的四个角的点位置信息,可以通过绘制线条方式绘制包含文本的旋转矩形,这样简单一些。
最后列出测试图片的识别效果(使用参考文献中的示例代码,文本块基本都圈出来了,但其中的内容有部分没有正确识别)。
参考文献
[1]https://github.com/sdcb/PaddleSharp
[2]https://github.com/sdcb/PaddleSharp/blob/master/docs/ocr.md
测试图片来源
[1]https://baijiahao.baidu.com/s?id=1676249081188736513&wfr=spider&for=pc
[2]https://www.xjauto.net/html/cheping/202105/69508.html
[3]https://item.jd.com/10041422363991.html?openbpab=dontwritecookie&uabt=92_16_21&cu=true&utm_source=image.baidu.com&utm_medium=tuiguang&utm_campaign=t_1003608409_&utm_term=1a1dd3a2f0b24eaab2325b16b12d3d8d
[4]http://news.sohu.com/a/524033869_121124363
版权声明
本文为[gc_2299]所创,转载请带上原文链接,感谢
https://blog.csdn.net/gc_2299/article/details/124183823
边栏推荐
- 退出vim的方法
- Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
- This call when the transaction does not take effect
- Various ways of writing timed tasks of small programs
- PHP counts the number of files in the specified folder
- Using PHP post temporary file mechanism to upload arbitrary files
- Define defines constants and macros, pointers and structures
- scp命令详解
- Logrus set log format and output function name
- 和谐宿舍(线性dp / 区间dp)
猜你喜欢
Restful toolkit of idea plug-in
低代码和无代码的注意事项
The applet calls the function of scanning QR code and jumps to the path specified by QR code
Discussion on flow restriction
Let the LAN group use the remote device
直播带货表格模板-自动显示图片-自动关联系列商品
JS Array常见方法
Minimum spanning tree -- unblocked project hdu1863
2021-09-23
SQLyog的基本使用
随机推荐
Jupyter notebook crawling web pages
Basic use of sqlyog
深度学习笔记 —— 微调
工具在数字化转型中扮演了什么样的角色?
Swing display time (click once to display once)
Summary of R & D technology
The 8 diagrams let you see the execution sequence of async / await and promise step by step
Summary of MySQL knowledge points
深度学习笔记 —— 物体检测和数据集 + 锚框
Redis lost key and bigkey
低代码和无代码的注意事项
深度学习笔记 —— 语义分割和数据集
The vscode ipynb file does not have code highlighting and code completion solutions
Golang memory escape
Day. JS common methods
MySQL views the SQL statement details executed by the optimizer
MySQL realizes row to column SQL
What are instruction cycles, machine cycles, and clock cycles?
静态流水线和动态流水线的区别认识
[2021] Spatio-Temporal Graph Contrastive Learning