/// <summary> /// Fov 选择改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbFovName_SelectedIndexChanged(object sender, EventArgs e) { if (cbFovName.SelectedIndex < 0) { cbTaskName.Text = ""; btFixFov.Enabled = false; return; } string currFovName = cbFovName.Text; string currTaskName = cbTaskName.Text; JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; string[] allFovNames = recipe.FovNames(); if (!allFovNames.Contains(currFovName)) { MessageBox.Show("当前Recipe未包含FovName:" + currFovName); cbTaskName.Text = ""; btFixFov.Enabled = false; return; } btFixFov.Enabled = true; double x, y; recipe.GetFovOffset(currFovName, out x, out y); lbFovOffset.Text = string.Format("x:{0:F3} y:{1:F3}", x, y); string[] allTaskNames = recipe.TaskNames(currFovName); cbTaskName.Items.Clear(); if (null != allTaskNames) { foreach (string s in allTaskNames) { cbTaskName.Items.Add(s); } } if (!string.IsNullOrEmpty(currTaskName)) { if (_isTaskVcEditting) { _isTaskVcEditting = false; cbTaskVc.Enabled = false; btTaskVcEditCancel.Enabled = false; btTaskVcEditSave.Text = "设置"; } cbTaskName.Text = currTaskName; if (allTaskNames != null && allTaskNames.Contains(currTaskName)) { cbTaskName.BackColor = SystemColors.Control; } else { cbTaskName.BackColor = Color.OrangeRed; } } }
/// <summary> /// 生成芯片实际扫描点位 /// </summary> /// <param name="imgs"></param> /// <param name="snapX"></param> /// <param name="snapY"></param> /// <param name="icsCenterX"></param> /// <param name="icsCenterY"></param> /// <param name="fovsOffsetX"></param> /// <param name="fovsOffsetY"></param> /// <param name="errorInfo"></param> /// <returns></returns> public bool CalibProduct(IJFImage[] imgs, double[] snapX, double[] snapY, out double[] icsCenterX, out double[] icsCenterY, out double[] fovsOffsetX, out double[] fovsOffsetY, out string errorInfo) { if (!_isInitOK) { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; errorInfo = "初始化未完成"; return(false); } HObject[] himgs = new HObject[] { null, null }; object oi; if (0 != imgs[0].GenHalcon(out oi)) { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; errorInfo = "左Mark图像转Halcon失败!"; return(false); } himgs[0] = oi as HObject; if (0 != imgs[1].GenHalcon(out oi)) { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; errorInfo = "右Mark图像转Halcon失败!"; return(false); } himgs[1] = oi as HObject; //左矫正点 HTuple hv_iFlag = new HTuple(); HTuple hvLeftModeHMap = new HTuple(); HTuple hvDefLeft_coorX = new HTuple(); HTuple hvDefLeft_coorY = new HTuple(); HTuple hvDefLeft_updateX = new HTuple(); HTuple hvDefLeft_updateY = new HTuple(); HTuple hvDefLeft_updateRow = new HTuple(); HTuple hvDefLeft_updateCol = new HTuple(); if (_leftMarkModel.matchRegion == null || !_leftMarkModel.matchRegion.IsInitialized()) { HOperatorSet.GetDomain(himgs[0], out _leftMarkModel.matchRegion); } VisionMethon.coor_uvToxy_point(himgs[0], _leftMarkModel.defRows, _leftMarkModel.defCols, _recipe.CheckPosX, _recipe.CheckPosY, _cmrCalibData, out hvDefLeft_coorX, out hvDefLeft_coorY, out hv_iFlag); if (hv_iFlag.S != "") { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; hvDefLeft_updateX = null; hvDefLeft_updateY = null; errorInfo = "左模板中心像素转换成实际坐标失败!" + hv_iFlag.S; return(false); } VisionMethon.Map_Points_Match(himgs[0], _leftMarkModel.matchRegion, _leftMarkModel.modelType, _leftMarkModel.modelID, _recipe.CheckPosScoreThresh, _leftMarkModel.defRows, _leftMarkModel.defCols, hvDefLeft_coorX, hvDefLeft_coorY, _cmrCalibData, out hvLeftModeHMap, out hvDefLeft_updateX, out hvDefLeft_updateY, out hvDefLeft_updateRow, out hvDefLeft_updateCol, out hv_iFlag); if (hv_iFlag.S != "") { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; hvDefLeft_updateX = null; hvDefLeft_updateY = null; errorInfo = "左矫正点匹配失败!" + hv_iFlag.S; return(false); } //if (showRegion != null) showRegion.Dispose(); //HOperatorSet.GenCrossContourXld(out showRegion, hvDefLeft_updateRow, hvDefLeft_updateCol, 512, 0); //ShowImage(hTWindow, himgs[0], showRegion); //左矫正点 HTuple hvRightModeHMap = new HTuple(); HTuple hvDefRight_coorX = new HTuple(); HTuple hvDefRight_coorY = new HTuple(); HTuple hvDefRight_updateX = new HTuple(); HTuple hvDefRight_updateY = new HTuple(); HTuple hvDefRight_updateRow = new HTuple(); HTuple hvDefRight_updateCol = new HTuple(); if (_rightMarkModel.matchRegion == null || !_rightMarkModel.matchRegion.IsInitialized()) { HOperatorSet.GetDomain(himgs[1], out _rightMarkModel.matchRegion); } VisionMethon.coor_uvToxy_point(himgs[1], _rightMarkModel.defRows, _rightMarkModel.defCols, _recipe.CheckPosRX, _recipe.CheckPosRY, _cmrCalibData, out hvDefRight_coorX, out hvDefRight_coorY, out hv_iFlag); if (hv_iFlag.S != "") { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; errorInfo = "右模板中心像素转换成实际坐标失败!" + hv_iFlag.S; return(false); } VisionMethon.Map_Points_Match(himgs[1], _rightMarkModel.matchRegion, _rightMarkModel.modelType, _rightMarkModel.modelID, _recipe.CheckPosRScoreThresh, _rightMarkModel.defRows, _rightMarkModel.defCols, hvDefRight_coorX, hvDefRight_coorY, _cmrCalibData, out hvRightModeHMap, out hvDefRight_updateX, out hvDefRight_updateY, out hvDefRight_updateRow, out hvDefRight_updateCol, out hv_iFlag); if (hv_iFlag.S != "") { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; errorInfo = "右矫正点匹配失败!" + hv_iFlag.S; return(false); } //if (showRegion != null) showRegion.Dispose(); //HOperatorSet.GenCrossContourXld(out showRegion, hvDefLeft_updateRow, hvDefLeft_updateCol, 512, 0); //ShowImage(hTWindow, himgs[1], showRegion); //生成矫正后芯片扫描点位 HTuple hvAfterFix_SnapX = new HTuple(); HTuple hvAfterFix_SnapY = new HTuple(); HTuple hvAfterFix_ICX = null; HTuple hvAfterFix_ICY = null; HTuple hv_du = null; HTuple hv_dv = null; VisionMethon.update_map_correction(_recipe.icMapX, _recipe.icMapY, _recipe.snapMapX, _recipe.snapMapY, hvDefLeft_coorX, hvDefLeft_coorY, hvDefRight_coorX, hvDefRight_coorY, hvDefLeft_updateX, hvDefLeft_updateY, hvDefRight_updateX, hvDefRight_updateY, _cmrCalibData, out hvAfterFix_ICX, out hvAfterFix_ICY, out hvAfterFix_SnapX, out hvAfterFix_SnapY, out hv_iFlag, out hv_du, out hv_dv); if (hv_iFlag.S != "") { icsCenterX = null; icsCenterY = null; fovsOffsetX = null; fovsOffsetY = null; errorInfo = "生成矫正点后扫描点位失败!" + hv_iFlag.S; return(false); } //Fov矫正日后添加 int fovCount = _recipe.FovCount; fovsOffsetX = new double[fovCount]; fovsOffsetY = new double[fovCount]; for (int i = 0; i < fovCount; i++) { _recipe.GetFovOffset(_recipe.FovNames()[i], out fovsOffsetX[i], out fovsOffsetY[i]); } double[] _icsCenterX = new double[hvAfterFix_SnapX.Length]; double[] _icsCenterY = new double[hvAfterFix_SnapX.Length]; icsCenterX = new double[hvAfterFix_SnapX.Length]; icsCenterY = new double[hvAfterFix_SnapX.Length]; for (int i = 0; i < hvAfterFix_SnapX.Length; i++) { _icsCenterX[i] = hvAfterFix_SnapX.TupleSelect(i).D; _icsCenterY[i] = hvAfterFix_SnapY.TupleSelect(i).D; } //重新排序每行扫描按照从左到右进行扫描 int currentIndex = 0; for (int m = 0; m < _recipe.RowCount; m++) { for (int n = 0; n < _recipe.ColCount; n++) { int index = 0; if (m % 2 == 0) { index = (int)(m * _recipe.ColCount + n); } else { index = (int)(m * _recipe.ColCount + (_recipe.ColCount - 1 - n)); } icsCenterX[currentIndex] = _icsCenterX[index]; icsCenterY[currentIndex] = _icsCenterY[index]; currentIndex++; } } errorInfo = "Success"; return(true); }
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); }