public ToolResult GetResult() { try { int imageWidt, imageHeight; HMetrologyModel metrologyModel = new HMetrologyModel(); HTuple startRow, startCol, endRow, endCol; HHomMat2D matd = new HHomMat2D(); HHomMat2D matd3 = matd.HomMat2dRotate(info.Rectangle2Angle, 0.0, 0.0); HHomMat2D matd4 = matd3.HomMat2dTranslate(info.Rectangle2Row, info.Rectangle2Col); HOperatorSet.AffineTransPoint2d(matd4, new HTuple(0.0), new HTuple(-info.Rectangle2Length1), out startRow, out startCol); HOperatorSet.AffineTransPoint2d(matd4, new HTuple(0.0), new HTuple(info.Rectangle2Length1), out endRow, out endCol); //创建找线工具 Image.GetImageSize(out imageWidt, out imageHeight); int[] value = new int[] { Convert.ToInt32(startRow.D), Convert.ToInt32(startCol.D), Convert.ToInt32(endRow.D), Convert.ToInt32(endCol.D) }; HTuple values = new HTuple(value); metrologyModel.CreateMetrologyModel(); metrologyModel.SetMetrologyModelImageSize(imageWidt, imageHeight); int index = metrologyModel.AddMetrologyObjectGeneric("line", values, 20, 5, 1, 30, "min_score", 0.6); #region 设置参数 metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_length1"), new HTuple(Convert.ToInt32(info.measure_length1))); metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_length2"), new HTuple(Convert.ToInt32(info.measure_length2))); metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_distance"), new HTuple(info.measure_distance)); metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("num_measures"), new HTuple(info.num_measures)); metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("num_instances"), new HTuple(info.num_instances)); metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_sigma"), new HTuple(info.measure_sigma)); metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_threshold"), new HTuple(info.measure_threshold)); metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_transition"), new HTuple(info.measure_transition.ToString())); #endregion HTuple Row; HTuple Col; HXLDCont modelXLD = metrologyModel.GetMetrologyObjectMeasures(index, "all", out Row, out Col); if (info.IsShowLineMeasureDetail) { Window.SetColor("red"); modelXLD.DispXld(Window.Window); } return(ApplyMetrology(metrologyModel, index, info.ToolName)); } catch (Exception e) { return(new ToolResult() { ResultName = info.ToolName, Errormessage = e.ToString(), GetResultTime = DateTime.Now, IsSuccess = false }); } }
private ToolResult ApplyMetrology(HMetrologyModel hMetrology, int index, string measureName) { HiPerfTimer timer = new HiPerfTimer(); timer.Start(); try { hMetrology.ApplyMetrologyModel(Image); double circleCenterRow, circleCenterCol, radius; HTuple circleResult = hMetrology.GetMetrologyObjectResult(new HTuple(index), new HTuple("all"), new HTuple("result_type"), new HTuple("all_param")); HXLDCont circleXLD = hMetrology.GetMetrologyObjectResultContour(new HTuple("all"), new HTuple("all"), new HTuple(1.5)); HXLDCont modelXLD = hMetrology.GetMetrologyObjectMeasures(index, "all", out HTuple Row, out HTuple Col); if (circleResult.Length < 3) { return(new ToolResult() { ResultName = measureName, Errormessage = "圆形测量失败", GetResultTime = DateTime.Now, IsSuccess = false }); } circleCenterRow = circleResult[0].D; circleCenterCol = circleResult[1].D; radius = circleResult[2].D; if (info.IsShowResult) { Window.SetColor("blue"); circleXLD.DispXld(Window.Window); } if (info.IsShowFindRegion) { Window.SetColor("green"); Window.DisplayCircle(info.ToolName, info.CircleRow, info.CircleCol, info.CircleRadius, true); } hMetrology.ClearMetrologyObject(new HTuple(index)); return(new ToolResult() { ResultName = measureName, ImageX = circleCenterCol, ImageY = circleCenterRow, ImageRadius = radius, GetResultTime = DateTime.Now, ElapsedTime = timer.Duration, IsSuccess = true }); } catch (Exception e) { WriteErrorLog("VisionTool", e.ToString()); return(new ToolResult() { ResultName = measureName, Errormessage = e.ToString(), GetResultTime = DateTime.Now, IsSuccess = false }); } }
public ToolResult GetResult() { try { int imageWidt, imageHeight; HMetrologyModel metrologyModel = new HMetrologyModel(); int circleRow = Convert.ToInt32(info.CircleRow), circleCol = Convert.ToInt32(info.CircleCol), circleRadius = Convert.ToInt32(info.CircleRadius); //创建找圆工具 Image.GetImageSize(out imageWidt, out imageHeight); metrologyModel.CreateMetrologyModel(); metrologyModel.SetMetrologyModelImageSize(imageWidt, imageHeight); HTuple index = metrologyModel.AddMetrologyObjectCircleMeasure(new HTuple(circleRow), new HTuple(circleCol), new HTuple(circleRadius), new HTuple(info.measure_length1), new HTuple(info.measure_length2), new HTuple(info.measure_sigma), new HTuple(info.measure_threshold), new HTuple(), new HTuple()); #region 设置参数 metrologyModel.SetMetrologyObjectParam(index, new HTuple("measure_transition"), new HTuple(info.Measure_transition.ToString())); metrologyModel.SetMetrologyObjectParam(index, new HTuple("min_score"), new HTuple(info.min_score)); metrologyModel.SetMetrologyObjectParam(index, new HTuple("measure_interpolation"), new HTuple(info.measure_interpolation)); metrologyModel.SetMetrologyObjectParam(index, new HTuple("measure_distance"), new HTuple(info.measure_distance)); #endregion #region 获取轮廓 HTuple Row; HTuple Col; HXLDCont modelXLD = metrologyModel.GetMetrologyObjectMeasures(index, "all", out Row, out Col); if (info.IsShowCircleMeasureDetail) { Window.SetColor("red"); modelXLD.DispXld(Window.Window); } #endregion return(ApplyMetrology(metrologyModel, index, info.ToolName)); } catch (Exception e) { return(new ToolResult() { ResultName = info.ToolName, Errormessage = e.ToString(), GetResultTime = DateTime.Now, IsSuccess = false }); } }