public ViewWindow(HWindowControl window, Label location_point) { this._hWndControl = new ViewROI.HWndCtrl(window, location_point); this._roiController = new ViewROI.ROIController(); this._hWndControl.setROIController(this._roiController); this._hWndControl.setViewState(ViewROI.HWndCtrl.MODE_VIEW_NONE); }
/// <summary> /// 初始化 /// </summary> /// <param name="roiController"></param> public void Init(ROIController roiController, HWndCtrl mView, GeoDataGridViewManager geoManager) { _roiController = roiController; _mView = mView; _geoManager = geoManager; if (_roiController != null) { _roiController.NotifyRCObserver += new IconicDelegate(resetFinalCheckedBox); } }
public bool Init(ROIController roicontroller, MeasureAssistant mAssistant , double resolution, int roundDigit, string[] inVisibleFields) { MessageLabel.Text = ""; var success = true; var model = new List<RefCoordinate>() { new RefCoordinate() { ID = "", Name = "Default", Desc = "影像座標" }, }; _dfCoordinateBindingList = new BindingList<RefCoordinate>(model); _geoManager = new GeoDataGridViewManager(GeoDataGridView, GeoContextMenuStrip , _dfCoordinateBindingList, inVisibleFields , ConfigurationMM.GeoImageDictionary , resolution, roundDigit, mAssistant); _roiController = roicontroller; initGeoContextMenu(); initCoordinateComboBox(); initLengthUnitComboBox(); initClearButton(); initExportButton(); initGeoTreeView(); return success; }
/// <summary> /// Registers an instance of an ROIController with this window /// controller (and vice versa). /// </summary> /// <param name="rC"> /// Controller that manages interactive ROIs for the HALCON window /// </param> public void useROIController(ROIController rC) { roiManager = rC; rC.setViewController(this); }
public MeasureViewModel GetMidLine() { #region 輸出結果 DistanceResult mResult = null; MeasureViewModel midLineModel = null; #endregion HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol; HOperatorSet.SetSystem("border_shape_models", "false"); //STD 中心點 hv_STD_Row = 839.5; hv_STD_Col = 1046.5; //目前圖形 中心點 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; //第一個 線段 ROI //HTuple f_ROI_Row = 528.01953125; //HTuple f_ROI_Col = 821.555555555556; //HTuple f_angle = 0; //HTuple f_ROI_Length1 = 20; //HTuple f_ROI_Length2 = 93; HTuple f_ROI_Row = 528.01953125; HTuple f_ROI_Col = 1067.82352941176; HTuple f_angle = 0; HTuple f_ROI_Length1 = 20.9019607843137; HTuple f_ROI_Length2 = 90.669921875; HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle; HTuple f_ROI_Cur_Row, f_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col); //第二個 線段 ROI //HTuple s_ROI_Row = 528.03515625; //HTuple s_ROI_Col = 858.300653594771; //HTuple s_angle = 3.14159265358979; //HTuple s_ROI_Length1 = 20; //HTuple s_ROI_Length2 = 93; HTuple s_ROI_Row = 528.03515625; HTuple s_ROI_Col = 1102.59477124183; HTuple s_angle = 3.14159265358979; HTuple s_ROI_Length1 = 17.3856209150328; HTuple s_ROI_Length2 = 91.6015625; HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle; HTuple s_ROI_Cur_Row, s_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col); #region Measure var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_Image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "nearest_neighbor"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "all"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiF.MakeROI(416, 998, 0, 26.5, 71.2); roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2); var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiS.MakeROI(400, 1041, 0, 13.3, 75.7); roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2); var lineF = new MeasurementEdge(roiF, cAssistant); var lineS = new MeasurementEdge(roiS, cAssistant); mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal); var firstModel = lineF.GetViewModel(); var secondModel = lineS.GetViewModel(); if (firstModel != null && secondModel != null && firstModel.Distance != null && secondModel.Distance != null && firstModel.Distance.TupleLength() > 0 && secondModel.Distance.TupleLength() > 0) { //作線段 var centerRow = (f_ROI_Cur_Row + s_ROI_Cur_Row) / 2.0; var centerCol = (f_ROI_Cur_Col + s_ROI_Cur_Col) / 2.0; midLineModel = DistanceHelper.MakeLine(centerRow, centerCol, hv_AllModelAngle, mResult.Distance / 2.0); } return midLineModel; #endregion }
/* To create the measure controller class the ROI controller has to be provided for initialization */ public MeasureAssistant(ROIController CRoi) { exceptionText = ""; roiController = CRoi; mROIList = roiController.getROIList(); mMeasureList = new ArrayList(15); mIsCalibValid = false; mActRoiIdx = -1; }
public MeasureResult Action() { #region 輸出結果 DistanceResult mResult = null; #endregion HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol; HOperatorSet.SetSystem("border_shape_models", "false"); //STD 中心點 hv_STD_Row = 839.5; hv_STD_Col = 1046.5; //目前圖形 中心點 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; //第一個 線段 ROI HTuple f_ROI_Row = 341.21875; HTuple f_ROI_Col = 803.078431372549; HTuple f_angle = 1.5707963267949; HTuple f_ROI_Length1 = 77.5390625; HTuple f_ROI_Length2 = 148.705882352941; HTuple f_angleOffset = f_angle - hv_Img_Rotate_Angle; HTuple f_ROI_Cur_Row, f_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col); // //第二個 線段 ROI HTuple s_ROI_Row = 774.4765625; HTuple s_ROI_Col = 709.622549019608; HTuple s_angle = 0; HTuple s_ROI_Length1 = 45.2843137254902; HTuple s_ROI_Length2 = 30.15234375; HTuple s_angleOffset = s_angle - hv_Img_Rotate_Angle; HTuple s_ROI_Cur_Row, s_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col); #region Measure var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_Image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "nearest_neighbor"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "all"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angleOffset, f_ROI_Length1, f_ROI_Length2); var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Point }; roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angleOffset, s_ROI_Length1, s_ROI_Length2); var lineF = new MeasurementEdge(roiF, cAssistant); var pointS = new MeasurementEdge(roiS, cAssistant); mResult = DistanceHelper.PointToLine(lineF, pointS, this.hv_AllModelAngle); #endregion return mResult; }
/// <summary> /// Registers an instance of an ROIController with this window /// controller (and vice versa). /// </summary> /// <param name="rC"> /// Controller that manages interactive ROIs for the HALCON window /// </param> protected internal void setROIController(ROIController rC) { roiManager = rC; rC.setViewController(this); this.setViewState(HWndCtrl.MODE_VIEW_NONE); }
/// <summary> /// Loads MeasureForm and initializes view functions /// to include in the MeasureAssistant. /// </summary> private void MeasureForm_Load(object sender, System.EventArgs e) { mView = new HWndCtrl(viewPort); roiController = new ROIController(); mView.useROIController(roiController); mAssistant = new MeasureAssistant(roiController); mShadow = new HXLDCont(); mView.setViewState(HWndCtrl.MODE_VIEW_NONE); mView.changeGraphicSettings(GraphicsContext.GC_LINEWIDTH, 1); roiController.NotifyRCObserver = new IconicDelegate(UpdateROIData); mAssistant.NotifyMeasureObserver = new MeasureDelegate(UpdateMeasureResults); plotGraphWindow = new FunctionPlot(panelAxis, true); openImageFileDialog.InitialDirectory = (string)(HSystem.GetSystem("image_dir").TupleSplit(";")); Init(); mView.setDispLevel(HWndCtrl.MODE_EXCLUDE_ROI); }
/// <summary> /// 初始化 /// </summary> /// <param name="message"></param> /// <returns></returns> public bool Init(out string message) { _isReady = true; message = ""; try { _roiController = new ROIController(); mView = new HWndCtrl(this.ViewPort); mView.useROIController(_roiController); _roiController.NotifyRCObserver = new IconicDelegate(On_ROIUpdated);// ROI 操作通知 mAssistant = new MeasureAssistant(_roiController); mAssistant.NotifyMeasureObserver = new MeasureDelegate(UpdateMeasureResults); initFileDialog(); initializeGrabImage(); } catch (Exception ex) { _isReady = false; message = ex.Message; } return _isReady; }
/// <summary> /// Registers an instance of an ROIController with this window /// controller (and vice versa). /// </summary> /// <param name="rC"> /// Controller that manages interactive ROIs for the HALCON window /// </param> public void useROIController(ROIController rC) { _roiManager = rC; rC.setViewController(this); }
/// <summary> /// 擬合圓 /// </summary> /// <param name="f_radius">圓 ROI 半徑</param> /// <param name="f_ROI_Cur_Row">圓 ROI Row 座標</param> /// <param name="f_ROI_Cur_Col">圓 ROI Col 座標</param> /// <returns></returns> public static MeasureViewModel GetFitCircleModel(HObject ho_image, HTuple f_radius, HTuple f_ROI_Cur_Row, HTuple f_ROI_Cur_Col) { var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "nearest_neighbor"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "all"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var roiF = new ROICircle() { ROIMeasureType = MeasureType.Circle }; //roiF.MakeROI(416, 998, 0, 26.5, 71.2); roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_radius); var fitCircle = new MeasurementCircle(roiF, cAssistant); var model = fitCircle.GetViewModel(); return model; }
/// <summary> /// In the beginning, some initialization tasks are performed. /// The control instances, like ROIController and WindowController, /// are initialized and registered with each other. Also, the /// delegates of the models are linked to update methods /// to get notified about changes. /// </summary> public MatchingForm() { InitializeComponent(); mView = new HWndCtrl(viewPort); createModelWindowMode = Color.RoyalBlue; trainModelWindowMode = Color.Chartreuse; roiController = new ROIController(); mView.useROIController(roiController); roiController.setROISign(ROIController.MODE_ROI_POS); mView.NotifyIconObserver = new IconicDelegate(UpdateViewData); roiController.NotifyRCObserver = new IconicDelegate(UpdateViewData); mView.setViewState(HWndCtrl.MODE_VIEW_NONE); locked = true; parameterSet = new MatchingParam(); Init(parameterSet); locked = false; mAssistant = new MatchingAssistant(parameterSet); mAssistant.NotifyIconObserver = new MatchingDelegate(UpdateMatching); mAssistant.NotifyParamObserver = new AutoParamDelegate(UpdateButton); speedOptHandler = new MatchingOptSpeed(mAssistant, parameterSet); speedOptHandler.NotifyStatisticsObserver = new StatisticsDelegate(UpdateStatisticsData); inspectOptHandler = new MatchingOptStatistics(mAssistant, parameterSet); inspectOptHandler.NotifyStatisticsObserver = new StatisticsDelegate(UpdateStatisticsData); }
/// <summary> /// Defines the initial settings for the window /// control. In the very beginning, the window control needs /// to know the view mode of the application form to perform /// the right behavior for incoming mouse events on the /// HALCON window. /// </summary> private void InteractiveForm_Load(object sender, System.EventArgs e) { String fileName = "patras"; HImage image; viewController = new HWndCtrl(viewPort); roiController = new ROIController(); viewController.useROIController(roiController); viewController.setViewState(HWndCtrl.MODE_VIEW_NONE); try { image = new HImage(fileName); } catch(HOperatorException) { MessageBox.Show("Problem occured while reading file!", "InteractROIForm", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } viewController.addIconicVar(image); viewController.repaint(); }
public MeasureViewModel GetMidLine() { #region 輸出結果 LineResult mResult = null; MeasureViewModel midLineModel = null; #endregion HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol; HOperatorSet.SetSystem("border_shape_models", "false"); //STD 中心點 hv_STD_Row = 839.5; hv_STD_Col = 1046.5; //目前圖形 中心點 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; //第一個 線段 ROI HTuple f_ROI_Row = 528.064453125; HTuple f_ROI_Col = 802.751633986928; HTuple f_angle = 0; HTuple f_ROI_Length1 = 38.2679738562091; HTuple f_ROI_Length2 = 99.6328125; HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle; HTuple f_ROI_Cur_Row, f_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col); //第二個 線段 ROI HTuple s_ROI_Row = 523.408203125; HTuple s_ROI_Col = 853.542483660131; HTuple s_angle = 3.14159265358979; HTuple s_ROI_Length1 = 27.4509803921568; HTuple s_ROI_Length2 = 105.341796875; HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle; HTuple s_ROI_Cur_Row, s_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col); #region Measure var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_Image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "bilinear"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "last"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiF.MakeROI(416, 998, 0, 26.5, 71.2); roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2); var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiS.MakeROI(400, 1041, 0, 13.3, 75.7); roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2); var lineF = new MeasurementEdge(roiF, cAssistant); var lineS = new MeasurementEdge(roiS, cAssistant); mResult = DistanceHelper.CalculateSymmetryLine(lineF.GetViewModel(), lineS.GetViewModel()); //mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal); midLineModel = new MeasureViewModel() { Row1 = mResult.Row1, Row2 = mResult.Row2, Col1 = mResult.Col1, Col2 = mResult.Col2, Distance = mResult.Distance, }; //var firstModel = lineF.GetViewModel(); //var secondModel = lineS.GetViewModel(); //if (firstModel != null && secondModel != null && firstModel.Distance != null && secondModel.Distance != null // && firstModel.Distance.TupleLength() > 0 && secondModel.Distance.TupleLength() > 0) //{ // //作線段 // var centerRow = (f_ROI_Cur_Row + s_ROI_Cur_Row) / 2.0; // var centerCol = (f_ROI_Cur_Col + s_ROI_Cur_Col) / 2.0; // midLineModel = DistanceHelper.MakeLine(centerRow, centerCol, hv_AllModelAngle, mResult.Distance / 2.0); //} return midLineModel; #endregion }
public MeasureResult Action() { #region 輸出結果 DistanceResult mResult = null; #endregion HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol; HOperatorSet.SetSystem("border_shape_models", "false"); //STD 中心點 hv_STD_Row = 839.5; hv_STD_Col = 1046.5; //目前圖形 中心點 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; //第一個 線段 ROI HTuple f_ROI_Row = 416.40625; HTuple f_ROI_Col = 752; HTuple f_angle = 0; HTuple f_ROI_Length1 = 56; HTuple f_ROI_Length2 = 256.25; HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle; HTuple f_ROI_Cur_Row, f_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col); //第二個 線段 ROI HTuple s_ROI_Row = 435.638671875; HTuple s_ROI_Col = 1429.16339869281; HTuple s_angle = 0; HTuple s_ROI_Length1 = 49.8594771241831; HTuple s_ROI_Length2 = 241.6796875; HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle; HTuple s_ROI_Cur_Row, s_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col); #region Measure var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_Image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "nearest_neighbor"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "all"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiF.MakeROI(416, 998, 0, 26.5, 71.2); roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2); var roiS = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiS.MakeROI(400, 1041, 0, 13.3, 75.7); roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2); var lineF = new MeasurementEdge(roiF, cAssistant); var lineS = new MeasurementEdge(roiS, cAssistant); mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal); #endregion return mResult; }
public MeasureResult Action() { #region 輸出結果 LineResult mResult = null; #endregion HTuple hv_STD_Row; HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle; HTuple hv_OffsetRow, hv_OffsetCol; HOperatorSet.SetSystem("border_shape_models", "false"); //STD 中心點 hv_STD_Row = 839.5; hv_STD_Col = 1046.5; //目前圖形 中心點 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; //第一個 線段 ROI //HTuple f_ROI_Row = 341.21875; //HTuple f_ROI_Col = 803.078431372549; //HTuple f_angle = 1.5707963267949; //HTuple f_ROI_Length1 = 77.5390625; //HTuple f_ROI_Length2 = 148.705882352941; HTuple f_ROI_Row = 357.08984375; HTuple f_ROI_Col = 816.555555555556; HTuple f_angle = 1.5707963267949; HTuple f_ROI_Length1 = 69.8359375; HTuple f_ROI_Length2 = 122.277777777778; HTuple f_angleOffset = f_angle - hv_Img_Rotate_Angle; HTuple f_ROI_Cur_Row, f_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col); //兩線段交點 HTuple p1_ROI_Row = 715.40234375; HTuple p1_ROI_Col = 744.222222222222; HTuple p1_angle = 0.764250656215704; HTuple p1_ROI_Length1 = 68.0072446324003; HTuple p1_ROI_Length2 = 105.756749157524; HTuple p1_angleOffset = p1_angle - hv_Img_Rotate_Angle; HTuple p1_ROI_Cur_Row, p1_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol , p1_ROI_Row, p1_ROI_Col, out p1_ROI_Cur_Row, out p1_ROI_Cur_Col); HTuple p2_ROI_Row = 794.64453125; HTuple p2_ROI_Col = 702.888888888889; HTuple p2_angle = 0; HTuple p2_ROI_Length1 = 100; HTuple p2_ROI_Length2 = 50; HTuple p2_angleOffset = p2_angle - hv_Img_Rotate_Angle; HTuple p2_ROI_Cur_Row, p2_ROI_Cur_Col; PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol , p2_ROI_Row, p2_ROI_Col, out p2_ROI_Cur_Row, out p2_ROI_Cur_Col); #region Measure var cROIController = new ROIController(); var cAssistant = new MeasureAssistant(cROIController); var hImage = ho_Image as HImage; cAssistant.setImage(hImage); /*參數值*/ cAssistant.mThresh = 40.0; cAssistant.mSigma = 1.0; cAssistant.mRoiWidth = 10; cAssistant.mInterpolation = "nearest_neighbor"; cAssistant.mSelPair = false; cAssistant.mTransition = "all"; cAssistant.mPosition = "all"; cAssistant.mDispEdgeLength = 30; cAssistant.mDispROIWidth = true; cAssistant.setUnit("cm"); cAssistant.mInitThresh = 40.0; cAssistant.mInitSigma = 1.0; cAssistant.mInitRoiWidth = 10; var p1Line = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiF.MakeROI(416, 998, 0, 26.5, 71.2); p1Line.MakeROI(p1_ROI_Cur_Row, p1_ROI_Cur_Col, p1_angleOffset, p1_ROI_Length1, p1_ROI_Length2); var p2Line = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; //roiS.MakeROI(400, 1041, 0, 13.3, 75.7); p2Line.MakeROI(p2_ROI_Cur_Row, p2_ROI_Cur_Col, p2_angleOffset, p2_ROI_Length1, p2_ROI_Length2); var p1F = new MeasurementEdge(p1Line, cAssistant); var p2S = new MeasurementEdge(p2Line, cAssistant); var angleResult = DistanceHelper.AngleLineToLine(p1F, p2S); var roiF = new ROIRectangle2() { ROIMeasureType = MeasureType.Line }; roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angleOffset, f_ROI_Length1, f_ROI_Length2); var lineF = new MeasurementEdge(roiF, cAssistant); if (angleResult != null && lineF != null) { var pointViewModel = new MeasureViewModel() { Row1 = angleResult.Row, Col1 = angleResult.Col, }; var lineViewModel = lineF.GetViewModel(); var distance = DistanceHelper.PointToLine(lineViewModel, pointViewModel); mResult = new LineResult() { Row1 = lineViewModel.Row2, Col1 = lineViewModel.Col2, Row2 = pointViewModel.Row1, Col2 = pointViewModel.Col1, Distance = distance, }; } #endregion return mResult; }