public void ShowImage(IJFImage img) { if (null == img) { _hcWnd.ClearWindow(); return; //img.DisplayTo(pPicWnd); } else { if (null != _hoImge) { _hoImge.Dispose(); _hoImge = null; } object oImg = null; int err = img.GenHalcon(out oImg); if (0 != err) { _hcWnd.ClearWindow(); ShowTips("图像显示失败!错误信息:" + img.GetErrorInfo(err)); } _hoImge = oImg as HObject; HOperatorSet.SetPart(_hcWnd, 0, 0, img.PicHeight - 1, img.PicWidth - 1);// ch: 使图像显示适应窗口大小 || en: Make the image adapt the window size HOperatorSet.DispObj(_hoImge, _hcWnd); ShowTips("图像已显示"); } }
public override void UpdateSrc2UI() { if (InvokeRequired) { Invoke(new Action(UpdateSrc2UI)); return; } if (null == _inspection) { return; } lbActionErrorInfo.Text = _inspection.GetActionErrorInfo(); lbInspectRet.Text = _inspection.GetMethodOutputValue("ErrorCode").ToString(); lbInspectInfo.Text = _inspection.GetMethodOutputValue("ErrorInfo").ToString(); lbActionSeconds.Text = _inspection.GetActionSeconds().ToString("F3"); htWindowControl1.ClearHWindow(); IJFImage imgInput = _inspection.GetMethodInputValue("Image") as IJFImage; if (null == imgInput) { return; } object hoImg = null; if (0 == imgInput.GenHalcon(out hoImg)) { htWindowControl1.DispImage(hoImg as HObject); } HObject BondContours = _inspection.GetMethodOutputValue("焊点区域") as HObject; if (null != BondContours) { htWindowControl1.DispImage(BondContours); } HObject Wires = _inspection.GetMethodOutputValue("金线区域") as HObject; if (null != Wires) { htWindowControl1.DispImage(Wires); } HObject FailRegs = _inspection.GetMethodOutputValue("失败区域") as HObject; if (FailRegs != null) { htWindowControl1.DispImage(FailRegs); } }
//DLAFDetectResultTransfer _detectResultTransfer = new DLAFDetectResultTransfer(); //受到自定义消息 public void OnCustomizeMsg(string msgCategory, object[] msgParams) { fmTips.AddOneTips("工站消息Categoty:" + msgCategory); BeginInvoke(new Action(() => { if (msgCategory == CMC_ShowJFImage) //显示一个IJFImage对象 { object ob; IJFImage ij = msgParams[0] as IJFImage; if (null == ij) { fmTips.AddOneTips("消息参数IJFImage == null"); return; } int err = ij.GenHalcon(out ob); if (err != 0) { fmTips.AddOneTips("参数IJFImage.GenHalcon 出错:" + ij.GetErrorInfo(err)); return; } htWindowControl1.DispImage(ob as HObject); } else if (msgCategory == CMC_ShowHO)//显示一个Halcon对象 { htWindowControl1.DispImage(msgParams[0] as HObject); } else if (CMC_StartNewPiece == msgCategory) { rchRDetectInfo.Text = ""; string pieceID = msgParams[0] as string; rchRDetectInfo.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + " " + msgParams[0] + " 开始检测,PieceID = pieceID"); //_detectResultTransfer.SetPieceID(pieceID); for (int i = 0; i < _currRecipe.RowNumber; i++) { for (int j = 0; j < _currRecipe.ColumnNumber * _currRecipe.BlockNumber; j++) { mappCtrl.SetDieState(i, j, "未检测"); } } _lstInspectData.Clear(); } else if (msgCategory == CMC_InspectResult) //一个FOV的检测结果 { IJFImage[] orgImgs = msgParams[0] as IJFImage[]; DlafFovDetectResult fdr = (msgParams[1] as DlafFovDetectResult); //.Clone(); int imgIndex2Show = 0; if (_isShowRealtimeDetectImg) //需要实时显示图像 { string taskName2Show = cbTaskImgShow.Text; if (!string.IsNullOrEmpty(taskName2Show)) { for (int i = 0; i < fdr.TaskNames.Length; i++) { if (fdr.TaskNames[i] == taskName2Show) { imgIndex2Show = i; break; } } } //if (null != fdr.WireRegion) //老版本的数据显示功能 //{ // htWindowControl1.ColorName = "green"; //金线为绿色显示 // if(null != _hoOrgImgShowing) // { // _hoOrgImgShowing.Dispose(); // _hoOrgImgShowing = null; // } // Object ob; // orgImgs[imgIndex2Show].GenHalcon(out ob); // _hoOrgImgShowing = ob as HObject; // htWindowControl1.RefreshWindow(_hoOrgImgShowing, fdr.WireRegion, "fit"); //} //if (null != fdr.DetectIterms && fdr.DetectIterms.Count > 0) //{ // htWindowControl1.ColorName = "yellow"; //其他成功检测项显示为黄色 // foreach (HObject ho in fdr.DetectIterms.Values) // htWindowControl1.DispRegion(ho); //} //if(null != fdr.DiesErrorRegions) //{ // htWindowControl1.ColorName = "red"; //错误区域显示为红色 // foreach(HObject[] errorRegions in fdr.DiesErrorRegions) // if(null != errorRegions) // foreach(HObject ho in errorRegions) // htWindowControl1.DispRegion(ho); //} //新数据结构的显示 if (null != _hoOrgImgShowing) { _hoOrgImgShowing.Dispose(); _hoOrgImgShowing = null; } Object ob; if (0 != orgImgs[imgIndex2Show].GenHalcon(out ob)) //图像转化出错 { htWindowControl1.ClearHWindow(); } else { _hoOrgImgShowing = (HObject)ob; htWindowControl1.RefreshWindow(_hoOrgImgShowing, null, "fit"); //显示图片 } //显示各检测项 if (!fdr.IsDetectSuccess || null == fdr.DieInspectResults) { return; } HObject errRegion = null;//所有错误区域 HOperatorSet.GenEmptyRegion(out errRegion); HObject bondRegion = null; //焊点 HOperatorSet.GenEmptyRegion(out bondRegion); HObject wireRegion = null; HOperatorSet.GenEmptyRegion(out wireRegion); HObject epoxyRegion = null; HOperatorSet.GenEmptyRegion(out epoxyRegion); bool _isShowAllItem = !chkJustShowNG.Checked; foreach (InspectResultItem[] dieItems in fdr.DieInspectResults) { foreach (InspectResultItem item in dieItems) { if (!item.IsDetectOK()) { HOperatorSet.ConcatObj(errRegion, item.ResultRegion, out errRegion); } if (!_isShowAllItem) { continue; } switch (item.InspectCategoty) { case InspectResultItem.Categoty.Frame: break; case InspectResultItem.Categoty.IC: break; case InspectResultItem.Categoty.Bond: HOperatorSet.ConcatObj(bondRegion, item.ResultRegion, out bondRegion); break; case InspectResultItem.Categoty.Wire: HOperatorSet.ConcatObj(wireRegion, item.ResultRegion, out wireRegion); break; case InspectResultItem.Categoty.Epoxy: HOperatorSet.ConcatObj(epoxyRegion, item.ResultRegion, out epoxyRegion); break; } } } if (_isShowAllItem) { htWindowControl1.ColorName = "green"; htWindowControl1.DispRegion(wireRegion); htWindowControl1.ColorName = "yellow"; htWindowControl1.DispRegion(bondRegion); htWindowControl1.ColorName = "blue"; htWindowControl1.DispRegion(epoxyRegion); } htWindowControl1.ColorName = "red"; htWindowControl1.DispRegion(errRegion); } if (fdr.DetectDiesImages != null) { foreach (HObject ho in fdr.DetectDiesImages) { ho.Dispose(); } } ///错误信息显示 StringBuilder sbInfo = new StringBuilder(); sbInfo.AppendLine("Fov:" + fdr.FovName + " 检测结果:"); if (!fdr.IsDetectSuccess) { sbInfo.AppendLine("图像检测失败,ErrorInfo:" + fdr.DetectErrorInfo); } else { if (fdr.IsFovOK) { sbInfo.AppendLine("检测结果: OK"); } else { for (int i = 0; i < fdr.DetectDiesRows.Length; i++) { if (fdr.IsDieOK(i)) { sbInfo.AppendLine("Row-" + fdr.ICRow + " Col-" + fdr.ICCol + " Die-" + i + " OK"); } else { sbInfo.AppendLine("Row-" + fdr.ICRow + " Col-" + fdr.ICCol + " Die-" + i + " NG 错误信息:"); int[] errors = fdr.DiesErrorCodes[i]; //for(int j = 0; j < errors.Length;j++) // sbInfo.AppendLine("ErrCode:" + errors[j] + " Info:" + InspectNode.DieErrorDescript(errors[j]) + "In Task:" + fdr.DiesErrorTaskNames[i][j]); } } } } fmTips.AddOneTips(sbInfo.ToString()); rchRDetectInfo.AppendText(sbInfo.ToString()); //将Fov检测项填入表格 dgvDetectItems.Rows.Clear(); if (null != fdr.DieInspectResults) { bool _isShowAllItems = !chkJustShowNG.Checked; int dieIndex = 0; int dieCount = fdr.CurrColCount * fdr.CurrRowCount; if (dieCount <= 0)//Fov只是Die的一部分 { dieCount = 1; } //表格行 : Die/检测项/检测结果/检测标准数据/检测结果数据/备注 for (dieIndex = 0; dieIndex < dieCount; dieIndex++) { if (!fdr.IsDetectSuccess) //视觉算子出错 { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell dieIndexCell = new DataGridViewTextBoxCell(); dieIndexCell.Style.BackColor = Color.Red; dieIndexCell.Value = dieIndex + 1; row.Cells.Add(dieIndexCell); DataGridViewTextBoxCell detectItemCell = new DataGridViewTextBoxCell(); detectItemCell.Value = "---"; detectItemCell.Style.ForeColor = Color.Red; row.Cells.Add(detectItemCell); DataGridViewTextBoxCell dieErrorCell = new DataGridViewTextBoxCell(); dieErrorCell.Value = "检测出错:" + fdr.DetectErrorInfo; dieErrorCell.Style.ForeColor = Color.Red; row.Cells.Add(dieErrorCell); DataGridViewTextBoxCell dieDetectVelCell = new DataGridViewTextBoxCell(); dieDetectVelCell.Value = "---"; dieDetectVelCell.Style.ForeColor = Color.Red; row.Cells.Add(dieDetectVelCell); DataGridViewTextBoxCell dieRefVelCell = new DataGridViewTextBoxCell(); dieRefVelCell.Value = "---"; dieRefVelCell.Style.ForeColor = Color.Red; row.Cells.Add(dieRefVelCell); DataGridViewTextBoxCell dieRemarksCell = new DataGridViewTextBoxCell(); string rowColInfo = "Die:" + (dieIndex + 1) + " 行:" + (dieIndex / dieCount + 1) + " 列:" + (dieIndex % dieCount + 1); dieRemarksCell.Value = rowColInfo; dieRemarksCell.Style.ForeColor = Color.Red; row.Cells.Add(dieRemarksCell); dgvDetectItems.Rows.Add(row); } else //检测成功,列出每个检测项 { for (int i = 0; i < fdr.DieInspectResults[dieIndex].Length; i++) { if (!_isShowAllItems && fdr.DieInspectResults[dieIndex][i].IsDetectOK()) { continue; } DataGridViewRow row = new DataGridViewRow(); Color txtColor = Color.DarkGreen; if (!DlafFovDetectResult.IsInspectItemsOK(fdr.DieInspectResults[dieIndex])) { txtColor = Color.DarkRed; } DataGridViewTextBoxCell dieIndexCell = new DataGridViewTextBoxCell(); dieIndexCell.Style.ForeColor = txtColor; dieIndexCell.Value = dieIndex + 1; row.Cells.Add(dieIndexCell); DataGridViewTextBoxCell detectItemCell = new DataGridViewTextBoxCell(); detectItemCell.Value = fdr.DieInspectResults[dieIndex][i].InspectID; detectItemCell.Style.ForeColor = fdr.DieInspectResults[dieIndex][i].IsDetectOK() ? Color.DarkGreen : Color.DarkRed; row.Cells.Add(detectItemCell); DataGridViewTextBoxCell dieErrorCell = new DataGridViewTextBoxCell(); dieErrorCell.Value = string.Join(" ", fdr.DieInspectResults[dieIndex][i].ErrorTexts); dieErrorCell.Style.ForeColor = fdr.DieInspectResults[dieIndex][i].IsDetectOK() ? Color.DarkGreen : Color.DarkRed; row.Cells.Add(dieErrorCell); DataGridViewTextBoxCell dieRefVelCell = new DataGridViewTextBoxCell(); dieRefVelCell.Value = fdr.DieInspectResults[dieIndex][i].QualifiedDescript; //dieRefVelCell.Style.ForeColor = fdr.DieInspectResults[dieIndex][i].IsDetectOK() ? Color.DarkGreen : Color.DarkRed; row.Cells.Add(dieRefVelCell); DataGridViewTextBoxCell dieDetectVelCell = new DataGridViewTextBoxCell(); dieDetectVelCell.Value = fdr.DieInspectResults[dieIndex][i].ResultDescript; row.Cells.Add(dieDetectVelCell); DataGridViewTextBoxCell dieRemarksCell = new DataGridViewTextBoxCell(); string rowColInfo = "Die:" + (dieIndex + 1) + " 行:" + (dieIndex / dieCount + 1) + " 列:" + (dieIndex % dieCount + 1); dieRemarksCell.Value = rowColInfo; row.Cells.Add(dieRemarksCell); dgvDetectItems.Rows.Add(row); } } } } } else if (CMC_DieResults == msgCategory) { InspectionData[] inspDatas = msgParams[0] as InspectionData[]; if (null == inspDatas) { return; } _lstInspectData.AddRange(inspDatas); foreach (InspectionData inspData in inspDatas) { mappCtrl.SetDieState(inspData.RowIndex, inspData.ColumnIndex, inspData.InspectionResult == InspectionResults.OK ? "合格" : "不合格"); } } else if (CMC_PieceFinished == msgCategory) { bool isOnLineReview = (bool)JFHubCenter.Instance.SystemCfg.GetItemValue("在线复判"); string recipeID = msgParams[0] as string; string lotID = msgParams[1] as string; string pieceID = msgParams[2] as string; string inspectResultFolder = msgParams[3] as string; string pictureFolder = msgParams[4] as string; rchRDetectInfo.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + " " + recipeID + " 检测完成"); if (!isOnLineReview) { fmTips.AddOneTips(msgParams[0] + " 检测完成"); } else { FormDLAFReview fm = new FormDLAFReview(); fm.SetReviewParam(recipeID, lotID, pieceID, inspectResultFolder + "\\" + recipeID + ".db", pictureFolder); fm.ShowDialog(); JFHubCenter.Instance.DataPool.SetItemValue("检测工站:在线复判完成", true); } } else { } })); }
void ShowImg(IJFImage img) { if (InvokeRequired) { Invoke(new dgShowImg(ShowImg), new object[] { img }); return; } int err = 0; if (_imgShowMode == ImgShowMode.sdk) // 使用SDK内部自带的图片显示功能 { picWnd = picBox.Handle; err = img.DisplayTo(picWnd); if (err != 0) { if (!chkContinueGrab.Checked) { MessageBox.Show("SDK显示图像失败,错误信息:" + _currImage.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms")); } else { ShowTips("SDK显示图像失败,错误信息:" + _currImage.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms")); } } else { ShowTips("SDK显示图像完成"); } } else if (_imgShowMode == ImgShowMode.halcon) //Halcon显示图片 { if (_currHo != null) { _currHo.Dispose(); _currHo = null; } object hoImage = null; ShowTips("Halcon转换开始:" + DateTime.Now.ToString("HH:mm:ss:ms")); err = img.GenHalcon(out hoImage); if (err != 0) { ShowTips("显示图片失败,未能将图片转化为Halcon对象,错误信息:" + img.GetErrorInfo(err)); if (!chkContinueGrab.Checked) { MessageBox.Show("显示图片失败,未能将图片转化为Halcon对象,错误信息:" + img.GetErrorInfo(err)); } return; } ShowTips("Halcon转换完成:" + DateTime.Now.ToString("HH:mm:ss:ms")); ShowHalconImg((HObject)hoImage, img.PicWidth, img.PicHeight); _currHo = (HObject)hoImage; ShowTips("图像显示完成:" + DateTime.Now.ToString("HH:mm:ss:ms")); } else if (_imgShowMode == ImgShowMode.bitmap) // { ShowTips("Bitmap转换开始:" + DateTime.Now.ToString("HH:mm:ss:ms")); Bitmap bmp = null; err = img.GenBmp(out bmp); if (err != 0) { ShowTips("显示图片失败,未能将图片转化为Bitmap对象,错误信息:" + _currImage.GetErrorInfo(err)); if (!chkContinueGrab.Checked) { MessageBox.Show("显示图片失败,未能将图片转化为Bitmap对象,错误信息:" + _currImage.GetErrorInfo(err)); } return; } ShowTips("Bitmap转换完成:" + DateTime.Now.ToString("HH:mm:ss:ms")); ShowBitmap(bmp);//// if (null != _currBmp) { _currBmp.Dispose(); _currBmp = bmp; } } _currImage = img; }
protected override bool ActionGenuine(out string errorInfo) { try { IJFImage img = GetMethodInputValue("Image") as IJFImage; if (null == img) { errorInfo = "输入图像为空"; return(false); } string recipeID = GetMethodInputValue("RecipeID") as string; if (string.IsNullOrEmpty(recipeID)) { errorInfo = "RecipeID未设置"; return(false); } string fovName = GetMethodInputValue("FovName") as string; if (string.IsNullOrEmpty(fovName)) { errorInfo = "FovName未设置"; return(false); } Inspect_Node node = JFDLAFInspectionManager.Instance.GetInspectNode(recipeID, fovName); if (null == node) { errorInfo = "RecipeID对应的InspectNode未初始化"; return(false); } object hoImg = null; int ret = img.GenHalcon(out hoImg); if (ret != 0) { errorInfo = "JFImage to halcon failed:" + img.GetErrorInfo(ret); return(false); } int errorCode = -1; //string errorInfo = "Unknown-Error"; HObject BondContours; HObject Wires; HObject FailRegs; string optErrorInfo = ""; if (!node.InspectImage(hoImg as HObject, out errorCode, out optErrorInfo, out BondContours, out Wires, out FailRegs)) { errorInfo = optErrorInfo; SetOutputParamValue("ErrorCode", errorCode); SetOutputParamValue("ErrorInfo", optErrorInfo); SetOutputParamValue("焊点区域", null); SetOutputParamValue("金线区域", null); SetOutputParamValue("失败区域", null); errorInfo = "Success"; return(false); } SetOutputParamValue("ErrorCode", errorCode); SetOutputParamValue("ErrorInfo", optErrorInfo); SetOutputParamValue("焊点区域", BondContours); SetOutputParamValue("金线区域", Wires); SetOutputParamValue("失败区域", FailRegs); errorInfo = "Success"; return(true); } catch (Exception ex) { errorInfo = ex.Message; return(false); } }
public void OnCustomizeMsg(string msgCategory, object[] msgParams) //其他自定义消息 { if (InvokeRequired) { Invoke(new dgCustomizeMsg(OnCustomizeMsg), new object[] { msgCategory, msgParams }); return; } if (msgCategory == DLAFDetectStation.CMC_ShowJFImage) { if (msgParams == null || 0 == msgParams.Length) { return; } IJFImage ji = msgParams[0] as IJFImage; if (null == ji) { return; } object hoImg = null; if (0 != ji.GenHalcon(out hoImg)) { return; } htWindowControl1.DispImage(hoImg as HObject); } else if (msgCategory == DLAFDetectStation.CMC_ShowHO) { if (msgParams == null || 0 == msgParams.Length) { return; } HObject hoImg = msgParams[0] as HObject; if (null == hoImg) { return; } htWindowControl1.DispImage(hoImg); } else if (msgCategory == DLAFDetectStation.CMC_InspectResult)////检测结果 , 后面的参数列表为 HObject/图像,RecipeID,ICRow,ICCol,FovName,ErrorCode,ErrorInfo,Hobject-Region/Bond,Hobject-Region/Wires,Hobject-FailedRegs { //IJFImage[] lstTaskImages = msgParams[0] as IJFImage[]; //string recipeID = msgParams[1] as string; //int icRow = Convert.ToInt32(msgParams[2]); //int icCol = Convert.ToInt32(msgParams[3]); //string fovName = msgParams[4] as string; //bool detectResult = Convert.ToBoolean(msgParams[5]); //string detectErrorInfo = msgParams[6] as string; //List<int[]> diesErrorCodes = msgParams[7] as List<int[]>; //string[] dieErrorInfos = msgParams[8] as string[]; //HObject bondRegion = msgParams[9] as HObject; //HObject wiresRegion = msgParams[10] as HObject; //HObject failedRegion = msgParams[11] as HObject; //object objTmp; //lstTaskImages[0].GenHalcon(out objTmp); //HObject hoImg = objTmp as HObject; //for (int i = 1; i < lstTaskImages.Count; i++) //{ // object ot; // lstTaskImages[i].GenHalcon(out ot); // HOperatorSet.ConcatObj(hoImg, ot as HObject, out hoImg); //} //List<HObject> rgs = new List<HObject>(); //if (null != bondRegion) // rgs.Add(bondRegion); //if (null != wiresRegion) // rgs.Add(wiresRegion); //if(null != failedRegion) // rgs.Add(failedRegion); //if (rgs.Count() == 0) // return; //HObject hoRegion = rgs[0]; //if(rgs.Count > 1) //{ // hoRegion = rgs[0]; // for (int i = 1; i< rgs.Count();i++) // HOperatorSet.ConcatObj(rgs[i], hoRegion, out hoRegion); //} //htWindowControl1.RefreshWindow(hoImg, hoRegion, "fit"); //StringBuilder sbInfo = new StringBuilder(); //sbInfo.AppendLine("-----------------------------"); //sbInfo.AppendLine("IcRow:" + icRow + " IcCol:" + icCol + "FovName:" + fovName + " 检测结果:"); //if(!detectResult) //{ // sbInfo.AppendLine("视觉检测失败:" + detectErrorInfo); //} //else //{ // for (int i = 0; i < diesErrorCodes.Count(); i++) // { // sbInfo.AppendLine("Die-" + i + " ErrorCodes:" + string.Join("|", diesErrorCodes[i])); // sbInfo.AppendLine( " ErrorInfo:" + dieErrorInfos[i]); // } //} //ShowDetectResultTxt(sbInfo.ToString()); } }