//If PMAlign results have changed then update the Score & Region graphic.
 //Handles PatMaxTool.Changed
 private void PatMaxTool_Changed(object sender, Cognex.VisionPro.CogChangedEventArgs e)
 {
     //If FunctionalArea And cogFA_Tool_Results Then
     if ((Cognex.VisionPro.Implementation.CogToolBase.SfCreateLastRunRecord
          | Cognex.VisionPro.Implementation.CogToolBase.SfRunStatus) > 0)
     {
         cogRecordDisplay1.StaticGraphics.Clear();
         //Note, Results will be nothing if Run failed.
         if (PatMaxTool.Results == null)
         {
             txtPatMaxScoreValue.Text = "N/A";
         }
         else if (PatMaxTool.Results.Count > 0)
         {
             //Passing result does not imply Pattern is found, must check count.
             txtPatMaxScoreValue.Text = PatMaxTool.Results[0].Score.ToString("g3");
             txtPatMaxScoreValue.Refresh();
             CogCompositeShape resultGraphics = default(CogCompositeShape);
             resultGraphics = PatMaxTool.Results[0].CreateResultGraphics(CogPMAlignResultGraphicConstants.MatchRegion);
             cogRecordDisplay1.InteractiveGraphics.Add(resultGraphics, "test", false);
         }
         else
         {
             txtPatMaxScoreValue.Text = "N/A";
         }
     }
 }
Пример #2
0
        private void PatMaxTool_Changed(object sender, Cognex.VisionPro.CogChangedEventArgs e)
        {
            //If FunctionalArea And cogFA_Tool_Results Then
            if ((Cognex.VisionPro.Implementation.CogToolBase.SfCreateLastRunRecord |
                 Cognex.VisionPro.Implementation.CogToolBase.SfRunStatus) > 0)
            {
                //Note, Results will be nothing if Run failed.
                if (PatMaxTool.Results == null)
                {
                    //txtPatMaxScoreValue.Text = "N/A";
                }
                else if (PatMaxTool.Results.Count > 0)
                {
                    int nRetrieved = PatMaxTool.Results.Count;

                    for (int nItem = 0; nItem < nRetrieved; nItem++)
                    {
                        if (nItem >= PARAM_NUM_TO_FIND)
                        {
                            break;
                        }

                        int nIndexer = nItem;//listSorted.ElementAt(nItem);

                        try
                        {
                            CogPMAlignResult result = PatMaxTool.Results[nIndexer];

                            if (result.Score <= PARAM_ACCEPT_RATIO / 100.0)
                            {
                                continue;
                            }

                            //Passing result does not imply Pattern is found, must check count.
                            CogCompositeShape resultGraphics = default(CogCompositeShape);
                            resultGraphics = PatMaxTool.Results[nIndexer].CreateResultGraphics(CogPMAlignResultGraphicConstants.MatchRegion);

                            CogRectangle rect     = resultGraphics.EnclosingRectangle(CogCopyShapeConstants.All);
                            RectangleF   rcResult = new RectangleF((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);

                            // Get matced Template Center
                            PointF ptTemplateCenter = CRect.GetCenter(rcResult);

                            // Set Relative Distance
                            PointF ptDistance = CPoint.GetDistancePoint(PARAM_PT_RELATIVE_ORIGIN, ptTemplateCenter);

                            CogTransform2DLinear ll = result.GetPose();

                            ptrnResult.AddData(rcResult, ptTemplateCenter, ptDistance, result.Score, 0);
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    //txtPatMaxScoreValue.Text = "N/A";
                }
            }
        }