From 31bf0fad61e7ef665fe3eaef61c803be5504a57e Mon Sep 17 00:00:00 2001 From: JanusTida <1250244560@qq.com> Date: Sat, 25 Mar 2023 14:30:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E7=9B=AE=E6=A0=87=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E5=A4=A7=E4=BA=8E=E7=AD=89=E4=BA=8E.net=20framework4.6?= =?UTF-8?q?=E6=88=96=E8=80=85=E4=B8=BA.net=20core=E6=97=B6,=E4=BD=BF?= =?UTF-8?q?=E7=94=A8AppContext.BaseDirectory=E6=9D=A5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=9A=84=E5=BD=93=E5=89=8D=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E4=BF=AE=E5=A4=8D=E5=BC=95=E7=94=A8=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E4=BD=BF=E7=94=A8=E5=8D=95=E6=96=87=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E6=97=B6=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PaddleOCRSharp/PaddleOCREngine.cs | 3 ++- PaddleOCRSharp/PaddleStructureEngine.cs | 2 +- PaddleOCRSharp/PathUtils.cs | 27 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 PaddleOCRSharp/PathUtils.cs diff --git a/PaddleOCRSharp/PaddleOCREngine.cs b/PaddleOCRSharp/PaddleOCREngine.cs index 0503bc3..491c22b 100644 --- a/PaddleOCRSharp/PaddleOCREngine.cs +++ b/PaddleOCRSharp/PaddleOCREngine.cs @@ -49,6 +49,7 @@ namespace PaddleOCRSharp #endregion #region 文本识别 + /// /// PaddleOCR识别引擎对象初始化 /// @@ -67,7 +68,7 @@ namespace PaddleOCRSharp if (parameter == null) parameter = new OCRParameter(); if (config == null) { - string root = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string root = PathUtils.GetRootDirectory(); config = new OCRModelConfig(); string modelPathroot = root + @"\inference"; config.det_infer = modelPathroot + @"\ch_PP-OCRv3_det_infer"; diff --git a/PaddleOCRSharp/PaddleStructureEngine.cs b/PaddleOCRSharp/PaddleStructureEngine.cs index 490e1a6..2309476 100644 --- a/PaddleOCRSharp/PaddleStructureEngine.cs +++ b/PaddleOCRSharp/PaddleStructureEngine.cs @@ -56,7 +56,7 @@ namespace PaddleOCRSharp if (parameter == null) parameter = new StructureParameter(); if (config == null) { - string root = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string root = PathUtils.GetRootDirectory(); config = new StructureModelConfig(); string modelPathroot = root + @"\inference"; diff --git a/PaddleOCRSharp/PathUtils.cs b/PaddleOCRSharp/PathUtils.cs new file mode 100644 index 0000000..e6bf1bb --- /dev/null +++ b/PaddleOCRSharp/PathUtils.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace PaddleOCRSharp +{ + /// + /// 路径相关方法; + /// + static class PathUtils + { + /// + /// 获取程序的当前路径; + /// + /// + public static string GetRootDirectory() + { +#if NET46_OR_GREATER || NETCOREAPP + return AppContext.BaseDirectory; +#else + return Path.GetDirectoryName(typeof(PathUtils).Assembly.Location); +#endif + } + } +} -- Gitee