修改结果框

This commit is contained in:
820689062 2024-07-29 13:45:55 +08:00
parent b4c7a6c6cb
commit 71997776cf
5 changed files with 186 additions and 245 deletions

View File

@ -17,8 +17,8 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0DE28139-2917-4B58-8240-4B4E11114730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DE28139-2917-4B58-8240-4B4E11114730}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DE28139-2917-4B58-8240-4B4E11114730}.Debug|X64.ActiveCfg = Debug|Any CPU
{0DE28139-2917-4B58-8240-4B4E11114730}.Debug|X64.Build.0 = Debug|Any CPU
{0DE28139-2917-4B58-8240-4B4E11114730}.Debug|X64.ActiveCfg = Debug|X64
{0DE28139-2917-4B58-8240-4B4E11114730}.Debug|X64.Build.0 = Debug|X64
{0DE28139-2917-4B58-8240-4B4E11114730}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DE28139-2917-4B58-8240-4B4E11114730}.Release|Any CPU.Build.0 = Release|Any CPU
{0DE28139-2917-4B58-8240-4B4E11114730}.Release|X64.ActiveCfg = Release|X64

View File

@ -72,7 +72,7 @@ namespace HisenceYoloDetection
/// <param name="path2">要对比的图像</param>
/// <param name="IfWhiteWord"> 白板黑字为true </param>
/// <param name="saveDir">存储路径</param>
public static bool CheckDiffSci(string path1, Mat MatDet, Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir)
public static bool CheckDiffSci(string path1, Mat MatDet, ref Mat ResultMat,Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir)
{
// 读取和处理第一张图片。。
Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
@ -101,6 +101,7 @@ namespace HisenceYoloDetection
// 读取和处理第二张图片
Mat img2 = MatDet.Clone();
ResultMat= MatDet.Clone();
if (img2.Empty())
{
// Console.WriteLine($"Error loading image {path2}");
@ -243,12 +244,14 @@ namespace HisenceYoloDetection
else
{
Rect boundingRect = Cv2.BoundingRect(contour);
Cv2.Resize(img2, img2, new Size(550, 270));
Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
isMatch = false;
string savePath2 = Path.Combine("D:\\Hisence\\Test\\2\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath2, img2);
ResultMat = img2.Clone();
string savePath = Path.Combine("D:\\Hisence\\Test\\2\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");

View File

@ -150,6 +150,8 @@
StartDecBtn = new Button();
CloseDecBtn = new Button();
groupBox6 = new GroupBox();
textBox2 = new TextBox();
label37 = new Label();
textBox3 = new TextBox();
label25 = new Label();
label24 = new Label();
@ -192,8 +194,6 @@
timer6 = new System.Windows.Forms.Timer(components);
richTextBox1 = new RichTextBox();
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
label37 = new Label();
textBox2 = new TextBox();
tabPage2.SuspendLayout();
panel1.SuspendLayout();
groupBox5.SuspendLayout();
@ -1556,6 +1556,26 @@
groupBox6.TabStop = false;
groupBox6.Text = "基础信息";
//
// textBox2
//
textBox2.Location = new Point(128, 146);
textBox2.Margin = new Padding(4, 2, 4, 2);
textBox2.Name = "textBox2";
textBox2.ReadOnly = true;
textBox2.Size = new Size(115, 31);
textBox2.TabIndex = 23;
//
// label37
//
label37.AutoSize = true;
label37.Location = new Point(7, 146);
label37.Margin = new Padding(4, 0, 4, 0);
label37.Name = "label37";
label37.Size = new Size(96, 25);
label37.TabIndex = 22;
label37.Text = "旋钮颜色";
label37.Click += label37_Click;
//
// textBox3
//
textBox3.Location = new Point(128, 95);
@ -1607,10 +1627,10 @@
// tabPage3
//
tabPage3.Controls.Add(panel2);
tabPage3.Location = new Point(4, 33);
tabPage3.Location = new Point(4, 34);
tabPage3.Margin = new Padding(4, 2, 4, 2);
tabPage3.Name = "tabPage3";
tabPage3.Size = new Size(1276, 816);
tabPage3.Size = new Size(1276, 815);
tabPage3.TabIndex = 4;
tabPage3.Text = "录入新型号";
tabPage3.UseVisualStyleBackColor = true;
@ -1930,26 +1950,6 @@
richTextBox1.TabIndex = 1;
richTextBox1.Text = "";
//
// label37
//
label37.AutoSize = true;
label37.Location = new Point(7, 146);
label37.Margin = new Padding(4, 0, 4, 0);
label37.Name = "label37";
label37.Size = new Size(96, 25);
label37.TabIndex = 22;
label37.Text = "旋钮颜色";
label37.Click += label37_Click;
//
// textBox2
//
textBox2.Location = new Point(128, 146);
textBox2.Margin = new Padding(4, 2, 4, 2);
textBox2.Name = "textBox2";
textBox2.ReadOnly = true;
textBox2.Size = new Size(115, 31);
textBox2.TabIndex = 23;
//
// MainForm
//
AutoScaleDimensions = new SizeF(12F, 25F);

View File

@ -453,13 +453,14 @@ namespace HisenceYoloDetection
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
string path22 = "D:\\Hisence\\test2\\222.jpg";
Mat pathmat2 = Cv2.ImRead(path22);
string path222 = "D:\\Hisence\\test2\\111.jpg";
Rect rect1 = new Rect(0, 0, 0, 0);
//string path22 = "D:\\Hisence\\test2\\222.jpg";
//Mat pathmat2 = Cv2.ImRead(path22);
//Mat pathmat2result = Cv2.ImRead(path22);
//string path222 = "D:\\Hisence\\test2\\111.jpg";
//Rect rect1 = new Rect(0, 0, 0, 0);
CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect1, rect1, true, "D://Hisence//test2");
//CheckDiffSciHelper.CheckDiffSci(path222, pathmat2,ref pathmat2result, rect1, rect1, true, "D://Hisence//test2");
Stopwatch sw = new Stopwatch();
@ -1641,151 +1642,158 @@ namespace HisenceYoloDetection
myLog("插入模板成功!", DateTime.Now);
}
}
}
string IOcrBAr = xKNow.OcrBar;
//xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值
//这里改成和海信的对接需求
IfCam1TwoTriger = false;
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
if (xkWordList.Count() == 1)
bool MatchStr=false;
if (xKNow != null)
{
xK_HisenceSQLWord = xkWordList[0];
string IOcrBAr = xKNow.OcrBar;
//xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值
//这里改成和海信的对接需求
IfCam1TwoTriger = false;
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
if (xkWordList.Count() == 1)
{
xK_HisenceSQLWord = xkWordList[0];
}
if (xKNow.Detect != "")
{
myLog("型号匹配成功" + IOcrBAr, DateTime.Now);
}
//从数据库中匹配完才可以进行模组移动
//如果这次型号和上次的型号一样 就不用换识别模型ll
//}
//相机1第二次拍照
// if (IfCam1TwoTriger && bBarTriger)
//{
//初始化板
Defet_OnDetectionDone(whiteMat, 1);
Defet_OnDetectionDone(whiteMat, 2);
Defet_OnDetectionDone(whiteMat, 3);
//Defet_OnDetectionDone(whiteMat, 4);
//Defet_OnDetectionDone(whiteMat, 5);
//Defet_OnDetectionDone(whiteMat, 6);
//Defet_OnDetectionDone(whiteMat, 7);
XK_HisenceWord xK_MatchDet = new XK_HisenceWord();
xK_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile;
AllDsums++;
//进行推理
MLRequest req = new MLRequest();
req.currentMat = Cam1ImgOne;
req.ResizeWidth = 640;
req.ResizeHeight = 640;
req.Score = 0.3f;
req.in_lable_path = LablePath;//标签路径
req.confThreshold = 0.3f;//模型置信度
req.iouThreshold = 0.4f;//检测IOU
req.out_node_name = "output";
MLResult mL = simboObjectDetection.RunInferenceFixed(req);
MLResult mLButton = simboObjectDetButton.RunInferenceFixed(req);
DateTime dt = DateTime.Now;
//将所有的块裁剪 识别字符对比字符串
List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = req.currentMat.Clone();
if (mL.ResultMap != null)
{
mL.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg");
ResultMatShow.Image = mL.ResultMap;
}
List<string> strMatListTwo = new List<string>();
List<string> strMatFuzzyListTwo = new List<string>();
// Mat mResultCut2 = req2.currentMat.Clone();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
#region
//执行定位数组块
string[] listLabels = xKNow.Detect.Split(",");
MLResult MLsum = mL;
//for (int i = 0; i < mL2.ResultDetails.Count; i++)
//{
// MLsum.ResultDetails.Add((DetectionResultDetail)mL2.ResultDetails[i]);
//}
string[] RealCFLabels = new string[MLsum.ResultDetails.Count];
for (int i = 0; i < MLsum.ResultDetails.Count; i++)
{
RealCFLabels[i] = MLsum.ResultDetails[i].LabelName;
}
RealCFLabels = RealCFLabels.Distinct().ToArray();//去重
string detstr = string.Join(",", RealCFLabels); //输出为abc-def-ghi 如果不加-,也可以省
//排序比对块
MatchStr = listLabels.SequenceEqual(RealCFLabels);
if (MatchStr == false)
{
WAIsums++;
}
#endregion
//块比对完了 进行详细比对
if (MatchStr)
{
//Mat mCut = new Mat();
Stopwatch sw = new Stopwatch();
sw.Start();
InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
// InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
sw.Stop();
//myLog("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now);
}
if (MatchStr)
{
//判断块值是否有含有匹配false
bool containsFalseValue = keyValueResult.ContainsValue(false);
if (containsFalseValue)
MatchStr = false;
}
}
if (xKNow.Detect != "")
else
{
myLog("型号匹配成功" + IOcrBAr, DateTime.Now);
}
//从数据库中匹配完才可以进行模组移动
//如果这次型号和上次的型号一样 就不用换识别模型ll
//}
//相机1第二次拍照
// if (IfCam1TwoTriger && bBarTriger)
//{
//初始化板
Defet_OnDetectionDone(whiteMat, 1);
Defet_OnDetectionDone(whiteMat, 2);
Defet_OnDetectionDone(whiteMat, 3);
//Defet_OnDetectionDone(whiteMat, 4);
//Defet_OnDetectionDone(whiteMat, 5);
//Defet_OnDetectionDone(whiteMat, 6);
//Defet_OnDetectionDone(whiteMat, 7);
XK_HisenceWord xK_MatchDet = new XK_HisenceWord();
xK_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile;
AllDsums++;
//进行推理
MLRequest req = new MLRequest();
req.currentMat = Cam1ImgOne;
req.ResizeWidth = 640;
req.ResizeHeight = 640;
req.Score = 0.3f;
req.in_lable_path = LablePath;//标签路径
req.confThreshold = 0.3f;//模型置信度
req.iouThreshold = 0.4f;//检测IOU
req.out_node_name = "output";
MLResult mL = simboObjectDetection.RunInferenceFixed(req);
MLResult mLButton = simboObjectDetButton.RunInferenceFixed(req);
DateTime dt = DateTime.Now;
//将所有的块裁剪 识别字符对比字符串
List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = req.currentMat.Clone();
if (mL.ResultMap != null)
{
mL.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg");
ResultMatShow.Image = mL.ResultMap;
}
List<string> strMatListTwo = new List<string>();
List<string> strMatFuzzyListTwo = new List<string>();
// Mat mResultCut2 = req2.currentMat.Clone();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
#region
//执行定位数组块
string[] listLabels = xKNow.Detect.Split(",");
MLResult MLsum = mL;
//for (int i = 0; i < mL2.ResultDetails.Count; i++)
//{
// MLsum.ResultDetails.Add((DetectionResultDetail)mL2.ResultDetails[i]);
//}
string[] RealCFLabels = new string[MLsum.ResultDetails.Count];
for (int i = 0; i < MLsum.ResultDetails.Count; i++)
{
RealCFLabels[i] = MLsum.ResultDetails[i].LabelName;
}
RealCFLabels = RealCFLabels.Distinct().ToArray();//去重
string detstr = string.Join(",", RealCFLabels); //输出为abc-def-ghi 如果不加-,也可以省
//排序比对块
bool MatchStr = listLabels.SequenceEqual(RealCFLabels);
if (MatchStr == false)
{
WAIsums++;
}
#endregion
//块比对完了 进行详细比对
if (MatchStr)
{
//Mat mCut = new Mat();
Stopwatch sw = new Stopwatch();
sw.Start();
InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
// InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
sw.Stop();
//myLog("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now);
}
if (MatchStr)
{
//判断块值是否有含有匹配false
bool containsFalseValue = keyValueResult.ContainsValue(false);
if (containsFalseValue)
MatchStr = false;
MatchStr = true;
}
///执行比对 小图
//bool MatchStr = ManagerModelHelper.IsMatchSQLText(ref mCut, ref xK_HisenceSQLWord, ref xK_MatchDet);
// int sqlblocksum=
melsecPLCTCPDriver.WriteInt("550", 0);//方行
if (MatchStr)
{
@ -2596,7 +2604,8 @@ namespace HisenceYoloDetection
//if (xkWord.OneblockText.)
//{ }
InsertXKHisenceWordData(xkWord);//往关键字表中插入一条数据
string OcrTextone = strMatListOne.Join("##");
@ -2604,6 +2613,10 @@ namespace HisenceYoloDetection
string detstr = "";
if (keyValueResult.Count<=1)
{
return;
}
for (int v = 0; v < keyValueResult.Count; v++)
{
@ -3422,16 +3435,17 @@ namespace HisenceYoloDetection
textBox2.Text = color;
}));
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rectsql, rectDet, iswhite, "D://Hisence//Test");
Mat matresult = CutBlockMat.Clone();
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat,ref matresult, rectsql, rectDet, iswhite, "D://Hisence//Test");
// juanjiMatch = true;
if (!OneIF1 || !juanjiMatch)
{
OneIF = false;
DisplayResult(mLcut);
//DisplayResult(mLcut);
//显示错误的板
// mLcut.ResultMap;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 2);
Defet_OnDetectionDone(matresult, 2);
}
else
{

View File

@ -104,83 +104,7 @@ namespace HisenceYoloDetection
return cslist;
}
public static bool IsMatchSQLText(ref Mat detMat, ref XK_HisenceWord XKSQL, ref XK_HisenceWord XKDet)
{
try
{
string TwoRectstr = XKSQL.TwoRect;
string oneBlockWordSql = XKSQL.OneblockMainWord;
string twoBlockWordSql = XKSQL.TwoblockMainWord;
string threeBlockWordSql = XKSQL.ThreeblockMainWord;
string fourBlockWordSql = XKSQL.FourblockMainWord;
string fiveBlockWordSql = XKSQL.FiveblockMainWord;
string sixBlockWordSql = XKSQL.SixblockMainWord;
string sevenBlockWordSql = XKSQL.SevenblockMainWord;
string eightBlockWordSql = XKSQL.EightblockMainWord;
string oneBlockWordDet = XKDet.OneblockMainWord;
string twoBlockWordDet = XKDet.TwoblockMainWord;
string threeBlockWordDet = XKDet.ThreeblockMainWord;
string fourBlockWordDet = XKDet.FourblockMainWord;
string fiveBlockWordDet = XKDet.FiveblockMainWord;
string sixBlockWordDet = XKDet.SixblockMainWord;
string sevenBlockWordDet = XKDet.SevenblockMainWord;
string eightBlockWordDet = XKDet.EightblockMainWord;
bool OneIF = isMatchStr(oneBlockWordSql, oneBlockWordDet);
bool TwoIF = isMatchStr(twoBlockWordSql, twoBlockWordDet);
bool ThreeIF = isMatchStr(threeBlockWordSql, threeBlockWordDet);
bool FourIF = isMatchStr(fourBlockWordSql, fourBlockWordDet);
bool FiveIF = isMatchStr(fiveBlockWordSql, fiveBlockWordDet);
bool SixIF = isMatchStr(sixBlockWordSql, sixBlockWordDet);
bool SenvenIF = isMatchStr(sevenBlockWordSql, sevenBlockWordDet);
bool EightIF = isMatchStr(eightBlockWordSql, eightBlockWordDet);
//第二快 卷积匹配
string PathSql = XKSQL.TwoblockPath;
//
Rect rectsql = CheckDiffSciHelper.strChangeRect(TwoRectstr);
Rect rectDet = CheckDiffSciHelper.strChangeRect(XKDet.TwoRect);
bool twoif2 = CheckDiffSciHelper.CheckDiffSci(PathSql, detMat, rectsql, rectDet, (bool)XKSQL.TwoIFWhile, "D://Test");
DateTime dt = DateTime.Now;
using (StreamWriter sw = new StreamWriter("D://Hisence//logsMatch.log", true))
{
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
sw.WriteLine(filename + "\n");
sw.WriteLine(oneBlockWordSql + " " + oneBlockWordDet + "\n");
sw.WriteLine(twoBlockWordSql + " " + twoBlockWordDet + "\n");
sw.WriteLine(threeBlockWordSql + " " + threeBlockWordDet + "\n");
sw.WriteLine(fourBlockWordSql + " " + fourBlockWordDet + "\n");
sw.WriteLine(fiveBlockWordSql + " " + fiveBlockWordDet + "\n");
sw.WriteLine(sixBlockWordSql + " " + sixBlockWordDet + "\n");
sw.WriteLine(sevenBlockWordSql + " " + sevenBlockWordDet + "\n");
sw.WriteLine(eightBlockWordSql + " " + eightBlockWordDet + "\n");
sw.WriteLine(" 卷积匹配 " + twoif2 + "\n");
sw.Flush();
}
//第三块区域一直都是false
if (OneIF && TwoIF && ThreeIF && FourIF && FiveIF && SixIF && SenvenIF && EightIF && twoif2)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public static bool StrMatch(string SqlText,string DetText)
{
// 计算Levenshtein距离