private void button_FindModel_Click(object sender, EventArgs e) { if (showRegion != null) { if (showRegion.IsInitialized()) { showRegion.Dispose(); } } _station.operation.ShowImage(htWindow, htWindow.Image, null); HTuple hv_found_row = null; HTuple hv_found_col = null; HTuple hv_found_angle = null; HTuple hv_found_score = null; HTuple hv_update_def_row = null; HTuple hv_update_def_col = null; HTuple hv_model_H_new = null; HTuple hv_iFlag = null; VisionMethon.find_model_ext(htWindow.Image, htWindow.Image, LoctionModels.showContour, out showRegion, LoctionModels.modelType, LoctionModels.modelID, -1, -1, ((double)trackBar1.Value) / 100, 0, LoctionModels.defRows, LoctionModels.defCols, out hv_found_row, out hv_found_col, out hv_found_angle, out hv_found_score, out hv_update_def_row, out hv_update_def_col, out hv_model_H_new, out hv_iFlag); _station.operation.ShowImage(htWindow, htWindow.Image, showRegion); if (regionModifyForm != null) { if (!regionModifyForm.IsDisposed) { regionModifyForm.Dispose(); } } regionModifyForm = new RegionModifyForm(htWindow, showRegion, RegionModifyForm.RegionMode.contour); regionModifyForm.Dock = DockStyle.Fill; regionModifyForm.Visible = true; panel1.Controls.Add(regionModifyForm); }
private void button_GenClipPos_Click(object sender, EventArgs e) { try { HTuple hv_iFlag = null; VisionMethon.get_mapping_coords_ext(showRegion, _station.hv_xSnapPosLT, _station.hv_ySnapPosLT, _station.List_UV2XYResult[_station.SelectedIndex], _station.jFDLAFProductRecipe.ScaleFactor, _station.RowNumber, _station.ColumnNumber * _station.BlockNumber, out _station.clipMapX, out _station.clipMapY, out _station.clipMapRow, out _station.clipMapCol, out _station.clipMapU, out _station.clipMapV, out _station.hv_dieWidth, out _station.hv_dieHeight, out hv_iFlag); if (hv_iFlag.S != "") { MessageBox.Show("生成芯片点位失败." + hv_iFlag.S); return; } HOperatorSet.WriteTuple(_station.clipMapX, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapX.dat"); HOperatorSet.WriteTuple(_station.clipMapY, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapY.dat"); HOperatorSet.WriteTuple(_station.clipMapRow, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapRow.dat"); HOperatorSet.WriteTuple(_station.clipMapCol, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapCol.dat"); //_station.scanIniConfig.Writedouble("ScanPoints", "dieWidth", _station.hv_dieWidth.D); //_station.scanIniConfig.Writedouble("ScanPoints", "dieHeight", _station.hv_dieHeight.D); //清除之前的点位 if (_station.ClipMapPostions != null) { _station.ClipMapPostions.Clear(); } else { _station.ClipMapPostions = new List <ImagePosition>(); } ImagePosition imagePosition = new ImagePosition(); imagePosition.z = _station.ZFocus; imagePosition.b = 0; _station.clipPosNum = _station.clipMapX.Length; for (int i = 0; i < _station.clipPosNum; i++) { imagePosition.x = _station.clipMapX.TupleSelect(i); imagePosition.y = _station.clipMapY.TupleSelect(i); imagePosition.r = _station.clipMapRow.TupleSelect(i); imagePosition.c = _station.clipMapCol.TupleSelect(i); _station.ClipMapPostions.Add(imagePosition); } MessageBox.Show("生成芯片点位完成."); } catch (Exception ex) { MessageBox.Show("保存芯片点位失败。\n" + ex.ToString()); } }
/// <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); }