diff --git a/App_Code/BitmapHelper.cs b/App_Code/BitmapHelper.cs new file mode 100644 index 0000000..3c991ce --- /dev/null +++ b/App_Code/BitmapHelper.cs @@ -0,0 +1,32 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; + + +public static class BitmapHelper +{ + + public static Stream ToStream(this Bitmap bitmap) + { + MemoryStream ms = new MemoryStream(); + bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); + ms.Seek(0, SeekOrigin.Begin); + return ms; + } + + + public static byte[] Bitmap2Byte(this Bitmap bitmap) + { + using (MemoryStream stream = new MemoryStream()) + { + bitmap.Save(stream, ImageFormat.Jpeg); + byte[] data = new byte[stream.Length]; + stream.Seek(0, SeekOrigin.Begin); + stream.Read(data, 0, Convert.ToInt32(stream.Length)); + return data; + } + } + +} + diff --git a/App_Code/CommonUse.cs b/App_Code/CommonUse.cs index 2a53ffb..5b993e9 100644 --- a/App_Code/CommonUse.cs +++ b/App_Code/CommonUse.cs @@ -171,7 +171,7 @@ public class CommonUse CommonUse commonUse = new CommonUse(); - string[] postionc = postionCut.Split('^'); + string[] postionc = postionCut.Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries); PYPostion = ""; Point GrXY; int PostionWW = 0; diff --git a/App_Code/OcrHelper.cs b/App_Code/OcrHelper.cs new file mode 100644 index 0000000..af6bada --- /dev/null +++ b/App_Code/OcrHelper.cs @@ -0,0 +1,65 @@ +using PaddleOCRSharp; +using System; +using System.Drawing; + +public class OcrHelper +{ + + //private static TesseractEngine engine = new TesseractEngine("./ocr_models", "chi_sim"); + //public static OCRResult GetOcrResult(Bitmap bitmap) + //{ + // try + // { + // using var tempBitmap = new Bitmap(bitmap); + // var ocrResult = paddleOCREngine.DetectText(tempBitmap); + // return ocrResult; + // } + // catch (Exception ex) + // { + // ExceptionNotice.SendAsync(ex, "Ocr文字识别异常!"); + // throw; + // } + //} + + private static string RootDirectory = EngineBase.GetRootDirectory().TrimEnd('\\') + "\\inference"; + + //建议程序全局初始化一次即可,不必每次识别都初始化,容易报错。 + private static PaddleOCREngine paddleOCREngine = paddleOCREngine = new PaddleOCREngine(new OCRModelConfig() + { + det_infer = RootDirectory + "\\ch_PP-OCRv3_det_infer", + cls_infer= RootDirectory + "\\ch_ppocr_mobile_v2.0_cls_infer", + rec_infer = RootDirectory + "\\ch_PP-OCRv3_rec_infer", + keys = RootDirectory + "\\ppocr_keys.txt", + }, new OCRParameter()); + + public static OCRResult GetOcrResult(Bitmap bitmap) + { + try + { + using (var tempBitmap = new Bitmap(bitmap)) + { + return paddleOCREngine.DetectText(tempBitmap); + } + } + catch (Exception ex) + { + throw; + } + } + + public static OCRResult GetOcrResult(byte[] bytes) + { + try + { + var ocrResult = paddleOCREngine.DetectText(bytes); + return ocrResult; + } + catch (Exception ex) + { + + throw; + } + } + +} + diff --git a/Bin/Newtonsoft.Json.dll b/Bin/Newtonsoft.Json.dll index 766ba57..d0aaed9 100644 Binary files a/Bin/Newtonsoft.Json.dll and b/Bin/Newtonsoft.Json.dll differ diff --git a/Temp/Default.aspx b/Temp/Default.aspx index 5145e9a..9dc2b37 100644 --- a/Temp/Default.aspx +++ b/Temp/Default.aspx @@ -70,28 +70,31 @@