Exemplo n.º 1
0
        public Boolean LoadFromVPPFile(string FileName)//檔案參數載入
        {
            string ProcID       = System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString();
            string TempFileName = (string)FileName;

            try
            {
                //從CogTool裡面讀出來
                string       strFolderPath = @"D:\VPS_File\Product\FindLineTool\" + @FileName + @"\";
                CogToolBlock ToolBlock1    = new CogToolBlock();

                FileName = strFolderPath + FileName + "_FLT.vpp";

                ToolBlock1 = (CogToolBlock)CogSerializer.LoadObjectFromFile(FileName);//開啟ToolBlock vpp檔案

                //依序載入
                mFindLineTool = (CogFindLineTool)ToolBlock1.Tools[TempFileName + "_FindLineTool_"];
                mFindLineTool.Run();

                SaveLog.Msg_("Data of Find Line Tool Loaded : " + @FileName);
                ToolBlock1 = null;

                FindLineTool_Status = true;
                return(true);
            }
            catch (Exception ex)
            {
                SaveLog.Msg_("Save Data Failed : " + ModularID + ":\r\n" + ProcID + ":\r\n" + ex.ToString());
                FindLineTool_Status = false;
                return(false);
            }
        }
Exemplo n.º 2
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HLRun(System.Drawing.Bitmap bipmapImage, out CResultData objResultData)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try
                {
                    m_dScore = 0;
                    m_objFindLineTool.InputImage = new CogImage8Grey(bipmapImage);
                    m_objFindLineTool.Run();

                    if (0 < m_objFindLineTool.Results.Count)
                    {
                        m_objResultLine        = m_objFindLineTool.Results.GetLine();
                        m_objResultLineSegment = m_objFindLineTool.Results.GetLineSegment();
                        m_objGraphics          = m_objFindLineTool.Results[0].CreateResultGraphics(CogFindLineResultGraphicConstants.All);

                        m_objResultLine.GetXYRotation(out m_dLinePositionX, out m_dLinePositionY, out m_dAngle);
                        m_dAngle = m_dAngle * (180 / Math.PI);
                    }
                    else
                    {
                        m_dLinePositionX = 0; m_dLinePositionY = 0; m_dAngle = 0;
                        MakeErrorMessage("HLSaveRecipe", 5305, "Line Fail");
                        break;
                    }
                }
                catch (System.Exception ex)
                {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    break;
                }

                m_dScore = 1;
                bReturn  = true;
            } while(false);

            //   objResultData.objGraphics = new CogCompositeShape();
            objResultData.dLinePositionX[0] = m_dLinePositionX;    objResultData.dLinePositionY[0] = m_dLinePositionY;        objResultData.dLineAngle[0] = m_dAngle;    objResultData.dScore[0] = m_dScore;
            //  objResultData.objGraphics = m_objGraphics;               objResultData.bitmapInputImage = bipmapImage;
            objResultData.bResult = bReturn;
            m_objResultData       = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
Exemplo n.º 3
0
        private bool Inspection(CogImage8Grey _SrcImage)
        {
            bool _Result = true;

            try
            {
                FindLineProc.InputImage = _SrcImage;
                FindLineProc.Run();
            }

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

            return(_Result);
        }
Exemplo n.º 4
0
        public Boolean Run(CogImage8Grey mInputImage)
        {
            string ProcID = System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString();

            FindLineTool_Status = false;

            try
            {
                mFindLineTool.InputImage = mInputImage;

                mFindLineTool.Run();
                FindLineTool_Status = true;
                return(true);
            }
            catch (Exception ex)
            {
                SaveLog.Msg_("FindLineTool ROI_create Failed : " + ModularID + ":\r\n" + ProcID + ":\r\n" + ex.ToString());
                return(false);
            }
        }
Exemplo n.º 5
0
        private void BtnRun_Click(object sender, EventArgs e)
        {
            var pDocument = CDocument.GetDocument;

            do
            {
                try {
                    m_objFindLineToolTop.Run();
                    m_objFindLineToolBottom.Run();

                    m_objCogDisplayMain.InteractiveGraphics.Clear();
                    m_objCogDisplayMain.StaticGraphics.Clear();

                    bool bResultTop    = false;
                    bool bResultBottom = false;
                    if (null != m_objFindLineToolTop.Results && 0 < m_objFindLineToolTop.Results.Count)
                    {
                        for (int iLoopCount = 0; iLoopCount < m_objFindLineToolTop.Results.Count; iLoopCount++)
                        {
                            m_objCogDisplayMain.StaticGraphics.Add(m_objFindLineToolTop.Results[iLoopCount].CreateResultGraphics(CogFindLineResultGraphicConstants.DataPoint | CogFindLineResultGraphicConstants.TipText), "");
                            m_objCogDisplayMain.StaticGraphics.Add(m_objFindLineToolTop.Results.GetLine(), "");
                        }
                        bResultTop = true;
                    }

                    if (null != m_objFindLineToolBottom.Results && 0 < m_objFindLineToolBottom.Results.Count)
                    {
                        for (int iLoopCount = 0; iLoopCount < m_objFindLineToolBottom.Results.Count; iLoopCount++)
                        {
                            m_objCogDisplayMain.StaticGraphics.Add(m_objFindLineToolBottom.Results[iLoopCount].CreateResultGraphics(CogFindLineResultGraphicConstants.DataPoint | CogFindLineResultGraphicConstants.TipText), "");
                            m_objCogDisplayMain.StaticGraphics.Add(m_objFindLineToolBottom.Results.GetLine(), "");
                        }
                        bResultBottom = true;
                    }

                    if (false == bResultTop || false == bResultBottom)
                    {
                        break;
                    }

                    CogLine objCogLine = new CogLine();
                    objCogLine.SelectedSpaceName = "#";
                    objCogLine.SetXYRotation(m_objListImage[m_iPositionCrop].Width / 2, 0, 90 * (Math.PI / 180));
                    m_objCogDisplayMain.StaticGraphics.Add(objCogLine, "");

                    double dPositionXTop    = 0;
                    double dPositionYTop    = 0;
                    double dPositionXBottom = 0;
                    double dPositionYBottom = 0;

                    CogIntersectLineLineTool objIntersectLine = new CogIntersectLineLineTool();
                    objIntersectLine.InputImage = m_objListImage[m_iPositionCrop];
                    objIntersectLine.LineA      = m_objFindLineToolTop.Results.GetLine();
                    objIntersectLine.LineB      = objCogLine;
                    objIntersectLine.Run();
                    dPositionXTop = objIntersectLine.X;
                    dPositionYTop = objIntersectLine.Y;

                    objIntersectLine.LineA = m_objFindLineToolBottom.Results.GetLine();
                    objIntersectLine.LineB = objCogLine;
                    objIntersectLine.Run();
                    dPositionXBottom = objIntersectLine.X;
                    dPositionYBottom = objIntersectLine.Y;

                    CogDistancePointPointTool objDistance = new CogDistancePointPointTool();
                    objDistance.InputImage = m_objListImage[m_iPositionCrop];
                    objDistance.StartX     = dPositionXTop;
                    objDistance.StartY     = dPositionYTop;
                    objDistance.EndX       = dPositionXBottom;
                    objDistance.EndY       = dPositionYBottom;
                    objDistance.Run();

                    CogGraphicLabel objLabel = new CogGraphicLabel();
                    objLabel.SelectedSpaceName = "#";
                    objLabel.Alignment         = CogGraphicLabelAlignmentConstants.BottomLeft;
                    double dDistance = objDistance.Distance * pDocument.m_objConfig.GetCameraParameter(( int )CDefine.enumCamera.CAMERA_1).dResolution;
                    objLabel.SetXYText(m_objListImage[m_iPositionCrop].Width / 2, 0, string.Format("DISTANCE : {0:F2}", dDistance));
                    m_objCogDisplayMain.StaticGraphics.Add(objLabel, "");
                } catch (Exception ex) {
                    pDocument.SetUpdateLog(CDefine.enumLogType.LOG_VISION_EXCEPTION_CAMERA_0, "CDialogFindLineSetting - Reload : " + ex.ToString());
                }
            } while(false);
        }
Exemplo n.º 6
0
        public static List <double> find(int toolNum, int method)
        {
            object toolgroup = CogSerializer.LoadObjectFromFile("c://tool.vpp");
            object job       = CogSerializer.LoadObjectFromFile("QuickBuild1.vpp");

            switch (toolNum)
            {
            case 0:  toolgroup = CogSerializer.LoadObjectFromFile("c://tool0.vpp");
                break;

            case 1:  toolgroup = CogSerializer.LoadObjectFromFile("c://tool1.vpp");
                break;

            case 2: toolgroup = CogSerializer.LoadObjectFromFile("c://tool2.vpp");
                break;

            case 3: toolgroup = CogSerializer.LoadObjectFromFile("c://tool3.vpp");
                break;

            default: break;
            }

            CogToolGroup  ToolGroup1 = toolgroup as CogToolGroup;
            CogJobManager cojob      = job as CogJobManager;
            CogJob        cojob      = cojob.Job["CogJob1"] as CogJob;


            CogImageFileTool myFile = ToolGroup1.Tools["CogImageFileTool1"] as CogImageFileTool;

            myFile.Run();
            CogFindCircleTool myCircleTool = ToolGroup1.Tools["CogFindCircleTool1"] as CogFindCircleTool;
            CogFindLineTool   myLineTool   = ToolGroup1.Tools["CogFindLineTool1"] as CogFindLineTool;

            switch (method)
            {
            case 1: myCircleTool.Run();
                break;

            case 2: myLineTool.Run();
                break;

            case 3: myCircleTool.Run();
                myLineTool.Run();
                break;

            default: break;
            }
            double Lx0    = 0;
            double Lx1    = 0;
            double Ly0    = 0;
            double Ly1    = 0;
            double Langle = 0;
            double Cx     = 0;
            double Cy     = 0;
            double Cr     = 0;


            if (method == 1 | method == 3)
            {
                Cx = myCircleTool.Results.GetCircle().CenterX;
                Cy = myCircleTool.Results.GetCircle().CenterY;
                Cr = myCircleTool.Results.GetCircle().Radius;
            }
            if (method == 2 | method == 3)
            {
                Lx0    = myLineTool.Results.GetLineSegment().StartX;
                Ly0    = myLineTool.Results.GetLineSegment().StartY;
                Lx1    = myLineTool.Results.GetLineSegment().EndX;
                Ly1    = myLineTool.Results.GetLineSegment().EndY;
                Langle = myLineTool.Results.GetLine().Rotation;
            }
            double[] result = { Cx, Cy, Cr, Lx0, Ly0, Lx1, Ly1, Langle };
            return(new List <double>(result));
        }