Commit 5fb72a03 张东亮

添加dll版paddle

1 个父辈 8e5c4804
正在显示 72 个修改的文件 包含 1353 行增加283 行删除
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
......
...@@ -228,7 +228,7 @@ namespace BLL ...@@ -228,7 +228,7 @@ namespace BLL
private void PrintLabel(object sender, EventArgs e) private void PrintLabel(object sender, EventArgs e)
{ {
LogNet.log.Debug("Enter PrintLabel Method"); LogNet.log.Debug("Enter PrintLabel Method");
if (lastkey == null) return;
//Dictionary<string, string> key = new(); //Dictionary<string, string> key = new();
for (int i = 0; i < extensions.Count; i++) for (int i = 0; i < extensions.Count; i++)
{ {
......
...@@ -375,7 +375,7 @@ namespace BLL ...@@ -375,7 +375,7 @@ namespace BLL
xmlDoc.Save(temp.FilePath); xmlDoc.Save(temp.FilePath);
temp.State = TemplateState.Saved; temp.State = TemplateState.Saved;
} }
string pythonEnvPath = ConfigHelper.Config.Get("pythonEnvPath", "C:\\ProgramData\\miniconda3\\envs\\paddle_env\\");
private bool TemplateExtract(int index, List<BarcodeInfo> code, out Dictionary<string, string> keyword, out bool[] isCodeUsed) private bool TemplateExtract(int index, List<BarcodeInfo> code, out Dictionary<string, string> keyword, out bool[] isCodeUsed)
{ {
keyword = new(StringComparer.OrdinalIgnoreCase); keyword = new(StringComparer.OrdinalIgnoreCase);
...@@ -429,7 +429,7 @@ namespace BLL ...@@ -429,7 +429,7 @@ namespace BLL
string codeOcr = ""; string codeOcr = "";
if (algro) if (algro)
{ {
codeOcr=PaddleOCRHelper.StartTest(pythonEnvPath+"python.exe", ".\\paddleOCR.py", ".\\ocr.jpg"); codeOcr=PaddleOCRHelper.StartTest("..\\ocr.jpg");
} }
else else
{ {
...@@ -449,6 +449,10 @@ namespace BLL ...@@ -449,6 +449,10 @@ namespace BLL
} }
} }
#endregion ocr文字提取结束 #endregion ocr文字提取结束
if(string.IsNullOrEmpty(codeOcr))
{
codeOcr = PaddleOCRHelper.StartTest("..\\ocr.jpg");
}
} }
......
...@@ -6,7 +6,10 @@ using System.Diagnostics; ...@@ -6,7 +6,10 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
...@@ -14,8 +17,7 @@ namespace BLL ...@@ -14,8 +17,7 @@ namespace BLL
{ {
public class PaddleOCRHelper public class PaddleOCRHelper
{ {
private static Process progressTest; static string baseUrl = ConfigHelper.Config.Get("PaddleServiceBase", "http://192.168.101.12:8090/paddle/getOcr");
static DateTime startTime;
/// <summary> /// <summary>
/// 开始检测 /// 开始检测
/// </summary> /// </summary>
...@@ -23,72 +25,70 @@ namespace BLL ...@@ -23,72 +25,70 @@ namespace BLL
/// <param name="pythonFile">python文件</param> /// <param name="pythonFile">python文件</param>
/// <param name="imgPath">图像文件路径</param> /// <param name="imgPath">图像文件路径</param>
/// <returns></returns> /// <returns></returns>
public static string StartTest(string pythonExePath, string pythonFile, string imgPath) public static string StartTest(string imgPath)
{ {
string state = ""; string ocr = StartCplusOcr(imgPath);
try if (!string.IsNullOrEmpty(ocr))
{ {
string sArguments = pythonFile + " " + imgPath; return ocr;
ProcessStartInfo start = new ProcessStartInfo(); }
start.FileName = pythonExePath + " ";//环境路径需要配置好 ocr= StartPythonOcr(imgPath);
start.Arguments = sArguments; if (!AppIsRun())
start.UseShellExecute = false; {
start.RedirectStandardOutput = true; var onnxexe = ".\\PaddleOCRSDK\\paddleOCR.exe";
start.RedirectStandardInput = true; Process.Start(onnxexe);
start.RedirectStandardError = true; }
start.CreateNoWindow = true; return ocr;
startTime = DateTime.Now; }
using (progressTest = Process.Start(start))
{
state = progressTest.StandardOutput.ReadToEnd();
progressTest.WaitForExit(30000);
//// 异步获取命令行内容
//progressTest.BeginOutputReadLine();
//// 为异步获取订阅事件
//progressTest.OutputDataReceived += new DataReceivedEventHandler(outputDataReceived);
}
string[] result = state.Split(new string[] { "\r\n" }, StringSplitOptions.None);
if (result != null && result.Length > 1)
{
foreach (var item in result.Reverse())
{
if (item.Contains("OCR-Result:"))
{
var ocrR = item.Substring(12);
if (!string.IsNullOrEmpty(ocrR))
{
var lst = DeserializeJsonToList<string>(ocrR);
if (lst != null && lst.Count > 0)
{
state = string.Join(" ", lst);
LogNet.log.Info($"Paddle OCR匹配["+ $"{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}s" + "]:"+ state);
}
else
{
state = "";
}
}
break; [HandleProcessCorruptedStateExceptions]
} static string StartCplusOcr(string imgPath)
} {
return state; string json=Http.Get($"{baseUrl}?ver=cplus&imgPath={imgPath}");
} Result result= JsonConvert.DeserializeObject<Result>(json);
else return result?.data??"";
return ""; }
}catch(Exception ex) static string StartPythonOcr(string imgPath)
{
if (!AppIsRun())
{
var onnxexe = ".\\PaddleOCRSDK\\paddleOCR.exe";
Process.Start(onnxexe);
Thread.Sleep(2000);
}
string json = Http.Get($"{baseUrl}?ver=python&imgPath={imgPath}");
Result result = JsonConvert.DeserializeObject<Result>(json);
return result?.data ?? "";
}
static bool AppIsRun()
{
Process[] processes = Process.GetProcessesByName("paddleOCR");
if (processes.Length > 0)
{ {
LogNet.log.Error("Paddle OCR匹配异常",ex); return true;
} }
return ""; LogNet.log.Info("paddleOCR 未在运行,启动程序");
return false;
} }
static List<T> DeserializeJsonToList<T>(string json) where T : class public class Result
{ {
JsonSerializer serializer = new JsonSerializer(); /// <summary>
StringReader sr = new StringReader(json); /// 状态码,0为正常
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>)); /// </summary>
List<T> list = o as List<T>; public int code { get; set; } = 0;
return list; /// <summary>
/// 返回数据
/// </summary>
public string data { get; set; } = "";
/// <summary>
/// 提示信息
/// </summary>
public string msg { get; set; } = "ok";
/// <summary>
/// 版本
/// </summary>
public string ver { get; set; } = "";
} }
} }
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
......
...@@ -24,6 +24,5 @@ namespace Model ...@@ -24,6 +24,5 @@ namespace Model
public static readonly string CONFIG_EXTENSION = Environment.CurrentDirectory + "\\Config\\Extension.json"; public static readonly string CONFIG_EXTENSION = Environment.CurrentDirectory + "\\Config\\Extension.json";
public static readonly string CONFIG_REELID = Environment.CurrentDirectory + "\\Config\\ReelID"; public static readonly string CONFIG_REELID = Environment.CurrentDirectory + "\\Config\\ReelID";
public static readonly string CONFIG_DATABASE = Environment.CurrentDirectory + "\\Config\\Database.db3"; public static readonly string CONFIG_DATABASE = Environment.CurrentDirectory + "\\Config\\Database.db3";
} }
} }
...@@ -29,12 +29,12 @@ namespace Model ...@@ -29,12 +29,12 @@ namespace Model
public static string Get(string url) public static string Get(string url)
{ {
LogNet.log.Info("[GET]URL:" + url);
RestClient client = new(url) { Timeout = 10000 }; RestClient client = new(url) { Timeout = 10000 };
RestRequest request = new(Method.GET); RestRequest request = new(Method.GET);
IRestResponse response = client.Execute(request); IRestResponse response = client.Execute(request);
string s = response.Content; string s = response.Content;
LogNet.log.Info("Return:" + s); LogNet.log.Info($"[GET][URL:{url}][Return:{s}]");
return FormatContent(s); return FormatContent(s);
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile> <DocumentationFile>
</DocumentationFile> </DocumentationFile>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
......
...@@ -18,33 +18,85 @@ EndProject ...@@ -18,33 +18,85 @@ EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|x64.ActiveCfg = Debug|x64
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|x64.Build.0 = Debug|x64
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|x86.ActiveCfg = Debug|Any CPU
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Debug|x86.Build.0 = Debug|Any CPU
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|Any CPU.Build.0 = Release|Any CPU {D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|Any CPU.Build.0 = Release|Any CPU
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|x64.ActiveCfg = Release|x64
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|x64.Build.0 = Release|x64
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|x86.ActiveCfg = Release|Any CPU
{D7FE70F5-DDE7-4A87-A69C-8B2DE5D88207}.Release|x86.Build.0 = Release|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|Any CPU.Build.0 = Debug|Any CPU {2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|x64.ActiveCfg = Debug|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|x64.Build.0 = Debug|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|x86.ActiveCfg = Debug|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Debug|x86.Build.0 = Debug|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Release|Any CPU.ActiveCfg = Release|Any CPU {2AB75B8C-0538-423C-83EA-702379AD622A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Release|Any CPU.Build.0 = Release|Any CPU {2AB75B8C-0538-423C-83EA-702379AD622A}.Release|Any CPU.Build.0 = Release|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Release|x64.ActiveCfg = Release|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Release|x64.Build.0 = Release|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Release|x86.ActiveCfg = Release|Any CPU
{2AB75B8C-0538-423C-83EA-702379AD622A}.Release|x86.Build.0 = Release|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|Any CPU.Build.0 = Debug|Any CPU {F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|x64.ActiveCfg = Debug|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|x64.Build.0 = Debug|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|x86.ActiveCfg = Debug|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Debug|x86.Build.0 = Debug|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|Any CPU.ActiveCfg = Release|Any CPU {F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|Any CPU.Build.0 = Release|Any CPU {F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|Any CPU.Build.0 = Release|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|x64.ActiveCfg = Release|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|x64.Build.0 = Release|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|x86.ActiveCfg = Release|Any CPU
{F7499DE9-5665-49FD-BDB6-602B9AF98541}.Release|x86.Build.0 = Release|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|Any CPU.Build.0 = Debug|Any CPU {E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|x64.ActiveCfg = Debug|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|x64.Build.0 = Debug|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|x86.ActiveCfg = Debug|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Debug|x86.Build.0 = Debug|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|Any CPU.ActiveCfg = Release|Any CPU {E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|Any CPU.Build.0 = Release|Any CPU {E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|Any CPU.Build.0 = Release|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|x64.ActiveCfg = Release|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|x64.Build.0 = Release|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|x86.ActiveCfg = Release|Any CPU
{E28DE77A-FC70-4BE4-96EC-D0C1A7215A15}.Release|x86.Build.0 = Release|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|Any CPU.Build.0 = Debug|Any CPU {20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|x64.ActiveCfg = Debug|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|x64.Build.0 = Debug|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|x86.ActiveCfg = Debug|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Debug|x86.Build.0 = Debug|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|Any CPU.ActiveCfg = Release|Any CPU {20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|Any CPU.Build.0 = Release|Any CPU {20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|Any CPU.Build.0 = Release|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|x64.ActiveCfg = Release|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|x64.Build.0 = Release|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|x86.ActiveCfg = Release|Any CPU
{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}.Release|x86.Build.0 = Release|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|Any CPU.Build.0 = Debug|Any CPU {7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|x64.ActiveCfg = Debug|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|x64.Build.0 = Debug|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|x86.ActiveCfg = Debug|x86
{7178A902-E193-40CB-8AF5-4EEA05876522}.Debug|x86.Build.0 = Debug|x86
{7178A902-E193-40CB-8AF5-4EEA05876522}.Release|Any CPU.ActiveCfg = Release|Any CPU {7178A902-E193-40CB-8AF5-4EEA05876522}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Release|Any CPU.Build.0 = Release|Any CPU {7178A902-E193-40CB-8AF5-4EEA05876522}.Release|Any CPU.Build.0 = Release|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Release|x64.ActiveCfg = Release|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Release|x64.Build.0 = Release|Any CPU
{7178A902-E193-40CB-8AF5-4EEA05876522}.Release|x86.ActiveCfg = Release|x86
{7178A902-E193-40CB-8AF5-4EEA05876522}.Release|x86.Build.0 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
...@@ -75,6 +75,7 @@ namespace SmartScan ...@@ -75,6 +75,7 @@ namespace SmartScan
this.faceLabel2.Size = new System.Drawing.Size(464, 45); this.faceLabel2.Size = new System.Drawing.Size(464, 45);
this.faceLabel2.TabIndex = 9; this.faceLabel2.TabIndex = 9;
this.faceLabel2.Text = "faceLabel2"; this.faceLabel2.Text = "faceLabel2";
this.faceLabel2.Click += new System.EventHandler(this.faceLabel2_Click);
// //
// FrmAbout // FrmAbout
// //
......
...@@ -22,5 +22,10 @@ namespace SmartScan ...@@ -22,5 +22,10 @@ namespace SmartScan
faceLabel2.Text = Common.config.SoftVersion; faceLabel2.Text = Common.config.SoftVersion;
} }
private void faceLabel2_Click(object sender, EventArgs e)
{
ConfigHelper.AdvanceConfigForm.ShowEditDialog(this);
}
} }
} }
...@@ -83,11 +83,6 @@ namespace SmartScan ...@@ -83,11 +83,6 @@ namespace SmartScan
} }
string pythonEnvPath = ConfigHelper.Config.Get("pythonEnvPath", "C:\\ProgramData\\miniconda3\\envs\\paddle_env\\");
private string GetOcrString(Rectangle rect) private string GetOcrString(Rectangle rect)
{ {
Bitmap bmpTemp = new(rect.Width, rect.Height); Bitmap bmpTemp = new(rect.Width, rect.Height);
...@@ -98,27 +93,7 @@ namespace SmartScan ...@@ -98,27 +93,7 @@ namespace SmartScan
g.Dispose(); g.Dispose();
bmpTemp.Save("ocrt.jpg"); bmpTemp.Save("ocrt.jpg");
bmpTemp.Dispose(); bmpTemp.Dispose();
string codeOcr = ""; string codeOcr = getOcrString();
bool algro = ConfigHelper.Config.Get("UsePaddleOCR", true);
if (algro)
{
codeOcr = PaddleOCRHelper.StartTest(pythonEnvPath + "python.exe", ".\\paddleOCR.py", ".\\ocrt.jpg");
}
else
{
var resp = Common.mateEdit.namedPipeClient.Request("..\\ocrt.jpg");
var lp = JsonConvert.DeserializeObject<List<TextBlock>>(resp);
double maxbox = 0;
foreach (var l in lp)
{
var boxa = l.CalculateArea(l.BoxPoints);
if (boxa > maxbox)
{
maxbox = boxa;
codeOcr = l.Text;
}
}
}
return codeOcr; return codeOcr;
} }
...@@ -226,20 +201,9 @@ namespace SmartScan ...@@ -226,20 +201,9 @@ namespace SmartScan
g.Dispose(); g.Dispose();
bmp.Save("ocrt.jpg"); bmp.Save("ocrt.jpg");
bmp.Dispose(); bmp.Dispose();
var resp = Common.mateEdit.namedPipeClient.Request("..\\ocrt.jpg");
var lp = JsonConvert.DeserializeObject<List<TextBlock>>(resp); string codeOcrs = getOcrString();
string codeOcrs = "";
double maxbox = 0;
foreach (var l in lp)
{
var boxa = l.CalculateArea(l.BoxPoints);
if (boxa > maxbox)
{
maxbox = boxa;
codeOcrs = l.Text;
}
}
codeOcr[ocrRectIndex].Text = codeOcrs; codeOcr[ocrRectIndex].Text = codeOcrs;
PicImage.Cursor = Cursors.Cross; PicImage.Cursor = Cursors.Cross;
//_ocr[ocrIndex[codeOcrIndex]].Offset = new Point(Convert.ToInt32(ocrRect[codeOcrIndex].X - codeCenter.X), Convert.ToInt32(ocrRect[codeOcrIndex].Y - codeCenter.Y)); //_ocr[ocrIndex[codeOcrIndex]].Offset = new Point(Convert.ToInt32(ocrRect[codeOcrIndex].X - codeCenter.X), Convert.ToInt32(ocrRect[codeOcrIndex].Y - codeCenter.Y));
...@@ -248,7 +212,35 @@ namespace SmartScan ...@@ -248,7 +212,35 @@ namespace SmartScan
PicImage.Refresh(); PicImage.Refresh();
} }
} }
string getOcrString()
{
string codeOcrs = "";
bool algro = ConfigHelper.Config.Get("UsePaddleOCR", true);
if (algro)
{
codeOcrs = PaddleOCRHelper.StartTest("..\\ocrt.jpg");
}
else
{
var resp = Common.mateEdit.namedPipeClient.Request("..\\ocrt.jpg");
var lp = JsonConvert.DeserializeObject<List<TextBlock>>(resp);
double maxbox = 0;
foreach (var l in lp)
{
var boxa = l.CalculateArea(l.BoxPoints);
if (boxa > maxbox)
{
maxbox = boxa;
codeOcrs = l.Text;
}
}
if (string.IsNullOrEmpty(codeOcrs))
{
codeOcrs = PaddleOCRHelper.StartTest("..\\ocrt.jpg");
}
}
return codeOcrs;
}
private void PicImage_MouseDown(object sender, MouseEventArgs e) private void PicImage_MouseDown(object sender, MouseEventArgs e)
{ {
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
......
...@@ -11,6 +11,8 @@ using BLL; ...@@ -11,6 +11,8 @@ using BLL;
using Model; using Model;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using DocumentFormat.OpenXml.Drawing.Charts;
using System.IO;
namespace SmartScan namespace SmartScan
{ {
...@@ -77,7 +79,7 @@ namespace SmartScan ...@@ -77,7 +79,7 @@ namespace SmartScan
private void SaveRetrospect(Bitmap labelBmp, string[] barcode, Dictionary<string, string> content) private void SaveRetrospect(Bitmap labelBmp, string[] barcode, Dictionary<string, string> content)
{ {
string path = FilePath.RETROSPECT_DIR + string.Format("{0:yyyy-MM-dd}\\", DateTime.Now); string path = FilePath.RETROSPECT_DIR + string.Format("{0:yyyy-MM-dd}\\", DateTime.Now);
if (!System.IO.Directory.Exists(path)) if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(path); System.IO.Directory.CreateDirectory(path);
...@@ -122,15 +124,15 @@ namespace SmartScan ...@@ -122,15 +124,15 @@ namespace SmartScan
// }; // };
// obj[i] = dicCode; // obj[i] = dicCode;
// } // }
Dictionary<string, object[]> dic = new() Dictionary<string, object[]> dic = new()
{ {
{ "Code", scanWork.SaveCodeInfo() }, { "Code", scanWork.SaveCodeInfo() },
{ "Label", barcode }, { "Label", barcode },
{"Content",new object[]{ content } }, {"Content",new object[]{ content } },
}; };
JavaScriptSerializer serializer = new(); JavaScriptSerializer serializer = new();
string json = serializer.Serialize(dic); string json = serializer.Serialize(dic);
System.IO.File.WriteAllText(path + fileName + "_code.json", json); System.IO.File.WriteAllText(path + fileName + "_code.json", json);
//} //}
LogNet.log.Info("保存历史记录"); LogNet.log.Info("保存历史记录");
} }
...@@ -163,8 +165,7 @@ namespace SmartScan ...@@ -163,8 +165,7 @@ namespace SmartScan
//Common.labelEdit.PrintLast(Common.config.DefaultPrintLabel, Common.config.PrinterName, Common.config.PrintLandscape, content, out string[] barcode); //Common.labelEdit.PrintLast(Common.config.DefaultPrintLabel, Common.config.PrinterName, Common.config.PrintLandscape, content, out string[] barcode);
//LogNet.log.Info(string.Format("打印标签 Label[{0}] Printer[{1}]", Common.config.DefaultPrintLabel, Common.config.PrinterName)); //LogNet.log.Info(string.Format("打印标签 Label[{0}] Printer[{1}]", Common.config.DefaultPrintLabel, Common.config.PrinterName));
var barcode = content.Values.ToArray(); var barcode = content.Values.ToArray();
SaveRetrospect(labelBmp, barcode,content); SaveRetrospect(labelBmp, barcode, content);
} }
catch (Exception ex) catch (Exception ex)
...@@ -172,6 +173,31 @@ namespace SmartScan ...@@ -172,6 +173,31 @@ namespace SmartScan
LogNet.log.Error("Extension_Printing", ex); LogNet.log.Error("Extension_Printing", ex);
} }
} }
string dir_Res = ConfigHelper.Config.Get("DirReelResult","");
string reelResultFileNameKey = ConfigHelper.Config.Get("FileNameKeyReelResult", "");
void SaveResult(Dictionary<string, string> content)
{
if (string.IsNullOrEmpty(dir_Res))
return;
if(!Directory.Exists(dir_Res))
Directory.CreateDirectory(dir_Res);
string filename = "";
if (string.IsNullOrEmpty(reelResultFileNameKey))
{
filename = dir_Res + DateTime.Now.ToString() + ".csv";
}
else
{
filename = dir_Res + content[reelResultFileNameKey] + ".csv";
}
StringBuilder sb = new StringBuilder();
sb.AppendLine("ReelID,PartNumber,Vendor,Lot,UserData1,UserData2,UserData3,UserData4,UserData5,InitialQuantity,MSDLevel,MSDInitialFloorTime ,MSDBagSealDate,MarketUsage,QuantityOverride,ShelfTime,SPMaterialName,WarningLimit,MaximumLimit,Comments,WarmupTime,StorageUnit,SubStorageUnit,LocationOverride,ExpirationDate,ManufacturingDate,PartClass,PSDOverride,AltPartNumber");
sb.AppendLine($"1,1005C,,,,,,,,2,,,,,1,,,,,,,SMT,,,,,,,");
//sb.AppendLine(string.Join(",", content.Keys.ToArray()));
//sb.AppendLine(string.Join(",", content.Values.ToArray()));
System.IO.File.WriteAllText(filename, sb.ToString(), Encoding.UTF8);
}
private void Extension_Printing(Dictionary<string, string> content) private void Extension_Printing(Dictionary<string, string> content)
{ {
try try
...@@ -179,13 +205,13 @@ namespace SmartScan ...@@ -179,13 +205,13 @@ namespace SmartScan
string str = "打印内容:"; string str = "打印内容:";
foreach (string key in content.Keys) foreach (string key in content.Keys)
str += string.Format("({0}:{1})", key, content[key]); str += string.Format("({0}:{1})", key, content[key]);
SaveResult(content);
LogNet.log.Info(str); LogNet.log.Info(str);
//Bitmap labelBmp = Common.labelEdit.PrintImage(Common.config.DefaultPrintLabel, content, out _); //Bitmap labelBmp = Common.labelEdit.PrintImage(Common.config.DefaultPrintLabel, content, out _);
Common.labelEdit.PrintLast(Common.config.DefaultPrintLabel, Common.config.PrinterName, Common.config.PrintLandscape, content, out string[] barcode); Common.labelEdit.PrintLast(Common.config.DefaultPrintLabel, Common.config.PrinterName, Common.config.PrintLandscape, content, out string[] barcode);
LogNet.log.Info(string.Format("打印标签 Label[{0}] Printer[{1}]", Common.config.DefaultPrintLabel, Common.config.PrinterName)); LogNet.log.Info(string.Format("打印标签 Label[{0}] Printer[{1}]", Common.config.DefaultPrintLabel, Common.config.PrinterName));
//SaveRetrospect(labelBmp, barcode); //SaveRetrospect(labelBmp, barcode);
if (Common.config.PrintCompletedClear) if (Common.config.PrintCompletedClear)
Common.extension.Clear(); Common.extension.Clear();
} }
...@@ -211,7 +237,7 @@ namespace SmartScan ...@@ -211,7 +237,7 @@ namespace SmartScan
monitor.Timeout += Monitor_Timeout; monitor.Timeout += Monitor_Timeout;
monitor.Start(Common.config.OperateTimeout); monitor.Start(Common.config.OperateTimeout);
} }
scanWork = new(); scanWork = new();
LblVersion.Text = Common.config.SoftVersion; LblVersion.Text = Common.config.SoftVersion;
LblUserName.Text = Common.config.UserName; LblUserName.Text = Common.config.UserName;
...@@ -230,9 +256,9 @@ namespace SmartScan ...@@ -230,9 +256,9 @@ namespace SmartScan
//语言 //语言
CboLanguage.Items.AddRange(Language.Name); CboLanguage.Items.AddRange(Language.Name);
CboLanguage.SelectedText = Common.config.Language; CboLanguage.SelectedText = Common.config.Language;
if (Common.config.OpenMaximize) Maximize(); if (Common.config.OpenMaximize) Maximize();
if (CheckCamera() && CheckIOModule()) if (CheckCamera() && CheckIOModule())
{ {
...@@ -247,7 +273,7 @@ namespace SmartScan ...@@ -247,7 +273,7 @@ namespace SmartScan
{ {
BtnStart.Enabled = false; BtnStart.Enabled = false;
} }
} }
private void Monitor_Timeout(object sender, EventArgs e) private void Monitor_Timeout(object sender, EventArgs e)
...@@ -348,11 +374,12 @@ namespace SmartScan ...@@ -348,11 +374,12 @@ namespace SmartScan
private void BtnTriggerIO_Click(object sender, EventArgs e) private void BtnTriggerIO_Click(object sender, EventArgs e)
{ {
LogNet.log.Info("按钮点击触发Work"); LogNet.log.Info("按钮点击触发Work");
Task.Run(()=>{ Task.Run(() =>
{
scanWork.Scan(); scanWork.Scan();
//scanWork.TouchOff(); //scanWork.TouchOff();
}); });
} }
private void BtnMatchedName_Click(object sender, EventArgs e) private void BtnMatchedName_Click(object sender, EventArgs e)
...@@ -362,11 +389,13 @@ namespace SmartScan ...@@ -362,11 +389,13 @@ namespace SmartScan
#endregion #endregion
public DialogResult ShowWaittingDialog() { public DialogResult ShowWaittingDialog()
{
Common.frmWaitting = new FrmWaitting(); Common.frmWaitting = new FrmWaitting();
return Common.frmWaitting.ShowDialog(); return Common.frmWaitting.ShowDialog();
} }
public void CloseWaittingDialog() { public void CloseWaittingDialog()
{
if (Common.frmMain.InvokeRequired) if (Common.frmMain.InvokeRequired)
{ {
if (Common.frmWaitting.Created) if (Common.frmWaitting.Created)
...@@ -386,7 +415,7 @@ namespace SmartScan ...@@ -386,7 +415,7 @@ namespace SmartScan
} }
public void SetWaittingMsg(string msg) public void SetWaittingMsg(string msg)
{ {
if (Common.frmMain.InvokeRequired) if (Common.frmMain.InvokeRequired)
{ {
Common.frmMain.Invoke(delegate () Common.frmMain.Invoke(delegate ()
......
...@@ -45,7 +45,8 @@ namespace SmartScan ...@@ -45,7 +45,8 @@ namespace SmartScan
var onnxexe = "onnx\\OcrLiteOnnxForm.exe"; var onnxexe = "onnx\\OcrLiteOnnxForm.exe";
Process.Start(onnxexe); Process.Start(onnxexe);
var paddle = ".\\PaddleOCRSDK\\paddleOCR.exe";
Process.Start(paddle);
......

namespace SmartScan
{
partial class UsrExportData
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.facePanel1 = new Asa.FaceControl.FacePanel();
this.panel1 = new System.Windows.Forms.Panel();
this.ChkRecursive = new Asa.FaceControl.FaceCheckBox();
this.groupBox_lblkey = new System.Windows.Forms.GroupBox();
this.txtkey = new System.Windows.Forms.TextBox();
this.BtnSelectFile = new Asa.FaceControl.FaceButton();
this.faceLabel2 = new Asa.FaceControl.FaceLabel();
this.faceLabel1 = new Asa.FaceControl.FaceLabel();
this.LblFilestatus = new Asa.FaceControl.FaceLabel();
this.CboDataTitle = new Asa.FaceControl.FaceComboBox();
this.CboDataKey = new Asa.FaceControl.FaceComboBox();
this.TxtDataSource = new Asa.FaceControl.FaceTextBox();
this.LblContent = new Asa.FaceControl.FaceLabel();
this.CboDataType = new Asa.FaceControl.FaceComboBox();
this.facePanel1.SuspendLayout();
this.panel1.SuspendLayout();
this.groupBox_lblkey.SuspendLayout();
this.SuspendLayout();
//
// facePanel1
//
this.facePanel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.facePanel1.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.facePanel1.BorderWidth = 2;
this.facePanel1.Controls.Add(this.panel1);
this.facePanel1.Controls.Add(this.LblContent);
this.facePanel1.Controls.Add(this.CboDataType);
this.facePanel1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.facePanel1.Location = new System.Drawing.Point(3, 3);
this.facePanel1.Name = "facePanel1";
this.facePanel1.Padding = new System.Windows.Forms.Padding(3);
this.facePanel1.ShowText = false;
this.facePanel1.Size = new System.Drawing.Size(870, 534);
this.facePanel1.TabIndex = 1;
this.facePanel1.Text = "facePanel1";
this.facePanel1.TitleFont = new System.Drawing.Font("宋体", 12F);
//
// panel1
//
this.panel1.Controls.Add(this.ChkRecursive);
this.panel1.Controls.Add(this.groupBox_lblkey);
this.panel1.Controls.Add(this.BtnSelectFile);
this.panel1.Controls.Add(this.faceLabel2);
this.panel1.Controls.Add(this.faceLabel1);
this.panel1.Controls.Add(this.LblFilestatus);
this.panel1.Controls.Add(this.CboDataTitle);
this.panel1.Controls.Add(this.CboDataKey);
this.panel1.Controls.Add(this.TxtDataSource);
this.panel1.Location = new System.Drawing.Point(6, 76);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(858, 452);
this.panel1.TabIndex = 22;
//
// ChkRecursive
//
this.ChkRecursive.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.ChkRecursive.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.ChkRecursive.BorderWidth = 0;
this.ChkRecursive.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.ChkRecursive.Location = new System.Drawing.Point(638, 23);
this.ChkRecursive.Name = "ChkRecursive";
this.ChkRecursive.Padding = new System.Windows.Forms.Padding(3);
this.ChkRecursive.Size = new System.Drawing.Size(217, 45);
this.ChkRecursive.TabIndex = 23;
this.ChkRecursive.Text = "遍历同目录";
//
// groupBox_lblkey
//
this.groupBox_lblkey.Controls.Add(this.txtkey);
this.groupBox_lblkey.ForeColor = System.Drawing.Color.White;
this.groupBox_lblkey.Location = new System.Drawing.Point(388, 115);
this.groupBox_lblkey.Name = "groupBox_lblkey";
this.groupBox_lblkey.Size = new System.Drawing.Size(300, 231);
this.groupBox_lblkey.TabIndex = 22;
this.groupBox_lblkey.TabStop = false;
this.groupBox_lblkey.Text = "标签可用字段";
//
// txtkey
//
this.txtkey.BackColor = System.Drawing.Color.Black;
this.txtkey.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtkey.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtkey.ForeColor = System.Drawing.Color.White;
this.txtkey.Location = new System.Drawing.Point(3, 17);
this.txtkey.Multiline = true;
this.txtkey.Name = "txtkey";
this.txtkey.ReadOnly = true;
this.txtkey.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtkey.Size = new System.Drawing.Size(294, 211);
this.txtkey.TabIndex = 0;
this.txtkey.Tag = "not";
//
// BtnSelectFile
//
this.BtnSelectFile.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.BtnSelectFile.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.BtnSelectFile.BorderWidth = 2;
this.BtnSelectFile.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.BtnSelectFile.HoldPress = false;
this.BtnSelectFile.Location = new System.Drawing.Point(542, 23);
this.BtnSelectFile.Name = "BtnSelectFile";
this.BtnSelectFile.Padding = new System.Windows.Forms.Padding(3);
this.BtnSelectFile.Size = new System.Drawing.Size(90, 45);
this.BtnSelectFile.TabIndex = 1;
this.BtnSelectFile.Text = "选择文件";
this.BtnSelectFile.Click += new System.EventHandler(this.BtnSelectFile_Click);
//
// faceLabel2
//
this.faceLabel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.faceLabel2.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.faceLabel2.BorderWidth = 0;
this.faceLabel2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.faceLabel2.Location = new System.Drawing.Point(18, 228);
this.faceLabel2.Name = "faceLabel2";
this.faceLabel2.Padding = new System.Windows.Forms.Padding(3);
this.faceLabel2.Size = new System.Drawing.Size(300, 45);
this.faceLabel2.TabIndex = 21;
this.faceLabel2.Text = "关键字匹配数据标题";
this.faceLabel2.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
//
// faceLabel1
//
this.faceLabel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.faceLabel1.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.faceLabel1.BorderWidth = 0;
this.faceLabel1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.faceLabel1.Location = new System.Drawing.Point(18, 115);
this.faceLabel1.Name = "faceLabel1";
this.faceLabel1.Padding = new System.Windows.Forms.Padding(3);
this.faceLabel1.Size = new System.Drawing.Size(334, 45);
this.faceLabel1.TabIndex = 21;
this.faceLabel1.Text = "识别关键词";
this.faceLabel1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
//
// LblFilestatus
//
this.LblFilestatus.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.LblFilestatus.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.LblFilestatus.BorderWidth = 0;
this.LblFilestatus.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.LblFilestatus.Location = new System.Drawing.Point(23, 74);
this.LblFilestatus.Name = "LblFilestatus";
this.LblFilestatus.Padding = new System.Windows.Forms.Padding(3);
this.LblFilestatus.Size = new System.Drawing.Size(411, 35);
this.LblFilestatus.TabIndex = 21;
this.LblFilestatus.Text = "文件状态:";
this.LblFilestatus.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// CboDataTitle
//
this.CboDataTitle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.CboDataTitle.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.CboDataTitle.BorderWidth = 2;
this.CboDataTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.CboDataTitle.Location = new System.Drawing.Point(23, 279);
this.CboDataTitle.Name = "CboDataTitle";
this.CboDataTitle.Padding = new System.Windows.Forms.Padding(3);
this.CboDataTitle.SelectedIndex = -1;
this.CboDataTitle.SelectedText = "";
this.CboDataTitle.Size = new System.Drawing.Size(239, 45);
this.CboDataTitle.TabIndex = 0;
this.CboDataTitle.Tag = "not";
//
// CboDataKey
//
this.CboDataKey.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.CboDataKey.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.CboDataKey.BorderWidth = 2;
this.CboDataKey.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.CboDataKey.Location = new System.Drawing.Point(23, 166);
this.CboDataKey.Name = "CboDataKey";
this.CboDataKey.Padding = new System.Windows.Forms.Padding(3);
this.CboDataKey.SelectedIndex = -1;
this.CboDataKey.SelectedText = "";
this.CboDataKey.Size = new System.Drawing.Size(239, 45);
this.CboDataKey.TabIndex = 0;
this.CboDataKey.Tag = "not";
//
// TxtDataSource
//
this.TxtDataSource.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.TxtDataSource.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.TxtDataSource.BorderWidth = 2;
this.TxtDataSource.Location = new System.Drawing.Point(23, 23);
this.TxtDataSource.MaxLength = 32767;
this.TxtDataSource.Name = "TxtDataSource";
this.TxtDataSource.Padding = new System.Windows.Forms.Padding(3);
this.TxtDataSource.SelectedText = "";
this.TxtDataSource.SelectionLength = 0;
this.TxtDataSource.SelectionStart = 0;
this.TxtDataSource.ShowDel = false;
this.TxtDataSource.ShowQuery = false;
this.TxtDataSource.Size = new System.Drawing.Size(513, 45);
this.TxtDataSource.TabIndex = 0;
this.TxtDataSource.Tag = "not";
this.TxtDataSource.Text = "faceTextBox1";
//
// LblContent
//
this.LblContent.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.LblContent.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.LblContent.BorderWidth = 0;
this.LblContent.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.LblContent.Location = new System.Drawing.Point(6, 16);
this.LblContent.Name = "LblContent";
this.LblContent.Padding = new System.Windows.Forms.Padding(3);
this.LblContent.Size = new System.Drawing.Size(121, 35);
this.LblContent.TabIndex = 21;
this.LblContent.Text = "导出数据类型";
this.LblContent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// CboDataType
//
this.CboDataType.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.CboDataType.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.CboDataType.BorderWidth = 2;
this.CboDataType.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.CboDataType.Location = new System.Drawing.Point(133, 10);
this.CboDataType.Name = "CboDataType";
this.CboDataType.Padding = new System.Windows.Forms.Padding(3);
this.CboDataType.SelectedIndex = -1;
this.CboDataType.SelectedText = "";
this.CboDataType.Size = new System.Drawing.Size(150, 45);
this.CboDataType.TabIndex = 0;
this.CboDataType.Tag = "not";
this.CboDataType.Text = "CboDataType";
//
// UsrExportData
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.facePanel1);
this.Name = "UsrExportData";
this.Size = new System.Drawing.Size(905, 553);
this.facePanel1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.groupBox_lblkey.ResumeLayout(false);
this.groupBox_lblkey.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private Asa.FaceControl.FacePanel facePanel1;
private Asa.FaceControl.FaceComboBox CboDataType;
private Asa.FaceControl.FaceLabel LblContent;
private System.Windows.Forms.Panel panel1;
private Asa.FaceControl.FaceTextBox TxtDataSource;
private Asa.FaceControl.FaceButton BtnSelectFile;
private Asa.FaceControl.FaceLabel LblFilestatus;
private Asa.FaceControl.FaceLabel faceLabel2;
private Asa.FaceControl.FaceLabel faceLabel1;
private Asa.FaceControl.FaceComboBox CboDataTitle;
private Asa.FaceControl.FaceComboBox CboDataKey;
private System.Windows.Forms.GroupBox groupBox_lblkey;
private System.Windows.Forms.TextBox txtkey;
private Asa.FaceControl.FaceCheckBox ChkRecursive;
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using Asa.FaceControl;
using BLL;
using ClosedXML.Excel;
using Model;
namespace SmartScan
{
public partial class UsrExportData : UserControl, ISetMenu
{
public UsrExportData()
{
InitializeComponent();
CboDataType.Items.Add("None");
CboDataType.Items.Add("Excel/CSV");
CboDataType.SelectedIndex = 0;
TxtDataSource.TextChanged += TxtDataSource_TextChanged;
TxtDataSource.Text = Config.DataSource_String;
ChkRecursive.Checked= Config.DataSource_Recursive;
Asa.FaceControl.Language.SetLanguage(this);
}
private void TxtDataSource_TextChanged(object sender, EventArgs e)
{
var filestring = TxtDataSource.Text.Trim();
if (string.IsNullOrEmpty(filestring)) {
LblFilestatus.Text = Language.Dialog("selectdatasource","请选择数据文件");
}
if (!File.Exists(filestring))
{
LblFilestatus.Text = Language.Dialog("filenotexists", "文件状态:改文件不存在");
}
List<string> titles;
if (Path.GetExtension(TxtDataSource.Text).ToLower() == ".csv")
{
titles = ExtraFileData.ParseCSVFileTitle(TxtDataSource.Text);
}
else if (Path.GetExtension(TxtDataSource.Text).ToLower() == ".xlsx")
{
try
{
XLWorkbook wb = new XLWorkbook(filestring);
}
catch
{
LblFilestatus.Text = Language.Dialog("filepatseerror", "文件内容解析失败");
return;
}
titles = ExtraFileData.ParseXLSFileTitle(TxtDataSource.Text);
}
else
{
LblFilestatus.Text = Language.Dialog("fileformaterror", "文件格式不正确");
return;
}
txtkey.Text = "";
CboDataTitle.Items.Clear();
titles.ForEach(t => {
CboDataTitle.Items.Add(t);
txtkey.Text += $"{{{t}}}\r\n";
});
if (CboDataTitle.Items.Count > 0)
CboDataTitle.SelectedIndex = 0;
if (!string.IsNullOrEmpty(Config.DataSource_DataTitle))
{
CboDataTitle.SelectedText = Config.DataSource_DataTitle;
}
}
public Asa.FaceControl.FacePanel GetPanel()
{
if (Config.DataSource_Type == "xls")
{
CboDataType.SelectedIndex = 1;
}
else {
}
CboDataKey.Items.Clear();
CboDataKey.Items.AddRange(Common.macroKey.ToArray());
CboDataKey.SelectedIndex = 0;
if (!string.IsNullOrEmpty(Config.DataSource_DataKey))
{
CboDataKey.SelectedText = Config.DataSource_DataKey;
}
TxtDataSource.Text = Config.DataSource_String;
return facePanel1;
}
public void Save()
{
if (CboDataType.SelectedIndex == 1)
Config.DataSource_Type = "xls";
else
Config.DataSource_Type = "none";
Config.DataSource_String = TxtDataSource.Text;
Config.DataSource_DataKey = CboDataKey.Text;
Config.DataSource_DataTitle = CboDataTitle.Text;
Config.DataSource_Recursive = ChkRecursive.Checked;
ExtraFileData.Init();
Common.extraKey = ExtraFileData.Titles;
}
private void BtnSelectFile_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "Excel files (*.csv;*.xlsx)|*.csv;*.xlsx";
fileDialog.RestoreDirectory = true;
if (fileDialog.ShowDialog() != DialogResult.OK)
return;
if (Path.GetExtension(fileDialog.FileName).ToLower() == ".csv")
{
if (!FrmDataFilePreview.ShowPreview(fileDialog.FileName, out string encodingtxt))
return;
Config.DataSource_Encoding = encodingtxt;
}
TxtDataSource.Text = fileDialog.FileName;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
...@@ -43,6 +43,25 @@ ...@@ -43,6 +43,25 @@
<PropertyGroup> <PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>preview</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>preview</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Asa.Camera.VisionLib, Version=1.3.8398.28384, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Asa.Camera.VisionLib, Version=1.3.8398.28384, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
...@@ -118,6 +137,12 @@ ...@@ -118,6 +137,12 @@
<Compile Include="SetControl\FrmDataFilePreview.Designer.cs"> <Compile Include="SetControl\FrmDataFilePreview.Designer.cs">
<DependentUpon>FrmDataFilePreview.cs</DependentUpon> <DependentUpon>FrmDataFilePreview.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="SetControl\UsrExportData.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="SetControl\UsrExportData.Designer.cs">
<DependentUpon>UsrExportData.cs</DependentUpon>
</Compile>
<Compile Include="SetControl\UsrDataSource.cs"> <Compile Include="SetControl\UsrDataSource.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
...@@ -290,6 +315,9 @@ ...@@ -290,6 +315,9 @@
<EmbeddedResource Include="SetControl\FrmDataFilePreview.resx"> <EmbeddedResource Include="SetControl\FrmDataFilePreview.resx">
<DependentUpon>FrmDataFilePreview.cs</DependentUpon> <DependentUpon>FrmDataFilePreview.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="SetControl\UsrExportData.resx">
<DependentUpon>UsrExportData.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="SetControl\UsrDataSource.resx"> <EmbeddedResource Include="SetControl\UsrDataSource.resx">
<DependentUpon>UsrDataSource.cs</DependentUpon> <DependentUpon>UsrDataSource.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
......
...@@ -6,4 +6,7 @@ ...@@ -6,4 +6,7 @@
<PropertyGroup> <PropertyGroup>
<ProjectView>ProjectFiles</ProjectView> <ProjectView>ProjectFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<StartArguments>hide-</StartArguments>
</PropertyGroup>
</Project> </Project>
\ No newline at end of file \ No newline at end of file
[2023-02-13 13:18:38,299][SmartScan.FrmLoading:23]INFO ===== 程序开始 3.1.8444.23946 ===== [2023-02-21 09:31:29,233][SmartScan.FrmLoading:23]INFO ===== 程序开始 3.1.8452.17130 =====
[2023-02-13 13:18:38,339][DAL.ConfigRW:17]INFO 读取配置文件 [2023-02-21 09:31:29,257][DAL.ConfigRW:17]INFO 读取配置文件
[2023-02-13 13:18:38,343][BLL.ExtraFileData:32]INFO 数据源:C:\download\sample.csv [2023-02-21 09:31:29,266][BLL.ExtraFileData:32]INFO 数据源:C:\download\sample.csv
[2023-02-13 13:18:38,344][BLL.ExtraFileData:54]INFO 数据源加载文件:C:\download\sample.csv [2023-02-21 09:31:29,267][BLL.ExtraFileData:54]INFO 数据源加载文件:C:\download\sample.csv
[2023-02-13 13:18:42,332][SmartScan.FrmLoading:35]INFO 加载相机,数量:0 [2023-02-21 09:31:36,386][SmartScan.FrmLoading:35]INFO 加载相机,数量:0
[2023-02-13 13:18:51,928][BLL.KND_IO:127]INFO Ping 192.168.20.100 请求没有回应 [2023-02-21 09:31:45,959][BLL.KND_IO:127]INFO Ping 192.168.20.100 请求没有回应
[2023-02-13 13:18:51,928][SmartScan.FrmLoading:42]INFO 加载IO模块,IP地址:192.168.20.100,iomodule: [2023-02-21 09:31:45,959][SmartScan.FrmLoading:42]INFO 加载IO模块,IP地址:192.168.20.100,iomodule:
[2023-02-13 13:18:51,928][SmartScan.FrmLoading:48]INFO 加载OCR模块 [2023-02-21 09:31:45,960][SmartScan.FrmLoading:48]INFO 加载OCR模块
[2023-02-13 13:18:51,930][BLL.Extension:38]INFO 加载扩展:General [2023-02-21 09:31:45,962][BLL.Extension:38]INFO 加载扩展:General
[2023-02-13 13:18:51,934][BLL.PrintLabelEdit:49]INFO 读取打印标签 [2023-02-21 09:31:45,964][BLL.PrintLabelEdit:49]INFO 读取打印标签
[2023-02-13 13:18:51,939][BLL.MaterialEdit:20]INFO 读取物料模板 [2023-02-21 09:31:45,971][BLL.MaterialEdit:20]INFO 读取物料模板
[2023-02-13 13:18:52,752][SmartScan.WebService:19]INFO WebService没有配置,不开启 [2023-02-21 09:31:46,858][SmartScan.WebService:19]INFO WebService没有配置,不开启
[2023-02-13 13:18:52,752][SmartScan.FrmLoading:64]INFO 读取关键字文件 [2023-02-21 09:31:46,858][SmartScan.FrmLoading:64]INFO 读取关键字文件
[2023-02-13 13:18:53,165][SmartScan.FrmMain:33]INFO 相机数量为0 [2023-02-21 09:31:47,211][SmartScan.FrmMain:35]INFO 相机数量为0
[2023-02-21 09:33:38,173][SmartScan.Program:86]INFO =====准备退出...=====
[2023-02-21 09:33:38,201][SmartScan.WebService:42]INFO Web服务已关闭
[2023-02-21 09:33:38,202][SmartScan.Program:91]INFO =====程序结束=====
[2023-02-13 13:18:38,299][SmartScan.FrmLoading:23]INFO ===== 程序开始 3.1.8444.23946 ===== [2023-02-21 09:31:29,233][SmartScan.FrmLoading:23]INFO ===== 程序开始 3.1.8452.17130 =====
[2023-02-13 13:18:38,339][DAL.ConfigRW:17]INFO 读取配置文件 [2023-02-21 09:31:29,257][DAL.ConfigRW:17]INFO 读取配置文件
[2023-02-13 13:18:38,343][BLL.ExtraFileData:32]INFO 数据源:C:\download\sample.csv [2023-02-21 09:31:29,266][BLL.ExtraFileData:32]INFO 数据源:C:\download\sample.csv
[2023-02-13 13:18:38,344][BLL.ExtraFileData:54]INFO 数据源加载文件:C:\download\sample.csv [2023-02-21 09:31:29,267][BLL.ExtraFileData:54]INFO 数据源加载文件:C:\download\sample.csv
[2023-02-13 13:18:38,397][Asa.Camera.VisionLib:11]DEBUG GetConfig Path=E:\Codes\Neotel\SmartScan\SmartScan\bin\Debug\Config\Camera.json [2023-02-21 09:31:29,292][Asa.Camera.VisionLib:11]DEBUG GetConfig Path=E:\Codes\Neotel\SmartScan\SmartScan\bin\Debug\Config\Camera.json
[2023-02-13 13:18:38,410][Asa.Camera.VisionLib:35]DEBUG GetConfig_CodeOrder [2023-02-21 09:31:29,347][Asa.Camera.VisionLib:35]DEBUG GetConfig_CodeOrder
[2023-02-13 13:18:38,411][Asa.Camera.VisionLib:41]DEBUG GetConfig_Halcon [2023-02-21 09:31:29,347][Asa.Camera.VisionLib:41]DEBUG GetConfig_Halcon
[2023-02-13 13:18:38,412][Asa.Camera.VisionLib:53]DEBUG GetConfig_EyemLib [2023-02-21 09:31:29,348][Asa.Camera.VisionLib:53]DEBUG GetConfig_EyemLib
[2023-02-13 13:18:38,413][Asa.Camera.VisionLib:69]DEBUG GetConfig_Region [2023-02-21 09:31:29,349][Asa.Camera.VisionLib:69]DEBUG GetConfig_Region
[2023-02-13 13:18:38,536][Asa.Region.Feature:51]INFO Feature init 0 [2023-02-21 09:31:31,019][Asa.Region.Feature:51]INFO Feature init 0
[2023-02-13 13:18:38,590][Asa.Region.Feature:51]INFO Feature init 0 [2023-02-21 09:31:31,053][Asa.Region.Feature:51]INFO Feature init 0
[2023-02-13 13:18:38,635][Asa.Region.Feature:51]INFO Feature init 0 [2023-02-21 09:31:31,091][Asa.Region.Feature:51]INFO Feature init 0
[2023-02-13 13:18:38,719][Asa.Region.Feature:51]INFO Feature init 0 [2023-02-21 09:31:31,128][Asa.Region.Feature:51]INFO Feature init 0
[2023-02-13 13:18:38,721][Asa.Camera.VisionLib:107]DEBUG GetConfig_HIKIPCamera [2023-02-21 09:31:31,129][Asa.Camera.VisionLib:107]DEBUG GetConfig_HIKIPCamera
[2023-02-13 13:18:42,302][Asa.HIK.IPCamera:348]INFO IPCamera Load failed, IP=192.168.10.64, errorcode=7 [2023-02-21 09:31:36,363][Asa.HIK.IPCamera:348]INFO IPCamera Load failed, IP=192.168.10.64, errorcode=7
[2023-02-13 13:18:42,328][Asa.HIK.VisionCamera:76]ERROR Load [2023-02-21 09:31:36,382][Asa.HIK.VisionCamera:76]ERROR Load
System.DllNotFoundException: 无法加载 DLL“MvCameraControl.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。 System.DllNotFoundException: 无法加载 DLL“MvCameraControl.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
在 MvCamCtrl.NET.MyCamera.MV_CC_EnumDevices(UInt32 nTLayerType, MV_CC_DEVICE_INFO_LIST& stDevList) 在 MvCamCtrl.NET.MyCamera.MV_CC_EnumDevices(UInt32 nTLayerType, MV_CC_DEVICE_INFO_LIST& stDevList)
在 Asa.HIK.VisionCamera.Load() 位置 D:\rick\vs\Camera\CameraVisionLib\HIK\HIK_VisionCamera.cs:行号 76 在 Asa.HIK.VisionCamera.Load() 位置 D:\rick\vs\Camera\CameraVisionLib\HIK\HIK_VisionCamera.cs:行号 76
[2023-02-13 13:18:42,332][Asa.Camera.VisionLib:50]INFO Load Camera, Asa.HIK.IPCamera:False, Asa.HIK.VisionCamera:False [2023-02-21 09:31:36,386][Asa.Camera.VisionLib:50]INFO Load Camera, Asa.HIK.IPCamera:False, Asa.HIK.VisionCamera:False
[2023-02-13 13:18:42,332][SmartScan.FrmLoading:35]INFO 加载相机,数量:0 [2023-02-21 09:31:36,386][SmartScan.FrmLoading:35]INFO 加载相机,数量:0
[2023-02-13 13:18:51,928][BLL.KND_IO:127]INFO Ping 192.168.20.100 请求没有回应 [2023-02-21 09:31:45,959][BLL.KND_IO:127]INFO Ping 192.168.20.100 请求没有回应
[2023-02-13 13:18:51,928][SmartScan.FrmLoading:42]INFO 加载IO模块,IP地址:192.168.20.100,iomodule: [2023-02-21 09:31:45,959][SmartScan.FrmLoading:42]INFO 加载IO模块,IP地址:192.168.20.100,iomodule:
[2023-02-13 13:18:51,928][SmartScan.FrmLoading:48]INFO 加载OCR模块 [2023-02-21 09:31:45,960][SmartScan.FrmLoading:48]INFO 加载OCR模块
[2023-02-13 13:18:51,930][BLL.Extension:38]INFO 加载扩展:General [2023-02-21 09:31:45,962][BLL.Extension:38]INFO 加载扩展:General
[2023-02-13 13:18:51,934][BLL.PrintLabelEdit:49]INFO 读取打印标签 [2023-02-21 09:31:45,964][BLL.PrintLabelEdit:49]INFO 读取打印标签
[2023-02-13 13:18:51,939][BLL.MaterialEdit:20]INFO 读取物料模板 [2023-02-21 09:31:45,971][BLL.MaterialEdit:20]INFO 读取物料模板
[2023-02-13 13:18:52,752][SmartScan.WebService:19]INFO WebService没有配置,不开启 [2023-02-21 09:31:46,858][SmartScan.WebService:19]INFO WebService没有配置,不开启
[2023-02-13 13:18:52,752][SmartScan.FrmLoading:64]INFO 读取关键字文件 [2023-02-21 09:31:46,858][SmartScan.FrmLoading:64]INFO 读取关键字文件
[2023-02-13 13:18:53,165][SmartScan.FrmMain:33]INFO 相机数量为0 [2023-02-21 09:31:47,211][SmartScan.FrmMain:35]INFO 相机数量为0
[2023-02-21 09:33:38,173][SmartScan.Program:86]INFO =====准备退出...=====
[2023-02-21 09:33:38,174][Asa.HIK.IPCamera:380]INFO IPCamera Dispose failed, IP=192.168.10.64, errorcode=17
[2023-02-21 09:33:38,200][Asa.Camera.VisionLib:61]INFO Dispose Camera
[2023-02-21 09:33:38,201][SmartScan.WebService:42]INFO Web服务已关闭
[2023-02-21 09:33:38,202][SmartScan.Program:91]INFO =====程序结束=====
54a965945f683f0ca664e757593753292b49778d df69419fd8d4c3e1c4b7ebcf5acafd67833542c4
...@@ -247,3 +247,4 @@ E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.csproj.CoreCompileInputs ...@@ -247,3 +247,4 @@ E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.csproj.CoreCompileInputs
E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.csproj.CopyComplete E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.csproj.CopyComplete
E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.exe E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.exe
E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.pdb E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.pdb
E:\Codes\Neotel\SmartScan\SmartScan\obj\Debug\SmartScan.UsrExportData.resources
namespace paddleOCR namespace paddleOCR
{ {
partial class Form1 partial class Paddle
{ {
/// <summary> /// <summary>
/// 必需的设计器变量。 /// 必需的设计器变量。
...@@ -33,24 +33,25 @@ ...@@ -33,24 +33,25 @@
this.button2 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.button4 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// textBox1 // textBox1
// //
this.textBox1.Location = new System.Drawing.Point(23, 54); this.textBox1.Location = new System.Drawing.Point(11, 11);
this.textBox1.Margin = new System.Windows.Forms.Padding(2);
this.textBox1.Name = "textBox1"; this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(757, 25); this.textBox1.Size = new System.Drawing.Size(569, 21);
this.textBox1.TabIndex = 0; this.textBox1.TabIndex = 0;
// //
// button1 // button1
// //
this.button1.Location = new System.Drawing.Point(93, 85); this.button1.Location = new System.Drawing.Point(594, 11);
this.button1.Margin = new System.Windows.Forms.Padding(2);
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 49); this.button1.Size = new System.Drawing.Size(105, 29);
this.button1.TabIndex = 1; this.button1.TabIndex = 1;
this.button1.Text = "打开"; this.button1.Text = "打开";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
...@@ -58,75 +59,75 @@ ...@@ -58,75 +59,75 @@
// //
// button2 // button2
// //
this.button2.Location = new System.Drawing.Point(212, 85); this.button2.Location = new System.Drawing.Point(119, 68);
this.button2.Margin = new System.Windows.Forms.Padding(2);
this.button2.Name = "button2"; this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 49); this.button2.Size = new System.Drawing.Size(112, 39);
this.button2.TabIndex = 2; this.button2.TabIndex = 2;
this.button2.Text = "识别"; this.button2.Text = "python识别";
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.Click += new System.EventHandler(this.button2_Click);
// //
// pictureBox1 // pictureBox1
// //
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Bottom; this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pictureBox1.Location = new System.Drawing.Point(0, 266); this.pictureBox1.Location = new System.Drawing.Point(0, 213);
this.pictureBox1.Margin = new System.Windows.Forms.Padding(2);
this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(993, 588); this.pictureBox1.Size = new System.Drawing.Size(745, 470);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 3; this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false; this.pictureBox1.TabStop = false;
// //
// textBox2 // textBox2
// //
this.textBox2.Dock = System.Windows.Forms.DockStyle.Bottom; this.textBox2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.textBox2.Location = new System.Drawing.Point(0, 148); this.textBox2.Location = new System.Drawing.Point(0, 118);
this.textBox2.Margin = new System.Windows.Forms.Padding(2);
this.textBox2.Multiline = true; this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2"; this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(993, 118); this.textBox2.Size = new System.Drawing.Size(745, 95);
this.textBox2.TabIndex = 4; this.textBox2.TabIndex = 4;
// //
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(23, 10);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(757, 25);
this.textBox3.TabIndex = 5;
this.textBox3.Text = "C:\\Users\\Test\\.conda\\envs\\paddle_env\\python.exe";
//
// button3
//
this.button3.Location = new System.Drawing.Point(804, 10);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 39);
this.button3.TabIndex = 6;
this.button3.Text = "打开";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(361, 102); this.label1.Location = new System.Drawing.Point(494, 81);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(55, 15); this.label1.Size = new System.Drawing.Size(49, 13);
this.label1.TabIndex = 7; this.label1.TabIndex = 7;
this.label1.Text = "label1"; this.label1.Text = "label1";
// //
// Form1 // button4
//
this.button4.Location = new System.Drawing.Point(262, 68);
this.button4.Margin = new System.Windows.Forms.Padding(2);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(112, 39);
this.button4.TabIndex = 8;
this.button4.Text = "c++识别";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// Paddle
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(993, 854); this.ClientSize = new System.Drawing.Size(745, 683);
this.Controls.Add(this.button4);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox2);
this.Controls.Add(this.pictureBox1); this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button2); this.Controls.Add(this.button2);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1); this.Controls.Add(this.textBox1);
this.Name = "Form1"; this.Margin = new System.Windows.Forms.Padding(2);
this.Text = "Form1"; this.Name = "Paddle";
this.Text = "PaddleOcr";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Paddle_FormClosed);
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
...@@ -140,9 +141,8 @@ ...@@ -140,9 +141,8 @@
private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button2;
private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button4;
} }
} }
...@@ -12,12 +12,14 @@ using System.Windows.Forms; ...@@ -12,12 +12,14 @@ using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
using Newtonsoft; using Newtonsoft;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Runtime.InteropServices;
using System.Runtime.ExceptionServices;
namespace paddleOCR namespace paddleOCR
{ {
public partial class Form1 : Form public partial class Paddle : Form
{ {
public Form1() public Paddle()
{ {
InitializeComponent(); InitializeComponent();
} }
...@@ -26,7 +28,7 @@ namespace paddleOCR ...@@ -26,7 +28,7 @@ namespace paddleOCR
{ {
using (OpenFileDialog openFileDialog = new OpenFileDialog()) using (OpenFileDialog openFileDialog = new OpenFileDialog())
{ {
openFileDialog.Filter = "image files (*.jpg)|*.jpg|All files (*.*)|*.*"; openFileDialog.Filter = "image files All files (*.*)|*.*";
openFileDialog.RestoreDirectory = true; openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
...@@ -35,7 +37,6 @@ namespace paddleOCR ...@@ -35,7 +37,6 @@ namespace paddleOCR
} }
} }
} }
private void button2_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e)
{ {
try try
...@@ -45,13 +46,10 @@ namespace paddleOCR ...@@ -45,13 +46,10 @@ namespace paddleOCR
{ {
return; return;
} }
if (string.IsNullOrEmpty(textBox3.Text))
{
return;
}
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
this.textBox2.Text = StartTest(textBox3.Text, path, textBox1.Text); startTime=DateTime.Now;
this.textBox2.Text = PaddleOCRHelper.StartPythonOcr(textBox1.Text);
this.label1.Text = $"elapsed:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}s"; this.label1.Text = $"elapsed:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}s";
try try
{ {
...@@ -70,68 +68,8 @@ namespace paddleOCR ...@@ -70,68 +68,8 @@ namespace paddleOCR
MessageBox.Show(e1.Message); MessageBox.Show(e1.Message);
} }
} }
private Process progressTest;
DateTime startTime; DateTime startTime;
/// <summary>
/// 开始检测
/// </summary>
/// <param name="pythonExePath">python解释器路径</param>
/// <param name="pythonFile">python文件</param>
/// <param name="imgPath">图像文件路径</param>
/// <returns></returns>
public string StartTest(string pythonExePath, string pythonFile, string imgPath)
{
string state = "";
string sArguments = pythonFile + " " + imgPath;
this.pictureBox1.Image = null;
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = pythonExePath + " ";//环境路径需要配置好
start.Arguments = sArguments;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.RedirectStandardInput = true;
start.RedirectStandardError = true;
start.CreateNoWindow = true;
startTime = DateTime.Now;
using (progressTest = Process.Start(start))
{
state = progressTest.StandardOutput.ReadToEnd();
progressTest.WaitForExit(30000);
//// 异步获取命令行内容
//progressTest.BeginOutputReadLine();
//// 为异步获取订阅事件
//progressTest.OutputDataReceived += new DataReceivedEventHandler(outputDataReceived);
}
string[] result= state.Split(new string[] { "\r\n" }, StringSplitOptions.None);
if (result!=null && result.Length>1)
{
foreach (var item in result.Reverse())
{
if(item.Contains("OCR-Result:"))
{
var ocrR=item.Substring(12);
if(!string.IsNullOrEmpty(ocrR))
{
var lst = DeserializeJsonToList<string>(ocrR);
if(lst!=null&& lst.Count>0)
{
state=string.Join(",", lst);
}
else
{
state = "";
}
}
break;
}
}
return state;
}
else
return "";
}
public static List<T> DeserializeJsonToList<T>(string json) where T : class public static List<T> DeserializeJsonToList<T>(string json) where T : class
{ {
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
...@@ -176,5 +114,81 @@ namespace paddleOCR ...@@ -176,5 +114,81 @@ namespace paddleOCR
} }
} }
} }
private void button4_Click(object sender, EventArgs e)
{
try
{
this.Invoke(new Action(() =>
{
startTime= DateTime.Now;
this.textBox2.Text = PaddleOCRHelper.StartCPlusOcr(textBox1.Text);
this.label1.Text = $"elapsed:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}s";
try
{
Stream s = File.Open(System.Windows.Forms.Application.StartupPath + @"\ocr_result.jpg", FileMode.Open);
pictureBox1.Image = Bitmap.FromStream(s);
s.Close();
s.Dispose();
}
catch
{
}
}));
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
}
private NotifyIcon notify;
private ContextMenuStrip notifyMenu;
bool exit=false;
DeviceLibrary.Service service;
string url = ConfigHelper.Config.Get("url", "http://localhost:8090");
private void Form1_Load(object sender, EventArgs e)
{
service = new DeviceLibrary.Service();
service.Open(url);
//托盘菜单
notifyMenu = new ContextMenuStrip();
ToolStripMenuItem itemShow = new ToolStripMenuItem("显示(&S)");
itemShow.Click += ItemShow_Click;
ToolStripMenuItem itemExit = new ToolStripMenuItem("退出(&X)");
itemExit.Click += ItemExit_Click;
notifyMenu.Items.Add(itemShow);
notifyMenu.Items.Add(itemExit);
//托盘控件
notify = new NotifyIcon { Icon = Icon, Visible = true, ContextMenuStrip = notifyMenu, Text = Text };
this.WindowState= FormWindowState.Minimized;
ShowInTaskbar = false;
}
private void ItemShow_Click(object sender, EventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
private void ItemExit_Click(object sender, EventArgs e)
{
notify.Dispose();
exit = true;
Close();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!exit)
{
e.Cancel = true;
Hide();
}
}
private void Paddle_FormClosed(object sender, FormClosedEventArgs e)
{
service.Close();
}
} }
} }
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace paddleOCR
{
public class PaddleOCRHelper
{
static string pythonEnvPath = ConfigHelper.Config.Get("pythonEnvPath", "C:\\ProgramData\\miniconda3\\envs\\paddle_env\\");
private static Process progressTest;
/// <summary>
/// 开始检测
/// </summary>
/// <param name="pythonExePath">python解释器路径</param>
/// <param name="pythonFile">python文件</param>
/// <param name="imgPath">图像文件路径</param>
/// <returns></returns>
public static string StartPythonOcr(string imgPath)
{
string state = "";
try
{
string sArguments = ".\\paddleOCR.py" + " " + imgPath;
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = pythonEnvPath + "python.exe" + " ";//环境路径需要配置好
start.Arguments = sArguments;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.RedirectStandardInput = true;
start.RedirectStandardError = true;
start.CreateNoWindow = true;
using (progressTest = Process.Start(start))
{
state = progressTest.StandardOutput.ReadToEnd();
progressTest.WaitForExit(30000);
//// 异步获取命令行内容
//progressTest.BeginOutputReadLine();
//// 为异步获取订阅事件
//progressTest.OutputDataReceived += new DataReceivedEventHandler(outputDataReceived);
}
string[] result = state.Split(new string[] { "\r\n" }, StringSplitOptions.None);
state = "";
if (result != null && result.Length > 1)
{
foreach (var item in result.Reverse())
{
if (item.Contains("OCR-Result:"))
{
var ocrR = item.Substring(12);
if (!string.IsNullOrEmpty(ocrR))
{
var lst = DeserializeJsonToList<string>(ocrR);
if (lst != null && lst.Count > 0)
{
state = string.Join(" ", lst);
//LogNet.log.Info($"Paddle Python OCR匹配[" + $"{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}s" + "]:" + state);
}
else
{
state = "";
}
}
break;
}
}
return state;
}
else
return "";
}
catch (Exception ex)
{
//LogNet.log.Error("Paddle OCR匹配异常", ex);
}
return "";
}
[HandleProcessCorruptedStateExceptions]
public static string StartCPlusOcr(string imgPath)
{
StringBuilder sb = new StringBuilder(1024);
try
{
eyemOCRRecognizer(".\\config.txt", imgPath, sb);
}
catch (Exception ex)
{
return ex.Message;
}
return sb.ToString().Trim();
}
static List<T> DeserializeJsonToList<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
List<T> list = o as List<T>;
return list;
}
[DllImport("PaddleOCRSDK.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemOCRRecognizer(string extractorModelPath, string path, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszContent);
}
}
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
...@@ -14,9 +15,30 @@ namespace paddleOCR ...@@ -14,9 +15,30 @@ namespace paddleOCR
[STAThread] [STAThread]
static void Main() static void Main()
{ {
if (IsRun())
return;
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.Run(new Paddle());
}
private static bool IsRun()
{
Process current = Process.GetCurrentProcess();
try
{
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.Id == current.Id) continue; //自己
if (process.MainModule.FileName == current.MainModule.FileName)
return true;
}
}
catch {
return true;
}
return false;
} }
} }
} }
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果想要更改 Windows 用户帐户控制级别,请使用
以下节点之一替换 requestedExecutionLevel 节点。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
元素。
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
...@@ -32,13 +32,46 @@ ...@@ -32,13 +32,46 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>pp.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ConfigHelper">
<HintPath>..\SharedDll\ConfigHelper.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\SmartScan\bin\Debug\Newtonsoft.Json.dll</HintPath> <HintPath>..\SmartScan\bin\Debug\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
...@@ -56,8 +89,11 @@ ...@@ -56,8 +89,11 @@
<Compile Include="Form1.Designer.cs"> <Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="PaddleOCRHelper.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="service\IService.cs" />
<Compile Include="service\Service.cs" />
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
...@@ -70,6 +106,7 @@ ...@@ -70,6 +106,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="app.manifest" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
...@@ -83,5 +120,8 @@ ...@@ -83,5 +120,8 @@
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="pp.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
\ No newline at end of file \ No newline at end of file
此文件类型无法预览
using System.ServiceModel;
using System.ServiceModel.Web;
using System.IO;
using System.Runtime.Serialization;
using System.Collections.Generic;
namespace DeviceLibrary
{
[ServiceContract(Name = "Service")]
internal interface IService
{
[OperationContract]
[WebInvoke(UriTemplate = "/paddle/getOcr?ver={ver}&imgPath={imgPath}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result Readocr(string ver,string imgPath);
}
[DataContract]
public class Result
{
/// <summary>
/// 状态码,0为正常
/// </summary>
[DataMember]
public int code { get; set; } = 0;
/// <summary>
/// 返回数据
/// </summary>
[DataMember]
public string data { get; set; } = "";
/// <summary>
/// 提示信息
/// </summary>
[DataMember]
public string msg { get; set; } = "ok";
/// <summary>
/// 版本
/// </summary>
[DataMember]
public string ver { get; set; } = "";
}
}
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Reflection;
using paddleOCR;
namespace DeviceLibrary
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
internal class WebService : IService
{
public Result Readocr(string ver, string imgPath)
{
Result result = new Result();
DateTime dateTime = DateTime.Now;
if (string.IsNullOrEmpty(ver))
{
result.data = PaddleOCRHelper.StartCPlusOcr(imgPath);
}
else if(ver.ToLower().Equals("python"))
{
result.data = PaddleOCRHelper.StartPythonOcr(imgPath);
}
else if(ver.ToLower().Equals("cplus"))
{
result.data = PaddleOCRHelper.StartCPlusOcr(imgPath);
}
else
{
result.data = PaddleOCRHelper.StartCPlusOcr(imgPath);
}
result.ver = ver;
result.msg = $"Paddle Ocr elapsed:{(DateTime.Now-dateTime).TotalSeconds.ToString("f2")}s";
return result;
}
}
public class Service
{
private WebServiceHost _serviceHost;
public bool State = false;
public void Open(string url)
{
try
{
WebService service = new WebService();
_serviceHost = new WebServiceHost(service, new Uri(url));//service, new Uri(url)
_serviceHost.Open();
State = true;
}
catch (Exception ex)
{
State = false;
}
}
public void Close()
{
try
{
if (_serviceHost != null)//判断服务是否关闭
_serviceHost.Close();//关闭服务
State = false;
}
catch (Exception ex)
{
}
}
}
}
文件属性发生变化
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!