Option ExplicitDim ImageNumber As Integer
Dim ImagePath As String
Dim Images As New Collection
Dim TemplateImage As New CWIMAQImage
Dim LookUpTable(0 To 255) As Long
Dim CurImage As New CWIMAQImage
Dim DisplayImage As New CWIMAQImagePrivate Sub CWSlide1_PointerValueChanged(ByVal Pointer As Long, Value As Variant)
Timer1.Interval = IIf(Value <> 0, Value, 1)
End SubPrivate Sub Exit_Click()
End
End SubPrivate Sub Form_Load()
ImagePath = App.Path + "\..\..\..\Images\Inspection"
ImageNumber = 0
LookUpTable(0) = 255
Dim i1
For i1 = 1 To 255
LookUpTable(i1) = i1
Next
CWIMAQVision1.ReadImageAndVisionInfo TemplateImage, ImagePath & "\template.png"
CWIMAQViewer1.Attach TemplateImage
CWIMAQViewer2.Attach DisplayImage
Timer1.Enabled = True
Timer1_Timer
End SubPrivate Sub Timer1_Timer()
Dim MatchPatternOptions As New CWIMAQMatchPatternOptions
Dim PatternMatchReport As New CWIMAQPatternMatchReport
Dim Alignment As New CWIMAQInspectionAlignment
Dim GoldenTemplateOptions As New CWIMAQInspectionOptions
Dim DefectImage As New CWIMAQImage
Dim ParticleReport As New CWIMAQParticleReport
Dim Red, Green, Blue
GetNextImage CurImage
MatchPatternOptions.MatchMode = cwimaqMatchRotationInvariant
MatchPatternOptions.MinimumMatchScore = 500
MatchPatternOptions.RotationAngleRanges.Add 1
MatchPatternOptions.RotationAngleRanges(1).Min = -5
MatchPatternOptions.RotationAngleRanges(1).Max = 5
CWIMAQVision1.MatchPattern2 CurImage, TemplateImage, MatchPatternOptions, PatternMatchReport
If (PatternMatchReport.Count <> 1) Then
PassFailButton.Value = False
Else
PatternMatchReport(1).Position.CopyTo Alignment.Position
Alignment.Angle = PatternMatchReport(1).Angle
GoldenTemplateOptions.EdgeThicknessToIgnore = 1
CWIMAQVision1.CompareGoldenTemplate CurImage, TemplateImage, Alignment, GoldenTemplateOptions, DefectImage, DefectImage
CWIMAQVision1.RemoveParticle DefectImage, DefectImage
CWIMAQVision1.ParticleReport DefectImage, ParticleReport
If (ParticleReport.Count > 0) Then
PassFailButton.Value = False
Else
PassFailButton.Value = True
End If
CWIMAQVision1.UserLookup DefectImage, DefectImage, LookUpTable
CWIMAQVision1.Max CurImage, 3, CurImage
CWIMAQViewer1.Palette.GetPalette Red, Green, Blue
If (DarkDefectButton) Then
Red(1) = 255
End If
If (BrightDefectButton) Then
Green(2) = 255
End If
CWIMAQViewer2.Palette.SetPalette Red, Green, Blue
CWIMAQVision1.Min CurImage, DefectImage, DisplayImage
End If
End SubPrivate Sub GetNextImage(ByRef Image As CWIMAQImage)
Dim NextImage As CWIMAQImage
If ImageNumber >= Images.Count Then
Set NextImage = New CWIMAQImage
CWIMAQVision1.ReadImage NextImage, ImagePath + "\NI_Label_" + Format(ImageNumber, "0000") + ".jp2"
Images.Add NextImage
Else
Set NextImage = Images(ImageNumber + 1)
End If CWIMAQVision1.Copy NextImage, CurImage
ImageNumber = ImageNumber + 1
If ImageNumber > 11 Then ImageNumber = 0
End Sub
Dim ImagePath As String
Dim Images As New Collection
Dim TemplateImage As New CWIMAQImage
Dim LookUpTable(0 To 255) As Long
Dim CurImage As New CWIMAQImage
Dim DisplayImage As New CWIMAQImagePrivate Sub CWSlide1_PointerValueChanged(ByVal Pointer As Long, Value As Variant)
Timer1.Interval = IIf(Value <> 0, Value, 1)
End SubPrivate Sub Exit_Click()
End
End SubPrivate Sub Form_Load()
ImagePath = App.Path + "\..\..\..\Images\Inspection"
ImageNumber = 0
LookUpTable(0) = 255
Dim i1
For i1 = 1 To 255
LookUpTable(i1) = i1
Next
CWIMAQVision1.ReadImageAndVisionInfo TemplateImage, ImagePath & "\template.png"
CWIMAQViewer1.Attach TemplateImage
CWIMAQViewer2.Attach DisplayImage
Timer1.Enabled = True
Timer1_Timer
End SubPrivate Sub Timer1_Timer()
Dim MatchPatternOptions As New CWIMAQMatchPatternOptions
Dim PatternMatchReport As New CWIMAQPatternMatchReport
Dim Alignment As New CWIMAQInspectionAlignment
Dim GoldenTemplateOptions As New CWIMAQInspectionOptions
Dim DefectImage As New CWIMAQImage
Dim ParticleReport As New CWIMAQParticleReport
Dim Red, Green, Blue
GetNextImage CurImage
MatchPatternOptions.MatchMode = cwimaqMatchRotationInvariant
MatchPatternOptions.MinimumMatchScore = 500
MatchPatternOptions.RotationAngleRanges.Add 1
MatchPatternOptions.RotationAngleRanges(1).Min = -5
MatchPatternOptions.RotationAngleRanges(1).Max = 5
CWIMAQVision1.MatchPattern2 CurImage, TemplateImage, MatchPatternOptions, PatternMatchReport
If (PatternMatchReport.Count <> 1) Then
PassFailButton.Value = False
Else
PatternMatchReport(1).Position.CopyTo Alignment.Position
Alignment.Angle = PatternMatchReport(1).Angle
GoldenTemplateOptions.EdgeThicknessToIgnore = 1
CWIMAQVision1.CompareGoldenTemplate CurImage, TemplateImage, Alignment, GoldenTemplateOptions, DefectImage, DefectImage
CWIMAQVision1.RemoveParticle DefectImage, DefectImage
CWIMAQVision1.ParticleReport DefectImage, ParticleReport
If (ParticleReport.Count > 0) Then
PassFailButton.Value = False
Else
PassFailButton.Value = True
End If
CWIMAQVision1.UserLookup DefectImage, DefectImage, LookUpTable
CWIMAQVision1.Max CurImage, 3, CurImage
CWIMAQViewer1.Palette.GetPalette Red, Green, Blue
If (DarkDefectButton) Then
Red(1) = 255
End If
If (BrightDefectButton) Then
Green(2) = 255
End If
CWIMAQViewer2.Palette.SetPalette Red, Green, Blue
CWIMAQVision1.Min CurImage, DefectImage, DisplayImage
End If
End SubPrivate Sub GetNextImage(ByRef Image As CWIMAQImage)
Dim NextImage As CWIMAQImage
If ImageNumber >= Images.Count Then
Set NextImage = New CWIMAQImage
CWIMAQVision1.ReadImage NextImage, ImagePath + "\NI_Label_" + Format(ImageNumber, "0000") + ".jp2"
Images.Add NextImage
Else
Set NextImage = Images(ImageNumber + 1)
End If CWIMAQVision1.Copy NextImage, CurImage
ImageNumber = ImageNumber + 1
If ImageNumber > 11 Then ImageNumber = 0
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货