天天看點

VisionPro通過代碼設定模闆訓練的中心坐标

QQ群日志記錄

使用代碼設定所選模闆區域的中心原點,圖形界面中可以使用如下圖的按鈕來操作

VisionPro通過代碼設定模闆訓練的中心坐标

C#代碼中可以使用如下的代碼來完成中心原點的設定:

private void PatternCenterPoint()
        {
            try
            {
                if (this.pmalign_.Pattern != null && this.pmalign_.Pattern.TrainImage != null && this.pmalign_.Pattern.TrainRegion != null)
                {
                    ICogTransform2D transform = this.pmalign_.Pattern.TrainImage.GetTransform(".", this.pmalign_.Pattern.TrainRegion.SelectedSpaceName);
                    CogRectangle rectangle = this.pmalign_.Pattern.TrainRegion.Map(transform, CogCopyShapeConstants.GeometryOnly).EnclosingRectangle(CogCopyShapeConstants.GeometryOnly);
                    this.pmalign_.Pattern.Origin.TranslationX = rectangle.CenterX;
                    this.pmalign_.Pattern.Origin.TranslationY = rectangle.CenterY;
                    this.Display_.AutoFit = true;
                }
            }
            catch (Exception e)
            {
                Common.MsgBox.show(e.Message);
            }
        }

           

繼續閱讀