public InspectionAutoPattern() { HistogramProc = new CogHistogram(); HistogramResult = new CogHistogramResult(); OneImageProc = new CogIPOneImageTool(); BlobProc = new CogBlob(); BlobResults = new CogBlobResults(); BlobResult = new CogBlobResult(); PMAlignProc = new CogPMAlignTool(); PMAlignProc.Pattern.TrainAlgorithm = CogPMAlignTrainAlgorithmConstants.PatMax; PMAlignResult = new CogPMAlignResult(); }
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"; } } }