Commit a1ec7f8c 刘韬

1

1 个父辈 4e445bf9
......@@ -88,11 +88,13 @@
<Compile Include="IO\NirenIO.cs" />
<Compile Include="MatchAnalysis.cs" />
<Compile Include="MonitorMouseKeyboard.cs" />
<Compile Include="NamedPipeClient.cs" />
<Compile Include="PrinterHelper.cs" />
<Compile Include="PrintLabelEdit.cs" />
<Compile Include="MaterialEdit.cs" />
<Compile Include="PrintLabelShow.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextBlock.cs" />
<Compile Include="UsersLogin.cs" />
</ItemGroup>
<ItemGroup>
......
......@@ -42,9 +42,16 @@ namespace BLL
Port = 6000;
bool rtn = KPIOServer.StartServer(Port);
KPIOServer.DeviceDIChangeEvent += KPIOServer_DeviceDIChangeEvent;
KPIOServer.DeviceOnlineEvent += KPIOServer_DeviceOnlineEvent;
IOLogUtil.info($"开启IO模块:{rtn}");
}
private void KPIOServer_DeviceOnlineEvent(string ip)
{
IP = ip;
IOLogUtil.info($"IO模块:{IP}上线");
}
private void KPIOServer_DeviceDIChangeEvent(string ip, int[] diStatus)
{
Status[] statuses = new Status[diStatus.Length];
......
using System;
using CameraVisionLib.Model;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -6,41 +8,117 @@ using System.Threading.Tasks;
namespace BLL
{
class MatchAnalysis
public class MatchAnalysis
{
static MatchCollection matchCollection;
public static void StartNewAnalysis(string templatename)
public static void StartNewAnalysis(List<BarcodeInfo> code)
{
matchCollection = new MatchCollection();
matchCollection.templateName = templatename;
matchCollection.Matchs = new List<Match>();
MatchTemplateList = new ();
}
public static void AddMatch(string matchKey, bool isMatch, int codeID, string matchDesc) {
Match match = new Match(matchKey, isMatch, codeID, matchDesc);
matchCollection.Matchs.Add(match);
static string CurrnetTemplateName="";
static BarcodeInfo CurrnetBarcode;
static public void SetTemplatename(string name) {
CurrnetTemplateName = name;
if (!MatchTemplateList.ContainsKey(CurrnetTemplateName))
{
MatchTemplateList.Add(CurrnetTemplateName, new TemplateCollection());
}
}
static List<MatchTemplate> MatchTemplateList;
public class MatchTemplate {
static public void SetBarcode(BarcodeInfo name)
{
CurrnetBarcode = name;
if (!MatchTemplateList[CurrnetTemplateName].BarcodeMatchs.ContainsKey(name.Text))
{
MatchTemplateList[CurrnetTemplateName].BarcodeMatchs.Add(name.Text, new BarcodeMatch(name));
MatchTemplateList[CurrnetTemplateName].barcodeInfos.Add(name);
}
}
public static void AddMatch(string matchKey, bool isMatch, int codeID, string colName,string matchDesc) {
Match match = new Match(matchKey, isMatch, codeID, colName,matchDesc);
var ms = MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections;
if (!ms.ContainsKey(matchKey))
ms.Add(matchKey,new MatchCollection());
ms[matchKey].Matchs.Add(match);
if (!MatchTemplateList[CurrnetTemplateName].MatchCollections.ContainsKey(matchKey))
{
MatchTemplateList[CurrnetTemplateName].MatchCollections.Add(matchKey, new MatchCollection());
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey].barcodeInfo = CurrnetBarcode;
}
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey].Matchs.Add(match);
}
public static void MatchResult(string matchKey, bool isMatch) {
MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections[matchKey].isMatch = isMatch;
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey]=MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections[matchKey];
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey].barcodeInfo = CurrnetBarcode;
}
public static void TemplateResult(bool isMatch) {
MatchTemplateList[CurrnetTemplateName].isMatch = isMatch;
}
static Dictionary<string, TemplateCollection> MatchTemplateList;
public static void ShowResult()
{
return;
foreach (var tp in MatchTemplateList) {
LogNet.log.Info($"开始解析模版:{tp.Key}");
foreach (var m in tp.Value.MatchCollections) {
LogNet.log.Info($"开始解析关键字:{m.Key}");
LogNet.log.Info($"匹配到关键字:{m.Key}");
string matchlist = m.Value.barcodeInfo.Text + "\t";
foreach (var item in m.Value.Matchs)
{
matchlist += $"{item.colName},{item.isMatch}\t";
}
LogNet.log.Info(matchlist);
}
}
}
public class TemplateCollection
{
public Dictionary<string, BarcodeMatch> BarcodeMatchs=new ();
public List<BarcodeInfo> barcodeInfos = new();
public Dictionary<string, MatchCollection> MatchCollections = new();
public bool isMatch;
}
public class MatchCollection
{
public string templateName;
public List<Match> Matchs;
public string MatchKey;
public List<Match> Matchs = new ();
public BarcodeInfo barcodeInfo;
public bool isMatch;
public string result;
}
public class BarcodeMatch {
public BarcodeInfo barcode;
public Dictionary<string, MatchCollection> MatchCollections = new();
public bool isMatch=false;
public BarcodeMatch(BarcodeInfo barcode)
{
this.barcode = barcode;
}
}
public class Match {
public string matchKey;
public bool isMatch;
public int codeID;
public string colName;
public string matchDesc;
public Match(string matchKey, bool isMatch, int codeID, string matchDesc) {
public Match(string matchKey, bool isMatch, int codeID, string colName,string matchDesc) {
this.matchKey = matchKey;
this.isMatch = isMatch;
this.codeID = codeID;
this.colName = colName;
this.matchDesc = matchDesc;
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading;
/// <summary>
/// 客户端管道
/// </summary>
public class NamedPipeClient
{
private NamedPipeClientStream Client { get; set; }
public NamedPipeClient(string serverName, string serverHost)
{
Client = new NamedPipeClientStream(serverHost, serverName);
}
byte[] readBytes = new byte[1024*50];
public string Request(string outPutStr)
{
string inputStr = "";
try
{
this.Client.Connect(1000*5);
var b = Encoding.UTF8.GetBytes(outPutStr);
this.Client.Write(b, 0, b.Length);
this.Client.Flush();
Client.WaitForPipeDrain();
int readlen = Client.Read(readBytes, 0, readBytes.Length);
while (readlen > 0)
{
inputStr += Encoding.UTF8.GetString(readBytes, 0, readlen);
readlen = Client.Read(readBytes, 0, readBytes.Length);
}
}
catch { }
finally
{
if (Client.IsConnected)
Client.Close();
}
//this.Client.Dispose();
return inputStr;
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
public sealed class TextBlock
{
public List<Point> BoxPoints { get; set; }
public float BoxScore { get; set; }
public int AngleIndex { get; set; }
public float AngleScore { get; set; }
public float AngleTime { get; set; }
public string Text { get; set; }
public List<float> CharScores { get; set; }
public float CrnnTime { get; set; }
public float BlockTime { get; set; }
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("├─TextBlock");
string textBox = $"│ ├──TextBox[score({BoxScore}),[x: {BoxPoints[0].X}, y: {BoxPoints[0].Y}], [x: {BoxPoints[1].X}, y: {BoxPoints[1].Y}], [x: {BoxPoints[2].X}, y: {BoxPoints[2].Y}], [x: {BoxPoints[3].X}, y: {BoxPoints[3].Y}]]";
sb.AppendLine(textBox);
string header = AngleIndex >= 0 ? "Angle" : "AngleDisabled";
string angle = $"│ ├──{header}[Index({AngleIndex}), Score({AngleScore}), Time({AngleTime}ms)]";
sb.AppendLine(angle);
StringBuilder sbScores = new StringBuilder();
CharScores.ForEach(x => sbScores.Append($"{x},"));
string textLine = $"│ ├──TextLine[Text({Text}),CharScores({sbScores.ToString()}),Time({CrnnTime}ms)]";
sb.AppendLine(textLine);
sb.AppendLine($"│ └──BlockTime({BlockTime}ms)");
return sb.ToString();
}
public double CalculateArea(List<Point> vectorPoints)
{
int iCycle, iCount;
iCycle = 0;
iCount = vectorPoints.Count;
double iArea = 0;
for (iCycle = 0; iCycle < iCount; iCycle++)
{
iArea = iArea + (vectorPoints[iCycle].X * vectorPoints[(iCycle + 1) % iCount].Y - vectorPoints[(iCycle + 1) % iCount].X * vectorPoints[iCycle].Y);
}
double area = (double)Math.Abs(0.5 * iArea);
return area;
}
}
}
b3779df0e1d99f6a50b50ac0c10a2045586c3cb8
625a16d94e24a12228b3782465bd026b987271aa
using System;
using System.Collections.Generic;
using System.Drawing;
namespace SmartScan
{
......@@ -17,7 +18,6 @@ namespace SmartScan
public static LightSource lightSource;
public static ServerCommunication SCMM;
public static List<string> macroKey;
public static int mateMaxCodeID;
public static readonly string[] CODE_SPLIT = new string[] { ",", ";", "@", "#", "$", "%", "&", "-", "_", "+", "|", "!", "^", "*", "?", "/", "\\", "[Space]", "[Tab]" };
......
......@@ -7,6 +7,8 @@ using System.Linq;
using System.Text;
using Model;
using System.Windows.Forms;
using Newtonsoft.Json;
using BLL;
namespace SmartScan
{
......@@ -94,7 +96,23 @@ namespace SmartScan
g.DrawImage(ocrRotate, destRect, rect, GraphicsUnit.Pixel);
g.Save();
g.Dispose();
return Common.ocr.GetString(bmpTemp);
bmpTemp.Save("ocrt.jpg");
bmpTemp.Dispose();
var resp = Common.mateEdit.namedPipeClient.Request("..\\ocrt.jpg");
var lp = JsonConvert.DeserializeObject<List<TextBlock>>(resp);
string codeOcr = "";
double maxbox = 0;
foreach (var l in lp)
{
var boxa = l.CalculateArea(l.BoxPoints);
if (boxa > maxbox)
{
maxbox = boxa;
codeOcr = l.Text;
}
}
return codeOcr;
}
private string FormatCode(int index)
......@@ -198,8 +216,23 @@ namespace SmartScan
g.DrawImage(ocrRotate, new Rectangle(0, 0, bmp.Width, bmp.Height), ocrRect[ocrRectIndex], GraphicsUnit.Pixel);
g.Save();
g.Dispose();
codeOcr[ocrRectIndex].Text = Common.ocr.GetString(bmp);
bmp.Save("ocrt.jpg");
bmp.Dispose();
var resp = Common.mateEdit.namedPipeClient.Request("..\\ocrt.jpg");
var lp = JsonConvert.DeserializeObject<List<TextBlock>>(resp);
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;
PicImage.Cursor = Cursors.Cross;
//_ocr[ocrIndex[codeOcrIndex]].Offset = new Point(Convert.ToInt32(ocrRect[codeOcrIndex].X - codeCenter.X), Convert.ToInt32(ocrRect[codeOcrIndex].Y - codeCenter.Y));
}
......
......@@ -42,7 +42,7 @@ namespace SmartScan
if (Common.config.EnabledOCR)
{
Common.ocr = new();
//Common.ocr = new();
LogNet.log.Info("加载OCR模块");
}
......
......@@ -14,6 +14,10 @@ namespace SmartScan
[STAThread]
static void Main(string[] args)
{
Environment.CurrentDirectory = Application.StartupPath;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
......@@ -25,6 +29,11 @@ namespace SmartScan
if (args.Length > 0)
back = args[0].ToLower() == "background";
var onnxexe = "onnx\\OcrLiteOnnxForm.exe";
Process.Start(onnxexe);
Application.Run(new FrmLoading(back)); //预加载,完成后自动退出
Common.frmMain = new FrmMain();
Common.frmWaitting = new FrmWaitting();
......
......@@ -219,6 +219,9 @@ namespace SmartScan
}
workCodeInfo = Common.cameraVision.GetBarCode(out List<Bitmap> image);
if (image.Count > 0 && !Common.config.Backgrounder) picShow.Image = image[0];
if (image.Count > 0)
Common.mateEdit.CurrntBitmap = image[0];
if (Common.config.TriggerOpenLight)
Common.lightSource.TurnOff();
return true;
......@@ -242,6 +245,7 @@ namespace SmartScan
{
if (!Common.config.Backgrounder)
picShow.Image = bmp;
Common.mateEdit.CurrntBitmap = bmp;
});
return true;
}
......@@ -276,7 +280,8 @@ namespace SmartScan
if (workCodeInfo.Count == 0) return false;
originalCodeText = Common.cameraVision.GetBarCodeText(workCodeInfo);
bool rtn = Common.mateEdit.MatchingTemplate(workCodeInfo, Common.config.DefaultMaterialName, out string mateName, out workCodeKeyword, out originalCodeIsUsed);
bool rtn = Common.mateEdit.MatchingTemplate(workCodeInfo, Common.config.DefaultMaterialName,false, out string mateName, out workCodeKeyword, out originalCodeIsUsed);
BLL.MatchAnalysis.ShowResult();
Common.frmMain.Invoke(delegate ()
{
if (rtn)
......
......@@ -119,7 +119,7 @@ namespace SmartScan
var t = ChoMatchMiddleType.SelectedIndex - 1;
int index = 0;
int count = 0;
while ((index = text.IndexOf(TxtMatchingMiddleText.Text, index)) != -1)
while ((index = text.IndexOf(TxtMatchingMiddleText.Text, index)) != -1 && !string.IsNullOrEmpty(TxtMatchingMiddleText.Text))
{
count++;
index += TxtMatchingMiddleText.Text.Length;
......@@ -132,7 +132,8 @@ namespace SmartScan
if (t == 1 && count < textcount)
text = "";
faceTextBox1.Text = text;
return;
if (string.IsNullOrEmpty(text))
return;
}
if (ChkMatchingSplit.Checked)
......
......@@ -28,7 +28,7 @@
<HttpServer>
</HttpServer>
<HttpReelID>http://127.0.0.1:8888/test</HttpReelID>
<DefaultMaterialName>m1</DefaultMaterialName>
<DefaultMaterialName>m2</DefaultMaterialName>
<TriggerOpenLight>True</TriggerOpenLight>
<WebService>
</WebService>
......@@ -38,5 +38,5 @@
</ReelIDKeyWord>
<SmfServer>http://192.168.1.243/smf-core/</SmfServer>
<CID>NeoScan01</CID>
<iomodule>NiRen</iomodule>
<IOModule>NiRen</IOModule>
</appSettings>
\ No newline at end of file
此文件的差异太大,无法显示。
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!