public static byte[] /*****/ HC_CropImage_Center(byte[] rawInput, int imageW, int imageH, RectangleF rc, PointF ptCenter) { PointF ptDist = CPoint.GetDistancePoint(CRect.GetCenter(rc), ptCenter); rc.Offset(ptDist); int nLength = (int)rc.Width * (int)rc.Height; int toHeight = (int)rc.Y + (int)rc.Height; int toWidth = (int)rc.Width; int px = (int)rc.X; byte[] rawCrop = new byte[nLength]; if (CRect.IsIntersectRect(new RectangleF(0, 0, imageW, imageH), rc) == true) { for (int y = (int)rc.Y, copyLine = 0; y < toHeight; y++) { Buffer.BlockCopy(rawInput, y * imageW + px, rawCrop, toWidth * copyLine++, toWidth); } } return(rawCrop); }
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"; } } }