[C#][原创]利用paddleocr.net库编写C#代码进行ocr检测和识别

PaddleOCR.NET是一个基于.NET framework4.5的C#库,使用的是paddleocr轻量级ocr检测和识别模型,目前PaddleOCR.NET只支持CPU版本,GPU版本后续会出来。

开发环境

  • windows10 x64
  • VS2019专业版
  • paddle_inference==2.1.1 cpu_avx_mkl
  • PaddleOCR-release-2.2
  • cmake==3.17.2
  • NET Framework4.5

使用教程

第一步引用PaddleOCR.NET库

第二步编写自己的代码:

案例一:仅做OCR检测,支持byte[],图片路径,和Bitmap,如果使用opencvsharp也可以扩展

Bitmap bmp = new Bitmap("D:\1.jpg");
Bitmap b = new Bitmap(bmp);
bmp.Dispose();
InferManager infer = new InferManager("config.txt",true,false);
var result = infer.Detect("D:\1.jpg");
pictureBox1.Image = infer.DrawImage(b,result);
infer.Dispose();

案例二:仅做OCR识别,单文本图片识别

InferManager infer = new InferManager("config.txt", false, true);
Bitmap bmp = new Bitmap("D:\line.jpg");
var result = infer.RecognizeOnly(bmp);
infer.Dispose();
MessageBox.Show(result.Text+"|"+result.Score);

案例三:对图片所有文本检测ocr检测和识别,并返回json数据格式

 InferManager infer = new InferManager("config.txt", true, true);  
 var result = infer.DetectAndRecognize("D:\\22.jpg");  
 Console.WriteLine(result);  
 infer.Dispose();

库地址:https://github.com/futureflsl/PaddleOCR.NET


版权声明:本文为FL1623863129原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。