c#深度学习—PaddleOCRSharp(附示例源码)

PaddleOCRSharp是基于PaddleOCR的C++库,为.NET开发者提供了文本识别、检测和表格识别功能的简单封装。它具有低门槛、高精度和离线可用的特点,支持多种图像格式,并可通过Nuget包轻松集成到.NET项目中。
摘要由CSDN通过智能技术生成

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

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

目录

 一、准备环境

 二、nuget包安装:

 三、代码如下


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

该项目只支持x64cpu编译

一、准备环境

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

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

        

二、nuget包安装:

 三、代码如下

using PaddleOCRSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PaddleOCRSharp1._0
{
    public partial class Form1 : Form
    {
        //程序全局初始化一次即可,不必每次识别都初始化,容易报错。
        // 初始化OCR模型配置,默认中英文V3模型
        OCRModelConfig config = null;
        // 初始化OCR参数
        OCRParameter oCRParameter = new OCRParameter();
        // 创建一个OCR识别结果对象
        OCRResult ocrResult = new OCRResult();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 创建对象,设置文件过滤器
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";

            // 显示文件选择对话框,选择要识别文字的图像文件
            if (ofd.ShowDialog() != DialogResult.OK)
            {                
                return;
            }

            // 读取选择的图像文件的所有字节数据
            var imagebyte = File.ReadAllBytes(ofd.FileName);

            // 将字节数据转换成Bitmap图像对象
            Bitmap bitmap = new Bitmap(new MemoryStream(imagebyte));
        
            // 创建PaddleOCR引擎,使用之前初始化的配置和参数
            PaddleOCREngine engine = new PaddleOCREngine(config, oCRParameter);

            // 使用PaddleOCR引擎对图像进行文字识别
            // OCR识别结果会保存在ocrResult对象中
            
                ocrResult = engine.DetectText(bitmap);
            

            // 如果识别结果不为空,显示识别出的文字内容
            if (ocrResult != null)
            {
                // 弹出一个消息框,显示识别出的文字内容
                MessageBox.Show(ocrResult.Text, "识别结果");
            }

        }
    }
}

demo下载:https://download.csdn.net/download/m0_55074196/88364787

 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)icon-default.png?t=N7T8https://github.com/raoyutian/PaddleOCRSharp/tree/main

  • 17
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值