Procházet zdrojové kódy

V2.0 博艺联通正常使用

LianTong
CPL před 1 rokem
rodič
revize
2146db7dde
8 změnil soubory, kde provedl 361 přidání a 98 odebrání
  1. binární
     
  2. binární
     
  3. +1
    -1
      LeatherProject/GeBoShi/.vs/GeBoShi.csproj.dtbcache.json
  4. +1
    -1
      LeatherProject/GeBoShi/ImageDefect/DefectLib.cs
  5. +1
    -0
      LeatherProject/GeBoShi/Main.cs
  6. +56
    -40
      LeatherProject/GeBoShi/SysCtrl/OpencvUtils.cs
  7. +300
    -56
      LeatherProject/GeBoShi/SysCtrl/SysMgr.cs
  8. +2
    -0
      LeatherProject/GeBoShi/UI/Product/ProductInfoFrm.cs

binární
Zobrazit soubor


binární
Zobrazit soubor


+ 1
- 1
LeatherProject/GeBoShi/.vs/GeBoShi.csproj.dtbcache.json
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 1
- 1
LeatherProject/GeBoShi/ImageDefect/DefectLib.cs Zobrazit soubor

@@ -75,7 +75,7 @@ namespace GeBoShi.ImageDefect
private readonly int image_channels = 3;
private readonly int image_bytes = 2048 * 2048 * 3;
private readonly int detect_elem_size = 7; //维度数据结果,x y w h conf classid
private readonly int detect_max_object_num = 20;//这个指的是一张子图可能最多给你返回的目标个
private readonly int detect_max_object_num = 20;//这个指的是一张子图可能最多给你返回的目标个
public Action<int, int> QueueCountEvent;//0/1/2, 数量
#endregion


+ 1
- 0
LeatherProject/GeBoShi/Main.cs Zobrazit soubor

@@ -1075,6 +1075,7 @@ namespace GeBoShi
}
else
{
AddTextEvent($"二次检测2", $"本次忽略判断");
reFreashFrm(index, ld, e.Records, null);
}
//});


+ 56
- 40
LeatherProject/GeBoShi/SysCtrl/OpencvUtils.cs Zobrazit soubor

@@ -22,7 +22,7 @@ namespace GeBoShi.SysCtrl
//Mat mat2 = new Mat();
//ResizeUniform(mat, dsize, out mat2, out xw);
xw = 0;
xw = (width - mat.Cols) / 2;
Mat mat2 = new Mat(height, width, MatType.CV_8UC3, new Scalar(114, 114, 114));
Rect roi = new Rect((width - mat.Cols) / 2, (height - mat.Rows) / 2, mat.Cols, mat.Rows);
mat.CopyTo(new Mat(mat2, roi));
@@ -225,48 +225,60 @@ namespace GeBoShi.SysCtrl
int length = (int)total.Average();
marginWidth = width-length;
#endif
int length = len; //(len > mat_rgb.Width / 2) ? len : mat_rgb.Width - len;
if (isLeft)
marginWidth = length;
else
marginWidth = mat_rgb.Width - length;
// 判断数据是否异常,判断当前线段的宽度是否大于设定像素的偏差
//int abnormal_pxl = 200;
//for (int i = 0; i < num_rows; i++)
//{
// if (Math.Abs(total[i] - length) > abnormal_pxl)
// throw new Exception("数据异常,当段图片的宽度有问题!");
//}
if (len > 0)
{
int length = len; //(len > mat_rgb.Width / 2) ? len : mat_rgb.Width - len;
if (isLeft)
marginWidth = length;
else
marginWidth = mat_rgb.Width - length;
// 判断数据是否异常,判断当前线段的宽度是否大于设定像素的偏差
//int abnormal_pxl = 200;
//for (int i = 0; i < num_rows; i++)
//{
// if (Math.Abs(total[i] - length) > abnormal_pxl)
// throw new Exception("数据异常,当段图片的宽度有问题!");
//}
//右侧相机,拍摄产品,边缘位于右侧判断,缩进100像素,去点针眼
//Cv2.Line(mat_rgb, new Point(length - 100, 0), new Point(length - 100, height), new Scalar(255, 0, 0), 20);
////左侧相机,拍摄产品,边缘位于左侧判断,缩进100像素,去点针眼
//Cv2.Line(mat_rgb, new Point(width - length + 100, 0), new Point(width - length + 100, height), new Scalar(0, 255, 0), 20);
//右侧相机,拍摄产品,边缘位于右侧判断,缩进100像素,去点针眼
//Cv2.Line(mat_rgb, new Point(length - 100, 0), new Point(length - 100, height), new Scalar(255, 0, 0), 20);
////左侧相机,拍摄产品,边缘位于左侧判断,缩进100像素,去点针眼
//Cv2.Line(mat_rgb, new Point(width - length + 100, 0), new Point(width - length + 100, height), new Scalar(0, 255, 0), 20);
//int decWidth = width - length + marginHoleWidth;
//if (isLeft)
// return cutImage(mat_rgb, decWidth, 0, width- decWidth, height);
//else
// return cutImage(mat_rgb, 0, 0, width - decWidth, height);
//int decWidth = width - length + marginHoleWidth;
//if (isLeft)
// return cutImage(mat_rgb, decWidth, 0, width- decWidth, height);
//else
// return cutImage(mat_rgb, 0, 0, width - decWidth, height);
//API.OutputDebugString($"getMaxInsetRect2:margin={marginWidth},length={length}({marginHoleWidth}),isLeft={isLeft},mat_rgb={mat_rgb.Width}*{mat_rgb.Height},w={length - marginHoleWidth},h={mat_rgb.Height}");
//API.OutputDebugString($"getMaxInsetRect2:margin={marginWidth},length={length}({marginHoleWidth}),isLeft={isLeft},mat_rgb={mat_rgb.Width}*{mat_rgb.Height},w={length - marginHoleWidth},h={mat_rgb.Height}");
#if online
if (isLeft)
return CutImage(mat_rgb, length + marginHoleWidth, 0, mat_rgb.Width - length - marginHoleWidth, mat_rgb.Height);
else
return CutImage(mat_rgb, 0, 0, length - marginHoleWidth, mat_rgb.Height);
if (isLeft)
return CutImage(mat_rgb, length + marginHoleWidth, 0, mat_rgb.Width - length - marginHoleWidth, mat_rgb.Height);
else
return CutImage(mat_rgb, 0, 0, length - marginHoleWidth, mat_rgb.Height);
#else
if (isLeft)
{
Cv2.Line(mat_rgb, new Point(length + marginHoleWidth, 0), new Point(length + marginHoleWidth, mat_rgb.Height), new Scalar(255, 0, 0), 20);
return mat_rgb;
if (isLeft)
{
Cv2.Line(mat_rgb, new Point(length + marginHoleWidth, 0), new Point(length + marginHoleWidth, mat_rgb.Height), new Scalar(255, 0, 0), 20);
return mat_rgb;
}
else
{
Cv2.Line(mat_rgb, new Point(length - marginHoleWidth, 0), new Point(length - marginHoleWidth, mat_rgb.Height), new Scalar(0, 255, 0), 20);
return mat_rgb;
}
#endif
}
else
{
Cv2.Line(mat_rgb, new Point(length - marginHoleWidth, 0), new Point(length - marginHoleWidth, mat_rgb.Height), new Scalar(0, 255, 0), 20);
return mat_rgb;
marginWidth = 0;
if (isLeft)
return CutImage(mat_rgb, bian + marginHoleWidth, 0, mat_rgb.Width - bian - marginHoleWidth, mat_rgb.Height);
else
return CutImage(mat_rgb, 0, 0, mat_rgb.Width - bian - marginHoleWidth, mat_rgb.Height);
}
#endif
}
/// <summary>
@@ -524,9 +536,12 @@ namespace GeBoShi.SysCtrl
// 取平均值作为宽度
int length = 0;
if(total_t.Count> 0)
if (total_t.Count > 0)
{
length = (int)total_t.Average();
//乘上换算系数还原
length = length * sf + Roi.X;
}
//endTime = DateTimeOffset.Now;
//Console.WriteLine("计算边(ms): " + (endTime - startTime).TotalMilliseconds.ToString("0.000"));
@@ -539,8 +554,7 @@ namespace GeBoShi.SysCtrl
// //出现数据异常,当段图片的宽度有问题
//}
//乘上换算系数还原
length = length * sf + Roi.X;
//if ((length > 6520 && length < 6530) || (length > 1570 && length < 1590))
// ;
@@ -692,10 +706,12 @@ namespace GeBoShi.SysCtrl
length = length - ConfMgr.Instance.SysConfigParams.Crop_offset;
else
length = length + ConfMgr.Instance.SysConfigParams.Crop_offset;
//乘上换算系数还原
length = length * sf + Roi.X;
}
//乘上换算系数还原
length = length * sf + Roi.X;
return length;
}
#endregion


+ 300
- 56
LeatherProject/GeBoShi/SysCtrl/SysMgr.cs Zobrazit soubor

@@ -6,6 +6,7 @@ using CCWin.SkinControl;
using CCWin.Win32;
using CCWin.Win32.Const;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.Wordprocessing;
using GeBoShi.ImageDefect;
using GeBoShi.UI.InageShow;
using HalconDotNet;
@@ -34,6 +35,7 @@ using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
@@ -133,6 +135,7 @@ namespace GeBoShi.SysCtrl
//实时速度
private double ActiveSpeed = 0;
//图片队列
private int _DefectEnd = 0;
private int listCntMax = 60;
private int Cam1Cnt = 0;
private int Cam2Cnt = 0;
@@ -166,11 +169,12 @@ namespace GeBoShi.SysCtrl
photoIndex = _photoIndex;
path = _path;
}
public ScanPhotoInfo(int _devIndex, int _photoIndex, Mat _mat)
public ScanPhotoInfo(int _devIndex, int _photoIndex, Mat _mat, bool haveEdge = true)
{
devIndex = _devIndex;
photoIndex = _photoIndex;
mat = _mat;
EdgeSts = haveEdge;
}
public int devIndex { get; set; }
/// <summary>
@@ -180,6 +184,8 @@ namespace GeBoShi.SysCtrl
public string path { get; set; }
public Mat mat { get; set; }
public bool EdgeSts { get; set; }
}
#endregion
private ConcurrentQueue<ScanPhotoInfo> _matList1 = new ConcurrentQueue<ScanPhotoInfo>();
@@ -633,6 +639,21 @@ namespace GeBoShi.SysCtrl
return statusMgr.Status == SystemStsEnum.Pause || statusMgr.Warning == WarningEnum.High;
}
/// <summary>
/// 获取缺陷数据
/// </summary>
/// <param name="liPhotoIndex"></param>
/// <returns></returns>
private List<DefectInfo> GetDefectListInfo(int liPhotoIndex)
{
List<DefectInfo> ret;
lock (lock_defectPuase)
{
ret = defectPuaseList.Where(m => m.PhotoIndex == liPhotoIndex).ToList();
}
return ret;
}
/// <summary>
/// 获取速度和长度
/// </summary>
@@ -736,7 +757,7 @@ namespace GeBoShi.SysCtrl
//if ((yqjimi - atcDis) < (defectPuaseList[0].Y / 100 + 1))
{
Log($"二次判断", $"计米器{yqjimi},瑕疵位置{defectPuaseList[0].Y / 100},停车距离{confMgr.SysConfigParams.StopLookDis}m,停车减速时间{confMgr.SysConfigParams.StopDecTime}s,减速位移{StopDecRunDis},实际停车距离{atcDis},实时速度{tRunSpd},匀速{aveSpd}", WarningEnum.Normal, false);
List<DefectInfo> lstEditDefect0 = defectPuaseList.Where(m => m.PhotoIndex == defectPuaseList[0].PhotoIndex).ToList();
List<DefectInfo> lstEditDefect0 = GetDefectListInfo(defectPuaseList[0].PhotoIndex);
Log($"二次判断", $"(图像{defectPuaseList[0].PhotoIndex})已达观察台,瑕疵二次判断=》({string.Join(",", lstEditDefect0.Select(m => m.Code).ToArray())})是否包含在({string.Join(",", curRecord.ProductInfo.DefectPauseOption.ToArray())})中。", WarningEnum.Normal, false);
//瑕疵选项过滤
if (curRecord.ProductInfo.DefectPauseOption.Count == 0 || lstEditDefect0.Where(x => curRecord.ProductInfo.DefectPauseOption.Contains(x.Code)).Count() > 0)
@@ -747,7 +768,7 @@ namespace GeBoShi.SysCtrl
Stop();
//获取完整数据
Thread.Sleep(500);
var lstEditDefect = defectPuaseList.Where(m => m.PhotoIndex == defectPuaseList[0].PhotoIndex).ToList();
var lstEditDefect = GetDefectListInfo(defectPuaseList[0].PhotoIndex);
#region 二级界面
int liPhotoIndex = defectPuaseList[0].PhotoIndex;
#region 加载界面
@@ -871,6 +892,7 @@ namespace GeBoShi.SysCtrl
private void Cam1ThreadFunction()
{
int errStep = 0;
int marginWidth0 = 0;
#if Online
#else
string imgfilePath = "D:\\CPL\\img\\L1.bmp";
@@ -939,25 +961,26 @@ namespace GeBoShi.SysCtrl
if (defectPuaseList.Count > 0)
{
errStep = 12;
List<DefectInfo> lstEditDefect = defectPuaseList.Where(m => m.PhotoIndex == liPhotoIndex).ToList();
Log($"二次判断2", $"(图像{liPhotoIndex})已达观察台,瑕疵二次判断=》({string.Join(",", lstEditDefect.Select(m => m.Code).ToArray())})是否包含在({string.Join(",", curRecord.ProductInfo.DefectPauseOption.ToArray())})中。", WarningEnum.Normal, false);
List<DefectInfo> lstEditDefect = GetDefectListInfo(liPhotoIndex);
Log($"二次判断2", $"(图像{liPhotoIndex})已达观察台,瑕疵二次判断=》({string.Join(",", lstEditDefect.Select(m => m.Code).ToArray())})是否包含在({string.Join(",", DefectItemsPuaseNameList.ToArray())})或({string.Join(",", curRecord.ProductInfo.DefectPauseOption.ToArray())})中。", WarningEnum.Normal, false);
//瑕疵选项过滤
if (curRecord.ProductInfo.DefectPauseOption.Count == 0 || lstEditDefect.Where(x => curRecord.ProductInfo.DefectPauseOption.Contains(x.Code)).Count() > 0)
{
Log($"二次判断2", $"(图像{liPhotoIndex})需瑕疵二次判断,已达观察台,进入暂停。速度:{GetSpd()}");
Log($"二次判断2", $"(图像{liPhotoIndex})需瑕疵二次判断,已达观察台,进入暂停。速度:{GetSpd()},停车缺陷数:{lstEditDefect.Where(x => DefectItemsPuaseNameList.Contains(x.Name)).Count()}");
// if (lstEditDefect.Where(x => x.Code == "jietou").Count() > 0)
if (lstEditDefect.Where(x => DefectItemsPuaseNameList.Contains(x.Name)).Count() > 0)
//if (lstEditDefect.Where(x => DefectItemsPuaseNameList.Contains(x.Name)).Count() > 0)
{
Stop();
//获取完整数据
Thread.Sleep(500);
lstEditDefect = defectPuaseList.Where(m => m.PhotoIndex == liPhotoIndex).ToList();
lstEditDefect = GetDefectListInfo(liPhotoIndex);
//获取完整数据
#region 二级界面
#region 加载界面
if (defectPuaseImgList.ContainsKey(liPhotoIndex))
{
Log($"二次判断2", $"(图像{liPhotoIndex})需瑕疵二次判断,缺陷数:{lstEditDefect.Count}");
var pmat = defectPuaseImgList[liPhotoIndex].Clone();
OnAutoRuning(new RunEventArgs(liPhotoIndex, lstEditDefect, curRecord, pmat));
#if false
@@ -1023,8 +1046,8 @@ namespace GeBoShi.SysCtrl
#endregion
#endif
//预处理
Stopwatch stopWatch = new Stopwatch();
//预处理
Stopwatch stopWatch = new Stopwatch();
//Log($"图像预处理", $"相机1-{Cam1Cnt}", WarningEnum.Normal, false);
string time = "";
stopWatch.Start();
@@ -1089,8 +1112,7 @@ namespace GeBoShi.SysCtrl
}
}
errStep = 4;
//左裁边
int marginWidth0;
//左裁边
mat = OpencvUtils.getMaxInsetRect2(mat, true, confMgr.SysConfigParams.HolePx, out marginWidth0);
//存储裁边异常相机图 差异5cm
if (_marginWidth1 == 0)
@@ -1115,7 +1137,7 @@ namespace GeBoShi.SysCtrl
}
//Log($"图像1入队列", $"相机1-{Cam1Cnt}", WarningEnum.Normal, false);
//Cv2.Flip(img, img, FlipMode.XY);//翻转
_matList1.Enqueue(new ScanPhotoInfo(0, Cam1Cnt++, mat.Clone()));
_matList1.Enqueue(new ScanPhotoInfo(0, Cam1Cnt++, mat.Clone(), marginWidth0 != 0));
}
else
Log($"相机1", $"(图像)-未扫码,图像丢弃!", WarningEnum.Low);
@@ -1150,7 +1172,9 @@ namespace GeBoShi.SysCtrl
/// 相机2采图预处理
/// </summary>
private void Cam2ThreadFunction()
{
{
int errStep = 0;
int marginWidth0 = 0;
#if Online
#else
string imgfilePath = "D:\\CPL\\img\\R1.bmp";
@@ -1234,7 +1258,7 @@ namespace GeBoShi.SysCtrl
System.GC.Collect();
}
int errStep = 0;
Mat mat = img;
try
{
@@ -1254,7 +1278,6 @@ namespace GeBoShi.SysCtrl
}
errStep = 4;
//右裁边
int marginWidth0;
mat = OpencvUtils.getMaxInsetRect2(mat, false, confMgr.SysConfigParams.HolePx, out marginWidth0);
//存储裁边异常相机图 差异5cm
if (_marginWidth2 == 0)
@@ -1277,7 +1300,7 @@ namespace GeBoShi.SysCtrl
}
//Log($"图像2入队列", $"相机2-{Cam1Cnt}", WarningEnum.Normal, false);
//Cv2.Flip(img, img, FlipMode.XY);//翻转
_matList2.Enqueue(new ScanPhotoInfo(1, Cam2Cnt++, mat.Clone()));
_matList2.Enqueue(new ScanPhotoInfo(1, Cam2Cnt++, mat.Clone(), marginWidth0 != 0));
//System.GC.Collect();
}
else
@@ -1856,34 +1879,46 @@ namespace GeBoShi.SysCtrl
#endregion
#endif
//----缺陷队列
//比例缩放图片
int xw;
int resizeWidth = OpencvUtils.GetWidthForResize(mat0.Width + mat1.Width - confMgr.SysConfigParams.MidCoin);
if (resizeWidth == 0)
throw new Exception("GetWidthForResize result 0 失败!");
var resize = new System.Drawing.Size(resizeWidth, OpencvUtils.image_height * 2);//固定8192*2张*4096
mat = OpencvUtils.Resize(mat, resize.Width, resize.Height, out xw);
//Log($"图像处理", $"(图像{scanPhotos0.photoIndex})-合成图resize后:{mat.Width}*{mat.Height}", WarningEnum.Normal, false);
defectLib.add(new DefectTask()
if (scanPhotos1.EdgeSts == false && scanPhotos0.EdgeSts == false && _DefectEnd >= 1)
{
modelName = curRecord.ProductInfo.ModelName,
record = curRecord,
bmp = mat,
bmpTag = mat.Clone(),
photoIndex = scanPhotos0.photoIndex,//0-n 首张必需为0,因下面计算长度是从0开始
widthRatio = 1.0f,//等比例缩放,高度不变
qualifiedLimitList = curRecord.ProductInfo.QualifiedLimitList,
labelDic = GetDefectCode(),
finishEvent = callBackDefectEvent,
xw = xw,
cm2px_x = confMgr.SysConfigParams.Cm2px_x,
cm2px_y = confMgr.SysConfigParams.Cm2px_y,
expand_pixel = confMgr.SysConfigParams.Expand_pixel,
});
curRecord.ScannerPhotoCount++;
errStep = 10;
time += $"->加入瑕疵待检队列({stopWatch.ElapsedMilliseconds})";
//出现第二次判断没有边缘
Log($"图像处理", $"未找到边缘当作空跑处理:(图像{scanPhotos0.photoIndex})", WarningEnum.Normal, false);
}
else
{
if (scanPhotos1.EdgeSts == false && scanPhotos0.EdgeSts == false)
_DefectEnd++;//没边计数
else
_DefectEnd = 0; //有边的情况重置
//----缺陷队列
//比例缩放图片
int xw;
int resizeWidth = OpencvUtils.GetWidthForResize(mat0.Width + mat1.Width - confMgr.SysConfigParams.MidCoin);
if (resizeWidth == 0)
throw new Exception("GetWidthForResize result 0 失败!");
var resize = new System.Drawing.Size(resizeWidth, OpencvUtils.image_height * 2);//固定8192*2张*4096
mat = OpencvUtils.Resize(mat, resize.Width, resize.Height, out xw);
//Log($"图像处理", $"(图像{scanPhotos0.photoIndex})-合成图resize后:{mat.Width}*{mat.Height}", WarningEnum.Normal, false);
defectLib.add(new DefectTask()
{
modelName = curRecord.ProductInfo.ModelName,
record = curRecord,
bmp = mat,
bmpTag = mat.Clone(),
photoIndex = scanPhotos0.photoIndex,//0-n 首张必需为0,因下面计算长度是从0开始
widthRatio = 1.0f,//等比例缩放,高度不变
qualifiedLimitList = curRecord.ProductInfo.QualifiedLimitList,
labelDic = GetDefectCode(),
finishEvent = callBackDefectEvent,
xw = xw,
cm2px_x = confMgr.SysConfigParams.Cm2px_x,
cm2px_y = confMgr.SysConfigParams.Cm2px_y,
expand_pixel = confMgr.SysConfigParams.Expand_pixel,
});
curRecord.ScannerPhotoCount++;
errStep = 10;
time += $"->加入瑕疵待检队列({stopWatch.ElapsedMilliseconds})";
}
}
catch (Exception ex)
{
@@ -2296,7 +2331,7 @@ namespace GeBoShi.SysCtrl
saveImgInfo.Img = null;
System.GC.Collect();
}
Log("存图警告", "存图超限-出队", WarningEnum.Low);
Log("存图警告", "存图超限-出队", WarningEnum.Normal);
}
}
private void AddImageSave(string path, DataTable dt)
@@ -2345,7 +2380,7 @@ namespace GeBoShi.SysCtrl
saveImgInfo.Img = null;
System.GC.Collect();
}
Log("存图警告", "存图超限-紧急出队", WarningEnum.Low);
Log("存图警告", "存图超限-紧急出队", WarningEnum.Normal);
}
#endregion
@@ -3396,6 +3431,7 @@ namespace GeBoShi.SysCtrl
_marginWidth1 = 0;
_marginWidth2 = 0;
_DefectEnd = 0;
Cam1Cnt = 0;
Cam2Cnt = 0;
@@ -3531,21 +3567,30 @@ namespace GeBoShi.SysCtrl
int count;
foreach (GradeLimit item in gradeLimitList)
{
if (model.DefectInfoList != null && model.DefectInfoList.Count > 0)
if (item.A == 0 && item.B == 0 && item.C == 0 && item.D == 0 && item.E == 0)
{
count = model.DefectInfoList.Where(m => m.Code == item.Code).Count();
if (count <= item.A && model.Grade <= 1) model.Grade = 1;
else if (count <= item.B && item.B > 0 && model.Grade <= 2) model.Grade = 2;
else if (count <= item.C && item.C > 0 && model.Grade <= 3) model.Grade = 3;
else if (count <= item.D && item.D > 0 && model.Grade <= 4) model.Grade = 4;
else if (count <= item.E && item.E > 0 && model.Grade <= 5) model.Grade = 5;
else if (count > 0) model.Grade = 6;//不合格
Log("标准判断", $"({key}) 条码({model.BarCode}),标准={(char)(model.Grade + 64)} [{item.Code}:{count};A<={item.A};B<={item.B};C<={item.C};D<={item.D};E<={item.E}]");
model.Grade = 1;
Log("标准判断", $"({key}) 条码({model.BarCode}),无设置标准={(char)(model.Grade + 64)} [{item.Code}:{count};A<={item.A};B<={item.B};C<={item.C};D<={item.D};E<={item.E}]");
}
else
{
model.Grade = 1;
Log("标准判断", $"({key}) 条码({model.BarCode}),标准={(char)(model.Grade + 64)} [{item.Code}:{0};A<={item.A};B<={item.B};C<={item.C};D<={item.D};E<={item.E}]");
if (model.DefectInfoList != null && model.DefectInfoList.Count > 0)
{
count = model.DefectInfoList.Where(m => m.Code == item.Code).Count();
if (count <= item.A && model.Grade <= 1) model.Grade = 1;
else if (count <= item.B && item.B > 0 && model.Grade <= 2) model.Grade = 2;
else if (count <= item.C && item.C > 0 && model.Grade <= 3) model.Grade = 3;
else if (count <= item.D && item.D > 0 && model.Grade <= 4) model.Grade = 4;
else if (count <= item.E && item.E > 0 && model.Grade <= 5) model.Grade = 5;
else if (count > 0) model.Grade = 6;//不合格
Log("标准判断", $"({key}) 条码({model.BarCode}),标准={(char)(model.Grade + 64)} [{item.Code}:{count};A<={item.A};B<={item.B};C<={item.C};D<={item.D};E<={item.E}]");
}
else
{
model.Grade = 1;
Log("标准判断", $"({key}) 条码({model.BarCode}),标准={(char)(model.Grade + 64)} [{item.Code}:{0};A<={item.A};B<={item.B};C<={item.C};D<={item.D};E<={item.E}]");
}
}
}
step = 5;
@@ -3705,6 +3750,133 @@ namespace GeBoShi.SysCtrl
}
}
#endregion
#region 颜色判断
/// <summary>
/// 根据RGB判断颜色
/// </summary>
/// <param name="Clr"></param>
/// <returns></returns>
public static string CLRToName(System.Drawing.Color Clr)
{
double d_r = (double)Clr.R / 83;
double d_g = (double)Clr.G / 83;
double d_b = (double)Clr.B / 83;
int r = (int)Math.Round(d_r);
int g = (int)Math.Round(d_g);
int b = (int)Math.Round(d_b);
string rgb = r.ToString() + "," + g.ToString() + "," + b.ToString();
#region "switch (rgb)"
switch (rgb)
{
case "0,0,0":
case "1,1,1":
case "2,2,2":
case "3,3,3":
if (r == 0) return RGBName.Black.GetDescription();
if (r == 1) return RGBName.Gray.GetDescription();
if (r == 2) return RGBName.LightGray.GetDescription();
if (r == 3) return RGBName.White.GetDescription();
break;
case "0,0,3":
case "0,3,0":
case "3,0,0":
case "1,1,3":
case "1,3,1":
case "3,1,1":
case "0,1,3":
case "0,3,1":
case "3,0,1":
case "1,0,3":
case "1,3,0":
case "3,1,0":
case "0,0,2":
case "0,2,0":
case "2,0,0":
case "1,1,2":
case "1,2,1":
case "2,1,1":
case "0,1,2":
case "0,2,1":
case "2,0,1":
case "1,0,2":
case "1,2,0":
case "2,1,0":
if (r == 2) return RGBName.DarkRed.GetDescription();
if (g == 2) return RGBName.DarkGreen.GetDescription();
if (b == 2) return RGBName.DarkBlue.GetDescription();
if (r == 3) return RGBName.Red.GetDescription();
if (g == 3) return RGBName.Green.GetDescription();
if (b == 3) return RGBName.Blue.GetDescription();
break;
case "0,0,1":
case "0,1,0":
case "1,0,0":
case "2,2,3":
case "2,3,2":
case "3,2,2":
if (r == 1) return RGBName.DarkRed.GetDescription();
if (g == 1) return RGBName.DarkGreen.GetDescription();
if (b == 1) return RGBName.DarkBlue.GetDescription();
if (r == 3) return RGBName.LightRed.GetDescription();
if (g == 3) return RGBName.LightGreen.GetDescription();
if (b == 3) return RGBName.LightBlue.GetDescription();
break;
case "1,1,0":
case "0,1,1":
case "1,0,1":
case "2,2,0":
case "0,2,2":
case "2,0,2":
case "2,2,1":
case "1,2,2":
case "2,1,2":
case "3,3,0":
case "0,3,3":
case "3,0,3":
case "3,3,1":
case "1,3,3":
case "3,1,3":
case "3,3,2":
case "2,3,3":
case "3,2,3":
if (r == 1 && g == 1) return RGBName.DarkYellow.GetDescription();
if (g == 1 && b == 1) return RGBName.DarkCyan.GetDescription();
if (r == 1 && b == 1) return RGBName.DarkPurple.GetDescription();
if (r == 2 && g == 2) return RGBName.Yellow.GetDescription();
if (g == 2 && b == 2) return RGBName.Cyan.GetDescription();
if (r == 2 && b == 2) return RGBName.Purple.GetDescription();
if (r == 3 && g == 3) return RGBName.LightYellow.GetDescription();
if (g == 3 && b == 3) return RGBName.LightCyan.GetDescription();
if (r == 3 && b == 3) return RGBName.LightPurple.GetDescription();
break;
case "3,2,0":
case "3,2,1":
return RGBName.Orange.GetDescription();
case "2,3,0":
case "2,3,1":
return RGBName.YellowGreen.GetDescription();
case "0,3,2":
case "1,3,2":
return RGBName.CyanGreen.GetDescription();
case "0,2,3":
case "1,2,3":
return RGBName.CyanBlue.GetDescription();
case "3,0,2":
case "3,1,2":
return RGBName.PurpleRed.GetDescription();
case "2,0,3":
case "2,1,3":
return RGBName.PurpleBlue.GetDescription();
default:
return "Error";
}
#endregion
return "Error";
}
#endregion
}
#region 系统事件
/// <summary>
@@ -3922,4 +4094,76 @@ namespace GeBoShi.SysCtrl
}
}
#endregion
#region 颜色定义
public enum RGBName
{
[Description("红")]
Red = 1,
[Description("绿")]
Green,
[Description("蓝")]
Blue,
[Description("深红")]
DarkRed,
[Description("深绿")]
DarkGreen,
[Description("深蓝")]
DarkBlue,
[Description("浅红")]
LightRed,
[Description("浅绿")]
LightGreen,
[Description("浅蓝")]
LightBlue,
[Description("黄")]
Yellow,
[Description("青")]
Cyan,
[Description("紫")]
Purple,
[Description("深黄")]
DarkYellow,
[Description("深青")]
DarkCyan,
[Description("深紫")]
DarkPurple,
[Description("浅黄")]
LightYellow,
[Description("浅青")]
LightCyan,
[Description("浅紫")]
LightPurple,
[Description("橙")]
Orange,
[Description("黄绿")]
YellowGreen,
[Description("青绿")]
CyanGreen,
[Description("青蓝")]
CyanBlue,
[Description("紫蓝")]
PurpleBlue,
[Description("紫红")]
PurpleRed,
[Description("黑")]
Black,
[Description("白")]
White,
[Description("灰")]
Gray,
[Description("浅灰")]
LightGray,
}
static class EnumExtensions
{
public static string GetDescription(this Enum val)
{
var field = val.GetType().GetField(val.ToString());
var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
}
}
#endregion
}

+ 2
- 0
LeatherProject/GeBoShi/UI/Product/ProductInfoFrm.cs Zobrazit soubor

@@ -383,6 +383,8 @@ namespace GeBoShi.UI.Product
Color selectedColor = dlg.Color;
// 在 label1 中显示所选颜色的 RGB 值
tbColorName.ForeColor = selectedColor;
tbColorName.Text = SysMgr.CLRToName(selectedColor);
}
}


Načítá se…
Zrušit
Uložit