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("图像已显示"); } }
private int GenImgObject(string imageType, IJFImage image, out HObject hObject, out string errMsg) { hObject = null; errMsg = ""; object ImgObject; int errCode = image.GenImgObject(out ImgObject, imageType); if (errCode != (int)ErrorDef.Success) { errMsg = image.GetErrorInfo(errCode); return(errCode); } hObject = (HObject)ImgObject; return((int)ErrorDef.Success); }
public void LoadImage(IJFImage jImage) { if (!Created) { return; } if (InvokeRequired) { Invoke(new dgLoadImage(LoadImage), new object[] { jImage }); return; } //if (jImage != jFImage) //{ // if (null != jFImage) // { // jFImage.Dispose(); // jFImage = null; // } //} jFImage = jImage; if (null != bitImage) { bitImage.Dispose(); bitImage = null; } if (null != jFImage) { int iRet = jFImage.GenBmp(out bitImage); if (0 == iRet) { DrawImage(); } else { string errorInfo = jFImage.GetErrorInfo(iRet); this.labErrorInfo.Text = errorInfo; } } else { labErrorInfo.Text = "Image = null"; } }
//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 { } })); }
private void btSaveImage_Click(object sender, EventArgs e) { if (null == _cmr) { ShowTips("操作失败,相机未设置"); return; } IJFImage img = _currImage; if (null == img) { MessageBox.Show("保存图像失败:当前未采集图像"); return; } if (cbImgFileFormat.SelectedIndex < 0) { MessageBox.Show("请先选择文件格式!"); return; } SaveFileDialog sfd = new SaveFileDialog(); switch (cbImgFileFormat.SelectedIndex) { case 0: sfd.Filter = "BMP files(*.BMP)| *.BMP "; break; case 1: sfd.Filter = "JPG files(*.JPG) | *.JPG "; break; case 2: sfd.Filter = " PNG files(*.PNG) | *.PNG "; break; case 3: sfd.Filter = "TIF files(*.TIF) | *.TIF"; break; default: throw new Exception("ImgFileFormat is not selected!"); //break; } sfd.FileName = "保存"; //设置默认文件名 sfd.DefaultExt = "BMP"; //设置默认格式(可以不设) sfd.AddExtension = true; //设置自动在文件名中添加扩展名 sfd.CheckFileExists = false; if (sfd.ShowDialog() == DialogResult.OK) { int err = img.Save(sfd.FileName, (JFImageSaveFileType)cbImgFileFormat.SelectedIndex); if (err != 0) { MessageBox.Show("保存文件失败,ErrorInfo:" + img.GetErrorInfo(err)); } else { ShowTips("图片已保存至文件:" + sfd.FileName); } } }
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); } }