public override bool LoadConfig(string str_parm_all) { string[] sArray = str_parm_all.Split('_'); OffsetXY = Convert.ToInt32(sArray[0]); AngleRange = Convert.ToInt32(sArray[1]); EnableRotateCenter = Convert.ToBoolean(sArray[2]); CalibDataFileName = sArray[3]; XMaxDeviation = Convert.ToDouble(sArray[4]); YMaxDeviation = Convert.ToDouble(sArray[5]); CenterRow = Convert.ToDouble(sArray[6]); CenterColumn = Convert.ToDouble(sArray[7]); DistanceMax = Convert.ToDouble(sArray[8]); int count = Convert.ToInt32(sArray[9]) * 4 + 9; for (int i = 10; i <= count;) { in_pixel_column.Append(Convert.ToDouble(sArray[i++])); in_pixel_row.Append(Convert.ToDouble(sArray[i++])); in_world_x.Append(Convert.ToDouble(sArray[i++])); in_world_y.Append(Convert.ToDouble(sArray[i++])); } return(true); }
/// <summary> /// 根据错误码优先级对错误进行输出,当错误优先级设置为一样时可以输出多个错误码 /// </summary> /// <param name="SToM"></param>单个芯片 多个不重复的错误码 /// <param name="DefectPriority"></param>芯片错误码优先级 /// <param name="SToS"></param> 单个芯片根据优先级输出错误码 public static void TranDefect(int[] SToM, Dictionary <int, int[]> DefectPriority, out HTuple SToS) { List <int []> tempPriority = new List <int []>(); List <int> tempIndex = new List <int>(); SToS = new HTuple(); for (int i = 0; i < SToM.Length; i++) { if (DefectPriority.ContainsKey(SToM[i])) { tempPriority.Add(DefectPriority[SToM[i]]); tempIndex.Add(DefectPriority[SToM[i]][0]); } else { SToS = -1; return; } } // for (int ind = 0; ind < tempIndex.Count; ind++) { if (tempPriority[ind][0] == tempIndex.Min()) { SToS.Append(tempPriority[ind][1]); } } }
/// <summary> /// 拷贝整个model文件夹信息 /// </summary> /// <param name="oriModel"></param> /// <returns></returns> public bool CopyModel(Model oriModel) { try { for (int i = 0; i < oriModel.modelID.Length; i++) { modelID.Append(Vision.CopyModel(oriModel.modelID[i], oriModel.modelType)); } modelType = oriModel.modelType; defRows = oriModel.defRows; defCols = oriModel.defCols; scoreThresh = oriModel.scoreThresh; angleStart = oriModel.angleStart; angleExtent = oriModel.angleExtent; if (oriModel.showContour.IsInitialized()) { showContour = oriModel.showContour.CopyObj(1, -1); } if (oriModel.showImage.IsInitialized()) { showImage = oriModel.showImage.CopyObj(1, -1); } if (oriModel.matchRegion.IsInitialized()) { matchRegion = oriModel.matchRegion.CopyObj(1, -1); } return(true); } catch (Exception) { this.Dispose(); return(false); } }
/**获取变换矩阵集合,不包含最初的初始变换矩阵 * **/ public HTuple GetTransformMatrix() { HTuple HomMat3DStart; /**生成一个标准变换矩阵 * 1 0 0 0 * 0 1 0 0 * 0 0 1 0 * 0 0 0 1 * **/ HOperatorSet.HomMat3dIdentity(out HomMat3DStart); HTuple transformMat = new HTuple(); //pose转Mat的临时存储 HTuple tempPoseMat; for (int i = 0; i < pairRegesters.Count; i++) { //Regester得到的pose转换成矩阵,既三维的变换矩阵 HOperatorSet.PoseToHomMat3d(pairRegesters[i].pose, out tempPoseMat); //当前矩阵与对应的三维变换矩阵,计算出变换到标准点云所需要的变换矩阵 HOperatorSet.HomMat3dCompose(HomMat3DStart, tempPoseMat, out HomMat3DStart); transformMat.Append(HomMat3DStart); } return(transformMat); }
private void GetRegion(object sender, HMouseEventArgs e) { if (e.Button == MouseButtons.Left) { SelectRegionRows.Append(e.Y); SelectRegionCols.Append(e.X); } }
// Short Description: Get all image files under the given path private static void ListImageFiles(ref HTuple hv_ImageFiles, string imgSaveFolder) { string[] imageNames = Directory.GetFiles(imgSaveFolder, "*.bmp"); for (int i = 0; i < imageNames.Length; i++) { hv_ImageFiles.Append(imageNames[i]); } }
/**获取所有点云的句柄集合 * **/ public HTuple GetModels() { HTuple modelHandle = new HTuple(); for (int i = 0; i < registePointsList.Count; i++) { modelHandle.Append(registePointsList[i].Pointclouds); } return(modelHandle); }
/** * Display all available interfaces that have at least one device available. * * @return List of the detected interfaces. */ static HTuple showAvailableInterfaces() { HTuple deviceInfo, deviceValue, interfacesAll, temp; HTuple interfaces = new HTuple(); Console.WriteLine(System.Environment.NewLine + "Detect and show all available interfaces..." + System.Environment.NewLine); interfacesAll = HInfo.GetParamInfo("info_framegrabber", "Name", "values"); if (interfacesAll.Length > 0) { Console.WriteLine("Available interfaces:"); } else { Console.WriteLine("Found no interfaces."); return(interfaces); } ErrorModes errorMode = GetErrorMode(); // Disable error dialog boxes on interface detection. SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); for (int i = 0; i < interfacesAll.Length; i++) { try { temp = interfacesAll.TupleSelect(i); deviceInfo = HInfo.InfoFramegrabber(temp.S.ToString(), "device", out deviceValue); } catch (HalconException) { // Interface not available. continue; } if (deviceValue.Length > 0) { interfaces.Append(interfacesAll.TupleSelect(i)); Console.WriteLine(interfaces.Length + ")" + interfacesAll.TupleSelect(i).S.ToString()); } } // Restore previous error mode. SetErrorMode(errorMode); return(interfaces); }
/// <summary> /// 获取DGV某个行列范围内的数据,赋值给tuple /// </summary> /// <param name="dgv"></param> /// <param name="rowInd">起始行与终止行数组</param> /// <param name="colInd">起始列与终止列数组</param> /// <param name="tuple"></param> private void GetDGVValue(DataGridView dgv, int[] rowInd, int[] colInd, ref HTuple tuple) { tuple = new HTuple(); for (int i = rowInd[0]; i < rowInd[1] - rowInd[0] + 1; i++) { for (int j = colInd[0]; j < colInd[1] - colInd[0] + 1; j++) { tuple.Append(Convert.ToDouble(dgv.Rows[i].Cells[j].Value)); } } }
/// <summary> /// 加载标定节点数据到实例 /// </summary> /// <param name="unit"></param> private void AppendCalibData(XmlNode unit) { Type type = GetType(); FieldInfo[] fields = type.GetFields(); foreach (var item in fields) { string xpath = "/Calibration/unit[@name=\"" + CalibName + "\"]/field[@name=\"" + item.Name + "\"]"; XmlNode node = unit.SelectSingleNode(xpath); if (node == null) { continue; } object value = null; string strValue = ((XmlElement)node).GetAttribute("value"); // 类型转换 TypeConverter converter = TypeDescriptor.GetConverter(item.FieldType); if (converter.CanConvertFrom(strValue.GetType())) { value = converter.ConvertFrom(strValue); } else { converter = TypeDescriptor.GetConverter(strValue); if (converter.CanConvertTo(item.FieldType)) { value = converter.ConvertTo(item, item.FieldType); } } if (value != null) { item.SetValue(this, value); } else { // 解析无法进行类型转换的类型 if (((XmlElement)node).GetAttribute("name") == nameof(HomMat2D)) { HomMat2D = new HTuple(); string[] array = strValue.Replace("[", "").Replace("]", "").Split(','); foreach (var i in array) { HomMat2D.Append(Convert.ToDouble(i.Trim())); } } } } }
/**当前Pose集合-》变换矩阵集合 * **/ private HTuple Pose2Mat() { HTuple PoseMat = new HTuple(); HTuple tempPoseMat; for (int i = 0; i < pairRegesters.Count; i++) { HOperatorSet.PoseToHomMat3d(pairRegesters[i].pose, out tempPoseMat); PoseMat.Append(tempPoseMat); } return(PoseMat); }
/// <summary>Concatenates all tuples stored in the vector</summary> public HTuple ConvertVectorToTuple() { if (this.mDimension <= 0) { return(this.mTuple); } HTuple htuple = new HTuple(); for (int index = 0; index < this.Length; ++index) { htuple.Append(this[index].ConvertVectorToTuple()); } return(htuple); }
private async void button1_Click(object sender, EventArgs e) { HTuple calibratedata = VisionManager.Instance.Calibrate.CalibrateData; if (calibratedata != null) { HOperatorSet.AffineTransPoint2d(calibratedata, 1024, 1536, out HTuple x, out HTuple y); // RobotPos robotPos = AbbRobot.GetRobotPos(); double robotY, robotZ; FormToolPosition form = new FormToolPosition(); if (form.ShowDialog() == DialogResult.OK) { robotY = form.RobotY; robotZ = form.RobotZ; } else { return; } offx = robotY - x; offy = robotZ - y; HTuple hTuple = new HTuple(); hTuple.Append(offx); hTuple.Append(offy); string _path = AppDomain.CurrentDomain.BaseDirectory + "CalibrateData"; VisionManager.Instance.Calibrate.ToolOffsetX = offx; VisionManager.Instance.Calibrate.ToolOffsetY = offy; if (!Directory.Exists(_path)) { Directory.CreateDirectory(_path); } HOperatorSet.WriteTuple(hTuple, _path + "\\tooloffset.tup"); // HOperatorSet.WriteTuple(hTuple, _path + "\\tooloffset.tup"); // HOperatorSet.WriteTuple(hTuple, _path + "\\tooloffset.tup"); } }
private void btn_SavePointData_Click(object sender, EventArgs e) { HTuple cameraX = new HTuple(); HTuple cameraY = new HTuple(); HTuple robotX = new HTuple(); HTuple robotY = new HTuple(); for (int i = 0; i < 9; i++) { DataGridViewRow dataGridViewRow = dGV_RobotPos.Rows[i]; if (dataGridViewRow.Cells[1].Value == null || dataGridViewRow.Cells[2].Value == null) { MessageBox.Show($"机器人第{(i + 1).ToString()}行点位信息为空", "提示"); return; } robotX.Append(dataGridViewRow.Cells[1].Value.ToString()); robotY.Append(dataGridViewRow.Cells[2].Value.ToString()); } for (int i = 0; i < 9; i++) { DataGridViewRow dataGridViewRow = dGV_CameraPos.Rows[i]; if (dataGridViewRow.Cells[1].Value == null || dataGridViewRow.Cells[2].Value == null) { MessageBox.Show($"机器人第{(i + 1).ToString()}行点位信息为空", "提示"); return; } cameraX.Append(dataGridViewRow.Cells[1].Value.ToString()); cameraY.Append(dataGridViewRow.Cells[2].Value.ToString()); } string _path = AppDomain.CurrentDomain.BaseDirectory + "CalibrateData"; if (!Directory.Exists(_path)) { Directory.CreateDirectory(_path); } HOperatorSet.WriteTuple(cameraX, _path + "\\cameraX.tup"); HOperatorSet.WriteTuple(cameraY, _path + "\\cameraY.tup"); HOperatorSet.WriteTuple(robotX, _path + "\\robotX.tup"); HOperatorSet.WriteTuple(robotY, _path + "\\robotY.tup"); }
public HRegion Process(HRegion region) { HTuple features = new HTuple(); HTuple min = new HTuple(); HTuple max = new HTuple(); string operation = Operation.ToHalconString(); HRegion selectedRegion = region; foreach (var entry in Items) { var feature = entry.Feature.ToHalconString(); features.Append(feature); min.Append(entry.Min); max.Append(entry.Max); } region = selectedRegion.SelectShape(features, operation, min, max); return(region); }
public void FindEdge(HObject image, HTuple row, HTuple column, HTuple radian, out HTuple edgeRow1, out HTuple edgeColumn1, out HTuple edgeRow2, out HTuple edgeColumn2) { HTuple homMat2D, rowTrans, columnTrans; //测量外边缘 edgeRow1 = 0; edgeColumn1 = 0; edgeRow2 = 0; edgeColumn2 = 0; HOperatorSet.GenMeasureRectangle2(row + DisHanldeRow, column /*+ DisHanldeColumn*/, Radian + Math.PI / 2, 20, 40, ImageWidth, ImageHeight, Interpolation, out HandleLine); for (int i = 0; i <= 5; i++) { //设置幅度值 HTuple threshold = Threshold - 10 - i * 2; if (threshold < 1) { threshold = 1; } HTuple rows = new HTuple(); HTuple columns = new HTuple(); for (int j = 0; j < PinCount; j++) { HTuple rowEdge, columnEdge, amplitude, distance; //变换检测位置 //HTuple homMat2D, rowTrans, columnTrans; HOperatorSet.HomMat2dIdentity(out homMat2D); HOperatorSet.HomMat2dTranslate(homMat2D, DisHanldeRow, j * PinDistance, out homMat2D); HOperatorSet.HomMat2dRotate(homMat2D, radian, row, column, out homMat2D); HOperatorSet.AffineTransPixel(homMat2D, row, column, out rowTrans, out columnTrans); HOperatorSet.TranslateMeasure(HandleLine, rowTrans, columnTrans); HOperatorSet.MeasurePos(image, HandleLine, Sigma, threshold, "negative", "first", out rowEdge, out columnEdge, out amplitude, out distance); if (rowEdge.Length > 0) { rows.Append(rowEdge); columns.Append(columnEdge); } } if (rows.Length >= PinCount / 2) { //生成轮廓 HObject contour; HTuple nr, nc, dist; HOperatorSet.GenContourPolygonXld(out contour, rows, columns); //拟合 HOperatorSet.FitLineContourXld(contour, "tukey", -1, 0, 5, 2, out edgeRow1, out edgeColumn1, out edgeRow2, out edgeColumn2, out nr, out nc, out dist); //生成直线,用于显示 contour?.Dispose(); HOperatorSet.GenContourPolygonXld(out contour, new HTuple(edgeRow1, edgeRow2), new HTuple(edgeColumn1, edgeColumn2)); HOperatorSet.ConcatObj(LineEdge, contour, out LineEdge); break; } } HOperatorSet.CloseMeasure(HandleLine); }
public void MeasurePos(HObject image, HObject edgeContour) { //记录测量数量 int meaCount = 0; try { HTuple row = CenterRow; HTuple column = CenterColumn; HTuple radian = Radian; HTuple homMat2D, rowTrans, columnTrans; /* * HOperatorSet.HomMat2dIdentity(out homMat2D); * HOperatorSet.HomMat2dTranslate(homMat2D, 0, PinDistance * PinCount / 2, out homMat2D); * HOperatorSet.HomMat2dRotate(homMat2D, radian, row, column, out homMat2D); * HOperatorSet.AffineTransPixel(homMat2D, row, column, out rowTrans, out columnTrans); * * HObject rect; * HOperatorSet.GenRectangle2(out rect, rowTrans, columnTrans, radian, PinDistance * PinCount / 2 + Width, 100); * HOperatorSet.ReduceDomain(image, rect, out image); * * HOperatorSet.AnisotropicDiffusion(image, out image, "weickert", 5, 1, 10); * HOperatorSet.Emphasize(image, out image, 15, 15, 1); * * HOperatorSet.ConcatObj(LineEdge, image, out LineEdge); */ //HTuple edgeRow1, edgeColumn1, edgeRow2, edgeColumn2; //FindEdge(image, row, column, radian, out edgeRow1, out edgeColumn1, out edgeRow2, out edgeColumn2); HOperatorSet.ConcatObj(LineEdge, edgeContour, out LineEdge); //测量所有碳碳点 for (int i = 0; i < PinCount; i++) { //变换检测位置 //HTuple homMat2D, rowTrans, columnTrans; HOperatorSet.HomMat2dIdentity(out homMat2D); HOperatorSet.HomMat2dTranslate(homMat2D, 0, i * PinDistance, out homMat2D); HOperatorSet.HomMat2dRotate(homMat2D, radian, row, column, out homMat2D); HOperatorSet.AffineTransPixel(homMat2D, row, column, out rowTrans, out columnTrans); //检测碳点 HObject contour; HTuple diameterMax, diameterMin, disLeft, disRight, edgeRow, edgeColumn; MeasureCircle(image, rowTrans, columnTrans, radian, out diameterMax, out diameterMin, out disLeft, out disRight, out edgeRow, out edgeColumn, out contour); //测量碳点到玻璃边缘的距离 HTuple disTop, distanceMax; //HOperatorSet.DistancePl(edgeRow, edgeColumn, edgeRow1, edgeColumn1, edgeRow2, edgeColumn2, out disTop); HOperatorSet.DistancePc(edgeContour, edgeRow, edgeColumn, out disTop, out distanceMax); //像素转毫米 double maxDiameter = Math.Round((PlatformCalibData.PixelToMm(diameterMax) + MeasureMgr.GetInstance().OffsetDia), 2); double minDiameter = Math.Round(PlatformCalibData.PixelToMm(diameterMin), 2); double leftPos = Math.Round(PlatformCalibData.PixelToMm(disLeft), 2); double reghtPos = Math.Round(PlatformCalibData.PixelToMm(disRight), 2); double topPos = Math.Round(PlatformCalibData.PixelToMm(disTop), 2); //优先判断面积NG,后判断位置NG double LimiteMax = PlatformCalibData.PixelToMm(PinDistance); if (maxDiameter > LimiteDiameterMax || maxDiameter < LimiteDiameterMin) { HOperatorSet.ConcatObj(ContourAreaNG, contour, out ContourAreaNG); CountAreaNG++; } else if (leftPos < LimiteLeft || leftPos > LimiteMax || reghtPos < LimiteRight || reghtPos > LimiteMax || topPos < LimiteTopMin || topPos > LimiteTopMax) { HOperatorSet.ConcatObj(ContourPosNG, contour, out ContourPosNG); CountPosNG++; } else { HOperatorSet.ConcatObj(ContourOk, contour, out ContourOk); CountOK++; } //添加到参数列表 DiameterMax.Append(maxDiameter); DiameterMin.Append(minDiameter); DisLeft.Append(leftPos); DisRight.Append(reghtPos); DisTop.Append(topPos); //计数 meaCount++; } } catch (Exception e) { throw e; } finally { //未测量完成计入面积NG if (PinCount != meaCount) { CountAreaNG += PinCount - meaCount; } } }
// Main procedure private HTuple action() { // Local iconic variables HObject ho_Image, ho_ImageRotate, ho_GrayImage; HObject ho_ImageMedian, ho_Region, ho_ConnectedRegions; HObject ho_SelectedRegions, ho_SelectedRegions2, ho_SelectedRegions1; HObject ho_SelectedRegions3, ho_SortedRegions, ho_RegionUnion; HObject ho_Rectangle, ho_ImageReduced, ho_GrayImageA, ho_GragImageA; HObject ho_RegionsA_temp, ho_ConnectedRegionsA_temp, ho_SelectedRegionsA_temp; HObject ho_ImageAffineTrans, ho_RegionsA, ho_RegionDilationA; HObject ho_ConnectedRegionsA, ho_SelectedRegionsA, ho_RegionsA1; HObject ho_RegionOpeningA, ho_SelectedRegionsA1, ho_RegionUnionA; HObject ho_SelectedRegionsA2, ho_RegionsB, ho_ConnectedRegionsB; HObject ho_SelectedRegionsB, ho_RectangleB1, ho_RectangleB2; HObject ho_RegionDifferenceB, ho_ImageReducedB1, ho_RegionB1; HObject ho_ConnectedRegionsB2, ho_SelectedRegionsB2, ho_outContours; HObject ho_SelectedContours, ho_SortedContours, ho_Region1; HObject ho_ConnectedRegions1, ho_SelectedRegions4, ho_SelectedRegions5; HObject ho_SelectedRegions6, ho_Contours, ho_SortedContours3; HObject ho_obj = null, ho_objj = null, ho_ContoursSplit = null; HObject ho_SelectedXLD = null, ho_SortedContours1 = null, ho_M = null; HObject ho_Contour = null, ho_SelectedXLD1 = null, ho_SortedContours2 = null; HObject ho_ObjectSelectedB = null; // Local control variables HTuple hv_NumberB = null, hv_Row1 = null, hv_Column1 = null; HTuple hv_Phi = null, hv_Length1 = null, hv_Length2 = null; HTuple hv_Phi_temp = null, hv_Area_temp = null, hv_Row_temp = null; HTuple hv_Column_temp = null, hv_HomMat2D = null, hv_RowA1 = null; HTuple hv_ColumnA1 = null, hv_RowA2 = null, hv_ColumnA2 = null; HTuple hv_RowA3 = null, hv_ColumnA3 = null, hv_RowA4 = null; HTuple hv_ColumnA4 = null, hv_RowB16 = null, hv_ColumnB16 = null; HTuple hv_PhiB3 = null, hv_LengthB1 = null, hv_LengthB2 = null; HTuple hv_AreaB = null, hv_RowB2 = null, hv_ColumnB2 = null; HTuple hv_Number = null, hv_Number3 = null, hv_A1 = null; HTuple hv_A2 = null, hv_B1 = null, hv_B2 = null, hv_C1 = null; HTuple hv_C2 = null, hv_C3 = null, hv_C4 = null, hv_i = null; HTuple hv_Ro1 = new HTuple(), hv_Co1 = new HTuple(), hv_MinBR = new HTuple(); HTuple hv_MaxBR = new HTuple(), hv_MinBC = new HTuple(); HTuple hv_MaxBC = new HTuple(), hv_BR = new HTuple(), hv_BC = new HTuple(); HTuple hv_j = new HTuple(), hv_Number1 = new HTuple(); HTuple hv_a = new HTuple(), hv_Ro2 = new HTuple(), hv_Co2 = new HTuple(); HTuple hv_LUC = new HTuple(), hv_RUC = new HTuple(), hv_Ro3 = new HTuple(); HTuple hv_Co3 = new HTuple(), hv_LDC = new HTuple(), hv_RDC = new HTuple(); HTuple hv_RowBegin = new HTuple(), hv_ColBegin = new HTuple(); HTuple hv_RowEnd = new HTuple(), hv_ColEnd = new HTuple(); HTuple hv_Nr = new HTuple(), hv_Nc = new HTuple(), hv_Dist = new HTuple(); HTuple hv_Rowc = new HTuple(), hv_Colc = new HTuple(); HTuple hv_MeanR = new HTuple(), hv_H1 = new HTuple(), hv_H3 = new HTuple(); HTuple hv_Number2 = new HTuple(), hv_b = new HTuple(); HTuple hv_Ro4 = new HTuple(), hv_Co4 = new HTuple(), hv_LUR = new HTuple(); HTuple hv_LDR = new HTuple(), hv_Ro5 = new HTuple(), hv_Co5 = new HTuple(); HTuple hv_RUR = new HTuple(), hv_RDR = new HTuple(), hv_MeanC = new HTuple(); HTuple hv_H4 = new HTuple(), hv_H2 = new HTuple(), hv_Distance1 = new HTuple(); HTuple hv_Distance2 = new HTuple(), hv_AreaA = null, hv_RowA = null; HTuple hv_ColumnA = null, hv_phi = null, hv_paozhengwei = null; HTuple hv_k = null, hv_Indices = null, hv_liebo = null; HTuple hv_NumB = null, hv_count = null, hv_I = new HTuple(); HTuple hv_AreaB1 = new HTuple(), hv_RowB3 = new HTuple(); HTuple hv_ColumnB3 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_ImageRotate); HOperatorSet.GenEmptyObj(out ho_GrayImage); HOperatorSet.GenEmptyObj(out ho_ImageMedian); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions3); HOperatorSet.GenEmptyObj(out ho_SortedRegions); HOperatorSet.GenEmptyObj(out ho_RegionUnion); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_GrayImageA); HOperatorSet.GenEmptyObj(out ho_GragImageA); HOperatorSet.GenEmptyObj(out ho_RegionsA_temp); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsA_temp); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA_temp); HOperatorSet.GenEmptyObj(out ho_ImageAffineTrans); HOperatorSet.GenEmptyObj(out ho_RegionsA); HOperatorSet.GenEmptyObj(out ho_RegionDilationA); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsA); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA); HOperatorSet.GenEmptyObj(out ho_RegionsA1); HOperatorSet.GenEmptyObj(out ho_RegionOpeningA); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA1); HOperatorSet.GenEmptyObj(out ho_RegionUnionA); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsA2); HOperatorSet.GenEmptyObj(out ho_RegionsB); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsB); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsB); HOperatorSet.GenEmptyObj(out ho_RectangleB1); HOperatorSet.GenEmptyObj(out ho_RectangleB2); HOperatorSet.GenEmptyObj(out ho_RegionDifferenceB); HOperatorSet.GenEmptyObj(out ho_ImageReducedB1); HOperatorSet.GenEmptyObj(out ho_RegionB1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsB2); HOperatorSet.GenEmptyObj(out ho_SelectedRegionsB2); HOperatorSet.GenEmptyObj(out ho_outContours); HOperatorSet.GenEmptyObj(out ho_SelectedContours); HOperatorSet.GenEmptyObj(out ho_SortedContours); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions4); HOperatorSet.GenEmptyObj(out ho_SelectedRegions5); HOperatorSet.GenEmptyObj(out ho_SelectedRegions6); HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_SortedContours3); HOperatorSet.GenEmptyObj(out ho_obj); HOperatorSet.GenEmptyObj(out ho_objj); HOperatorSet.GenEmptyObj(out ho_ContoursSplit); HOperatorSet.GenEmptyObj(out ho_SelectedXLD); HOperatorSet.GenEmptyObj(out ho_SortedContours1); HOperatorSet.GenEmptyObj(out ho_M); HOperatorSet.GenEmptyObj(out ho_Contour); HOperatorSet.GenEmptyObj(out ho_SelectedXLD1); HOperatorSet.GenEmptyObj(out ho_SortedContours2); HOperatorSet.GenEmptyObj(out ho_ObjectSelectedB); ho_Image.Dispose(); if (!this.index) { HOperatorSet.ReadImage(out ho_Image, "test.bmp"); } else { HOperatorSet.ReadImage(out ho_Image, "PersonImg\\xiaosy.png"); } //*******************************************第一组预处理*********************************************** ho_ImageRotate.Dispose(); HOperatorSet.RotateImage(ho_Image, out ho_ImageRotate, 45, "constant"); ho_GrayImage.Dispose(); HOperatorSet.Rgb1ToGray(ho_ImageRotate, out ho_GrayImage); ho_ImageMedian.Dispose(); HOperatorSet.MedianImage(ho_GrayImage, out ho_ImageMedian, "circle", 3, "mirrored"); ho_Region.Dispose(); HOperatorSet.Threshold(ho_GrayImage, out ho_Region, 200, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", 150, 99999); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions, out ho_SelectedRegions2, "circularity", "and", 0.37, 0.7); ho_SelectedRegions1.Dispose(); HOperatorSet.ClosingRectangle1(ho_SelectedRegions2, out ho_SelectedRegions1, 5, 5); ho_SelectedRegions3.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions1, out ho_SelectedRegions3, "holes_num", "and", 1, 99); ho_SortedRegions.Dispose(); HOperatorSet.SortRegion(ho_SelectedRegions3, out ho_SortedRegions, "first_point", "true", "column"); HOperatorSet.CountObj(ho_SelectedRegions3, out hv_NumberB); ho_RegionUnion.Dispose(); HOperatorSet.Union1(ho_SelectedRegions3, out ho_RegionUnion); HOperatorSet.SmallestRectangle2(ho_RegionUnion, out hv_Row1, out hv_Column1, out hv_Phi, out hv_Length1, out hv_Length2); ho_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row1, hv_Column1, hv_Phi, hv_Length1, hv_Length2); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_GrayImage, ho_Rectangle, out ho_ImageReduced); //*******************************************第二组预处理*********************************************** ho_GrayImageA.Dispose(); HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImageA); ho_GragImageA.Dispose(); HOperatorSet.GrayDilationRect(ho_GrayImageA, out ho_GragImageA, 4, 4); ho_RegionsA_temp.Dispose(); HOperatorSet.Threshold(ho_GrayImageA, out ho_RegionsA_temp, 116, 218); ho_ConnectedRegionsA_temp.Dispose(); HOperatorSet.Connection(ho_RegionsA_temp, out ho_ConnectedRegionsA_temp); ho_SelectedRegionsA_temp.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA_temp, out ho_SelectedRegionsA_temp, "area", "and", 108357, 495042); HOperatorSet.OrientationRegion(ho_SelectedRegionsA_temp, out hv_Phi_temp); HOperatorSet.AreaCenter(ho_SelectedRegionsA_temp, out hv_Area_temp, out hv_Row_temp, out hv_Column_temp); HOperatorSet.VectorAngleToRigid(hv_Row_temp, hv_Column_temp, hv_Phi_temp, hv_Row_temp, hv_Column_temp, (new HTuple(0)).TupleRad(), out hv_HomMat2D); ho_ImageAffineTrans.Dispose(); HOperatorSet.AffineTransImage(ho_GrayImageA, out ho_ImageAffineTrans, hv_HomMat2D, "constant", "false"); ho_RegionsA.Dispose(); HOperatorSet.Threshold(ho_ImageAffineTrans, out ho_RegionsA, 116, 218); ho_RegionDilationA.Dispose(); HOperatorSet.DilationRectangle1(ho_RegionsA, out ho_RegionDilationA, 2, 2); ho_ConnectedRegionsA.Dispose(); HOperatorSet.Connection(ho_RegionDilationA, out ho_ConnectedRegionsA); ho_SelectedRegionsA.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA, out ho_SelectedRegionsA, "circularity", "and", 0.001, 0.03); ho_RegionsA1.Dispose(); HOperatorSet.Threshold(ho_GrayImageA, out ho_RegionsA1, 227, 255); ho_RegionOpeningA.Dispose(); HOperatorSet.OpeningCircle(ho_RegionsA1, out ho_RegionOpeningA, 5.5); ho_ConnectedRegionsA.Dispose(); HOperatorSet.Connection(ho_RegionOpeningA, out ho_ConnectedRegionsA); ho_SelectedRegionsA1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA, out ho_SelectedRegionsA1, "row", "and", 513.2, 601.23); ho_RegionUnionA.Dispose(); HOperatorSet.Union1(ho_SelectedRegionsA1, out ho_RegionUnionA); HOperatorSet.SmallestRectangle1(ho_RegionUnionA, out hv_RowA1, out hv_ColumnA1, out hv_RowA2, out hv_ColumnA2); ho_SelectedRegionsA2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsA, out ho_SelectedRegionsA2, "width", "and", 92.694, 100); HOperatorSet.InnerRectangle1(ho_SelectedRegionsA2, out hv_RowA3, out hv_ColumnA3, out hv_RowA4, out hv_ColumnA4); ho_ConnectedRegionsA.Dispose(); HOperatorSet.Connection(ho_RegionsA1, out ho_ConnectedRegionsA); //*******************************************第三组预处理********************************************* ho_RegionsB.Dispose(); HOperatorSet.Threshold(ho_Image, out ho_RegionsB, 131, 153); ho_ConnectedRegionsB.Dispose(); HOperatorSet.Connection(ho_RegionsB, out ho_ConnectedRegionsB); ho_SelectedRegionsB.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegionsB, out ho_SelectedRegionsB, "max_area", 70); HOperatorSet.SmallestRectangle2(ho_SelectedRegionsB, out hv_RowB16, out hv_ColumnB16, out hv_PhiB3, out hv_LengthB1, out hv_LengthB2); ho_RectangleB1.Dispose(); HOperatorSet.GenRectangle2(out ho_RectangleB1, hv_RowB16 - 5, hv_ColumnB16, hv_PhiB3, hv_LengthB1 - 5, hv_LengthB2 - 5); ho_RectangleB2.Dispose(); HOperatorSet.GenRectangle2(out ho_RectangleB2, hv_RowB16 - 3, hv_ColumnB16, hv_PhiB3, hv_LengthB1 - 5, hv_LengthB2 - 18); ho_RegionDifferenceB.Dispose(); HOperatorSet.Difference(ho_RectangleB1, ho_RectangleB2, out ho_RegionDifferenceB ); ho_ImageReducedB1.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_RegionDifferenceB, out ho_ImageReducedB1 ); ho_RegionB1.Dispose(); HOperatorSet.Threshold(ho_ImageReducedB1, out ho_RegionB1, 200, 255); ho_ConnectedRegionsB2.Dispose(); HOperatorSet.Connection(ho_RegionB1, out ho_ConnectedRegionsB2); ho_SelectedRegionsB2.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegionsB2, out ho_SelectedRegionsB2, "area", "and", 26.01, 200); HOperatorSet.AreaCenter(ho_SelectedRegionsB2, out hv_AreaB, out hv_RowB2, out hv_ColumnB2); //*****************************************花瓣ABC************************************************** //边缘轮廓检测 ho_outContours.Dispose(); HOperatorSet.GenContourRegionXld(ho_SelectedRegions3, out ho_outContours, "border"); ho_SelectedContours.Dispose(); HOperatorSet.SelectContoursXld(ho_outContours, out ho_SelectedContours, "contour_length", 60, 600, -0.5, 0.5); ho_SortedContours.Dispose(); HOperatorSet.SortContoursXld(ho_SelectedContours, out ho_SortedContours, "upper_left", "true", "column"); HOperatorSet.CountObj(ho_SortedContours, out hv_Number); //中心轮廓检测 ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, 0, 135); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions1); ho_SelectedRegions4.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions4, "area", "and", 230, 600); ho_SelectedRegions5.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions4, out ho_SelectedRegions5, "ratio", "and", 0.7, 1.352); ho_SelectedRegions6.Dispose(); HOperatorSet.SelectShape(ho_SelectedRegions5, out ho_SelectedRegions6, "circularity", "and", 0.2, 1); ho_Contours.Dispose(); HOperatorSet.GenContourRegionXld(ho_SelectedRegions6, out ho_Contours, "border"); ho_SortedContours3.Dispose(); HOperatorSet.SortContoursXld(ho_Contours, out ho_SortedContours3, "upper_left", "true", "row"); HOperatorSet.CountObj(ho_SortedContours3, out hv_Number3); if ((int)(new HTuple((((hv_Number + hv_Number3) % 2)).TupleEqual(1))) != 0) { //这里需要在C#输出无法检测的信息 HDevelopStop(); } //里面的轮廓 A1左上到右下 A2左下到右上 hv_A1 = new HTuple(); hv_A2 = new HTuple(); //外面的轮廓 B1垂直方向 B2水平方向 hv_B1 = new HTuple(); hv_B2 = new HTuple(); //c1到c4顺时针顺序的四个花瓣长度 hv_C1 = new HTuple(); hv_C2 = new HTuple(); hv_C3 = new HTuple(); hv_C4 = new HTuple(); //B的检测 HTuple end_val103 = hv_Number; HTuple step_val103 = 1; for (hv_i = 1; hv_i.Continue(end_val103, step_val103); hv_i = hv_i.TupleAdd(step_val103)) { ho_obj.Dispose(); HOperatorSet.SelectObj(ho_SortedContours, out ho_obj, hv_i); HOperatorSet.GetContourXld(ho_obj, out hv_Ro1, out hv_Co1); HOperatorSet.TupleMin(hv_Ro1, out hv_MinBR); HOperatorSet.TupleMax(hv_Ro1, out hv_MaxBR); HOperatorSet.TupleMin(hv_Co1, out hv_MinBC); HOperatorSet.TupleMax(hv_Co1, out hv_MaxBC); hv_BR = hv_MaxBR - hv_MinBR; hv_BC = hv_MaxBC - hv_MinBC; hv_B1 = hv_B1.TupleConcat(hv_BR); hv_B2 = hv_B2.TupleConcat(hv_BC); //A的检测 HTuple end_val118 = hv_Number3; HTuple step_val118 = 1; for (hv_j = 1; hv_j.Continue(end_val118, step_val118); hv_j = hv_j.TupleAdd(step_val118)) { if ((int)(new HTuple(hv_i.TupleEqual(hv_j))) != 0) { ho_objj.Dispose(); HOperatorSet.SelectObj(ho_SortedContours3, out ho_objj, hv_j); //C的检测 ho_ContoursSplit.Dispose(); HOperatorSet.SegmentContoursXld(ho_objj, out ho_ContoursSplit, "lines", 5, 4, 2); ho_SelectedXLD.Dispose(); HOperatorSet.SelectShapeXld(ho_ContoursSplit, out ho_SelectedXLD, "width", "and", 13, 99); ho_SortedContours1.Dispose(); HOperatorSet.SortContoursXld(ho_SelectedXLD, out ho_SortedContours1, "upper_left", "true", "row"); HOperatorSet.CountObj(ho_SortedContours1, out hv_Number1); HTuple end_val130 = hv_Number1; HTuple step_val130 = 1; for (hv_a = 1; hv_a.Continue(end_val130, step_val130); hv_a = hv_a.TupleAdd(step_val130)) { ho_M.Dispose(); HOperatorSet.SelectObj(ho_SortedContours1, out ho_M, hv_a); if ((int)(new HTuple(hv_a.TupleEqual(1))) != 0) { HOperatorSet.GetContourXld(ho_M, out hv_Ro2, out hv_Co2); HOperatorSet.TupleMin(hv_Co2, out hv_LUC); HOperatorSet.TupleMax(hv_Co2, out hv_RUC); } else { HOperatorSet.GetContourXld(ho_M, out hv_Ro3, out hv_Co3); HOperatorSet.TupleMin(hv_Co3, out hv_LDC); HOperatorSet.TupleMax(hv_Co3, out hv_RDC); } HOperatorSet.FitLineContourXld(ho_M, "huber", -1, 0, 5, 2, out hv_RowBegin, out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc, out hv_Dist); ho_Contour.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowBegin.TupleConcat( hv_RowEnd), hv_ColBegin.TupleConcat(hv_ColEnd)); HOperatorSet.GetContourXld(ho_Contour, out hv_Rowc, out hv_Colc); HOperatorSet.TupleMean(hv_Rowc, out hv_MeanR); if ((int)(new HTuple(hv_a.TupleEqual(1))) != 0) { hv_H1 = hv_MeanR - hv_MinBR; hv_C1 = hv_C1.TupleConcat(hv_H1); } else { hv_H3 = hv_MaxBR - hv_MeanR; hv_C3 = hv_C3.TupleConcat(hv_H3); } } ho_SelectedXLD1.Dispose(); HOperatorSet.SelectShapeXld(ho_ContoursSplit, out ho_SelectedXLD1, "height", "and", 13, 99); ho_SortedContours2.Dispose(); HOperatorSet.SortContoursXld(ho_SelectedXLD1, out ho_SortedContours2, "upper_left", "true", "column"); HOperatorSet.CountObj(ho_SortedContours2, out hv_Number2); HTuple end_val157 = hv_Number2; HTuple step_val157 = 1; for (hv_b = 1; hv_b.Continue(end_val157, step_val157); hv_b = hv_b.TupleAdd(step_val157)) { ho_M.Dispose(); HOperatorSet.SelectObj(ho_SortedContours2, out ho_M, hv_b); if ((int)(new HTuple(hv_b.TupleEqual(1))) != 0) { HOperatorSet.GetContourXld(ho_M, out hv_Ro4, out hv_Co4); HOperatorSet.TupleMin(hv_Ro4, out hv_LUR); HOperatorSet.TupleMax(hv_Ro4, out hv_LDR); } else { HOperatorSet.GetContourXld(ho_M, out hv_Ro5, out hv_Co5); HOperatorSet.TupleMin(hv_Ro5, out hv_RUR); HOperatorSet.TupleMax(hv_Ro5, out hv_RDR); } HOperatorSet.FitLineContourXld(ho_M, "huber", -1, 0, 5, 2, out hv_RowBegin, out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc, out hv_Dist); ho_Contour.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowBegin.TupleConcat( hv_RowEnd), hv_ColBegin.TupleConcat(hv_ColEnd)); HOperatorSet.GetContourXld(ho_Contour, out hv_Rowc, out hv_Colc); HOperatorSet.TupleMean(hv_Colc, out hv_MeanC); if ((int)(new HTuple(hv_b.TupleEqual(1))) != 0) { hv_H4 = hv_MeanC - hv_MinBC; hv_C4 = hv_C4.TupleConcat(hv_H4); } else { hv_H2 = hv_MaxBC - hv_MeanC; hv_C2 = hv_C2.TupleConcat(hv_H2); } } HOperatorSet.DistancePp(hv_LUC, hv_LUR, hv_RDC, hv_RDR, out hv_Distance1); HOperatorSet.DistancePp(hv_RUC, hv_RUR, hv_LDC, hv_LDR, out hv_Distance2); hv_A1 = hv_A1.TupleConcat(hv_Distance1); hv_A2 = hv_A2.TupleConcat(hv_Distance2); } } } //*********************************倾斜角度 跑针位 k******************************************* HOperatorSet.AreaCenter(ho_SelectedRegionsA, out hv_AreaA, out hv_RowA, out hv_ColumnA); HOperatorSet.OrientationRegion(ho_SelectedRegionsA, out hv_Phi); hv_Phi = hv_Phi.TupleDeg(); hv_phi = ((90 - (hv_Phi.TupleAbs()))).TupleAbs(); hv_paozhengwei = (hv_RowA3 - ((hv_RowA2 / 2) + (hv_RowA1 / 2))) - 4; hv_k = (hv_RowA2 - hv_RowA1) + 4; //***************************************裂箔**************************************************** HOperatorSet.TupleSortIndex(hv_AreaB, out hv_Indices); hv_liebo = new HTuple(); hv_NumB = new HTuple(hv_Indices.TupleLength()); hv_count = 0; if ((int)(new HTuple(hv_NumB.TupleGreater(0))) != 0) { HTuple end_val208 = hv_NumB; HTuple step_val208 = 1; for (hv_I = 1; hv_I.Continue(end_val208, step_val208); hv_I = hv_I.TupleAdd(step_val208)) { ho_ObjectSelectedB.Dispose(); HOperatorSet.SelectObj(ho_SelectedRegionsB2, out ho_ObjectSelectedB, hv_I); HOperatorSet.AreaCenter(ho_ObjectSelectedB, out hv_AreaB1, out hv_RowB3, out hv_ColumnB3); if ((int)(new HTuple(hv_AreaB1.TupleGreater(30))) != 0) { hv_count = hv_count + 1; } else { } } } else { } if (hv_liebo == null) { hv_liebo = new HTuple(); } hv_liebo[0] = hv_count; HTuple result = new HTuple(); result.Append(hv_A1[0]); result.Append(hv_A2[0]); result.Append(hv_B1[0]); result.Append(hv_B2[0]); result.Append(hv_C1[0]); result.Append(hv_C2[0]); result.Append(hv_C3[0]); result.Append(hv_C4[0]); result.Append(hv_phi[0]); result.Append(hv_paozhengwei[0]); result.Append(hv_liebo[0]); //************************************************************************************************** ho_Image.Dispose(); ho_ImageRotate.Dispose(); ho_GrayImage.Dispose(); ho_ImageMedian.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_SelectedRegions2.Dispose(); ho_SelectedRegions1.Dispose(); ho_SelectedRegions3.Dispose(); ho_SortedRegions.Dispose(); ho_RegionUnion.Dispose(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_GrayImageA.Dispose(); ho_GragImageA.Dispose(); ho_RegionsA_temp.Dispose(); ho_ConnectedRegionsA_temp.Dispose(); ho_SelectedRegionsA_temp.Dispose(); ho_ImageAffineTrans.Dispose(); ho_RegionsA.Dispose(); ho_RegionDilationA.Dispose(); ho_ConnectedRegionsA.Dispose(); ho_SelectedRegionsA.Dispose(); ho_RegionsA1.Dispose(); ho_RegionOpeningA.Dispose(); ho_SelectedRegionsA1.Dispose(); ho_RegionUnionA.Dispose(); ho_SelectedRegionsA2.Dispose(); ho_RegionsB.Dispose(); ho_ConnectedRegionsB.Dispose(); ho_SelectedRegionsB.Dispose(); ho_RectangleB1.Dispose(); ho_RectangleB2.Dispose(); ho_RegionDifferenceB.Dispose(); ho_ImageReducedB1.Dispose(); ho_RegionB1.Dispose(); ho_ConnectedRegionsB2.Dispose(); ho_SelectedRegionsB2.Dispose(); ho_outContours.Dispose(); ho_SelectedContours.Dispose(); ho_SortedContours.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions4.Dispose(); ho_SelectedRegions5.Dispose(); ho_SelectedRegions6.Dispose(); ho_Contours.Dispose(); ho_SortedContours3.Dispose(); ho_obj.Dispose(); ho_objj.Dispose(); ho_ContoursSplit.Dispose(); ho_SelectedXLD.Dispose(); ho_SortedContours1.Dispose(); ho_M.Dispose(); ho_Contour.Dispose(); ho_SelectedXLD1.Dispose(); ho_SortedContours2.Dispose(); ho_ObjectSelectedB.Dispose(); return(result); }
/// <summary> /// The section of the user process. /// 用户自定义流程函数。 /// /// Please write your process in the following method. /// 请在以下函数中定义您的工艺流程。 /// /// </summary> /// <param name="Service"></param> /// <returns></returns> static void BenchMarkSet(SystemServiceClient Service, CamRemoteAccessContractClient Camera = null) { string message = ""; double pdX = 0, pdY = 0, pdAngle = 0; double offsetX, offsetY, offsetAngle; Camera.SetExposure("AWG", 30000); Camera.SetExposure("Left", 16000); try { if (!Directory.Exists(programDataFile)) { Directory.CreateDirectory(programDataFile); } if (!File.Exists(programDataFile + "\\calibratedata.tup")) { throw new Exception("cannot find the calibratedata file"); } if (!File.Exists(programDataFile + "\\Model")) { throw new Exception("cannot find the model file"); } HOperatorSet.ReadTuple(programDataFile + "\\calibratedata.tup", out calibratedata); HOperatorSet.ReadShapeModel(programDataFile + "\\Model", out HTuple model); PointInfo pdOriginAngle = new PointInfo(); pdOriginAngle.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "R")); pdOriginAngle.Aliger = Aliger; pdOriginAngle.PointName = "pd初始角度"; pdOriginAngle.Save(programDataFile, "pd初始角度.json"); PointInfo awgCouplingLower = new PointInfo(); awgCouplingLower.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "Z", 20)); awgCouplingLower.Aliger = Aliger; awgCouplingLower.PointName = "Awg耦合低位"; awgCouplingLower.Save(programDataFile, "Awg耦合低位.json"); Service.__SSC_MoveAxis(Aliger, "Z", SSC_MoveMode.REL, 100, -500); PointInfo awgCouplingHigher = new PointInfo(); awgCouplingHigher.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "X")); awgCouplingHigher.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "Y")); awgCouplingHigher.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "Z", 100, 2)); awgCouplingHigher.Aliger = Aliger; awgCouplingHigher.PointName = "Awg耦合高位"; awgCouplingHigher.Save(programDataFile, "Awg耦合高位.json"); #region pd初始位置获取并保存 Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "pd拍照位置"); var image2 = Camera.GrabOneFrame("Left"); HObject pdImage; visionFun.Bitmap2HObjectBpp32(image2, out pdImage); GetPdOriginPosition(pdImage, out double pdx, out double pdy, out double pdangle, out Bitmap pdresultImage); Service.__SSC_ShowImage(pdresultImage); HTuple PdOrigin = new HTuple(); PdOrigin.Append(pdx); PdOrigin.Append(pdy); PdOrigin.Append(pdangle); HOperatorSet.WriteTuple(PdOrigin, programDataFile + "\\PdOrigin.tup"); #endregion #region awg初始位置获取并保存 Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "awg拍照位置"); Thread.Sleep(100); var image1 = Camera.GrabOneFrame("AWG"); HObject awgImage; visionFun.Bitmap2HObjectBpp32(image1, out awgImage); GetAwgOriginPosition(awgImage, out double awgX, out double awgY, out double awgAngle, out Bitmap awgimage); Service.__SSC_ShowImage(awgimage); HTuple AwgOrigin = new HTuple(); AwgOrigin.Append(awgX); AwgOrigin.Append(awgY); AwgOrigin.Append(awgAngle); HOperatorSet.WriteTuple(AwgOrigin, programDataFile + "\\AwgOrigin.tup"); #endregion } catch (Exception ex) { Service.__SSC_LogError(ex.Message); } System.Threading.Thread.Sleep(100); }
private static bool DepthFromFocusProc(HImage image, string imgSaveFolder, string imgSaveName) { bool ret = false; try { HObject ho_img1 = new HObject(); HObject ho_img2 = new HObject(); HObject ho_img3 = new HObject(); HOperatorSet.Decompose3(image, out ho_img1, out ho_img2, out ho_img3); HTuple filter = new HTuple("highpass"); filter.Append(7); filter.Append(7); HTuple selection = new HTuple("next_maximum"); HOperatorSet.ChannelsToImage(ho_img1, out ho_img1); HObject ho_Depth1 = new HObject(); HObject ho_Confidence1 = new HObject(); HOperatorSet.DepthFromFocus(ho_img1, out ho_Depth1, out ho_Confidence1, filter, selection); //Construct sharp image HObject ho_DepthHighConf1 = new HObject(); HOperatorSet.MeanImage(ho_Depth1, out ho_DepthHighConf1, 11, 11); HObject ho_SharpImage1 = new HObject(); HOperatorSet.SelectGrayvaluesFromChannels(ho_img1, ho_DepthHighConf1, out ho_SharpImage1); //Smooth depth map //HObject ho_ImageScaleMax1 = new HObject(); //HOperatorSet.ScaleImageMax(ho_DepthHighConf1, out ho_ImageScaleMax1); //HObject ho_DepthMean1 = new HObject(); //HOperatorSet.MeanImage(ho_ImageScaleMax1, out ho_DepthMean1, 51, 51); //HOperatorSet.WriteImage(ho_SharpImage1, "bmp", 0, imgSaveFolder + "\\SharpImage1.bmp"); HOperatorSet.ChannelsToImage(ho_img2, out ho_img2); HObject ho_Depth2 = new HObject(); HObject ho_Confidence2 = new HObject(); HOperatorSet.DepthFromFocus(ho_img2, out ho_Depth2, out ho_Confidence2, filter, selection); //Construct sharp image HObject ho_DepthHighConf2 = new HObject(); HOperatorSet.MeanImage(ho_Depth2, out ho_DepthHighConf2, 11, 11); HObject ho_SharpImage2 = new HObject(); HOperatorSet.SelectGrayvaluesFromChannels(ho_img2, ho_DepthHighConf2, out ho_SharpImage2); //Smooth depth map //HObject ho_ImageScaleMax2 = new HObject(); //HOperatorSet.ScaleImageMax(ho_DepthHighConf2, out ho_ImageScaleMax2); //HObject ho_DepthMean2 = new HObject(); //HOperatorSet.MeanImage(ho_ImageScaleMax2, out ho_DepthMean2, 51, 51); //HOperatorSet.WriteImage(ho_SharpImage2, "bmp", 0, imgSaveFolder + "\\SharpImage2.bmp"); HOperatorSet.ChannelsToImage(ho_img3, out ho_img3); HObject ho_Depth3 = new HObject(); HObject ho_Confidence3 = new HObject(); HOperatorSet.DepthFromFocus(ho_img3, out ho_Depth3, out ho_Confidence3, filter, selection); //Construct sharp image HObject ho_DepthHighConf3 = new HObject(); HOperatorSet.MeanImage(ho_Depth3, out ho_DepthHighConf3, 11, 11); HObject ho_SharpImage3 = new HObject(); HOperatorSet.SelectGrayvaluesFromChannels(ho_img3, ho_DepthHighConf3, out ho_SharpImage3); //Smooth depth map //HObject ho_ImageScaleMax3 = new HObject(); //HOperatorSet.ScaleImageMax(ho_DepthHighConf3, out ho_ImageScaleMax3); //HObject ho_DepthMean3 = new HObject(); //HOperatorSet.MeanImage(ho_ImageScaleMax3, out ho_DepthMean3, 51, 51); //HOperatorSet.WriteImage(ho_SharpImage3, "bmp", 0, imgSaveFolder + "\\SharpImage3.bmp"); HObject ho_SharpImage = new HObject(); HOperatorSet.Compose3(ho_SharpImage1, ho_SharpImage2, ho_SharpImage3, out ho_SharpImage); HOperatorSet.WriteImage(ho_SharpImage, "bmp", 0, imgSaveFolder + "\\" + imgSaveName); ho_SharpImage.Dispose(); ret = true; } catch (HalconException hex) { Trace.WriteLine(hex.GetErrorMessage(), "HALCON error"); } return(ret); }
public bool FindCircle(HObject img) { HTuple Row = new HTuple(); HTuple Col = new HTuple(); HTuple Distance = new HTuple(); HTuple outRow = new HTuple(); HTuple outCol = new HTuple(); HTuple outAmp = new HTuple(); HTuple outDistance = new HTuple(); HRegion regionCount = new HRegion(); regionCount.GenEmptyRegion(); HXLDCont contour = new HXLDCont(); if (img == null) { return(false); } HTuple imgWidth, imgHeight; HTuple hms = null; HOperatorSet.GetImageSize(img, out imgWidth, out imgHeight); double xCenter, yCenter, Center_radius, angle, angleSplit; angle = 0; //分割角度 angleSplit = 2 * 3.1415926 / (Hnum); xCenter = in_col[0].D + data_col; yCenter = in_row[0].D + data_row; Center_radius = in_radius[0].D; HHomMat2D hom = new HHomMat2D(); hom.HomMat2dIdentity(); hom = hom.HomMat2dRotate(angleSplit, yCenter, xCenter); double rect_row, rect_col, angleStart, L1, L2; //分割矩形的中心坐标 rect_row = yCenter; rect_col = xCenter + Center_radius; L1 = HLengh[0].D / 2; L2 = Hwid[0].D / 2; if (Hdirection != "in2out") { //由外向内 angleStart = angle + (new HTuple(180)).TupleRad(); } else { angleStart = angle; } for (int i = 0; i < Hnum[0].I; ++i) { if (m_bShowRectang2) { contour.Dispose(); contour.GenRectangle2ContourXld(rect_row, rect_col, angleStart + angleSplit * i, L1, L2); HRegion region; region = contour.GenRegionContourXld("margin"); regionCount = regionCount.Union2(region); region.Dispose(); } try {//out_row, out_col, out_radius; HOperatorSet.GenMeasureRectangle2(rect_row, rect_col, angleStart + angleSplit * i, L1, L2, imgWidth, imgHeight, "nearest_neighbor", out hms); HOperatorSet.MeasurePos(img, hms, Hsomth, Hamp, Htransition, Hselect, out outRow, out outCol, out outAmp, out outDistance); } catch { continue; } if (Hselect == "all" && outRow.Length > 1) { HTuple hIndex = outAmp.TupleSortIndex(); int nMax = hIndex[hIndex.Length - 1]; Row.Append(outRow[nMax]); Col.Append(outCol[nMax]); } else { Row.Append(outRow); Col.Append(outCol); } hom.AffineTransPixel(rect_row, rect_col, out rect_row, out rect_col); } HOperatorSet.CloseMeasure(hms); if (m_bShowRectang2) { m_hRectang2.Dispose(); m_hRectang2 = regionCount.GenContoursSkeletonXld(1, "filter"); } if (Row.Length > Hnum[0].D / 3) { HXLDCont counter = new HXLDCont(); counter.GenContourPolygonXld(Row, Col); HTuple startphi, endphi; HTuple pointorder; counter.FitCircleContourXld("atukey", -1, 0, 0, 3, 2, out out_row, out out_col, out out_radius, out startphi, out endphi, out pointorder); HTuple rowDrop = new HTuple(); HTuple colDrop = new HTuple(); if (Row.Length - 5 > m_nNumDropPoints && m_nNumDropPoints > 0) { HTuple distance = new HTuple(); for (int i = 0; i < Row.Length; ++i) { double dis = HMisc.DistancePp(Row[i], Col[i], xCenter, yCenter); distance.Append(Math.Abs(dis - Center_radius)); } HTuple index = distance.TupleSortIndex(); index = index.TupleInverse(); for (int i = 0; i < m_nNumDropPoints; ++i) { int n = index[i]; rowDrop.Append(Row[n]); colDrop.Append(Col[n]); } index = index.TupleFirstN(m_nNumDropPoints - 1); Row = Row.TupleRemove(index); Col = Col.TupleRemove(index); counter.GenContourPolygonXld(Row, Col); counter.FitCircleContourXld("atukey", -1, 0, 0, 3, 2, out out_row, out out_col, out out_radius, out startphi, out endphi, out pointorder); } m_hCircle.Dispose(); m_centerCross.Dispose(); if (m_bShowCircle) { HOperatorSet.GenCrossContourXld(out m_centerCross, out_row, out_col, (out_radius / 2) + 1, (new HTuple(0)).TupleRad()); HOperatorSet.GenCircleContourXld(out m_hCircle, out_row, out_col, out_radius, 0, 3.1415926 * 2, "positive", 1); } m_hCross.Dispose(); if (m_bShowCross) { HOperatorSet.GenCrossContourXld(out m_hCross, Row, Col, 17, (new HTuple(45)).TupleRad()); } Result_Array[0] = out_row; Result_Array[1] = out_col; Result_Array[2] = out_radius; return(true); } return(false); }
public void FindEdge(HObject image, HTuple row, HTuple column, HTuple radian, out HTuple edgeRow1, out HTuple edgeColumn1, out HTuple edgeRow2, out HTuple edgeColumn2) { HTuple homMat2D, rowTrans, columnTrans; //测量外边缘 edgeRow1 = 0; edgeColumn1 = 0; edgeRow2 = 0; edgeColumn2 = 0; /* * // Local iconic variables * * //HObject ho_Image, ho_ImageEmphasize, ho_ROI_0; * //HObject ho_ImageReduced, ho_ImageScaled, ho_Regions, ho_Connection; * //HObject ho_RegionOpening, ho_RegionClosing, ho_ObjectSelected; * //HObject ho_RegionTrans, ho_ImageMean, ho_ImageResult; * * // Local control variables * * HTuple hv_Area = null, hv_Row = null, hv_Column = null; * HTuple hv_Indices = null, hv_Inverted = null; * * HOperatorSet.ScaleImage(image, out ho_ImageScaled, 4.25, -425); * HOperatorSet.Threshold(ho_ImageScaled, out ho_Regions, 100, 255); * HOperatorSet.OpeningCircle(ho_Regions, out ho_RegionOpening, 3.5); * HOperatorSet.ClosingCircle(ho_RegionOpening, out ho_RegionClosing, 19.5); * HOperatorSet.Connection(ho_RegionClosing, out ho_Connection); * HOperatorSet.AreaCenter(ho_Connection, out hv_Area, out hv_Row, out hv_Column); * HOperatorSet.TupleSortIndex(hv_Area, out hv_Indices); * HOperatorSet.TupleInverse(hv_Indices, out hv_Inverted); * HOperatorSet.SelectObj(ho_Connection, out ho_ObjectSelected, (hv_Inverted.TupleSelect(0)) + 1); * HOperatorSet.ShapeTrans(ho_ObjectSelected, out ho_RegionTrans, "rectangle2"); * HOperatorSet.MeanImage(ho_ImageScaled, out ho_ImageMean, 15, 15); * HOperatorSet.PaintRegion(ho_RegionTrans, ho_ImageMean, out ho_ImageResult, 255, "fill"); */ HOperatorSet.GenMeasureRectangle2(row + DisHanldeRow, column /*+ DisHanldeColumn*/, Radian + Math.PI / 2, 20, 40, ImageWidth, ImageHeight, Interpolation, out HandleLine); for (int i = 0; i <= 5; i++) { //设置幅度值 HTuple threshold = Threshold - 10 - i * 2; if (threshold < 1) { threshold = 1; } HTuple rows = new HTuple(); HTuple columns = new HTuple(); for (int j = 0; j < PinCount; j++) { HTuple rowEdge, columnEdge, amplitude, distance; //变换检测位置 //HTuple homMat2D, rowTrans, columnTrans; HOperatorSet.HomMat2dIdentity(out homMat2D); HOperatorSet.HomMat2dTranslate(homMat2D, DisHanldeRow, j * PinDistance, out homMat2D); HOperatorSet.HomMat2dRotate(homMat2D, radian, row, column, out homMat2D); HOperatorSet.AffineTransPixel(homMat2D, row, column, out rowTrans, out columnTrans); HOperatorSet.TranslateMeasure(HandleLine, rowTrans, columnTrans); HOperatorSet.MeasurePos(image, HandleLine, Sigma, threshold, "negative", "first", out rowEdge, out columnEdge, out amplitude, out distance); //HOperatorSet.MeasurePos(ho_ImageResult, HandleLine, Sigma, threshold, "positive", "first", // out rowEdge, out columnEdge, out amplitude, out distance); if (rowEdge.Length > 0) { rows.Append(rowEdge); columns.Append(columnEdge); } } if (rows.Length >= PinCount / 2) { //生成轮廓 HObject contour; HTuple nr, nc, dist; HOperatorSet.GenContourPolygonXld(out contour, rows, columns); //拟合 HOperatorSet.FitLineContourXld(contour, "tukey", -1, 0, 5, 2, out edgeRow1, out edgeColumn1, out edgeRow2, out edgeColumn2, out nr, out nc, out dist); //生成直线,用于显示 contour?.Dispose(); HOperatorSet.GenContourPolygonXld(out contour, new HTuple(edgeRow1, edgeRow2), new HTuple(edgeColumn1, edgeColumn2)); HOperatorSet.ConcatObj(LineEdge, contour, out LineEdge); break; } } HOperatorSet.CloseMeasure(HandleLine); }
/// <summary> /// 在当前图像上按单元配置查找直线 /// </summary> /// <param name="img"></param> /// <param name="hFixTool"></param> /// <returns></returns> public bool FindLine(HObject img) { m_rowBegin = new HTuple(); m_colBegin = new HTuple(); m_rowEnd = new HTuple(); m_colEnd = new HTuple(); m_hLine.Dispose(); m_hCross.Dispose(); m_hCrossDrop.Dispose(); if (img == null) { return(false); } string strSelect = string.Empty; if (Hselect == "strongest") { strSelect = "all"; } else { strSelect = Hselect; } HTuple imgWidth, imgHeight; HOperatorSet.GetImageSize(img, out imgWidth, out imgHeight); m_imageWidth = imgWidth; m_imageHeight = imgHeight; double x1, y1, x2, y2; HTuple in_phi_t = in_phi + data_from_phi + data_phi * 3.1415926 / 180; double angle = in_phi_t[0].D + 3.1415926 / 2; x1 = (in_col + data_col)[0].D + L2 * Math.Cos(angle); x2 = (in_col + data_col)[0].D - L2 * Math.Cos(angle); y1 = (in_row + data_row)[0].D - L2 * Math.Sin(angle); y2 = (in_row + data_row)[0].D + L2 * Math.Sin(angle); HHomMat2D hom = new HHomMat2D(); hom.HomMat2dIdentity(); hom = hom.HomMat2dTranslate((y2 - y1) / (Hnum - 1), (x2 - x1) / (Hnum - 1)); double rect_row = y1; double rect_col = x1; double rect_phi = in_phi_t[0].D; double rect_len1 = L1; double rect_len2 = (double)Hwid / 2.0; HTuple hms = null; HOperatorSet.GenMeasureRectangle2(rect_row, rect_col, rect_phi, rect_len1, rect_len2, imgWidth, imgHeight, "nearest_neighbor", out hms); HTuple Row = new HTuple(); HTuple Col = new HTuple(); HTuple Distance = new HTuple(); HTuple outRow = new HTuple(); HTuple outCol = new HTuple(); HTuple outAmp = new HTuple(); HTuple outDistance = new HTuple(); HRegion regionCount = new HRegion(); regionCount.GenEmptyRegion(); HXLDCont contour = new HXLDCont(); for (int i = 0; i < Hnum[0].I; ++i) { if (m_bShowRectang2) { contour.Dispose(); contour.GenRectangle2ContourXld(rect_row, rect_col, rect_phi, rect_len1, rect_len2); HRegion region; region = contour.GenRegionContourXld("margin"); regionCount = regionCount.Union2(region); } try { HOperatorSet.MeasurePos(img, hms, Hsomth, Hamp, Htransition, strSelect, out outRow, out outCol, out outAmp, out outDistance); } catch { continue; } if (strSelect == "all" && outRow.Length > 1) { HTuple hIndex = outAmp.TupleSortIndex(); int nMax = hIndex[hIndex.Length - 1]; Row.Append(outRow[nMax]); Col.Append(outCol[nMax]); } else { Row.Append(outRow); Col.Append(outCol); } hom.AffineTransPixel(rect_row, rect_col, out rect_row, out rect_col); HOperatorSet.TranslateMeasure(hms, rect_row, rect_col); } HOperatorSet.CloseMeasure(hms); if (m_bShowRectang2) { m_hRectang2 = regionCount.GenContoursSkeletonXld(1, "filter"); } if (Row.Length > 1) { HXLDCont counter = new HXLDCont(); counter.GenContourPolygonXld(Row, Col); HTuple nr, nc, dist; counter.FitLineContourXld("tukey", -1, 0, 5, 2, out m_rowBegin, out m_colBegin, out m_rowEnd, out m_colEnd, out nr, out nc, out dist); HTuple rowDrop = new HTuple(); HTuple colDrop = new HTuple(); if (Row.Length - 3 > m_nNumDropPoints && m_nNumDropPoints > 0) { HTuple distance = new HTuple(); for (int i = 0; i < Row.Length; ++i) { double dis = HMisc.DistancePl(Row[i], Col[i], m_rowBegin, m_colBegin, m_rowEnd, m_colEnd); distance.Append(dis); } HTuple index = distance.TupleSortIndex(); index = index.TupleInverse(); for (int i = 0; i < m_nNumDropPoints; ++i) { int n = index[i]; rowDrop.Append(Row[n]); colDrop.Append(Col[n]); } index = index.TupleFirstN(m_nNumDropPoints - 1); Row = Row.TupleRemove(index); Col = Col.TupleRemove(index); counter.GenContourPolygonXld(Row, Col); counter.FitLineContourXld("tukey", -1, 0, 5, 2, out m_rowBegin, out m_colBegin, out m_rowEnd, out m_colEnd, out nr, out nc, out dist); } if (m_bShowLine) { HTuple rrow = new HTuple(m_rowBegin); HTuple ccol = new HTuple(m_colBegin); rrow.Append(m_rowEnd); ccol.Append(m_colEnd); m_hLine.GenContourPolygonXld(rrow, ccol); } if (m_bShowCross) { m_hCross.GenEmptyObj(); m_hCross.GenCrossContourXld(Row, Col, 17, (new HTuple(45)).TupleRad()); } if (m_bShowCrossDrop) { m_hCrossDrop.GenEmptyObj(); m_hCrossDrop.GenCrossContourXld(rowDrop, colDrop, 17, (new HTuple(45)).TupleRad()); } Result_Array[0] = m_rowBegin; Result_Array[1] = m_colBegin; Result_Array[2] = m_rowEnd; Result_Array[3] = m_colEnd; return(true); } return(false); }
public bool CalibrationMake(SourceBuffer _sourceBuffer, ExecuteBuffer _executeBuffer, out SourceBuffer outsourcebuffer, out ExecuteBuffer outexecutebuffer, HWndCtrl hWndCtrl, out string result_info) { outsourcebuffer = _sourceBuffer; outexecutebuffer = _executeBuffer; result_info = ""; HTuple hv_PixelSize = 0.00001; HTuple hv_Message = new HTuple(), hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Index = new HTuple(); HTuple hv_Error = null; HObject ho_Contours = null, ho_Cross = null, hv_outimage = null; HTuple hv_HomMat3DIdentity = null; HTuple hv_cp1Hur1 = null, hv_cam2Hcp2 = null, hv_cam2Hul2 = null; HTuple hv_PoseNewOrigin2 = null, hv_ULX = null, hv_ULY = null, hv_PoseNewOrigin = null; double[] Get_actual_pixel = new double[7]; HTuple WorldPixelx, WorldPixely; HTuple Heightx = new HTuple(), Widthx = new HTuple(); Heightx.Append(Height / 2); Heightx.Append(Height / 2); Heightx.Append(Height / 2 + 1); Widthx.Append(Width / 2); Widthx.Append(Width / 2 + 1); Widthx.Append(Width / 2); HTuple WorldLength1, WorldLength2; HTuple ScaleForSimilarPixelSize = 0; HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_Cross); HOperatorSet.GenEmptyObj(out hv_outimage); if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image参数为空或者未赋值"); result_info = " 二值化处理: 输入图像已经不存在,请重置设置输入图像"; return(false); } string comboBox_imageoutname = this.Output_image.Text.ToString() + ".img"; if (_executeBuffer.imageBuffer[comboBox_imageoutname] != null) { if (_executeBuffer.imageBuffer[comboBox_imageoutname].IsInitialized()) { _executeBuffer.imageBuffer[comboBox_imageoutname].Dispose(); } } HTuple width, height; int m = _executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"].CountObj(); HOperatorSet.GetImageSize(_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"], out width, out height); int number = Convert.ToInt32(this.textBox1.Text.ToString()); if (!this.checkBox1.Checked) { if (Get_Cal_pixel) { Get_Cal_pixel = false; } if (number == 0) { hv_StartCamPar = new HTuple(); if (this.checkBox_focalize.Checked) { hv_StartCamPar.Append(0); } else { hv_StartCamPar.Append(Convert.ToDouble(this.textbox_lens.Text.ToString()) / 100); } hv_StartCamPar.Append(0); hv_StartCamPar.Append(Convert.ToDouble(this.textBox_width.Text.ToString()) / 10000000); hv_StartCamPar.Append(Convert.ToDouble(this.textBox_height.Text.ToString()) / 10000000); hv_StartCamPar.Append(width / 2); hv_StartCamPar.Append(height / 2); hv_StartCamPar.Append(width); hv_StartCamPar.Append(height); hv_CalTabDescrFile = this.textBox_file.Text; HOperatorSet.CreateCalibData("calibration_object", 1, 1, out CalibDataID); if (this.checkBox_focalize.Checked) { HOperatorSet.SetCalibDataCamParam(CalibDataID, 0, "area_scan_telecentric_division", hv_StartCamPar); } else { HOperatorSet.SetCalibDataCamParam(CalibDataID, 0, "area_scan_division", hv_StartCamPar); } HOperatorSet.SetCalibDataCalibObject(CalibDataID, 0, hv_CalTabDescrFile); } try { HOperatorSet.FindCalibObject(_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"], CalibDataID, 0, 0, number, new HTuple(), new HTuple()); HOperatorSet.GetCalibData(CalibDataID, "camera", 0, "init_params", out hv_StartCamPar); HOperatorSet.GetCalibDataObservPoints(CalibDataID, 0, 0, number, out hv_Row, out hv_Column, out hv_Index, out hv_Pose); HOperatorSet.GetCalibDataObservContours(out ho_Contours, CalibDataID, "caltab", 0, 0, number); HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row, hv_Column, 6, 0.785398); hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, "orange"); hWndCtrl.addIconicVar(ho_Cross); hWndCtrl.addIconicVar(ho_Contours); hWndCtrl.repaint(); } catch { MessageBox.Show("找不到标定板"); ho_Contours.Dispose(); ho_Cross.Dispose(); return(false); } if (number == hv_NumImages - 1) { Read_file = false; HOperatorSet.CalibrateCameras(CalibDataID, out hv_Error); HOperatorSet.GetCalibData(CalibDataID, "camera", 0, "params", out hv_CamParam); HOperatorSet.GetCalibData(CalibDataID, "calib_obj_pose", (new HTuple(0)).TupleConcat(6), "pose", out hv_Pose); HOperatorSet.HomMat3dIdentity(out hv_HomMat3DIdentity); HOperatorSet.HomMat3dRotateLocal(hv_HomMat3DIdentity, ((-(hv_Pose.TupleSelect(5)))).TupleRad(), "z", out hv_cp1Hur1); HOperatorSet.PoseToHomMat3d(hv_Pose, out hv_cam2Hcp2); HOperatorSet.HomMat3dCompose(hv_cam2Hcp2, hv_cp1Hur1, out hv_cam2Hul2); HOperatorSet.HomMat3dToPose(hv_cam2Hul2, out hv_PoseNewOrigin2); HOperatorSet.ImagePointsToWorldPlane(hv_CamParam, hv_PoseNewOrigin2, 0, 0, "m", out hv_ULX, out hv_ULY); HOperatorSet.SetOriginPose(hv_PoseNewOrigin2, hv_ULX, hv_ULY, 0, out hv_PoseNewOrigin); HOperatorSet.ImagePointsToWorldPlane(hv_CamParam, hv_Pose, Heightx, Widthx, 1, out WorldPixelx, out WorldPixely); HOperatorSet.DistancePp(WorldPixely[0], WorldPixelx[0], WorldPixely[1], WorldPixelx[1], out WorldLength1); HOperatorSet.DistancePp(WorldPixely[0], WorldPixelx[0], WorldPixely[2], WorldPixelx[2], out WorldLength2); ScaleForSimilarPixelSize = (WorldLength1 + WorldLength2) / 2; HOperatorSet.GenImageToWorldPlaneMap(out ho_MapSingle1, hv_CamParam, hv_PoseNewOrigin, width, height, width, height, ScaleForSimilarPixelSize, "bilinear"); HOperatorSet.WriteObject(ho_MapSingle1, this.textBox2.Text.ToString()); Read_file = true; Get_Calibration = true; this.checkBox1.Checked = true; result_info = " 校正参数: 设置完成"; } this.textBox1.Text = (number + 1).ToString(); } if (this.checkBox1.Checked) { if (Read_file) { if (File.Exists(this.textBox2.Text)) { HOperatorSet.ReadObject(out ho_MapSingle1, this.textBox2.Text); } else { MessageBox.Show("校正文件不存在 ,请检查"); return(false); } } HOperatorSet.MapImage(_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"], ho_MapSingle1, out hv_outimage); _executeBuffer.imageBuffer[comboBox_imageoutname] = hv_outimage; outexecutebuffer = _executeBuffer; result_info = " 校正: 完成"; HTuple Distance; if (!Get_Cal_pixel) { try { double all_number = 0; HOperatorSet.FindCalibObject(hv_outimage, CalibDataID, 0, 0, 0, new HTuple(), new HTuple()); HOperatorSet.GetCalibDataObservPoints(CalibDataID, 0, 0, 0, out hv_Row, out hv_Column, out hv_Index, out hv_Pose); for (int i = 0; i < 7; i++) { HOperatorSet.DistancePp(hv_Row[i * 7], hv_Column[i * 7], hv_Row[i * 7 + 6], hv_Column[i * 7 + 6], out Distance); Get_actual_pixel[i] = Distance.D; all_number = all_number + Get_actual_pixel[i]; } Pixel_number = (Convert.ToDouble(this.textBox_pixel.Text)) / (all_number / 7); Get_Cal_pixel = true; this.label_pixel.Text = Pixel_number.ToString(); Pixel_Trans = Convert.ToDouble(Pixel_number.ToString()); } catch { MessageBox.Show("请再次添加图像寻找计算像素比"); } } if (Read_file) { ho_MapSingle1.Dispose(); } } return(true); }
public static void GenDefectRegions(Bitmap bitmap, List <Rectangle> rectangles, double radiusOfDilation, out List <SingleDefectRegion> defectRegions) { defectRegions = new List <SingleDefectRegion>(); HObject ho_image; HObject ho_ConnectedDilations; HTuple hv_Row1OfRectangles = new HTuple(); HTuple hv_Row2OfRectangles = new HTuple(); HTuple hv_Column1OfRectangles = new HTuple(); HTuple hv_Column2OfRectangles = new HTuple(); HTuple hv_RadiusOfDilation = new HTuple(); HTuple hv_IndexOfRectangles = new HTuple(); HTuple hv_NumberListOfRectangles = new HTuple(); // initialation HOperatorSet.GenEmptyObj(out ho_image); ho_image.Dispose(); ImageOperateTools.Bitmap8HObjectBpp8(bitmap, out ho_image); for (int i = 0; i < rectangles.Count; i++) { var rectangle = rectangles[i]; hv_Row1OfRectangles.Append(new HTuple(rectangle.Top)); hv_Row2OfRectangles.Append(new HTuple(rectangle.Bottom)); hv_Column1OfRectangles.Append(new HTuple(rectangle.Left)); hv_Column2OfRectangles.Append(new HTuple(rectangle.Right)); } hv_RadiusOfDilation = radiusOfDilation; dilate_regions_pro(ho_image, out ho_ConnectedDilations, hv_Row1OfRectangles, hv_Row2OfRectangles, hv_Column1OfRectangles, hv_Column2OfRectangles, hv_RadiusOfDilation, out hv_IndexOfRectangles, out hv_NumberListOfRectangles); List <int> defectInfoIndexList = new List <int>(); List <int> defectInfoNumberList = new List <int>(); if (hv_IndexOfRectangles.TupleLength() > 0 && hv_NumberListOfRectangles.TupleLength() > 0) { defectInfoIndexList.AddRange(hv_IndexOfRectangles.ToIArr()); defectInfoNumberList.AddRange(hv_NumberListOfRectangles.ToIArr()); } else { return; } HOperatorSet.CountObj(ho_ConnectedDilations, out var hv_NumberOfDilations); for (var index = 1; index <= hv_NumberOfDilations; ++index) { SingleDefectRegion defectRegion = new SingleDefectRegion(); HOperatorSet.SelectObj(ho_ConnectedDilations, out var ho_Dilation, index); // DefectRegion.DefectInfoIndexList for (var cnt = 0; cnt < defectInfoNumberList[index - 1]; ++cnt) { defectRegion.DefectInfoIndexList.Add(defectInfoIndexList[0]); defectInfoIndexList.RemoveAt(0); } // DefectRegion.Xldxxx convert_single_region_to_points(ho_Dilation, out var hv_posYs, out var hv_posXs, out var hv_pointsNum); if (hv_posYs.TupleLength() > 0) { defectRegion.XldYs.AddRange(hv_posYs.ToDArr()); } if (hv_posXs.TupleLength() > 0) { defectRegion.XldXs.AddRange(hv_posXs.ToDArr()); } if (hv_pointsNum.TupleLength() > 0) { defectRegion.XldPointCount.AddRange(hv_pointsNum.ToIArr()); } // DefectRegion.SmallestRect HOperatorSet.SmallestRectangle1(ho_Dilation, out var hv_Row1, out var hv_Column1, out var hv_Row2, out var hv_Column2); defectRegion.SmallestRect = Rectangle.FromLTRB(hv_Column1.I, hv_Row1.I, hv_Column2.I, hv_Row2.I); defectRegions.Add(defectRegion); } return; }
/// <summary> /// 已测试 /// 软触发拍照下,计算相机的uv->xy坐标系变换的操作,如large相机 /// 要求之前设置好相机/光源/触发至“合理”状态 /// [x] = [ H1 H2 H3 ] [u] /// [y] = [ H4 H5 H6 ] * [v] /// [1] /// </summary> /// <param name="matUV2XY">uv->xy变换矩阵,将2*3的矩阵按照行堆叠的方式存储为1*6的数组, ref传递方式,需要数组有一个初始值</param> /// <param name="cam">相机控制类,注意曝光时间需要设置合适。软触发拍照建议曝光时间在100ms左右</param> /// <param name="modelID">匹配的ncc模板</param> /// <param name="score_thresh">匹配分数,需要大于0.5</param> /// <param name="axisPara">运动轴信息(xy插补),具体包括轴速,加速度</param> /// <param name="initPoint">初始点,中间仅适用了xy信息,需要保证走到初始点时室内内包含完整的,可匹配的model</param> /// <param name="lightInd">软触发拍照对应的光源id,需要事先设置好对应光源合适的时间</param> /// <param name="axisInd">x,y轴号</param> /// <param name="xyRange">计算变换时,以初始点为中心,随机走位的范围,单位mm</param> /// <param name="nPoints">随机走位多少个点</param> /// <param name="lightDelay">软触发拍照光源的延迟,单位us,典型值10us</param> /// <param name="timeOut">单次运动的延迟,单位ms</param> /// <param name="winID">(调试用)显示窗口ID</param> /// <returns>操作是否成功</returns> public bool calibUV2XY ( int camInd, ref HTuple matUV2XY, Model model, double xyRange, int nPoints = 20 ) { //if (model.ReadModel(CalibrUV2XYModelPath) == false) //{ // HTUi.PopError("加载标定模版失败!"); // return false; //} string errMsg = ""; if (_station.operation.MultiAxisMove(_station.AxisXYZ, new double[] { _xUv2xy, _yUv2xy, _zUv2xy }, true, out errMsg) != 0) { HTUi.PopError("无法移动至标定点位置!"); return(false); } Thread.Sleep(200); // App.obj_light.FlashMultiLight(LightUseFor.ScanPoint1st); //if(_station.operation.SWPosTrig(_station.AxisX,out errMsg)!=0) //{ // HTUi.PopError(errMsg); // return false; //} Thread.Sleep(10); if (image != null) { image.Dispose(); } HOperatorSet.GenEmptyObj(out image); if (_station.operation.CaputreOneImage(_station.CamereDev[camInd], "Halcon", out image, out errMsg) != 0) { HTUi.PopError("采集图像失败:" + errMsg); return(false); } //3. match HTuple u, v, angle; bool status = matchModel(camInd, ref image, model, out u, out v, out angle); HObject showRegion = new HObject(); showRegion.Dispose(); HOperatorSet.GenCrossContourXld(out showRegion, u, v, 512, 0); _station._rtUi._fm.ShowImage(_station._rtUi._fm.htWindowCalibration, image, showRegion); //image.Dispose(); if (!status) { HTUi.PopError("获取匹配初始位置图像失败"); return(false); } HTuple xArr = new HTuple(), yArr = new HTuple(), uArr = new HTuple(), vArr = new HTuple(); Random rand = new Random(); //4. for ... snap , match, add <u,v,x,y> for (int i = 0; i < nPoints; i++) { DateTime t1 = DateTime.Now; //大于或等于 0.0 且小于 1.0 的双精度浮点数 double x = (rand.NextDouble() - 0.5) * xyRange + _xUv2xy; double y = (rand.NextDouble() - 0.5) * xyRange + _yUv2xy; if (_station.operation.MultiAxisMove(new string[] { _station.AxisXYZ[0], _station.AxisXYZ[1], }, new double[] { x, y }, true, out errMsg) != 0) { HTUi.PopError("无法移动至标定点位置!"); return(false); } Thread.Sleep(200);; //if (_station.operation.SWPosTrig(_station.AxisX, out errMsg) != 0) //{ // HTUi.PopError(errMsg); // return false; //} Thread.Sleep(10); if (image != null) { image.Dispose(); } HOperatorSet.GenEmptyObj(out image); if (_station.operation.CaputreOneImage(_station.CamereDev[camInd], "Halcon", out image, out errMsg) != 0) { HTUi.PopError("采集图像失败:" + errMsg); return(false); } if (matchModel(camInd, ref image, model, out u, out v, out angle)) //found something { xArr.Append(x); yArr.Append(y); uArr.Append(u); vArr.Append(v); } showRegion.Dispose(); HOperatorSet.GenCrossContourXld(out showRegion, u, v, 512, 0); _station._rtUi._fm.ShowImage(_station._rtUi._fm.htWindowCalibration, image, showRegion); //image.Dispose(); } if (xArr.Length < 10) { HTUi.PopError("有效点数不够"); return(false); } //5. least square estimation Matrix <double> In = Matrix <double> .Build.Dense(3, xArr.Length, 1.0); //by default In[2,:] = 1.0 Matrix <double> Out = Matrix <double> .Build.Dense(2, xArr.Length); Out.SetRow(0, xArr.ToDArr()); Out.SetRow(1, yArr.ToDArr()); In.SetRow(0, uArr.ToDArr()); In.SetRow(1, vArr.ToDArr()); Matrix <double> A = vec2Mat(In, Out); //6. move to center of uv space double[] aArr = A.ToRowWiseArray(); //need to be tested _station._calibrationUV2XYParameter = string.Join(",", aArr.ToArray()); //parse if (matUV2XY == null) { matUV2XY = new HTuple(); } for (int i = 0; i < 6; i++) { matUV2XY.Append(aArr[i]); } return(true); }
public override bool process(HTuple window, HObject img) { try { #region 9点标定 if (PointCount <= 9) { if (PointCount != 9) { Result_Array[0] = (PointCount % 3 - 1) * OffsetXY; //x偏移量 Result_Array[1] = (PointCount / 3 - 1) * OffsetXY; //y偏移量 Result_Array[2] = 0; //angle偏移量 Result_Array[3] = 1; //标定状态 -1——标定失败,0——标定成功,1——9点标定,2——旋转中心标定 } if (PointCount++ == 0) { ClearData(); return(true); } Refresh_in(); if (in_pixel_row.Length == 9) { HTuple qx, qy; HOperatorSet.VectorToHomMat2d(in_pixel_column, in_pixel_row, in_world_x, in_world_y, out HomMat2D); HOperatorSet.AffineTransPoint2d(HomMat2D, in_pixel_column, in_pixel_row, out qx, out qy); XMaxDeviation = qx.TupleSub(in_world_x).TupleAbs().TupleMax(); YMaxDeviation = qy.TupleSub(in_world_y).TupleAbs().TupleMax(); if (!EnableRotateCenter) { HomMat2D.WriteTuple(CalibDataFileName.Replace("\\", "/")); SaveConfig(); Result_Array[0] = 0; Result_Array[1] = 0; Result_Array[2] = 0; Result_Array[3] = 0; PointCount = 0; return(true); } } } #endregion #region 旋转中心标定 if (EnableRotateCenter && PointCount > 9) { if (PointCount <= 15) { Result_Array[0] = 0; Result_Array[1] = 0; Result_Array[2] = (AngleRange * 1.0 / 5) * (PointCount - 10); Result_Array[3] = 2; if (PointCount++ == 10) { return(true); } } Refresh_in(); if (in_pixel_row.Length == 15) { HObject contour; HTuple radius, startPhi, endPhi, pointOrder; HTuple row = in_pixel_row.TupleSelectRange(9, 14); HTuple col = in_pixel_column.TupleSelectRange(9, 14); HOperatorSet.GenContourPolygonXld(out contour, row, col); HOperatorSet.FitCircleContourXld(contour, "algebraic", -1, 0, 0, 3, 2, out CenterRow, out CenterColumn, out radius, out startPhi, out endPhi, out pointOrder); HOperatorSet.GenCircleContourXld(out contour, CenterRow, CenterColumn, radius, 0, 6.28318, "positive", 1); HOperatorSet.DistancePc(contour, row, col, out DistanceMin, out DistanceMax); HomMat2D.Append(CenterRow); HomMat2D.Append(CenterColumn); HomMat2D.WriteTuple(CalibDataFileName.Replace("\\", "/")); SaveConfig(); Result_Array[0] = 0; Result_Array[1] = 0; Result_Array[2] = 0; Result_Array[3] = 0; PointCount = 0; return(true); } } #endregion return(true); } catch (Exception) { PointCount = 0; Result_Array[0] = 0; Result_Array[1] = 0; Result_Array[2] = 0; Result_Array[3] = -1; return(false); } }
private async void btnSaveCalibModel2D_Click(object sender, EventArgs e) { if (!this.mTmpFrm.tmpResult.createTmpOK) { HTUi.PopError("创建标定模板失败!"); return; } Form_Wait.ShowForm(); bool result = await Task.Run(() => { try { this.aoiModels = new Model(); this.aoiModels.Dispose(); this.aoiModels.showContour = this.mTmpFrm.tmpResult.showContour.CopyObj(1, -1); this.aoiModels.defRows = this.mTmpFrm.tmpResult.defRows; this.aoiModels.defCols = this.mTmpFrm.tmpResult.defCols; this.aoiModels.modelType = this.mTmpFrm.tmpResult.modelType; this.aoiModels.modelID = Vision.CopyModel(this.mTmpFrm.tmpResult.modelID, this.mTmpFrm.tmpResult.modelType); this.aoiModels.scoreThresh = this.mTmpFrm.mte_TmpPrmValues.Score; this.aoiModels.angleStart = this.mTmpFrm.mte_TmpPrmValues.AngleStart; this.aoiModels.angleExtent = this.mTmpFrm.mte_TmpPrmValues.AngleExtent; //保存至硬盘 string folderPath = _station.SystemUV2XYDir + "\\Camera_" + _station.SelectedIndex; _station.CalibrUV2XYModelPath = folderPath; if (!this.aoiModels.WriteModel(folderPath)) { HTLog.Error("保存标定模板失败!"); HTUi.PopError("保存标定模板失败!"); return(false); } string errMsg = ""; Pos_Uv2Xy = new HTuple(); double xUV2xy = 0, yUV2xy = 0, zUV2xy = 0; if (!_station.GetAxisPosition(_station.AxisXYZ[0], out xUV2xy, out errMsg)) { HTLog.Error(errMsg + ":保存获取X轴反馈坐标失败!"); HTUi.PopError(errMsg + ":保存获取X轴反馈坐标失败!"); return(false); } if (!_station.GetAxisPosition(_station.AxisXYZ[1], out yUV2xy, out errMsg)) { HTLog.Error(errMsg + ":保存获取Y轴反馈坐标失败!"); HTUi.PopError(errMsg + ":保存获取Y轴反馈坐标失败!"); return(false); } if (!_station.GetAxisPosition(_station.AxisXYZ[2], out zUV2xy, out errMsg)) { HTLog.Error(errMsg + ":保存获取Z轴反馈坐标失败!"); HTUi.PopError(errMsg + ":保存获取Z轴反馈坐标失败!"); return(false); } _station.operation.YUv2xy = yUV2xy; _station.operation.XUv2xy = xUV2xy; _station.operation.ZUv2xy = zUV2xy; Pos_Uv2Xy.Append(_station.operation.XUv2xy); Pos_Uv2Xy.Append(_station.operation.YUv2xy); Pos_Uv2Xy.Append(_station.operation.ZUv2xy); HOperatorSet.WriteTuple(Pos_Uv2Xy, folderPath + "\\Pos_Uv2Xy.tup"); HTUi.TipHint("保存标定模板成功!"); HTLog.Info("保存标定模板成功!"); return(true); } catch (Exception ex) { HTLog.Error(ex.ToString()); HTUi.PopError(ex.ToString()); return(false); } }); Form_Wait.CloseForm(); if (!result) { HTLog.Error("保存标定模板失败!"); HTUi.PopError("保存标定模板失败!"); return; } HTUi.TipHint("保存标定模板成功!"); HTLog.Info("保存标定模板成功!"); }
/// <summary> /// 图像匹配函数,测试使用,可重新编写 /// 只实现了简单ncc匹配,不支持roi内匹配,只能匹配一个目标 /// </summary> /// <param name="image">输入图像</param> /// <param name="model">模型</param> /// <param name="u">返回匹配行坐标,pixel,如果失败为null</param> /// <param name="v">返回匹配列坐标,pixel,如果失败为null</param> /// <param name="angle">返回匹配角度,弧度,如果失败为null</param> /// <returns>是否匹配成功</returns> public bool matchModel(int camInd, ref HObject image, Model model, out HTuple u, out HTuple v, out HTuple angle) { //HTuple _u = new HTuple(), _v = new HTuple(), _angle = new HTuple(); //bool matched = matchModel(image, model.modelID, model.scoreThresh.D, out _u, out _v, out _angle); //u = _u; v = _v; angle = _angle; //return matched; u = null; v = null; angle = null; try { HTuple scores = new HTuple(); // HTuple a = new HTuple(); HTuple b = new HTuple(); HTuple us = new HTuple(), vs = new HTuple(); HTuple score; HObject cross = null; HOperatorSet.GenEmptyObj(out cross); HObject updateShowCont = null; HOperatorSet.GenEmptyObj(out updateShowCont); HTuple updateDefRow = new HTuple(), updateDefCol = new HTuple(), hom2d, iFlag = new HTuple(); HObject matchRegion = (model.matchRegion != null && model.matchRegion.IsInitialized()) ? model.matchRegion : image; //HOperatorSet.FindNccModel(image, modelID, -0.39, 0.78, 0.5, 1, 0.5, "true", 0, out u, out v, out angle, out score); //模版句柄 for (int i = 0; i < model.modelID.Length; i++) { updateShowCont.Dispose(); HOperatorSet.GenEmptyObj(out model.showContour); //匹配起始角度为-1rad,范围为2rad,阈值为0.5 ToolKits.FunctionModule.Vision.find_model(image, matchRegion, model.showContour, out updateShowCont, model.modelType, model.modelID[i], -0.1, 0.2, 0.5, 1, model.defRows[i], model.defCols[i], out u, out v, out angle, out score, out updateDefRow, out updateDefCol, out hom2d, out iFlag); if (iFlag.I == 0) { scores.Append(score); us.Append(updateDefRow); vs.Append(updateDefCol); } else { us.Append(0); vs.Append(0); scores.Append(0); updateShowCont.Dispose(); cross.Dispose(); return(false); } } HTuple sortInd; //排数 从小到大 HOperatorSet.TupleSortIndex(scores, out sortInd); //sortInd ??? HTuple maxInd = sortInd[sortInd.Length - 1]; score = scores[maxInd]; bool status = false; //double if (score.D < 0.01) { u = null; v = null; angle = null; return(false); } else { u = us[maxInd]; v = vs[maxInd]; angle = 0; status = true; } if (this.GrabImageDoneHandler != null && camInd >= 0) { //Show _show = new Show(); //_show.CamInd = camInd; //_show.Image = image.CopyObj(1, -1); //_show.Mode = 2; //_show.Row = status ? u.D : 0; //_show.Column = status ? v.D : 0; //; //this.GrabImageDoneHandler(null, _show); } HOperatorSet.GenCrossContourXld(out cross, updateDefRow, updateDefCol, 300, 0); //App.mainWindow.ShowImage(frmCalibration.Instance.htWindowCalibration, image, cross); if (ImageSrc != null) { ImageSrc.Dispose(); } HOperatorSet.GenEmptyObj(out ImageSrc); //for (int i = 0; i < imageNum; i++) //{ // //从acq里取图并保存图片,行号-列号.tiff HOperatorSet.SelectObj(image, out ImageSrc, 1); ////frmCalibration.Instance.ShowImage(frmCalibration.Instance.htWindowCalibration, image, cross); _station._rtUi._fm.ShowImage(_station._rtUi._fm.htWindowCalibration, ImageSrc, cross); //HOperatorSet.WriteContourXldDxf(updateShowCont, "D://CONT"); //htWindow.RefreshWindow(image, cross, ""); cross.Dispose(); updateShowCont.Dispose(); return(status); } catch (HalconException EXP) { string errMsg = EXP.Message; return(false); } }
public bool Puzzle_tezheng(ExecuteBuffer _executeBuffer, out ExecuteBuffer outexecutebuffer, out string result_info, Dictionary <int, PointName> Pointlist) { outexecutebuffer = _executeBuffer; result_info = ""; HObject image1, image2, image3, image4, image5, image6, image7, image8, image9; double X_shu = Convert.ToDouble(this.textBox_x.Text.ToString()) / Convert.ToDouble(this.textBox_bi.Text.ToString()); double Y_shu = Convert.ToDouble(this.textBox_y.Text.ToString()) / Convert.ToDouble(this.textBox_bi.Text.ToString()); if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image1.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像1已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像1已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image1.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image1参数为空或者未赋值"); result_info = " 二值化处理: 输入图像1已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image2.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像2已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像2已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image2.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image2参数为空或者未赋值"); result_info = " 二值化处理: 输入图像2已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image3.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像3已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像3已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image3.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image3参数为空或者未赋值"); result_info = " 二值化处理: 输入图像3已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image4.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像4已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像4已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image4.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image4参数为空或者未赋值"); result_info = " 二值化处理: 输入图像4已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image5.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像5已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像5已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image5.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image5参数为空或者未赋值"); result_info = " 二值化处理: 输入图像5已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image6.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像6已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像6已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image6.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image6参数为空或者未赋值"); result_info = " 二值化处理: 输入图像6已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image7.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像7已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像7已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image7.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image7参数为空或者未赋值"); result_info = " 二值化处理: 输入图像7已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image8.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像8已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像8已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image8.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image8参数为空或者未赋值"); result_info = " 二值化处理: 输入图像8已经不存在,请重置设置输入图像"; return(false); } if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image9.SelectedItem.ToString() + ".img")) { MessageBox.Show("二值化处理: 输入图像9已经不存在,请重置设置输入图像"); result_info = " 二值化处理: 输入图像9已经不存在,请重置设置输入图像"; return(false); } if (_executeBuffer.imageBuffer[this.Input_image9.SelectedItem.ToString() + ".img"] == null) { MessageBox.Show("二值化处理: image9参数为空或者未赋值"); result_info = " 二值化处理: 输入图像9已经不存在,请重置设置输入图像"; return(false); } string comboBox_imageoutname = this.Output_image.Text.ToString() + ".img"; if (_executeBuffer.imageBuffer[comboBox_imageoutname] != null) { if (_executeBuffer.imageBuffer[comboBox_imageoutname].IsInitialized()) { _executeBuffer.imageBuffer[comboBox_imageoutname].Dispose(); } } HObject imagex; HOperatorSet.GenEmptyObj(out imagex); // image1 = _executeBuffer.imageBuffer[this.Input_image1.SelectedItem.ToString() + ".img"]; HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image1.SelectedItem.ToString() + ".img"], out image1); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image2.SelectedItem.ToString() + ".img"], out image2); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image3.SelectedItem.ToString() + ".img"], out image3); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image4.SelectedItem.ToString() + ".img"], out image4); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image5.SelectedItem.ToString() + ".img"], out image5); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image6.SelectedItem.ToString() + ".img"], out image6); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image7.SelectedItem.ToString() + ".img"], out image7); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image8.SelectedItem.ToString() + ".img"], out image8); HOperatorSet.CopyImage(_executeBuffer.imageBuffer[this.Input_image9.SelectedItem.ToString() + ".img"], out image9); /* * image2 = _executeBuffer.imageBuffer[this.Input_image2.SelectedItem.ToString() + ".img"]; * image3 = _executeBuffer.imageBuffer[this.Input_image3.SelectedItem.ToString() + ".img"]; * image4 = _executeBuffer.imageBuffer[this.Input_image4.SelectedItem.ToString() + ".img"]; * image5 = _executeBuffer.imageBuffer[this.Input_image5.SelectedItem.ToString() + ".img"]; * image6 = _executeBuffer.imageBuffer[this.Input_image6.SelectedItem.ToString() + ".img"]; * image7 = _executeBuffer.imageBuffer[this.Input_image7.SelectedItem.ToString() + ".img"]; * image8 = _executeBuffer.imageBuffer[this.Input_image8.SelectedItem.ToString() + ".img"]; * image9 = _executeBuffer.imageBuffer[this.Input_image9.SelectedItem.ToString() + ".img"]; * */ HOperatorSet.ConcatObj(imagex, image1, out imagex); HOperatorSet.ConcatObj(imagex, image2, out imagex); HOperatorSet.ConcatObj(imagex, image3, out imagex); HOperatorSet.ConcatObj(imagex, image4, out imagex); HOperatorSet.ConcatObj(imagex, image5, out imagex); HOperatorSet.ConcatObj(imagex, image6, out imagex); HOperatorSet.ConcatObj(imagex, image7, out imagex); HOperatorSet.ConcatObj(imagex, image8, out imagex); HOperatorSet.ConcatObj(imagex, image9, out imagex); HObject ho_TiledImage; HOperatorSet.GenEmptyObj(out ho_TiledImage); HTuple width, height; HOperatorSet.GetImageSize(image1, out width, out height); HTuple Pal_1 = new HTuple(), Pal_2 = new HTuple(), Pal_3 = new HTuple(); for (int i = 0; i < 9; i++) { Pal_3.Append(-1); if (i % 3 == 0) { Pal_2.Append(0); } else if (i % 3 == 1) { Pal_2.Append(width + 20); } else { Pal_2.Append(2 * width + 40); } if ((int)i / 3 < 1) { Pal_1.Append(0); } else if ((int)i / 3 < 2) { Pal_1.Append(height + 20); } else { Pal_1.Append(2 * height + 40); } } HOperatorSet.TileImagesOffset(imagex, out ho_TiledImage, Pal_1, Pal_2, Pal_3, Pal_3, Pal_3, Pal_3, (width * 3 + 2 * 20), height * 3 + 2 * 20); HTuple From = new HTuple(1, 1, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5, 5, 6); HTuple End = new HTuple(4, 5, 2, 5, 6, 3, 6, 7, 8, 5, 8, 9, 6, 9); return(true); }