• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

c#深度学习—PaddleOCRSharp附展示源码

武飞扬头像
亦陈不染
帮助1

PaddleOCRSharp是基于PaddleOCR的C 代码修改并封装的.NET工具类库,支持文本识别、文本检测、基于文本检测结果的统计分析的表格识别功能。

PaddleOCRSharp封装极其简化,实际调用仅几行代码,极大的方便了中下游开发者的使用和降低了PaddleOCR的使用入门级别,同时提供不同的.NET框架使用,方便各个行业应用开发与部署。Nuget包即装即用,可以离线部署,不需要网络就可以识别的高精度中英文OCR。

目录

 一、准备环境

 二、nuget包安装:

 三、代码如下


跑通了例程代码并根据建议进行了些许优化,代码中注释详细,自行阅读。

该项目只支持x64cpu编译

一、准备环境

1、先创建一个窗体项目,添加一个按钮(我的是VS2017)

2、项目-属性-生成。配置和图中一样即可

学新通        

学新通

二、nuget包安装:

学新通

 三、代码如下

  1.  
    using PaddleOCRSharp;
  2.  
    using System;
  3.  
    using System.Collections.Generic;
  4.  
    using System.ComponentModel;
  5.  
    using System.Data;
  6.  
    using System.Drawing;
  7.  
    using System.IO;
  8.  
    using System.Linq;
  9.  
    using System.Text;
  10.  
    using System.Threading.Tasks;
  11.  
    using System.Windows.Forms;
  12.  
     
  13.  
    namespace PaddleOCRSharp1._0
  14.  
    {
  15.  
    public partial class Form1 : Form
  16.  
    {
  17.  
    //程序全局初始化一次即可,不必每次识别都初始化,容易报错。
  18.  
    // 初始化OCR模型配置,默认中英文V3模型
  19.  
    OCRModelConfig config = null;
  20.  
    // 初始化OCR参数
  21.  
    OCRParameter oCRParameter = new OCRParameter();
  22.  
    // 创建一个OCR识别结果对象
  23.  
    OCRResult ocrResult = new OCRResult();
  24.  
     
  25.  
    public Form1()
  26.  
    {
  27.  
    InitializeComponent();
  28.  
    }
  29.  
     
  30.  
    private void button1_Click(object sender, EventArgs e)
  31.  
    {
  32.  
    // 创建对象,设置文件过滤器
  33.  
    OpenFileDialog ofd = new OpenFileDialog();
  34.  
    ofd.Filter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
  35.  
     
  36.  
    // 显示文件选择对话框,选择要识别文字的图像文件
  37.  
    if (ofd.ShowDialog() != DialogResult.OK)
  38.  
    {
  39.  
    return;
  40.  
    }
  41.  
     
  42.  
    // 读取选择的图像文件的所有字节数据
  43.  
    var imagebyte = File.ReadAllBytes(ofd.FileName);
  44.  
     
  45.  
    // 将字节数据转换成Bitmap图像对象
  46.  
    Bitmap bitmap = new Bitmap(new MemoryStream(imagebyte));
  47.  
     
  48.  
    // 创建PaddleOCR引擎,使用之前初始化的配置和参数
  49.  
    PaddleOCREngine engine = new PaddleOCREngine(config, oCRParameter);
  50.  
     
  51.  
    // 使用PaddleOCR引擎对图像进行文字识别
  52.  
    // OCR识别结果会保存在ocrResult对象中
  53.  
     
  54.  
    ocrResult = engine.DetectText(bitmap);
  55.  
     
  56.  
     
  57.  
    // 如果识别结果不为空,显示识别出的文字内容
  58.  
    if (ocrResult != null)
  59.  
    {
  60.  
    // 弹出一个消息框,显示识别出的文字内容
  61.  
    MessageBox.Show(ocrResult.Text, "识别结果");
  62.  
    }
  63.  
     
  64.  
    }
  65.  
    }
  66.  
    }

 PaddleOCRSharp的github:

raoyutian/PaddleOCRSharp: This project is modified and encapsulated by C code based on Baidu PaddlePaddle OCR. Net class library. It includes the table recognition function of text recognition, text detection and statistical analysis based on text detection results. At the same time, it is optimized to improve the recognition accuracy in the case of inaccurate small image recognition. The project encapsulation is extremely simplified, and the actual call is only one line of code, which greatly facilitates the use of middle and downstream developers and reduces the entry level of paddleocr. At the same time, different functions are provided Net framework to facilitate application development and deployment in various industries. (github.com)学新通https://github.com/raoyutian/PaddleOCRSharp/tree/main

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhghfcke
系列文章
更多 icon
同类精品
更多 icon
继续加载