private void AssignToolResult(string parent, CogBlobResults blobResults) { CogBlobResultCollection blobResultColl = blobResults.GetBlobs(false); int count = blobResultColl.Count; AddResult(string.Format("{0}.Count", parent), blobResultColl.Count); double areaX = 0.0; double areaY = 0.0; double totalArea = 0.0; for (int i = 0; i < count; i++) { CogBlobResult blobResult = blobResultColl[i]; double x = blobResult.CenterOfMassX; double y = blobResult.CenterOfMassY; double area = blobResult.Area; totalArea += area; areaX += x * area; areaY += y * area; AddResult(string.Format("{0}[{1}].Area", parent, i), area); AddResult(string.Format("{0}[{1}].CenterOfMassX", parent, i), x); AddResult(string.Format("{0}[{1}].CenterOfMassY", parent, i), y); AddResult(string.Format("{0}[{1}].Angle", parent, i), blobResult.Angle); } AddResult(string.Format("{0}[+].Area", parent), totalArea); AddResult(string.Format("{0}[A].CenterOfMassX", parent), totalArea > 0 ? areaX / totalArea : 0.0); AddResult(string.Format("{0}[A].CenterOfMassY", parent), totalArea > 0 ? areaY / totalArea : 0.0); }
private bool GetResult(bool _IsGraphicResult) { bool _Result = true; if (null == BlobResults || BlobResults.GetBlobs().Count < 0) { return(false); } InspResults.BlobCount = BlobResults.GetBlobs().Count; InspResults.BlobArea = new double[BlobResults.GetBlobs().Count]; InspResults.Width = new double[BlobResults.GetBlobs().Count]; InspResults.Height = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMinX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMinY = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMaxX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMaxY = new double[BlobResults.GetBlobs().Count]; InspResults.BlobCenterX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobCenterY = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMessCenterX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMessCenterY = new double[BlobResults.GetBlobs().Count]; InspResults.OriginX = new double[BlobResults.GetBlobs().Count]; InspResults.OriginY = new double[BlobResults.GetBlobs().Count]; InspResults.IsGoods = new bool[BlobResults.GetBlobs().Count]; if (_IsGraphicResult) { InspResults.ResultGraphic = new CogCompositeShape[InspResults.BlobCount]; } for (int iLoopCount = 0; iLoopCount < InspResults.BlobCount; ++iLoopCount) { BlobResult = BlobResults.GetBlobByID(iLoopCount); InspResults.BlobArea[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.Area, iLoopCount); InspResults.Width[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeWidth, iLoopCount); InspResults.Height[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeHeight, iLoopCount); InspResults.BlobMinX[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMinX, iLoopCount); InspResults.BlobMinY[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMinY, iLoopCount); InspResults.BlobMaxX[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMaxX, iLoopCount); InspResults.BlobMaxY[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMaxY, iLoopCount); InspResults.BlobCenterX[iLoopCount] = (InspResults.BlobMaxX[iLoopCount] + InspResults.BlobMinX[iLoopCount]) / 2; InspResults.BlobCenterY[iLoopCount] = (InspResults.BlobMaxY[iLoopCount] + InspResults.BlobMinY[iLoopCount]) / 2; InspResults.BlobMessCenterX[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.CenterMassX, iLoopCount); InspResults.BlobMessCenterY[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.CenterMassY, iLoopCount); if (_IsGraphicResult) { InspResults.ResultGraphic[iLoopCount] = BlobResult.CreateResultGraphics(CogBlobResultGraphicConstants.Boundary); } } return(_Result); }
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 InspectionBlob() { BlobProc = new CogBlob(); BlobResults = new CogBlobResults(); BlobResult = new CogBlobResult(); InspResults = new CogBlobReferenceResult(); BlobProc.SegmentationParams.Mode = CogBlobSegmentationModeConstants.HardFixedThreshold; BlobProc.SegmentationParams.Polarity = CogBlobSegmentationPolarityConstants.LightBlobs; BlobProc.SegmentationParams.HardFixedThreshold = 100; BlobProc.ConnectivityMode = CogBlobConnectivityModeConstants.GreyScale; BlobProc.ConnectivityCleanup = CogBlobConnectivityCleanupConstants.Fill; BlobProc.ConnectivityMinPixels = 10; }
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(); }
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 bool Run(CogImage8Grey _SrcImage, CogRectangle _InspRegion, CogEllipseAlgo _CogEllipseAlgo, ref CogEllipseResult _CogEllipseResult, double _OffsetX = 0, double _OffsetY = 0, int _NgNumber = 0) { bool _Result = true; #region Caliper Center XY 구하기 -> Blob으로 Center 위치 Search #region GetAutoThresholdValue CogHistogramTool _HistoTool = new CogHistogramTool(); _HistoTool.InputImage = _SrcImage; _HistoTool.Region = _InspRegion; _HistoTool.Run(); int[] _HistoValue = _HistoTool.Result.GetHistogram(); double _TotSize = _InspRegion.Width * _InspRegion.Height; double _ThresholdSum = 0; int _ThresholdValue = 0; for (int iLoopCount = 0; iLoopCount < 256; ++iLoopCount) { _ThresholdSum += iLoopCount * _HistoValue[iLoopCount]; } double _ThresholdSum2 = 0; double _WeightBack = 0, _WeightFore = 0, _VarMax = 0; for (int iLoopCount = 0; iLoopCount < 256; ++iLoopCount) { _WeightBack += _HistoValue[iLoopCount]; if (0 == _WeightBack) { continue; } _WeightFore = _TotSize - _WeightBack; if (0 == _WeightFore) { break; } _ThresholdSum2 += (double)(iLoopCount * _HistoValue[iLoopCount]); double _MeanBack = _ThresholdSum2 / _WeightBack; double _MeanFore = (_ThresholdSum - _ThresholdSum2) / _WeightFore; double _VarBetween = _WeightBack * _WeightFore * Math.Pow((_MeanBack - _MeanFore), 2); if (_VarBetween > _VarMax) { _VarMax = _VarBetween; _ThresholdValue = iLoopCount; } } #endregion #region Blob Search CogBlobTool _BlobTool = new CogBlobTool(); _BlobTool.InputImage = _SrcImage; _BlobTool.Region = _InspRegion; _BlobTool.RunParams.SegmentationParams.Mode = CogBlobSegmentationModeConstants.HardFixedThreshold; _BlobTool.RunParams.SegmentationParams.Polarity = CogBlobSegmentationPolarityConstants.LightBlobs; _BlobTool.RunParams.ConnectivityMode = CogBlobConnectivityModeConstants.GreyScale; _BlobTool.RunParams.ConnectivityCleanup = CogBlobConnectivityCleanupConstants.Fill; _BlobTool.RunParams.SegmentationParams.HardFixedThreshold = _ThresholdValue; _BlobTool.RunParams.ConnectivityMinPixels = 10000; _BlobTool.Run(); CogBlobResults _BlobResults = _BlobTool.Results; double _MaxSize = 0; double _CaliperCenterX = 0; double _CaliperCenterY = 0; if (_BlobResults.GetBlobs().Count > 0) { for (int iLoopCount = 0; iLoopCount < _BlobResults.GetBlobs().Count; ++iLoopCount) { CogBlobResult _BlobResult = _BlobResults.GetBlobByID(iLoopCount); if (_BlobResult.Area > _MaxSize) { _MaxSize = _BlobResult.Area; _CaliperCenterX = _BlobResult.CenterOfMassX; _CaliperCenterY = _BlobResult.CenterOfMassY; } } } else { _CaliperCenterX = _CogEllipseAlgo.ArcCenterX - _OffsetX; _CaliperCenterY = _CogEllipseAlgo.ArcCenterY - _OffsetY; } //CogSerializer.SaveObjectToFile(_BlobTool, string.Format(@"D:\CircleBlob.vpp")); #endregion #endregion SetCaliperDirection(_CogEllipseAlgo.CaliperSearchDirection, _CogEllipseAlgo.CaliperPolarity); SetCaliper(_CogEllipseAlgo.CaliperNumber, _CogEllipseAlgo.CaliperSearchLength, _CogEllipseAlgo.CaliperProjectionLength, _CogEllipseAlgo.CaliperIgnoreNumber); //LJH 2019.05.23 Caliper Center 기준점 변경 //SetEllipticalArc(_CogEllipseAlgo.ArcCenterX - _OffsetX, _CogEllipseAlgo.ArcCenterY - _OffsetY, _CogEllipseAlgo.ArcRadiusX, _CogEllipseAlgo.ArcRadiusY, _CogEllipseAlgo.ArcAngleSpan); SetEllipticalArc(_CaliperCenterX, _CaliperCenterY, _CogEllipseAlgo.ArcRadiusX, _CogEllipseAlgo.ArcRadiusY, _CogEllipseAlgo.ArcAngleSpan); if (true == Inspection(_SrcImage)) { GetResult(); } if (FindEllipseResults != null && FindEllipseResults.Count > 0) { _CogEllipseResult.IsGood = true; } else { _CogEllipseResult.IsGood = false; } if (!_CogEllipseResult.IsGood) { CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Ellipse Find Fail!!", CLogManager.LOG_LEVEL.MID); _CogEllipseResult.CenterX = _CogEllipseAlgo.ArcCenterX; _CogEllipseResult.CenterY = _CogEllipseAlgo.ArcCenterY; _CogEllipseResult.RadiusX = _CogEllipseAlgo.ArcRadiusX; _CogEllipseResult.RadiusY = _CogEllipseAlgo.ArcRadiusY; _CogEllipseResult.OriginX = 0; _CogEllipseResult.OriginY = 0; _CogEllipseResult.Rotation = 0; _CogEllipseResult.NgNumber = _NgNumber; } else { if (FindEllipseResults.GetEllipse() != null) { CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Ellipse Complete", CLogManager.LOG_LEVEL.MID); _CogEllipseResult.PointFoundCount = FindEllipseResults.NumPointsFound; _CogEllipseResult.CenterX = FindEllipseResults.GetEllipse().CenterX; _CogEllipseResult.CenterY = FindEllipseResults.GetEllipse().CenterY; _CogEllipseResult.RadiusX = FindEllipseResults.GetEllipse().RadiusX; _CogEllipseResult.RadiusY = FindEllipseResults.GetEllipse().RadiusY; _CogEllipseResult.OriginX = FindEllipseResults.GetEllipse().CenterX; _CogEllipseResult.OriginY = FindEllipseResults.GetEllipse().CenterY; _CogEllipseResult.Rotation = FindEllipseResults.GetEllipse().Rotation; _CogEllipseResult.NgNumber = _NgNumber; _CogEllipseResult.PointPosXInfo = new double[FindEllipseResults.Count]; _CogEllipseResult.PointPosYInfo = new double[FindEllipseResults.Count]; _CogEllipseResult.PointStatusInfo = new bool[FindEllipseResults.Count]; for (int iLoopCount = 0; iLoopCount < FindEllipseResults.Count; ++iLoopCount) { if (true == FindEllipseResults[iLoopCount].Found) { _CogEllipseResult.PointPosXInfo[iLoopCount] = FindEllipseResults[iLoopCount].X; _CogEllipseResult.PointPosYInfo[iLoopCount] = FindEllipseResults[iLoopCount].Y; } _CogEllipseResult.PointStatusInfo[iLoopCount] = FindEllipseResults[iLoopCount].Used; } _CogEllipseResult.DiameterMinAlgo = _CogEllipseAlgo.DiameterSize - _CogEllipseAlgo.DiameterMinus; _CogEllipseResult.DiameterMaxAlgo = _CogEllipseAlgo.DiameterSize + _CogEllipseAlgo.DiameterPlus; CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - Center X : {0}, Y : {1}", _CogEllipseResult.CenterX.ToString("F2"), _CogEllipseResult.CenterY.ToString("F2")), CLogManager.LOG_LEVEL.MID); CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - Radius X : {0}, Y : {1}", _CogEllipseResult.RadiusX.ToString("F2"), _CogEllipseResult.RadiusY.ToString("F2")), CLogManager.LOG_LEVEL.MID); } else { CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Ellipse Find Fail!!", CLogManager.LOG_LEVEL.MID); _CogEllipseResult.CenterX = _CogEllipseAlgo.ArcCenterX; _CogEllipseResult.CenterY = _CogEllipseAlgo.ArcCenterY; _CogEllipseResult.RadiusX = _CogEllipseAlgo.ArcRadiusX; _CogEllipseResult.RadiusY = _CogEllipseAlgo.ArcRadiusY; _CogEllipseResult.OriginX = 0; _CogEllipseResult.OriginY = 0; _CogEllipseResult.NgNumber = _NgNumber; _CogEllipseResult.IsGood = false; } } CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Result : " + _CogEllipseResult.IsGood.ToString(), CLogManager.LOG_LEVEL.MID); return(_Result); }
public bool Run(CogImage8Grey _SrcImage, CogRectangle _InspRegion, CogBlobAlgo _CogBlobAlgo, ref CogBlobResult _CogBlobResult, int _NgNumber = 0) { bool _Result = true; SetHardFixedThreshold(_CogBlobAlgo.ThresholdMin); SetConnectivityMinimum((int)_CogBlobAlgo.BlobAreaMin); SetPolarity(Convert.ToBoolean(_CogBlobAlgo.ForeGround)); //SetMeasurement(CogBlobMeasureConstants.Area, CogBlobMeasureModeConstants.Filter, CogBlobFilterModeConstants.IncludeBlobsInRange, _CogBlobReferAlgo.BlobAreaMin, _CogBlobReferAlgo.BlobAreaMax); return(_Result); }
string Blob_Packet(CogBlobResult blob) { return(String.Format($"{objectManager.mToolBlockProcess.RunStatus.Result},ID={blob.ID},angle={blob.Angle},x={blob.CenterOfMassX},y={blob.CenterOfMassY}\r\n")); }
private bool GetResult(bool _IsGraphicResult = false) { bool _Result = true; if (null == BlobResult || BlobResults.GetBlobs().Count < 0) { return(false); } InspResults.IsGood = true; InspResults.BlobCount = BlobResults.GetBlobs().Count; InspResults.BlobArea = new double[BlobResults.GetBlobs().Count]; InspResults.BlobCenterX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobCenterY = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMinX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMinY = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMaxX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMaxY = new double[BlobResults.GetBlobs().Count]; InspResults.Width = new double[BlobResults.GetBlobs().Count]; InspResults.Height = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMessCenterX = new double[BlobResults.GetBlobs().Count]; InspResults.BlobMessCenterY = new double[BlobResults.GetBlobs().Count]; InspResults.PrincipalWidth = new double[BlobResults.GetBlobs().Count]; InspResults.PrincipalHeight = new double[BlobResults.GetBlobs().Count]; InspResults.Angle = new double[BlobResults.GetBlobs().Count]; InspResults.Degree = new double[BlobResults.GetBlobs().Count]; InspResults.IsLeadBentGood = new bool[BlobResults.GetBlobs().Count]; InspResults.LeadPitchTopX = new double[BlobResults.GetBlobs().Count]; InspResults.LeadPitchTopY = new double[BlobResults.GetBlobs().Count]; InspResults.LeadPitchBottomX = new double[BlobResults.GetBlobs().Count]; InspResults.LeadPitchBottomY = new double[BlobResults.GetBlobs().Count]; InspResults.LeadLength = new double[BlobResults.GetBlobs().Count]; InspResults.LeadLengthStartX = new double[BlobResults.GetBlobs().Count]; InspResults.LeadLengthStartY = new double[BlobResults.GetBlobs().Count]; if (_IsGraphicResult) { InspResults.ResultGraphic = new CogCompositeShape[InspResults.BlobCount]; } for (int iLoopCount = 0; iLoopCount < InspResults.BlobCount; ++iLoopCount) { BlobResult = BlobResults.GetBlobByID(iLoopCount); InspResults.BlobArea[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.Area, iLoopCount); InspResults.Width[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeWidth, iLoopCount); InspResults.Height[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeHeight, iLoopCount); InspResults.BlobMinX[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMinX, iLoopCount); InspResults.BlobMinY[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMinY, iLoopCount); InspResults.BlobMaxX[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMaxX, iLoopCount); InspResults.BlobMaxY[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPixelAlignedNoExcludeMaxY, iLoopCount); InspResults.BlobCenterX[iLoopCount] = (InspResults.BlobMaxX[iLoopCount] + InspResults.BlobMinX[iLoopCount]) / 2; InspResults.BlobCenterY[iLoopCount] = (InspResults.BlobMaxY[iLoopCount] + InspResults.BlobMinY[iLoopCount]) / 2; InspResults.BlobMessCenterX[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.CenterMassX, iLoopCount); InspResults.BlobMessCenterY[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.CenterMassY, iLoopCount); InspResults.PrincipalWidth[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPrincipalAxisWidth, iLoopCount); InspResults.PrincipalHeight[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.BoundingBoxPrincipalAxisHeight, iLoopCount); InspResults.Angle[iLoopCount] = BlobResults.GetBlobMeasure(CogBlobMeasureConstants.Angle, iLoopCount); InspResults.Degree[iLoopCount] = InspResults.Angle[iLoopCount] * 180 / Math.PI; if (_IsGraphicResult) { InspResults.ResultGraphic[iLoopCount] = BlobResult.CreateResultGraphics(CogBlobResultGraphicConstants.Boundary); } } return(_Result); }