Esempio n. 1
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);
         HTuple CrossRow = new HTuple(), CrossCol = new HTuple(), IsParallel = new HTuple();
         //第一条直线和第二条直线的交点
         HOperatorSet.IntersectionLl(LineRow1[0], LineCol1[0], LineRow2[0], LineCol2[0], LineRow1[1], LineCol1[1], LineRow2[1], LineCol2[1],
                                     out CrossRow, out CrossCol, out IsParallel);
         HTuple angle;
         //图像坐标轴X轴到直线1的角度
         HOperatorSet.AngleLx(LineRow1[0], LineCol1[0], LineRow2[0], LineCol2[0], out angle);
         NowResult.row   = CrossRow.D;
         NowResult.col   = CrossCol.D;
         NowResult.angle = angle.D;
         HOperatorSet.ConcatObj(LinesContour, LinePtCont, out LinesContour);
         LinePtCont.Dispose();
         NowResult.ShowContour = LinesContour;
         return(true);
     }
     catch {
         return(false);
     }
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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); }
 }