public bool InitInspectNode(string recipeID, out string errorInfo) { if (string.IsNullOrEmpty(recipeID)) { errorInfo = "参数recipeID 为空字串"; return(false); } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; if (rm == null) { errorInfo = "配方管理器为空!"; return(false); } if (!rm.IsInitOK) { errorInfo = "配方管理器未初始化:" + rm.GetInitErrorInfo(); return(false); } string[] allRecipeIds = rm.AllRecipeIDsInCategoty(CategoyProduct); if (null == allRecipeIds || 0 == allRecipeIds.Length) { errorInfo = "配方管理器中不存在任何RecipeID"; return(false); } if (!allRecipeIds.Contains(recipeID)) { errorInfo = "配方管理器中不存在RecipeID = " + recipeID; return(false); } Dictionary <string, InspectNode> dctFovInspections = null; if (!_dctRecipeInspections.ContainsKey(recipeID)) //当前 { dctFovInspections = new Dictionary <string, InspectNode>(); _dctRecipeInspections.Add(recipeID, dctFovInspections); string rmPath = rm.GetInitParamValue("配方保存路径") as string; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoyProduct, recipeID) as JFDLAFProductRecipe; string[] fovNames = recipe.FovNames(); foreach (string fovName in fovNames) { string recipePath = rmPath + "\\" + recipeID + "\\" + fovName + "\\Recipe\\"; string modelPath = rmPath + "\\" + recipeID + "\\" + fovName + "\\Models\\"; InspectNode inspectNode = new InspectNode(modelPath, recipePath); dctFovInspections.Add(fovName, inspectNode); } } string err; dctFovInspections = _dctRecipeInspections[recipeID]; foreach (KeyValuePair <string, InspectNode> kv in dctFovInspections) { if (!kv.Value.InitInspectParam(out err)) { errorInfo = "Fov = " + kv.Key + " 初始化失败:" + err; return(false); } } errorInfo = "Success"; return(true); }
private void MappCtrl_OnSelectedDieChanged(HTMappingControl.DieInfo dieInfo) { if (dieInfo.DieState == "未检测") { rchDieInfo.Text = "未检测"; return; } else if (dieInfo.DieState == "合格") { rchDieInfo.Text = "合格"; return; } foreach (InspectionData inspData in _lstInspectData) { if (inspData.RowIndex == dieInfo.RowIndex && inspData.ColumnIndex == dieInfo.ColumnIndex) { //将检测结果显示在Die信息栏 rchDieInfo.Text = "不合格 NG信息:"; for (int i = 0; i < inspData.List_DefectData.Count(); i++) { DefectData dd = inspData.List_DefectData[i]; rchDieInfo.AppendText("Err No:" + (i + 1) + /* " Code:" + dd.DefectTypeIndex + */ "Describ:" + InspectNode.DieErrorDescript(dd.DefectTypeIndex) + "Detail:" + dd.ErrorDetail + "\n"); } } } }
protected override void RunLoopInWork() { NotifyCustomizeMsg(SCM_PieceStart, new object[] { _currPiecePicFolder }); //Inspect_Node inpect = JFDLAFInspectionManager.Instance.GetInspectNode int rows = _currRecipe.RowCount; int cols = _currRecipe.ColCount; string[] fovNames = _currRecipe.FovNames(); for (int currRow = 0; currRow < rows; currRow++) { for (int currCol = 0; currCol < cols; currCol++) { for (int currFov = 0; currFov < fovNames.Length; currFov++) { CheckCmd(CycleMilliseconds); //检测是否有暂停/恢复/退出 消息 string fovName = fovNames[currFov]; string fovSubFolder = "Row_" + currRow + "-" + "Col_" + currCol + "-Fov_" + fovName; string fovFolder = _currPiecePicFolder + "\\" + fovSubFolder;//存储图片的文件夹 if (!Directory.Exists(fovFolder)) { ExitWork(WorkExitCode.Error, "Fov图片文件夹:\"" + fovFolder + "\"不存在"); } InspectNode fovInspNode = JFDLAFInspectionManager.Instance.GetInspectNode(RecipeID, fovName); if (null == fovInspNode) { ExitWork(WorkExitCode.Error, "算子管理器中不存在 RecipeID = " + RecipeID + " Fov = " + fovName + " 的检测算子"); } string[] filesInFovFolder = Directory.GetFiles(fovFolder);//Fov文件夹中现有的文件 if (null == filesInFovFolder || filesInFovFolder.Length == 0) { ExitWork(WorkExitCode.Error, "Fov图片文件夹:\"" + fovFolder + "\"中没有文件"); } string[] taskNames = _currRecipe.TaskNames(fovName); List <HObject> taskImgs = new List <HObject>(); foreach (string taskName in taskNames) { HObject hoImg; HOperatorSet.GenEmptyObj(out hoImg); string taskImgFile = null; foreach (string s in filesInFovFolder) { string exn = Path.GetExtension(s); if (string.Compare(exn, ".bmp", true) != 0 && string.Compare(exn, ".tiff", true) != 0 && string.Compare(exn, ".tif", true) != 0 && string.Compare(exn, ".jpg", true) != 0 && string.Compare(exn, ".jpeg", true) != 0 && string.Compare(exn, ".png", true) != 0) { continue; //先过滤掉非图像文件 } string fnn = Path.GetFileNameWithoutExtension(s); //不带后缀的文件名 if (fnn.LastIndexOf(taskName) >= 0 && fnn.Length == (fnn.LastIndexOf(taskName) + taskName.Length)) { taskImgFile = s; break; } } if (null == taskImgFile) { ExitWork(WorkExitCode.Error, "Task = " + taskName + " 图片文件不存在"); } HOperatorSet.ReadImage(out hoImg, taskImgFile); taskImgs.Add(hoImg); } DlafFovDetectResult fdr = new DlafFovDetectResult(); fdr.FovName = fovName; fdr.ICRow = currRow; fdr.ICCol = currCol; fdr.TaskNames = taskNames; string errorInfo; //检测输入参数 HObject dieRegions; int[] dieRows, dieCols; int currDieRowCount, currDieColCount; if (!_visionFixer.GetDetectRegionInFov(currRow, currCol, out dieRegions, out dieRows, out dieCols, out currDieRowCount, out currDieColCount, out errorInfo)) { ExitWork(WorkExitCode.Error, "GetDetectRegionInFov failed,ErrorInfo:" + errorInfo); } fdr.DetectDiesRows = dieRows; fdr.DetectDiesCols = dieCols; fdr.CurrRowCount = currDieRowCount; fdr.CurrColCount = currDieColCount; //fdr.DieInspectResults = new List<InspectResultItem>[currDieRowCount* currDieColCount]; //for (int i = 0; i < currDieRowCount * currDieColCount; i++) // fdr.DieInspectResults[i] = new List<InspectResultItem>(); //检测输出参数 string detectErrorInfo; //算子执行信息 List <int[]> diesErrorCodes; //= new List<int[]>(); List <string[]> diesErrorTaskNames; List <HObject[]> diesFailedRegions; List <string[]> diesErrorDetails; //错误的详细描述信息 Dictionary <string, HObject> detectItems; //算子中输出的检测项(BondContours/WireRegions 等等) Dictionary <string, string> detectItemTaskNames; //bool isDetectOK = fovInspNode.InspectImage(taskImgs.ToArray(), taskNames, dieRegions, // out detectErrorInfo, out diesErrorCodes, out diesErrorTaskNames, out diesFailedRegions,out diesErrorDetails, // out detectItems,out detectItemTaskNames); //用于测试新数据结构 List <InspectResultItem[]> inspectResults = null; bool isDetectOK = fovInspNode.InspectImage(taskImgs.ToArray(), dieRegions, out detectErrorInfo, out inspectResults); fdr.DieInspectResults = inspectResults; //所有检测项 int dieCountInfov = dieRegions.CountObj(); //裁剪后的图象(按照Die的检测区域) HObject[] dieImgs = new HObject[dieCountInfov]; HTuple _row1, _col1, _row2, _col2; HTuple TWidth, THeight; for (int i = 0; i < dieCountInfov; i++) { HOperatorSet.SmallestRectangle1(dieRegions.SelectObj(i + 1), out _row1, out _col1, out _row2, out _col2); if (_row1 < 0) { _row1 = 0; } if (_col1 < 0) { _col1 = 0; } HOperatorSet.GetImageSize(taskImgs[0], out TWidth, out THeight); if (_row2 > THeight) { _row2 = THeight; } if (_col2 > TWidth) { _row2 = TWidth; } HObject hoImages = null; //一颗Die的多通道图 HOperatorSet.GenEmptyObj(out hoImages); for (int j = 0; j < taskImgs.Count; j++) { HObject ho; HOperatorSet.CropRectangle1(taskImgs[j], out ho, _row1, _col1, _row2, _col2); HOperatorSet.ConcatObj(hoImages, ho, out hoImages); } dieImgs[i] = hoImages; } fdr.DetectDiesImages = dieImgs; fdr.IsDetectSuccess = isDetectOK; fdr.DetectErrorInfo = detectErrorInfo; //if (null != diesErrorCodes) // fdr.DiesErrorCodes = diesErrorCodes.ToArray(); //else // fdr.DiesErrorCodes = null; //if (null != diesErrorTaskNames) // fdr.DiesErrorTaskNames = diesErrorTaskNames.ToArray(); //else // fdr.DiesErrorTaskNames = null; //if (null != diesFailedRegions) // fdr.DiesErrorRegions = diesFailedRegions.ToArray(); //else // fdr.DiesErrorRegions = null; //if (diesErrorDetails != null) // fdr.DiesErrorDetails = diesErrorDetails.ToArray(); //else // fdr.DiesErrorDetails = null; //fdr.DetectIterms = detectItems; //fdr.DetectItemTaskNames = detectItemTaskNames; //if (fdr.DetectIterms != null && fdr.DetectIterms.ContainsKey("WireRegions")) //{ // fdr.WireRegion = fdr.DetectIterms["WireRegions"]; // fdr.WireRegionTaskName = fdr.DetectItemTaskNames["WireRegions"]; // fdr.DetectIterms.Remove("WireRegions"); // fdr.DetectItemTaskNames.Remove("WireRegions"); //} NotifyCustomizeMsg(SCM_FovDetectResult, new object[] { taskImgs, //FOV原图 fdr //测试结果 }); } } } NotifyCustomizeMsg(SCM_PieceEnd, null); ExitWork(WorkExitCode.Normal, ""); }