修改最新代码

This commit is contained in:
YZJ 2024-06-27 09:22:31 +08:00
parent 132fd6e1b3
commit 61a9d5230e
13 changed files with 1240 additions and 459 deletions

View File

@ -12,6 +12,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="ManagerModelHelper.cs~RF97ff9f.TMP" />
<None Remove="MelsecPLCTCPDriver.cs~RFacf25a.TMP" /> <None Remove="MelsecPLCTCPDriver.cs~RFacf25a.TMP" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,216 @@

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HisenceYoloDetection
{
public class DetectResultDisplay
{
//深度学习 显示结果
private List<DetectionResultDetail> mlResultList = null;
public List<DetectionResultDetail> MLResultList
{
get => mlResultList;
set
{
if (mlResultList != value)
{
mlResultList = value;
}
}
}
string DisplayTxt = "";
Bitmap ResultImage = null;
PointF StartPoint = new PointF();
Brush FontBrush = new SolidBrush(Color.Green);
Pen DetectResultRectPen = new Pen(new SolidBrush(Color.Green));
public Font Font { get; private set; }
ResultState ResultState = ResultState.DetectNG;
Font DetectResultFont = new Font(new FontFamily("Tahoma"), 15, GraphicsUnit.World);
public int ImageWidth { get; set; }
public int ImageHeight { get; set; }
public DetectResultDisplay() { }
//public DetectResultDisplay(NetResult result, List<IndexedSpec> specs, ResultState resultState, int imageWidth)
//{
// ImageWidth = imageWidth;
// ResultState = resultState;
// displayTxt = resultState.ToString() + "\r\n";
// if (resultState != ResultState.OK)
// {
// fontBrush = new SolidBrush(Color.Red);
// }
// NetResult = result;
// SpecList = specs;
// Font = new Font(new FontFamily("Tahoma"), 35 * ImageWidth / 1400, GraphicsUnit.World);
// startPoint = new PointF(150 * ImageWidth / 1400, 150 * ImageWidth / 1400);
//}
public DetectResultDisplay(List<DetectionResultDetail> ResultDetails, Bitmap resultImage, string displayTxt)
{
ImageWidth = resultImage.Width;
ImageHeight = resultImage.Height;
var longSide = ImageWidth > ImageHeight ? ImageWidth : ImageHeight;
MLResultList = ResultDetails;
ResultImage = resultImage;
DisplayTxt = displayTxt;
if (ResultState != ResultState.OK)
{
FontBrush = new SolidBrush(Color.Red);
DetectResultRectPen = new Pen(new SolidBrush(Color.Red));
}
Font = new Font(new FontFamily("Tahoma"), 35 * longSide / 1400, GraphicsUnit.World);
DetectResultFont = new Font(new FontFamily("Tahoma"), 25 * longSide / 1400, GraphicsUnit.World);
StartPoint = new PointF(100 * ImageWidth / 1400, 100 * ImageHeight / 1400);
}
public object Clone()
{
return null;
}
public void Draw(Graphics g)
{
//画检测结果图
if (ResultImage != null && ResultState != ResultState.OK)
{
g.DrawImage(ResultImage, new Point(0, 0));
}
//画文字
if (!string.IsNullOrWhiteSpace(DisplayTxt))
{
g.DrawString(DisplayTxt, Font, FontBrush, StartPoint);
}
//画外接矩形+label 深度学习
if (MLResultList != null && MLResultList.Count > 0)
{
MLResultList.ForEach(d =>
{
g.DrawRectangle(DetectResultRectPen, d.Rect);
string locationTxt = $"{d.LabelDisplay}";
var locationX = d.Rect.X;
var locationY = d.Rect.Y <= 20 ? d.Rect.Y + 20 : d.Rect.Y - 20;
g.DrawString(locationTxt, DetectResultFont, FontBrush, locationX, locationY);
});
}
//画spec信息
//if (DetectResult != null && DetectResult.NetResult?.DetectDetails?.Count > 0)
//{
// DetectResult.NetResult?.DetectDetails.ForEach(d =>
// {
// g.DrawRectangle(defectRectPen, d.Rect);
// string locationTxt = $"{d.Rect.X},{d.Rect.Y}";
// g.DrawString(locationTxt, defectFont, fontBrush, d.Rect.X, d.Rect.Y - 5);
// });
//}
//float fontHeight = g.MeasureString(displayTxt, Font).Height;
//startPoint.Y += fontHeight * 1.2f;
//var defects = DetectResult.NetResult?.DetectDetails;
//if (defects != null && defects.Count > 0)
//{
// defects.ForEach(d =>
// {
// g.DrawString($"{d.ClassName} X:{d.Rect.X.ToString("f2")} Y:{d.Rect.Y.ToString("f2")} S:{d.Area}", Font, d.FinalResult == EnumHelper.ResultState.OK ? fontBrushOK : fontBrushNG, startPoint);
// startPoint.Y += fontHeight;
// });
//}
//DetectResult.Specs.ForEach(s =>
//{
// g.DrawString($"{s.Code}:{(s.ActualValue ?? 0).ToString("f2")}", Font, s.MeasureResult ?? false == true ? fontBrushOK : fontBrushNG, startPoint);
// startPoint.Y += fontHeight;
//});
}
public string GetDisplayText()
{
return "";
}
}
public class RectResultDisplay
{
ResultState ResultState = ResultState.DetectNG;
public string DisplayTxt = "";
Color FillColor = Color.Lime;
int FontSize = 15;
RectangleF Rect = new RectangleF();
bool IsFilled = false;
public RectResultDisplay() { }
public RectResultDisplay(ResultState _resultState, RectangleF _rect, string _displayTxt, Color _fillColor, bool _isFilled, int _fontSize)
{
ResultState = _resultState;
Rect = _rect;
DisplayTxt = _displayTxt;
FillColor = _fillColor;
IsFilled = _isFilled;
FontSize = _fontSize;
}
public object Clone()
{
RectResultDisplay rect = new RectResultDisplay();
rect.ResultState = ResultState;
rect.Rect = Rect;
rect.DisplayTxt = DisplayTxt;
rect.FillColor = FillColor;
rect.FontSize = FontSize;
rect.IsFilled = IsFilled;
return rect;
}
public void Draw(Graphics g)
{
g.DrawRectangle(new Pen(FillColor, 1), Rect.X, Rect.Y, Rect.Width, Rect.Height);
if (IsFilled)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(20, FillColor)), Rect);
}
Font font = new Font("Tahoma", FontSize);
var txtSize = g.MeasureString(DisplayTxt, font);
g.DrawString(DisplayTxt, font, new SolidBrush(FillColor), (float)(Rect.X + Rect.Width / 2.0 - txtSize.Width / 2.0), Rect.Y + Rect.Height + 5);
}
public string GetDisplayText()
{
return $"{ResultState} {DisplayTxt} ({Rect.X},{Rect.Y},{Rect.Width},{Rect.Height})";
}
}
}

View File

@ -230,7 +230,7 @@
tabPage2.Location = new Point(4, 26); tabPage2.Location = new Point(4, 26);
tabPage2.Name = "tabPage2"; tabPage2.Name = "tabPage2";
tabPage2.Padding = new Padding(3); tabPage2.Padding = new Padding(3);
tabPage2.Size = new Size(1319, 765); tabPage2.Size = new Size(1276, 765);
tabPage2.TabIndex = 1; tabPage2.TabIndex = 1;
tabPage2.Text = "PLC"; tabPage2.Text = "PLC";
tabPage2.UseVisualStyleBackColor = true; tabPage2.UseVisualStyleBackColor = true;
@ -288,9 +288,9 @@
// //
// txtSetValue // txtSetValue
// //
txtSetValue.Location = new Point(670, 78); txtSetValue.Location = new Point(574, 78);
txtSetValue.Name = "txtSetValue"; txtSetValue.Name = "txtSetValue";
txtSetValue.Size = new Size(100, 23); txtSetValue.Size = new Size(196, 23);
txtSetValue.TabIndex = 14; txtSetValue.TabIndex = 14;
// //
// groupBox4 // groupBox4
@ -686,11 +686,11 @@
XZerorbx.Text = "X归零"; XZerorbx.Text = "X归零";
XZerorbx.TextAlign = ContentAlignment.MiddleCenter; XZerorbx.TextAlign = ContentAlignment.MiddleCenter;
XZerorbx.UseVisualStyleBackColor = true; XZerorbx.UseVisualStyleBackColor = true;
XZerorbx.Click += radioButton1_Click; XZerorbx.Click += XZerorbx_Click;
// //
// PLCPostion // PLCPostion
// //
PLCPostion.Location = new Point(6, 258); PLCPostion.Location = new Point(6, 266);
PLCPostion.Name = "PLCPostion"; PLCPostion.Name = "PLCPostion";
PLCPostion.Size = new Size(97, 101); PLCPostion.Size = new Size(97, 101);
PLCPostion.TabIndex = 2; PLCPostion.TabIndex = 2;
@ -828,7 +828,7 @@
tabPage1.Location = new Point(4, 26); tabPage1.Location = new Point(4, 26);
tabPage1.Name = "tabPage1"; tabPage1.Name = "tabPage1";
tabPage1.Padding = new Padding(3); tabPage1.Padding = new Padding(3);
tabPage1.Size = new Size(1319, 765); tabPage1.Size = new Size(1276, 765);
tabPage1.TabIndex = 0; tabPage1.TabIndex = 0;
tabPage1.Text = "相机"; tabPage1.Text = "相机";
tabPage1.UseVisualStyleBackColor = true; tabPage1.UseVisualStyleBackColor = true;
@ -1105,7 +1105,7 @@
tabControl1.Location = new Point(0, 0); tabControl1.Location = new Point(0, 0);
tabControl1.Name = "tabControl1"; tabControl1.Name = "tabControl1";
tabControl1.SelectedIndex = 0; tabControl1.SelectedIndex = 0;
tabControl1.Size = new Size(1327, 795); tabControl1.Size = new Size(1284, 795);
tabControl1.TabIndex = 0; tabControl1.TabIndex = 0;
// //
// tabPage5 // tabPage5
@ -1113,7 +1113,7 @@
tabPage5.Controls.Add(panel4); tabPage5.Controls.Add(panel4);
tabPage5.Location = new Point(4, 26); tabPage5.Location = new Point(4, 26);
tabPage5.Name = "tabPage5"; tabPage5.Name = "tabPage5";
tabPage5.Size = new Size(1319, 765); tabPage5.Size = new Size(1276, 765);
tabPage5.TabIndex = 3; tabPage5.TabIndex = 3;
tabPage5.Text = "流程"; tabPage5.Text = "流程";
tabPage5.UseVisualStyleBackColor = true; tabPage5.UseVisualStyleBackColor = true;
@ -1124,7 +1124,7 @@
panel4.Dock = DockStyle.Fill; panel4.Dock = DockStyle.Fill;
panel4.Location = new Point(0, 0); panel4.Location = new Point(0, 0);
panel4.Name = "panel4"; panel4.Name = "panel4";
panel4.Size = new Size(1319, 765); panel4.Size = new Size(1276, 765);
panel4.TabIndex = 0; panel4.TabIndex = 0;
// //
// panel5 // panel5
@ -1135,7 +1135,7 @@
panel5.Dock = DockStyle.Top; panel5.Dock = DockStyle.Top;
panel5.Location = new Point(0, 0); panel5.Location = new Point(0, 0);
panel5.Name = "panel5"; panel5.Name = "panel5";
panel5.Size = new Size(1319, 762); panel5.Size = new Size(1276, 762);
panel5.TabIndex = 0; panel5.TabIndex = 0;
// //
// DefetShow5 // DefetShow5
@ -1471,7 +1471,7 @@
tabPage3.Controls.Add(panel2); tabPage3.Controls.Add(panel2);
tabPage3.Location = new Point(4, 26); tabPage3.Location = new Point(4, 26);
tabPage3.Name = "tabPage3"; tabPage3.Name = "tabPage3";
tabPage3.Size = new Size(1319, 765); tabPage3.Size = new Size(1276, 765);
tabPage3.TabIndex = 4; tabPage3.TabIndex = 4;
tabPage3.Text = "录入新型号"; tabPage3.Text = "录入新型号";
tabPage3.UseVisualStyleBackColor = true; tabPage3.UseVisualStyleBackColor = true;
@ -1641,9 +1641,9 @@
// //
// QueryoneBtn // QueryoneBtn
// //
QueryoneBtn.Location = new Point(896, 245); QueryoneBtn.Location = new Point(838, 222);
QueryoneBtn.Name = "QueryoneBtn"; QueryoneBtn.Name = "QueryoneBtn";
QueryoneBtn.Size = new Size(93, 23); QueryoneBtn.Size = new Size(115, 53);
QueryoneBtn.TabIndex = 25; QueryoneBtn.TabIndex = 25;
QueryoneBtn.Text = "条件查询"; QueryoneBtn.Text = "条件查询";
QueryoneBtn.UseVisualStyleBackColor = true; QueryoneBtn.UseVisualStyleBackColor = true;
@ -1668,9 +1668,9 @@
// //
// InsertBtn // InsertBtn
// //
InsertBtn.Location = new Point(896, 155); InsertBtn.Location = new Point(838, 92);
InsertBtn.Name = "InsertBtn"; InsertBtn.Name = "InsertBtn";
InsertBtn.Size = new Size(93, 23); InsertBtn.Size = new Size(115, 47);
InsertBtn.TabIndex = 22; InsertBtn.TabIndex = 22;
InsertBtn.Text = "插入"; InsertBtn.Text = "插入";
InsertBtn.UseVisualStyleBackColor = true; InsertBtn.UseVisualStyleBackColor = true;
@ -1796,9 +1796,9 @@
// //
// queryALLBtn // queryALLBtn
// //
queryALLBtn.Location = new Point(896, 196); queryALLBtn.Location = new Point(838, 157);
queryALLBtn.Name = "queryALLBtn"; queryALLBtn.Name = "queryALLBtn";
queryALLBtn.Size = new Size(93, 23); queryALLBtn.Size = new Size(115, 59);
queryALLBtn.TabIndex = 2; queryALLBtn.TabIndex = 2;
queryALLBtn.Text = "查询全部"; queryALLBtn.Text = "查询全部";
queryALLBtn.UseVisualStyleBackColor = true; queryALLBtn.UseVisualStyleBackColor = true;
@ -1827,7 +1827,7 @@
richTextBox1.Dock = DockStyle.Bottom; richTextBox1.Dock = DockStyle.Bottom;
richTextBox1.Location = new Point(0, 801); richTextBox1.Location = new Point(0, 801);
richTextBox1.Name = "richTextBox1"; richTextBox1.Name = "richTextBox1";
richTextBox1.Size = new Size(1327, 176); richTextBox1.Size = new Size(1284, 176);
richTextBox1.TabIndex = 1; richTextBox1.TabIndex = 1;
richTextBox1.Text = ""; richTextBox1.Text = "";
// //
@ -1840,7 +1840,7 @@
// //
AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1327, 977); ClientSize = new Size(1284, 977);
Controls.Add(richTextBox1); Controls.Add(richTextBox1);
Controls.Add(tabControl1); Controls.Add(tabControl1);
Icon = (Icon)resources.GetObject("$this.Icon"); Icon = (Icon)resources.GetObject("$this.Icon");

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,8 @@ using System.Diagnostics.Eventing.Reader;
using static System.Runtime.InteropServices.JavaScript.JSType; using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Drawing; using System.Drawing;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using System.Xml;
using System.Runtime.InteropServices;
namespace HisenceYoloDetection namespace HisenceYoloDetection
{ {
@ -23,262 +25,6 @@ namespace HisenceYoloDetection
/// <summary>
/// 全图洗衣机 裁剪之后 OCR识别的结果
/// </summary>
/// <param name="saveimage"></param>
/// <param name="CutMat"></param>
/// <param name="currentMatC">全图图片</param>
/// <param name="cam1TwoML">全局图片上的目标定位结果(包括定位矩形框)</param>
/// <param name="cam1Button"></param>
/// <param name="xK_HisenceWord"></param>
/// <param name="strMatList">返回的定位框的结果</param>
/// <param name="strMatRefList"></param>
/// <param name="IOcrModel"></param>
public static void InsertSqlRunDataButton(bool saveimage,ref Mat CutMat, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel)
{
#if true
//try
//{
Mat mResultCut = currentMatC.Clone();
Rect areaBlack=new Rect();
//旋钮的位置
if (cam1Button.ResultDetails.Count == 1)
{
Mat mResultCuti = mResultCut.Clone();
int rectsx = cam1Button.ResultDetails[0].Rect.X;
int rectsy = cam1Button.ResultDetails[0].Rect.Y;
int rectsWidth = cam1Button.ResultDetails[0].Rect.Width;
int rectsHeight = cam1Button.ResultDetails[0].Rect.Height;
areaBlack = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
}
for (int i = 0; i < cam1TwoML.ResultDetails.Count; i++)
{
Mat mResultCuti = mResultCut.Clone();
int rectsx = cam1TwoML.ResultDetails[i].Rect.X;
int rectsy = cam1TwoML.ResultDetails[i].Rect.Y;
int rectsWidth = cam1TwoML.ResultDetails[i].Rect.Width;
int rectsHeight = cam1TwoML.ResultDetails[i].Rect.Height;
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
Rect area2 = new Rect();
if (blockIndex == "2"|| blockIndex == "7")//根据旋钮扩大范围
{
areaBlack.X -= rectsx;
areaBlack.Y -= rectsy;
area2 = areaBlack;
string TwoRectStr= CheckDiffSciHelper.rectChangeStr(area2);
xK_HisenceWord.TwoRect = TwoRectStr;
//Mat matCutblack = new Mat(mResultCuti, area2);
//if((bool)xK_HisenceWord.TwoIFWhile)
//{
// matCutblack.SetTo(Scalar.Black);
//}
//else
//{
// matCutblack.SetTo(Scalar.Black);
//}
//rectsx -= rectsWidth;
//rectsy -= 50;
//rectsWidth = rectsWidth + 2 * rectsWidth;
//rectsHeight = rectsHeight + 2 + 50;
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
Mat matCut = new Mat(mResultCuti, area);
CutMat = matCut.Clone();
//Mat TwoCut = new Mat(mResultCuti, area2);
//TwoCut.SetTo(Scalar.Black);
//OCR识别裁剪图片
MLRequest reqcut = new MLRequest();
reqcut.currentMat = matCut.Clone();
MLResult mLCut = IOcrModel.RunInferenceFixed(reqcut);
//if (mLCut.IsSuccess)
//{
// DateTime dt = DateTime.Now;
// mLCut.ResultMap.Save("D:\\Hisence\\detImages\\OCR" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg");
//}
BlockChangeFun(saveimage, blockIndex, ref matCut, ref mLCut, ref xK_HisenceWord);
}
else
{
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
Mat matCut = new Mat(mResultCuti, area);
//OCR识别裁剪图片
MLRequest reqcut = new MLRequest();
reqcut.currentMat = matCut.Clone();
MLResult mLCut = IOcrModel.RunInferenceFixed(reqcut);
//if (mLCut.IsSuccess)
//{
// DateTime dt = DateTime.Now;
// mLCut.ResultMap.Save("D:\\Hisence\\detImages\\OCR" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg");
//}
BlockChangeFun(saveimage, blockIndex, ref matCut, ref mLCut, ref xK_HisenceWord);
}
//插入数据库
}
//}
//catch (Exception ex)
//{
//}
#endif
}
/// <summary>
/// 全图洗衣机 裁剪之后 OCR识别的结果
/// </summary>
/// <param name="currentMatC">全图图片</param>
/// <param name="cam1TwoML">全局图片上的目标定位结果(包括定位矩形框)</param>
/// <param name="strMatList">返回的定位框的结果</param>
public static void InsertSqlRunData(bool saveimage, ref Mat currentMatC, MLResult cam1TwoML, ref XK_HisenceWord xK_HisenceWord, /*ref List<string> strMatList, ref List<string> strMatRefList,*/ ref PaddleOcrModel IOcrModel)
{
#if true
//try
//{
Mat mResultCut = currentMatC.Clone();
for (int i = 0; i < cam1TwoML.ResultDetails.Count; i++)
{
Mat mResultCuti = mResultCut.Clone();
int rectsx = cam1TwoML.ResultDetails[i].Rect.X;
int rectsy = cam1TwoML.ResultDetails[i].Rect.Y;
int rectsWidth = cam1TwoML.ResultDetails[i].Rect.Width;
int rectsHeight = cam1TwoML.ResultDetails[i].Rect.Height;
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
Mat matCut = new Mat(mResultCuti, area);
//OCR识别裁剪图片
MLRequest reqcut = new MLRequest();
reqcut.currentMat = matCut.Clone();
MLResult mLCut = IOcrModel.RunInferenceFixed(reqcut);
//if (mLCut.IsSuccess)
//{
// DateTime dt = DateTime.Now;
// mLCut.ResultMap.Save("D:\\Hisence\\detImages\\OCR" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg");
//}
BlockChangeFun(saveimage, blockIndex, ref matCut, ref mLCut, ref xK_HisenceWord);
//插入数据库
}
//}
//catch (Exception ex)
//{
//}
#endif
}
/// <summary>
///
/// </summary>
/// <param name="saveimage">是否保存</param>
/// <param name="blockIndex">裁剪的一块索引</param>
/// <param name="CutBlockMat">裁剪的一张图片</param>
/// <param name="mLcut">裁剪图片的一些信息</param>
/// <param name="xK_HisenceWord">要存储入数据库的东西</param>
public static void BlockChangeFun(bool saveimage, string blockIndex, ref Mat CutBlockMat, ref MLResult mLcut, ref XK_HisenceWord xK_HisenceWord)
{
string ocrBar = xK_HisenceWord.OcrBar;
//存放关键字和所有字符串
List<string> OcrTextinsert = new List<string>();//存放关键字
List<string> OcrFuzzyTextInsert = new List<string>();//存放模糊字
string CutSavePath = "";
CombineMessage(saveimage, ocrBar, blockIndex, ref CutBlockMat, ref mLcut, ref OcrTextinsert, ref OcrFuzzyTextInsert, ref CutSavePath);
switch (blockIndex)
{
case "1"://完全匹配 重量信息
{
xK_HisenceWord.OneblockPath = CutSavePath;
xK_HisenceWord.OneblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.OneblockText = OcrFuzzyTextInsert.Join("##");
}
break;
case "2"://控制面板 匹配
{
xK_HisenceWord.TwoblockPath = CutSavePath;
xK_HisenceWord.TwoblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.TwoblockText = OcrFuzzyTextInsert.Join("##");
}
break;
case "3"://第三块板匹配
{
xK_HisenceWord.ThreeblockPath = CutSavePath;
xK_HisenceWord.ThreeblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.ThreeblockText = OcrFuzzyTextInsert.Join("##");
}
break;
case "4"://贴纸匹配
{
xK_HisenceWord.FourblockPath = CutSavePath;
xK_HisenceWord.FourblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.FourblockText = OcrFuzzyTextInsert.Join("##");
}
break;
case "5"://贴纸匹配
{
xK_HisenceWord.FiveblockPath = CutSavePath;
xK_HisenceWord.FiveblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.FiveblockText = OcrFuzzyTextInsert.Join("##");
}
break;
case "6"://贴纸匹配
{
xK_HisenceWord.SixblockPath = CutSavePath;
xK_HisenceWord.SixblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.SixblockText = OcrFuzzyTextInsert.Join("##");
}
break;
case "7"://贴纸匹配
{
xK_HisenceWord.SevenblockPath = CutSavePath;
xK_HisenceWord.SevenblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.SevenblockText = OcrFuzzyTextInsert.Join("##");
}
break;
case "8"://贴纸匹配
{
xK_HisenceWord.EightblockPath = CutSavePath;
xK_HisenceWord.EightblockMainWord = OcrTextinsert.Join("##");
xK_HisenceWord.EightblockText = OcrFuzzyTextInsert.Join("##");
}
break;
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -290,8 +36,9 @@ namespace HisenceYoloDetection
/// <param name="OcrTextinsert">关键字</param> /// <param name="OcrTextinsert">关键字</param>
/// <param name="OcrFuzzyTextInsert">所有字</param> /// <param name="OcrFuzzyTextInsert">所有字</param>
/// <param name="cutSavepath">图片保存路径</param> /// <param name="cutSavepath">图片保存路径</param>
public static void CombineMessage(bool saveimage, string OcrBar, string blockIndex, ref Mat CutBlockMat, ref MLResult mLcut, ref List<string> OcrTextinsert, ref List<string> OcrFuzzyTextInsert, ref string cutSavepath) public static void MatMessage(bool saveimage, string OcrBar, string blockIndex, ref Mat CutBlockMat, ref MLResult mLcut, ref List<string> OcrTextinsert, ref List<string> OcrFuzzyTextInsert, ref string cutSavepath)
{ {
//在这里面找到带数字的关键字 将所有字也存放在数据库中 //在这里面找到带数字的关键字 将所有字也存放在数据库中
for (int j = 0; j < mLcut.ResultDetails.Count; j++) for (int j = 0; j < mLcut.ResultDetails.Count; j++)
{ {
@ -362,7 +109,7 @@ namespace HisenceYoloDetection
try try
{ {
string TwoRectstr=XKSQL.TwoRect; string TwoRectstr = XKSQL.TwoRect;
string oneBlockWordSql = XKSQL.OneblockMainWord; string oneBlockWordSql = XKSQL.OneblockMainWord;
string twoBlockWordSql = XKSQL.TwoblockMainWord; string twoBlockWordSql = XKSQL.TwoblockMainWord;
string threeBlockWordSql = XKSQL.ThreeblockMainWord; string threeBlockWordSql = XKSQL.ThreeblockMainWord;
@ -397,7 +144,7 @@ namespace HisenceYoloDetection
Rect rectsql = CheckDiffSciHelper.strChangeRect(TwoRectstr); Rect rectsql = CheckDiffSciHelper.strChangeRect(TwoRectstr);
Rect rectDet = CheckDiffSciHelper.strChangeRect(XKDet.TwoRect); Rect rectDet = CheckDiffSciHelper.strChangeRect(XKDet.TwoRect);
bool twoif2 = CheckDiffSciHelper.CheckDiffSci(PathSql, detMat, rectsql, rectDet,(bool)XKSQL.TwoIFWhile, "D://Test"); bool twoif2 = CheckDiffSciHelper.CheckDiffSci(PathSql, detMat, rectsql, rectDet, (bool)XKSQL.TwoIFWhile, "D://Test");
DateTime dt = DateTime.Now; DateTime dt = DateTime.Now;
using (StreamWriter sw = new StreamWriter("D://Hisence//logsMatch.log", true)) using (StreamWriter sw = new StreamWriter("D://Hisence//logsMatch.log", true))
{ {
@ -411,11 +158,11 @@ namespace HisenceYoloDetection
sw.WriteLine(sixBlockWordSql + " " + sixBlockWordDet + "\n"); sw.WriteLine(sixBlockWordSql + " " + sixBlockWordDet + "\n");
sw.WriteLine(sevenBlockWordSql + " " + sevenBlockWordDet + "\n"); sw.WriteLine(sevenBlockWordSql + " " + sevenBlockWordDet + "\n");
sw.WriteLine(eightBlockWordSql + " " + eightBlockWordDet + "\n"); sw.WriteLine(eightBlockWordSql + " " + eightBlockWordDet + "\n");
sw.WriteLine( " 卷积匹配 " + twoif2 + "\n"); sw.WriteLine(" 卷积匹配 " + twoif2 + "\n");
sw.Flush(); sw.Flush();
} }
//第三块区域一直都是false //第三块区域一直都是false
if (OneIF && TwoIF && ThreeIF && FourIF && FiveIF && SixIF && SenvenIF && EightIF&& twoif2) if (OneIF && TwoIF && ThreeIF && FourIF && FiveIF && SixIF && SenvenIF && EightIF && twoif2)
{ {
return true; return true;
} }
@ -434,19 +181,7 @@ namespace HisenceYoloDetection
} }
} }
public static bool isMatchStr(string SqlText, string DetText) public static bool StrMatch(string SqlText,string DetText)
{
if ((SqlText == "" || SqlText == null) && (DetText == "" || DetText == null))
{
return true;
}
else
{
if(SqlText!=null&& DetText!=null)
{
if (SqlText.Contains("##") && DetText.Contains("##"))
{ {
// 计算Levenshtein距离 // 计算Levenshtein距离
int distance = LevenshteinDistance(SqlText, DetText); int distance = LevenshteinDistance(SqlText, DetText);
@ -468,10 +203,153 @@ namespace HisenceYoloDetection
return areEqual; return areEqual;
} }
static bool AreArraysEqual(string[] array1, string[] array2)
{
if (array1.Length != array2.Length)
{
return false;
}
// 将数组排序
Array.Sort(array1);
Array.Sort(array2);
// 逐个比较对应位置的数字
for (int i = 0; i < array1.Length; i++)
{
if (array1[i] != array2[i])
{
return false;
}
}
return true;
}
static bool AreMoreThanHalfEqual(string[] array1, string[] array2)
{
int io = 0;
foreach (string ch1 in array1)
{
foreach (string ch2 in array2)
{
if (ch1 == ch2)
{
io++;
Console.WriteLine(ch1);
break;
}
}
}
//// 将数组转换为集合
//HashSet<string> set1 = new HashSet<string>(array1);
//HashSet<string> set2 = new HashSet<string>(array2);
//// 计算交集的数量
//int intersectionCount = set1.Intersect(set2).Count();
// 判断交集数量是否超过一半
return io > array1.Length / 2;
}
public static bool StrMatch2(string SqlText, string DetText)
{
string[] numbers = FindNumbers(SqlText);
if (numbers.Length>0)
{
//Console.WriteLine("字符串中包含数字:" + number);
}
else else
{
Console.WriteLine("字符串中不包含数字");
}
string[] numbers2= FindNumbers(DetText);
if (numbers2.Length>0)
{
//Console.WriteLine("字符串中包含数字:" + detnumber);
}
else
{
Console.WriteLine("字符串中不包含数字");
}
bool areEqual ;
if (numbers2.Length>2&& numbers.Length > 2)
{
areEqual = AreMoreThanHalfEqual(numbers, numbers2);
}
else
{
areEqual = AreArraysEqual(numbers, numbers2);
}
//string[] sArraysql = Regex.Split(SqlText, "##", RegexOptions.IgnoreCase);
//string[] sArraydet = Regex.Split(DetText, "##", RegexOptions.IgnoreCase);
//for(int i=0;i< sArraydet.Length;i++)
//{
// string s = sArraydet[i];
// for (int j = 0; j < sArraysql.Length; j++)
// {
// }
//}
//bool areEqual = sArraysql.OrderBy(x => x).SequenceEqual(sArraydet.OrderBy(x => x));
return areEqual;
}
static string[] FindNumbers(string str)
{
Regex regex = new Regex(@"\d+");
MatchCollection matches = regex.Matches(str);
string[] numbers = new string[matches.Count];
for (int i = 0; i < matches.Count; i++)
{
numbers[i] = matches[i].Value;
}
return numbers;
}
static string GetNumber(string str)
{
Regex regex = new Regex(@"\d+");
Match match = regex.Match(str);
if (match.Success)
{
return match.Value;
}
else
{
return null;
}
}
public static bool isMatchStr(string SqlText, string DetText)
{
if ((SqlText == "" || SqlText == null) && (DetText == "" || DetText == null))
{ {
return true; return true;
} }
else
{
if (SqlText != null && DetText != null)
{
if (SqlText.Contains("##") && DetText.Contains("##"))
{
return StrMatch2(SqlText, DetText);
}
else if(SqlText != "" && DetText != "")
{
return StrMatch2(SqlText, DetText);
}
else
{
return false;
}
} }
else else
{ {

View File

@ -11,7 +11,7 @@ using static OpenCvSharp.FileStorage;
public class MelsecPLCTCPDriver1 public class MelsecPLCTCPDriver
{ {
private MelsecMcNet melsecMc = new MelsecMcNet(); private MelsecMcNet melsecMc = new MelsecMcNet();
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet(); // private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();

View File

@ -1,4 +1,4 @@
 //#define USE_MULTI_THREAD
using Newtonsoft.Json; using Newtonsoft.Json;
using OpenCvSharp; using OpenCvSharp;
@ -183,8 +183,7 @@ namespace XKRS.Device.SimboVision.SimboHelper
detectionResultDetail.LabelNo = det.classId; detectionResultDetail.LabelNo = det.classId;
//todo: 标签名相对应 //todo: 标签名相对应
detectionResultDetail.LabelDisplay = det.classname; detectionResultDetail.LabelDisplay = det.classname;
detectionResultDetail.Rect = new Rectangle(rectX.ToInt(), rectY.ToInt(), rectWidth.ToInt(), rectHeight.ToInt()); detectionResultDetail.Rect = new Rectangle((int)rectX, (int)rectY, (int)rectWidth, (int)rectHeight); detectionResultDetail.Score = det.fScore;
detectionResultDetail.Score = det.fScore;
detectionResultDetail.LabelName = det.classname; detectionResultDetail.LabelName = det.classname;
detectionResultDetail.Area = det.area; detectionResultDetail.Area = det.area;
result.ResultDetails.Add(detectionResultDetail); result.ResultDetails.Add(detectionResultDetail);

View File

@ -139,12 +139,21 @@ namespace XKRS.Device.SimboVision.SimboHelper
} }
//string pattern = @"^[A-Za-z0-9]+$"; //@意思忽略转义,+匹配前面一次或多次,$匹配结尾
// Match match = Regex.Match(str, pattern);
private void ConvertJsonResult(string json, ref MLResult result) private void ConvertJsonResult(string json, ref MLResult result)
{ {
// json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}"; // json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}";
// //
Console.WriteLine("检测结果JSON" + json); Console.WriteLine("检测结果JSON" + json);
SegResultCountry detResult = JsonConvert.DeserializeObject<SegResultCountry>(json); SegResult detResult = JsonConvert.DeserializeObject<SegResult>(json);
if (detResult == null) if (detResult == null)
{ {
return; return;
@ -178,45 +187,26 @@ namespace XKRS.Device.SimboVision.SimboHelper
float rectWidth = width; float rectWidth = width;
float rectHeight = height; float rectHeight = height;
//string pattern = @"^[A-Za-z0-9]+$"; //@意思忽略转义,+匹配前面一次或多次,$匹配结尾
// bool match = Regex.IsMatch(det.classname, pattern);
if (det.classname != ""&& rectWidth>0&& rectHeight>0)
{
DetectionResultDetail detectionResultDetail = new DetectionResultDetail(); DetectionResultDetail detectionResultDetail = new DetectionResultDetail();
detectionResultDetail.LabelNo = det.classId; detectionResultDetail.LabelNo = det.classId;
//todo: 标签名相对应 //todo: 标签名相对应
detectionResultDetail.LabelDisplay = det.classname; detectionResultDetail.LabelDisplay = det.classname;
detectionResultDetail.Rect = new Rectangle(rectX.ToInt(), rectY.ToInt(), rectWidth.ToInt(), rectHeight.ToInt()); detectionResultDetail.Rect = new Rectangle((int)rectX, (int)rectY, (int)rectWidth, (int)rectHeight);
detectionResultDetail.Score = det.fScore; detectionResultDetail.Score = det.fScore;
detectionResultDetail.LabelName = det.classname; detectionResultDetail.LabelName = det.classname;
detectionResultDetail.Area = det.area; detectionResultDetail.Area = det.area;
result.ResultDetails.Add(detectionResultDetail); result.ResultDetails.Add(detectionResultDetail);
//if (det.classname.Contains("Model:") || det.classname.Contains("Batch:"))
//{
// string[] sArray = Regex.Split(det.classname, "Model:", RegexOptions.IgnoreCase);
// string splitBar = "";
// if (sArray.Count() > 1)
// {
// result.WashMachineBar = sArray[1];
// string[] aBatch = Regex.Split(sArray[0], "Batch:", RegexOptions.IgnoreCase);
// if (aBatch.Count() > 1)
// {
// result.WashMachineBatch = aBatch[1];
// }
// }
//}
//if (det.classname.Contains("SN:") )
//{
// string[] sArray = Regex.Split(det.classname, "SN:", RegexOptions.IgnoreCase);
// string splitBar = "";
// if (sArray.Count() > 1)
// {
// result.WashMachineSN = sArray[1];
// }
//}
}
} }
}
}
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]

View File

@ -174,6 +174,8 @@ public class SimboObjectDetection
result.ResultDetails.Add(detectionResultDetail); result.ResultDetails.Add(detectionResultDetail);
} }
result.ResultDetails.Sort((s1, s2) => s1.Rect.X.CompareTo(s2.Rect.X));
} }

View File

@ -2,6 +2,7 @@
using OpenCvSharp; using OpenCvSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -182,6 +183,14 @@ public class MLResult
public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>(); public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>();
} }
public enum ResultState
{
[Description("检测NG")]
DetectNG = 0,
[Description("OK")]
OK = 1,
}
public static class MLEngine public static class MLEngine
{ {

View File

@ -1,6 +1,7 @@
using Microsoft.CSharp.RuntimeBinder; using Microsoft.CSharp.RuntimeBinder;
//using Newtonsoft.Json; //using Newtonsoft.Json;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Dynamic; using System.Dynamic;
using System.Linq.Expressions; using System.Linq.Expressions;
@ -13,6 +14,7 @@ using System.Text.RegularExpressions;
public static class StaticHelper public static class StaticHelper
{ {
//判断是否为正整数 //判断是否为正整数
public static bool IsInt(string inString) public static bool IsInt(string inString)
{ {

View File

@ -12,7 +12,7 @@ using static OpenCvSharp.FileStorage;
public class MelsecPLCTCPDriver public class MelsecPLCTCPDriver1
{ {
// private MelsecMcNet melsecMc = new MelsecMcNet(); // private MelsecMcNet melsecMc = new MelsecMcNet();
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet(); // private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB