public MeasurementFitLine(ROI roi, MeasureAssistant mAssist)
     : base(roi, mAssist)
 {
     mResult = new FitLineResult();
     _cameraOut = new HTuple();
     UpdateMeasure();
 }
 public MeasurementFitLine(ROI roi, MeasureAssistant mAssist)
     : base(roi, mAssist)
 {
     mResult    = new FitLineResult();
     _cameraOut = new HTuple();
     UpdateMeasure();
 }
        private FitLineResult fitline(HObject contoursSplit)
        {
            FitLineResult result = new FitLineResult()
            {
                Col1 = new HTuple(),
                Row1 = new HTuple(),
                Col2 = new HTuple(),
                Row2 = new HTuple(),
            };

            //fitLine
            HTuple  number, rowBegin, colBegin, rowEnd, colEnd, nr, nc, dist;
            HObject objectSelected;

            HOperatorSet.GenEmptyObj(out objectSelected);

            HTuple distance, preDistance = 0.0;

            var fitlineContourAlgorithm = (mMeasAssist != null) ? new HTuple(mMeasAssist.FitLineAlgorithm) : _algorithm;

            HOperatorSet.CountObj(contoursSplit, out number);
            for (HTuple hv_i = 1; hv_i.Continue(number, 1); hv_i = hv_i.TupleAdd(1))
            {
                HOperatorSet.SelectObj(contoursSplit, out objectSelected, hv_i);
                HOperatorSet.FitLineContourXld(objectSelected
                                               , fitlineContourAlgorithm, _maxNumPoints, _clippingEndPoints, _iterations, _clippingFactor,
                                               out rowBegin, out colBegin, out rowEnd, out colEnd, out nr, out nc, out dist);

                HOperatorSet.DistancePp(rowBegin, colBegin, rowEnd, colEnd, out distance);
                if (distance > preDistance)
                {
                    preDistance = new HTuple(distance);
                    //Answer
                    result = new FitLineResult()
                    {
                        Row1 = new HTuple(rowBegin),
                        Col1 = new HTuple(colBegin),
                        Row2 = new HTuple(rowEnd),
                        Col2 = new HTuple(colEnd),
                    };
                }
            }
            return(result);
        }
        /// <summary>
        /// 更新量測結果.
        /// 量測演算法放這裡
        /// </summary>
        public override void UpdateResults()
        {
            if (mMeasAssist.mImage == null) return;
            //init result
            mResult = new FitLineResult()
            {
                Col1 = new HTuple(),
                Row1 = new HTuple(),
                Col2 = new HTuple(),
                Row2 = new HTuple(),
            };
            var image = mMeasAssist.getImage();

            HObject imageReduced;
            HOperatorSet.GenEmptyObj(out imageReduced);

            //建 ROI
            var roiModel = mRoi.getModelData();
            var row = roiModel[0];
            var column = roiModel[1];
            var phi = roiModel[2].D * -1;//修正為 Retangle 2 的方向
            var length1 = roiModel[3];
            var length2 = roiModel[4];

            HRegion region = new HRegion();
            region.GenRectangle2(row.D, column.D, phi, length1.D, length2.D);
            HOperatorSet.ReduceDomain(image, region, out imageReduced);
            try
            {
                HOperatorSet.WriteImage(imageReduced, "tiff", 0, @"D:\ttt.tif");
            }
            catch (Exception)
            {

            }
            var contoursSplit = extractEdges(imageReduced);

            try
            {
                if (mMeasAssist.ApplyCalibration && mMeasAssist.IsCalibrationValid)
                {
                    if (_cameraOut.TupleLength() == 0)
                        HOperatorSet.ChangeRadialDistortionCamPar("adaptive", mMeasAssist.CameraIn, 0, out _cameraOut);

                    HObject calibrationContoursSplits;
                    HOperatorSet.GenEmptyObj(out calibrationContoursSplits);

                    //var imageRect = image.ChangeRadialDistortionImage(region, mMeasAssist.CameraIn, _cameraOut);
                    //mResult = fitline(imageRect, true);
                    HOperatorSet.ChangeRadialDistortionContoursXld(contoursSplit, out calibrationContoursSplits, mMeasAssist.CameraIn, _cameraOut);
                    mResult = fitline(calibrationContoursSplits);
                }
                else
                {
                    mResult = fitline(contoursSplit);
                }
                mResultWorld = new FitLineResult(mResult);
            }
            catch (HOperatorException ex)
            {
                Hanbo.Log.LogManager.Error(ex);
            }
            UpdateXLD();
        }
 public override void ClearResultData()
 {
     mResultWorld = new FitLineResult();
 }
        private FitLineResult fitline(HObject contoursSplit)
        {
            FitLineResult result = new FitLineResult()
            {
                Col1 = new HTuple(),
                Row1 = new HTuple(),
                Col2 = new HTuple(),
                Row2 = new HTuple(),
            };

            //fitLine
            HTuple number, rowBegin, colBegin, rowEnd, colEnd, nr, nc, dist;
            HObject objectSelected;
            HOperatorSet.GenEmptyObj(out objectSelected);

            HTuple distance, preDistance = 0.0;

            var fitlineContourAlgorithm = (mMeasAssist != null) ? new HTuple(mMeasAssist.FitLineAlgorithm) : _algorithm;
            HOperatorSet.CountObj(contoursSplit, out number);
            for (HTuple hv_i = 1; hv_i.Continue(number, 1); hv_i = hv_i.TupleAdd(1))
            {
                HOperatorSet.SelectObj(contoursSplit, out objectSelected, hv_i);
                HOperatorSet.FitLineContourXld(objectSelected
                    , fitlineContourAlgorithm, _maxNumPoints, _clippingEndPoints, _iterations, _clippingFactor,
                    out rowBegin, out colBegin, out rowEnd, out colEnd, out nr, out nc, out dist);

                HOperatorSet.DistancePp(rowBegin, colBegin, rowEnd, colEnd, out distance);
                if (distance > preDistance)
                {
                    preDistance = new HTuple(distance);
                    //Answer
                    result = new FitLineResult()
                    {
                        Row1 = new HTuple(rowBegin),
                        Col1 = new HTuple(colBegin),
                        Row2 = new HTuple(rowEnd),
                        Col2 = new HTuple(colEnd),
                    };
                }
            }
            return result;
        }
 public FitLineResult(FitLineResult result)
     : this(result.Row1, result.Col1, result.Row2, result.Col2)
 {
 }
        /// <summary>
        /// 更新量測結果.
        /// 量測演算法放這裡
        /// </summary>
        public override void UpdateResults()
        {
            if (mMeasAssist.mImage == null)
            {
                return;
            }
            //init result
            mResult = new FitLineResult()
            {
                Col1 = new HTuple(),
                Row1 = new HTuple(),
                Col2 = new HTuple(),
                Row2 = new HTuple(),
            };
            var image = mMeasAssist.getImage();

            HObject imageReduced;

            HOperatorSet.GenEmptyObj(out imageReduced);

            //建 ROI
            var roiModel = mRoi.getModelData();
            var row      = roiModel[0];
            var column   = roiModel[1];
            var phi      = roiModel[2].D * -1;       //修正為 Retangle 2 的方向
            var length1  = roiModel[3];
            var length2  = roiModel[4];

            HRegion region = new HRegion();

            region.GenRectangle2(row.D, column.D, phi, length1.D, length2.D);
            HOperatorSet.ReduceDomain(image, region, out imageReduced);
            try
            {
                HOperatorSet.WriteImage(imageReduced, "tiff", 0, @"D:\ttt.tif");
            }
            catch (Exception)
            {
            }
            var contoursSplit = extractEdges(imageReduced);

            try
            {
                if (mMeasAssist.ApplyCalibration && mMeasAssist.IsCalibrationValid)
                {
                    if (_cameraOut.TupleLength() == 0)
                    {
                        HOperatorSet.ChangeRadialDistortionCamPar("adaptive", mMeasAssist.CameraIn, 0, out _cameraOut);
                    }

                    HObject calibrationContoursSplits;
                    HOperatorSet.GenEmptyObj(out calibrationContoursSplits);

                    //var imageRect = image.ChangeRadialDistortionImage(region, mMeasAssist.CameraIn, _cameraOut);
                    //mResult = fitline(imageRect, true);
                    HOperatorSet.ChangeRadialDistortionContoursXld(contoursSplit, out calibrationContoursSplits, mMeasAssist.CameraIn, _cameraOut);
                    mResult = fitline(calibrationContoursSplits);
                }
                else
                {
                    mResult = fitline(contoursSplit);
                }
                mResultWorld = new FitLineResult(mResult);
            }
            catch (HOperatorException ex)
            {
                Hanbo.Log.LogManager.Error(ex);
            }
            UpdateXLD();
        }
 public override void ClearResultData()
 {
     mResultWorld = new FitLineResult();
 }
Пример #10
0
 public FitLineResult(FitLineResult result)
     : this(result.Row1, result.Col1, result.Row2, result.Col2)
 {
 }