private void Form1_Load(object sender, EventArgs e) { _viewCtrl = new HWndCtrl(hWindowControl1); _roiCtrl = new ROIController(); _viewCtrl.useROIController(_roiCtrl); _roiCtrl.viewController.viewPort.HMouseMove += ViewPort_HMouseMove;; }
private void AddRoiToRoiController(string roiType, string roiName, ROIController roiController) { var newRoi = (ROI)Activator.CreateInstance(Type.GetType(roiType) !); newRoi.RoiName = roiName; roiController.setROIShape(newRoi); }
public EditHalconFormBase(bool showResult) { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; hWindow = new HWindowControl(); hWindow.Dock = DockStyle.Fill; this.tabCurrent.Controls.Clear(); this.tabCurrent.Controls.Add(hWindow); mView = new HWndCtrl(this.hWindow); mView.changeGraphicSettings(GraphicsContext.GC_LINESTYLE, new HTuple()); createModelWindowMode = Color.RoyalBlue; trainModelWindowMode = Color.Chartreuse; roiController = new ROIController(); roiController.ROISelected += RoiController_ROISelected; roiController.setROISign(ROIController.MODE_ROI_POS); mView.NotifyIconObserver = new IconicDelegate(UpdateViewData); roiController.NotifyRCObserver = new IconicDelegate(UpdateViewData); mView.useROIController(roiController); mView.setViewState(HWndCtrl.MODE_VIEW_ZOOM_MOVE); halconEditable = this as IHalconEditable; this.nudSettlingTime.Maximum = 1000; this.btnStop.Visible = showResult; this.btnIgnore.Visible = showResult; this.chxFixedROI.Checked = showResult; }
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> /// 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 FindMax(int Station = 1) { InitializeComponent(); station = Station; Path = AppDomain.CurrentDomain.BaseDirectory + "Setting" + Station.ToString() + "\\"; if (!Directory.Exists(Path)) { Directory.CreateDirectory(Path); } if (Station == 1) { this.Text = "工位一感光片设置"; } else { this.Text = "工位二感光片设置"; } CircleLine = new LookForCircleLine.mainUtl(Path); panelControl1.Controls.Add(CircleLine); Size sz = CircleLine.Size; panelControl1.Size = sz; CircleLine.Dock = DockStyle.Fill; CircleLine.isFitWindow = false; int height = panelControl1.Size.Height; int width = (int)(height * (0.006 / 0.05) * 5); CircleLine.splitContainer1.SplitterDistance = width; //splitContainerControl1.SplitterPosition = sz.Width; roiController = CircleLine.hWindow_Final1.viewWindow._roiController; roiController.NotifyRCObserver = new IconicDelegate(ROiMove); UpDownBase upDown = (UpDownBase)numericUpDown1; upDown.TextChanged += new EventHandler(numericUpDown1_ValueChanged); UpDownBase upDown2 = (UpDownBase)numericUpDown2; upDown2.TextChanged += new EventHandler(numericUpDown2_ValueChanged); UpDownBase upDown3 = (UpDownBase)numericUpDown3; upDown3.TextChanged += new EventHandler(numericUpDown3_ValueChanged); UpDownBase upDown4 = (UpDownBase)numericUpDown4; upDown4.TextChanged += new EventHandler(numericUpDown4_ValueChanged); //settingPath = Path + "MaxSetting.xml"; roiPath = Path + "Roi.roi"; //if (File.Exists(settingPath)) //{ // inParam = (InputParam)StaticOperate.ReadXML(settingPath, inParam.GetType()); //} inParam = LoadXml(Station); ShowToUI(); CircleLine.load = new LookForCircleLine.mainUtl.LoadImage(LoadImage); }
public Form1() { InitializeComponent(); roiController = new ROIController(); viewController = new HWndCtrl(this.hWindowControl1); viewController.useROIController(roiController); viewController.setViewState(HWndCtrl.MODE_VIEW_MOVE); }
/* 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; }
/// <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 HcImageView() { InitializeComponent(); roiController = new ROIController(); viewController = new HWndCtrl(this.Viewer); viewController.useROIController(roiController); viewController.setViewState(HWndCtrl.MODE_VIEW_MOVE); roiController.ActiveChanged += roiController_ActiveChanged; roiController.ROIChanged += roiController_ROIChanged; }
CameraOperate Camera = new CameraOperate(); //相机操作 #endregion #region 构造函数 public MainWindow() { InitializeComponent(); PLCButton.AddHandler(System.Windows.Controls.Button.MouseDownEvent, new RoutedEventHandler(Button_MouseDown), true); PLCButton.AddHandler(System.Windows.Controls.Button.MouseUpEvent, new RoutedEventHandler(Button_MouseUp), true); viewController1 = new HWndCtrl(ImageWindow1);//HWindowControlWPF窗口给到窗口控制器 roiController1 = new ROIController(); viewController1.useROIController(roiController1); viewController1.setViewState(HWndCtrl.MODE_VIEW_MOVE); }
public void SetRoiCreator(ROIController roiController) { RoiController = roiController; if (RoiController.viewController != null) { RoiController.viewController.viewPort.HMouseMove += GetActiveRoiParameters; } RoiController.NotifyRCObserver += dummyI; GetAllRoiInfo(); }
public Form1() { InitializeComponent(); hWndCrtl = hWndUnit1.HWndCtrl; ROIController = new ROIController(); ROIController.ROINotifyEvent += new EventHandler <ViewEventArgs>(UpdateViewData); roiActUnit1.RoiController = ROIController; hWndCrtl.useROIController(ROIController); ROIController.SetROISign(ROIOperation.Positive); }
public void MakeRoi_model(ROIController mx) { if (Sousuo_region_get.Roi_model == "ROICircle") { mx.genCircle(Sousuo_region_get.Roi_x, Sousuo_region_get.Roi_y, Sousuo_region_get.Roi_Cir1radius, ref sou_regions); mx.reset(); } else if (Sousuo_region_get.Roi_model == "ROIRectangle2") { mx.genRect2(Sousuo_region_get.Roi_x, Sousuo_region_get.Roi_y, Sousuo_region_get.Roi_Rec2phi, Sousuo_region_get.Roi_Rec2length1, Sousuo_region_get.Roi_Rec2length2, ref sou_regions); mx.reset(); } }
public ShowForm() { InitializeComponent(); splitContainerControl1.Panel2.Controls.Add(sw); sw.Dock = DockStyle.Fill; MyGlobal.GoSDK.MeasurementRecFinish += GoSDK_MeasurementRecFinish; textBox_Current.Text = "0"; textBox_Total.Text = "0"; roiController = sw.hwnd[1].viewWindow._roiController; roiController.NotifyRCObserver = new IconicDelegate(ROiMove); context = MyGlobal.GoSDK.context; }
public HDisplay() { InitializeComponent(); searchRegionList = new List <HObject>(); trainRegionList = new List <HObject>(); viewController = new HWndCtrl(hWindowControl); roiController = new ROIController(); viewController.useROIController(roiController); //减少控件的闪烁 SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, false); hWindowControl.BackColor = Color.Gray; viewController.MouseMoveEvent += viewController_MouseMoveEvent; hWindowControl.SizeChanged += new System.EventHandler(this.hWindowControl_SizeChanged); m_Windowhandle = hWindowControl.HalconID; }
private void InitializeMyComponent() { // hWindowControl _hWindowControl.Width = Width; _hWindowControl.Height = Height; // hWndCtrl _hWndCtrl = new HWndCtrl(_hWindowControl); ROIController roiController = new ROIController(); _hWndCtrl.useROIController(roiController); _hWndCtrl.setViewState(HWndCtrl.MODE_VIEW_MOVE); // hWindow _hWindow = _hWindowControl.HalconWindow; }
public ImageViewer() { InitializeComponent(); //hv_window = this.WPF_HWindow.HalconWindow; viewController = new HWndCtrl(this.WPF_HWindow); roiController = new ROIController(); viewController.useROIController(roiController); viewController.setViewState(HWndCtrl.MODE_VIEW_MOVE); HObjectList = viewController.HObjList; viewController.HObjListChanged += ViewController_HObjListChanged; ROIList = roiController.ROIList; roiController.ActiveChanged += RoiController_ActiveChanged; roiController.ROIChanged += RoiController_ROIChanged; }
/// <summary> /// Performs the initialization of the HDisplayControl /// during loading to the memory. /// </summary> private void HDisplayControl_Load(object sender, EventArgs e) { hWndControl = new HWndCtrl(viewPort); // Initialization graphic window size windowExtents = new Rectangle(0, 0, this.viewPort.WindowSize.Width, this.viewPort.WindowSize.Height); imageWidth = imageHeight = 0; displayZoomValue = 100; zoomCenter = new Point(windowExtents.Width / 2, windowExtents.Height / 2); if (MoveOnPressedMouseButton) { hWndControl.setViewState(HWndCtrl.MODE_VIEW_MOVE); } else { hWndControl.setViewState(HWndCtrl.MODE_VIEW_NONE); } // add event handler after zooming the image hWndControl.OnImageZoomed += new OnIconicObjectZoomedHandler( this.hWndControl_IconicObjectZoomed); hWndControl.OnImageMoved += new OnIconicObjectMovedHandler( this.hWndControl_IconicObjectMoved); // setup ROIController roiController = new ROIController(); hWndControl.useROIController(roiController); // handle the changes of regions roiController.NotifyRCObserver = null; roiController.NotifyRCObserver = new IconicDelegate(UpdateViewData); hWndControl.clearList(); //--------- // set the sign of the draw region to the value "Add Region" roiController.setROISign(ROIController.MODE_ROI_POS); this.ShowROI = true; }
///<summary> ///程序初始化 ///</summary> public void Initialization() { //实例化:检测画面子菜单 LineDetect = new LineDetect(); LineDetect.TopLevel = false; LineDetect.Dock = DockStyle.Fill; LineDetect.FormBorderStyle = FormBorderStyle.None; LineDetect.Size = TLPCheckParam.Size; ROIRectangle2 = new ROIRectangle2(); ho_Image = null; hv_ImageWindow = HWControl1.HalconID; InspectionStandard = new InspectionStandard(); InspectionStandard.TopLevel = false; InspectionStandard.Dock = DockStyle.Fill; InspectionStandard.FormBorderStyle = FormBorderStyle.None; InspectionStandard.Size = TLPCheckParam.Size; SendMessage(this.TLPanel_Bottom.Handle, WM_SETREDRAW, 0, IntPtr.Zero);//禁止重绘 TLPCheckParam.Controls.Clear(); TLPCheckParam.Controls.Add(InspectionStandard); InspectionStandard.Show(); SendMessage(TLPanel_Bottom.Handle, WM_SETREDRAW, 1, IntPtr.Zero); //取消禁止 TLPanel_Bottom.Refresh(); //刷新控件 // //画面缩放 roiController = new ROIController(); HWndCtrl = new HWndCtrl(HWControl1); HWndCtrl.useROIController(roiController); HWndCtrl.setViewState(HWndCtrl.MODE_VIEW_ZOOM); HWndCtrl.setViewState(HWndCtrl.MODE_VIEW_MOVE); HWndCtrl.ReDrawEvent += new HWndCtrl.ReDrawDelegate(ReDraw); //更改测量矩形,重绘直线 LineDetect.ReviewLineEvent += new LineDetect.ReviewLineDelegate(ReviewLine); //参数更改,重绘直线 HWndCtrl.ImageProcessingEvent += HWndCtrl_ImageProcessingEvent; if (ho_Image != null) { HWndCtrl.addIconicVar(ho_Image); HWndCtrl.repaint(); } // }
/// <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> /// 初始化 /// </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); }
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); }
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 }
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 }
internal void ReadData(List <string> n_Path, int j, ROIController mm) { IniFile IniFile = new IniFile(n_Path[0] + n_Path[1]); int Selectnumber = 0; if (IniFile.IniReadValue(j.ToString(), "ShapeModel") != "") { Selectnumber = Convert.ToInt32(IniFile.IniReadValue(j.ToString(), "ShapeModel")); } this.comboBox1.SelectedIndex = Selectnumber; if (IniFile.IniReadValue(j.ToString(), "CbbAngle") != "") { this.cbb_angle.SelectedIndex = Convert.ToInt32(IniFile.IniReadValue(j.ToString(), "CbbAngle")); } if (IniFile.IniReadValue(j.ToString(), "CbbPoint") != "") { this.cbb_point.SelectedIndex = Convert.ToInt32(IniFile.IniReadValue(j.ToString(), "CbbPoint")); } this.tb_no.Text = IniFile.IniReadValue(j.ToString(), "TbNo"); if (IniFile.IniReadValue(j.ToString(), "Check_Roi") == "True") { this.checkBox_get.Checked = true; } else { this.checkBox_get.Checked = false; } if (IniFile.IniReadValue(j.ToString(), "Check_handle") == "True") { this.checkBox1.Checked = true; } else { this.checkBox1.Checked = false; } Panel_show(); this.cbb_image.Items.Add(IniFile.IniReadValue(j.ToString(), "ImageIn")); this.cbb_image.SelectedIndex = 0; if (Selectnumber == 1) { this.textBox_rec2row1.Text = IniFile.IniReadValue(j.ToString(), "Rec2row1"); this.textBox_rec2col1.Text = IniFile.IniReadValue(j.ToString(), "Rec2col1"); this.textBox_rec2len1.Text = IniFile.IniReadValue(j.ToString(), "Rec2len1"); this.textBox_rec2len2.Text = IniFile.IniReadValue(j.ToString(), "Rec2len2"); this.txt_rec2phi.Text = IniFile.IniReadValue(j.ToString(), "Rec2phi"); } else { this.textBox_circlerow.Text = IniFile.IniReadValue(j.ToString(), "Cirrow"); this.textBox_circlecolumn.Text = IniFile.IniReadValue(j.ToString(), "Circol"); this.textBox_circleradius.Text = IniFile.IniReadValue(j.ToString(), "Cirradius"); } this.shape_name.Text = IniFile.IniReadValue(j.ToString(), "Modelname"); string Regionnull_check = IniFile.IniReadValue(j.ToString(), "Region_Not_null"); if (Regionnull_check == "ROIRectangle2") { double rec2length1 = 0, rec2length2 = 0, rec2phi = 0, rec2midc = 0, rec2midr = 0; if (IniFile.IniReadValue(j.ToString(), "Rec2length1") != "") { rec2length1 = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Rec2length1")); } if (IniFile.IniReadValue(j.ToString(), "Rec2length2") != "") { rec2length2 = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Rec2length2")); } if (IniFile.IniReadValue(j.ToString(), "Rec2phi") != "") { rec2phi = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Rec2phi")); } if (IniFile.IniReadValue(j.ToString(), "Rec2midc") != "") { rec2midc = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Rec2midc")); } if (IniFile.IniReadValue(j.ToString(), "Rec2midr") != "") { rec2midr = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Rec2midr")); } //this.comboBox2.SelectedIndex = 1; mm.genRect2(rec2midr, rec2midc, rec2phi, rec2length1, rec2length2, ref sou_regions); mm.reset(); } else if (Regionnull_check == "ROICircle") { double cir1midc = 0, cir1midr = 0, cir1radius = 0; if (IniFile.IniReadValue(j.ToString(), "Cir1midc") != "") { cir1midc = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Cir1midc")); } if (IniFile.IniReadValue(j.ToString(), "Cir1midr") != "") { cir1midr = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Cir1midr")); } if (IniFile.IniReadValue(j.ToString(), "Cir1radius") != "") { cir1radius = Convert.ToDouble(IniFile.IniReadValue(j.ToString(), "Cir1radius")); } // this.comboBox2.SelectedIndex = 2; mm.genCircle(cir1midr, cir1midc, cir1radius, ref sou_regions); mm.reset(); } if (IniFile.IniReadValue(j.ToString(), "ButtonPress") == "True") { Button_press = true; this.button_搜索形状.BackColor = Color.Yellow; } else { Button_press = false; } }
/// <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 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); }
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); }