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 官网资料