Assembly: Cognex.VisionPro.PMAlign (in Cognex.VisionPro.PMAlign.dll) Version: 91.0.0.0
Property Value
Type: ICogShapeModelCollection| Event Type | Reason |
|---|---|
| CogPMAlignPattern Changed | Fires when this property changes. The following state flag may be affected: |
| CogPMAlignPattern Changed | Fires when this property changes and the pattern becomes untrained. The following state flags may be affected: |
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.
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 subusing 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, ""); } }