public bool Read(string Path) { bool IsOk = true; // BasePath = System.IO.Directory.GetCurrentDirectory(); string path = Path + ConfigName + @"\"; this.localSetting = XML <LocalSettingPara> .Read(path + "LocalSetting.xml"); this.Template = XML <St_TemplateParam> .Read(path + "Template.xml"); this.Lines = XML <St_LinesParam> .Read(path + "Lines.xml"); this.Circles = XML <St_CirclesParam> .Read(path + "Circles.xml"); this.Blobs = XML <St_BlobLocalParam> .Read(path + "Blobs.xml"); this.LineCirRectInspParam = XML <St_InspectImageSetting> .Read(path + "LineCirRectInspParam.xml"); if (localSetting == null) { return(true); } if (localSetting.localModel.ToString().Contains("Temp")) { Template.Load(path); } return(IsOk); }
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); } }
public LocalPara() { localSetting = new LocalSettingPara(); Template = new St_TemplateParam(true); Lines = new St_LinesParam(4); Circles = new St_CirclesParam(2); Blobs = new St_BlobLocalParam(2); }
public St_InspectImageSetting(bool isInit = true) { LinePara = new St_LinesParam(4); CirclePara = new St_CirclesParam(true); VectorAngle0 = new St_VectorAngle(true); NowVectorAngle = new St_VectorAngle(true); InspectLinePara = new St_InsepctLinePara(2, true); InspectCirclePara = new St_InspectCirclePara(2, true); InspectRectPara = new St_InspectRectanglePara(1, true); }
public SubFrmFindLine(St_LinesParam lineParam, ViewControl viewIn, HObject ImgIn, Action <bool> drawRoiInHWindow) { InitializeComponent(); TeachLinesPara = lineParam; view1 = viewIn; ActionIsDrawingRoi = drawRoiInHWindow; if (ImgIn != null && ImgIn.IsInitialized()) { HOperatorSet.CopyImage(ImgIn, out GrabedImg); } }
/// <summary> /// 判断示教直线与找出直线的角度 /// </summary> /// <param name="TeachLinePara"></param> /// <param name="LineRow1U"></param> /// <param name="LineCol1U"></param> /// <param name="LineRow2U"></param> /// <param name="LineCol2U"></param> /// <returns></returns> public static bool JugeLine(St_LinesParam TeachLinePara, HTuple LineRow1U, HTuple LineCol1U, HTuple LineRow2U, HTuple LineCol2U) { HTuple Pt1Row = new HTuple(), Pt1Col = new HTuple(), Pt2Row = new HTuple(), Pt2Col = new HTuple(); HTuple IsParallel = new HTuple(); if (LineRow1U.Length != 4 || LineCol1U.Length != 4 || LineRow2U.Length != 4 || LineRow2U.Length != 4) { return(false); } List <double> ListRow1 = new List <double>(); List <double> ListCol1 = new List <double>(); List <double> ListRow2 = new List <double>(); List <double> ListCol2 = new List <double>(); ListRow1 = TeachLinePara.Row1s; ListCol1 = TeachLinePara.Col1s; ListRow2 = TeachLinePara.Row2s; ListCol2 = TeachLinePara.Col2s; try{ //示教直线的交点 HOperatorSet.IntersectionLl(ListRow1[0], ListCol1[0], ListRow2[0], ListCol2[0], ListRow1[1], ListCol1[1], ListRow2[1], ListCol2[1], out Pt1Row, out Pt1Col, out IsParallel); //交点1 HOperatorSet.IntersectionLl(ListRow1[3], ListCol1[3], ListRow2[3], ListCol2[3], ListRow1[0], ListCol1[0], ListRow2[0], ListCol2[0], out Pt2Row, out Pt2Col, out IsParallel); //交点4 HTuple TeachLength = new HTuple(), NowLength = new HTuple(); HOperatorSet.DistancePp(Pt1Row, Pt1Col, Pt2Row, Pt2Col, out TeachLength); //找出来的直线交点 HOperatorSet.IntersectionLl(LineRow1U[0], LineCol1U[0], LineRow2U[0], LineCol2U[0], LineRow1U[1], LineCol1U[1], LineRow2U[1], LineCol2U[1], out Pt1Row, out Pt1Col, out IsParallel); HOperatorSet.IntersectionLl(LineRow1U[3], LineCol1U[3], LineRow2U[3], LineCol2U[3], LineRow1U[0], LineCol1U[0], LineRow2U[0], LineCol2U[0], out Pt2Row, out Pt2Col, out IsParallel); //交点4 HOperatorSet.DistancePp(Pt1Row, Pt1Col, Pt2Row, Pt2Col, out NowLength); if (Math.Abs((TeachLength - NowLength).D) < 50) { return(true); } else { return(false); } } catch (Exception e0) { Logger.Pop(e0.Source + e0.Message); return(false); } }
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 ClearParaBtn_Click(object sender, EventArgs e) { DialogResult rlt = MessageBox.Show("真的要清除参数?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rlt != DialogResult.Yes) { return; } int initLineCount = 1; int i = 1; while (true) { rlt = MessageBox.Show("示教" + i.ToString() + "条线?", "线数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rlt == DialogResult.Yes) { initLineCount = i; break; } i++; } TeachLinesPara = new St_LinesParam(initLineCount); InitCombox(); }
public static bool FindLine(St_LinesParam LineParaIn, HObject ImgIn, out HTuple OutLineRow1, out HTuple OutLineCol1, out HTuple OutLineRow2, out HTuple OutLineCol2, out HObject lines, out HObject linesContour) { OutLineRow1 = new HTuple(); OutLineCol1 = new HTuple(); OutLineRow2 = new HTuple(); OutLineCol2 = new HTuple(); HOperatorSet.GenEmptyObj(out lines); HOperatorSet.GenEmptyObj(out linesContour); St_LinesParam TeachLinePara; TeachLinePara = LineParaIn; HTuple LineRow1U = new HTuple(), LineCol1U = new HTuple(), LineRow2U = new HTuple(), LineCol2U = new HTuple(); HObject RoiContour = new HObject(); HTuple ResultRows = new HTuple(), ResultCols = new HTuple(); HTuple LengthL = new HTuple(); HObject LineContourI = new HObject(); for (int i = 0; i < TeachLinePara.Col2s.Count(); i++) { //2.0利用卡尺工具找出边界点 if (!MyVisionBase.Rake1(ImgIn, out RoiContour, TeachLinePara.Elements[i], TeachLinePara.DetectHeights[i], 2, 2, TeachLinePara.Thresholds[i], "all", "first", TeachLinePara.Row1s[i], TeachLinePara.Col1s[i], TeachLinePara.Row2s[i], TeachLinePara.Col2s[i], out ResultRows, out ResultCols)) { Logger.PopError("直线定位找边界点时Rake1返回false"); return(false); } //提出要删除的中心点 MyVisionBase.ClipCenterElement(ResultRows, TeachLinePara.CenterClips[i], out ResultRows); MyVisionBase.ClipCenterElement(ResultCols, TeachLinePara.CenterClips[i], out ResultCols); HObject FitLineContour = new HObject(); HTuple LineRow1 = new HTuple(), LineCol1 = new HTuple(), LineRow2 = new HTuple(), LineCol2 = new HTuple(), DistPtToLine; MyVisionBase.PtsToBestLine(out FitLineContour, ResultRows, ResultCols, 3, out LineRow1, out LineCol1, out LineRow2, out LineCol2, out DistPtToLine); LineRow1U[i] = LineRow1[0]; LineCol1U[i] = LineCol1[0]; LineRow2U[i] = LineRow2[0]; LineCol2U[i] = LineCol2[0]; HOperatorSet.GenContourPolygonXld(out LineContourI, LineRow1.TupleConcat(LineRow2), LineCol1.TupleConcat(LineCol2)); //生成直线的轮廓 HOperatorSet.ConcatObj(LineContourI, lines, out lines); HOperatorSet.DistancePp(LineRow1, LineCol1, LineRow2, LineRow2, out LengthL); HTuple PtSize = LengthL / 60; if (LengthL / 60 < 10) { PtSize = 10.0; } HOperatorSet.GenCrossContourXld(out LineContourI, ResultRows, ResultCols, PtSize, 0.6); //生成 拟合直线点的轮廓 HOperatorSet.ConcatObj(LineContourI, linesContour, out linesContour); FitLineContour.Dispose(); } if (LineRow1U.TupleLength() != TeachLinePara.Col2s.Count() || LineCol1U.TupleLength() != TeachLinePara.Col2s.Count() || LineRow2U.TupleLength() != TeachLinePara.Col2s.Count()) { Logger.Pop("找出的线的数量和示教的数量不一致"); return(false); } OutLineRow1 = LineRow1U; OutLineCol1 = LineCol1U; OutLineRow2 = LineRow2U; OutLineCol2 = LineCol2U; RoiContour.Dispose(); LineContourI.Dispose(); return(true); }
public void UpdatePara(St_LinesParam LineParaIn, St_CirclesParam CircleParaIn, St_VectorAngle VectorAngle0In) { InspectImageSetting.VectorAngle0 = VectorAngle0In; InspectImageSetting.CirclePara = CircleParaIn; InspectImageSetting.LinePara = LineParaIn; }