C# PaddleOCR字符识别

1 安装Nuget

2 C#

cs 复制代码
using System;
using OpenCvSharp;
using Sdcb.PaddleOCR;
using Sdcb.PaddleOCR.Models.Local;
using Sdcb.PaddleOCR.Models;
using Sdcb.PaddleInference;


namespace ConsoleApp1
{
    public class MichaelOCR
    {
        string imagePath = "D:\\BUFFER\\VS\\Text\\ConsoleApp1\\2.jpg";

        public static int myAdd(int x, int y)
        {
            return x + y;

            Console.WriteLine("Hello World!");

        }


        public static string Poem()
        {
            return "heelo world" +
                "world----";
        }



        static void Main(string[] args)
        {
            string imagePath = "D:\\BUFFER\\VS\\Text\\ConsoleApp1\\2.jpg";
            FullOcrModel model = LocalFullModels.ChineseV3;
            Console.WriteLine(PaddleConfig.Version);


            using (PaddleOcrAll all = new PaddleOcrAll(model, PaddleDevice.Mkldnn())
            {
                AllowRotateDetection = true, /* 允许识别有角度的文字 */
                Enable180Classification = false, /* 允许识别旋转角度大于90度的文字 */
            })
            {
                // Load local file by following code:
                using (Mat src2 = Cv2.ImRead(imagePath))
                {
                    PaddleOcrResult result = all.Run(src2);
                    Console.WriteLine(result.Text);
                }
            }
            Console.WriteLine("Hello World!");
        }


        //下面是生成C# dll的

        //public static string Main(string imagePath)
        //{
        //    FullOcrModel model = LocalFullModels.ChineseV3;
        //    //Console.WriteLine(PaddleConfig.Version);


        //    using (PaddleOcrAll all = new PaddleOcrAll(model, PaddleDevice.Mkldnn())

        //    {
        //        AllowRotateDetection = true, /* 允许识别有角度的文字 */
        //        Enable180Classification = false, /* 允许识别旋转角度大于90度的文字 */
        //    })
        //    {

        //        // Load local file by following code:
        //        using (Mat src2 = Cv2.ImRead(imagePath))
        //        {
        //            PaddleOcrResult result = all.Run(src2);

        //            return result.Text;
        //            //Console.WriteLine(result.Text);
        //        }
        //    }
        //    //Console.WriteLine("Hello World!");
        //}
    }
}

3 官网资料

https://github.com/sdcb/PaddleSharp

相关推荐
dhxhsgrx2 小时前
PYTHON训练营DAY25
java·开发语言·python
敲代码的 蜡笔小新4 小时前
【行为型之中介者模式】游戏开发实战——Unity复杂系统协调与通信架构的核心秘诀
unity·设计模式·c#·中介者模式
风逸hhh4 小时前
python打卡day25@浙大疏锦行
开发语言·python
刚入门的大一新生4 小时前
C++初阶-string类的模拟实现与改进
开发语言·c++
程序猿多布5 小时前
使用Visual Studio将C#程序发布为.exe文件
c#·visual studio
chxii6 小时前
5java集合框架
java·开发语言
老衲有点帅6 小时前
C#多线程Thread
开发语言·c#
C++ 老炮儿的技术栈6 小时前
什么是函数重载?为什么 C 不支持函数重载,而 C++能支持函数重载?
c语言·开发语言·c++·qt·算法
IsPrisoner6 小时前
Go语言安装proto并且使用gRPC服务(2025最新WINDOWS系统)
开发语言·后端·golang