GetSelectedRectangleFromViewer Method
Syntax
CWMachineVision.GetSelectedRectangleFromViewer Viewer, Rectangle [, RaiseErrorOnBadIndex = True] [, Index]
Return Type
On success, this method returns 0. On failure, this function returns a negative number.
Purpose
Returns a copy of the rectangle at the specified index from the region of interest on the viewer.
Remarks
If a different shape is at the specified index, this method raises an error. If the index is invalid, this method raises an error only if RaiseErrorOnBadIndex is true. Otherwise, it returns a rectangle the size of the image. This behavior is useful for routines that take optional search rectangles.
Parameters
Viewer As CWIMAQViewer
The viewer that contains the region of interest from which you want to get the rectangle.
Rectangle As CWIMAQRectangle
On return, this parameter contains a copy of the rectangle that is selected on the viewer.
RaiseErrorOnBadIndex As Variant
[Optional] Indicates whether an error should be raised if index is invalid. If this is set to False, the rectangle returned is the size of the viewer image.
This parameter has a default value of True.
Index As Variant
[Optional] The index of the Region in the CWIMAQViewer.Regions collection. Set this parameter to the appropriate index when the viewer contains multiple regions of interest.
Example
Private Sub Learn_Click() 'Declarations Dim TemplateRectangle As New CWIMAQRectangle 'Get the currently selected rectangle from the viewer CWMachineVision1.GetSelectedRectangleFromViewer CWIMAQViewer1, TemplateRectangle 'Extract the template image CWIMAQVision1.Extract2 CWIMAQViewer1.Image, CWIMAQViewer2.Image, TemplateRectangle End Sub Private Sub Match_Click() 'Declarations Dim SearchArea As New CWIMAQRotatedRectangle Dim Options As New CWMVFindPatternOptions Dim Transformation As New CWMVCoordinateTransformation Dim Report As New CWIMAQPatternMatchReport 'Get the currently selected rotated rectangle from the viewer. If none is selected, 'search the entire image. CWMachineVision1.GetSelectedRotatedRectFromViewer CWIMAQViewer1, SearchArea, False 'Use rotation invariant pattern matching Options.MatchMode = cwimaqMatchRotationInvariant Options.NumMatchesRequested = 10 'Find the pattern on the Viewer image in the selected rectangle. If this is the first 'first time matching after a learn, this process will take longer than normal because 'it will first learn the template image. CWMachineVision1.FindPattern CWIMAQViewer1.Image, CWIMAQViewer2.Image, Report, SearchArea, _ Options, Transformation End Sub