Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
 private void GenVirtualBtn_Click(object sender, EventArgs e)
 {
     TryDebugBtn_Click(null, new EventArgs());
     if (FindCircleRow.Length >= 2 && FindCircleCol.Length >= 2)
     {
         HTuple OutLineRow1 = new HTuple(), OutLineCol1 = new HTuple(), OutLineRow2 = new HTuple(), OutLineCol2 = new HTuple();
         view1.ResetView();
         view1.AddImage(GrabedImg);
         //1.0找线
         TryDebugBtn_Click(null, new EventArgs());
         HTuple  LineAngle   = new HTuple();
         HObject LineArrow   = new HObject();
         HObject LitCirCross = new HObject();
         //2.0计算圆心连线与相机X轴的夹角
         OutLineRow1 = FindCircleRow[0].D;
         OutLineCol1 = FindCircleCol[0].D;
         OutLineRow2 = FindCircleRow[1].D;
         OutLineCol2 = FindCircleCol[1].D;
         LineTypePos.CalculateLineAng(OutLineRow1, OutLineCol1, OutLineRow2, OutLineCol2, out LineAngle, out LineArrow);
         LineAngle = LineAngle.D / Math.PI * 180.0;
         HTuple LitCirRow = new HTuple(), LitCircol = new HTuple();
         HTuple DistRr = (7.78 / 2.0) / 2.8 * FindCircleR[0].D;
         //3.0生成虚拟圆的圆心
         CircleTypePos.GenCirCenter(FindCircleRow[0].D, FindCircleCol[0].D, DistRr, out LitCirRow, out LitCircol);
         HOperatorSet.GenCrossContourXld(out LitCirCross, LitCirRow, LitCircol, 60, 0);
         view1.SetDraw("blue", "margin");
         view1.AddViewObject(LineArrow);
         view1.AddViewObject(LitCirCross);
         HHomMat2D MyHomMat = new HHomMat2D();
         MyHomMat = MyHomMat.HomMat2dRotate((TeachCirclePara.OffSetPixelTh + LineAngle) / 180.0 * Math.PI, FindCircleRow[0], FindCircleCol[0]);
         //4.0旋转生成圆的圆心
         MyHomMat.AffineTransPixel(LitCirRow, LitCircol, out LitCirRow, out LitCircol);
         HOperatorSet.GenCrossContourXld(out LitCirCross, LitCirRow, LitCircol, 60, 0);
         HObject FirstCirCont = new HObject(), SecondCirCont = new HObject();
         HOperatorSet.GenCircleContourXld(out FirstCirCont, LitCirRow[0].D, LitCircol[0].D, 60, 0, 2 * Math.PI, "positive", 0.1);
         HOperatorSet.GenCircleContourXld(out SecondCirCont, LitCirRow[1].D, LitCircol[1].D, 40, 0, 2 * Math.PI, "positive", 0.1);
         HOperatorSet.ConcatObj(LitCirCross, FirstCirCont, out LitCirCross);
         HOperatorSet.ConcatObj(LitCirCross, SecondCirCont, out LitCirCross);
         view1.SetDraw("red", "margin");
         view1.AddViewObject(LitCirCross);
     }
 }
Beispiel #4
0
 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); }
 }
Beispiel #5
0
 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);
     }
 }