using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using System.IO;
|
using Bro.Common;
|
using Bro.Common.Util;
|
|
namespace P066.Data
|
{
|
public partial class Form1 : Form
|
{
|
DirectoryInfo directoryInfo1;
|
DirectoryInfo directoryInfo2;
|
private P066RunParam runparam = new P066RunParam();
|
|
|
public Form1()
|
{
|
InitializeComponent();
|
//ConfigHelper.Save(@"D:\P066-Data\P066XML\1.xml", runparam);
|
runparam = ConfigHelper.Load<P066RunParam>(@"E:\P066.Data\P066XML\Jin_Mid.xml");
|
|
|
}
|
|
private void btnLoadData1_Click(object sender, EventArgs e)
|
{
|
if (folderBrowserDialog1.ShowDialog() != DialogResult.OK)
|
return;
|
directoryInfo1 = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
|
}
|
|
private void btnLoadData2_Click(object sender, EventArgs e)
|
{
|
if (folderBrowserDialog1.ShowDialog() != DialogResult.OK)
|
return;
|
|
directoryInfo2 = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
|
}
|
|
|
|
private void btnAnalyze_Click(object sender, EventArgs e)
|
{
|
|
var fileinfos1 = directoryInfo1.GetFiles();
|
var fileinfos2 = directoryInfo2.GetFiles();
|
var listSum = new List<ResultData>();
|
var JudgeListSum = new List<ResultData>();
|
string filename = "";
|
string filenameDir = "";
|
int WhiteI = 0;
|
int WhiteningI = 0;
|
int ChuNum = 0;
|
int FuNum = 0;
|
int GuaNum = 0;
|
#region//获取时间戳并排序
|
var allLines1 = File.ReadAllLines(fileinfos1[0].FullName, Encoding.Default);
|
List<ResultData> dataList1 = new List<ResultData>();
|
if (allLines1.Length > 1)
|
{
|
dataList1 = GetData(allLines1);
|
}
|
var dataGroup111 = dataList1.GroupBy(a => a.TimeTip);
|
var dataListSum22 = new List<string>();
|
foreach (var item in dataGroup111)
|
{
|
dataListSum22.Add(item.Key);
|
}
|
dataListSum22 = dataListSum22.Distinct().ToList();
|
dataListSum22.Sort();
|
#endregion
|
|
for (int i = 0; i < fileinfos1.Length; i++)
|
{
|
var list = CompareFile(fileinfos1[i], fileinfos2[i],dataListSum22);
|
var judgeList = JudgeCompareFile(fileinfos1[i], fileinfos2[i],dataListSum22);
|
|
if (fileinfos1[i].Name.Contains("白点"))
|
{
|
WhiteI++;
|
list.ForEach(a => a.Lensnumber = WhiteI);
|
listSum.AddRange(list);
|
judgeList.ForEach(a => a.Lensnumber = WhiteI);
|
JudgeListSum.AddRange(judgeList);
|
}
|
if (fileinfos1[i].Name.Contains("刮白"))
|
{
|
WhiteningI++;
|
list.ForEach(a => a.Lensnumber = WhiteningI);
|
listSum.AddRange(list);
|
judgeList.ForEach(a => a.Lensnumber = WhiteningI);
|
JudgeListSum.AddRange(judgeList);
|
|
}
|
|
string currPath = "";
|
#region//判断是初检文件夹还是复检文件夹
|
if (fileinfos1[i].Name.Contains("初检中框"))
|
{
|
ChuNum++;
|
filenameDir = "初检中框白点";
|
filename = "初检中框白点" + ChuNum;
|
judgeList = GetMidLocation(judgeList);
|
//给镜头区分位置及角度
|
list = GetMidLocation(list);
|
}
|
else if (fileinfos1[i].Name.Contains("复检中框")&& fileinfos1[i].Name.Contains("白点"))
|
{
|
FuNum=FuNum+1;
|
filenameDir = "复检中框白点";
|
filename = "复检中框白点" + FuNum;
|
judgeList = GetMidLocation(judgeList);
|
//给镜头区分位置及角度
|
list = GetMidLocation(list);
|
}
|
else if ( fileinfos1[i].Name.Contains("复检中框") &&fileinfos1[i].Name.Contains("刮白"))
|
{
|
GuaNum=GuaNum+1;
|
filenameDir = "复检中框刮白";
|
filename = "复检中框刮白" + GuaNum;
|
judgeList = GetBkLocation(judgeList);
|
//给镜头区分位置及角度
|
list = GetBkLocation(list);
|
}
|
else if (fileinfos1[i].Name.Contains("初检背板"))
|
{
|
ChuNum++;
|
filenameDir = "初检背板白点";
|
filename = "初检背板白点" + ChuNum;
|
judgeList = GetBkLocation(judgeList);
|
//给镜头区分位置及角度
|
list = GetBkLocation(list);
|
}
|
else if (fileinfos1[i].Name.Contains("复检背板") && fileinfos1[i].Name.Contains("白点"))
|
{
|
FuNum = FuNum + 1;
|
filenameDir = "复检背板白点";
|
filename = "复检背板白点" + FuNum;
|
judgeList = GetBkLocation(judgeList);
|
//给镜头区分位置及角度
|
list = GetBkLocation(list);
|
}
|
|
currPath = directoryInfo1.Parent.Parent.FullName;
|
string subPath = currPath + "/" + filenameDir + "合并后" + "/";
|
if (false==Directory.Exists(subPath))
|
{
|
Directory.CreateDirectory(subPath);
|
}
|
|
#endregion
|
|
|
var title1 = $"时间戳,文件名,判断,可能性,不确定性,高,宽,X,Y,最大尺寸,位置,R,角度";
|
var file1 = $"{subPath}\\{filename}.csv";
|
File.AppendAllText(file1, title1, Encoding.UTF8);
|
File.AppendAllText(file1, "\r\n");
|
|
#region//计算总数
|
|
//var group1 = list.GroupBy(a => a.TimeTip);
|
|
//var title2 = $"时间戳,总数";
|
//var file2 = $"{directoryInfo1.Parent.FullName}\\{ "总数" +( i+1)}.csv";
|
//File.AppendAllText(file2, title2, Encoding.UTF8);
|
//File.AppendAllText(file2, "\r\n");
|
//foreach (var item in group1)
|
//{
|
// var content = $"{item.Key},{item.ToList().Count}";
|
|
// File.AppendAllText(file2, content, Encoding.UTF8);
|
// File.AppendAllText(file2, "\r\n");
|
//}
|
#endregion
|
|
foreach (var item in dataListSum22)
|
{
|
var list11 = list.FindAll(a =>a.TimeTip==item&&!a.Result);
|
for (int q = 0; q < list11.Count; q++)
|
{
|
string result = list11[q].Result ? "OK" : "NG";
|
|
var content = $"{list11[q].TimeTip},{list11[q].ImageFileName},{result},{list11[q].Probability},{list11[q].Uncertainty},{list11[q].Height},{list11[q].Width},{list11[q].X},{list11[q].Y},{list11[q].ex},{list11[q].location},{ Convert.ToInt32(list11[q].R)},{ Convert.ToInt32(list11[q].angle)}";
|
|
File.AppendAllText(file1, content, Encoding.UTF8);
|
File.AppendAllText(file1, "\r\n");
|
}
|
|
|
}
|
}
|
|
|
#region//将设备判断结果输出到CSV报表中
|
var title12 = $"时间戳,相机序号,设备判断结果,缺陷类型,设备后处理结果,最大尺寸,位置,X,Y,R,角度";
|
var file12 = $"{directoryInfo1.Parent.FullName}\\{filenameDir + "设备判断结果"}.csv";
|
File.AppendAllText(file12, title12, Encoding.UTF8);
|
File.AppendAllText(file12, "\r\n");
|
foreach (var item in dataListSum22)
|
{
|
var Lens1 = JudgeListSum.FindAll(a => a.TimeTip == item&&a.Lensnumber==1);
|
WriteJR(Lens1,item,1,file12);
|
var Lens2 = JudgeListSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 2);
|
WriteJR(Lens2,"",2,file12);
|
var Lens3 = JudgeListSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 3);
|
WriteJR(Lens3,"",3,file12);
|
var Lens4 = JudgeListSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 4);
|
WriteJR(Lens4,"",4,file12);
|
|
}
|
#endregion
|
|
|
|
|
#region//根据产品编号输出总缺陷报表
|
var title = $"产品编号,镜头编号,总缺陷数量";
|
var file = $"{directoryInfo1.Parent.FullName}\\{filenameDir + "缺陷总数报表"}.csv";
|
File.AppendAllText(file, title, Encoding.UTF8);
|
File.AppendAllText(file, "\r\n");
|
foreach (var item in dataListSum22)
|
{
|
var listLensnumber1 = listSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 1);
|
var listLensnumberCount1 = listLensnumber1.Count;
|
var listLensnumber2 = listSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 2);
|
var listLensnumberCount2 = listLensnumber2.Count;
|
var listLensnumber3 = listSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 3);
|
var listLensnumberCount3 = listLensnumber3.Count;
|
var listLensnumber4 = listSum.FindAll(a => a.TimeTip == item&& a.Lensnumber == 4);
|
var listLensnumberCount4 = listLensnumber4.Count;
|
//第一行
|
var content1 = $"{item},{1},{listLensnumberCount1}";
|
File.AppendAllText(file, content1, Encoding.UTF8);
|
File.AppendAllText(file, "\r\n");
|
//第二行
|
var content2 = $"{""},{2},{listLensnumberCount2}";
|
File.AppendAllText(file, content2, Encoding.UTF8);
|
File.AppendAllText(file, "\r\n");
|
//第三行
|
var content3 = $"{""},{3},{listLensnumberCount3}";
|
File.AppendAllText(file, content3, Encoding.UTF8);
|
File.AppendAllText(file, "\r\n");
|
//第四行
|
var content4 = $"{""},{4},{listLensnumberCount4}";
|
File.AppendAllText(file, content4, Encoding.UTF8);
|
File.AppendAllText(file, "\r\n");
|
|
}
|
#endregion
|
|
|
}
|
|
|
private List<ResultData> CompareFile(FileInfo fileInfo1, FileInfo fileInfo2,List<string> DataTipsor)
|
{
|
var allLines1 = File.ReadAllLines(fileInfo1.FullName, Encoding.Default);
|
var allLines2 = File.ReadAllLines(fileInfo2.FullName, Encoding.Default);
|
List<ResultData> dataList1 = new List<ResultData>();
|
List<ResultData> dataList2 = new List<ResultData>();
|
if (allLines1.Length>1)
|
{
|
dataList1 = GetData(allLines1);
|
}
|
if (allLines2.Length > 1)
|
{
|
dataList2 = GetData(allLines2);
|
}
|
|
|
|
var dataList = new List<ResultData>();
|
var dataList11 = new List<ResultData>();
|
var dataList22 = new List<ResultData>();
|
foreach (var item in DataTipsor)
|
{
|
var list1 = dataList1.FindAll(a => a.TimeTip == item && !a.Result);
|
var list2 = dataList2.FindAll(a => a.TimeTip == item && !a.Result);
|
var itemToRemove = new List<ResultData>();
|
#region//计算表格2最大尺寸
|
for (int ii = 0; ii < list2.Count; ii++)
|
{
|
if (list2[ii].Width > list2[ii].Height)
|
{
|
list2[ii].ex = list2[ii].Width * 0.0042;
|
}
|
else
|
{
|
list2[ii].ex = list2[ii].Height * 0.0042;
|
}
|
var distance = GetDistance(1050, 1050, list2[ii].X, list2[ii].Y);
|
list2[ii].R = distance;
|
}
|
#endregion
|
for (int i = 0; i < list1.Count; i++)
|
{
|
#region//计算表格1最大尺寸
|
if (list1[i].Width > list1[i].Height)
|
{
|
list1[i].ex = list1[i].Width * 0.0042;
|
}
|
else
|
{
|
list1[i].ex = list1[i].Height * 0.0042;
|
}
|
var distance1 = GetDistance(1050, 1050, list1[i].X, list1[i].Y);
|
list1[i].R = distance1;
|
|
#endregion
|
for (int j = 0; j < list2.Count; j++)
|
{
|
|
var distance = GetDistance(list1[i].X, list1[i].Y, list2[j].X, list2[j].Y);
|
if (distance < 20)
|
{
|
itemToRemove.Add(list2[j]);
|
//if (list1[i].PostTreatmentResults=="")
|
//{
|
// list1[i].PostTreatmentResults = list2[j].PostTreatmentResults;
|
//}
|
//else
|
//{
|
// list2[j].PostTreatmentResults = list1[i].PostTreatmentResults;
|
//}
|
}
|
}
|
}
|
|
for (int i = 0; i < itemToRemove.Count; i++)
|
{
|
list2.Remove(itemToRemove[i]);
|
}
|
|
dataList.AddRange(list1);
|
dataList.AddRange(list2);
|
}
|
|
|
//dataList.AddRange(dataList1);
|
//dataList.AddRange(dataList2);
|
return dataList;
|
}
|
//统计设备判断结果
|
private List<ResultData> JudgeCompareFile(FileInfo fileInfo1, FileInfo fileInfo2,List<string> DataTipsor)
|
{
|
|
|
var allLines1 = File.ReadAllLines(fileInfo1.FullName, Encoding.Default);
|
var allLines2 = File.ReadAllLines(fileInfo2.FullName, Encoding.Default);
|
List<ResultData> dataList1 = new List<ResultData>();
|
List<ResultData> dataList2 = new List<ResultData>();
|
if (allLines1.Length > 1)
|
{
|
dataList1 = GetData(allLines1);
|
}
|
if (allLines2.Length > 1)
|
{
|
dataList2 = GetData(allLines2);
|
}
|
|
|
|
var dataList = new List<ResultData>();
|
var dataList11 = new List<ResultData>();
|
var dataList22 = new List<ResultData>();
|
foreach (var item in DataTipsor)
|
{
|
var list1 = dataList1.FindAll(a => a.TimeTip == item && !a.Result);
|
var list2 = dataList2.FindAll(a => a.TimeTip == item && !a.Result);
|
var itemToRemove1 = new List<ResultData>();
|
#region//计算表格2最大尺寸
|
for (int ii = 0; ii < list2.Count; ii++)
|
{
|
if (list2[ii].Width > list2[ii].Height)
|
{
|
list2[ii].ex = list2[ii].Width * 0.0042;
|
}
|
else
|
{
|
list2[ii].ex = list2[ii].Height * 0.0042;
|
}
|
var distance = GetDistance(1050, 1050, list2[ii].X, list2[ii].Y);
|
list2[ii].R = distance;
|
}
|
#endregion
|
for (int i = 0; i < list1.Count; i++)
|
{
|
#region//计算表格1最大尺寸
|
if (list1[i].Width > list1[i].Height)
|
{
|
list1[i].ex = list1[i].Width * 0.0042;
|
}
|
else
|
{
|
list1[i].ex = list1[i].Height * 0.0042;
|
}
|
var distance1 = GetDistance(1050, 1050, list1[i].X, list1[i].Y);
|
list1[i].R = distance1;
|
|
#endregion
|
for (int j = 0; j < list2.Count; j++)
|
{
|
|
var distance = GetDistance(list1[i].X, list1[i].Y, list2[j].X, list2[j].Y);
|
if (distance < 20)
|
{
|
itemToRemove1.Add(list2[j]);
|
if (list1[i].JudgmentResult!=list2[j].JudgmentResult)
|
{
|
list1[i].JudgmentResult = "NG";
|
list2[j].JudgmentResult = "NG";
|
}
|
//if (list1[i].PostTreatmentResults == "")
|
//{
|
// list1[i].PostTreatmentResults = list2[j].PostTreatmentResults;
|
//}
|
//else
|
//{
|
// list2[j].PostTreatmentResults = list1[i].PostTreatmentResults;
|
//}
|
|
}
|
}
|
}
|
|
for (int i = 0; i < itemToRemove1.Count; i++)
|
{
|
list2.Remove(itemToRemove1[i]);
|
}
|
|
dataList11.AddRange(list1);
|
dataList22.AddRange(list2);
|
}
|
|
//var itemToRemove = new List<ResultData>();
|
foreach (var item in DataTipsor)
|
{
|
|
var list1 = dataList11.FindAll(a => a.TimeTip == item/* && a.JudgmentResult == "NG"*/ ); //不管OK、NG都要输出
|
var list2 = dataList22.FindAll(a => a.TimeTip == item /*&& a.JudgmentResult == "NG"*/); //不管OK、NG都要输出
|
|
dataList.AddRange(list1);
|
dataList.AddRange(list2);
|
}
|
|
return dataList;
|
|
}
|
|
private List<ResultData> GetData(string[] allLines)
|
{
|
var dataList = new List<ResultData>();
|
var nametemp = allLines[1].Split(',')[0];
|
var resulttemp = allLines[1].Split(',')[1];
|
string Ptr = "";
|
//if (allLines[1].Split(',')[10].Length>3)
|
//{
|
// Ptr = allLines[1].Split(',')[10];
|
//}
|
|
string defectType = "";
|
string judgmentresult = "";
|
for (int i = 1; i < allLines.Length; i++)
|
{
|
|
var data = allLines[i].Split(',');
|
|
//if (data.Length>10)
|
//{
|
// Ptr = data[10];
|
//}
|
|
|
|
//string Ptr = "";
|
if (data[0] == "")
|
{
|
data[0] = nametemp;
|
data[1] = resulttemp;
|
if (data[3] != "刮白")
|
{
|
data[10] = Ptr;
|
}
|
|
}
|
if (data[3]== "刮白")
|
{
|
defectType = "刮白";
|
judgmentresult =data[1];
|
Ptr = "刮白";
|
}
|
else
|
{
|
defectType = "白点";
|
judgmentresult = data[1];
|
}
|
|
if (data[6] == "-")
|
{
|
|
dataList.Add(new ResultData()
|
{
|
TimeTip = data[0].Split('-')[0],
|
ImageFileName = data[0],
|
JudgmentResult = data[1],
|
Result = data[3] == "OK",
|
DefectType = defectType,
|
|
}); ; ;
|
|
continue;
|
|
}
|
var data6 = data[6].Split('#').ToList();
|
data6.Remove("");
|
var temp6 = Convert.ToInt32(data6[0]);
|
for (int a6 = 0; a6 < data6.Count; a6++)
|
{
|
if (Convert.ToInt32(data6[a6]) > temp6)
|
{
|
temp6 = Convert.ToInt32(data6[a6]);
|
}
|
}
|
data[6] = Convert.ToString(temp6);
|
|
var data7 = data[7].Split('#').ToList();
|
data7.Remove("");
|
var temp7 = Convert.ToInt32(data7[0]);
|
for (int a7 = 0; a7 < data7.Count; a7++)
|
{
|
if (Convert.ToInt32(data7[a7]) > temp7)
|
{
|
temp7 = Convert.ToInt32(data7[a7]);
|
}
|
}
|
data[7] = Convert.ToString(temp7);
|
if (data[3]=="NG")
|
{
|
Ptr = data[10];
|
}
|
else
|
{
|
Ptr = "";
|
}
|
|
dataList.Add(new ResultData()
|
{
|
TimeTip = data[0].Split('-')[0],
|
ImageFileName = data[0],
|
JudgmentResult = judgmentresult,
|
Result = data[3] == "OK",
|
Probability = Convert.ToDouble(data[4]),
|
Uncertainty = Convert.ToDouble(data[5]),
|
//Height = Convert.ToDouble(data[6].Replace("#", "").Replace("-", "")),
|
//Width = Convert.ToDouble(data[7].Replace("#", "").Replace("-", "")),
|
Height = Convert.ToDouble(data[6]),
|
Width = Convert.ToDouble(data[7]),
|
X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")),
|
Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")),
|
DefectType = defectType,
|
PostTreatmentResults = Ptr,
|
|
}) ; ; ;
|
|
nametemp = data[0];
|
resulttemp= data[1];
|
//Ptr = data[10];
|
|
}
|
|
return dataList;
|
}
|
|
//获取中框角度和位置
|
private List<ResultData> GetMidLocation(List<ResultData> list)
|
{
|
var group = list.GroupBy(a => a.TimeTip);
|
foreach (var item in group)
|
{
|
//计算镜头1缺陷位置及角度
|
var listLensnumber1 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 1);
|
for (int k = 0; k < listLensnumber1.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber1[k].X, listLensnumber1[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber1[k].angle = lenAngle;
|
|
var distance = GetDistance(1050, 1050, listLensnumber1[k].X, listLensnumber1[k].Y);
|
if (distance <= runparam.MidLens1R1)
|
{
|
listLensnumber1[k].location = "镜头";
|
}
|
else if (runparam.MidLens1R1 < distance && distance <= runparam.MidLens1R2)
|
{
|
listLensnumber1[k].location = "斜面";
|
}
|
else
|
{
|
listLensnumber1[k].location = "平面";
|
}
|
|
}
|
//计算镜头2位置及角度
|
var listLensnumber2 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 2);
|
for (int k = 0; k < listLensnumber2.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber2[k].X, listLensnumber2[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber2[k].angle = lenAngle;
|
var distance = GetDistance(1050, 1050, listLensnumber2[k].X, listLensnumber2[k].Y);
|
if (distance <= runparam.MidLens2R1)
|
{
|
listLensnumber2[k].location = "镜头";
|
}
|
else if (runparam.MidLens2R1 < distance && distance <= runparam.MidLens2R2)
|
{
|
listLensnumber2[k].location = "斜面";
|
}
|
else
|
{
|
listLensnumber2[k].location = "平面";
|
}
|
}
|
//计算镜头3位置及角度
|
var listLensnumber3 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 3);
|
for (int k = 0; k < listLensnumber3.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber3[k].X, listLensnumber3[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber3[k].angle = lenAngle;
|
var distance = GetDistance(1050, 1050, listLensnumber3[k].X, listLensnumber3[k].Y);
|
if (distance <= runparam.MidLens3R1)
|
{
|
listLensnumber3[k].location = "镜头";
|
}
|
else if ( runparam.MidLens3R1< distance && distance <= runparam.MidLens3R2)
|
{
|
listLensnumber3[k].location = "斜面";
|
}
|
else
|
{
|
listLensnumber3[k].location = "平面";
|
}
|
}
|
//计算镜头4位置及角度
|
var listLensnumber4 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 4);
|
for (int k = 0; k < listLensnumber4.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber4[k].X, listLensnumber4[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber4[k].angle = lenAngle;
|
var distance = GetDistance(1050, 1050, listLensnumber4[k].X, listLensnumber4[k].Y);
|
if (distance <= runparam.MidLens4R1)
|
{
|
listLensnumber4[k].location = "镜头";
|
}
|
else if (runparam.MidLens4R1 < distance && distance <= runparam.MidLens4R2)
|
{
|
listLensnumber4[k].location = "斜面";
|
}
|
else
|
{
|
listLensnumber4[k].location = "平面";
|
|
}
|
}
|
|
}
|
return list;
|
}
|
//获取背板角度和位置
|
private List<ResultData> GetBkLocation(List<ResultData> list)
|
{
|
var group = list.GroupBy(a => a.TimeTip);
|
foreach (var item in group)
|
{
|
//计算镜头1缺陷位置及角度
|
var listLensnumber1 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 1);
|
for (int k = 0; k < listLensnumber1.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber1[k].X, listLensnumber1[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber1[k].angle = lenAngle;
|
|
var distance = GetDistance(1050, 1050, listLensnumber1[k].X, listLensnumber1[k].Y);
|
if (distance <= runparam.BkLens1R1)
|
{
|
listLensnumber1[k].location = "可视区";
|
}
|
|
else
|
{
|
listLensnumber1[k].location = "非可视区";
|
}
|
|
}
|
//计算镜头2位置及角度
|
var listLensnumber2 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 2);
|
for (int k = 0; k < listLensnumber2.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber2[k].X, listLensnumber2[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber2[k].angle = lenAngle;
|
var distance = GetDistance(1050, 1050, listLensnumber2[k].X, listLensnumber2[k].Y);
|
if (distance <= runparam.BkLens2R1)
|
{
|
listLensnumber2[k].location = "可视区";
|
}
|
else
|
{
|
listLensnumber2[k].location = "非可视区";
|
}
|
}
|
//计算镜头3位置及角度
|
var listLensnumber3 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 3);
|
for (int k = 0; k < listLensnumber3.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber3[k].X, listLensnumber3[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber3[k].angle = lenAngle;
|
var distance = GetDistance(1050, 1050, listLensnumber3[k].X, listLensnumber3[k].Y);
|
if (distance <= runparam.BkLens3R1)
|
{
|
listLensnumber3[k].location = "可视区";
|
}
|
|
else
|
{
|
listLensnumber3[k].location = "非可视区";
|
}
|
}
|
//计算镜头4位置及角度
|
var listLensnumber4 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 4);
|
for (int k = 0; k < listLensnumber4.Count; k++)
|
{
|
var lenAngle = GetAngle(listLensnumber4[k].X, listLensnumber4[k].Y);
|
if (lenAngle < 0)
|
{
|
lenAngle = 360 + lenAngle;
|
}
|
listLensnumber4[k].angle = lenAngle;
|
var distance = GetDistance(1050, 1050, listLensnumber4[k].X, listLensnumber4[k].Y);
|
if (distance <= runparam.BkLens4R1)
|
{
|
listLensnumber4[k].location = "可视区";
|
}
|
else
|
{
|
listLensnumber4[k].location = "非可视区";
|
|
}
|
}
|
|
}
|
return list;
|
}
|
|
private void WriteJR(List<ResultData> Lens,string item,int LensNumb, string file12)
|
{
|
if (Lens.Count == 0)
|
{
|
|
var content11 = $"{item},{LensNumb},{"OK"}";
|
File.AppendAllText(file12, content11, Encoding.UTF8);
|
File.AppendAllText(file12, "\r\n");
|
}
|
else
|
{
|
if (Lens[0].DefectType == "刮白")
|
{
|
var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}";
|
File.AppendAllText(file12, content11, Encoding.UTF8);
|
File.AppendAllText(file12, "\r\n");
|
for (int i = 0; i < Lens.Count; i++)
|
{
|
if (Lens[i].DefectType == "刮白")
|
{
|
var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
|
File.AppendAllText(file12, content111, Encoding.UTF8);
|
File.AppendAllText(file12, "\r\n");
|
}
|
else
|
{
|
var content111 = $"{""},{""},{""},{Lens[i].DefectType},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
|
File.AppendAllText(file12, content111, Encoding.UTF8);
|
File.AppendAllText(file12, "\r\n");
|
}
|
|
}
|
}
|
else
|
{
|
var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType},{Lens[0].PostTreatmentResults}";
|
File.AppendAllText(file12, content11, Encoding.UTF8);
|
File.AppendAllText(file12, "\r\n");
|
for (int i = 0; i < Lens.Count; i++)
|
{
|
var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
|
File.AppendAllText(file12, content111, Encoding.UTF8);
|
File.AppendAllText(file12, "\r\n");
|
}
|
}
|
|
}
|
}
|
|
|
|
private double GetDistance(double x1, double y1, double x2, double y2)
|
{
|
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
|
}
|
private double GetAngle(double x1, double y1)
|
{
|
return Math.Atan2((y1 - 1050), (x1 - 1050)) * (180 / Math.PI);
|
}
|
|
}
|
|
public class ResultData
|
{
|
public string TimeTip = "";
|
public string JudgmentResult = "";
|
public string ImageFileName = "";
|
public bool Result = true;
|
public int Lensnumber = 0;
|
public double Probability = 0;
|
public double Uncertainty = 0;
|
public double Height = 0;
|
public double Width = 0;
|
public double X = 0;
|
public double Y = 0;
|
public double ex = 0;
|
public string location = "";
|
public double angle = 0;
|
public double R = 0;
|
public string DefectType = "";
|
public string PostTreatmentResults = "";
|
|
|
}
|
|
|
}
|