public static DistanceResult PointToPoint(Measurement first, Measurement second, HTuple angle, LineDirection direction) { DistanceResult result = null; var p1 = first.GetViewModel(); var p2 = second.GetViewModel(); if (p1 == null || p2 == null) { return(null); } if (p1.Row1 != null && p1.Row1.TupleLength() > 0 && p2.Row1 != null && p2.Row1.TupleLength() > 0) { HTuple distanceMin; HOperatorSet.DistancePp(p1.Row1, p1.Col1, p2.Row1, p2.Col1, out distanceMin); result = new DistanceResult() { Distance = distanceMin, Direction = direction, Angle = angle, FirstRowBegin = p1.Row1, FirstColBegin = p1.Col1, FirstRowEnd = p2.Row1, FirstColEnd = p2.Col1, }; } return(result); }
public MeasureResult Action() { #region 輸出結果 DistanceResult mResult = null; #endregion var fMidLine = new SDMS_FirstFingerMidLine(); var image = new HImage(ho_Image); fMidLine.Initialize(image, hv_AllModelRow, hv_AllModelColumn, hv_AllModelAngle); var fMidLineModel = fMidLine.GetMidLine() as IMeasureGeoModel; var sMidLine = new SecondFingerMidLine(); sMidLine.Initialize(image, hv_AllModelRow, hv_AllModelColumn, hv_AllModelAngle); var sMidLineModel = sMidLine.GetMidLine() as IMeasureGeoModel; var distance = DistanceHelper.LineToLine(fMidLineModel, sMidLineModel); mResult = new DistanceResult() { FirstRowBegin = fMidLineModel.Row1, FirstColBegin = fMidLineModel.Col1, FirstRowEnd = fMidLineModel.Row2, FirstColEnd = fMidLineModel.Col2, SecondRowBegin = sMidLineModel.Row1, SecondColBegin = sMidLineModel.Col1, SecondRowEnd = sMidLineModel.Row2, SecondColEnd = sMidLineModel.Col2, Angle = hv_AllModelAngle, Direction = LineDirection.Horizontal, Distance = distance, }; return mResult; }
public static DistanceResult PointToLine(Measurement first, Measurement second, HTuple angle) { DistanceResult result = null; var firstData = first.GetViewModel(); var secData = second.GetViewModel(); if (firstData.Row1 != null && firstData.Row1.TupleLength() > 0 && secData.Row1 != null && secData.Row1.TupleLength() > 0) { HTuple distanceMin, distanceMax; var point = (firstData.Row2 != null) ? secData : firstData; var line = (firstData.Row2 != null) ? firstData : secData; HOperatorSet.DistancePs(point.Row1, point.Col1, line.Row1, line.Col1, line.Row2, line.Col2, out distanceMin, out distanceMax); result = new DistanceResult() { FirstRowBegin = new HTuple(line.Row1), FirstColBegin = new HTuple(line.Col1), FirstRowEnd = new HTuple(line.Row2), FirstColEnd = new HTuple(line.Col2), SecondRowBegin = new HTuple(point.Row1), SecondColBegin = new HTuple(point.Col1), //SecondRowEnd = new HTuple(line2.Row2), //SecondColEnd = new HTuple(line2.Col2), Direction = LineDirection.Vertical, Distance = new HTuple(distanceMin), Angle = angle, }; } return(result); }
public MeasureResult Action() { #region 輸出結果 DistanceResult mResult = null; #endregion // Local iconic variables HObject ho_A_1_1_Rectangle = null; HObject ho_A_1_1_Image = null, ho_A_1_1_Edges = null, ho_A_1_1_Contours = null; HObject ho_A_1_1_SelectedLines = null, ho_A_1_1_Line = null; HObject ho_A_1_2_Rectangle = null, ho_A_1_2_Image = null, ho_A_1_2_Edges = null; HObject ho_A_1_2_Contours = null, ho_A_1_2_SelectedLines = null; HObject ho_A_1_2_Line = null; // Local control variables HTuple hv_msgOffsetY, hv_msgOffsetX; HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol, hv_STD_A_1_1_Row, hv_STD_A_1_1_Col; HTuple hv_STD_A_1_1_V_Row, hv_STD_A_1_1_V_Col, hv_A_1_1_X; HTuple hv_A_1_1_Y, hv_A_1_1_Pos_Row, hv_A_1_1_Pos_Col; HTuple hv_Corner_W = new HTuple(), hv_Corner_H = new HTuple(); HTuple hv_low = new HTuple(), hv_high = new HTuple(), hv_algo = new HTuple(); HTuple hv_A_1_1Number = new HTuple(), hv_A_1_1_LineRowBegin = new HTuple(); HTuple hv_A_1_1_LineColBegin = new HTuple(), hv_A_1_1_LineRowEnd = new HTuple(); HTuple hv_A_1_1_LineColEnd = new HTuple(), hv_A_1_1_LineNr = new HTuple(); HTuple hv_A_1_1_LineNc = new HTuple(), hv_A_1_1_LineDist = new HTuple(); HTuple hv_STD_A_1_2_Row, hv_STD_A_1_2_Col, hv_STD_A_1_2_V_Row; HTuple hv_STD_A_1_2_V_Col, hv_A_1_2_X, hv_A_1_2_Y, hv_A_1_2_Pos_Row; HTuple hv_A_1_2_Pos_Col, hv_A_1_2Number = new HTuple(), hv_A_1_2_LineRowBegin = new HTuple(); HTuple hv_A_1_2_LineColBegin = new HTuple(), hv_A_1_2_LineRowEnd = new HTuple(); HTuple hv_A_1_2_LineColEnd = new HTuple(), hv_A_1_2_LineNr = new HTuple(); HTuple hv_A_1_2_LineNc = new HTuple(), hv_A_1_2_LineDist = new HTuple(); HTuple hv_DistanceMin, hv_DistanceMax; HTuple hv_MeasureReasult; // Initialize local and output iconic variables //HOperatorSet.GenEmptyObj(out ho_Image); //HOperatorSet.GenEmptyObj(out ho_AllModelContours); HOperatorSet.GenEmptyObj(out ho_A_1_1_Rectangle); HOperatorSet.GenEmptyObj(out ho_A_1_1_Image); HOperatorSet.GenEmptyObj(out ho_A_1_1_Edges); HOperatorSet.GenEmptyObj(out ho_A_1_1_Contours); HOperatorSet.GenEmptyObj(out ho_A_1_1_SelectedLines); HOperatorSet.GenEmptyObj(out ho_A_1_1_Line); HOperatorSet.GenEmptyObj(out ho_A_1_2_Rectangle); HOperatorSet.GenEmptyObj(out ho_A_1_2_Image); HOperatorSet.GenEmptyObj(out ho_A_1_2_Edges); HOperatorSet.GenEmptyObj(out ho_A_1_2_Contours); HOperatorSet.GenEmptyObj(out ho_A_1_2_SelectedLines); HOperatorSet.GenEmptyObj(out ho_A_1_2_Line); //Measure: SDMS_A //Author: John Hsieh //Date: 2012 //ho_Image.Dispose(); //HOperatorSet.ReadImage(out ho_Image, "Images/STD.bmp"); //dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle); // dev_update_off(...); only in hdevelop HOperatorSet.SetSystem("border_shape_models", "false"); //****Message Args hv_msgOffsetY = 100; hv_msgOffsetX = 100; //****Model All //HOperatorSet.ReadShapeModel("D:/Projects/Halcon/SDMS/SDMS_Measure/Model/MatchingAll.shm", // out hv_AllModelId); //ho_AllModelContours.Dispose(); //HOperatorSet.GetShapeModelContours(out ho_AllModelContours, hv_AllModelId, 1); //HOperatorSet.FindShapeModel(ho_Image, hv_AllModelId, (new HTuple(0)).TupleRad() // , (new HTuple(360)).TupleRad(), 0.5, 1, 0.5, "least_squares", 6, 0.75, out hv_AllModelRow, // out hv_AllModelColumn, out hv_AllModelAngle, out hv_AllModelScore); //****Model Args //STD 中心點 hv_STD_Row = 772; hv_STD_Col = 1003; //目前圖形 中心點 hv_Img_Row = hv_AllModelRow.Clone(); hv_Img_Col = hv_AllModelColumn.Clone(); //目前圖形 Rotate Angle hv_Img_Rotate_Angle = hv_AllModelAngle.Clone(); //目前圖形偏移量 hv_OffsetRow = hv_Img_Row - hv_STD_Row; hv_OffsetCol = hv_Img_Col - hv_STD_Col; //*****A //****A_1_1 //STD A_1_1_ 位置 HTuple newR, newC; hv_STD_A_1_1_Row = 1110; hv_STD_A_1_1_Col = 630; ReLocater(hv_STD_Row, hv_STD_Col, hv_Img_Rotate_Angle, hv_OffsetRow, hv_OffsetCol, hv_STD_A_1_1_Row, hv_STD_A_1_1_Col, out newR, out newC); //STD 向量 STD_A_1_1_ hv_STD_A_1_1_V_Row = hv_STD_A_1_1_Row - hv_STD_Row; hv_STD_A_1_1_V_Col = hv_STD_A_1_1_Col - hv_STD_Col; //A_1_1_X, A_1_1_Y 分量 hv_A_1_1_X = (hv_STD_A_1_1_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_A_1_1_V_Row * (hv_Img_Rotate_Angle.TupleSin() )); hv_A_1_1_Y = (hv_STD_A_1_1_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_A_1_1_V_Col * (hv_Img_Rotate_Angle.TupleSin() )); //目前圖形 A_1_1_ 位置 hv_A_1_1_Pos_Row = (hv_STD_Row + hv_A_1_1_Y) + hv_OffsetRow; hv_A_1_1_Pos_Col = (hv_STD_Col + hv_A_1_1_X) + hv_OffsetCol; hv_Corner_W = 30; hv_Corner_H = 120; ho_A_1_1_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_A_1_1_Rectangle, hv_A_1_1_Pos_Row, hv_A_1_1_Pos_Col, hv_Img_Rotate_Angle, hv_Corner_W, hv_Corner_H); ho_A_1_1_Image.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_A_1_1_Rectangle, out ho_A_1_1_Image); //corner detect hv_low = 60; hv_high = 90; ho_A_1_1_Edges.Dispose(); HOperatorSet.EdgesSubPix(ho_A_1_1_Image, out ho_A_1_1_Edges, "lanser2", 0.3, hv_low, hv_high); hv_algo = "lines"; ho_A_1_1_Contours.Dispose(); HOperatorSet.SegmentContoursXld(ho_A_1_1_Edges, out ho_A_1_1_Contours, hv_algo, 9, 4, 2); //取長線段 ho_A_1_1_SelectedLines.Dispose(); HOperatorSet.SelectShapeXld(ho_A_1_1_Contours, out ho_A_1_1_SelectedLines, "contlength", "and", 50, 99999); HOperatorSet.CountObj(ho_A_1_1_SelectedLines, out hv_A_1_1Number); if ((int)(new HTuple(hv_A_1_1Number.TupleGreater(0))) != 0) { ho_A_1_1_Line.Dispose(); HOperatorSet.SelectObj(ho_A_1_1_SelectedLines, out ho_A_1_1_Line, 1); HOperatorSet.FitLineContourXld(ho_A_1_1_Line, "tukey", -1, 0, 5, 2, out hv_A_1_1_LineRowBegin, out hv_A_1_1_LineColBegin, out hv_A_1_1_LineRowEnd, out hv_A_1_1_LineColEnd, out hv_A_1_1_LineNr, out hv_A_1_1_LineNc, out hv_A_1_1_LineDist); mResult = new DistanceResult() { FirstRowBegin = new HTuple(hv_A_1_1_LineRowBegin), FirstColBegin = new HTuple(hv_A_1_1_LineColBegin), FirstRowEnd = new HTuple(hv_A_1_1_LineRowEnd), FirstColEnd = new HTuple(hv_A_1_1_LineColEnd), Angle = this.hv_AllModelAngle, }; } //********* //****A_1_2 //STD A_1_2_ 位置 hv_STD_A_1_2_Row = 997; hv_STD_A_1_2_Col = 1376; //STD 向量 STD_A_1_2_ hv_STD_A_1_2_V_Row = hv_STD_A_1_2_Row - hv_STD_Row; hv_STD_A_1_2_V_Col = hv_STD_A_1_2_Col - hv_STD_Col; //A_1_2_X, A_1_2_Y 分量 hv_A_1_2_X = (hv_STD_A_1_2_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_A_1_2_V_Row * (hv_Img_Rotate_Angle.TupleSin() )); hv_A_1_2_Y = (hv_STD_A_1_2_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_A_1_2_V_Col * (hv_Img_Rotate_Angle.TupleSin() )); //目前圖形 A_1_2_ 位置 hv_A_1_2_Pos_Row = (hv_STD_Row + hv_A_1_2_Y) + hv_OffsetRow; hv_A_1_2_Pos_Col = (hv_STD_Col + hv_A_1_2_X) + hv_OffsetCol; //for (hv_MatchingObjIdx = 0; (int)hv_MatchingObjIdx <= (int)((new HTuple(hv_AllModelScore.TupleLength() // )) - 1); hv_MatchingObjIdx = (int)hv_MatchingObjIdx + 1) //{ hv_Corner_W = 30; hv_Corner_H = 600; ho_A_1_2_Rectangle.Dispose(); HOperatorSet.GenRectangle2(out ho_A_1_2_Rectangle, hv_A_1_2_Pos_Row, hv_A_1_2_Pos_Col, hv_Img_Rotate_Angle, hv_Corner_W, hv_Corner_H); //stop () ho_A_1_2_Image.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_A_1_2_Rectangle, out ho_A_1_2_Image); //corner detect hv_low = 60; hv_high = 90; ho_A_1_2_Edges.Dispose(); HOperatorSet.EdgesSubPix(ho_A_1_2_Image, out ho_A_1_2_Edges, "lanser2", 0.3, hv_low, hv_high); hv_algo = "lines"; ho_A_1_2_Contours.Dispose(); HOperatorSet.SegmentContoursXld(ho_A_1_2_Edges, out ho_A_1_2_Contours, hv_algo, 9, 4, 2); //取長線段 ho_A_1_2_SelectedLines.Dispose(); HOperatorSet.SelectShapeXld(ho_A_1_2_Contours, out ho_A_1_2_SelectedLines, "contlength", "and", 50, 99999); HOperatorSet.CountObj(ho_A_1_2_SelectedLines, out hv_A_1_2Number); if ((int)(new HTuple(hv_A_1_2Number.TupleGreater(0))) != 0) { ho_A_1_2_Line.Dispose(); HOperatorSet.SelectObj(ho_A_1_2_SelectedLines, out ho_A_1_2_Line, 1); HOperatorSet.FitLineContourXld(ho_A_1_2_Line, "tukey", -1, 0, 5, 2, out hv_A_1_2_LineRowBegin, out hv_A_1_2_LineColBegin, out hv_A_1_2_LineRowEnd, out hv_A_1_2_LineColEnd, out hv_A_1_2_LineNr, out hv_A_1_2_LineNc, out hv_A_1_2_LineDist); mResult.SecondColBegin = new HTuple(hv_A_1_2_LineColBegin); mResult.SecondColEnd = new HTuple(hv_A_1_2_LineColEnd); mResult.SecondRowBegin = new HTuple(hv_A_1_2_LineRowBegin); mResult.SecondRowEnd = new HTuple(hv_A_1_2_LineRowEnd); } //********* HOperatorSet.DistanceCc(ho_A_1_1_Line, ho_A_1_2_Line, "point_to_segment", out hv_DistanceMin, out hv_DistanceMax); mResult.Distance = new HTuple(hv_DistanceMin); /* //****Mark_A_C //STD Mark_A_C_ 位置 hv_STD_Mark_A_C_Row = 1400; hv_STD_Mark_A_C_Col = 1000; //STD 向量 STD_Mark_A_C_ hv_STD_Mark_A_C_V_Row = hv_STD_Mark_A_C_Row - hv_STD_Row; hv_STD_Mark_A_C_V_Col = hv_STD_Mark_A_C_Col - hv_STD_Col; //Mark_A_C_X, Mark_A_C_Y 分量 hv_Mark_A_C_X = (hv_STD_Mark_A_C_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_Mark_A_C_V_Row * (hv_Img_Rotate_Angle.TupleSin() )); hv_Mark_A_C_Y = (hv_STD_Mark_A_C_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_Mark_A_C_V_Col * (hv_Img_Rotate_Angle.TupleSin() )); //目前圖形 Mark_A_C_ 位置 hv_Mark_A_C_Pos_Row = (hv_STD_Row + hv_Mark_A_C_Y) + hv_OffsetRow; hv_Mark_A_C_Pos_Col = (hv_STD_Col + hv_Mark_A_C_X) + hv_OffsetCol; //****Mark_A_Start //STD Mark_A_Start_ 位置 hv_STD_Mark_A_Start_Row = 1400; hv_STD_Mark_A_Start_Col = 618; //STD 向量 STD_Mark_A_Start_ hv_STD_Mark_A_Start_V_Row = hv_STD_Mark_A_Start_Row - hv_STD_Row; hv_STD_Mark_A_Start_V_Col = hv_STD_Mark_A_Start_Col - hv_STD_Col; //Mark_A_Start_X, Mark_A_Start_Y 分量 hv_Mark_A_Start_X = (hv_STD_Mark_A_Start_V_Col * (hv_Img_Rotate_Angle.TupleCos() )) + (hv_STD_Mark_A_Start_V_Row * (hv_Img_Rotate_Angle.TupleSin())); hv_Mark_A_Start_Y = (hv_STD_Mark_A_Start_V_Row * (hv_Img_Rotate_Angle.TupleCos() )) - (hv_STD_Mark_A_Start_V_Col * (hv_Img_Rotate_Angle.TupleSin())); //目前圖形 Mark_A_Start_ 位置 hv_Mark_A_Start_Pos_Row = (hv_STD_Row + hv_Mark_A_Start_Y) + hv_OffsetRow; hv_Mark_A_Start_Pos_Col = (hv_STD_Col + hv_Mark_A_Start_X) + hv_OffsetCol; //****Mark_A_End //STD Mark_A_End_ 位置 hv_STD_Mark_A_End_Row = 1400; hv_STD_Mark_A_End_Col = 1415; //STD 向量 STD_Mark_A_End_ hv_STD_Mark_A_End_V_Row = hv_STD_Mark_A_End_Row - hv_STD_Row; hv_STD_Mark_A_End_V_Col = hv_STD_Mark_A_End_Col - hv_STD_Col; //Mark_A_End_X, Mark_A_End_Y 分量 hv_Mark_A_End_X = (hv_STD_Mark_A_End_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_Mark_A_End_V_Row * (hv_Img_Rotate_Angle.TupleSin() )); hv_Mark_A_End_Y = (hv_STD_Mark_A_End_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_Mark_A_End_V_Col * (hv_Img_Rotate_Angle.TupleSin() )); //目前圖形 Mark_A_End_ 位置 hv_Mark_A_End_Pos_Row = (hv_STD_Row + hv_Mark_A_End_Y) + hv_OffsetRow; hv_Mark_A_End_Pos_Col = (hv_STD_Col + hv_Mark_A_End_X) + hv_OffsetCol; HOperatorSet.SetTposition(hv_WindowHandle, hv_Mark_A_C_Pos_Row - 25, hv_Mark_A_C_Pos_Col); HOperatorSet.WriteString(hv_WindowHandle, "A"); HOperatorSet.DispArrow(hv_WindowHandle, hv_Mark_A_C_Pos_Row, hv_Mark_A_C_Pos_Col - 50, hv_Mark_A_Start_Pos_Row, hv_Mark_A_Start_Pos_Col, 5); HOperatorSet.DispArrow(hv_WindowHandle, hv_Mark_A_C_Pos_Row, hv_Mark_A_C_Pos_Col + 50, hv_Mark_A_End_Pos_Row, hv_Mark_A_End_Pos_Col, 5); */ //********* hv_MeasureReasult = hv_DistanceMin.Clone(); //*****A End //ho_Image.Dispose(); //ho_AllModelContours.Dispose(); ho_A_1_1_Rectangle.Dispose(); ho_A_1_1_Image.Dispose(); ho_A_1_1_Edges.Dispose(); ho_A_1_1_Contours.Dispose(); ho_A_1_1_SelectedLines.Dispose(); ho_A_1_1_Line.Dispose(); ho_A_1_2_Rectangle.Dispose(); ho_A_1_2_Image.Dispose(); ho_A_1_2_Edges.Dispose(); ho_A_1_2_Contours.Dispose(); ho_A_1_2_SelectedLines.Dispose(); ho_A_1_2_Line.Dispose(); return mResult; }
public DistanceResult(DistanceResult result) : this(result.FirstRowBegin, result.FirstColBegin, result.FirstRowEnd, result.FirstColEnd, result.SecondRowBegin, result.SecondColBegin, result.SecondRowEnd, result.SecondColEnd, result.Angle, result.Distance) { }
public static DistanceResult PointToPoint(Measurement first, Measurement second, HTuple angle, LineDirection direction) { DistanceResult result = null; var p1 = first.GetViewModel(); var p2 = second.GetViewModel(); if (p1 == null || p2 == null) return null; if (p1.Row1 != null && p1.Row1.TupleLength() > 0 && p2.Row1 != null && p2.Row1.TupleLength() > 0) { HTuple distanceMin; HOperatorSet.DistancePp(p1.Row1, p1.Col1, p2.Row1, p2.Col1, out distanceMin); result = new DistanceResult() { Distance = distanceMin, Direction = direction, Angle = angle, FirstRowBegin = p1.Row1, FirstColBegin = p1.Col1, FirstRowEnd = p2.Row1, FirstColEnd = p2.Col1, }; } return result; }
public static DistanceResult PointToLine(Measurement first, Measurement second, HTuple angle) { DistanceResult result = null; var firstData = first.GetViewModel(); var secData = second.GetViewModel(); if (firstData.Row1 != null && firstData.Row1.TupleLength() > 0 && secData.Row1 != null && secData.Row1.TupleLength() > 0) { HTuple distanceMin, distanceMax; var point = (firstData.Row2 != null) ? secData : firstData; var line = (firstData.Row2 != null) ? firstData : secData; HOperatorSet.DistancePs(point.Row1, point.Col1, line.Row1, line.Col1, line.Row2, line.Col2, out distanceMin, out distanceMax); result = new DistanceResult() { FirstRowBegin = new HTuple(line.Row1), FirstColBegin = new HTuple(line.Col1), FirstRowEnd = new HTuple(line.Row2), FirstColEnd = new HTuple(line.Col2), SecondRowBegin = new HTuple(point.Row1), SecondColBegin = new HTuple(point.Col1), //SecondRowEnd = new HTuple(line2.Row2), //SecondColEnd = new HTuple(line2.Col2), Direction = LineDirection.Vertical, Distance = new HTuple(distanceMin), Angle = angle, }; } return result; }
public MeasureResult Action() { #region 輸出結果 DistanceResult mResult = null; #endregion // Local iconic variables HObject ho_ROI_Rec = null; HObject ho_ROI_Image = null, ho_ROI_Edges = null, ho_ROI_ContoursSplit = null; HObject ho_ROI_SortedContours = null, ho_FirstLine = null, ho_SecondLine = null; // Local control variables HTuple hv_msgOffsetY, hv_msgOffsetX; HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol, hv_STD_B_Row, hv_STD_B_Col; HTuple hv_STD_B_V_Row, hv_STD_B_V_Col, hv_B_X, hv_B_Y; HTuple hv_B_Pos_Row, hv_B_Pos_Col, hv_ROI_W = new HTuple(); HTuple hv_ROI_H = new HTuple(), hv_low = new HTuple(), hv_high = new HTuple(); HTuple hv_algo = new HTuple(), hv_Number = new HTuple(), hv_FirstRowBegin = new HTuple(); HTuple hv_FirstColBegin = new HTuple(), hv_FirstRowEnd = new HTuple(); HTuple hv_FirstColEnd = new HTuple(), hv_FirstNr = new HTuple(); HTuple hv_FirstNc = new HTuple(), hv_FirstDist = new HTuple(); HTuple hv_SecondRowBegin = new HTuple(), hv_SecondColBegin = new HTuple(); HTuple hv_SecondRowEnd = new HTuple(), hv_SecondColEnd = new HTuple(); HTuple hv_SecondNr = new HTuple(), hv_SecondNc = new HTuple(); HTuple hv_SecondDist = new HTuple(), hv_minDist = new HTuple(); HTuple hv_maxDist = new HTuple(), hv_STD_Mark_B_C_Row = new HTuple(); HTuple hv_STD_Mark_B_C_Col = new HTuple(), hv_STD_Mark_B_Start_Row = new HTuple(); HTuple hv_STD_Mark_B_Start_Col = new HTuple(), hv_STD_Mark_B_End_Row = new HTuple(); HTuple hv_STD_Mark_B_End_Col = new HTuple(), hv_STD_Mark_B_C_V_Row = new HTuple(); HTuple hv_STD_Mark_B_C_V_Col = new HTuple(), hv_Mark_B_C_X = new HTuple(); HTuple hv_Mark_B_C_Y = new HTuple(), hv_Mark_B_C_Pos_Row = new HTuple(); HTuple hv_Mark_B_C_Pos_Col = new HTuple(), hv_STD_Mark_B_Start_V_Row = new HTuple(); HTuple hv_STD_Mark_B_Start_V_Col = new HTuple(), hv_Mark_B_Start_X = new HTuple(); HTuple hv_Mark_B_Start_Y = new HTuple(), hv_Mark_B_Start_Pos_Row = new HTuple(); HTuple hv_Mark_B_Start_Pos_Col = new HTuple(), hv_STD_Mark_B_End_V_Row = new HTuple(); HTuple hv_STD_Mark_B_End_V_Col = new HTuple(), hv_Mark_B_End_X = new HTuple(); HTuple hv_Mark_B_End_Y = new HTuple(), hv_Mark_B_End_Pos_Row = new HTuple(); HTuple hv_Mark_B_End_Pos_Col = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ROI_Rec); HOperatorSet.GenEmptyObj(out ho_ROI_Image); HOperatorSet.GenEmptyObj(out ho_ROI_Edges); HOperatorSet.GenEmptyObj(out ho_ROI_ContoursSplit); HOperatorSet.GenEmptyObj(out ho_ROI_SortedContours); HOperatorSet.GenEmptyObj(out ho_FirstLine); HOperatorSet.GenEmptyObj(out ho_SecondLine); //Measure: SDMS_B //Author: John Hsieh //Date: 2012 //ho_Image.Dispose(); //HOperatorSet.ReadImage(out ho_Image, "Images/STD.bmp"); //dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle); //// dev_update_off(...); only in hdevelop HOperatorSet.SetSystem("border_shape_models", "false"); //****Message Args hv_msgOffsetY = 100; hv_msgOffsetX = 100; //****Model Args //STD 中心點 hv_STD_Row = 772; hv_STD_Col = 1003; //目前圖形 中心點 hv_Img_Row = hv_AllModelRow.Clone(); hv_Img_Col = hv_AllModelColumn.Clone(); //目前圖形 Rotate Angle hv_Img_Rotate_Angle = hv_AllModelAngle.Clone(); //目前圖形偏移量 hv_OffsetRow = hv_Img_Row - hv_STD_Row; hv_OffsetCol = hv_Img_Col - hv_STD_Col; //****Display if (HDevWindowStack.IsOpen()) { HOperatorSet.ClearWindow(HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } //*****B //STD B_ 位置 hv_STD_B_Row = 743; hv_STD_B_Col = 1118; //STD 向量 STD_B_ hv_STD_B_V_Row = hv_STD_B_Row - hv_STD_Row; hv_STD_B_V_Col = hv_STD_B_Col - hv_STD_Col; //B_X, B_Y 分量 hv_B_X = (hv_STD_B_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_B_V_Row * (hv_Img_Rotate_Angle.TupleSin() )); hv_B_Y = (hv_STD_B_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_B_V_Col * (hv_Img_Rotate_Angle.TupleSin() )); //目前圖形 B_ 位置 hv_B_Pos_Row = (hv_STD_Row + hv_B_Y) + hv_OffsetRow; hv_B_Pos_Col = (hv_STD_Col + hv_B_X) + hv_OffsetCol; hv_ROI_W = 150; hv_ROI_H = 600; ho_ROI_Rec.Dispose(); HOperatorSet.GenRectangle2(out ho_ROI_Rec, hv_B_Pos_Row, hv_B_Pos_Col, hv_Img_Rotate_Angle, hv_ROI_W, hv_ROI_H); //stop () ho_ROI_Image.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_ROI_Rec, out ho_ROI_Image); //corner detect hv_low = 130; hv_high = 180; ho_ROI_Edges.Dispose(); HOperatorSet.EdgesSubPix(ho_ROI_Image, out ho_ROI_Edges, "lanser2", 0.3, hv_low, hv_high); //stop () hv_algo = "lines"; ho_ROI_ContoursSplit.Dispose(); HOperatorSet.SegmentContoursXld(ho_ROI_Edges, out ho_ROI_ContoursSplit, hv_algo, 9, 4, 2); ho_ROI_SortedContours.Dispose(); HOperatorSet.SortContoursXld(ho_ROI_ContoursSplit, out ho_ROI_SortedContours, "upper_left", "true", "row"); HOperatorSet.CountObj(ho_ROI_SortedContours, out hv_Number); if (HDevWindowStack.IsOpen()) { //dev_display (ROI_SortedContours) } //兩線段 if ((int)(new HTuple(hv_Number.TupleEqual(2))) != 0) { ho_FirstLine.Dispose(); HOperatorSet.SelectObj(ho_ROI_SortedContours, out ho_FirstLine, 1); ho_SecondLine.Dispose(); HOperatorSet.SelectObj(ho_ROI_SortedContours, out ho_SecondLine, 2); HOperatorSet.FitLineContourXld(ho_FirstLine, "tukey", -1, 0, 5, 2, out hv_FirstRowBegin, out hv_FirstColBegin, out hv_FirstRowEnd, out hv_FirstColEnd, out hv_FirstNr, out hv_FirstNc, out hv_FirstDist); HOperatorSet.FitLineContourXld(ho_SecondLine, "tukey", -1, 0, 5, 2, out hv_SecondRowBegin, out hv_SecondColBegin, out hv_SecondRowEnd, out hv_SecondColEnd, out hv_SecondNr, out hv_SecondNc, out hv_SecondDist); //line to line //取兩線段的最小距離 HOperatorSet.DistanceSs(hv_FirstRowBegin, hv_FirstColBegin, hv_FirstRowEnd, hv_FirstColEnd, hv_SecondRowBegin, hv_SecondColBegin, hv_SecondRowEnd, hv_SecondColEnd, out hv_minDist, out hv_maxDist); mResult = new DistanceResult() { FirstRowBegin = new HTuple(hv_FirstRowBegin), FirstColBegin = new HTuple(hv_FirstColBegin), FirstRowEnd = new HTuple(hv_FirstRowEnd), FirstColEnd = new HTuple(hv_FirstColEnd), SecondRowBegin = new HTuple(hv_SecondRowBegin), SecondColBegin = new HTuple(hv_SecondColBegin), SecondRowEnd = new HTuple(hv_SecondRowEnd), SecondColEnd = new HTuple(hv_SecondColEnd), Angle = new HTuple(this.hv_AllModelAngle), Distance = new HTuple(hv_minDist), Direction = LineDirection.Vertical, }; } //*****B End ho_ROI_Rec.Dispose(); ho_ROI_Image.Dispose(); ho_ROI_Edges.Dispose(); ho_ROI_ContoursSplit.Dispose(); ho_ROI_SortedContours.Dispose(); ho_FirstLine.Dispose(); ho_SecondLine.Dispose(); return mResult; }