diff --git a/LeatherProject/.vs/LeatherApp/FileContentIndex/3fd1848c-8756-45c4-aac8-eaac68ac69aa.vsidx b/LeatherProject/.vs/LeatherApp/FileContentIndex/3fd1848c-8756-45c4-aac8-eaac68ac69aa.vsidx deleted file mode 100644 index 508c3ea..0000000 Binary files a/LeatherProject/.vs/LeatherApp/FileContentIndex/3fd1848c-8756-45c4-aac8-eaac68ac69aa.vsidx and /dev/null differ diff --git a/LeatherProject/.vs/LeatherApp/FileContentIndex/6937d47b-3606-4753-9cb3-1952fa419e9b.vsidx b/LeatherProject/.vs/LeatherApp/FileContentIndex/6937d47b-3606-4753-9cb3-1952fa419e9b.vsidx new file mode 100644 index 0000000..c74b65a Binary files /dev/null and b/LeatherProject/.vs/LeatherApp/FileContentIndex/6937d47b-3606-4753-9cb3-1952fa419e9b.vsidx differ diff --git a/LeatherProject/LeatherApp/Device/DefectLib.cs b/LeatherProject/LeatherApp/Device/DefectLib.cs index 229c3f5..9741be1 100644 --- a/LeatherProject/LeatherApp/Device/DefectLib.cs +++ b/LeatherProject/LeatherApp/Device/DefectLib.cs @@ -371,6 +371,24 @@ namespace LeatherApp.Device } } } + + private class DefectLabelInfo + { + public int x { get; set; } + public int y { get; set; } + public int w { get; set; } + public int h { get; set; } + public int classId { get; set; } + public double confidence { get; set; } //置信度 + public double contrast { get; set; }//对比度 + + public double cmW { get; set; } + public double cmH { get; set; } + + public int i { get; set; }//小图index + public int j { get; set; }//缺陷index + } + //打标 private void run3() { @@ -395,11 +413,58 @@ namespace LeatherApp.Device int rowNum = task.bmp.Height / image_hight; int count = 0; liStep = 3; + + //车用革去除接头处横档误判 + bool haveJieTou = false; + List DefectLabelInfoList = new List(); + for (int i = 0; i < cut_count; i++) { liStep = i * 100; task.resultInfo += $"第 {i}/{cut_count} 张小图(大图索引{task.photoIndex}): 缺陷数 = {task.output_num[i]}\n"; //task.resultInfo +=$"大图({task.tag})[{task.bmp.Width}*{task.bmp.Height}],第 {i + 1}/{cut_count} 张小图[{task.bmps_cut[i].Width}*{task.bmps_cut[i].Height}]: 瑕疵output_num = {output_num[i]}\n"; + #region 检测信息汇总 + for (int j = 0; j < task.output_num[i]; j++)//缺陷数 + { + liStep += j;//0 + //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"-------"); + int index = count * detect_elem_size; + + // 打印输出信息(示例代码,根据实际情况进行修改和格式化) + // 获取输出信息 + int x = (int)task.output[index]; + int y = (int)task.output[index + 1]; + int w = (int)task.output[index + 2]; + int h = (int)task.output[index + 3]; + int classId = (int)task.output[index + 4]; + double confidence = Math.Round(task.output[index + 5], 2); //置信度 + double contrast = Math.Round(task.output[index + 6], 3);//对比度 + //y = image_hight-y-h;//转到右下角为原点 + count++; + + var cmW = Math.Round(w * task.widthRatio / Config.cm2px_x, 2); + var cmH = Math.Round(h * task.widthRatio / Config.cm2px_y, 2); + // 打印输出信息 + task.resultInfo += $"----{i}----col:{i % colNum}/{colNum} row:{i / colNum}/{colNum}-----------\n目标:{j + 1} 类别ID:{classId} 置信度:{confidence} 对比度:{contrast} 坐标:({x},{y})-({x + w},{y + h}) 宽高:w={w},h={h}; \n"; + + DefectLabelInfoList.Add(new DefectLabelInfo() + { + x = (int)task.output[index], + y = (int)task.output[index + 1], + w = (int)task.output[index + 2], + h = (int)task.output[index + 3], + classId = (int)task.output[index + 4], + confidence = Math.Round(task.output[index + 5], 2), //置信度 + contrast = Math.Round(task.output[index + 6], 3),//对比度 + cmW = Math.Round(w * task.widthRatio / Config.cm2px_x, 2), + cmH = Math.Round(h * task.widthRatio / Config.cm2px_y, 2), + i = i, + j = j, + }); + } + + #endregion +#if false for (int j = 0; j < task.output_num[i]; j++)//缺陷数 { liStep += j;//0 @@ -424,7 +489,7 @@ namespace LeatherApp.Device task.resultInfo += $"----{i}----col:{i % colNum}/{colNum} row:{i / colNum}/{colNum}-----------\n目标:{j + 1} 类别ID:{classId} 置信度:{confidence} 对比度:{contrast} 坐标:({x},{y})-({x + w},{y + h}) 宽高:w={w},h={h}; \n"; //是否满足此产品标准 if (task.qualifiedLimitList != null && task.qualifiedLimitList.Count > 0) - { + { qualifiedLimit = task.qualifiedLimitList.FirstOrDefault(m => m.Code == Config.getDefectCode(classId)); if (qualifiedLimit != null) { @@ -462,6 +527,7 @@ namespace LeatherApp.Device } } + //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"判断是瑕疵:类别ID:{classId}; 置信度({confidence},[{qualifiedLimit.ZXD}]); isOr({qualifiedLimit.IsOR}); 面积({cmW * cmH},[{ qualifiedLimit.Area}]); 对比度({contrast},[{qualifiedLimit.ContrastLower}-{qualifiedLimit.ContrastTop}])"); } } @@ -512,8 +578,111 @@ namespace LeatherApp.Device liStep++;//7 //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"缺陷小图数量:{task.lstDefectBmp.Count}"); } +#endif } + //结果过滤 + #region 结果过滤 + //降序排序,先得到是否有接头检出 + List DefectLabelInfoListByClassID = DefectLabelInfoList.OrderByDescending(t => t.classId).ToList();//降序 + for (int q = 0; q < DefectLabelInfoList.Count; q++) + { + //是否满足此产品标准 + if (task.qualifiedLimitList != null && task.qualifiedLimitList.Count > 0) + { + qualifiedLimit = task.qualifiedLimitList.FirstOrDefault(m => m.Code == Config.getDefectCode(DefectLabelInfoList[q].classId)); + if (qualifiedLimit != null) + { + //if ((qualifiedLimit.ZXD > 0 && qualifiedLimit.ZXD > confidence) + // || (qualifiedLimit.ContrastTop + qualifiedLimit.ContrastLower > 0 && x> qualifiedLimit.ContrastLower && x < qualifiedLimit.ContrastTop) + // || (qualifiedLimit.Area > 0 && qualifiedLimit.Area > cmW * cmH)) + if (DefectLabelInfoList[q].confidence <= qualifiedLimit.ZXD)//confidence > qualifiedLimit.ZXD 是瑕疵 才继续判断下面的两个条件 + { + task.resultInfo += $" 置信度不满足此产品瑕疵标准,跳过! \n"; + continue; + } + + //下限<对比度<上限:不是瑕疵 + var ContrastTotal = qualifiedLimit.ContrastTop + qualifiedLimit.ContrastLower; + if (qualifiedLimit.IsOR) + { + if (!( + (qualifiedLimit.Area <= 0 || DefectLabelInfoList[q].cmW * DefectLabelInfoList[q].cmH >= qualifiedLimit.Area) || + (ContrastTotal <= 0 || (DefectLabelInfoList[q].contrast < qualifiedLimit.ContrastLower || DefectLabelInfoList[q].contrast > qualifiedLimit.ContrastTop)))) + { + task.resultInfo += $" 不满足此产品瑕疵标准,跳过! \n"; + //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"判断不是瑕疵:类别ID:{classId}; 置信度({confidence},[{qualifiedLimit.ZXD}]); isOr({qualifiedLimit.IsOR}); 面积({cmW * cmH},[{ qualifiedLimit.Area}]); 对比度({contrast},[{qualifiedLimit.ContrastLower}-{qualifiedLimit.ContrastTop}])"); + continue; + } + } + else + { + if (!( + (qualifiedLimit.Area <= 0 || DefectLabelInfoList[q].cmW * DefectLabelInfoList[q].cmH >= qualifiedLimit.Area) && + (ContrastTotal <= 0 || (DefectLabelInfoList[q].contrast < qualifiedLimit.ContrastLower || DefectLabelInfoList[q].contrast > qualifiedLimit.ContrastTop)))) + { + task.resultInfo += $" 不满足此产品瑕疵标准,跳过! \n"; + //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"判断不是瑕疵:类别ID:{classId}; 置信度({confidence},[{qualifiedLimit.ZXD}]); isOr({qualifiedLimit.IsOR}); 面积({cmW * cmH},[{ qualifiedLimit.Area}]); 对比度({contrast},[{qualifiedLimit.ContrastLower}-{qualifiedLimit.ContrastTop}])"); + continue; + } + } + if (Config.getDefectCode(DefectLabelInfoList[q].classId) == "jietou") + haveJieTou = true; + if(haveJieTou && (Config.getDefectCode(DefectLabelInfoList[q].classId) == "hengdang")) + { + task.resultInfo += $" 判断为接头处横档,跳过! \n"; + continue; + } + //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"判断是瑕疵:类别ID:{classId}; 置信度({confidence},[{qualifiedLimit.ZXD}]); isOr({qualifiedLimit.IsOR}); 面积({cmW * cmH},[{ qualifiedLimit.Area}]); 对比度({contrast},[{qualifiedLimit.ContrastLower}-{qualifiedLimit.ContrastTop}])"); + } + } + liStep++;//1 + //打标 + var point1 = new OpenCvSharp.Point((DefectLabelInfoList[q].i % colNum) * image_width + DefectLabelInfoList[q].x, (DefectLabelInfoList[q].i / colNum) * image_hight + DefectLabelInfoList[q].y); + var point2 = new OpenCvSharp.Point(point1.X + DefectLabelInfoList[q].w, point1.Y + DefectLabelInfoList[q].h); + liStep++;//2 + task.resultInfo += $" 转换到大图坐标(px):p1={point1.X},{point1.Y}; p2={point2.X},{point2.Y}\n"; + Cv2.Rectangle(task.bmpTag, point1, point2, new Scalar(0.0, 0.0, 255.0), 1);//画打标点 + //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"保存第 {count} 行缺陷信息;"); + var cmX = Math.Round(point1.X * task.widthRatio / Config.cm2px_x, 2); + var cmY = Math.Round((task.bmp.Height - point1.Y - DefectLabelInfoList[q].h) * task.widthRatio / Config.cm2px_y, 2);//外面计Y从右下角为原点 + liStep++;//3 + task.resultInfo += $" 转换到大图坐标(cm)[widthRatio={task.widthRatio}]:x={cmX},y={cmY}; w={DefectLabelInfoList[q].cmW},h={DefectLabelInfoList[q].cmH}\n"; + task.excelTable.Rows.Add($"{task.photoIndex}", cmX, cmY, DefectLabelInfoList[q].cmW, DefectLabelInfoList[q].cmH, DefectLabelInfoList[q].j + 1, DefectLabelInfoList[q].classId, DefectLabelInfoList[q].confidence, DefectLabelInfoList[q].contrast); + + liStep++;//4 + //切缺陷小图 + //WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"保存第 {count} 个缺陷小图;"); + int left, top, decX, decY; + decX = (DefectLabelInfoList[q].w > 236 ? 20 : 256 - DefectLabelInfoList[q].w) / 2; + decY = (DefectLabelInfoList[q].h > 236 ? 20 : 256 - DefectLabelInfoList[q].h) / 2; + left = point1.X - decX; + top = point1.Y - decY; + if (left < 0) left = 0; + if (top < 0) top = 0; + + int width = DefectLabelInfoList[q].w + decX * 2; + int height = DefectLabelInfoList[q].h + decY * 2; + if (left + width > task.bmp.Width - 1) width = task.bmp.Width - left - 1; + if (top + height > task.bmp.Height - 1) height = task.bmp.Height - top - 1; + liStep++;//5 + Rect roi = new Rect(left, top, width, height); + liStep++;//6 + if (height < 1 || width < 1) + { + task.resultInfo += $" 打标到大图坐标Rect(px):left={left},top={top}; width={width},height={height}\n"; + task.resultInfo += $" test point1.Y={point1.Y},h={DefectLabelInfoList[q].h}; top={top},mat.Height={task.bmp.Height}\n================\n"; + WarningEvent?.Invoke(DateTime.Now, WarningEnum.Normal, task.resultInfo); + } + + //保存 + //string filename = $"{Config.appBasePath}\\temp\\{task.tag}\\{task.tag}_X{mmX.ToString()}_Y{mmY.ToString()}_W{mmW.ToString()}_H{mmH.ToString()}_目标{j + 1}_类别{classId}_置信度{confidence}.bmp"; + //OpenCvSharp.Extensions.BitmapConverter.ToBitmap(new Mat(task.bmp, roi)).Save(filename, ImageFormat.Jpeg); + + task.lstDefectBmp.Add(new Mat(task.bmpTag, roi).Clone()); + liStep++;//7 + } + #endregion liStep = 99; stopwatch.Stop(); task.stopwatch[3] = stopwatch.ElapsedMilliseconds; diff --git a/LeatherProject/LeatherApp/FrmVerList.resx b/LeatherProject/LeatherApp/FrmVerList.resx index baab57b..5ed0178 100644 --- a/LeatherProject/LeatherApp/FrmVerList.resx +++ b/LeatherProject/LeatherApp/FrmVerList.resx @@ -118,7 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - v1.0.2.3 (2024-02-8) + v1.0.2.4 (2024-03-15) +1、更新车用革情况,接头处过滤横档缺陷; +v1.0.2.3 (2024-02-8) 1、更新报表导出高度单位cm; 2、更新还在处理过程中,按停止按钮崩溃问题; v1.0.2.2 (2024-01-20) diff --git a/LeatherProject/LeatherApp/Properties/AssemblyInfo.cs b/LeatherProject/LeatherApp/Properties/AssemblyInfo.cs index ac0328f..dae0db2 100644 --- a/LeatherProject/LeatherApp/Properties/AssemblyInfo.cs +++ b/LeatherProject/LeatherApp/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.2.3")] -[assembly: AssemblyFileVersion("1.0.2.3")] +[assembly: AssemblyVersion("1.0.2.4")] +[assembly: AssemblyFileVersion("1.0.2.4")] diff --git a/LeatherProject/LeatherApp/obj/Debug/LeatherApp.FrmVerList.resources b/LeatherProject/LeatherApp/obj/Debug/LeatherApp.FrmVerList.resources index 8727fc6..a1facd6 100644 Binary files a/LeatherProject/LeatherApp/obj/Debug/LeatherApp.FrmVerList.resources and b/LeatherProject/LeatherApp/obj/Debug/LeatherApp.FrmVerList.resources differ