Пример #1
0
        public bool GetPatternReference(CogImage8Grey _SrcImage, CogRectangle _Region, double _OriginX, double _OriginY, ref CogPMAlignPattern _Pattern)
        {
            //CogPMAlignPattern _Pattern = new CogPMAlignPattern();

            _Pattern = new CogPMAlignPattern();
            CogRectangleAffine _ReferRegionAffine = new CogRectangleAffine();

            _ReferRegionAffine.SetCenterLengthsRotationSkew(_Region.CenterX, _Region.CenterY, _Region.Width, _Region.Height, 0, 0);

            CogAffineTransformTool _AffineTool = new CogAffineTransformTool();

            _AffineTool.InputImage = _SrcImage;
            _AffineTool.Region     = _ReferRegionAffine;
            _AffineTool.Run();

            _Pattern.TrainImage          = (CogImage8Grey)_AffineTool.OutputImage;
            _Pattern.TrainRegion         = _ReferRegionAffine;
            _Pattern.Origin.TranslationX = _OriginX;
            _Pattern.Origin.TranslationY = _OriginY;

            try
            {
                _Pattern.Train();
            }

            catch
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        private bool Inspection(CogImage8Grey _SrcImage, CogRectangle _InspArea, bool _IsRotate = false)
        {
            bool _Result = true;

            try
            {
                if (true == _IsRotate)
                {
                    CogRectangleAffine _Area = new CogRectangleAffine();
                    _Area.SetCenterLengthsRotationSkew(_InspArea.CenterX, _InspArea.CenterY, _InspArea.Width, _InspArea.Height, -3.14, 0);
                    IDResults = IDProc.Execute(_SrcImage, _Area);
                }
                else
                {
                    IDResults = IDProc.Execute(_SrcImage, _InspArea);
                }
            }
            catch (Exception ex)
            {
                CLogManager.AddSystemLog(CLogManager.LOG_TYPE.ERR, "InspectionID - Inspection Exception : " + ex.ToString(), CLogManager.LOG_LEVEL.LOW);
                _Result = false;
            }

            return(_Result);
        }
Пример #3
0
        //영역표시툴 생성 후 코그 디스플레이에 표시
        private void button2_Click(object sender, EventArgs e)
        {
            if (PMTool.Pattern.Trained)
            {
                PMTool.Pattern.Untrain();
            }

            PMTool.Pattern.TrainImage = PMTool.InputImage;

            //CogRectangleAffine 생성
            CogRectangleAffine rec = PMTool.Pattern.TrainRegion as CogRectangleAffine;//CogPMAlignTool.Pattern.TrainRegion을 레퍼런스로

            rec.GraphicDOFEnable = CogRectangleAffineDOFConstants.All;
            rec.Interactive      = true;
            rec.TipText          = "학습 영역";
            rec.SetCenterLengthsRotationSkew(300, 300, 300, 300, 0, 0);

            //CogCoordinateAxes 생성 (오리진 좌표)
            CogCoordinateAxes axes = new CogCoordinateAxes();

            axes.Transform        = PMTool.Pattern.Origin;//CogPMAlignTool.Pattern.Origin을 레퍼런스로
            axes.TipText          = "중심좌표";
            axes.GraphicDOFEnable = CogCoordinateAxesDOFConstants.All;
            axes.Interactive      = true;
            axes.MouseCursor      = CogStandardCursorConstants.ManipulableGraphic;
            axes.OriginX          = 300;
            axes.OriginY          = 300;

            //코그디스플레이의 InteractiveGraphics 프라퍼티에 생성한 CogRectangleAffine, CogCoordinateAxes를 Add.
            MainDisplay.InteractiveGraphics.Add(rec, "RectangleAffine", false);
            MainDisplay.InteractiveGraphics.Add(axes, "Origin", false);
        }
Пример #4
0
        public bool GrabRegion(ADisplay aDisplay)
        {
            try
            {
                aDisplay.ClearOverlay();

                ICogGraphicInteractive icogGraphInteractive = null;
                CogRectangleAffine     cogRectangleAffine   = m_cogCaliperTool.Region;

                if (cogRectangleAffine == null)
                {
                    cogRectangleAffine = new CogRectangleAffine();
                    cogRectangleAffine.FitToImage(aDisplay.GetImage8Grey(), 0.5, 0.5);
                }

                icogGraphInteractive = cogRectangleAffine as ICogGraphicInteractive;

                if (icogGraphInteractive != null)
                {
                    icogGraphInteractive.GraphicDOFEnableBase = CogGraphicDOFConstants.All;
                    icogGraphInteractive.Interactive          = true;
                    icogGraphInteractive.TipText = "Region of Interest";
                    aDisplay.AddOverlay(icogGraphInteractive, "");
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #5
0
        //*****************************************************************************************
        // Conversion
        //*****************************************************************************************


        public void Do_Ptrn(Bitmap bmpSource, Bitmap bmpTemplate)
        {
            CogRectangleAffine PatMaxTrainRegion = default(CogRectangleAffine);

            PatMaxTrainRegion = PatMaxTool.Pattern.TrainRegion as CogRectangleAffine;

            ICogImage cogInput = this.Conv_BitmapToCog8Grey(bmpSource);
            ICogImage cogTeach = this.Conv_BitmapToCog8Grey(bmpTemplate);

            int imageW = bmpSource.Width;
            int imageH = bmpSource.Height;

            int teachW = bmpTemplate.Width;
            int teachH = bmpTemplate.Height;


            lock (locker)
            {
                CogRectangle PatMaxSearchRegion = new CogRectangle();
                PatMaxTool.SearchRegion = PatMaxSearchRegion;
                PatMaxSearchRegion.SetCenterWidthHeight(PARAM_SEARCH_CX, PARAM_SEARCH_CY, PARAM_RC_SEARCH.Width, PARAM_RC_SEARCH.Height);
                PatMaxSearchRegion.GraphicDOFEnable = CogRectangleDOFConstants.Position | CogRectangleDOFConstants.Size;
                PatMaxSearchRegion.Interactive      = true;

                if ((PatMaxTrainRegion != null))
                {
                    PatMaxTrainRegion.SetCenterLengthsRotationSkew(teachW / 2, teachH / 2, teachW, teachH, 0, 0);
                    PatMaxTrainRegion.GraphicDOFEnable = CogRectangleAffineDOFConstants.Position |
                                                         CogRectangleAffineDOFConstants.Rotation |
                                                         CogRectangleAffineDOFConstants.Size;
                }

                try
                {
                    PatMaxTool.Pattern.TrainImage     = cogTeach as CogImage8Grey;
                    PatMaxTool.Pattern.TrainAlgorithm = CogPMAlignTrainAlgorithmConstants.PatMax;
                    PatMaxTool.Pattern.TrainMode      = CogPMAlignTrainModeConstants.Image;
                    PatMaxTool.Pattern.Train();
                }
                catch (CogSecurityViolationException ex)
                {
                    MessageBox.Show("Please Check The License Dongle Validity.", "LISENCE ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                PatMaxTool.InputImage = cogInput;
                PatMaxTool.RunParams.ApproximateNumberToFind = 100;
                PatMaxTool.RunParams.AcceptThreshold         = 0.5;

                //PatMaxTool.Changed += PatMaxTool_Changed;

                ptrnResult.removeAll();
                PatMaxTool.Run();
            }
        }
Пример #6
0
        public CogRectangleAffine GetInterActiveRectangleAffine()
        {
            CogRectangleAffine cogRectangleAffine = new CogRectangleAffine();
            double             CenterX, CenterY, Width, Height, Rotate, Skew;

            InteractiveRectAffineGraphic.GetCenterLengthsRotationSkew(out CenterX, out CenterY, out Width, out Height, out Rotate, out Skew);
            cogRectangleAffine.SetCenterLengthsRotationSkew(CenterX, CenterY, Width, Height, Rotate, Skew);
            return(cogRectangleAffine);
        }
Пример #7
0
 /// <summary>
 /// 수정이 불 가능한 고정 도형 그리기
 /// </summary>
 /// <param name="_cogRectAffine">RectAffine 객체</param>
 /// <param name="_groupName">그려지는 그룹명</param>
 /// <param name="_color">색상</param>
 public void DrawStaticShape(CogRectangleAffine _cogRectAffine, string _groupName, CogColorConstants _color, int _LineSize = 2)
 {
     StaticRectAffineGraphic       = new CogRectangleAffine();
     StaticRectAffineGraphic       = _cogRectAffine;
     StaticRectAffineGraphic.Color = _color;
     StaticRectAffineGraphic.LineWidthInScreenPixels = _LineSize;
     StaticRectAffineGraphic.Selected = true;
     kCogDisplay.ClearDisplay(_groupName);
     kCogDisplay.StaticGraphics.Add(StaticRectAffineGraphic.CopyBase(CogCopyShapeConstants.All), _groupName);
 }
Пример #8
0
 /// <summary>
 /// Display에 그리기
 /// </summary>
 /// <param name="_cogRectAffine">CogRectangleAffine 영역</param>
 /// <param name="_Interactive">Interactive = true, Static = false</param>
 public void DrawShape(CogRectangleAffine _cogRectAffine, string _groupName, CogColorConstants _color, bool _Interactive)
 {
     if (_Interactive == true)
     {
         DrawInterActiveShape(_cogRectAffine, _groupName, _color);
     }
     else
     {
         DrawStaticShape(_cogRectAffine, _groupName, _color);
     }
 }
Пример #9
0
        // 2014.09.02
        public void SetInitSearchRegion()
        {
            ICogRegion region = m_cogCaliperTool.Region;

            if (region is CogRectangleAffine)
            {
                CogRectangleAffine rectangleAffine = region as CogRectangleAffine;

                m_dInitSearchRegionX = rectangleAffine.CenterX - m_dMoveSearchRegionX;
                m_dInitSearchRegionY = rectangleAffine.CenterY - m_dMoveSearchRegionY;
            }
        }
Пример #10
0
        /// <summary>
        /// 수정이 가능한 도형 그리기
        /// </summary>
        /// <param name="_cogRectAffine">RectAffine 객체</param>
        /// <param name="_groupName">그려지는 그룹명</param>
        /// <param name="_color">색상</param>
        public void DrawInterActiveShape(CogRectangleAffine _cogRectAffine, string _groupName, CogColorConstants _color)
        {
            InteractiveRectAffineGraphic                         = new CogRectangleAffine();
            InteractiveRectAffineGraphic                         = _cogRectAffine;
            InteractiveRectAffineGraphic.Interactive             = true;
            InteractiveRectAffineGraphic.Color                   = _color;
            InteractiveRectAffineGraphic.LineWidthInScreenPixels = 2;
            InteractiveRectAffineGraphic.GraphicDOFEnable        = CogRectangleAffineDOFConstants.All;

            kCogDisplay.ClearDisplay(_groupName);
            kCogDisplay.InteractiveGraphics.Add(InteractiveRectAffineGraphic, _groupName, true);
        }
Пример #11
0
        public void SetRegion(ADisplay aDisplay)
        {
            ICogGraphicInteractive icogGraphInteractive = aDisplay.GetInteractiveGraphics("Region of Interest");

            if (icogGraphInteractive != null)
            {
                icogGraphInteractive.GraphicDOFEnableBase = CogGraphicDOFConstants.None;
                icogGraphInteractive.Color       = CogColorConstants.Cyan;
                icogGraphInteractive.Interactive = false;
            }

            m_cogRegion = icogGraphInteractive as CogRectangleAffine;
        }
Пример #12
0
        // 2014.09.02
        public void SetInitSearchRegion(double dX, double dY)
        {
            m_dInitSearchRegionX = dX;
            m_dInitSearchRegionY = dY;

            ICogRegion region = m_cogCaliperTool.Region;

            if (region is CogRectangleAffine)
            {
                CogRectangleAffine rectangleAffine = region as CogRectangleAffine;

                rectangleAffine.CenterX = m_dInitSearchRegionX;
                rectangleAffine.CenterY = m_dInitSearchRegionY;
            }
        }
Пример #13
0
        // 2014.09.02
        public void MoveSearchRegion(double x, double y)
        {
            m_dMoveSearchRegionX = x;
            m_dMoveSearchRegionY = y;

            ICogRegion region = m_cogCaliperTool.Region;

            if (region is CogRectangleAffine)
            {
                CogRectangleAffine rectangleAffine = region as CogRectangleAffine;

                rectangleAffine.CenterX = m_dInitSearchRegionX + x;
                rectangleAffine.CenterY = m_dInitSearchRegionY + y;
            }
        }
Пример #14
0
        private bool Inspection(CogImage8Grey _SrcImage, CogRectangleAffine _InspArea)
        {
            bool _Result = true;

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

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

            return(_Result);
        }
Пример #15
0
        public bool unLoad()
        {
            string ProcID = System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString();

            try
            {
                mIDTool = null;
                mID_ROI = null;

                return(true);
            }
            catch (Exception ex)
            {
                SaveLog.Msg_("IDTool Load Failed : " + ModularID + ":\r\n" + ProcID + ":\r\n" + ex.ToString());
                return(false);
            }
        }
Пример #16
0
        // 2014.09.02
        public void MoveSearchRegion(double x, double y)
        {
            m_dMoveSearchRegionX = x;
            m_dMoveSearchRegionY = y;

            ICogRegion region = m_icogRegion;

            if (region is CogCircle)
            {
                CogCircle circle = region as CogCircle;

                circle.CenterX = m_dInitSearchRegionX + x;
                circle.CenterY = m_dInitSearchRegionY + y;
            }
            else if (region is CogEllipse)
            {
                CogEllipse ellipse = region as CogEllipse;
                ellipse.CenterX = m_dInitSearchRegionX + x;
                ellipse.CenterY = m_dInitSearchRegionY + y;
            }
            else if (region is CogRectangle)
            {
                CogRectangle rectangle = region as CogRectangle;
                rectangle.X = m_dInitSearchRegionX + x;
                rectangle.Y = m_dInitSearchRegionY + y;
            }
            else if (region is CogRectangleAffine)
            {
                CogRectangleAffine rectangleAffine = region as CogRectangleAffine;
                rectangleAffine.CenterX = m_dInitSearchRegionX + x;
                rectangleAffine.CenterY = m_dInitSearchRegionY + y;
            }
            else if (region is CogCircularAnnulusSection)
            {
                CogCircularAnnulusSection circularAnnuluns = region as CogCircularAnnulusSection;
                circularAnnuluns.CenterX = m_dInitSearchRegionX + x;
                circularAnnuluns.CenterY = m_dInitSearchRegionY + y;
            }
            else if (region is CogEllipticalAnnulusSection)
            {
                CogEllipticalAnnulusSection ellipticalAnnuluns = region as CogEllipticalAnnulusSection;
                ellipticalAnnuluns.CenterX = m_dInitSearchRegionX + x;
                ellipticalAnnuluns.CenterY = m_dInitSearchRegionY + y;
            }
        }
Пример #17
0
        // 2014.09.02
        public void SetInitSearchRegion(double dX, double dY)
        {
            m_dInitSearchRegionX = dX;
            m_dInitSearchRegionY = dY;

            ICogRegion region = m_icogRegion;

            if (region is CogCircle)
            {
                CogCircle circle = region as CogCircle;

                circle.CenterX = m_dInitSearchRegionX;
                circle.CenterY = m_dInitSearchRegionY;
            }
            else if (region is CogEllipse)
            {
                CogEllipse ellipse = region as CogEllipse;
                ellipse.CenterX = m_dInitSearchRegionX;
                ellipse.CenterY = m_dInitSearchRegionY;
            }
            else if (region is CogRectangle)
            {
                CogRectangle rectangle = region as CogRectangle;
                rectangle.X = m_dInitSearchRegionX;
                rectangle.Y = m_dInitSearchRegionY;
            }
            else if (region is CogRectangleAffine)
            {
                CogRectangleAffine rectangleAffine = region as CogRectangleAffine;
                rectangleAffine.CenterX = m_dInitSearchRegionX;
                rectangleAffine.CenterY = m_dInitSearchRegionY;
            }
            else if (region is CogCircularAnnulusSection)
            {
                CogCircularAnnulusSection circularAnnuluns = region as CogCircularAnnulusSection;
                circularAnnuluns.CenterX = m_dInitSearchRegionX;
                circularAnnuluns.CenterY = m_dInitSearchRegionY;
            }
            else if (region is CogEllipticalAnnulusSection)
            {
                CogEllipticalAnnulusSection ellipticalAnnuluns = region as CogEllipticalAnnulusSection;
                ellipticalAnnuluns.CenterX = m_dInitSearchRegionX;
                ellipticalAnnuluns.CenterY = m_dInitSearchRegionY;
            }
        }
Пример #18
0
        private void Init()
        {
            m_cogRegion       = m_cogCaliperTool.Region;
            m_emEdgeMode      = m_cogCaliperTool.RunParams.EdgeMode;
            m_emEdge0Polarity = m_cogCaliperTool.RunParams.Edge0Polarity;
            m_emEdge1Polarity = m_cogCaliperTool.RunParams.Edge1Polarity;
            m_dExpectedWidth  = m_cogCaliperTool.RunParams.Edge1Position * 2;

            // 2011.06.17
            m_dContrastThreshold = m_cogCaliperTool.RunParams.ContrastThreshold;
            m_nFilterHalfSize    = m_cogCaliperTool.RunParams.FilterHalfSizeInPixels;

            // 2014.09.02
            SetInitSearchRegion();

            // 2015.04.08
            m_cogCaliperTool.Ran += new EventHandler(RanEvent);
        }
Пример #19
0
        public bool Load()
        {
            string ProcID = System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString();

            try
            {
                mPMA_Tool = null;
                mPMA_Tool = new CogPMAlignTool();

                mPMA_ROI = null;
                mPMA_ROI = new CogRectangleAffine();
                return(true);
            }
            catch (Exception ex)
            {
                SaveLog.Msg_("PMA_Tool Load Failed : " + ModularID + ":\r\n" + ProcID + ":\r\n" + ex.ToString());
                return(false);
            }
        }
Пример #20
0
        // 2014.09.02
        public void SetInitSearchRegion()
        {
            ICogRegion region = m_icogRegion;

            if (region is CogCircle)
            {
                CogCircle circle = region as CogCircle;

                m_dInitSearchRegionX = circle.CenterX - m_dMoveSearchRegionX;
                m_dInitSearchRegionY = circle.CenterY - m_dMoveSearchRegionY;
            }
            else if (region is CogEllipse)
            {
                CogEllipse ellipse = region as CogEllipse;
                m_dInitSearchRegionX = ellipse.CenterX - m_dMoveSearchRegionX;
                m_dInitSearchRegionY = ellipse.CenterY - m_dMoveSearchRegionY;
            }
            else if (region is CogRectangle)
            {
                CogRectangle rectangle = region as CogRectangle;
                m_dInitSearchRegionX = rectangle.X - m_dMoveSearchRegionX;
                m_dInitSearchRegionY = rectangle.Y - m_dMoveSearchRegionY;
            }
            else if (region is CogRectangleAffine)
            {
                CogRectangleAffine rectangleAffine = region as CogRectangleAffine;
                m_dInitSearchRegionX = rectangleAffine.CenterX - m_dMoveSearchRegionX;
                m_dInitSearchRegionY = rectangleAffine.CenterY - m_dMoveSearchRegionY;
            }
            else if (region is CogCircularAnnulusSection)
            {
                CogCircularAnnulusSection circularAnnuluns = region as CogCircularAnnulusSection;
                m_dInitSearchRegionX = circularAnnuluns.CenterX - m_dMoveSearchRegionX;
                m_dInitSearchRegionY = circularAnnuluns.CenterY - m_dMoveSearchRegionY;
            }
            else if (region is CogEllipticalAnnulusSection)
            {
                CogEllipticalAnnulusSection ellipticalAnnuluns = region as CogEllipticalAnnulusSection;
                m_dInitSearchRegionX = ellipticalAnnuluns.CenterX - m_dMoveSearchRegionX;
                m_dInitSearchRegionY = ellipticalAnnuluns.CenterY - m_dMoveSearchRegionY;
            }
        }
Пример #21
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);
                }
            }
        }
Пример #22
0
        public bool GrabRegion(ADisplay aDisplay, AVisionProBuild._emRegionShape emRegionShape)
        {
            aDisplay.ClearOverlay();

            ICogGraphicInteractive icogGraphInteractive = null;
            ICogRegion             icogRegion           = m_cogBlobTool.Region;

            CogCircle                   circle             = icogRegion as CogCircle;
            CogEllipse                  ellipse            = icogRegion as CogEllipse;
            CogRectangle                rectangle          = icogRegion as CogRectangle;
            CogRectangleAffine          rectangleAffine    = icogRegion as CogRectangleAffine;
            CogCircularAnnulusSection   circularAnnuluns   = icogRegion as CogCircularAnnulusSection;
            CogEllipticalAnnulusSection ellipticalAnnuluns = icogRegion as CogEllipticalAnnulusSection;

            switch (emRegionShape)
            {
            case AVisionProBuild._emRegionShape.Circle:
            {
                if (circle == null)
                {
                    circle = new CogCircle();
                    circle.FitToImage(aDisplay.GetImage8Grey(), 0.5, 0.5);
                }
                icogGraphInteractive = circle as ICogGraphicInteractive;
            }
            break;

            case AVisionProBuild._emRegionShape.Ellipse:
            {
                if (ellipse == null)
                {
                    ellipse = new CogEllipse();
                    ellipse.FitToImage(aDisplay.GetImage8Grey(), 0.5, 0.5);
                }
                icogGraphInteractive = ellipse as ICogGraphicInteractive;
            }
            break;

            case AVisionProBuild._emRegionShape.Rectangle:
            {
                if (rectangle == null)
                {
                    rectangle = new CogRectangle();
                    rectangle.FitToImage(aDisplay.GetImage8Grey(), 0.5, 0.5);
                }
                icogGraphInteractive = rectangle as ICogGraphicInteractive;
            }
            break;

            case AVisionProBuild._emRegionShape.RectangleAffine:
            {
                if (rectangleAffine == null)
                {
                    rectangleAffine = new CogRectangleAffine();
                    rectangleAffine.FitToImage(aDisplay.GetImage8Grey(), 0.5, 0.5);
                }
                icogGraphInteractive = rectangleAffine as ICogGraphicInteractive;
            }
            break;

            case AVisionProBuild._emRegionShape.CircularAnnulusSection:
            {
                if (circularAnnuluns == null)
                {
                    circularAnnuluns = new CogCircularAnnulusSection();
                    circularAnnuluns.FitToImage(aDisplay.GetImage8Grey(), 0.5, 0.5);
                }
                icogGraphInteractive = circularAnnuluns as ICogGraphicInteractive;
            }
            break;

            case AVisionProBuild._emRegionShape.EllipticalAnnulusSection:
            {
                if (ellipticalAnnuluns == null)
                {
                    ellipticalAnnuluns = new CogEllipticalAnnulusSection();
                    ellipticalAnnuluns.FitToImage(aDisplay.GetImage8Grey(), 0.5, 0.5);
                }
                icogGraphInteractive = ellipticalAnnuluns as ICogGraphicInteractive;
            }
            break;

            case AVisionProBuild._emRegionShape.Entire:
            {
                m_icogRegion = null;
                aDisplay.ClearOverlay();
            }
            break;

            default:
                m_icogRegion = null;

                return(false);
            }

            if (icogGraphInteractive != null)
            {
                icogGraphInteractive.GraphicDOFEnableBase = CogGraphicDOFConstants.All;
                icogGraphInteractive.Interactive          = true;
                icogGraphInteractive.TipText = "Region of Interest";
                aDisplay.AddOverlay(icogGraphInteractive, "");
            }

            return(true);
        }
Пример #23
0
        public bool Run(CogImage8Grey _SrcImage, ref CogImage8Grey _DestImage, CogRectangle _InspRegion, CogLineFindAlgo _CogLineFindAlgo, ref CogLineFindResult _CogLineFindResult, int _NgNumber = 0)
        {
            bool _Result = true;

            SetCaliperDirection(_CogLineFindAlgo.CaliperSearchDirection);
            SetCaliper(_CogLineFindAlgo.CaliperNumber, _CogLineFindAlgo.CaliperSearchLength, _CogLineFindAlgo.CaliperProjectionLength, _CogLineFindAlgo.IgnoreNumber);
            SetCaliperLine(_CogLineFindAlgo.CaliperLineStartX, _CogLineFindAlgo.CaliperLineStartY, _CogLineFindAlgo.CaliperLineEndX, _CogLineFindAlgo.CaliperLineEndY);

            if (true == Inspection(_SrcImage))
            {
                GetResult();
            }
            if (FindLineResults != null && (_CogLineFindAlgo.CaliperNumber - _CogLineFindAlgo.IgnoreNumber) < (FindLineResults.NumPointsFound + 5))
            {
                try
                {
                    _CogLineFindResult.StartX     = FindLineResults.GetLineSegment().StartX;
                    _CogLineFindResult.StartY     = FindLineResults.GetLineSegment().StartY;
                    _CogLineFindResult.EndX       = FindLineResults.GetLineSegment().EndX;
                    _CogLineFindResult.EndY       = FindLineResults.GetLineSegment().EndY;
                    _CogLineFindResult.Length     = FindLineResults.GetLineSegment().Length;
                    _CogLineFindResult.Rotation   = FindLineResults.GetLineSegment().Rotation;
                    _CogLineFindResult.PointCount = FindLineResults.Count;

                    if (_CogLineFindAlgo.UseAlignment)
                    {
                        CogAffineTransformTool _CogTransForm = new CogAffineTransformTool();
                        CogRectangleAffine     _AffineRegion = new CogRectangleAffine();
                        _AffineRegion.SetCenterLengthsRotationSkew(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height, _CogLineFindResult.Rotation, 0);
                        _CogTransForm.InputImage = _SrcImage;
                        _CogTransForm.Region     = _AffineRegion;
                        _CogTransForm.Run();

                        CogCopyRegionTool _CopyRegion = new CogCopyRegionTool();
                        _CopyRegion.InputImage       = _CogTransForm.OutputImage;
                        _CopyRegion.DestinationImage = _SrcImage;
                        _CopyRegion.RunParams.ImageAlignmentEnabled = true;
                        _CopyRegion.Region = null;
                        _CopyRegion.Run();

                        _DestImage = (CogImage8Grey)_CopyRegion.OutputImage;

                        if (true == Inspection(_DestImage))
                        {
                            GetResult();
                        }
                        if (FindLineResults != null)
                        {
                            _CogLineFindResult.StartX     = FindLineResults.GetLineSegment().StartX;
                            _CogLineFindResult.StartY     = FindLineResults.GetLineSegment().StartY;
                            _CogLineFindResult.EndX       = FindLineResults.GetLineSegment().EndX;
                            _CogLineFindResult.EndY       = FindLineResults.GetLineSegment().EndY;
                            _CogLineFindResult.Length     = FindLineResults.GetLineSegment().Length;
                            _CogLineFindResult.Rotation   = FindLineResults.GetLineSegment().Rotation;
                            _CogLineFindResult.PointCount = FindLineResults.Count;

                            _CogLineFindResult.IsGood = true;
                        }

                        else
                        {
                            _CogLineFindResult.IsGood = false;
                        }

                        GC.Collect();
                    }

                    else
                    {
                        _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation;
                        double _Rotation = 0;
                        _Rotation = _CogLineFindResult.Rotation * 180 / Math.PI;
                        _CogLineFindResult.IsGood = true;
                    }
                }

                catch
                {
                    _CogLineFindResult.IsGood = false;
                }
            }

            else
            {
                _CogLineFindResult.IsGood = false;
            }

            return(_Result);
        }
Пример #24
0
        private void ApplyLeadInspValueFunction(CogLeadAlgo _CogLeadAlgo, ref CogLeadResult _CogLeadResult, bool _IsDisplay = true)
        {
            if (eTeachStep.ALGO_SET != CurrentTeachStep)
            {
                MessageBox.Show("Not select \"Algorithm Set\" button"); return;
            }
            if (_IsDisplay)
            {
                AlgorithmAreaDisplayRefresh();
            }

            bool _Result = InspLeadProcess.Run(InspectionImage, AlgoRegionRectangle, _CogLeadAlgo, ref _CogLeadResult);

            #region Result Display
            if (_IsDisplay)
            {
                for (int iLoopCount = 0; iLoopCount < _CogLeadResult.BlobCount; ++iLoopCount)
                {
                    //Blob Boundary
                    CogRectangleAffine _BlobRectAffine = new CogRectangleAffine();
                    _BlobRectAffine.SetCenterLengthsRotationSkew(_CogLeadResult.BlobCenterX[iLoopCount], _CogLeadResult.BlobCenterY[iLoopCount], _CogLeadResult.PrincipalWidth[iLoopCount], _CogLeadResult.PrincipalHeight[iLoopCount], _CogLeadResult.Angle[iLoopCount], 0);
                    kpTeachDisplay.DrawStaticShape(_BlobRectAffine, "BlobRectAffine" + (iLoopCount + 1), CogColorConstants.Green);
                    kpTeachDisplay.DrawBlobResult(_CogLeadResult.ResultGraphic[iLoopCount], "BlobRectGra" + (iLoopCount + 1));

                    CogLineSegment _CenterLine = new CogLineSegment();
                    kpTeachDisplay.DrawStaticLine(_CogLeadResult.BlobCenterX[iLoopCount], _CogLeadResult.BlobCenterY[iLoopCount], _CogLeadResult.PrincipalWidth[iLoopCount] / 2 + 20, _CogLeadResult.Angle[iLoopCount], 2, "CenterLine+_" + (iLoopCount + 1), CogColorConstants.Cyan);
                    kpTeachDisplay.DrawStaticLine(_CogLeadResult.BlobCenterX[iLoopCount], _CogLeadResult.BlobCenterY[iLoopCount], _CogLeadResult.PrincipalWidth[iLoopCount] / 2 + 20, (Math.PI) + _CogLeadResult.Angle[iLoopCount], 2, "CenterLine-_" + (iLoopCount + 1), CogColorConstants.Cyan);

                    CogPointMarker _PitchPoint = new CogPointMarker();
                    _PitchPoint.SetCenterRotationSize(_CogLeadResult.LeadPitchTopX[iLoopCount], _CogLeadResult.LeadPitchTopY[iLoopCount], 0, 1);
                    kpTeachDisplay.DrawStaticShape(_PitchPoint, "PointStart" + (iLoopCount + 1), CogColorConstants.Yellow, 2);
                    _PitchPoint.SetCenterRotationSize(_CogLeadResult.LeadPitchBottomX[iLoopCount], _CogLeadResult.LeadPitchBottomY[iLoopCount], 0, 1);
                    kpTeachDisplay.DrawStaticShape(_PitchPoint, "PointEnd" + (iLoopCount + 1), CogColorConstants.Orange, 2);
                }
            }
            #endregion Result Display

            #region Pitch Average 측정
            try
            {
                double[] _LeadPitchX = new double[_CogLeadResult.BlobCount];
                Array.Copy(_CogLeadResult.LeadPitchTopX, _LeadPitchX, _CogLeadResult.BlobCount);
                Array.Sort(_LeadPitchX);

                double[] _LeadPitches = new double[_CogLeadResult.BlobCount - 1];
                for (int iLoopCount = 0; iLoopCount < _CogLeadResult.BlobCount - 1; ++iLoopCount)
                {
                    _LeadPitches[iLoopCount] = _LeadPitchX[iLoopCount + 1] - _LeadPitchX[iLoopCount];
                }

                Array.Sort(_LeadPitches);
                double _Gab = _LeadPitches[4];
                int    _Index = 1;
                double _PitchSum = _LeadPitches[4], _PitchArray = 0;
                for (int iLoopCount = 5; iLoopCount < _CogLeadResult.BlobCount - 1; ++iLoopCount)
                {
                    if (_Gab + 20 < _LeadPitches[iLoopCount])
                    {
                        break;
                    }
                    _PitchSum += _LeadPitches[iLoopCount];
                    _Index++;
                }

                _PitchArray = _PitchSum / _Index;
                _CogLeadResult.LeadPitchAvg = _PitchArray;
            }

            catch
            {
                _CogLeadResult.LeadPitchAvg = 0;
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.ERR, "ApplyLeadInspValueFunction Exception", CLogManager.LOG_LEVEL.LOW);
            }
            #endregion Pitch Average 측정

            #region Lead Angle Average 측정
            try
            {
                double[] _LeadAngles = new double[_CogLeadResult.BlobCount];
                Array.Copy(_CogLeadResult.Angle, _LeadAngles, _CogLeadResult.BlobCount);
                Array.Sort(_LeadAngles);

                int    _Index = 0;
                double _AngleSum = 0, _AngleAvg = 0;
                for (int iLoopCount = 5; iLoopCount < _CogLeadResult.BlobCount - 5; ++iLoopCount)
                {
                    _AngleSum += _CogLeadResult.Angle[iLoopCount];
                    _Index++;
                }
                _AngleAvg = _AngleSum / _Index;
                _CogLeadResult.LeadAngleAvg = _AngleAvg;
            }

            catch
            {
                _CogLeadResult.LeadAngleAvg = 0;
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.ERR, "ApplyLeadInspValueFunction Exception", CLogManager.LOG_LEVEL.LOW);
            }
            #endregion Lead Angle Average 측정
        }
Пример #25
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);
        }
Пример #26
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);
                }
            }
        }
Пример #27
0
    //#region "when the tool group is run"

    // The GroupRun function is called when the tool group is run.  The default
    // implementation provided here is equivalent to the normal behavior of the
    // tool group.  Modifying this function will allow you to change the behavior
    // when the tool group is run.
    public override bool GroupRun(ref string message, ref CogToolResultConstants result)
    {
        // To let the execution stop in this script when a debugger is attached, uncomment the following lines.
#if DEBUG
        if (System.Diagnostics.Debugger.IsAttached)
        {
            System.Diagnostics.Debugger.Break();
        }
#endif

        histCntr = 0;
        CogGraphicLabel myBaslerLabel = new CogGraphicLabel();
        CogGraphicLabel myFlirLabel   = new CogGraphicLabel();
        CogPointMarker  baslerMarker; //= new CogPointMarker();
        double          blobAngle        = 0;
        double          blobAngleRadians = 0;

        //Get references to the tools
        CogBlobTool      blobBaslerTool   = (CogBlobTool)toolGroup.Tools["FindWrappersInBasler"];
        CogBlobTool      blobFlirTool     = (CogBlobTool)toolGroup.Tools["PopsicleBlobFinder"];
        CogHistogramTool popsicleHistTool = (CogHistogramTool)toolGroup.Tools["PopsicleHistogramTool"];

        //Define the regions
        CogRectangleAffine popsicleRegion  = blobFlirTool.Region as CogRectangleAffine;
        CogRectangleAffine histogramRegion = blobFlirTool.Region as CogRectangleAffine;


        //Define the fonts
        System.Drawing.Font myBaslerFont = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        System.Drawing.Font myFlirFont   = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));


        //Reset stats
        angleFailures   = 0;
        thermalFailures = 0;

        //Reset any labels and rectangles from previous runs
        BaslerLabels.Clear();
        FlirLabels.Clear();
        FlirRectangles.Clear();


        //***** Run the tools to perform the search in the basler image *****

        //Update status strings for Visual Studio. Do not popup a message box for errors, this causes confusion with the operators.
        toolGroup.SetScriptTerminalData("BaslerStatus", "OK");
        toolGroup.SetScriptTerminalData("FlirStatus", "OK");

        bool acquireException = false;
        try
        {
            //Aquire an image from the Basler, send Exception to Visual Studio
            toolGroup.RunTool(toolGroup.Tools["BaslerAcqFifo"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Check power connections and communication cables.");
            acquireException = true;
        }

        try
        {
            //Aquire an image from the Flir, send Exception to Visual Studio
            toolGroup.RunTool(toolGroup.Tools["FlirAcqFifo"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Check power connections and communication cables.");
            acquireException = true;
        }
        if (acquireException)
        {
            return(false);
        }

        try
        {
            // Scale the Flir image to zoom in to smaller temperature range
            toolGroup.RunTool(toolGroup.Tools["ScaleFlirImagePmap"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: ScaleFlirImagePmap");
            return(false);
        }


        try
        {
            // Transform the images to calibrated space
            toolGroup.RunTool(toolGroup.Tools["CalBasler"], ref message, ref result);
            toolGroup.RunTool(toolGroup.Tools["CalFlir"], ref message, ref result);
        }
        catch (Exception ex)
        {
            //MessageBox.Show("Calibration tool error: " + ex.Message, "Script Exception");
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CalBasler");
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: CalFlir");
            return(false);
        }

        try
        {
            toolGroup.RunTool(toolGroup.Tools["CogPixelMapBasler"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CogPixelMapBasler");
            return(false);
        }

        try
        {
            toolGroup.RunTool(toolGroup.Tools["CogIPOneImageTool1"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CogIPOneImageTool1");
            return(false);
        }

        try
        {
            // Run the Flir hist tool
            toolGroup.RunTool(toolGroup.Tools["PopsicleHistogramTool"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: PopsicleHistogramTool");
            return(false);
        }

        try
        {
            // Run the blob tool and get a reference to the results.
            toolGroup.RunTool(blobBaslerTool, ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: Basler blobBaslerTool");
            return(false);
        }

        CogBlobResultCollection blobResults = blobBaslerTool.Results.GetBlobs();


        // Clear list before starting loop
        malBlobPoses.Clear();
        Crosshairs.Clear();

        // Get group input terminal data
        try
        {
            disableHist          = (bool)toolGroup.GetScriptTerminalData("DisableHistogramInspection");
            minPickAngle         = (double)toolGroup.GetScriptTerminalData("MinPickAngle");
            maxPickAngle         = (double)toolGroup.GetScriptTerminalData("MaxPickAngle");
            minPopsicleHistCount = (double)toolGroup.GetScriptTerminalData("MinPopsicleHistCount");
            VisStudio_Running    = (bool)toolGroup.GetScriptTerminalData("VS_Running");
            showArea             = (bool)toolGroup.GetScriptTerminalData("ShowArea");
            showHist             = (bool)toolGroup.GetScriptTerminalData("ShowHistCount");
            visSideXLength       = (double)toolGroup.GetScriptTerminalData("VisSideXLength");
            visSideYLength       = (double)toolGroup.GetScriptTerminalData("VisSideYLength");
            visFlirRegionXadj    = (double)toolGroup.GetScriptTerminalData("VisFlirRegionXadj");
            visFlirRegionYadj    = (double)toolGroup.GetScriptTerminalData("VisFlirRegionYadj");
        }
        catch (Exception ex)
        {
            //MessageBox.Show("Getting terminal data exception: ", ex.Message);
            toolGroup.SetScriptTerminalData("BaslerStatus", "Getting script data: " + ex.Message);
        }

        // Set run variables for manual triggering
        if (!VisStudio_Running)
        {
            minPopsicleHistCount = 0;
            minPickAngle         = -20;
            maxPickAngle         = 20;
            showArea             = true;
            showHist             = true;
            visSideXLength       = 200;
            visSideYLength       = 70;
            visFlirRegionXadj    = 0;
            visFlirRegionYadj    = 0;
        }


        // ***************************************
        // ******** Process the blobs *********
        // ***************************************
        try
        {
            foreach (CogBlobResult blob in blobResults)
            {
                // Set the transform for collections
                CogTransform2DLinear l2d = new CogTransform2DLinear();
                l2d.TranslationX = blob.GetBoundingBoxAtAngle(blob.Angle).CenterX;
                l2d.TranslationY = blob.GetBoundingBoxAtAngle(blob.Angle).CenterY;
                l2d.Rotation     = blob.Angle;
                blobAngleRadians = blob.Angle;

                // Crosshair setup for the Basler
                baslerMarker             = new CogPointMarker();
                baslerMarker.X           = l2d.TranslationX;
                baslerMarker.Y           = l2d.TranslationY;
                baslerMarker.Color       = CogColorConstants.Green;
                baslerMarker.GraphicType = CogPointMarkerGraphicTypeConstants.Crosshair;

                // Flir region
                CogRectangleAffine myFlirRegion = new CogRectangleAffine();
                myFlirRegion.CenterX     = l2d.TranslationX + visFlirRegionXadj;
                myFlirRegion.CenterY     = l2d.TranslationY + visFlirRegionYadj;
                myFlirRegion.Rotation    = l2d.Rotation;
                myFlirRegion.SideXLength = visSideXLength;
                myFlirRegion.SideYLength = visSideYLength;

                blobFlirTool.Region = myFlirRegion;
                toolGroup.RunTool(blobFlirTool, ref message, ref result);

                popsicleHistTool.Region = myFlirRegion;
                toolGroup.RunTool(popsicleHistTool, ref message, ref result);

                // Get the histogram results from the bin
                binHist = popsicleHistTool.Result.GetHistogram();

                // Count total pixels
                histCntr = 1;
                for (int i = 0; i < blobFlirTool.RunParams.SegmentationParams.HardFixedThreshold; i++)
                {
                    histCntr = histCntr + binHist[i];
                }

                myBaslerLabel = new CogGraphicLabel();
                myBaslerLabel.SetXYText(0, 0, "");
                myFlirLabel = new CogGraphicLabel();

                myBaslerLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                myFlirLabel.Font   = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                myFlirRegion.Visible = true;

                myBaslerLabel.Alignment = CogGraphicLabelAlignmentConstants.BaselineCenter;
                myFlirLabel.Alignment   = CogGraphicLabelAlignmentConstants.BaselineCenter;

                // Decide to add the popsicle blob to the collection list
                if ((histCntr < minPopsicleHistCount) && (!disableHist))
                {
                    myBaslerLabel.Color = CogColorConstants.Red;
                    myFlirRegion.Color  = CogColorConstants.Red;


                    // Show the hist count in the Flir image
                    myFlirLabel.Color = CogColorConstants.Red;
                    if (showHist)
                    {
                        myFlirLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Size: " + histCntr.ToString());
                    }
                    thermalFailures++;
                }
                else
                {
                    myBaslerLabel.Color = CogColorConstants.Green;


                    // If histogram check is disabled, draw rectangle in yellow, else green
                    if (disableHist)
                    {
                        myFlirLabel.Color  = CogColorConstants.Red;
                        myFlirRegion.Color = CogColorConstants.Yellow;
                    }
                    else
                    {
                        myFlirLabel.Color  = CogColorConstants.Green;
                        myFlirRegion.Color = CogColorConstants.Green;
                    }

                    if (showHist)
                    {
                        myFlirLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Size: " + histCntr.ToString());
                    }


                    // Convert blob angle to degrees
                    blobAngle = blob.Angle * 180 / Math.PI;

                    if ((blobAngle > (double)minPickAngle) && (blobAngle < (double)maxPickAngle))
                    {
                        malBlobPoses.Add(l2d);

                        if (showArea)
                        {
                            myBaslerLabel.Color = CogColorConstants.Green;
                            myBaslerLabel.SetXYText(l2d.TranslationX, l2d.TranslationY - 15, "Size: " + blob.Area.ToString("0"));
                        }
                    }
                    else
                    {
                        myBaslerLabel.Color = CogColorConstants.Red;
                        myBaslerLabel.SetXYText(l2d.TranslationX, l2d.TranslationY, "Angle: " + blobAngle.ToString("0"));
                        myFlirLabel.Color  = CogColorConstants.Red;
                        myFlirRegion.Color = CogColorConstants.Red;
                        angleFailures++;
                    }
                }

                myBaslerLabel.Rotation = blobAngleRadians;

                BaslerLabels.Add(myBaslerLabel);
                FlirLabels.Add(myFlirLabel);
                FlirRectangles.Add(myFlirRegion);
                Crosshairs.Add(baslerMarker);

                // Update group output terminals
                toolGroup.SetScriptTerminalData("AngleFailures", angleFailures);
                toolGroup.SetScriptTerminalData("ThermalFailures", thermalFailures);
                toolGroup.SetScriptTerminalData("BlobCollection", malBlobPoses);
            }
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error during blob processing: " + ex.Message);
            malBlobPoses.Clear(); // Clear positional data for this frame
        }

        // Returning False indicates we ran the tools in script, and they should not be
        // run by VisionPro
        return(false);
    }
Пример #28
0
        public void InitVision()
        {
            SettingUp          = false;
            ImageFileTool      = CogImageFileEdit1.Subject;
            ImageFileTool.Ran += ImageFileTool_Ran;
            //Set reference to CogAcqFifoTool created by Edit Control
            //The Acq Fifo Edit Control creates its subject when its AutoCreateTool property is True
            AcqFifoTool      = CogAcqFifoEdit1.Subject;
            AcqFifoTool.Ran += AcqFifoTool_Ran;

            cogAcqTool = CogAcqFifoEdit1.Subject;
            cogAcqTool = cogToolBlockEditV21.Subject.Tools["CogAcqFifoTool1"] as CogAcqFifoTool;
            cogAcqTool.Run();

            //Operator will be Nothing if no Frame Grabber is available.  Disable the Frame Grabber
            //option on the "VisionPro Demo" tab if no frame grabber available.
            if (AcqFifoTool.Operator == null)
            {
                optImageAcquisitionOptionFrameGrabber.Enabled = false;
            }

            //Initialize the Dialog box for the "Open File" button on the "VisionPro Demo" tab.
            ImageAcquisitionCommonDialog.Filter          = ImageFileTool.Operator.FilterText;
            ImageAcquisitionCommonDialog.CheckFileExists = true;
            ImageAcquisitionCommonDialog.ReadOnlyChecked = true;

            //AutoCreateTool for the PMAlign edit control is False, therefore, we must create
            //a PMAlign tool and set the subject of the control to reference the new tool.
            PatMaxTool              = new CogPMAlignTool();
            PatMaxTool.Changed     += PatMaxTool_Changed;
            CogPMAlignEdit1.Subject = PatMaxTool;

            //Change the default Train Region to center of a 640x480 image & change the DOFs
            //so that Skew is not enabled.  Note - TrainRegion is of type ICogRegion, therefore,
            //we must use a CogRectangleAffine reference in order to call CogRectangleAffine
            //properties.
            CogRectangleAffine PatMaxTrainRegion = default(CogRectangleAffine);

            PatMaxTrainRegion = PatMaxTool.Pattern.TrainRegion as CogRectangleAffine;
            //PatMaxTrainRegion = cogPMAlignTool.Pattern.TrainRegion as CogRectangleAffine;
            if ((PatMaxTrainRegion != null))
            {
                PatMaxTrainRegion.SetCenterLengthsRotationSkew(320, 240, 100, 100, 0, 0);
                PatMaxTrainRegion.GraphicDOFEnable = CogRectangleAffineDOFConstants.Position | CogRectangleAffineDOFConstants.Rotation | CogRectangleAffineDOFConstants.Size;
            }
            //PatMaxTool.SearchRegion = PatMaxSearchRegion;
            //PatMaxSearchRegion.SetCenterWidthHeight(320, 240, 640, 480);
            //PatMaxSearchRegion.GraphicDOFEnable = CogRectangleDOFConstants.Position | CogRectangleDOFConstants.Size;
            //PatMaxSearchRegion.Interactive = true;
            numericUpDown1.Value = Convert.ToDecimal(cogPMAlignTool.RunParams.AcceptThreshold);
            PatMaxTool.RunParams.AcceptThreshold = Convert.ToDouble(numericUpDown1.Value);
            numericUpDown2.Value = Convert.ToDecimal(cogPMAlignTool.RunParams.ApproximateNumberToFind);
            PatMaxTool.RunParams.ApproximateNumberToFind = Convert.ToInt32(numericUpDown2.Value);
            myAcqFifo = AcqFifoTool.Operator;
            try
            {
                myFrameGrabber       = cogAcqTool.Operator.FrameGrabber;
                myAcqFifo            = cogAcqTool.Operator;
                AcqFifoTool.Operator = myAcqFifo;

                myAcqFifo.OwnedContrastParams.Contrast     = cogAcqTool.Operator.OwnedContrastParams.Contrast;
                myAcqFifo.OwnedBrightnessParams.Brightness = cogAcqTool.Operator.OwnedBrightnessParams.Brightness;
                brightnessParams = myAcqFifo.OwnedBrightnessParams;
                contrastParams   = myAcqFifo.OwnedContrastParams;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (brightnessParams != null)
            {
                brightnessUpDown.Value = Convert.ToDecimal(brightnessParams.Brightness);
            }
            if (contrastParams != null)
            {
                contrastUpDown.Value = Convert.ToDecimal(contrastParams.Contrast);
            }
            try
            {
                cogToolBlockEditV21.Subject.Inputs["Image"].Value = cogRecordDisplay1.Image;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Input image wasn't set");
            }
        }
Пример #29
0
        public bool Run(CogImage8Grey _SrcImage, ref CogImage8Grey _DestImage, CogRectangle _InspRegion, CogLineFindAlgo _CogLineFindAlgo, ref CogLineFindResult _CogLineFindResult, int _NgNumber = 0)
        {
            bool _Result = true;

            SetCaliperContrastAndHalfPixel(_CogLineFindAlgo.ContrastThreshold, _CogLineFindAlgo.FilterHalfSizePixels);
            SetCaliperDirection(_CogLineFindAlgo.CaliperSearchDirection);
            SetCaliper(_CogLineFindAlgo.CaliperNumber, _CogLineFindAlgo.CaliperSearchLength, _CogLineFindAlgo.CaliperProjectionLength, _CogLineFindAlgo.IgnoreNumber);
            SetCaliperLine(_CogLineFindAlgo.CaliperLineStartX, _CogLineFindAlgo.CaliperLineStartY, _CogLineFindAlgo.CaliperLineEndX, _CogLineFindAlgo.CaliperLineEndY);

            if (true == Inspection(_SrcImage))
            {
                GetResult();
            }
            if (FindLineResults != null && (_CogLineFindAlgo.CaliperNumber - _CogLineFindAlgo.IgnoreNumber) < (FindLineResults.NumPointsFound + 5))
            {
                try
                {
                    _CogLineFindResult.StartX     = FindLineResults.GetLineSegment().StartX;
                    _CogLineFindResult.StartY     = FindLineResults.GetLineSegment().StartY;
                    _CogLineFindResult.EndX       = FindLineResults.GetLineSegment().EndX;
                    _CogLineFindResult.EndY       = FindLineResults.GetLineSegment().EndY;
                    _CogLineFindResult.Length     = FindLineResults.GetLineSegment().Length;
                    _CogLineFindResult.Rotation   = FindLineResults.GetLineSegment().Rotation;
                    _CogLineFindResult.PointCount = FindLineResults.Count;

                    #region Line segment 설정별로, 결과 각도별로 보정값 계산
                    //Radian 값으로 설정
                    //Line segment가 가로
                    //if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -45 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= 45)
                    if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -0.785 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= 0.785)
                    {
                        _CogLineFindResult.LineRotation = FindLineResults.GetLineSegment().Rotation;
                    }

                    //Line segment가 가로
                    //else if ((FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -180 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= -130) ||
                    //    (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= 135 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < 180))
                    else if ((FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -3.15 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= -2.26) ||
                             (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= 2.26 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < 3.14))
                    {
                        if (_CogLineFindResult.Rotation > 0)
                        {
                            _CogLineFindResult.LineRotation = _CogLineFindResult.Rotation - 3.14159;
                        }

                        else
                        {
                            _CogLineFindResult.LineRotation = 3.14159 + _CogLineFindResult.Rotation;
                        }
                    }

                    //Line segment가 세로(90도)
                    else if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= 0.785 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < 2.35)
                    {
                        _CogLineFindResult.LineRotation = (-1.57) + _CogLineFindResult.Rotation;
                    }

                    else if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -2.35 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < -0.785)
                    {
                        _CogLineFindResult.LineRotation = _CogLineFindResult.Rotation - (-1.57);
                    }
                    #endregion

                    if (_CogLineFindAlgo.UseAlignment)
                    {
                        CogAffineTransformTool _CogTransForm = new CogAffineTransformTool();
                        CogRectangleAffine     _AffineRegion = new CogRectangleAffine();
                        _AffineRegion.SetCenterLengthsRotationSkew(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height, _CogLineFindResult.LineRotation, 0);
                        _CogTransForm.InputImage = _SrcImage;
                        _CogTransForm.Region     = _AffineRegion;
                        _CogTransForm.Run();

                        CogCopyRegionTool _CopyRegion = new CogCopyRegionTool();
                        _CopyRegion.InputImage       = _CogTransForm.OutputImage;
                        _CopyRegion.DestinationImage = _SrcImage;
                        _CopyRegion.RunParams.ImageAlignmentEnabled = true;
                        _CopyRegion.Region = null;
                        _CopyRegion.Run();

                        _DestImage = (CogImage8Grey)_CopyRegion.OutputImage;

                        if (true == Inspection(_DestImage))
                        {
                            GetResult();
                        }
                        if (FindLineResults != null)
                        {
                            _CogLineFindResult.StartX     = FindLineResults.GetLineSegment().StartX;
                            _CogLineFindResult.StartY     = FindLineResults.GetLineSegment().StartY;
                            _CogLineFindResult.EndX       = FindLineResults.GetLineSegment().EndX;
                            _CogLineFindResult.EndY       = FindLineResults.GetLineSegment().EndY;
                            _CogLineFindResult.Length     = FindLineResults.GetLineSegment().Length;
                            _CogLineFindResult.Rotation   = FindLineResults.GetLineSegment().Rotation;
                            _CogLineFindResult.PointCount = FindLineResults.Count;

                            _CogLineFindResult.IsGood = true;
                        }

                        else
                        {
                            _CogLineFindResult.IsGood = false;
                        }

                        GC.Collect();
                    }

                    else
                    {
                        _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation;
                        double _Rotation = 0;
                        _Rotation = _CogLineFindResult.Rotation * 180 / Math.PI;
                        _CogLineFindResult.IsGood = true;
                    }
                }

                catch
                {
                    _CogLineFindResult.IsGood = false;
                }
            }

            else
            {
                _CogLineFindResult.IsGood = false;
            }

            return(_Result);
        }
Пример #30
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);
        }