Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Pattern match in vision with a masked region

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

Greg Stoll
LabVIEW R&D
0 Kudos
Message 11 of 26
(3,222 Views)

Greg,  Is there an example of this anywhere, or would I find this anywhere in the documentation?

 

 

0 Kudos
Message 12 of 26
(3,219 Views)

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

Greg Stoll
LabVIEW R&D
0 Kudos
Message 13 of 26
(3,218 Views)

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?

0 Kudos
Message 14 of 26
(3,079 Views)

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

Greg Stoll
LabVIEW R&D
0 Kudos
Message 15 of 26
(3,072 Views)

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..

 

 

Message 16 of 26
(2,762 Views)

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, 

 

Marti C
Applications Engineer
National Instruments
NI Medical
0 Kudos
Message 17 of 26
(2,732 Views)

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

0 Kudos
Message 18 of 26
(2,722 Views)

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,

Marti C
Applications Engineer
National Instruments
NI Medical
0 Kudos
Message 19 of 26
(2,694 Views)
it just convert a image to template with a mask(select a ROI), so you can use any picture for it. thx again!
0 Kudos
Message 20 of 26
(2,690 Views)