// 2015.06.15 public void ViewResult2(ADisplay aDisplay, bool isShowRegion) { if (m_cogCaliperTool == null) { return; } // 2015.02.09 if (isShowRegion) { ShowRegion(aDisplay); } int nFindCount = m_cogCaliperTool.Results.Count; if (nFindCount > 0) { CogCaliperResults cogCaliperResults = new CogCaliperResults(); cogCaliperResults = m_cogCaliperTool.Results; if (cogCaliperResults != null && cogCaliperResults.Count >= 1) { CogCaliperResult caliperResult = new CogCaliperResult(); caliperResult = cogCaliperResults[0]; CogCompositeShape compositeShape = new CogCompositeShape(); compositeShape = caliperResult.CreateResultGraphics((CogCaliperResultGraphicConstants)(1 + 2)); aDisplay.AddOverlay((ICogGraphicInteractive)compositeShape, ""); } } }
//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"; } } }
private void Recognize_Click(object sender, EventArgs e) { this.cogDisplayRecognize.StaticGraphics.Clear(); this.txtResult.Text = string.Empty; this.txtLocationX.Text = string.Empty; this.txtLocationY.Text = string.Empty; this.txtConstrast.Text = string.Empty; if (!_PMAlignTool.Pattern.Trained) { TrainCurrentImage(); } try { _PMAlignTool.RunParams.AcceptThreshold = double.Parse(this.spinAcceptThreshold.Value.ToString()); //_PMAlignTool.RunParams.ContrastThreshold = 10; _PMAlignTool.RunParams.RunAlgorithm = (CogPMAlignRunAlgorithmConstants)Enum.Parse (typeof(CogPMAlignRunAlgorithmConstants), this.cboRunAlgorithm.Text); _PMAlignTool.RunParams.RunMode = (CogPMAlignRunModeConstants)Enum.Parse (typeof(CogPMAlignRunModeConstants), this.cboRunMode.Text); _PMAlignTool.InputImage = new CogImage8Grey(_inputImageRecognize); _PMAlignTool.Run(); if ((CogToolBase.SfCreateLastRunRecord == (int)CogBarcodeLastRunRecordConstants.ResultsBounds) || (CogToolBase.SfRunStatus == 4)) { if (_PMAlignTool.Results == null && _PMAlignTool.RunStatus.Exception != null) { return; } var bestResult = from CogPMAlignResult eachResult in _PMAlignTool.Results orderby(eachResult.GetPose().TranslationX) orderby eachResult.GetPose().TranslationY select eachResult; foreach (CogPMAlignResult eachResult in bestResult) { CogTransform2DLinear resultPosition = eachResult.GetPose(); this.txtResult.Text += eachResult.Score.ToString("0.00") + ";"; this.txtLocationX.Text += resultPosition.TranslationX.ToString("0.00") + ";"; this.txtLocationY.Text += resultPosition.TranslationY.ToString("0.00") + ";"; this.txtConstrast.Text += eachResult.Contrast.ToString("0.00") + ";"; CogCompositeShape shape = eachResult.CreateResultGraphics(CogPMAlignResultGraphicConstants.All); ICogGraphic graphic = shape.CopyBase(CogCopyShapeConstants.BasicGraphics); graphic.Color = CogColorConstants.Green; this.cogDisplayRecognize.StaticGraphics.Add(graphic, "ResultRegion"); } } } catch (Exception ex) { XtraMessageBox.Show(string.Format("Recognize Failed! {0}", ex.Message)); } }
public CogCompositeShape[] GetGraphicResult() { CogCompositeShape[] _GraphicResult = new CogCompositeShape[BlobResults.GetBlobs().Count]; CogBlobResult _BlobResult = new CogBlobResult(); for (int iLoopCount = 0; iLoopCount < BlobResults.GetBlobs().Count; ++iLoopCount) { BlobResult = BlobResults.GetBlobByID(iLoopCount); _GraphicResult[iLoopCount] = BlobResult.CreateResultGraphics(CogBlobResultGraphicConstants.Boundary); } return(_GraphicResult); }
public void ViewResult(ADisplay displayInput, ADisplay displayOutput, bool isShowMedian, bool isShowMean, bool isShowRegion) { int nOption = 0; if (isShowMean) { nOption = nOption + 64; } if (isShowMedian) { nOption = nOption + 128; } // 2015.02.09 if (isShowRegion) { ShowRegion(displayInput); } if (m_isRun) { CogHistogramResult histResult = new CogHistogramResult(); histResult = m_cogHistogramTool.Result; if (histResult != null) { // 2015.02.09 /* * if (isShowRegion) * { * ShowRegion(displayInput); * } */ CogCompositeShape compositeShape = new CogCompositeShape(); compositeShape = histResult.CreateResultGraphics((CogHistogramResultGraphicConstants)(1 + 2 + 16 + nOption)); if (displayOutput != null) { displayOutput.ClearAll(); displayOutput.AddOverlay((ICogGraphicInteractive)compositeShape, ""); displayOutput.Display.Fit(true); } } } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //수정 : //목적 : 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); }
public void ViewResult(ADisplay aDisplay, bool isShowCenter, bool isShowRegion) { int nOption = 0; if (isShowCenter) { nOption = 2; } // 2015.02.09 if (isShowRegion) { ShowRegion(aDisplay); } if (m_nFindCount > 0) { CogBlobResult cogBlobResult = new CogBlobResult(); // 2016.03.22 int[] pnID = new int[m_nFindCount]; pnID = m_cogBlobTool.Results.GetBlobIDs(true); for (int i = 0; i < m_nFindCount; i++) { // 2016.03.22 i => pnID[i] cogBlobResult = m_cogBlobTool.Results.GetBlobByID(pnID[i]); if (cogBlobResult != null) { CogCompositeShape cogCompositeShape = new CogCompositeShape(); cogCompositeShape = cogBlobResult.CreateResultGraphics((CogBlobResultGraphicConstants)(1 + 4 + nOption)); aDisplay.AddOverlay((ICogGraphicInteractive)cogCompositeShape, ""); } } // 2015.02.09 /* * if (isShowRegion) * { * ShowRegion(aDisplay); * } */ } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //수정 : //목적 : 초기화 //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override bool HLInitialize(HLDevice.Abstract.CVisionLibraryAbstract.CInitializeParameter objInitializeParameter) { bool bReturn = false; do { m_objResultLine = new CogLine(); m_objResultLineSegment = new CogLineSegment(); m_objGraphics = new CogCompositeShape(); m_objFindLineTool = new CogFindLineTool(); m_iIndex = m_objInitializeParameter.iIndex; m_objInitializeParameter = ( CInitializeParameter )objInitializeParameter.Clone(); HLLoadRecipe(m_objInitializeParameter.strRecipePath, m_objInitializeParameter.strRecipeName); bReturn = true; } while(false); return(bReturn); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //수정 : //목적 : 초기화 //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override bool HLInitialize(HLDevice.Abstract.CVisionLibraryAbstract.CInitializeParameter objInitializeParameter) { bool bReturn = false; do { m_objInitializeParameter = (HLDevice.Abstract.CVisionLibraryAbstract.CInitializeParameter)objInitializeParameter.Clone(); m_objFindLineTool = new CogFindLineTool[( int )CResultData.enumLine.LINE_FINAL]; m_objResultLine = new CogLine[( int )CResultData.enumLine.LINE_FINAL]; m_objResultLineSegment = new CogLineSegment[( int )CResultData.enumLine.LINE_FINAL]; m_objLineGraphics = new CogCompositeShape[( int )CResultData.enumLine.LINE_FINAL]; m_dLinePositionX = new double[( int )CResultData.enumLine.LINE_FINAL]; m_dLinePositionY = new double[( int )CResultData.enumLine.LINE_FINAL]; m_dLineAngle = new double[( int )CResultData.enumLine.LINE_FINAL]; for (int iLoopCount = 0; iLoopCount < ( int )CResultData.enumLine.LINE_FINAL; iLoopCount++) { m_objFindLineTool[iLoopCount] = new CogFindLineTool(); m_objResultLine[iLoopCount] = new CogLine(); m_objResultLineSegment[iLoopCount] = new CogLineSegment(); m_objLineGraphics[iLoopCount] = new CogCompositeShape(); } m_objIntersectTool = new CogIntersectLineLineTool(); m_iIndex = m_objInitializeParameter.iIndex; m_objInitializeParameter = ( CInitializeParameter )objInitializeParameter.Clone(); HLLoadRecipe(m_objInitializeParameter.strRecipePath, m_objInitializeParameter.strRecipeName); bReturn = true; } while(false); return(bReturn); }
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"; } } }
public void DrawBlobResult(CogCompositeShape ResGraphic, string GroupName) { ResGraphic.Color = CogColorConstants.Blue; ResGraphic.LineWidthInScreenPixels = 2; kCogDisplay.StaticGraphics.Add(ResGraphic, GroupName); }