private void ApplyNeedleCircleFindValueFunction(CogNeedleFindAlgo _CogNeedleFindAlgo, ref CogNeedleFindResult _CogNeedleFindResult) { if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } AlgorithmAreaDisplayRefresh(); bool _Result = InspNeedleCircleFindProcess.Run(InspectionImage, _CogNeedleFindAlgo, ref _CogNeedleFindResult); _CogNeedleFindResult.CenterXReal = (_CogNeedleFindResult.CenterX - (InspectionImage.Width / 2)) * ResolutionX; _CogNeedleFindResult.CenterYReal = (_CogNeedleFindResult.CenterY - (InspectionImage.Height / 2)) * ResolutionY; _CogNeedleFindResult.OriginXReal = (_CogNeedleFindResult.OriginX - (InspectionImage.Width / 2)) * ResolutionX; _CogNeedleFindResult.OriginYReal = (_CogNeedleFindResult.OriginY - (InspectionImage.Height / 2)) * ResolutionY; _CogNeedleFindResult.RadiusReal = _CogNeedleFindResult.Radius * ResolutionX; CogCircle _CogCircle = new CogCircle(); if (_CogNeedleFindResult.Radius <= 0) { return; } _CogCircle.SetCenterRadius(_CogNeedleFindResult.CenterX, _CogNeedleFindResult.CenterY, _CogNeedleFindResult.Radius); CogPointMarker _CogCenterPoint = new CogPointMarker(); _CogCenterPoint.SetCenterRotationSize(_CogNeedleFindResult.CenterX, _CogNeedleFindResult.CenterY, 0, 2); kpTeachDisplay.DrawStaticShape(_CogCircle, "Circle", CogColorConstants.Green, 3); kpTeachDisplay.DrawStaticShape(_CogCenterPoint, "CirclePoint", CogColorConstants.Green); string _CenterName = string.Format("X = {0:F2}mm, Y = {1:F2}mm, R = {2:F2}mm", _CogNeedleFindResult.CenterXReal, _CogNeedleFindResult.CenterYReal, _CogNeedleFindResult.RadiusReal); kpTeachDisplay.DrawText(_CenterName, _CogNeedleFindResult.CenterX, _CogNeedleFindResult.CenterY + 150, CogColorConstants.Green, 10, CogGraphicLabelAlignmentConstants.BaselineCenter); }
private void Init() { m_cogCalibNPointToNPointTool.Calibration.NumPoints = 3; for (int i = 0; i < 3; i++) { m_pcogPointMaker[i] = new CogPointMarker(); m_cogCalibNPointToNPointTool.Calibration.GetRawCalibratedPoint(i, out m_pdRawX[i], out m_pdRawY[i]); m_cogCalibNPointToNPointTool.Calibration.GetUncalibratedPoint(i, out m_pdPixelX[i], out m_pdPixelY[i]); } m_bCalibrated = m_cogCalibNPointToNPointTool.Calibration.Calibrated; m_icogImageCalibration = m_cogCalibNPointToNPointTool.CalibrationImage; m_bSwapY = m_cogCalibNPointToNPointTool.Calibration.SwapCalibratedHandedness; m_dCaibratedOriginX = m_cogCalibNPointToNPointTool.Calibration.CalibratedOriginX; m_dCaibratedOriginY = m_cogCalibNPointToNPointTool.Calibration.CalibratedOriginY; m_dCaibratedRotation = m_cogCalibNPointToNPointTool.Calibration.CalibratedXAxisRotation; m_dOriginX = m_dCaibratedOriginX; m_dOriginY = m_dCaibratedOriginY; m_dRotation = m_dCaibratedRotation; // 2015.04.08 m_cogCalibNPointToNPointTool.Ran += new EventHandler(RanEvent); }
private void btnUnitPatternAreaSet_Click(object sender, EventArgs e) { #region Button Status btnUnitPatternSearchAreaShow.Enabled = true; btnUnitPatternSearchAreaShow.BackColor = Color.SandyBrown; btnUnitPatternSearchAreaSet.Enabled = false; btnUnitPatternSearchAreaSet.BackColor = Color.Gray; btnUnitPatternOriginCenterSet.Enabled = false; btnUnitPatternOriginCenterSet.BackColor = Color.Gray; btnUnitPatternAreaShow.Enabled = true; btnUnitPatternAreaShow.BackColor = Color.PaleGreen; btnUnitPatternAreaSet.Enabled = false; btnUnitPatternAreaSet.BackColor = Color.Gray; //btnUnitPatternAreaCancel.Enabled = false; #endregion Button Status CogRectangle _PatternRegion = kpTeachDisplay.GetInterActiveRectangle(); CogPointMarker _PatternOrigin = new CogPointMarker(); _PatternOrigin.SetCenterRotationSize(_PatternRegion.CenterX, _PatternRegion.CenterY, 0, 2); kpTeachDisplay.ClearDisplay("PatternRegion"); kpTeachDisplay.ClearDisplay("PatternOriginPoint"); kpTeachDisplay.DrawStaticShape(_PatternRegion, "PatternRegion", CogColorConstants.Green, 2, CogGraphicLineStyleConstants.Dash); kpTeachDisplay.DrawStaticShape(_PatternOrigin, "PatternOriginPoint", CogColorConstants.Green, 14); MapDataParam.Unit.PatternAreaCenterX = _PatternRegion.CenterX; MapDataParam.Unit.PatternAreaCenterY = _PatternRegion.CenterY; MapDataParam.Unit.PatternAreaWidth = _PatternRegion.Width; MapDataParam.Unit.PatternAreaHeight = _PatternRegion.Height; MapDataParam.Unit.PatternAreaOriginX = _PatternOrigin.X; MapDataParam.Unit.PatternAreaOriginY = _PatternOrigin.Y; //Pattern 등록 CogPMAlignPattern _Pattern = InspPattern.GetPatternReference(OriginImage, _PatternRegion, _PatternOrigin.X, _PatternOrigin.Y); kpPatternDisplay.SetDisplayImage((CogImage8Grey)_Pattern.GetTrainedPatternImage()); MapDataParam.Info.UnitPattern = _Pattern; SelectingRectName = SelectedRectName = ""; IsDrawPatterns = false; }
private void ShowSearchArea() { if (MapDataParam.Info.UnitListCenterX == null || MapDataParam.Info.UnitListCenterY == null) { return; } if (MapDataParam.Info.UnitListCenterX.Count == 0 || MapDataParam.Info.UnitListCenterY.Count == 0) { return; } if (MapDataParam.Info.UnitListCenterX.Count != MapDataParam.Info.UnitListCenterY.Count) { return; } uint _RowCount = Convert.ToUInt32(numUpDownUnitRowCount.Value); uint _ColCount = Convert.ToUInt32(numUpDownUnitColumnCount.Value); int _TotalCount = MapDataParam.Info.UnitListCenterX.Count; if (_TotalCount != (_RowCount * _ColCount)) { MessageBox.Show(string.Format("Total : {0}, Row : {1}, Column : {2}", _TotalCount, _RowCount, _ColCount)); return; } CenterPoint[] _CenterPointArray = new CenterPoint[_TotalCount]; for (int iLoopCount = 0; iLoopCount < _TotalCount; ++iLoopCount) { _CenterPointArray[iLoopCount] = new CenterPoint(); _CenterPointArray[iLoopCount].X = MapDataParam.Info.UnitListCenterX[iLoopCount]; _CenterPointArray[iLoopCount].Y = MapDataParam.Info.UnitListCenterY[iLoopCount]; } CenterPoint[,] _SortedCenterPoint = CenterPointSort((uint)_RowCount, (uint)_ColCount, _CenterPointArray); MapDataParam.Info.UnitListCenterX.Clear(); MapDataParam.Info.UnitListCenterY.Clear(); for (int iLoopCount = 0; iLoopCount < _RowCount; ++iLoopCount) { for (int jLoopCount = 0; jLoopCount < _ColCount; ++jLoopCount) { MapDataParam.Info.UnitListCenterX.Add(_SortedCenterPoint[iLoopCount, jLoopCount].X); MapDataParam.Info.UnitListCenterY.Add(_SortedCenterPoint[iLoopCount, jLoopCount].Y); } } kpTeachDisplay.ClearDisplay(); for (int iLoopCount = 0; iLoopCount < MapDataParam.Info.UnitListCenterX.Count; ++iLoopCount) { CogRectangle _FindPattern = new CogRectangle(); _FindPattern.SetCenterWidthHeight(MapDataParam.Info.UnitListCenterX[iLoopCount], MapDataParam.Info.UnitListCenterY[iLoopCount], MapDataParam.Info.UnitListWidth[iLoopCount], MapDataParam.Info.UnitListHeight[iLoopCount]); kpTeachDisplay.DrawStaticShape(_FindPattern, "SearchArea" + (iLoopCount + 1)); CogPointMarker _OriginPoint = new CogPointMarker(); _OriginPoint.SetCenterRotationSize(MapDataParam.Info.UnitListCenterX[iLoopCount], MapDataParam.Info.UnitListCenterY[iLoopCount], 0, 2); kpTeachDisplay.DrawStaticShape(_OriginPoint, "PatternOrigin" + (iLoopCount + 1), CogColorConstants.Green, 12); kpTeachDisplay.DrawText((iLoopCount + 1).ToString(), MapDataParam.Info.UnitListCenterX[iLoopCount], MapDataParam.Info.UnitListCenterY[iLoopCount] - 15, CogColorConstants.Green, 10); } SelectingRectName = SelectedRectName = ""; IsDrawPatterns = true; }
public CogPointMarker GetInterActivePoint() { CogPointMarker cogPointMarker = new CogPointMarker(); double CenterX, CenterY, Rotate; int Pixel; InteractivePointMarker.GetCenterRotationSize(out CenterX, out CenterY, out Rotate, out Pixel); cogPointMarker.SetCenterRotationSize(CenterX, CenterY, Rotate, Pixel); return(cogPointMarker); }
private void btnUnitPatternOriginCenterSet_Click(object sender, EventArgs e) { CogRectangle _PatternRegion = kpTeachDisplay.GetInterActiveRectangle(); CogPointMarker _PatternOrigin = new CogPointMarker(); _PatternOrigin.SetCenterRotationSize(_PatternRegion.CenterX, _PatternRegion.CenterY, 0, 2); kpTeachDisplay.ClearDisplay("PatternOriginPoint"); kpTeachDisplay.DrawInterActiveShape(_PatternOrigin, "PatternOriginPoint", CogColorConstants.Green, 14); }
/// <summary> /// Display에 그리기 /// </summary> /// <param name="_cogRectAffine">CogRectangleAffine 영역</param> /// <param name="_Interactive">Interactive = true, Static = false</param> public void DrawShape(CogPointMarker _cogPointMarker, string _groupName, CogColorConstants _color, bool _Interactive) { if (_Interactive == true) { DrawInterActiveShape(_cogPointMarker, _groupName, _color); } else { DrawStaticShape(_cogPointMarker, _groupName, _color); } }
/// <summary> /// /// </summary> /// <param name="_cogPointMarker"></param> /// <param name="_groupName"></param> /// <param name="_color"></param> public void DrawInterActiveShape(CogPointMarker _cogPointMarker, string _groupName, CogColorConstants _color, int _LineSize = 12) { InteractivePointMarker = new CogPointMarker(); InteractivePointMarker = _cogPointMarker; InteractivePointMarker.Interactive = true; InteractivePointMarker.Color = _color; InteractivePointMarker.LineWidthInScreenPixels = 2; InteractivePointMarker.SizeInScreenPixels = _LineSize; InteractivePointMarker.GraphicType = CogPointMarkerGraphicTypeConstants.Cross; InteractivePointMarker.GraphicDOFEnable = CogPointMarkerDOFConstants.All; kCogDisplay.ClearDisplay(_groupName); kCogDisplay.InteractiveGraphics.Add(InteractivePointMarker, _groupName, true); }
public void DrwaInterActiveCross(int _StartX, int _StartY, int _Thickness, int _CrossSize, string _GroupName, CogColorConstants _Color) { InteractivePointMarker = new CogPointMarker(); InteractivePointMarker.Interactive = true; InteractivePointMarker.Color = _Color; InteractivePointMarker.X = _StartX; InteractivePointMarker.Y = _StartY; InteractivePointMarker.LineWidthInScreenPixels = _Thickness; InteractivePointMarker.SizeInScreenPixels = _CrossSize; InteractivePointMarker.GraphicType = CogPointMarkerGraphicTypeConstants.Cross; InteractivePointMarker.GraphicDOFEnable = CogPointMarkerDOFConstants.All; kCogDisplay.ClearDisplay(_GroupName); kCogDisplay.InteractiveGraphics.Add(InteractivePointMarker, _GroupName, true); }
/// <summary> /// 수정이 불가능한 고정 도형 그리기 /// </summary> /// <param name="_cogRectAffine">RectAffine 객체</param> /// <param name="_groupName">그려지는 그룹명</param> /// <param name="_color">색상</param> public void DrawStaticShape(CogPointMarker _cogPointMarker, string _groupName, CogColorConstants _color, int _LineSize = 12, bool ClearFlag = true) { StaticPointMarker = new CogPointMarker(); StaticPointMarker = _cogPointMarker; StaticPointMarker.Color = _color; StaticPointMarker.LineWidthInScreenPixels = 2; StaticPointMarker.SizeInScreenPixels = _LineSize; StaticPointMarker.GraphicType = CogPointMarkerGraphicTypeConstants.Cross; if (ClearFlag == true) { kCogDisplay.ClearDisplay(_groupName); } kCogDisplay.StaticGraphics.Add(StaticPointMarker, _groupName); }
public void DrawStaticCross(double _StartX, double _StartY, int _Thickness, int _CrossSize, string _GroupName, CogColorConstants _Color) { StaticPointMarker = new CogPointMarker(); StaticPointMarker.Interactive = false; StaticPointMarker.Color = _Color; StaticPointMarker.X = _StartX; StaticPointMarker.Y = _StartY; StaticPointMarker.LineWidthInScreenPixels = _Thickness; StaticPointMarker.SizeInScreenPixels = _CrossSize; StaticPointMarker.GraphicType = CogPointMarkerGraphicTypeConstants.Cross; StaticPointMarker.GraphicDOFEnable = CogPointMarkerDOFConstants.All; //kCogDisplay.ClearDisplay(_GroupName); kCogDisplay.StaticGraphics.Add(StaticPointMarker, _GroupName); }
private void DrawReferRegionFunction(CogRectangle _ReferRegion, double _OriginX, double _OriginY, CogColorConstants _Color) { if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } AlgorithmAreaDisplayRefresh(); CogPointMarker _PointMarker = new CogPointMarker(); _PointMarker.SetCenterRotationSize(_OriginX, _OriginY, 0, 1); kpTeachDisplay.DrawInterActiveShape(_ReferRegion, "ReferRegion", _Color); kpTeachDisplay.DrawInterActiveShape(_PointMarker, "ReferOriginPoint", _Color, 14); }
private void ApplyBlobReferenceValueFunction(CogBlobReferenceAlgo _CogBlobReferAlgo, ref CogBlobReferenceResult _CogBlobReferResult) { if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } AlgorithmAreaDisplayRefresh(); CogRectangleAffine _AlgoRegionAffine = new CogRectangleAffine(); _AlgoRegionAffine.SetCenterLengthsRotationSkew(AlgoRegionRectangle.CenterX, AlgoRegionRectangle.CenterY, AlgoRegionRectangle.Width, AlgoRegionRectangle.Height, 0, 0); bool _Result = InspBlobReferProcess.Run(InspectionImage, _AlgoRegionAffine, _CogBlobReferAlgo, ref _CogBlobReferResult); for (int iLoopCount = 0; iLoopCount < _CogBlobReferResult.BlobCount; ++iLoopCount) { double _Width = _CogBlobReferResult.Width[iLoopCount] * ResolutionX; double _Height = _CogBlobReferResult.Height[iLoopCount] * ResolutionX; if (_CogBlobReferAlgo.WidthMin < _Width && _CogBlobReferAlgo.WidthMax > _Width && _CogBlobReferAlgo.HeightMin < _Height && _CogBlobReferAlgo.HeightMax > _Height) { CogRectangle _BlobRect = new CogRectangle(); _BlobRect.SetCenterWidthHeight(_CogBlobReferResult.BlobCenterX[iLoopCount], _CogBlobReferResult.BlobCenterY[iLoopCount], _CogBlobReferResult.Width[iLoopCount], _CogBlobReferResult.Height[iLoopCount]); kpTeachDisplay.DrawStaticShape(_BlobRect, "BlobRect" + (iLoopCount + 1), CogColorConstants.Green); kpTeachDisplay.DrawBlobResult(_CogBlobReferResult.ResultGraphic[iLoopCount], "BlobRectGra" + (iLoopCount + 1)); CogPointMarker _Point = new CogPointMarker(); _Point.X = _CogBlobReferResult.OriginX[iLoopCount]; _Point.Y = _CogBlobReferResult.OriginY[iLoopCount]; kpTeachDisplay.DrawStaticShape(_Point, "BlobSearchPoint", CogColorConstants.Green, 5); string _RectSizeName = string.Format("W : {0:F2}mm, H : {1:F2}mm, Area : {2}", _Width, _Height, _CogBlobReferResult.BlobArea[iLoopCount]); kpTeachDisplay.DrawText(_RectSizeName, _CogBlobReferResult.BlobCenterX[iLoopCount] + _CogBlobReferResult.Width[iLoopCount] / 2 + 100, _CogBlobReferResult.BlobCenterY[iLoopCount] + _CogBlobReferResult.Height[iLoopCount] / 2 + 100, CogColorConstants.Green, 10, CogGraphicLabelAlignmentConstants.BaselineCenter); } } }
private void ApplyAutoPatternFindValueFunction(CogAutoPatternAlgo _CogAutoPatternAlgo, ref CogAutoPatternResult _CogAutoPatternResult) { if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } AlgorithmAreaDisplayRefresh(); bool _Result = InspAutoPatternProcess.Run(InspectionImage, AlgoRegionRectangle, _CogAutoPatternAlgo, ref _CogAutoPatternResult); if (_CogAutoPatternAlgo.ReferenceInfoList.Count != 0) { CogRectangle _PatternRect = new CogRectangle(); _PatternRect.SetCenterWidthHeight(_CogAutoPatternResult.CenterX, _CogAutoPatternResult.CenterY, _CogAutoPatternResult.Width, _CogAutoPatternResult.Height); kpTeachDisplay.DrawStaticShape(_PatternRect, "AutoPatternRect" + 1, CogColorConstants.Green); CogPointMarker _Point = new CogPointMarker(); _Point.SetCenterRotationSize(_CogAutoPatternResult.OriginPointX, _CogAutoPatternResult.OriginPointY, 0, 2); kpTeachDisplay.DrawStaticShape(_Point, "AutoPatternOrigin" + 1, CogColorConstants.Green, 12); string _MatchingName = string.Format($"Rate = {_CogAutoPatternResult.Score:F2}, X = {_CogAutoPatternResult.OriginPointX:F2}, Y = {_CogAutoPatternResult.OriginPointY:F2}"); kpTeachDisplay.DrawText(_MatchingName, _CogAutoPatternResult.OriginPointX, _CogAutoPatternResult.OriginPointY + 30, CogColorConstants.Green, 10, CogGraphicLabelAlignmentConstants.BaselineCenter); } }
private void ApplyMultiPatternValueFunction(CogMultiPatternAlgo _CogMultiPatternAlgo, ref CogMultiPatternResult _CogMultiPatternResult) { if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } AlgorithmAreaDisplayRefresh(); bool _Result = InspMultiPatternProcess.Run(InspectionImage, AlgoRegionRectangle, _CogMultiPatternAlgo, ref _CogMultiPatternResult); for (int iLoopCount = 0; iLoopCount < _CogMultiPatternResult.FindCount; ++iLoopCount) { CogRectangle _PatternRect = new CogRectangle(); _PatternRect.SetCenterWidthHeight(_CogMultiPatternResult.CenterX[iLoopCount], _CogMultiPatternResult.CenterY[iLoopCount], _CogMultiPatternResult.Width[iLoopCount], _CogMultiPatternResult.Height[iLoopCount]); kpTeachDisplay.DrawStaticShape(_PatternRect, "PatternRect" + (iLoopCount + 1), CogColorConstants.Green); CogPointMarker _Point = new CogPointMarker(); _Point.SetCenterRotationSize(_CogMultiPatternResult.OriginPointX[iLoopCount], _CogMultiPatternResult.OriginPointY[iLoopCount], 0, 2); kpTeachDisplay.DrawStaticShape(_Point, "PatternOrigin" + (iLoopCount + 1), CogColorConstants.Green, 12); string _MatchingName = string.Format($"Rate = {_CogMultiPatternResult.Score[iLoopCount]:F2}, X = {_CogMultiPatternResult.OriginPointX[iLoopCount]:F2}, Y = {_CogMultiPatternResult.OriginPointY[iLoopCount]:F2}"); kpTeachDisplay.DrawText(_MatchingName, _CogMultiPatternResult.OriginPointX[iLoopCount], _CogMultiPatternResult.OriginPointY[iLoopCount] + 30, CogColorConstants.Green, 10, CogGraphicLabelAlignmentConstants.BaselineCenter); } }
private void btnFindCenter_Click(object sender, EventArgs e) { try { CogFitCircleTool fitCircle = new CogFitCircleTool(); fitCircle.InputImage = this.cogRecordDisplay1.Image; fitCircle.RunParams.NumPoints = 0; for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { double x = double.Parse(this.dataGridView1.Rows[i].Cells[0].Value.ToString()); double y = double.Parse(this.dataGridView1.Rows[i].Cells[1].Value.ToString()); fitCircle.RunParams.AddPoint(x, y); } fitCircle.Run(); circleX = Math.Round(fitCircle.Result.GetCircle().CenterX, 3); circleY = Math.Round(fitCircle.Result.GetCircle().CenterY, 3); double circleRadius = Math.Round(fitCircle.Result.GetCircle().Radius, 3); fitCircle.Result.GetCircle().Color = CogColorConstants.Green; CogPointMarker ptr = new CogPointMarker(); ptr.Color = CogColorConstants.Green; ptr.SetCenterRotationSize(circleX, circleY, 0, 60); this.cogRecordDisplay1.StaticGraphics.Add(fitCircle.Result.GetCircle(), ""); this.cogRecordDisplay1.StaticGraphics.Add(ptr, ""); txtResultX.Text = circleX.ToString("f3"); txtResultY.Text = circleY.ToString("f3"); txtResultRadius.Text = circleRadius.ToString("f3"); } catch (Exception ex) { MessageBox.Show("计算旋转中心失败"); txtResultX.Text = string.Empty; txtResultY.Text = string.Empty; txtResultRadius.Text = string.Empty; } }
//private void DrawAutoPatternRegionFunction(CogRectangle _ReferRegion, double _OriginX, double _OriginY, CogColorConstants _Color) //{ // if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } // AlgorithmAreaDisplayRefresh(); // CogPointMarker _PointMarker = new CogPointMarker(); // _PointMarker.SetCenterRotationSize(_OriginX, _OriginY, 0, 1); // kpTeachDisplay.DrawInterActiveShape(_ReferRegion, "ReferRegion", _Color); // kpTeachDisplay.DrawInterActiveShape(_PointMarker, "ReferOriginPoint", _Color, 14); //} private void AutoPatternActionFunction(eReferAction _ReferAction, int _Index = 0) { if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } //if (_ReferAction == eReferAction.ADD) //{ // CogPointMarker _PointMark = new CogPointMarker(); // int _Pixel; // double _PointCenterX, _PointCenterY, _Rotate; // _PointMark = kpTeachDisplay.GetInterActivePoint(); // _PointMark.GetCenterRotationSize(out _PointCenterX, out _PointCenterY, out _Rotate, out _Pixel); // CogRectangle _ReferRegion = new CogRectangle(); // CogRectangle _Boundary = new CogRectangle(); // _Boundary.SetXYWidthHeight(AlgoRegionRectangle.X, AlgoRegionRectangle.Y, AlgoRegionRectangle.Width, AlgoRegionRectangle.Height); // if (false == GetCorrectionRectangle(kpTeachDisplay, _Boundary, ref _ReferRegion)) { MessageBox.Show("The rectangle is outside the inspection area."); return; } // double _OriginPointOffsetX = _ReferRegion.CenterX - _PointCenterX; // double _OriginPointOffsetY = _ReferRegion.CenterY - _PointCenterY; // DrawReferRegionFunction(_ReferRegion, _PointMark.X, _PointMark.Y, CogColorConstants.Cyan); // //Pattern 추출 // ReferenceInformation _PatternInfo = new ReferenceInformation(); // _PatternInfo.StaticStartX = _ReferRegion.X; // _PatternInfo.StaticStartY = _ReferRegion.Y; // _PatternInfo.CenterX = _ReferRegion.CenterX; // _PatternInfo.CenterY = _ReferRegion.CenterY; // _PatternInfo.Width = _ReferRegion.Width; // _PatternInfo.Height = _ReferRegion.Height; // _PatternInfo.OriginPointOffsetX = _OriginPointOffsetX; // _PatternInfo.OriginPointOffsetY = _OriginPointOffsetY; // _PatternInfo.Reference = InspPatternProcess.GetPatternReference(InspectionImage, _ReferRegion, _PointCenterX, _PointCenterY); // ((CogPatternAlgo)InspParam.InspAreaParam[InspAreaSelected].InspAlgoParam[InspAlgoSelected].Algorithm).ReferenceInfoList.Add(_PatternInfo); // //((CogMultiPatternAlgo)InspParam.InspAreaParam[InspAreaSelected].InspAlgoParam[InspAlgoSelected].Algorithm).ReferenceInfoList.Add(_PatternInfo); //} else if (_ReferAction == eReferAction.MODIFY) { CogPointMarker _PointMark = new CogPointMarker(); int _Pixel; double _PointCenterX, _PointCenterY, _Rotate; _PointMark = kpTeachDisplay.GetInterActivePoint(); _PointMark.GetCenterRotationSize(out _PointCenterX, out _PointCenterY, out _Rotate, out _Pixel); CogRectangle _ReferRegion = new CogRectangle(); CogRectangle _Boundary = new CogRectangle(); _Boundary.SetXYWidthHeight(AlgoRegionRectangle.X, AlgoRegionRectangle.Y, AlgoRegionRectangle.Width, AlgoRegionRectangle.Height); if (false == GetCorrectionRectangle(kpTeachDisplay, _Boundary, ref _ReferRegion)) { MessageBox.Show("The rectangle is outside the inspection area."); return; } double _OriginPointOffsetX = _ReferRegion.CenterX - _PointCenterX; double _OriginPointOffsetY = _ReferRegion.CenterY - _PointCenterY; DrawReferRegionFunction(_ReferRegion, _PointMark.X, _PointMark.Y, CogColorConstants.Cyan); //Pattern 추출 ReferenceInformation _PatternInfo = new ReferenceInformation(); _PatternInfo.StaticStartX = _ReferRegion.X; _PatternInfo.StaticStartY = _ReferRegion.Y; _PatternInfo.CenterX = _ReferRegion.CenterX; _PatternInfo.CenterY = _ReferRegion.CenterY; _PatternInfo.Width = _ReferRegion.Width; _PatternInfo.Height = _ReferRegion.Height; _PatternInfo.OriginPointOffsetX = _OriginPointOffsetX; _PatternInfo.OriginPointOffsetY = _OriginPointOffsetY; bool PatternResult = InspPatternProcess.GetPatternReference(InspectionImage, _ReferRegion, _PointCenterX, _PointCenterY, ref _PatternInfo.Reference); if (PatternResult) { ((CogPatternAlgo)InspParam.InspAreaParam[InspAreaSelected].InspAlgoParam[InspAlgoSelected].Algorithm).ReferenceInfoList[_Index] = _PatternInfo; } } //else if (_ReferAction == eReferAction.DEL) //{ // kpTeachDisplay.ClearDisplay("ReferRegion"); // kpTeachDisplay.ClearDisplay("ReferOriginPoint"); // ((CogPatternAlgo)InspParam.InspAreaParam[InspAreaSelected].InspAlgoParam[InspAlgoSelected].Algorithm).ReferenceInfoList.RemoveAt(_Index); //} GC.Collect(); }
//#region "when the tool group is run" // The GroupRun function is called when the tool group is run. The default // implementation provided here is equivalent to the normal behavior of the // tool group. Modifying this function will allow you to change the behavior // when the tool group is run. public override bool GroupRun(ref string message, ref CogToolResultConstants result) { // To let the execution stop in this script when a debugger is attached, uncomment the following lines. #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } #endif histCntr = 0; CogGraphicLabel myBaslerLabel = new CogGraphicLabel(); CogGraphicLabel myFlirLabel = new CogGraphicLabel(); CogPointMarker baslerMarker; //= new CogPointMarker(); double blobAngle = 0; double blobAngleRadians = 0; //Get references to the tools CogBlobTool blobBaslerTool = (CogBlobTool)toolGroup.Tools["FindWrappersInBasler"]; CogBlobTool blobFlirTool = (CogBlobTool)toolGroup.Tools["PopsicleBlobFinder"]; CogHistogramTool popsicleHistTool = (CogHistogramTool)toolGroup.Tools["PopsicleHistogramTool"]; //Define the regions CogRectangleAffine popsicleRegion = blobFlirTool.Region as CogRectangleAffine; CogRectangleAffine histogramRegion = blobFlirTool.Region as CogRectangleAffine; //Define the fonts System.Drawing.Font myBaslerFont = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); System.Drawing.Font myFlirFont = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); //Reset stats angleFailures = 0; thermalFailures = 0; //Reset any labels and rectangles from previous runs BaslerLabels.Clear(); FlirLabels.Clear(); FlirRectangles.Clear(); //***** Run the tools to perform the search in the basler image ***** //Update status strings for Visual Studio. Do not popup a message box for errors, this causes confusion with the operators. toolGroup.SetScriptTerminalData("BaslerStatus", "OK"); toolGroup.SetScriptTerminalData("FlirStatus", "OK"); bool acquireException = false; try { //Aquire an image from the Basler, send Exception to Visual Studio toolGroup.RunTool(toolGroup.Tools["BaslerAcqFifo"], ref message, ref result); } catch (Exception ex) { toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Check power connections and communication cables."); acquireException = true; } try { //Aquire an image from the Flir, send Exception to Visual Studio toolGroup.RunTool(toolGroup.Tools["FlirAcqFifo"], ref message, ref result); } catch (Exception ex) { toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Check power connections and communication cables."); acquireException = true; } if (acquireException) { return(false); } try { // Scale the Flir image to zoom in to smaller temperature range toolGroup.RunTool(toolGroup.Tools["ScaleFlirImagePmap"], ref message, ref result); } catch (Exception ex) { toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: ScaleFlirImagePmap"); return(false); } try { // Transform the images to calibrated space toolGroup.RunTool(toolGroup.Tools["CalBasler"], ref message, ref result); toolGroup.RunTool(toolGroup.Tools["CalFlir"], ref message, ref result); } catch (Exception ex) { //MessageBox.Show("Calibration tool error: " + ex.Message, "Script Exception"); toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CalBasler"); toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: CalFlir"); return(false); } try { toolGroup.RunTool(toolGroup.Tools["CogPixelMapBasler"], ref message, ref result); } catch (Exception ex) { toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CogPixelMapBasler"); return(false); } try { toolGroup.RunTool(toolGroup.Tools["CogIPOneImageTool1"], ref message, ref result); } catch (Exception ex) { toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CogIPOneImageTool1"); return(false); } try { // Run the Flir hist tool toolGroup.RunTool(toolGroup.Tools["PopsicleHistogramTool"], ref message, ref result); } catch (Exception ex) { toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: PopsicleHistogramTool"); return(false); } try { // Run the blob tool and get a reference to the results. toolGroup.RunTool(blobBaslerTool, ref message, ref result); } catch (Exception ex) { toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: Basler blobBaslerTool"); return(false); } CogBlobResultCollection blobResults = blobBaslerTool.Results.GetBlobs(); // Clear list before starting loop malBlobPoses.Clear(); Crosshairs.Clear(); // Get group input terminal data try { disableHist = (bool)toolGroup.GetScriptTerminalData("DisableHistogramInspection"); minPickAngle = (double)toolGroup.GetScriptTerminalData("MinPickAngle"); maxPickAngle = (double)toolGroup.GetScriptTerminalData("MaxPickAngle"); minPopsicleHistCount = (double)toolGroup.GetScriptTerminalData("MinPopsicleHistCount"); VisStudio_Running = (bool)toolGroup.GetScriptTerminalData("VS_Running"); showArea = (bool)toolGroup.GetScriptTerminalData("ShowArea"); showHist = (bool)toolGroup.GetScriptTerminalData("ShowHistCount"); visSideXLength = (double)toolGroup.GetScriptTerminalData("VisSideXLength"); visSideYLength = (double)toolGroup.GetScriptTerminalData("VisSideYLength"); visFlirRegionXadj = (double)toolGroup.GetScriptTerminalData("VisFlirRegionXadj"); visFlirRegionYadj = (double)toolGroup.GetScriptTerminalData("VisFlirRegionYadj"); } catch (Exception ex) { //MessageBox.Show("Getting terminal data exception: ", ex.Message); toolGroup.SetScriptTerminalData("BaslerStatus", "Getting script data: " + ex.Message); } // Set run variables for manual triggering if (!VisStudio_Running) { minPopsicleHistCount = 0; minPickAngle = -20; maxPickAngle = 20; showArea = true; showHist = true; visSideXLength = 200; visSideYLength = 70; visFlirRegionXadj = 0; visFlirRegionYadj = 0; } // *************************************** // ******** Process the blobs ********* // *************************************** try { foreach (CogBlobResult blob in blobResults) { // Set the transform for collections CogTransform2DLinear l2d = new CogTransform2DLinear(); l2d.TranslationX = blob.GetBoundingBoxAtAngle(blob.Angle).CenterX; l2d.TranslationY = blob.GetBoundingBoxAtAngle(blob.Angle).CenterY; l2d.Rotation = blob.Angle; blobAngleRadians = blob.Angle; // Crosshair setup for the Basler baslerMarker = new CogPointMarker(); baslerMarker.X = l2d.TranslationX; baslerMarker.Y = l2d.TranslationY; baslerMarker.Color = CogColorConstants.Green; baslerMarker.GraphicType = CogPointMarkerGraphicTypeConstants.Crosshair; // Flir region CogRectangleAffine myFlirRegion = new CogRectangleAffine(); myFlirRegion.CenterX = l2d.TranslationX + visFlirRegionXadj; myFlirRegion.CenterY = l2d.TranslationY + visFlirRegionYadj; myFlirRegion.Rotation = l2d.Rotation; myFlirRegion.SideXLength = visSideXLength; myFlirRegion.SideYLength = visSideYLength; blobFlirTool.Region = myFlirRegion; toolGroup.RunTool(blobFlirTool, ref message, ref result); popsicleHistTool.Region = myFlirRegion; toolGroup.RunTool(popsicleHistTool, ref message, ref result); // Get the histogram results from the bin binHist = popsicleHistTool.Result.GetHistogram(); // Count total pixels histCntr = 1; for (int i = 0; i < blobFlirTool.RunParams.SegmentationParams.HardFixedThreshold; i++) { histCntr = histCntr + binHist[i]; } myBaslerLabel = new CogGraphicLabel(); myBaslerLabel.SetXYText(0, 0, ""); myFlirLabel = new CogGraphicLabel(); myBaslerLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); myFlirLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); myFlirRegion.Visible = true; myBaslerLabel.Alignment = CogGraphicLabelAlignmentConstants.BaselineCenter; myFlirLabel.Alignment = CogGraphicLabelAlignmentConstants.BaselineCenter; // Decide to add the popsicle blob to the collection list if ((histCntr < minPopsicleHistCount) && (!disableHist)) { myBaslerLabel.Color = CogColorConstants.Red; myFlirRegion.Color = CogColorConstants.Red; // Show the hist count in the Flir image myFlirLabel.Color = CogColorConstants.Red; if (showHist) { myFlirLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Size: " + histCntr.ToString()); } thermalFailures++; } else { myBaslerLabel.Color = CogColorConstants.Green; // If histogram check is disabled, draw rectangle in yellow, else green if (disableHist) { myFlirLabel.Color = CogColorConstants.Red; myFlirRegion.Color = CogColorConstants.Yellow; } else { myFlirLabel.Color = CogColorConstants.Green; myFlirRegion.Color = CogColorConstants.Green; } if (showHist) { myFlirLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Size: " + histCntr.ToString()); } // Convert blob angle to degrees blobAngle = blob.Angle * 180 / Math.PI; if ((blobAngle > (double)minPickAngle) && (blobAngle < (double)maxPickAngle)) { malBlobPoses.Add(l2d); if (showArea) { myBaslerLabel.Color = CogColorConstants.Green; myBaslerLabel.SetXYText(l2d.TranslationX, l2d.TranslationY - 15, "Size: " + blob.Area.ToString("0")); } } else { myBaslerLabel.Color = CogColorConstants.Red; myBaslerLabel.SetXYText(l2d.TranslationX, l2d.TranslationY, "Angle: " + blobAngle.ToString("0")); myFlirLabel.Color = CogColorConstants.Red; myFlirRegion.Color = CogColorConstants.Red; angleFailures++; } } myBaslerLabel.Rotation = blobAngleRadians; BaslerLabels.Add(myBaslerLabel); FlirLabels.Add(myFlirLabel); FlirRectangles.Add(myFlirRegion); Crosshairs.Add(baslerMarker); // Update group output terminals toolGroup.SetScriptTerminalData("AngleFailures", angleFailures); toolGroup.SetScriptTerminalData("ThermalFailures", thermalFailures); toolGroup.SetScriptTerminalData("BlobCollection", malBlobPoses); } } catch (Exception ex) { toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error during blob processing: " + ex.Message); malBlobPoses.Clear(); // Clear positional data for this frame } // Returning False indicates we ran the tools in script, and they should not be // run by VisionPro return(false); }
private void ApplyLeadInspValueFunction(CogLeadAlgo _CogLeadAlgo, ref CogLeadResult _CogLeadResult, bool _IsDisplay = true) { if (eTeachStep.ALGO_SET != CurrentTeachStep) { MessageBox.Show("Not select \"Algorithm Set\" button"); return; } if (_IsDisplay) { AlgorithmAreaDisplayRefresh(); } bool _Result = InspLeadProcess.Run(InspectionImage, AlgoRegionRectangle, _CogLeadAlgo, ref _CogLeadResult); #region Result Display if (_IsDisplay) { for (int iLoopCount = 0; iLoopCount < _CogLeadResult.BlobCount; ++iLoopCount) { //Blob Boundary CogRectangleAffine _BlobRectAffine = new CogRectangleAffine(); _BlobRectAffine.SetCenterLengthsRotationSkew(_CogLeadResult.BlobCenterX[iLoopCount], _CogLeadResult.BlobCenterY[iLoopCount], _CogLeadResult.PrincipalWidth[iLoopCount], _CogLeadResult.PrincipalHeight[iLoopCount], _CogLeadResult.Angle[iLoopCount], 0); kpTeachDisplay.DrawStaticShape(_BlobRectAffine, "BlobRectAffine" + (iLoopCount + 1), CogColorConstants.Green); kpTeachDisplay.DrawBlobResult(_CogLeadResult.ResultGraphic[iLoopCount], "BlobRectGra" + (iLoopCount + 1)); CogLineSegment _CenterLine = new CogLineSegment(); kpTeachDisplay.DrawStaticLine(_CogLeadResult.BlobCenterX[iLoopCount], _CogLeadResult.BlobCenterY[iLoopCount], _CogLeadResult.PrincipalWidth[iLoopCount] / 2 + 20, _CogLeadResult.Angle[iLoopCount], 2, "CenterLine+_" + (iLoopCount + 1), CogColorConstants.Cyan); kpTeachDisplay.DrawStaticLine(_CogLeadResult.BlobCenterX[iLoopCount], _CogLeadResult.BlobCenterY[iLoopCount], _CogLeadResult.PrincipalWidth[iLoopCount] / 2 + 20, (Math.PI) + _CogLeadResult.Angle[iLoopCount], 2, "CenterLine-_" + (iLoopCount + 1), CogColorConstants.Cyan); CogPointMarker _PitchPoint = new CogPointMarker(); _PitchPoint.SetCenterRotationSize(_CogLeadResult.LeadPitchTopX[iLoopCount], _CogLeadResult.LeadPitchTopY[iLoopCount], 0, 1); kpTeachDisplay.DrawStaticShape(_PitchPoint, "PointStart" + (iLoopCount + 1), CogColorConstants.Yellow, 2); _PitchPoint.SetCenterRotationSize(_CogLeadResult.LeadPitchBottomX[iLoopCount], _CogLeadResult.LeadPitchBottomY[iLoopCount], 0, 1); kpTeachDisplay.DrawStaticShape(_PitchPoint, "PointEnd" + (iLoopCount + 1), CogColorConstants.Orange, 2); } } #endregion Result Display #region Pitch Average 측정 try { double[] _LeadPitchX = new double[_CogLeadResult.BlobCount]; Array.Copy(_CogLeadResult.LeadPitchTopX, _LeadPitchX, _CogLeadResult.BlobCount); Array.Sort(_LeadPitchX); double[] _LeadPitches = new double[_CogLeadResult.BlobCount - 1]; for (int iLoopCount = 0; iLoopCount < _CogLeadResult.BlobCount - 1; ++iLoopCount) { _LeadPitches[iLoopCount] = _LeadPitchX[iLoopCount + 1] - _LeadPitchX[iLoopCount]; } Array.Sort(_LeadPitches); double _Gab = _LeadPitches[4]; int _Index = 1; double _PitchSum = _LeadPitches[4], _PitchArray = 0; for (int iLoopCount = 5; iLoopCount < _CogLeadResult.BlobCount - 1; ++iLoopCount) { if (_Gab + 20 < _LeadPitches[iLoopCount]) { break; } _PitchSum += _LeadPitches[iLoopCount]; _Index++; } _PitchArray = _PitchSum / _Index; _CogLeadResult.LeadPitchAvg = _PitchArray; } catch { _CogLeadResult.LeadPitchAvg = 0; CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.ERR, "ApplyLeadInspValueFunction Exception", CLogManager.LOG_LEVEL.LOW); } #endregion Pitch Average 측정 #region Lead Angle Average 측정 try { double[] _LeadAngles = new double[_CogLeadResult.BlobCount]; Array.Copy(_CogLeadResult.Angle, _LeadAngles, _CogLeadResult.BlobCount); Array.Sort(_LeadAngles); int _Index = 0; double _AngleSum = 0, _AngleAvg = 0; for (int iLoopCount = 5; iLoopCount < _CogLeadResult.BlobCount - 5; ++iLoopCount) { _AngleSum += _CogLeadResult.Angle[iLoopCount]; _Index++; } _AngleAvg = _AngleSum / _Index; _CogLeadResult.LeadAngleAvg = _AngleAvg; } catch { _CogLeadResult.LeadAngleAvg = 0; CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.ERR, "ApplyLeadInspValueFunction Exception", CLogManager.LOG_LEVEL.LOW); } #endregion Lead Angle Average 측정 }
public void ShowCalibratedPoints(ADisplay aDisplay, bool isShowDistorted, bool isSwapHandedness) { try { int pointCount = m_cogCalibCheckerboardTool.Calibration.NumPoints; if (isShowDistorted == true) { double x, y, mappedX, mappedY; aDisplay.ClearAll(); aDisplay.Display.Image = m_cogCalibCheckerboardTool.Calibration.OwnedWarpParams.UndistortedCalibrationImage; aDisplay.Display.Fit(true); ICogGraphic mask = m_cogCalibCheckerboardTool.Calibration.OwnedWarpParams.OutputImageMask as ICogGraphic; if (mask != null) { aDisplay.AddStaticGraphic(mask, ""); } for (int i = 0; i < pointCount; i++) { CogPointMarker cogPointMaker = new CogPointMarker(); x = m_cogCalibCheckerboardTool.Calibration.GetUncalibratedPointX(i); y = m_cogCalibCheckerboardTool.Calibration.GetUncalibratedPointY(i); ICogTransform2D transform2D = m_cogCalibCheckerboardTool.Calibration.OwnedWarpParams.GetInputPixelFromOutputPixelTransform(aDisplay.Image); transform2D.InvertBase().MapPoint(x, y, out mappedX, out mappedY); cogPointMaker.GraphicType = CogPointMarkerGraphicTypeConstants.Crosshair; cogPointMaker.Color = CogColorConstants.Magenta; cogPointMaker.X = mappedX; cogPointMaker.Y = mappedY; cogPointMaker.GraphicDOFEnable = CogPointMarkerDOFConstants.None; cogPointMaker.Interactive = true; cogPointMaker.TipText = "Uncalibrated Point " + i.ToString(); aDisplay.AddOverlay(cogPointMaker as ICogGraphicInteractive, ""); } } else { aDisplay.ClearAll(); aDisplay.Display.Image = m_cogCalibCheckerboardTool.Calibration.CalibrationImage; aDisplay.Display.Fit(true); for (int i = 0; i < pointCount; i++) { CogPointMarker cogPointMaker = new CogPointMarker(); cogPointMaker.GraphicType = CogPointMarkerGraphicTypeConstants.Crosshair; cogPointMaker.Color = CogColorConstants.Magenta; cogPointMaker.X = m_cogCalibCheckerboardTool.Calibration.GetUncalibratedPointX(i); cogPointMaker.Y = m_cogCalibCheckerboardTool.Calibration.GetUncalibratedPointY(i); cogPointMaker.GraphicDOFEnable = CogPointMarkerDOFConstants.None; cogPointMaker.Interactive = true; cogPointMaker.TipText = "Uncalibrated Point " + i.ToString(); aDisplay.AddOverlay(cogPointMaker as ICogGraphicInteractive, ""); } } ShowCalibratedOrigin(aDisplay, isShowDistorted, isSwapHandedness); } catch { } }
private void btnFindSearchArea_Click(object sender, EventArgs e) { double _OffsetX = MapDataParam.Unit.PatternAreaOriginX - MapDataParam.Unit.PatternAreaCenterX; double _OffsetY = MapDataParam.Unit.PatternAreaOriginY - MapDataParam.Unit.PatternAreaCenterY; InspPattern.SetPatternReference(MapDataParam.Info.UnitPattern); InspPattern.SetMatchingParameter(MapDataParam.Info.FindCount, MapDataParam.Info.FindScore); if (false == InspPattern.Run(OriginImage)) { MessageBox.Show("Pattern Not Found"); return; } CogPMAlignResults _PatternResult = InspPattern.GetResults(); if (null == _PatternResult) { return; } MapDataParam.Info.UnitListCenterX.Clear(); MapDataParam.Info.UnitListCenterY.Clear(); MapDataParam.Info.UnitListWidth.Clear(); MapDataParam.Info.UnitListHeight.Clear(); if (_PatternResult.Count > 0) { double[] _OriginX, _OriginY, _CenterX, _CenterY, _Width, _Height; _OriginX = new double[_PatternResult.Count]; _OriginY = new double[_PatternResult.Count]; _CenterX = new double[_PatternResult.Count]; _CenterY = new double[_PatternResult.Count]; _Width = new double[_PatternResult.Count]; _Height = new double[_PatternResult.Count]; uint _RowCount = Convert.ToUInt32(numUpDownUnitRowCount.Value); uint _ColCount = Convert.ToUInt32(numUpDownUnitColumnCount.Value); CenterPoint[] _CenterPointArray = new CenterPoint[_RowCount * _ColCount]; for (int iLoopCount = 0; iLoopCount < _PatternResult.Count; ++iLoopCount) { _OriginX[iLoopCount] = _PatternResult[iLoopCount].GetPose().TranslationX; _OriginY[iLoopCount] = _PatternResult[iLoopCount].GetPose().TranslationY; _CenterX[iLoopCount] = _PatternResult[iLoopCount].GetPose().TranslationX - _OffsetX; _CenterY[iLoopCount] = _PatternResult[iLoopCount].GetPose().TranslationY - _OffsetY; _Width[iLoopCount] = _PatternResult.GetTrainArea().Width; _Height[iLoopCount] = _PatternResult.GetTrainArea().Height; CogRectangle _FindPattern = new CogRectangle(); _FindPattern.SetCenterWidthHeight(_CenterX[iLoopCount], _CenterY[iLoopCount], MapDataParam.Unit.SearchAreaWidth, MapDataParam.Unit.SearchAreaHeight); kpTeachDisplay.DrawStaticShape(_FindPattern, "SearchArea" + (iLoopCount + 1)); CogPointMarker _OriginPoint = new CogPointMarker(); _OriginPoint.SetCenterRotationSize(_OriginX[iLoopCount], _OriginY[iLoopCount], 0, 2); kpTeachDisplay.DrawStaticShape(_OriginPoint, "PatternOrigin" + (iLoopCount + 1), CogColorConstants.Green, 12); MapDataParam.Info.UnitListCenterX.Add(_CenterX[iLoopCount]); MapDataParam.Info.UnitListCenterY.Add(_CenterY[iLoopCount]); MapDataParam.Info.UnitListWidth.Add(_Width[iLoopCount]); MapDataParam.Info.UnitListHeight.Add(_Height[iLoopCount]); if (_CenterPointArray.Length > iLoopCount) { _CenterPointArray[iLoopCount] = new CenterPoint(); _CenterPointArray[iLoopCount].X = _CenterX[iLoopCount]; _CenterPointArray[iLoopCount].Y = _CenterY[iLoopCount]; } } if ((_RowCount * _ColCount) != _PatternResult.Count) { MessageBox.Show("Unit 개수와 Find Result 개수가 맞지 않습니다."); return; } else { CenterPoint[,] _SortedCenterPoint = CenterPointSort(_RowCount, _ColCount, _CenterPointArray); MapDataParam.Info.UnitListCenterX.Clear(); MapDataParam.Info.UnitListCenterY.Clear(); for (int iLoopCount = 0; iLoopCount < _RowCount; ++iLoopCount) { for (int jLoopCount = 0; jLoopCount < _ColCount; ++jLoopCount) { MapDataParam.Info.UnitListCenterX.Add(_SortedCenterPoint[iLoopCount, jLoopCount].X); MapDataParam.Info.UnitListCenterY.Add(_SortedCenterPoint[iLoopCount, jLoopCount].Y); } } SelectingRectName = SelectedRectName = ""; IsDrawPatterns = true; MessageBox.Show("Pattern Find Complete"); } } }