/// <summary> /// 采集一张图片并显示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btGrabOne_Click(object sender, EventArgs e) { if (null == _cmr) { ShowTips("操作失败,相机未设置"); return; } IJFImage img = null; int err = _cmr.GrabOne(out img); if (err != 0) { if (!chkContinueGrab.Checked) { MessageBox.Show("抓图失败,错误信息:" + _cmr.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms")); } else { ShowTips("抓图失败,错误信息:" + _cmr.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms")); } return; } ShowTips("抓图操作成功,开始显示图像..."); ShowImg(img); //if(null != _currImage) //{ // _currImage.Dispose(); // _currImage = null; //} }
public int CaputreOneImage(string cmrName, string imageType, out HObject hObject, out string errMsg, int timeoutMilSwconds = -1) { IJFInitializable dev = null; JFDevCellInfo ci = null; IJFImage image = null; hObject = null; errMsg = ""; if (!JFCMFunction.CheckDevCellName(JFCMFunction.Cmr, cmrName, out dev, out ci, out errMsg)) { return((int)ErrorDef.InvokeFailed); } IJFDevice_Camera cmr = (dev as IJFDevice_Camera); cmr.ClearBuff(); int errCode = cmr.GrabOne(out image, timeoutMilSwconds); if (errCode != (int)ErrorDef.Success) { errMsg = cmr.GetErrorInfo(errCode); return(errCode); } if (GenImgObject(imageType, image, out hObject, out errMsg) != 0) { return((int)ErrorDef.InvokeFailed); } return((int)ErrorDef.Success); }
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("图像已显示"); } }
void _FuncAutoGrab() { while (_isAutoGrabRunning) { if (!chkCallBack.Checked) { IJFImage img = null; int err = _cmr.GrabOne(out img); if (err != 0) { if (!chkContinueGrab.Checked) { MessageBox.Show("抓图失败,错误信息:" + _cmr.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms")); } else { ShowTips("抓图失败,错误信息:" + _cmr.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms")); } return; } ShowTips("抓图操作成功,开始显示图像..."); ShowImg(img); _currImage = img; } else //使用回调 + 连续 { } } }
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); } }
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); }
/// <summary>实时抓拍一张图片</summary> public int GrabOne(out IJFImage img, int timeoutMilSeconds = -1) { img = null; if (!IsDeviceOpen) { return((int)ErrorDef.NotOpen); } if (!IsGrabbing) { return((int)ErrorDef.NotGrabbing); } JFCmrTrigMode currTM = JFCmrTrigMode.disable; GetTrigMode(out currTM); if (currTM != JFCmrTrigMode.disable) { return((int)ErrorDef.TrigModeUnMatch); } int err = 0; if (_payloadSize <= 0) { MyCamera.MVCC_INTVALUE stVal = new MyCamera.MVCC_INTVALUE(); err = _hikCmr.MV_CC_GetIntValue_NET("PayloadSize", ref stVal); if (MyCamera.MV_OK != err) { return((int)ErrorDef.InvokeFailed); } else { _payloadSize = (int)stVal.nCurValue; } } byte[] dataBytes = new byte[_payloadSize]; IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(dataBytes, 0); MyCamera.MV_FRAME_OUT_INFO_EX frameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX(); err = _hikCmr.MV_CC_GetOneFrameTimeout_NET(ptr, (uint)_payloadSize, ref frameInfo, timeoutMilSeconds); if (err != MyCamera.MV_OK) { return((int)ErrorDef.InvokeFailed); } img = new JFImage_Hik(dataBytes, frameInfo, _hikCmr); return((int)ErrorDef.Success); }
public override void UpdateSrc2UI() { //base.UpdateSrc2UI(); if (InvokeRequired) { Invoke(new Action(UpdateSrc2UI)); return; } if (null == _method) { btAction.Enabled = false; btSelectFile.Enabled = false; tbFilePath.Enabled = false; tbFilePath.Text = ""; tbFilePath.BackColor = SystemColors.Control; tssImgWidth.Text = "宽:未知"; tssImgHeight.Text = "高:未知"; tssSpanSeconds.Text = "耗时:未执行"; tssInfo.Text = "信息:方法对象未设置!"; return; } btAction.Enabled = true; btSelectFile.Enabled = true; tbFilePath.Enabled = true; tbFilePath.BackColor = SystemColors.Control; tbFilePath.Text = _method.GetInitParamValue("FilePath") as string;//_method.GetMethodInputValue("FilePath") as string; IJFImage img = _method.GetMethodOutputValue("Image") as IJFImage; if (null == img) { tssImgWidth.Text = "宽:未知"; tssImgHeight.Text = "高:未知"; tssSpanSeconds.Text = "耗时:未执行"; tssInfo.Text = "信息:无图像"; } else { tssImgWidth.Text = "宽:" + img.PicWidth; tssImgHeight.Text = "高:" + img.PicHeight; tssSpanSeconds.Text = "耗时:" + _method.GetActionSeconds().ToString("F3"); tssInfo.Text = "信息:图像正常"; ShowImage(img); } }
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"; } }
public bool Action() { _startPfCnt = JFFunctions.PerformanceCounter(); _endPfCnt = _startPfCnt; if (string.IsNullOrEmpty(_filePath)) { _actionErrorInfo = "图片文件路径未设置"; _endPfCnt = JFFunctions.PerformanceCounter(); return(false); } if (!File.Exists(_filePath)) { _actionErrorInfo = "Failed By: _filePath = \"" + _filePath + "\" is not existed"; _endPfCnt = JFFunctions.PerformanceCounter(); return(false); } //if(_image != null) //{ // _image.Dispose(); // _image = null; //} try { HObject ho; HOperatorSet.ReadImage(out ho, _filePath); _image = new JFImage_Hlc(ho, 0); } catch (Exception ex) { _actionErrorInfo = "Failed By:Exception =" + ex.ToString(); _endPfCnt = JFFunctions.PerformanceCounter(); return(false); } _endPfCnt = JFFunctions.PerformanceCounter(); _actionErrorInfo = "Success"; return(true); }
public override void UpdateSrc2UI() { if (InvokeRequired) { Invoke(new Action(UpdateSrc2UI)); return; } if (null == _method) { return; } IJFImage img = _method.GetMethodOutputValue(JFCM_CmrSnapOne_S.ON_Image) as IJFImage; if (null == img) { return; } else { ucImageView1.LoadImage(img); ucImageView1.UpdateView(); } }
protected override bool ActionGenuine(out string errorInfo) { string cmrID = GetInitParamValue(PN_CmrName) as string; //bool isAutoOpenDev = (bool)GetInitParamValue(PN_AutoOpenDevice); //bool isAutoSwitchMode = (bool)GetInitParamValue(PN_AutoSwitchMode); //bool isAutoGrab = (bool)GetInitParamValue(PN_AutoGrab); string[] allCmrIDs = JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_Camera)); if (null == allCmrIDs) { errorInfo = "抓图失败,设备列表中不存在相机"; SetOutputParamValue(ON_Image, null); return(false); } if (!allCmrIDs.Contains(cmrID)) { errorInfo = "抓图失败,设备列表中未包含名称为:\"" + cmrID + "\"的相机"; SetOutputParamValue(ON_Image, null); return(false); } int errCode = 0; IJFDevice_Camera cmr = JFHubCenter.Instance.InitorManager.GetInitor(cmrID) as IJFDevice_Camera; IJFImage img = null; errCode = cmr.GrabOne(out img, 1000); if (errCode != 0) { errorInfo = "抓图失败,错误信息:" + cmr.GetErrorInfo(errCode); SetOutputParamValue(ON_Image, null); return(false); } errorInfo = "Success"; SetOutputParamValue(ON_Image, img); return(true); }
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()); } }
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; }
//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 { } })); }
protected override bool ActionGenuine(out string errorInfo) { string recipeID = GetMethodInputValue("RecipeID") as string; if (string.IsNullOrEmpty(recipeID)) { errorInfo = "输入参数RecipeID 为空字串"; return(false); } IJFImage markImg1 = GetMethodInputValue("MarkImage1") as IJFImage; if (null == markImg1) { errorInfo = "MarkImage1 is null"; return(false); } IJFImage markImg2 = GetMethodInputValue("MarkImage2") as IJFImage; if (null == markImg1) { errorInfo = "MarkImage1 is null"; return(false); } IDLAFProductFixReceiver rcver = GetMethodInputValue("定位结果接收者") as IDLAFProductFixReceiver; if (null == rcver) { errorInfo = "定位结果接收者 未设置"; return(false); } double markSnapX1 = Convert.ToDouble(GetMethodInputValue("MarkSanpX1")); double markSnapY1 = Convert.ToDouble(GetMethodInputValue("MarkSanpY1")); double markSnapX2 = Convert.ToDouble(GetMethodInputValue("MarkSanpX2")); double markSnapY2 = Convert.ToDouble(GetMethodInputValue("MarkSanpY2")); double[] icCenterX = null; double[] icCenterY = null; double[] fovOffsetX = null; double[] fovOffsetY = null; int fixErrorCode = -1; string fixErrorInfo = "软件功能未实现"; //////////////////////////////////////////////添加定位算法流程 IJFRecipeManager irm = JFHubCenter.Instance.RecipeManager; if (null == irm) { errorInfo = "配方管理器未设置"; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } if (!irm.IsInitOK) { errorInfo = "配方管理器未初始化 :" + irm.GetInitErrorInfo(); rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } JFDLAFRecipeManager rm = irm as JFDLAFRecipeManager; if (null == rm) { errorInfo = "配方管理器类型错误 :" + irm.GetType().Name; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } JFDLAFProductRecipe recipe = rm.GetRecipe("Product", recipeID) as JFDLAFProductRecipe; if (null == recipe) { errorInfo = "RecipeID =\"" + recipeID + "\" 在配方管理器中不存在"; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } ///使用原始拍照点位 icCenterX = new double[recipe.ICCount]; icCenterY = new double[recipe.ICCount]; for (int i = 0; i < recipe.RowCount; i++) { for (int j = 0; j < recipe.ColCount; j++) { recipe.GetICSnapCenter(i, j, out icCenterX[i * recipe.ColCount + j], out icCenterY[i * recipe.ColCount + j]); } } ///使用原始Fov偏移量 fovOffsetX = new double[recipe.FovCount]; fovOffsetY = new double[recipe.FovCount]; for (int i = 0; i < recipe.FovCount; i++) { recipe.GetFovOffset(recipe.FovNames()[i], out fovOffsetX[i], out fovOffsetY[i]); } fixErrorCode = 0; //当前为演示代码,返回模板图像拍照位置 rcver.PFRecipeID = recipeID; rcver.PFErrorInfo = fixErrorInfo; rcver.PFICCenterX = icCenterX; rcver.PFICCenterY = icCenterY; rcver.PFFovOffsetX = fovOffsetX; rcver.PFFovOffsetY = fovOffsetY; rcver.PFErrorCode = fixErrorCode; errorInfo = "Success"; return(true); }
/// <summary> /// 显示一幅JF图像 /// </summary> /// <param name="img"></param> public void DisplayImage(IJFImage img) { }
/// <summary>实时抓拍一张图片</summary> public int Snap(out IJFImage img) { throw new NotImplementedException(); }
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); } }
void _HikFrameCallback(IJFDevice_Camera cmr, IJFImage frame) //JF的海康相机回调函数 { ShowImg(frame); }
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); } } }