1.使用NuGet 下载安装
- OpenCvSharp4
- OpenCVSharp4.runtime.win
- Sdcb.OpenVINO
- Sdcb.OpenVINO.runtime.win-x64
- Sdcb.OpenVINO.PaddleOCR
- Sdcb.OpenVINO.PaddleOCR.Models.Online
2.编写使用代码
我这个方法是传入图片的字节数据
public class VinoOcrHandler
{
public static async Task<string> handlerImgAsync(byte[] sampleImageData)
{
Settings.GlobalModelDirectory = ".\\Models";
FullOcrModel model = await OnlineFullModels.ChineseV3.DownloadAsync();
using (PaddleOcrAll all = new PaddleOcrAll(model)
{
AllowRotateDetection = true, /* 允许识别有角度的文字 */
Enable180Classification = false, /* 允许识别旋转角度大于90度的文字 */
})
{
// Load local file by following code:
// using (Mat src2 = Cv2.ImRead(@"C:\test.jpg"))
using (Mat src = Cv2.ImDecode(sampleImageData, ImreadModes.Color))
{
PaddleOcrResult result = all.Run(src);
//Console.WriteLine("Detected all texts: \n" + result.Text);
return result.Text;
}
}
}
}
Settings.GlobalModelDirectory = ".\\Models";
非常重要,在初次使用时,会将支持文件下载到这个目录,在发布的时候需要把这个目录拷贝到对应的目录下
下次使用就不会再下载了