Commit bc632dd6 张东亮

1

1 个父辈 5fb72a03
...@@ -430,6 +430,25 @@ namespace BLL ...@@ -430,6 +430,25 @@ namespace BLL
if (algro) if (algro)
{ {
codeOcr=PaddleOCRHelper.StartTest("..\\ocr.jpg"); codeOcr=PaddleOCRHelper.StartTest("..\\ocr.jpg");
if(string.IsNullOrEmpty(codeOcr))
{
#region ocrr文字提取开始
//ocr匹配调用
var resp = namedPipeClient.Request("..\\ocr.jpg");
//ocr结果
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;
}
}
#endregion ocr文字提取结束
}
} }
else else
{ {
...@@ -449,10 +468,6 @@ namespace BLL ...@@ -449,10 +468,6 @@ namespace BLL
} }
} }
#endregion ocr文字提取结束 #endregion ocr文字提取结束
if(string.IsNullOrEmpty(codeOcr))
{
codeOcr = PaddleOCRHelper.StartTest("..\\ocr.jpg");
}
} }
......
...@@ -27,17 +27,16 @@ namespace BLL ...@@ -27,17 +27,16 @@ namespace BLL
/// <returns></returns> /// <returns></returns>
public static string StartTest(string imgPath) public static string StartTest(string imgPath)
{ {
string ocr = StartCplusOcr(imgPath); string ocr = "";
if (!string.IsNullOrEmpty(ocr))
{
return ocr;
}
ocr= StartPythonOcr(imgPath);
if (!AppIsRun()) if (!AppIsRun())
{ {
var onnxexe = ".\\PaddleOCRSDK\\paddleOCR.exe"; var onnxexe = ".\\paddle\\paddleOCR.exe";
Process.Start(onnxexe); Process.Start(onnxexe);
} }
if(AppIsRun())
{
ocr = StartCplusOcr(imgPath);
}
return ocr; return ocr;
} }
...@@ -52,7 +51,7 @@ namespace BLL ...@@ -52,7 +51,7 @@ namespace BLL
{ {
if (!AppIsRun()) if (!AppIsRun())
{ {
var onnxexe = ".\\PaddleOCRSDK\\paddleOCR.exe"; var onnxexe = ".\\paddle\\paddleOCR.exe";
Process.Start(onnxexe); Process.Start(onnxexe);
Thread.Sleep(2000); Thread.Sleep(2000);
} }
......
...@@ -100,6 +100,7 @@ namespace SmartScan ...@@ -100,6 +100,7 @@ namespace SmartScan
private string FormatCode(int index) private string FormatCode(int index)
{ {
if (codeOcr.Count <= index) return "";
string text = codeOcr[index].Text; string text = codeOcr[index].Text;
List<string> arr = new(); List<string> arr = new();
for (int i = 0; i < codeMatch.Count; i++) for (int i = 0; i < codeMatch.Count; i++)
...@@ -219,6 +220,21 @@ namespace SmartScan ...@@ -219,6 +220,21 @@ namespace SmartScan
if (algro) if (algro)
{ {
codeOcrs = PaddleOCRHelper.StartTest("..\\ocrt.jpg"); codeOcrs = PaddleOCRHelper.StartTest("..\\ocrt.jpg");
if(string.IsNullOrEmpty(codeOcrs))
{
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;
}
}
}
} }
else else
{ {
...@@ -234,10 +250,6 @@ namespace SmartScan ...@@ -234,10 +250,6 @@ namespace SmartScan
codeOcrs = l.Text; codeOcrs = l.Text;
} }
} }
if (string.IsNullOrEmpty(codeOcrs))
{
codeOcrs = PaddleOCRHelper.StartTest("..\\ocrt.jpg");
}
} }
return codeOcrs; return codeOcrs;
} }
......
...@@ -4,6 +4,7 @@ using System.Windows.Forms; ...@@ -4,6 +4,7 @@ using System.Windows.Forms;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.IO;
namespace SmartScan namespace SmartScan
{ {
...@@ -42,10 +43,10 @@ namespace SmartScan ...@@ -42,10 +43,10 @@ namespace SmartScan
if (args.Length > 0) if (args.Length > 0)
hide = args[0].ToLower() == "hide"; hide = args[0].ToLower() == "hide";
var onnxexe = "onnx\\OcrLiteOnnxForm.exe"; var onnxexe = "onnx\\OcrLiteOnnxForm.exe";
Process.Start(onnxexe); Process.Start(onnxexe);
var paddle = ".\\PaddleOCRSDK\\paddleOCR.exe"; var paddle = "paddle\\paddleOCR.exe";
Process.Start(paddle); Process.Start(paddle);
...@@ -63,7 +64,8 @@ namespace SmartScan ...@@ -63,7 +64,8 @@ namespace SmartScan
fsp.WindowState = FormWindowState.Minimized; fsp.WindowState = FormWindowState.Minimized;
Application.Run(fsp); Application.Run(fsp);
}else }
else
Application.Run(Common.frmMain); Application.Run(Common.frmMain);
Exit(); Exit();
......
...@@ -14,6 +14,7 @@ using Newtonsoft; ...@@ -14,6 +14,7 @@ using Newtonsoft;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Security.Cryptography.X509Certificates;
namespace paddleOCR namespace paddleOCR
{ {
...@@ -22,6 +23,7 @@ namespace paddleOCR ...@@ -22,6 +23,7 @@ namespace paddleOCR
public Paddle() public Paddle()
{ {
InitializeComponent(); InitializeComponent();
PaddleOCRHelper.Init();
} }
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
......
...@@ -15,6 +15,10 @@ namespace paddleOCR ...@@ -15,6 +15,10 @@ namespace paddleOCR
{ {
public class PaddleOCRHelper public class PaddleOCRHelper
{ {
public static void Init()
{
int code=eyemInitOCRRecognizer(".\\config.txt");
}
static string pythonEnvPath = ConfigHelper.Config.Get("pythonEnvPath", "C:\\ProgramData\\miniconda3\\envs\\paddle_env\\"); static string pythonEnvPath = ConfigHelper.Config.Get("pythonEnvPath", "C:\\ProgramData\\miniconda3\\envs\\paddle_env\\");
private static Process progressTest; private static Process progressTest;
/// <summary> /// <summary>
...@@ -91,7 +95,7 @@ namespace paddleOCR ...@@ -91,7 +95,7 @@ namespace paddleOCR
StringBuilder sb = new StringBuilder(1024); StringBuilder sb = new StringBuilder(1024);
try try
{ {
eyemOCRRecognizer(".\\config.txt", imgPath, sb); eyemOCRRecognizer(imgPath,ref sb);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -107,7 +111,10 @@ namespace paddleOCR ...@@ -107,7 +111,10 @@ namespace paddleOCR
List<T> list = o as List<T>; List<T> list = o as List<T>;
return list; return list;
} }
[DllImport("PaddleOCRSDK.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitOCRRecognizer(string extractorModelPath);
[DllImport("PaddleOCRSDK.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("PaddleOCRSDK.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemOCRRecognizer(string extractorModelPath, string path, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszContent); private static extern int eyemOCRRecognizer(string path, ref StringBuilder lpszContent);
} }
} }
...@@ -17,23 +17,24 @@ namespace DeviceLibrary ...@@ -17,23 +17,24 @@ namespace DeviceLibrary
{ {
Result result = new Result(); Result result = new Result();
DateTime dateTime = DateTime.Now; DateTime dateTime = DateTime.Now;
if (string.IsNullOrEmpty(ver)) //if (string.IsNullOrEmpty(ver))
{ //{
result.data = PaddleOCRHelper.StartCPlusOcr(imgPath); // result.data = PaddleOCRHelper.StartCPlusOcr(imgPath);
} //}
else if(ver.ToLower().Equals("python")) //else
{ //if (ver.ToLower().Equals("python"))
//{
result.data = PaddleOCRHelper.StartPythonOcr(imgPath); result.data = PaddleOCRHelper.StartPythonOcr(imgPath);
} //}
else if(ver.ToLower().Equals("cplus")) //else if(ver.ToLower().Equals("cplus"))
{ //{
result.data = PaddleOCRHelper.StartCPlusOcr(imgPath); // result.data = PaddleOCRHelper.StartCPlusOcr(imgPath);
} //}
else //else
{ //{
result.data = PaddleOCRHelper.StartCPlusOcr(imgPath); // result.data = PaddleOCRHelper.StartCPlusOcr(imgPath);
} //}
result.ver = ver; result.ver = ver;
result.msg = $"Paddle Ocr elapsed:{(DateTime.Now-dateTime).TotalSeconds.ToString("f2")}s"; result.msg = $"Paddle Ocr elapsed:{(DateTime.Now-dateTime).TotalSeconds.ToString("f2")}s";
return result; return result;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!