/// <summary>
        /// Factory method to create measure objects
        /// </summary>
        /// <param name="roi">Interactive ROI</param>
        /// <param name="parent">
        /// Reference to measure controller class
        /// </param>
        /// <returns>New measure object</returns>
        public static Measurement CreateMeasure(ROI roi, MeasureAssistant parent)
        {
            Measurement mMeasurement = null;

            switch (roi.ROIMeasureType)
            {
            case MeasureType.Circle:
                mMeasurement = new MeasurementCircle(roi, parent);
                break;

            case MeasureType.Line:
                if (_doFitLineAlgo)
                {
                    mMeasurement = new MeasurementFitLine(roi, parent);
                }
                else
                {
                    mMeasurement = new MeasurementEdge(roi, parent);
                }
                break;

            case MeasureType.Point:
                if (roi is ViewROI.SmartROIs.SmartPoint)
                {
                    mMeasurement = new SmartMeasurements.AutoFitPoint(roi, parent);
                }
                else
                {
                    mMeasurement = new MeasurementEdge(roi, parent);
                }
                break;

            default:
                mMeasurement = new MeasurementEdge(roi, parent);
                break;
            }
            //if (parent.mSelPair)
            //	return new MeasurementPair(roi, parent);
            //else if (roi.ROIMeasureType == MeasureType.Circle)
            //{
            //	return new MeasurementCircle(roi, parent);
            //}
            //else
            //	return new MeasurementEdge(roi, parent);
            return(mMeasurement);
        }
Пример #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);
        }
Пример #3
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 = 874.4296875;
            //HTuple f_ROI_Col = 737.209150326797;
            //HTuple f_radius = 11.353000779328;

            HTuple f_ROI_Row = 875.6796875;
            HTuple f_ROI_Col = 738.565359477124;
            HTuple f_radius = 20.0;

            //重定位
            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.1;
            double maxRadius = 0.3;
            double currentRadius = 0;
            int doingCount = 0;
            //0.1,0.2,0.3

            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;
        }
        /// <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>
 /// Factory method to create measure objects
 /// </summary>
 /// <param name="roi">Interactive ROI</param>
 /// <param name="parent">
 /// Reference to measure controller class
 /// </param>
 /// <returns>New measure object</returns>
 public static Measurement CreateMeasure(ROI roi, MeasureAssistant parent)
 {
     Measurement mMeasurement = null;
     switch (roi.ROIMeasureType)
     {
         case MeasureType.Circle:
             mMeasurement = new MeasurementCircle(roi, parent);
             break;
         case MeasureType.Line:
             if (_doFitLineAlgo)
                 mMeasurement = new MeasurementFitLine(roi, parent);
             else
                 mMeasurement = new MeasurementEdge(roi, parent);
             break;
         case MeasureType.Point:
             if (roi is ViewROI.SmartROIs.SmartPoint)
             {
                 mMeasurement = new SmartMeasurements.AutoFitPoint(roi, parent);
             }
             else
             {
                 mMeasurement = new MeasurementEdge(roi, parent);
             }
             break;
         default:
             mMeasurement = new MeasurementEdge(roi, parent);
             break;
     }
     //if (parent.mSelPair)
     //	return new MeasurementPair(roi, parent);
     //else if (roi.ROIMeasureType == MeasureType.Circle)
     //{
     //	return new MeasurementCircle(roi, parent);
     //}
     //else
     //	return new MeasurementEdge(roi, parent);
     return mMeasurement;
 }