public override bool doLocal() { try { NowResult = new LocalResult(); St_CirclesParam CirclesParam = new St_CirclesParam(2); CirclesParam = NowVisionPara.Circles; HTuple CircleRows = new HTuple(), CircleCols = new HTuple(), CircleRs = new HTuple(), StartPhis = new HTuple(), EndPhis = new HTuple(); HObject CircleContour = new HObject(), CircleCont = new HObject(), CenterCross = new HObject(); //找出要找的圆 CircleTypePos.FindCircle(NowImg, CirclesParam, out CircleRows, out CircleCols, out CircleRs, out StartPhis, out EndPhis, out CircleContour, out CircleCont, out CenterCross); HOperatorSet.ConcatObj(CircleContour, CircleCont, out CircleContour); HOperatorSet.ConcatObj(CircleContour, CenterCross, out CircleContour); CircleCont.Dispose(); CenterCross.Dispose(); NowResult.ShowContour = CircleContour; NowResult.row = (CircleRows[0].D + CircleCols[1].D) / 2.0; NowResult.col = (CircleCols[0].D + CircleCols[1].D) / 2.0; HTuple angle = new HTuple(); HOperatorSet.AngleLx(CircleRows[0], CircleCols[0], CircleRows[1], CircleCols[1], out angle); NowResult.angle = angle.D; return(true); } catch { return(false); } }
private void TryDebugBtn_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); try{ #region Point2Db MotionPos = new Point2Db(0, 0); HObject CirContour = new HObject(); HObject circle = new HObject(); HObject centerCont = new HObject(); //模板的VectorAngle double TempTeachRow = LocalPara0.Template.CenterY; double TempTeachCol = LocalPara0.Template.CenterX; double TempTeachAngle = LocalPara0.Template.TemplateAngle; view1.Refresh(); HTuple Y = new HTuple(), X = new HTuple(); //找出要定位的的圆 St_CirclesParam AdjCirclePara = new St_CirclesParam(2); St_VectorAngle VectorAngle0 = new St_VectorAngle(LocalPara0.Template.CenterY, LocalPara0.Template.CenterX, LocalPara0.Template.TemplateAngle); HTuple CircleStartPhi = new HTuple(), CircleEndPhi = new HTuple(); CircleTypePos.FindCircle(GrabedImg, AdjCirclePara, out Y, out X, out FindCircleR, out CircleStartPhi, out CircleEndPhi, out circle, out CirContour, out centerCont); FindCircleRow = Y; FindCircleCol = X; view1.AddImage(GrabedImg); Thread.Sleep(100); view1.SetDraw("green", "margin"); view1.AddViewObject(circle); view1.SetDraw("blue", "margin"); view1.AddViewObject(CirContour); view1.SetDraw("red", "margin"); view1.AddViewObject(centerCont); HObject CirCenterCross = new HObject(); HOperatorSet.GenCrossContourXld(out CirCenterCross, Y, X, 120, 0.6); view1.AddViewObject(CirCenterCross); #endregion } catch (Exception e0) { Logger.PopError(e0.Message.ToString(), true); } }
public override bool doLocal() { try { NowResult = new LocalResult(); St_LinesParam LinesPara = new St_LinesParam(2); LinesPara = NowVisionPara.Lines; HTuple LineRow1 = new HTuple(), LineCol1 = new HTuple(), LineRow2 = new HTuple(), LineCol2 = new HTuple(); HObject LinesContour = new HObject(), LinePtCont = new HObject(); //找出所有的直线 LineTypePos.FindLine(LinesPara, NowImg, out LineRow1, out LineCol1, out LineRow2, out LineCol2, out LinesContour, out LinePtCont); St_CirclesParam CirclesParam = new St_CirclesParam(2); CirclesParam = NowVisionPara.Circles; HTuple CircleRows = new HTuple(), CircleCols = new HTuple(), CircleRs = new HTuple(), StartPhis = new HTuple(), EndPhis = new HTuple(); HObject CircleContour = new HObject(), CircleCont = new HObject(), CenterCross = new HObject(); HTuple angle; //图像坐标轴X轴到直线1的角度 HOperatorSet.AngleLx(LineRow1[0], LineCol1[0], LineRow2[0], LineCol2[0], out angle); //找出要找的圆 CircleTypePos.FindCircle(NowImg, CirclesParam, out CircleRows, out CircleCols, out CircleRs, out StartPhis, out EndPhis, out CircleContour, out CircleCont, out CenterCross); HOperatorSet.ConcatObj(CircleContour, CircleCont, out CircleContour); HOperatorSet.ConcatObj(CircleContour, CenterCross, out CircleContour); CircleCont.Dispose(); CenterCross.Dispose(); HOperatorSet.ConcatObj(CircleContour, LinesContour, out CircleContour); HOperatorSet.ConcatObj(CircleContour, LinePtCont, out CircleContour); LinesContour.Dispose(); LinePtCont.Dispose(); NowResult.row = CircleRows[0].D; NowResult.col = CircleCols[0].D; NowResult.angle = angle.D; NowResult.ShowContour = CircleContour; return(true); } catch { return(false); } }
private void FindCircleBtn_Click(object sender, EventArgs e) { try{ Stopwatch sw = new Stopwatch(); sw.Start(); txtFindTime.Text = ""; #region view1.Refresh(); HTuple CircleRows = new HTuple(), CircleCols = new HTuple(); HObject RoiContour = new HObject(); HTuple ResultRows = new HTuple(), ResultCols = new HTuple(), ArcType0 = new HTuple(); view1.AddImage(GrabedImg); HTuple FitCirRows = new HTuple(), FitCirCols = new HTuple(), FitCirRs = new HTuple(), CirStartPhis = new HTuple(), CirEndPhi = new HTuple(); for (int i = 0; i < TeachCirclePara.CenterRows.Count; i++) { //利用存下来的圆的信息,创建圆的边缘点坐标 MyVisionBase.GenCirclePts2(TeachCirclePara.CenterRows[i], TeachCirclePara.CenterCols[i], TeachCirclePara.CircleRs[i], TeachCirclePara.StartPhis[i], TeachCirclePara.EndPhis[i], TeachCirclePara.PointOrders[i], out CircleRows, out CircleCols); HObject CrossContour = new HObject(); HOperatorSet.GenCrossContourXld(out CrossContour, CircleRows, CircleCols, 6, 0.6); view1.SetDraw("blue", "margin"); view1.AddViewObject(CrossContour); //生成圆的边缘ROI MyVisionBase.gen_spoke_ROI(GrabedImg, out RoiContour, TeachCirclePara.Elements[i], TeachCirclePara.DetectHeights[i], 2, CircleRows, CircleCols, TeachCirclePara.Directs[i]); view1.AddViewObject(RoiContour); //3.0找出圆的边缘点 MyVisionBase.spoke(GrabedImg, out RoiContour, view1, TeachCirclePara.Elements[i], TeachCirclePara.DetectHeights[i], 2, 2, TeachCirclePara.Thresholds[i], "all", "first", CircleRows, CircleCols, TeachCirclePara.Directs[i], out ResultRows, out ResultCols, out ArcType0); HObject CirclePtCross = new HObject(); //2.5显示拟合的点 HOperatorSet.GenCrossContourXld(out CirclePtCross, ResultRows, ResultCols, 12, 0.7); if (ResultRows.Length > i && ResultCols.Length > i) { FitCirRows[i] = ResultRows.D; FitCirCols[i] = ResultCols.D; } view1.SetDraw("green", "margin"); view1.AddViewObject(CirclePtCross); txtFindTime.Text = sw.ElapsedMilliseconds.ToString(); } HObject CircleCont = new HObject(), CirContour = new HObject(), CirCross = new HObject(); CircleTypePos.FindCircle(GrabedImg, TeachCirclePara, out FitCirRows, out FitCirCols, out FitCirRs, out CirStartPhis, out CirEndPhi, out CircleCont, out CirContour, out CirCross); this.view1.SetDraw("red", "margin"); this.view1.AddViewObject(CircleCont); this.view1.Repaint(); HTuple PlDist = new HTuple(), DistPp = new HTuple(), DistPp1 = new HTuple(); if (FitCirRows.Length >= 3 && FitCirCols.Length >= 3) { HOperatorSet.DistancePl(FitCirRows[2].D, FitCirCols[2].D, FitCirRows[0].D, FitCirCols[0].D, FitCirRows[1].D, FitCirCols[1].D, out PlDist); HOperatorSet.DistancePp(FitCirRows[0].D, FitCirCols[0].D, FitCirRows[1].D, FitCirCols[1].D, out DistPp); HOperatorSet.DistancePp(FitCirRows[0].D, FitCirCols[0].D, FitCirRows[2].D, FitCirCols[2].D, out DistPp1); PlDist = 3.2 * 3.0 / DistPp.D * DistPp1.D; txtFindTime.Text = PlDist.D.ToString(); } #endregion } catch (Exception e0) { Logger.PopError(e0.Message.ToString(), true); } }