V1.0 接头处去除横档判断
This commit is contained in:
parent
51c051fde1
commit
30ff04ea77
Binary file not shown.
Binary file not shown.
@ -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()
|
private void run3()
|
||||||
{
|
{
|
||||||
@ -395,11 +413,58 @@ namespace LeatherApp.Device
|
|||||||
int rowNum = task.bmp.Height / image_hight;
|
int rowNum = task.bmp.Height / image_hight;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
liStep = 3;
|
liStep = 3;
|
||||||
|
|
||||||
|
//车用革去除接头处横档误判
|
||||||
|
bool haveJieTou = false;
|
||||||
|
List<DefectLabelInfo> DefectLabelInfoList = new List<DefectLabelInfo>();
|
||||||
|
|
||||||
for (int i = 0; i < cut_count; i++)
|
for (int i = 0; i < cut_count; i++)
|
||||||
{
|
{
|
||||||
liStep = i * 100;
|
liStep = i * 100;
|
||||||
task.resultInfo += $"第 {i}/{cut_count} 张小图(大图索引{task.photoIndex}): 缺陷数 = {task.output_num[i]}\n";
|
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";
|
//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++)//缺陷数
|
for (int j = 0; j < task.output_num[i]; j++)//缺陷数
|
||||||
{
|
{
|
||||||
liStep += j;//0
|
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";
|
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)
|
if (task.qualifiedLimitList != null && task.qualifiedLimitList.Count > 0)
|
||||||
{
|
{
|
||||||
qualifiedLimit = task.qualifiedLimitList.FirstOrDefault(m => m.Code == Config.getDefectCode(classId));
|
qualifiedLimit = task.qualifiedLimitList.FirstOrDefault(m => m.Code == Config.getDefectCode(classId));
|
||||||
if (qualifiedLimit != null)
|
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}])");
|
//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
|
liStep++;//7
|
||||||
//WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"缺陷小图数量:{task.lstDefectBmp.Count}");
|
//WarningEvent?.Invoke(DateTime.Now,WarningEnum.Low, $"缺陷小图数量:{task.lstDefectBmp.Count}");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//结果过滤
|
||||||
|
#region 结果过滤
|
||||||
|
//降序排序,先得到是否有接头检出
|
||||||
|
List<DefectLabelInfo> 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;
|
liStep = 99;
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
|
task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
|
||||||
|
@ -118,7 +118,9 @@
|
|||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<data name="textBox1.Text" xml:space="preserve">
|
<data name="textBox1.Text" xml:space="preserve">
|
||||||
<value>v1.0.2.3 (2024-02-8)
|
<value>v1.0.2.4 (2024-03-15)
|
||||||
|
1、更新车用革情况,接头处过滤横档缺陷;
|
||||||
|
v1.0.2.3 (2024-02-8)
|
||||||
1、更新报表导出高度单位cm;
|
1、更新报表导出高度单位cm;
|
||||||
2、更新还在处理过程中,按停止按钮崩溃问题;
|
2、更新还在处理过程中,按停止按钮崩溃问题;
|
||||||
v1.0.2.2 (2024-01-20)
|
v1.0.2.2 (2024-01-20)
|
||||||
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||||
//通过使用 "*",如下所示:
|
//通过使用 "*",如下所示:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.2.3")]
|
[assembly: AssemblyVersion("1.0.2.4")]
|
||||||
[assembly: AssemblyFileVersion("1.0.2.3")]
|
[assembly: AssemblyFileVersion("1.0.2.4")]
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user