11-21-2008 09:57 AM
ADL -
I think I understand your point. Like Ben said above, Vision Development Module 8.6 does support learning a template with a mask image. In your example, you could create a mask image and remove the logo area and any area outside of the ball, and Match Pattern will ignore those areas when doing the search.
Greg Stoll
Vision R&D
National Instruments
11-21-2008 10:01 AM
Greg, Is there an example of this anywhere, or would I find this anywhere in the documentation?
11-21-2008 10:27 AM
ADL -
Our Pattern Matching examples weren't updated to use this new parameter, and I just noticed that our LabVIEW documentation missed it as well. The NI Vision Template Editor was updated, so you can draw regions to ignore on a new template. This would probably be the easiest way to test it out.
If you want to do it programmatically, it should be fairly straightforward to use -just create a U8 mask image of the same size as the template image, fill it with 255, and then set the pixels to 0 at the parts you want to ignore.
Greg Stoll
Vision R&D
National Instruments
12-31-2008 01:37 PM
Greg,
Thanks for the info, you said that it was in Vision Development Module 8.6, does that mean it is not in VBAI or Vision Assistant?
12-31-2008 03:34 PM
ADL -
I just checked, and it is also present in Vision Assistant 8.6 and VBAI 3.6.
Greg Stoll
Vision R&D
National Instruments
08-13-2009 04:22 AM
Hi all,
I can not get a correct template file according your method. please check below vb code..
1. get the template from viewer1 to viewer2.
2. user set the ROI as mask.
3. learn and save viewer2.image to 0.png
when i open the 0.png by template editor. the mask area is a black not red, it means NI program does not think that is a correct template. am I right?
Private Sub Get_temp_Click()
Dim LearnOptions As New CWIMAQLearnPatternOptions
Dim Rectangle As New CWIMAQRectangle
Dim ImageMask As New CWIMAQImage
Learn.Caption = "Learning..."
'Extract region correspoding to the region of interest in the image window
CWMachineVision1.GetSelectedRectangleFromViewer CWIMAQViewer1, Rectangle
CWIMAQViewer1.Regions.RemoveAll
CWIMAQVision1.Extract2 CWIMAQViewer1.Image, CWIMAQViewer2.Image, Rectangle
End Sub
' Clicking the Learn button calls LearnPattern to learn the template
Private Sub Learn_Click()
Dim LearnOptions As New CWIMAQLearnPatternOptions
' Dim Rectangle As New CWIMAQRectangle
Dim ImageMask As New CWIMAQImage
Learn.Caption = "Learning..."
' 'Extract region correspoding to the region of interest in the image window
' CWMachineVision1.GetSelectedRectangleFromViewer CWIMAQViewer1, Rectangle
' CWIMAQViewer1.Regions.RemoveAll
' CWIMAQVision1.Extract2 CWIMAQViewer1.Image, CWIMAQViewer2.Image, Rectangle
ImageMask.Type = cwimaqImageTypeU8
CWIMAQVision1.RegionsToMask ImageMask, CWIMAQViewer2.Regions, CWIMAQViewer2.Image, 255
CWIMAQViewer2.Regions.RemoveAll
CWIMAQVision1.Xor ImageMask, 255, ImageMask
CWIMAQVision1.Mask CWIMAQViewer2.Image, ImageMask, CWIMAQViewer2.Image
'Set up Learn parameters
LearnOptions.LearnMode = cwimaqLearnAll
'Learn template
CWIMAQVision1.LearnPattern2 CWIMAQViewer2.Image, LearnOptions
CWIMAQVision1.WriteImageAndVisionInfo CWIMAQViewer2.Image, App.Path & "\images\0.png", _
CWIMAQViewer2.Palette
Learn.Caption = "&Learn Pattern"
'Enable the Match button and disable the Learn button
Match.Enabled = True
Learn.Enabled = False
End Sub
thx for your reply..
08-14-2009 03:38 PM
Hi,
Could you please let me know what version of Vision/Visual Studio you are using? Have you been able to create any masks for your images?
Cheers,
08-15-2009 09:43 PM
It is NI vision8.6 and VB6.0.
I pick up the mask code as below, user select a ROI as mask.then program learn and save image to 0.png as template, but it is only a mask image, not a template.
Private Sub Learn_Click()
Dim LearnOptions As New CWIMAQLearnPatternOptions
Dim ImageMask As New CWIMAQImage
'============ Mask ===========
ImageMask.Type = cwimaqImageTypeU8
CWIMAQVision1.RegionsToMask ImageMask, CWIMAQViewer2.Regions, CWIMAQViewer2.Image, 255
CWIMAQViewer2.Regions.RemoveAll
CWIMAQVision1.Xor ImageMask, 255, ImageMask
CWIMAQVision1.Mask CWIMAQViewer2.Image, ImageMask, CWIMAQViewer2.Image
'============ Template learn ===========
LearnOptions.LearnMode = cwimaqLearnAll
CWIMAQVision1.LearnPattern2 CWIMAQViewer2.Image, LearnOptions
'============ Save the template ===========
CWIMAQVision1.WriteImageAndVisionInfo CWIMAQViewer2.Image, App.Path & "\images\0.png", _
CWIMAQViewer2.Palette
End Sub
08-17-2009 09:09 PM
Hi Jack,
I'm going to go ahead and test out your code on my machine tomorrow morning- do you have a sample image that I could use to do this?
Thanks,
08-17-2009 09:30 PM