CogPMAlignPattern TrainShapeModels Property Cognex VisionPro 9.24
A collection of shape models used to train a PMAlign pattern when the TrainMode property is either cogPMAlignTrainModeShapeModelsWithImage or cogPMAlignTrainModeShapeModelsWithTransform.

Namespace: Cognex.VisionPro.PMAlign
Assembly: Cognex.VisionPro.PMAlign (in Cognex.VisionPro.PMAlign.dll) Version: 91.0.0.0
Syntax

public ICogShapeModelCollection TrainShapeModels { get; set; }

Property Value

Type: ICogShapeModelCollection
Events

Remarks

A collection of shape models used to train this pattern when the TrainMode property is either ShapeModelsWithImage or ShapeModelsWithTransform.

The CogPMAlignPattern object will sink collection events for the this property, and it will be untrained if an ItemAdded, Cleared, ItemRemoved, or ItemReplaced event occurs. The pattern also will untrain if a geometry, selected space, weight, or polarity change is detected for any sub-objects (shape models) of the collection. The CogPMAlignPattern object will also become untrained if this property reference is changed.

Default Value: An empty collection.

Examples

Imports Cognex.VisionPro
Imports Cognex.VisionPro.PMAlign

Private myPattern As New CogPMAlignPattern
Private myParams As New CogPMAlignRunParams
Private myResults As CogPMAlignResults

Private Sub doTrain()
  Dim affRect As New CogRectangleAffine
  Dim newTransform As New CogTransform2DLinear
  Dim shapeModel As ICogShapeModel
  Dim i As Integer

  myPattern.TrainAlgorithm = CogPMAlignTrainAlgorithmConstants.PatMaxAndPatQuick
  myPattern.TrainMode = CogPMAlignTrainModeConstants.ShapeModelsWithImage

  affRect.SetFromRectangle(trainRect, newTransform)
  shapeModel = affRect.MakeShapeModel(1, CogShapeModelPolarityConstants.NegativeOne, True)

  myPattern.TrainShapeModels.Add(shapeModel)

  myPattern.TrainImage = anImage
  myPattern.TrainRegion = Nothing
  myPattern.TrainRegionMode = CogRegionModeConstants.PixelAlignedBoundingBox
  myPattern.Origin.TranslationX = trainRect.CenterX
  myPattern.Origin.TranslationY = trainRect.CenterY

  myPattern.Train()
  CogDisplay1.Image = myPattern.GetTrainedPatternImage
  For i = 0 To myPattern.GetTrainedPatternShapeModels.Count - 1
      CogDisplay1.StaticGraphics.Add(CType(myPattern.GetTrainedPatternShapeModels.Item(i).Shape, ICogGraphic), "")
  Next
end sub
using Cognex.VisionPro;
using Cognex.VisionPro.PMAlign;

private CogPMAlignPattern myPattern = new CogPMAlignPattern();
private CogPMAlignRunParams myParams =new CogPMAlignRunParams();
private CogPMAlignResults myResults;

private void doTrain()
{
  CogRectangleAffine affRect = new CogRectangleAffine();
  CogTransform2DLinear newTransform = new CogTransform2DLinear();
  ICogShapeModel shapeModel; 
  int i;

  myPattern.TrainAlgorithm = CogPMAlignTrainAlgorithmConstants.PatMaxAndPatQuick;
  myPattern.TrainMode = CogPMAlignTrainModeConstants.ShapeModelsWithImage;

  affRect.SetFromRectangle(trainRect, newTransform);
  shapeModel = affRect.MakeShapeModel(1, CogShapeModelPolarityConstants.NegativeOne, true);

  myPattern.TrainShapeModels.Add(shapeModel);

  myPattern.TrainImage = anImage;
  myPattern.TrainRegion = null;
  myPattern.TrainRegionMode = CogRegionModeConstants.PixelAlignedBoundingBox;
  myPattern.Origin.TranslationX = trainRect.CenterX;
  myPattern.Origin.TranslationY = trainRect.CenterY;
  myPattern.Train();
  CogDisplay1.Image = myPattern.GetTrainedPatternImage();
  for( i=0; i < myPattern.GetTrainedPatternShapeModels().Count; i++)
    {
      CogDisplay1.StaticGraphics.Add((ICogGraphic) myPattern.GetTrainedPatternShapeModels().get_Item(i).Shape, "");
    }
}
See Also