Ejemplo n.º 1
0
        private void GetValueButton_Click(object sender, EventArgs e)
        {
            // Create a circular detector for the size specified
            ROICircle ROICircleObj = new ROICircle(DistanceUnitType.Millimeters, Convert.ToSingle(DetSizeTextBox.Text));

            // Set other detector properties, such as location
            float LocationX = Convert.ToSingle(XLocTextBox.Text);
            float LocationY = Convert.ToSingle(YLocTextBox.Text);

            ROICircleObj.LocationDistanceScale = DistanceScaleType.Relative;
            ROICircleObj.set_Center(meas, new PointF(LocationX, LocationY));

            // Create a new CIEColor object
            CIEColor CIEColorObj;

            CIEColorObj = ROICircleObj.GetColor(meas);

            // Display the luminance value
            ValueTextBox.Text = Convert.ToString(CIEColorObj.Lv);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        private void btnDrawCircle_Click(object sender, EventArgs e)
        {
            ROICircle circle = new ROICircle();

            _roiCtrl.setROIShape(circle);
        }
Ejemplo n.º 4
0
        public MeasureResult Action()
        {
            #region 輸出結果
            CircleResult 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 = 765.53125;
            HTuple f_ROI_Col = 704.333333333333;
            HTuple f_radius  = 11.6440268146406;


            //重定位
            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);


            /**/
            #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 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);


            double inc           = 0.3;
            double miniRadius    = 0.2;
            double maxRadius     = 0.6;
            double currentRadius = 0;
            int    doingCount    = 0;
            //,0.2,0.4,0.6
            //0.2,0.4,0.6
            MeasureViewModel model = null;
            var inBoundry          = false;
            do
            {
                roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_radius);
                var fitCircle = new MeasurementCircle(roiF, cAssistant);
                model = fitCircle.GetViewModel();
                if (model.Distance != null && model.Distance.TupleLength() > 0)
                {
                    currentRadius = CameraSystem.ToRealWorldValue(model.Distance.D);
                    inBoundry     = (miniRadius <= currentRadius && currentRadius <= maxRadius);
                    if (inBoundry)
                    {
                        mResult = new CircleResult()
                        {
                            Row        = new HTuple(model.Row1),
                            Col        = new HTuple(model.Col1),
                            Radius     = new HTuple(model.Distance),
                            StartPhi   = new HTuple(model.StartPhi),
                            EndPhi     = new HTuple(model.EndPhi),
                            PointOrder = new HTuple(model.PointOrder),
                        };
                        break;
                    }
                }
                if (currentRadius < miniRadius)
                {
                    f_radius += inc;
                }
                else
                {
                    f_radius -= inc;
                }
                doingCount++;
                if (doingCount > 15)
                {
                    break;
                }
            }while (!inBoundry);

            #endregion
            return(mResult);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 指定ROI类型画ROI
        /// </summary>
        /// <param name="ROI_TYPE">ROI.ROI_TYPE</param>
        /// <returns></returns>
        public ROI DrawROI(int ROI_TYPE)
        {
            ROI NewROI = null;

            viewController.setViewState(HWndCtrl.MODE_ROI_Create);
            WPF_HWindow.HalconWindow.SetColor("red");

            if (ROI_TYPE == ROI.ROI_TYPE_LINE)
            {
                double row1, row2, column1, column2;
                hv_window.DrawLine(out row1, out column1, out row2, out column2);
                if (row1 == 0 && row2 == 0 && column1 == 0 && column2 == 0)
                {
                    Console.WriteLine("空的ROI");
                }
                else
                {
                    ROILine _ROI = new ROILine();
                    _ROI.createROI(row1, column1, row2, column2);
                    NewROI = _ROI;
                }
            }
            else if (ROI_TYPE == ROI.ROI_TYPE_RECTANGLE1)
            {//如果type是Rectangle1
                double row1, row2, column1, column2;
                hv_window.DrawRectangle1(out row1, out column1, out row2, out column2);

                if (row1 == 0 && row2 == 0 && column1 == 0 && column2 == 0)
                {
                    Console.WriteLine("空的ROI");
                }
                else
                {
                    ROIRectangle1 _ROI = new ROIRectangle1();
                    _ROI.createROI(row1, column1, row2, column2);
                    NewROI = _ROI;
                }
            }
            else if (ROI_TYPE == ROI.ROI_TYPE_RECTANGLE2)
            {//
                double row, column, phi, length1, length2;
                hv_window.DrawRectangle2(out row, out column, out phi, out length1, out length2);

                if (row == 0 && column == 0 && length1 == 0 && length2 == 0)
                {
                    Console.WriteLine("空的ROI");
                }
                else
                {
                    ROIRectangle2 _ROI = new ROIRectangle2();
                    _ROI.createROI(row, column, phi, length1, length2);
                    NewROI = _ROI;
                }
            }
            else if (ROI_TYPE == ROI.ROI_TYPE_REGION)
            {//如果type是Region
                HRegion hr = hv_window.DrawRegion();
                if (hr.Area.L == 0)
                {
                    Console.WriteLine("空的ROI");
                }
                else
                {
                    NewROI = new ROIRegion(hr);
                }
            }
            else if (ROI_TYPE == ROI.ROI_TYPE_CIRCLE)
            {
                double row, column, radius;
                hv_window.DrawCircle(out row, out column, out radius);
                if (row == 0 && column == 0 && radius == 0)
                {
                    Console.WriteLine("空的ROI");
                }
                else
                {
                    ROICircle _ROI = new ROICircle();
                    _ROI.createROI(column, row, radius);
                    NewROI = _ROI;
                }
            }

            DelaySetViewState(HWndCtrl.MODE_VIEW_MOVE);
            //hv_window.DispObj(hr);
            return(NewROI);
        }