Beispiel #1
0
        public bool Inspection(CogImage8Grey _SrcImage, CogRectangle _InspArea)
        {
            bool _Result = true;

            try
            {
                BlobResults = BlobProc.Execute(_SrcImage, _InspArea);
            }

            catch (System.Exception ex)
            {
                CLogManager.AddSystemLog(CLogManager.LOG_TYPE.ERR, "InspectionBlob - Inspection Exception : " + ex.ToString(), CLogManager.LOG_LEVEL.LOW);
                _Result = false;
            }

            return(_Result);
        }
Beispiel #2
0
        public bool LeadAlignSE(CogImage8Grey _SrcImage, CogRectangle _InspRegion, CogLeadFormAlgo _CogLeadFormAlgo)
        {
            if (LeadFormResult.IsGood != true)
            {
                return(true);
            }

            CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, "LeadAlign - Start", CLogManager.LOG_LEVEL.MID);

            if (false == _CogLeadFormAlgo.IsUseAlign)
            {
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, "LeadAlign Disable - End", CLogManager.LOG_LEVEL.MID);
                return(true);
            }

            bool          _Result             = true;
            List <double> _AlignPositionX     = new List <double>();
            List <double> _AlignPositionY     = new List <double>();
            List <double> _AlignPositionWidth = new List <double>();

            try
            {
                System.Diagnostics.Stopwatch _ProcessWatch = new System.Diagnostics.Stopwatch();
                _ProcessWatch.Reset(); _ProcessWatch.Start();

                SetHardFixedThreshold(_CogLeadFormAlgo.AlignThreshold);
                SetConnectivityMinimum(500);
                SetPolarity(true);

                CogBlobResults _BlobResults    = BlobProc.Execute(_SrcImage, _InspRegion);
                List <double>  _GuidePositionX = GetLeadGuidePosition(_BlobResults);

                #region Caliper Tool Setting => Y좌표 위치 정보 찾기
                LeadFormResult.LeadCount = _GuidePositionX.Count;

                if (_GuidePositionX.Count != _CogLeadFormAlgo.LeadCount)
                {
                    LeadFormResult.IsGood = false;
                    LeadFormResult.NgType = eNgType.LEAD_CNT;
                    LeadFormResult.SearchArea.SetCenterWidthHeight(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height);
                    LeadFormResult.LeadCountStatus = LeadFormResult.LeadCount.ToString();
                    return(false);
                }

                for (int iLoopCount = 0; iLoopCount < _GuidePositionX.Count; ++iLoopCount)
                {
                    CogRectangleAffine _CaliperRegion = new CogRectangleAffine();
                    _CaliperRegion.SetCenterLengthsRotationSkew(_GuidePositionX[iLoopCount], _InspRegion.CenterY, _InspRegion.Height, 170, 1.5708, 0);

                    CogCaliperTool _LeadCaliper = new CogCaliperTool();
                    _LeadCaliper.RunParams.EdgeMode      = CogCaliperEdgeModeConstants.SingleEdge;
                    _LeadCaliper.RunParams.Edge0Polarity = CogCaliperPolarityConstants.DarkToLight;
                    _LeadCaliper.RunParams.MaxResults    = 2;
                    _LeadCaliper.Region = _CaliperRegion;

                    _LeadCaliper.InputImage = _SrcImage;
                    _LeadCaliper.Run();

                    if (_LeadCaliper.Results.Count == 1)
                    {
                        _AlignPositionY.Add(_LeadCaliper.Results[0].PositionY);
                    }
                    else if (_LeadCaliper.Results.Count == 2)
                    {
                        _AlignPositionY.Add((_LeadCaliper.Results[0].PositionY < _LeadCaliper.Results[1].PositionY) ? _LeadCaliper.Results[0].PositionY : _LeadCaliper.Results[1].PositionY);
                    }

                    //CogSerializer.SaveObjectToFile(_LeadCaliper, string.Format(@"D:\GuideCaliper{0}.vpp", iLoopCount + 1));
                }
                #endregion

                #region Blob Tool Setting => X좌표 위치 정보 찾기
                for (int iLoopCount = 0; iLoopCount < _GuidePositionX.Count; ++iLoopCount)
                {
                    SetHardFixedThreshold(_CogLeadFormAlgo.AlignThreshold);
                    SetConnectivityMinimum(500);
                    SetPolarity(true);

                    CogRectangle _BlobRegion = new CogRectangle();
                    _BlobRegion.SetCenterWidthHeight(_GuidePositionX[iLoopCount], _AlignPositionY[iLoopCount] + 18, 170, 36);
                    _BlobResults = BlobProc.Execute(_SrcImage, _BlobRegion);

                    if (_BlobResults.GetBlobs().Count == 0)
                    {
                        LeadFormResult.IsGood = false;
                        LeadFormResult.NgType = eNgType.LEAD_CNT;
                        LeadFormResult.SearchArea.SetCenterWidthHeight(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height);
                        LeadFormResult.LeadCountStatus = "NG";
                        return(false);
                    }

                    _AlignPositionX.Add(GetCenterXResult(_BlobResults));
                    _AlignPositionWidth.Add(GetWidthResult(_BlobResults));
                }
                #endregion

                #region Align XY 좌표 ADD
                if (_CogLeadFormAlgo.LeadCount == _GuidePositionX.Count)
                {
                    LeadFormResult.AlignResultDataList.Clear();
                    for (int iLoopCount = 0; iLoopCount < _GuidePositionX.Count; ++iLoopCount)
                    {
                        LeadFormAlignResultData _AlignResult = new LeadFormAlignResultData();
                        _AlignResult.CenterX = _AlignPositionX[iLoopCount];
                        _AlignResult.CenterY = _AlignPositionY[iLoopCount];
                        _AlignResult.Width   = _AlignPositionWidth[iLoopCount];
                        _AlignResult.Height  = _AlignPositionWidth[iLoopCount];
                        _AlignResult.IsGood  = true;
                        LeadFormResult.AlignResultDataList.Add(_AlignResult);
                    }
                }

                else
                {
                    LeadFormResult.IsGood          = false;
                    LeadFormResult.NgType          = eNgType.LEAD_CNT;
                    LeadFormResult.LeadCountStatus = _GuidePositionX.Count.ToString();
                    LeadFormResult.SearchArea.SetCenterWidthHeight(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height);
                    _Result = false;
                }
                #endregion

                //Lead 간격 조건 검사
                LeadFormResult.AlignOffsetDataList.Clear();
                PointD _AlignOffset = new PointD();
                if (_CogLeadFormAlgo.LeadCount == LeadFormResult.LeadCount)
                {
                    for (int iLoopCount = 0; iLoopCount < _CogLeadFormAlgo.LeadCount; ++iLoopCount)
                    {
                        double _RealCenterX = LeadFormResult.AlignResultDataList[iLoopCount].CenterX * _CogLeadFormAlgo.ResolutionX;
                        double _RealCenterY = LeadFormResult.AlignResultDataList[iLoopCount].CenterY * _CogLeadFormAlgo.ResolutionY;

                        #region X 축 Skew 확인
                        //Align Pitch Spec에서 완전히 벗어났는지 확인
                        if (_RealCenterX > _CogLeadFormAlgo.AlignPositionArray[iLoopCount].X - _CogLeadFormAlgo.AlignPitchSpec &&
                            _RealCenterX < _CogLeadFormAlgo.AlignPositionArray[iLoopCount].X + _CogLeadFormAlgo.AlignPitchSpec)
                        {
                            //Align Skew 가능 범위에 들어와 있는지 확인
                            //Skew 범위 안쪽이면 Skew 여부에 상관없이 GOOD
                            if (_RealCenterX > _CogLeadFormAlgo.AlignPositionArray[iLoopCount].X - _CogLeadFormAlgo.AlignSkewSpec &&
                                _RealCenterX < _CogLeadFormAlgo.AlignPositionArray[iLoopCount].X + _CogLeadFormAlgo.AlignSkewSpec)
                            {
                                if (LeadFormResult.NgType == eNgType.GOOD)
                                {
                                    LeadFormResult.AlignResultDataList[iLoopCount].IsGood = true;
                                }
                                LeadFormResult.EachLeadStatusArray[iLoopCount].SetSkewResult(eLeadStatus.GOOD);
                            }

                            //Skew 범위 < Position < Pitch Err 범위
                            //불량 판정 & Skew 가능 에러로 전달
                            else
                            {
                                LeadFormResult.AlignResultDataList[iLoopCount].IsGood = false;
                                LeadFormResult.IsGood = false;

                                LeadFormResult.EachLeadStatusArray[iLoopCount].SetSkewResult(eLeadStatus.LEAD_SKEW_ENABLE);
                                _Result = false;
                            }
                        }

                        //완전히 벗어나면  Skew 불가능 에러
                        else
                        {
                            LeadFormResult.AlignResultDataList[iLoopCount].IsGood = false;
                            LeadFormResult.IsGood = false;

                            LeadFormResult.EachLeadStatusArray[iLoopCount].SetSkewResult(eLeadStatus.LEAD_SKEW_DISABLE);
                            _Result = false;
                        }
                        #endregion

                        #region Y 축 Skew 확인
                        //Align Pitch Spec에서 완전히 벗어났는지 확인
                        if (_RealCenterY > _CogLeadFormAlgo.AlignPositionArray[iLoopCount].Y - _CogLeadFormAlgo.AlignPitchSpec &&
                            _RealCenterY < _CogLeadFormAlgo.AlignPositionArray[iLoopCount].Y + _CogLeadFormAlgo.AlignPitchSpec)
                        {
                            //Align Skew 가능 범위에 들어와 있는지 확인
                            //Skew 범위 안쪽이면 Skew 여부에 상관없이 GOOD
                            if (_RealCenterY > _CogLeadFormAlgo.AlignPositionArray[iLoopCount].Y - _CogLeadFormAlgo.AlignSkewSpec &&
                                _RealCenterY < _CogLeadFormAlgo.AlignPositionArray[iLoopCount].Y + _CogLeadFormAlgo.AlignSkewSpec)
                            {
                                //if (LeadFormResult.NgType == eNgType.GOOD)
                                //    LeadFormResult.AlignResultDataList[iLoopCount].IsGood = true;
                                LeadFormResult.EachLeadStatusArray[iLoopCount].SetSkewResult(eLeadStatus.GOOD);
                            }

                            //Skew 범위 < Position < Pitch Err 범위
                            //불량 판정 & Skew 가능 에러로 전달
                            else
                            {
                                LeadFormResult.AlignResultDataList[iLoopCount].IsGood = false;
                                LeadFormResult.IsGood = false;

                                LeadFormResult.EachLeadStatusArray[iLoopCount].SetSkewResult(eLeadStatus.LEAD_SKEW_ENABLE);
                                _Result = false;
                            }
                        }

                        else
                        {
                            LeadFormResult.AlignResultDataList[iLoopCount].IsGood = false;
                            LeadFormResult.IsGood = false;

                            LeadFormResult.EachLeadStatusArray[iLoopCount].SetSkewResult(eLeadStatus.LEAD_SKEW_DISABLE);
                            _Result = false;
                        }
                        #endregion

                        _AlignOffset.X = Math.Round(_RealCenterX - _CogLeadFormAlgo.AlignPositionArray[iLoopCount].X, 4);
                        _AlignOffset.Y = Math.Round(_RealCenterY - _CogLeadFormAlgo.AlignPositionArray[iLoopCount].Y, 4);
                        LeadFormResult.AlignOffsetDataList.Add(_AlignOffset);

                        LeadFormResult.EachLeadStatusArray[iLoopCount].SideX = _AlignOffset.X.ToString();
                        LeadFormResult.EachLeadStatusArray[iLoopCount].SideY = _AlignOffset.Y.ToString();
                    }
                }

                else
                {
                    LeadFormResult.IsGood          = false;
                    LeadFormResult.NgType          = eNgType.LEAD_CNT;
                    LeadFormResult.LeadCountStatus = LeadFormResult.LeadCount.ToString();
                    LeadFormResult.SearchArea.SetCenterWidthHeight(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height);
                    _Result = false;
                }

                _ProcessWatch.Stop();
                string _ProcessTime = String.Format("LeadAlign Time : {0} ms", _ProcessWatch.Elapsed.TotalSeconds.ToString());
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, _ProcessTime, CLogManager.LOG_LEVEL.LOW);
            }

            catch (Exception ex)
            {
                CLogManager.AddSystemLog(CLogManager.LOG_TYPE.ERR, "LeadAlign - Inspection Exception : " + ex.ToString(), CLogManager.LOG_LEVEL.LOW);
                LeadFormResult.NgType         = eNgType.EMPTY;
                LeadFormResult.IsGood         = false;
                LeadFormResult.LeadBodyStatus = "NG";
                LeadFormResult.SearchArea.SetCenterWidthHeight(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height);
                _Result = false;
            }

            return(_Result);
        }