예제 #1
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);
        }
예제 #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;
                    //이미지 결과 그래픽 생성
                    objResultData.objLineGraphics = new CogCompositeShape[2];

                    for (int iLoopCount = 0; iLoopCount < ( int )CResultData.enumLine.LINE_FINAL; iLoopCount++)
                    {
                        m_objFindLineTool[iLoopCount].InputImage = new CogImage8Grey(bipmapImage);
                        m_objFindLineTool[iLoopCount].Run();

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

                            objResultData.objLineGraphics[iLoopCount] = new CogCompositeShape();
                            objResultData.objLineGraphics[iLoopCount] = m_objLineGraphics[iLoopCount];
                            m_objResultLine[iLoopCount].GetXYRotation(out m_dLinePositionX[iLoopCount], out m_dLinePositionY[iLoopCount], out m_dLineAngle[iLoopCount]);
                            m_dLineAngle[iLoopCount] = m_dLineAngle[iLoopCount] * (180 / Math.PI);
                        }
                        else
                        {
                            m_dLinePositionX[iLoopCount] = 0; m_dLinePositionY[iLoopCount] = 0; m_dLineAngle[iLoopCount] = 0;
                            MakeErrorMessage("HLSaveRecipe", 5405, "Line Fail");
                            break;
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    break;
                }

                m_objIntersectTool.InputImage = new CogImage8Grey(bipmapImage);
                m_objIntersectTool.LineA      = m_objResultLine[( int )CResultData.enumLine.LINE_VERTICAL]; m_objIntersectTool.LineB = m_objResultLine[( int )CResultData.enumLine.LINE_HORIZON];
                m_objIntersectTool.Run();

                if (true == m_objIntersectTool.Intersects)
                {
                    m_dAngle = Math.Abs(m_objIntersectTool.Angle * (180 / Math.PI));

                    if ((85 < m_dAngle || 95 > m_dAngle) || (265 < m_dAngle || 275 > m_dAngle))
                    {
                        m_dPositionX = m_objIntersectTool.X; m_dPositionY = m_objIntersectTool.Y;
                    }
                    else
                    {
                        m_dPositionX = -1; m_dPositionY = -1;
                        MakeErrorMessage("HLSaveRecipe", 5406, "IntersectTool Angle Range Out");
                        break;
                    }
                }
                else
                {
                    m_dPositionX = -1; m_dPositionY = -1;
                    MakeErrorMessage("HLSaveRecipe", 5407, "IntersectTool Fail");
                    break;
                }

                m_dScore = 1;
                bReturn  = true;
            } while(false);
            for (int iLoopCount = 0; iLoopCount < ( int )CResultData.enumLine.LINE_FINAL; iLoopCount++)
            {
                objResultData.dLinePositionX[iLoopCount] = m_dLinePositionX[iLoopCount];    objResultData.dLinePositionY[0] = m_dLinePositionY[iLoopCount];        objResultData.dLineAngle[0] = m_dLineAngle[iLoopCount];
            }
            objResultData.dPositionX[0] = m_dPositionX; objResultData.dPositionY[0] = m_dPositionY; objResultData.dScore[0] = m_dScore;
            //      objResultData.bitmapInputImage = bipmapImage;
            objResultData.bResult = bReturn; objResultData.eLibrary = CResultData.enumLibrary.FINDLINE_INTERSECT;
            m_objResultData       = ( CResultData )objResultData.Clone();

            return(bReturn);
        }