Archived:Common Errors and Issues When Using Pattern Matching with NI Vision

Updated Feb 2, 2018

National Instruments does not actively maintain this document.

This content provides support for older products and technology, so you may notice outdated links or obsolete information about operating systems or other relevant products.

Reported In

Software

  • Vision Development Module

Driver

  • NI-IMAQ
  • Vision Acquisition Software

Issue Details

How should I use the pattern matching functions? Why am I getting invalid template errors when I do pattern matching?

Solution

Pattern matching quickly locates regions of grayscale images that match a known reference pattern, also referred to as a model or template. Pattern matching involves creating a template that represents the object for which you are searching. The machine vision application then searches for instances of the template in each acquired image, calculating a score for each match. This score relates how closely the located matches resemble the template. Pattern matching can find template matches in varying degrees of lighting, blur, noise, and geometric transformations such as shifting, rotation, or scaling of the template.

Here are some common pattern matching errors: 

Error Message: -1074395247: Invalid template descriptor 
Error Message: Not a valid template 
Error Message: The Contrast In The Template Is Too Low 
Error Message: -1074396077: ERR_INCOMP_TYPE - Incompatible image type 
Some Matches Lie Outside A Rotated ROI When Doing Pattern Matching 
Various Errors When Logged On Under a Windows User Account

 
  • Error Message -1074395247: Invalid template descriptor
    When you create a pattern matching template in Vision Assistant or Vision Builder for Automated Inspection (VBAI), there is extra information saved in addition to the image itself. This includes overlay information, pattern matching template information, and calibration information. This information lets LabVIEW, Vision Assistant, or Vision Builder know how the template was learned. When you open that template in LabVIEW using the IMAQ ReadFile VI, this extra vision information is not transferred with the image. Likewise, if you try to create a template file using the IMAQ Write PNG File VI the extra vision information is not saved to file with the image, so Vision Assistant and Vision Builder do not recognize it as a valid pattern matching template.

    In LabVIEW: To retain the extra vision information with the image, open and create your pattern matching template using the IMAQ Read Image And Vision Info VI and the IMAQ Write Image And Vision Info VI, respectively. These VIs can be found in three locations:
    Vision and Motion»Vision Utilities»Overlay,
    Vision and Motion»Vision Utilities»Calibration
    Vision and Motion»Vision Utilities»Files.

    When creating a Template in LabVIEW, the IMAQ Learn Pattern VI should be used before the IMAQ Write PNG File VI in order to create the extra vision information that must be saved on the PNG file. Refer to the Create Template example in the Related Links section.

    In Visual Basic: To write an image, along with extra vision information associated with the image use the following.
    CWIMAQVision.WriteImageAndVisionInfo ( SourceImage, Path [, ColorPalette]) 

    This extra vision information includes overlay, pattern matching template, and calibration information, and custom data. To read an image file, including any extra vision information saved with the image use the following.
    CWIMAQVision.ReadImageAndVisionInfo ( SourceImage, Path [, ColorPalette])
This includes overlay information, pattern matching template information, custom data, and calibration information, as written by WriteImageAndVisionInfo.

Note: If you are using IMAQ Vision Builder 6.1, upgrade your Vision Acquisition drivers (NI IMAQ and NI IMAQdx), Vision Development Module (which contains Vision Assistant), and Vision Builder software to the latest versions. This error is reported when IMAQ Read Image and Vision Info VI cannot read the template information properly. Typically this error will arise when there are different versions of Vision Builder and Vision Development Module installed.
 
  • Error Message: Not a valid template
    You might get a not a valid template message in Vision Builder/Vision Assistant and a system error with NI Vision software 5.0 or 6.0 when selecting a large pattern matching template from your image. These errors occur because of a limitation with the size of the pattern matching template in the IMAQ Vision software. This limitation is present in Vision 5.0, Vision 6.0, and Vision 7.0. In Vision 7.0, the error message is: The Template is Too Large. For these versions of NI Vision, the maximum size for the pattern matching template is 160,000 pixels. It does not matter what the template dimensions are. 

    This behavior was addressed and changed in the Vision Development Module version 7.1. In this revision, there is no limit on the size of the template. 
 
  • Error Message -1074395235: The Contrast In The Template Is Too Low
    The error is generated when the selected region does not contain enough information to create a useful template. Most often this is caused by an image not having very high contrast. This error can also be caused if the region specified is very small. There are two ways to fix the problem:
    • Increase the contrast of the image. If you choose to use this option you should also increase the contrast in all the images on which you will perform pattern matching in order to ensure the pattern is found.
    • Increase the size of your template. This will give the algorithm more information to create a valid template.
 
  • Error Message -1074396077: ERR_INCOMP_TYPE - Incompatible image type
    In order for the pattern matching to operate correctly, the acquired image and the pattern template image must both have the same bit depth. For example, if you acquire 16-bit images but your pattern image is an 8-bit file, then LabVIEW will return the above error and will be unable to match the pattern to the image correctly.

    With certain FireWire cameras operating under NI-IMAQdx or NI-IMAQ for IEEE 1394, you can adjust the bit resolution of the image acquired by going through Measurement & Automation Explorer (MAX). In MAX go to Devices and Interfaces»NI-IMAQ IEEE 1394 Devices and then highlight your camera. Information about your camera and settings will appear on the right-hand side of the window and there you can check to see if the bit representation can be adjusted for your camera. If so, then if you have an 8-bit pattern image and your camera is set to 16-bit representation, then you can adjust the camera to correct the problem. Also, in some circumstances you will need to adjust the Byte Order and the Color coding options if you still receive LabVIEW errors. 

    If you cannot adjust your camera's bit representation but you have verified that your pattern image has a different bit resolution, then you can acquire a new pattern image file that matches the images being acquired. 
 
  • Some Matches Lie Outside A Rotated ROI When Doing Pattern Matching
    The pattern match algorithm can only search for an object inside of a non-rotated rectangular Region of Interest (ROI). If an ROI that does not meet these criteria is selected, the pattern match algorithm uses the bounding box for the selected ROI as its area to search. This means that the area searched is defined by the minimum and maximum X and Y values of your ROI rather than the ROI itself. 

    Workarounds: 
    • Rotate the image you are going to search so that you can give a non-rotated ROI. If you do this, you'll either need to have your template relearned or select Rotation Invariant for the Match Mode input on the IMAQ Setup Match Pattern VI.
    • First mask off everything outside of your selected ROI, forcing the area to black. Although the algorithm will still search the entire area as described above, this will ensure that no matches are found outside of your selected ROI.
 
  • Various Errors When Logged On Under a Windows User Account
    Users need to be logged on with Administrator privileges under Windows. Captured images in Vision Builder and Vision Assistant are saved as temporary files in the installation folder. Also, Vision algorithms use DLLs that are installed in the Windows system folder. If a user does not have write/read access to these system folders errors such as Not a valid template when using pattern matching will occur, even when all the settings are correct and the template image is valid.

WAS THIS ARTICLE HELPFUL?

Not Helpful