Example #1
0
        static void Main(string[] args)
        {
            // load image
            var bmp = new System.Drawing.Bitmap(@"D:\test.bmp");

            #region Using Vision Pro
            //vision pro tool initializing
            CogCaliperTool calipertool = new CogCaliperTool();
            //or load .vpp file (specific tool vpp)
            calipertool = CogSerializer.LoadObjectFromFile(@"D:\CaliperTool.vpp") as CogCaliperTool;

            //input processing image
            calipertool.InputImage = new CogImage8Grey(bmp);

            //process
            calipertool.Run();

            //create result record
            var caliper_record = calipertool.CreateLastRunRecord().SubRecords[0];

            //use result
            Console.Write("Edge Position is : X = {0}, Y = {1}", calipertool.Results[0].PositionX, calipertool.Results[0].PositionY);

            //save current tool (it saved specific tool vpp)
            CogSerializer.SaveObjectToFile(calipertool, @"D:\CaliperTool_Saved.vpp");
            #endregion


            #region Using ViDi in Runtime

            //open ViDi control (it has to open only one in the application.)
            ViDi2.Runtime.Local.Control runtime_control = new ViDi2.Runtime.Local.Control();
            //add runtime workspace (and open)
            ViDi2.Runtime.IWorkspace runtime_workspace = runtime_control.Workspaces.Add("TestWorkspace", @"D:\DeeplearningWorkspace.vrws");
            //select stream in workspace
            ViDi2.Runtime.IStream runtime_stream = runtime_workspace.Streams.Single(s => s.Name.Equals("Stream"));


            //pack image for use ViDi
            ViDi2.IImage runtime_ViDiImg = new ViDi2.FormsImage(bmp);
            //process
            ViDi2.ISample runtime_sample = runtime_stream.Process(runtime_ViDiImg);

            //using red result
            ViDi2.IRedMarking redMarking = runtime_sample.Markings["Analyze"] as ViDi2.IRedMarking;

            //marking has a value for each view result
            var r_score  = redMarking.Views[0].Score;
            var r_region = redMarking.Views[0].Regions;
            var r_pose   = redMarking.Views[0].Pose;

            //using blue result
            ViDi2.IBlueMarking blueMarking = runtime_sample.Markings["Locate"] as ViDi2.IBlueMarking;

            var b_features = blueMarking.Views[0].Features;
            var b_pose     = blueMarking.Views[0].Pose;

            //using green result
            ViDi2.IGreenMarking greenMarking = runtime_sample.Markings["Classify"] as ViDi2.IGreenMarking;

            var g_best_tag = greenMarking.Views[0].BestTag;
            var g_tags     = greenMarking.Views[0].Tags;

            //free vidi image
            runtime_ViDiImg.Dispose();

            //close workspace
            runtime_workspace.Close();

            //close vidi control
            runtime_control.Dispose();
            #endregion


            #region Using ViDi - Vision Pro Integration
            //open ViDi control (it has to open only one in the application.)
            ViDi2.Runtime.Local.Control integ_control = new ViDi2.Runtime.Local.Control();
            //add runtime workspace (and open)
            ViDi2.Runtime.IWorkspace integ_workspace = integ_control.Workspaces.Add("TestWorkspace", @"D:\DeeplearningWorkspace.vrws");
            //select stream in workspace
            ViDi2.Runtime.IStream integ_stream = integ_workspace.Streams.Single(s => s.Name.Equals("Stream"));

            //vision pro tool initializing
            CogAffineTransformTool transform_tool = new CogAffineTransformTool();
            //or load .vpp file (specific tool vpp)
            transform_tool = CogSerializer.LoadObjectFromFile(@"D:\TransformTool.vpp") as CogAffineTransformTool;

            //input processing image
            transform_tool.InputImage = new CogImage8Grey(bmp);
            //process Vision Pro
            transform_tool.Run();

            //pack vison pro output image for use ViDi
            ViDi2.IImage integ_ViDiImg = new ViDi2.VisionPro.Image(transform_tool.OutputImage);
            //process ViDi
            var integ_sample = integ_stream.Process(integ_ViDiImg);

            //create vision pro record
            var vp_record = transform_tool.CreateLastRunRecord().SubRecords[0];

            //create ViDi record
            var integ_redMarking = integ_sample.Markings["Analyze"] as ViDi2.IRedMarking;
            var vidi_red_record  = new ViDi2.VisionPro.RedViewRecord(integ_redMarking.Views[0] as ViDi2.IRedView, new ViDi2.VisionPro.Records.DefaultRedToolGraphicCreator());

            var integ_blueMarking = integ_sample.Markings["Locate"] as ViDi2.IBlueMarking;
            var vidi_blue_record  = new ViDi2.VisionPro.BlueViewRecord(integ_blueMarking.Views[0] as ViDi2.IBlueView, new ViDi2.VisionPro.Records.DefaultBlueToolGraphicCreator());

            var integ_greenMarking = integ_sample.Markings["Classify"] as ViDi2.IGreenMarking;
            var vidi_green_record  = new ViDi2.VisionPro.GreenViewRecord(integ_greenMarking.Views[0] as ViDi2.IGreenView, new ViDi2.VisionPro.Records.DefaultGreenToolGraphicCreator());

            //free vidi image
            integ_ViDiImg.Dispose();
            //close workspace
            integ_workspace.Close();
            //close vidi control
            integ_control.Dispose();
            #endregion


            //free image
            bmp.Dispose();
        }
Example #2
0
        public int Run(ADisplay aDisplay)
        {
            SetCaliperParam();

            if (m_cogCaliperTool != null)
            {
                m_cogCaliperTool.InputImage = aDisplay.GetImage8Grey();

                // 2015.04.08
                m_bRan = false;

                m_cogCaliperTool.Run();

                // 2015.04.08
                WaitRanEvent();

                // 2012.02.02
                if (m_cogCaliperTool.Results == null)
                {
                    m_nFindCount = 0;
                    return(m_nFindCount);
                }

                if (m_cogCaliperTool.Results.Count > 0)
                {
                    m_dScore     = m_cogCaliperTool.Results[0].Score;
                    m_dPositionX = m_cogCaliperTool.Results[0].PositionX;
                    m_dPositionY = m_cogCaliperTool.Results[0].PositionY;
                    m_dPosition  = m_cogCaliperTool.Results[0].Position;

                    if (m_emEdgeMode == CogCaliperEdgeModeConstants.SingleEdge)
                    {
                        m_dEdge0PositionX = m_cogCaliperTool.Results[0].Edge0.PositionX;
                        m_dEdge0PositionY = m_cogCaliperTool.Results[0].Edge0.PositionY;
                        m_dEdge0Position  = m_cogCaliperTool.Results[0].Edge0.Position;
                        m_dEdge0Contrast  = m_cogCaliperTool.Results[0].Edge0.Contrast;
                        m_dEdge1PositionX = 0;
                        m_dEdge1PositionY = 0;
                        m_dEdge1Position  = 0;
                        m_dEdge1Contrast  = 0;
                    }
                    else
                    {
                        m_dEdge0PositionX = m_cogCaliperTool.Results[0].Edge0.PositionX;
                        m_dEdge0PositionY = m_cogCaliperTool.Results[0].Edge0.PositionY;
                        m_dEdge0Position  = m_cogCaliperTool.Results[0].Edge0.Position;
                        m_dEdge0Contrast  = m_cogCaliperTool.Results[0].Edge0.Contrast;
                        m_dEdge1PositionX = m_cogCaliperTool.Results[0].Edge1.PositionX;
                        m_dEdge1PositionY = m_cogCaliperTool.Results[0].Edge1.PositionY;
                        m_dEdge1Position  = m_cogCaliperTool.Results[0].Edge1.Position;
                        m_dEdge1Contrast  = m_cogCaliperTool.Results[0].Edge1.Contrast;
                    }

                    m_dWidth     = m_cogCaliperTool.Results[0].Width;
                    m_nFindCount = m_cogCaliperTool.Results.Count;
                }
                else
                {
                    m_dScore          = 0;
                    m_dPositionX      = 0;
                    m_dPositionY      = 0;
                    m_dPosition       = 0;
                    m_dEdge0PositionX = 0;
                    m_dEdge0PositionY = 0;
                    m_dEdge0Position  = 0;
                    m_dEdge0Contrast  = 0;
                    m_dEdge1PositionX = 0;
                    m_dEdge1PositionY = 0;
                    m_dEdge1Position  = 0;
                    m_dEdge1Contrast  = 0;
                    m_dWidth          = 0;
                    m_nFindCount      = 0;
                }
            }

            return(m_nFindCount);
        }
Example #3
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);
        }