コード例 #1
0
        public InspectionBlob()
        {
            BlobProc    = new CogBlob();
            BlobResults = new CogBlobResults();
            BlobResult  = new CogBlobResult();
            InspResults = new CogBlobReferenceResult();

            BlobProc.SegmentationParams.Mode               = CogBlobSegmentationModeConstants.HardFixedThreshold;
            BlobProc.SegmentationParams.Polarity           = CogBlobSegmentationPolarityConstants.LightBlobs;
            BlobProc.SegmentationParams.HardFixedThreshold = 100;
            BlobProc.ConnectivityMode      = CogBlobConnectivityModeConstants.GreyScale;
            BlobProc.ConnectivityCleanup   = CogBlobConnectivityCleanupConstants.Fill;
            BlobProc.ConnectivityMinPixels = 10;
        }
コード例 #2
0
        private void ApplySettingValue()
        {
            CogBlobReferenceResult _CogBlobReferResult  = new CogBlobReferenceResult();
            CogBlobReferenceAlgo   _CogBlobReferAlgoRcp = new CogBlobReferenceAlgo();

            _CogBlobReferAlgoRcp.ThresholdMin      = Convert.ToInt32(graLabelThresholdValue.Text);
            _CogBlobReferAlgoRcp.BlobAreaMin       = Convert.ToDouble(textBoxBlobAreaMin.Text);
            _CogBlobReferAlgoRcp.BlobAreaMax       = Convert.ToDouble(textBoxBlobAreaMax.Text);
            _CogBlobReferAlgoRcp.Width             = Convert.ToDouble(textBoxWidthSize.Text);
            _CogBlobReferAlgoRcp.WidthPos          = Convert.ToDouble(textBoxWidthSpecPos.Text);
            _CogBlobReferAlgoRcp.WidthNeg          = Convert.ToDouble(textBoxWidthSpecNeg.Text);
            _CogBlobReferAlgoRcp.Height            = Convert.ToDouble(textBoxHeightSize.Text);
            _CogBlobReferAlgoRcp.HeightPos         = Convert.ToDouble(textBoxHeightSpecPos.Text);
            _CogBlobReferAlgoRcp.HeightNeg         = Convert.ToDouble(textBoxHeightSpecNeg.Text);
            _CogBlobReferAlgoRcp.ForeGround        = Convert.ToInt32(graLabelForeground.Text);
            _CogBlobReferAlgoRcp.BenchMarkPosition = Convert.ToInt32(textBoxBenchMarkPosition.Text);
            _CogBlobReferAlgoRcp.ResolutionX       = ResolutionX;
            _CogBlobReferAlgoRcp.ResolutionY       = ResolutionY;

            var _ApplyBlobReferValueEvent = ApplyBlobReferValueEvent;

            if (_ApplyBlobReferValueEvent != null)
            {
                _ApplyBlobReferValueEvent(_CogBlobReferAlgoRcp, ref _CogBlobReferResult);
            }

            if (_CogBlobReferResult.BlobArea != null)
            {
                double _MaxArea  = _CogBlobReferResult.BlobArea.Max();
                int    _MaxIndex = Array.IndexOf(_CogBlobReferResult.BlobArea, _MaxArea);
                BodyAreaSize   = _CogBlobReferResult.BlobArea[_MaxIndex];
                BodyWidthSize  = _CogBlobReferResult.Width[_MaxIndex];
                BodyHeightSize = _CogBlobReferResult.Height[_MaxIndex];

                OriginX = _CogBlobReferResult.OriginX[_MaxIndex];
                OriginY = _CogBlobReferResult.OriginY[_MaxIndex];
            }

            else
            {
                textBoxBodyArea.Text   = "0";
                textBoxBodyWidth.Text  = "0";
                textBoxBodyHeight.Text = "0";

                OriginX = 0;
                OriginY = 0;
            }
        }
コード例 #3
0
        private void ApplyBlobReferenceValueFunction(CogBlobReferenceAlgo _CogBlobReferAlgo, ref CogBlobReferenceResult _CogBlobReferResult)
        {
            if (eTeachStep.ALGO_SET != CurrentTeachStep)
            {
                MessageBox.Show("Not select \"Algorithm Set\" button"); return;
            }
            AlgorithmAreaDisplayRefresh();

            CogRectangleAffine _AlgoRegionAffine = new CogRectangleAffine();

            _AlgoRegionAffine.SetCenterLengthsRotationSkew(AlgoRegionRectangle.CenterX, AlgoRegionRectangle.CenterY, AlgoRegionRectangle.Width, AlgoRegionRectangle.Height, 0, 0);
            bool _Result = InspBlobReferProcess.Run(InspectionImage, _AlgoRegionAffine, _CogBlobReferAlgo, ref _CogBlobReferResult);

            for (int iLoopCount = 0; iLoopCount < _CogBlobReferResult.BlobCount; ++iLoopCount)
            {
                double _Width  = _CogBlobReferResult.Width[iLoopCount] * ResolutionX;
                double _Height = _CogBlobReferResult.Height[iLoopCount] * ResolutionX;

                if (_CogBlobReferAlgo.WidthMin < _Width && _CogBlobReferAlgo.WidthMax > _Width && _CogBlobReferAlgo.HeightMin < _Height && _CogBlobReferAlgo.HeightMax > _Height)
                {
                    CogRectangle _BlobRect = new CogRectangle();
                    _BlobRect.SetCenterWidthHeight(_CogBlobReferResult.BlobCenterX[iLoopCount], _CogBlobReferResult.BlobCenterY[iLoopCount], _CogBlobReferResult.Width[iLoopCount], _CogBlobReferResult.Height[iLoopCount]);
                    kpTeachDisplay.DrawStaticShape(_BlobRect, "BlobRect" + (iLoopCount + 1), CogColorConstants.Green);
                    kpTeachDisplay.DrawBlobResult(_CogBlobReferResult.ResultGraphic[iLoopCount], "BlobRectGra" + (iLoopCount + 1));

                    CogPointMarker _Point = new CogPointMarker();
                    _Point.X = _CogBlobReferResult.OriginX[iLoopCount];
                    _Point.Y = _CogBlobReferResult.OriginY[iLoopCount];
                    kpTeachDisplay.DrawStaticShape(_Point, "BlobSearchPoint", CogColorConstants.Green, 5);

                    string _RectSizeName = string.Format("W : {0:F2}mm, H : {1:F2}mm, Area : {2}", _Width, _Height, _CogBlobReferResult.BlobArea[iLoopCount]);
                    kpTeachDisplay.DrawText(_RectSizeName, _CogBlobReferResult.BlobCenterX[iLoopCount] + _CogBlobReferResult.Width[iLoopCount] / 2 + 100,
                                            _CogBlobReferResult.BlobCenterY[iLoopCount] + _CogBlobReferResult.Height[iLoopCount] / 2 + 100, CogColorConstants.Green, 10, CogGraphicLabelAlignmentConstants.BaselineCenter);
                }
            }
        }
コード例 #4
0
        public bool Run(CogImage8Grey _SrcImage, CogRectangleAffine _InspRegion, CogBlobReferenceAlgo _CogBlobReferAlgo, ref CogBlobReferenceResult _CogBlobReferResult, int _NgNumber = 0)
        {
            bool   _Result = true;
            double _X = 0, _Y = 0;

            SetHardFixedThreshold(_CogBlobReferAlgo.ThresholdMin);
            SetConnectivityMinimum((int)_CogBlobReferAlgo.BlobAreaMin);
            SetPolarity(Convert.ToBoolean(_CogBlobReferAlgo.ForeGround));
            SetMeasurement(CogBlobMeasureConstants.Area, CogBlobMeasureModeConstants.Filter, CogBlobFilterModeConstants.IncludeBlobsInRange, _CogBlobReferAlgo.BlobAreaMin, _CogBlobReferAlgo.BlobAreaMax);
            if (true == Inspection(_SrcImage, _InspRegion))
            {
                GetResult(true);
            }

            List <int> _ResultIndexList = new List <int>();

            if (GetResults().BlobCount > 0)
            {
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Blob Total Count : " + GetResults().BlobCount.ToString(), CLogManager.LOG_LEVEL.MID);

                CogBlobReferenceResult _CogBlobReferResultTemp = new CogBlobReferenceResult();
                _CogBlobReferResultTemp = GetResults();

                double _ResolutionX = _CogBlobReferAlgo.ResolutionX;
                double _ResolutionY = _CogBlobReferAlgo.ResolutionY;
                for (int iLoopCount = 0; iLoopCount < _CogBlobReferResultTemp.BlobCount; ++iLoopCount)
                {
                    double _ResultRealWidth  = _CogBlobReferResultTemp.Width[iLoopCount] * _ResolutionX;
                    double _ResultRealHeight = _CogBlobReferResultTemp.Height[iLoopCount] * _ResolutionY;

                    if (_CogBlobReferAlgo.WidthMin < _ResultRealWidth && _CogBlobReferAlgo.WidthMax > _ResultRealWidth && _CogBlobReferAlgo.HeightMin < _ResultRealHeight && _CogBlobReferAlgo.HeightMax > _ResultRealHeight)
                    {
                        _CogBlobReferResultTemp.IsGoods[iLoopCount] = true;
                        if (_CogBlobReferAlgo.UseBodyArea)
                        {
                            CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - UseBodyArea Flag True", CLogManager.LOG_LEVEL.MID);
                            double _BodyAreaGap = Math.Abs(_CogBlobReferResultTemp.BlobArea[iLoopCount] - _CogBlobReferAlgo.BodyArea);
                            if ((_CogBlobReferAlgo.BodyArea * _CogBlobReferAlgo.BodyAreaPermitPercent / 100) > _BodyAreaGap)
                            {
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - UseBodyArea Result Fail!!", CLogManager.LOG_LEVEL.MID);
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - UseBodyArea Result : {0}", _BodyAreaGap.ToString("F2")), CLogManager.LOG_LEVEL.MID);
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - UseBodyArea Condition : {0}", (_CogBlobReferAlgo.BodyArea * _CogBlobReferAlgo.BodyAreaPermitPercent / 100).ToString("F2")), CLogManager.LOG_LEVEL.MID);

                                _CogBlobReferResultTemp.IsGoods[iLoopCount] = false;
                                continue;
                            }
                        }

                        if (_CogBlobReferAlgo.UseBodyWidth)
                        {
                            CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - UseBodyWidth Flag True", CLogManager.LOG_LEVEL.MID);
                            double _BodyWidthGap = Math.Abs(_CogBlobReferResultTemp.Width[iLoopCount] - _CogBlobReferAlgo.BodyWidth);
                            if ((_CogBlobReferAlgo.BodyWidth * _CogBlobReferAlgo.BodyWidthPermitPercent / 100) > _BodyWidthGap)
                            {
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - UseBodyWidth Result Fail!!", CLogManager.LOG_LEVEL.MID);
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - UseBodyWidth Result : {0}", _BodyWidthGap.ToString("F2")), CLogManager.LOG_LEVEL.MID);
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - UseBodyWidth Condition : {0}", (_CogBlobReferAlgo.BodyWidth * _CogBlobReferAlgo.BodyWidthPermitPercent / 100).ToString("F2")), CLogManager.LOG_LEVEL.MID);

                                _CogBlobReferResultTemp.IsGoods[iLoopCount] = false;
                                continue;
                            }
                        }

                        if (_CogBlobReferAlgo.UseBodyHeight)
                        {
                            CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - UseBodyHeight Flag True", CLogManager.LOG_LEVEL.MID);
                            double _BodyHeightGap = Math.Abs(_CogBlobReferResultTemp.Height[iLoopCount] - _CogBlobReferAlgo.BodyHeight);
                            if ((_CogBlobReferAlgo.BodyHeight * _CogBlobReferAlgo.BodyHeightPermitPercent / 100) > _BodyHeightGap)
                            {
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - UseBodyHeight Result Fail!!", CLogManager.LOG_LEVEL.MID);
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - UseBodyHeight Result : {0}", _BodyHeightGap.ToString("F2")), CLogManager.LOG_LEVEL.MID);
                                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - UseBodyHeight Condition : {0}", (_CogBlobReferAlgo.BodyHeight * _CogBlobReferAlgo.BodyHeightPermitPercent / 100).ToString("F2")), CLogManager.LOG_LEVEL.MID);

                                _CogBlobReferResultTemp.IsGoods[iLoopCount] = false;
                                continue;
                            }
                        }

                        CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - W : {0}mm, H : {1}mm", _ResultRealWidth, _ResultRealHeight), CLogManager.LOG_LEVEL.MID);

                        eBenchMarkPosition _eBenchMark = (eBenchMarkPosition)_CogBlobReferAlgo.BenchMarkPosition;
                        if (eBenchMarkPosition.TL == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobMinX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobMinY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.TC == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobCenterX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobMinY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.TR == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobMaxX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobMinY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.ML == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobMinX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobCenterY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.MC == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobCenterX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobCenterY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.MR == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobMaxX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobCenterY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.BL == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobMinX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobMaxY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.BC == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobCenterX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobMaxY[iLoopCount];
                        }
                        else if (eBenchMarkPosition.BR == _eBenchMark)
                        {
                            _X = _CogBlobReferResultTemp.BlobMaxX[iLoopCount]; _Y = _CogBlobReferResultTemp.BlobMaxY[iLoopCount];
                        }
                        _CogBlobReferResultTemp.OriginX[iLoopCount] = _X;
                        _CogBlobReferResultTemp.OriginY[iLoopCount] = _Y;

                        _ResultIndexList.Add(iLoopCount);
                    }
                }

                if (_ResultIndexList.Count > 0)
                {
                    if (_CogBlobReferAlgo.UseDummyValue)
                    {
                        //Image ADD
                        CogIPTwoImageAddTool _CogImageAddTool = new CogIPTwoImageAddTool();
                        _CogImageAddTool.InputImageA = _SrcImage;
                        _CogImageAddTool.InputImageB = _SrcImage;
                        _CogImageAddTool.Run();

                        CogImage8Grey _DestImage = (CogImage8Grey)_CogImageAddTool.OutputImage;

                        //Histogram check
                        CogHistogramTool _CogHistoTool = new CogHistogramTool();
                        //_CogHistoTool.InputImage = _SrcImage;
                        _CogHistoTool.InputImage = _DestImage;
                        _CogHistoTool.Region     = _InspRegion;
                        _CogHistoTool.Run();
                        double _HistoAvg = _CogHistoTool.Result.StandardDeviation;
                        _CogBlobReferResult.HistogramAvg = _HistoAvg;
                        //if (_CogBlobReferAlgo.DummyHistoMeanValue + 5 > _HistoAvg)// && _CogBlobReferAlgo.DummyHistoMeanValue - 5 < _HistoAvg)
                        if (_CogBlobReferAlgo.DummyHistoMeanValue > _HistoAvg)
                        {
                            _CogBlobReferResult.DummyStatus = true;
                        }

                        CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Dummy Deviation : " + _HistoAvg.ToString("F2"), CLogManager.LOG_LEVEL.MID);
                        CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Dummy Status : " + _CogBlobReferResult.DummyStatus.ToString(), CLogManager.LOG_LEVEL.MID);
                    }

                    CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Blob Condition Count : " + _ResultIndexList.Count.ToString(), CLogManager.LOG_LEVEL.MID);
                    #region _CogBlobReferResult 할당
                    int _Count = _ResultIndexList.Count;
                    _CogBlobReferResult.BlobCount       = _Count;
                    _CogBlobReferResult.BlobMessCenterX = new double[_Count];
                    _CogBlobReferResult.BlobMessCenterY = new double[_Count];
                    _CogBlobReferResult.BlobCenterX     = new double[_Count];
                    _CogBlobReferResult.BlobCenterY     = new double[_Count];
                    _CogBlobReferResult.BlobMinX        = new double[_Count];
                    _CogBlobReferResult.BlobMaxX        = new double[_Count];
                    _CogBlobReferResult.BlobMinY        = new double[_Count];
                    _CogBlobReferResult.BlobMaxY        = new double[_Count];
                    _CogBlobReferResult.Width           = new double[_Count];
                    _CogBlobReferResult.Height          = new double[_Count];
                    _CogBlobReferResult.BlobRatio       = new double[_Count];
                    _CogBlobReferResult.Angle           = new double[_Count];
                    _CogBlobReferResult.BlobXMinYMax    = new double[_Count];
                    _CogBlobReferResult.BlobXMaxYMin    = new double[_Count];
                    _CogBlobReferResult.BlobArea        = new double[_Count];
                    _CogBlobReferResult.OriginX         = new double[_Count];
                    _CogBlobReferResult.OriginY         = new double[_Count];
                    _CogBlobReferResult.IsGoods         = new bool[_Count];
                    _CogBlobReferResult.ResultGraphic   = new CogCompositeShape[_Count];
                    #endregion _CogBlobReferResult 할당

                    for (int iLoopCount = 0; iLoopCount < _Count; ++iLoopCount)
                    {
                        _CogBlobReferResult.BlobMessCenterX[iLoopCount] = _CogBlobReferResultTemp.BlobMessCenterX[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.BlobMessCenterY[iLoopCount] = _CogBlobReferResultTemp.BlobMessCenterY[_ResultIndexList[iLoopCount]];

                        _CogBlobReferResult.BlobCenterX[iLoopCount]   = _CogBlobReferResultTemp.BlobCenterX[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.BlobCenterY[iLoopCount]   = _CogBlobReferResultTemp.BlobCenterY[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.BlobMinX[iLoopCount]      = _CogBlobReferResultTemp.BlobMinX[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.BlobMaxX[iLoopCount]      = _CogBlobReferResultTemp.BlobMaxX[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.BlobMinY[iLoopCount]      = _CogBlobReferResultTemp.BlobMinY[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.BlobMaxY[iLoopCount]      = _CogBlobReferResultTemp.BlobMaxY[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.Width[iLoopCount]         = _CogBlobReferResultTemp.Width[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.Height[iLoopCount]        = _CogBlobReferResultTemp.Height[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.BlobArea[iLoopCount]      = _CogBlobReferResultTemp.BlobArea[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.OriginX[iLoopCount]       = _CogBlobReferResultTemp.OriginX[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.OriginY[iLoopCount]       = _CogBlobReferResultTemp.OriginY[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.IsGoods[iLoopCount]       = _CogBlobReferResultTemp.IsGoods[_ResultIndexList[iLoopCount]];
                        _CogBlobReferResult.ResultGraphic[iLoopCount] = _CogBlobReferResultTemp.ResultGraphic[iLoopCount];
                    }
                    _CogBlobReferResult.IsGood = true;
                }

                else
                {
                    _CogBlobReferResult.BlobMinX       = new double[1];
                    _CogBlobReferResult.BlobMinY       = new double[1];
                    _CogBlobReferResult.BlobCenterX    = new double[1];
                    _CogBlobReferResult.BlobCenterY    = new double[1];
                    _CogBlobReferResult.Width          = new double[1];
                    _CogBlobReferResult.Height         = new double[1];
                    _CogBlobReferResult.OriginX        = new double[1];
                    _CogBlobReferResult.OriginY        = new double[1];
                    _CogBlobReferResult.IsGoods        = new bool[1];
                    _CogBlobReferResult.BlobMinX[0]    = _InspRegion.CenterX - (_InspRegion.SideXLength / 2);
                    _CogBlobReferResult.BlobMinY[0]    = _InspRegion.CenterY - (_InspRegion.SideYLength / 2);
                    _CogBlobReferResult.BlobCenterX[0] = _InspRegion.CenterX;
                    _CogBlobReferResult.BlobCenterY[0] = _InspRegion.CenterY;
                    _CogBlobReferResult.Width[0]       = _InspRegion.SideXLength;
                    _CogBlobReferResult.Height[0]      = _InspRegion.SideXLength;
                    _CogBlobReferResult.OriginX[0]     = _InspRegion.CenterX;
                    _CogBlobReferResult.OriginY[0]     = _InspRegion.CenterY;

                    _CogBlobReferResult.IsGood = false;
                }
            }

            else
            {
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Blob not found!!", CLogManager.LOG_LEVEL.MID);

                _CogBlobReferResult.BlobMinX       = new double[1];
                _CogBlobReferResult.BlobMinY       = new double[1];
                _CogBlobReferResult.BlobCenterX    = new double[1];
                _CogBlobReferResult.BlobCenterY    = new double[1];
                _CogBlobReferResult.Width          = new double[1];
                _CogBlobReferResult.Height         = new double[1];
                _CogBlobReferResult.OriginX        = new double[1];
                _CogBlobReferResult.OriginY        = new double[1];
                _CogBlobReferResult.IsGoods        = new bool[1];
                _CogBlobReferResult.BlobMinX[0]    = _InspRegion.CenterX - (_InspRegion.SideXLength / 2);
                _CogBlobReferResult.BlobMinY[0]    = _InspRegion.CenterX - (_InspRegion.SideYLength / 2);
                _CogBlobReferResult.BlobCenterX[0] = _InspRegion.CenterX;
                _CogBlobReferResult.BlobCenterY[0] = _InspRegion.CenterY;
                _CogBlobReferResult.Width[0]       = _InspRegion.SideXLength;
                _CogBlobReferResult.Height[0]      = _InspRegion.SideXLength;
                _CogBlobReferResult.OriginX[0]     = _InspRegion.CenterX;
                _CogBlobReferResult.OriginY[0]     = _InspRegion.CenterY;

                _CogBlobReferResult.IsGood = false;
            }

            CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Result : " + _CogBlobReferResult.IsGood.ToString(), CLogManager.LOG_LEVEL.MID);
            return(_Result);
        }
コード例 #5
0
        private void ApplyMapIDReference()
        {
            CogBlobReferenceAlgo _BlobReferAlgo = new CogBlobReferenceAlgo();

            _BlobReferAlgo.ThresholdMin = Convert.ToInt32(graLabelThresholdValue.Text);
            _BlobReferAlgo.BlobAreaMin  = 100;
            _BlobReferAlgo.BlobAreaMax  = 50000;
            _BlobReferAlgo.WidthMin     = Convert.ToDouble(graLabelWidthMin.Text);
            _BlobReferAlgo.WidthMax     = Convert.ToDouble(graLabelWidthMax.Text);
            _BlobReferAlgo.HeightMin    = 5;
            _BlobReferAlgo.HeightMax    = 100000;
            _BlobReferAlgo.ForeGround   = 1;

            if (null == OriginImage)
            {
                return;
            }
            kpTeachDisplay.ClearDisplay();

            CogRectangleAffine _ReferRegionAffine = new CogRectangleAffine();

            _ReferRegionAffine.SetCenterLengthsRotationSkew(MapDataParam.MapID.SearchAreaCenterX, MapDataParam.MapID.SearchAreaCenterY, MapDataParam.MapID.SearchAreaWidth, MapDataParam.MapID.SearchAreaHeight, 0, 0);

            CogBlobReferenceResult _BlobReferResult = new CogBlobReferenceResult();
            bool _Result = InspBlobRefer.Run(OriginImage, _ReferRegionAffine, _BlobReferAlgo, ref _BlobReferResult);

            List <MapIDRectInfo> _MapIDRectInfoList = new List <MapIDRectInfo>();

            for (int iLoopCount = 0; iLoopCount < _BlobReferResult.BlobCount; ++iLoopCount)
            {
                double _Width  = _BlobReferResult.Width[iLoopCount];
                double _Height = _BlobReferResult.Height[iLoopCount];

                if (_BlobReferAlgo.WidthMin < _Width && _BlobReferAlgo.WidthMax > _Width)
                {
                    MapIDRectInfo _RectInfo = new MapIDRectInfo();
                    _RectInfo.CenterPt.X = _BlobReferResult.BlobCenterX[iLoopCount];
                    _RectInfo.CenterPt.Y = _BlobReferResult.BlobCenterY[iLoopCount];
                    _RectInfo.Width      = _BlobReferResult.Width[iLoopCount];
                    _RectInfo.Height     = _BlobReferResult.Height[iLoopCount];
                    _MapIDRectInfoList.Add(_RectInfo);
                }
            }

            _MapIDRectInfoList.Sort(delegate(MapIDRectInfo _First, MapIDRectInfo _Second) { return(_First.CenterPt.Y.CompareTo(_Second.CenterPt.Y)); });
            for (int iLoopCount = 0; iLoopCount < _MapIDRectInfoList.Count; ++iLoopCount)
            {
                CogRectangle _MapRect = new CogRectangle();
                _MapRect.SetCenterWidthHeight(_MapIDRectInfoList[iLoopCount].CenterPt.X, _MapIDRectInfoList[iLoopCount].CenterPt.Y, _MapIDRectInfoList[iLoopCount].Width, _MapIDRectInfoList[iLoopCount].Height);
                kpTeachDisplay.DrawStaticShape(_MapRect, "BlobRect" + (iLoopCount + 1), CogColorConstants.Green);
                kpTeachDisplay.DrawText("BlobRect" + iLoopCount, _MapIDRectInfoList[iLoopCount].CenterPt.X + 10, _MapIDRectInfoList[iLoopCount].CenterPt.Y + 10, CogColorConstants.Green);
            }

            if (_MapIDRectInfoList.Count != MapDataParam.Info.UnitTotalCount)
            {
                //MessageBox.Show("Unit 갯수와 Map ID 갯수가 일치하지 않습니다.");
                return;
            }

            else
            {
                MapDataParam.MapID.MapIDInfoList.Clear();
                for (int iLoopCount = 0; iLoopCount < _MapIDRectInfoList.Count; ++iLoopCount)
                {
                    MapIDRectInfo _RectInfo = new MapIDRectInfo();
                    _RectInfo.CenterPt.X = _MapIDRectInfoList[iLoopCount].CenterPt.X;
                    _RectInfo.CenterPt.Y = _MapIDRectInfoList[iLoopCount].CenterPt.Y;
                    _RectInfo.Width      = _MapIDRectInfoList[iLoopCount].Width;
                    _RectInfo.Height     = _MapIDRectInfoList[iLoopCount].Height;
                    MapDataParam.MapID.MapIDInfoList.Add(_RectInfo);
                }
            }
        }