National Instruments IMAQTM User Manual
National Instruments IMAQTM User Manual

National Instruments IMAQTM User Manual

Vision for visual basic
Table of Contents

Advertisement

Quick Links

IMAQ
TM
IMAQ Vision for Visual Basic

User Manual

IMAQ Vision for Visual Basic User Manual
August 2004 Edition
Part Number 371257A-01

Advertisement

Table of Contents
loading

Summary of Contents for National Instruments IMAQTM

  • Page 1: User Manual

    IMAQ IMAQ Vision for Visual Basic User Manual IMAQ Vision for Visual Basic User Manual August 2004 Edition Part Number 371257A-01...
  • Page 2 For further support information, refer to the Technical Support and Professional Services appendix. To comment on National Instruments documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback. © 2001–2004 National Instruments Corporation. All rights reserved.
  • Page 3: Important Information

    The reader should consult National Instruments if errors are suspected. In no event shall National Instruments be liable for any damages arising out of or related to this document or the information contained in it.
  • Page 4: Table Of Contents

    Acquiring an Image ...2-4 One-Shot Acquisition...2-4 Continuous Acquisition...2-5 Reading a File...2-6 Converting an Array to an Image ...2-6 Display an Image ...2-6 Attach Calibration Information...2-7 Analyze an Image ...2-7 © National Instruments Corporation IMAQ Vision for Visual Basic User Manual...
  • Page 5 Contents Improve an Image... 2-9 Lookup Tables... 2-9 Filters ... 2-9 Convolution Filter... 2-10 Nth Order Filter ... 2-10 Grayscale Morphology... 2-10 FFT... 2-11 Complex Image Operations ... 2-12 Chapter 3 Making Grayscale and Color Measurements Define Regions of Interest... 3-1 Defining Regions Interactively ...
  • Page 6 Instrument Reader Measurements ...5-28 Identify Parts Under Inspection ...5-28 Classifying Samples ...5-28 Reading Characters...5-29 Reading Barcodes...5-29 Read 1D Barcodes...5-29 Read Data Matrix Barcode...5-30 Read PDF417 Barcode...5-31 Display Results ...5-31 © National Instruments Corporation IMAQ Vision for Visual Basic User Manual Contents...
  • Page 7 Contents Chapter 6 Calibrating Images Perspective and Nonlinear Distortion Calibration... 6-1 Defining a Calibration Template... 6-2 Defining a Reference Coordinate System ... 6-3 Learning Calibration Information ... 6-5 Specifying Scaling Factors ... 6-6 Choosing a Region of Interest ... 6-6 Choosing a Learning Algorithm ...
  • Page 8: About This Manual

    This font is also used for the proper names of disk drives, paths, directories, programs, subprograms, subroutines, device names, functions, operations, variables, filenames, and extensions. © National Instruments Corporation IMAQ Vision for Visual Basic User Manual...
  • Page 9: Related Documentation

    IMAQ Vision objects, methods, properties, or events while creating your application, refer to this help file. You can access this file by selecting Start»Programs»National Instruments» Documentation»Vision»IMAQ Vision for Visual Basic Reference. NI Vision Assistant Tutorial—If you need to install NI Vision Assistant and learn the fundamental features of the software, follow the instructions in this tutorial.
  • Page 10 Vision\Examples\MSVB.NET Application Notes—If you want to know more about advanced IMAQ Vision concepts and applications, refer to the Application Notes located on the National Instruments Web site at appnotes.nsf NI Developer Zone (NIDZ)—If you want even more information about developing your vision application, visit the NI Developer Zone .
  • Page 11: Introduction To Imaq Vision

    This manual assumes that you are familiar with Visual Basic and can use ActiveX controls in Visual Basic. The following are good sources of information about Visual Basic and ActiveX controls: • • © National Instruments Corporation ™ ™ /CVI and other C development environments, as well as msdn.microsoft.com...
  • Page 12: Imaq Vision For Visual Basic Organization

    Access this file from within Visual Basic or from the Start menu by selecting Programs»National Instruments»Vision» Documentation. NI-IMAQ User Manual—If you have a National Instruments image acquisition (IMAQ) device and need information about the functions that control the IMAQ device, refer to this portable document (PDF) file which was installed at the following location when you installed NI-IMAQ: Start»Programs»National Instruments»Vision»...
  • Page 13: Cwimaq.ocx

    Note The CWIMAQViewer control is referred to as a document. © National Instruments Corporation Chapter 1 contains the following three ActiveX controls and a ActiveX Objects viewer...
  • Page 14: Niocr.ocx

    Chapter 1 Introduction to IMAQ Vision niocr.ocx niocr.ocx objects you use in a machine vision application to perform optical character recognition (OCR). NIOCR control Use this control to perform OCR, which is the process by which the machine vision software reads text and/or characters in an image. OCR consists of the following two procedures: •...
  • Page 15: Activex Objects

    Dim image As New CWIMAQImage If you intend to develop an application in Visual C++, National Instruments recommends that you use IMAQ Vision for LabWindows/CVI. However, if you decide...
  • Page 16 Chapter 1 Introduction to IMAQ Vision Measurement-Ready IMAQ Vision for Visual Basic User Manual Set Up Your Imaging System Calibrate Your Imaging System Create an Image Acquire or Read an Image Chapter 2: Getting Images Display an Image Attach Calibration Information Analyze an Image Improve an Image Improve an Image...
  • Page 17 Performing Classify Read Read Machine Objects Characters Symbologies Vision Tasks Convert Pixel Coordinates to Real-World Coordinates Make Measurements Display Results Figure 1-2. Inspection Steps for Building a Vision Application © National Instruments Corporation IMAQ Vision for Visual Basic User Manual...
  • Page 18: Getting Measurement-Ready Images

    Follow the guidelines below to set up an imaging system. © National Instruments Corporation Determine the type of equipment you need based on the space constraints and the size of the object you need to inspect. For more information, refer to Chapter 3, System Setup and Calibration, of the IMAQ Vision Concepts Manual.
  • Page 19: Calibrate Your Imaging System

    IMAQ devices. ni.com/imaq Configure the driver software for the image acquisition device. If you have a National Instruments image acquisition device, configure the NI-IMAQ driver software through Measurement & Automation Explorer (MAX). Open MAX by double-clicking the Measurement &...
  • Page 20 Most operations between two images require that the images have the same type and size. However, arithmetic operations work between two different types of images. For example, an arithmetic operation between an 8-bit image and 16-bit image results in a 16-bit image. © National Instruments Corporation Chapter 2 Complex 32-bit RGB...
  • Page 21: Acquire Or Read An Image

    Acquiring an Image Use the CWIMAQ control to acquire images with a National Instruments IMAQ device. You can use IMAQ Vision for Visual Basic to perform one-shot and continuous acquisitions. You can choose the acquisition type during design time by setting the value of the Acquisition Type combo box to One-Shot or Continuous.
  • Page 22: Continuous Acquisition

    The following code illustrates a ring, where images that you want to process: Private Sub Start_Click() End Sub © National Instruments Corporation CWIMAQ1.AcquisitionType = cwimaqAcquisitionOneShot CWIMAQ1.Images.RemoveAll CWIMAQ1.Images.Add numberOfImages CWIMAQ1.Start CWIMAQ.Start method to stop the acquisition. If you use a single buffer CWIMAQ.Stop...
  • Page 23: Reading A File

    Chapter 2 Getting Measurement-Ready Images Private Sub Stop_Click() End Sub Reading a File Use the a file stored on the computer into the image reference. You can read from image files stored in several standard formats, such as BMP, TIFF, JPEG, PNG, and AIPD.
  • Page 24: Attach Calibration Information

    • • The histogram and line profile tools can help you analyze the quality of the images. © National Instruments Corporation Chapter 2 CWIMAQPalette.Type . For more information about color palettes, refer to save the image and all of the To determine if the image quality is high enough for the inspection task.
  • Page 25 Chapter 2 Getting Measurement-Ready Images distribution in the image. Use the histogram of the image to analyze two important criteria that define the quality of an image—saturation and contrast. If the image does not have enough light, the majority of the pixels will have low intensity values, which appear as a concentration of peaks on the left side of the histogram.
  • Page 26: Improve An Image

    Lowpass filters remove insignificant details by smoothing the image, removing sharp details, and smoothing the edges between the objects and the background. You can use your own lowpass filter with CWIMAQVision.NthOrder © National Instruments Corporation Chapter 2 lookup table (LUT) transformations to highlight image details in CWIMAQVision.MathLookup image by replacing them with values from a predefined lookup table.
  • Page 27: Convolution Filter

    Chapter 2 Getting Measurement-Ready Images Highpass filters emphasize details, such as edges, object boundaries, or cracks. These details represent sharp transitions in intensity value. You can define your own highpass filter with CWIMAQVision.NthOrder filter with CWIMAQVision.CannyEdgeFilter allows you to find edges in an image using predefined edge detection kernels, such as the Sobel, Prewitt, and Roberts kernels.
  • Page 28: Fft

    Complete the following steps to obtain an image in which the unwanted pattern has disappeared but the overall features remain: © National Instruments Corporation Chapter 2 CWIMAQVision.GrayMorphology Erosion—Reduces the brightness of pixels that are surrounded by neighbors with a lower intensity.
  • Page 29: Complex Image Operations

    Chapter 2 Getting Measurement-Ready Images Complex Image Operations CWIMAQVision.ReplaceComplexPlane CWIMAQVision.ExtractComplexPlane and update independently the magnitude, phase, real, and imaginary planes of a complex image. You can also convert a complex image to an array and back with CWIMAQImage.ArrayToImage IMAQ Vision for Visual Basic User Manual Improve the image in the frequency domain with a lowpass or highpass frequency filter.
  • Page 30: Making Grayscale And Color Measurements

    You can interactively define an ROI in a viewer that displays an image. Use the tools from the right-click menu to interactively define and manipulate the ROIs. Table 3-1 describes each of the tools and the manner in which you use them. © National Instruments Corporation Define Regions of Interest Measure Grayscale Statistics Figure 3-1.
  • Page 31 Chapter 3 Making Grayscale and Color Measurements None Selection Tool Point Line Rectangle Rotated Rectangle Oval Annulus Broken Line IMAQ Vision for Visual Basic User Manual Table 3-1. Tools Palette Functions Tool Name Disable the tools. Select an ROI in the image and adjust the position of its control points and contours.
  • Page 32 Tool Info check box on the Status Bar property page during design time, or set the time to display tool information. You also can show or hide the tool information from the right-click menu. © National Instruments Corporation Chapter 3 Table 3-1. Tools Palette Functions (Continued) Tool Name Draw a polygon in the image.
  • Page 33 Chapter 3 Making Grayscale and Color Measurements 1 Anchoring Coordinates of a Region of Interest 2 Size of the Image 3 Zoom Factor 4 Image Type Indicator (8-bit, 16-bit, Float, RGB32, RGBU64, HSL, Complex) IMAQ Vision for Visual Basic User Manual 5 Pixel Intensity 6 Coordinates of the Mouse 7 Size of an Active Region of Interest...
  • Page 34: Defining Regions Programmatically

    CWIMAQViewer.Regions The individual CWIMAQRegion objects provide access to the shapes in the collection. Each region has one shape object associated with it. Use the CWIMAQRegion.Shape © National Instruments Corporation Chapter 3 CWIMAQViewer.Tool Table 3-2. Methods that Add Shapes to Regions...
  • Page 35: Defining Regions With Masks

    Chapter 3 Making Grayscale and Color Measurements CWIMAQRegion contains. When you know the type of shape that the region contains, you can set the region into a shape variable and use that variable to manipulate the shape properties. For example, the following code resizes a rectangle selected on the viewer: Dim MyRectangle As CWIMAQRectangle Set MyRectangle = CWIMAQViewer1.Regions(1)
  • Page 36: Measure Color Statistics

    8-bit or 16-bit images, where each image becomes one of the three primary components. Figures 3-3 and 3-4 illustrate how a color image breaks down into its three components. © National Instruments Corporation Chapter 3 to obtain the following statistics about the CWIMAQVision.Quantify...
  • Page 37 Chapter 3 Making Grayscale and Color Measurements Green Blue Saturation Color Intensity Image Saturation Luminance Saturation Value Color Image A color pixel encoded as a individual components using You can convert a pixel value represented in any color model into its components in any other color model using CWIMAQVision.ColorValueConversion2 IMAQ Vision for Visual Basic User Manual...
  • Page 38: Comparing Colors

    When learning color information, choose the color information carefully: • • • © National Instruments Corporation Chapter 3 Select an image containing the color information that you want to use as a reference. The color information can consist of a single color or multiple dissimilar colors, such as red and blue.
  • Page 39: Specifying The Color Information To Learn

    Chapter 3 Making Grayscale and Color Measurements Specifying the Color Information to Learn Because color matching only uses color information to measure similarity, the image or regions in the image representing the object should contain only the significant colors that represent the object, as shown in Figure 3-5a.
  • Page 40 3-amp fuses in the learning phase, draw a Region around the 3-amp fuse in the upper row, hold down <Ctrl>, and draw another Region around the 3 amp fuse in the lower row. The new color spectrum represents 3-amp © National Instruments Corporation 3-11 IMAQ Vision for Visual Basic User Manual...
  • Page 41: Choosing A Color Representation Sensitivity

    Chapter 3 Making Grayscale and Color Measurements fuses much better and results in high match scores—around 800—for both the fuses. You can use an unlimited number of samples to learn the representative color spectrum for a specified template. 1 Regions used to learn color information Choosing a Color Representation Sensitivity When you learn a color, you need to specify the granularity required to specify the color information.
  • Page 42: Ignoring Learned Colors

    For more information about the color wheel and color bins, refer to Chapter 14, Color Inspection, in the IMAQ Vision Concepts Manual. © National Instruments Corporation Chapter 3 Copy CWIMAQColorInformation.ColorSpectrum...
  • Page 43: Performing Particle Analysis

    You can use different techniques to threshold the image. If all the objects of interest in the grayscale image fall within a continuous range of intensities and you can specify this threshold range manually, use CWIMAQVision.Threshold © National Instruments Corporation Create a Binary Image Improve a Binary Image Make Particle Measurements in Pixels or Real-World Units Figure 4-1.
  • Page 44: Improve The Binary Image

    Chapter 4 Performing Particle Analysis If all the objects in the grayscale image are either brighter or darker than the background, you can use automatically determine the optimal threshold range and threshold the image. Automatic thresholding techniques offer more flexibility than simple thresholds based on fixed ranges.
  • Page 45: Removing Unwanted Particles

    Note A separation is a time-intensive operation compared to an erosion or open operation. Consider using an erosion if speed is an issue with the application. © National Instruments Corporation CWIMAQVision.RejectBorder CWIMAQVision.RemoveParticle CWIMAQVision.Morphology CWIMAQVision.RemoveParticle...
  • Page 46: Improving Particle Shapes

    Chapter 4 Performing Particle Analysis Improving Particle Shapes CWIMAQVision.Morphology particles. You can use the Open, Close, Proper Open, Proper Close, and auto-median operations to smooth the boundaries of the particles. Open and Proper Open Smooth the boundaries of the particle by removing small isthmuses, while close widens the isthmuses.
  • Page 47 © National Instruments Corporation Table 4-1. Measurement Types (Continued) Average length of a horizontal segment in the particle. Average length of a vertical segment in the particle. Y-coordinate of the lowest particle point.
  • Page 48 Chapter 4 Performing Particle Analysis Measurement cwimaqMeasurementConvexHullPerimeter cwimaqMeasurementElongationFactor cwimaqMeasurementEquivalentEllipseMajorAxis cwimaqMeasurementEquivalentEllipseMinorAxis cwimaqMeasurementEquivalentEllipseMinorAxisFeret cwimaqMeasurementEquivalentRectDiagonal cwimaqMeasurementEquivalentRectLongSide cwimaqMeasurementEquivalentRectShortSide cwimaqMeasurementEquivalentRectShortSideFeret cwimaqMeasurementFirstPixelX cwimaqMeasurementFirstPixelY cwimaqMeasurementHeywoodCircularityFactor IMAQ Vision for Visual Basic User Manual Table 4-1. Measurement Types (Continued) Perimeter of the smallest convex polygon containing all points in the particle.
  • Page 49 © National Instruments Corporation Table 4-1. Measurement Types (Continued) Sum of the areas of each hole in the particle. Sum of the perimeters of each hole in the particle. The first Hu moment.
  • Page 50 Chapter 4 Performing Particle Analysis Measurement cwimaqMeasurementMaxFeretDiameterStartY cwimaqMeasurementMaxHorizSegmentLengthLeft cwimaqMeasurementMaxHorizSegmentLengthRight cwimaqMeasurementMaxHorizSegmentLengthRow cwimaqMeasurementMomentOfInertiaXX cwimaqMeasurementMomentOfInertiaXXX cwimaqMeasurementMomentOfInertiaXXY cwimaqMeasurementMomentOfInertiaXY cwimaqMeasurementMomentOfInertiaXYY cwimaqMeasurementMomentOfInertiaYY cwimaqMeasurementMomentOfInertiaYYY cwimaqMeasurementNormMomentOfInertiaXX cwimaqMeasurementNormMomentOfInertiaXXX cwimaqMeasurementNormMomentOfInertiaXXY IMAQ Vision for Visual Basic User Manual Table 4-1. Measurement Types (Continued) Y-coordinate of the start of the line segment connecting the two perimeter points that are the furthest apart.
  • Page 51 © National Instruments Corporation Table 4-1. Measurement Types (Continued) The normalized moment of inertia in the X and Y directions. The normalized moment of inertia in the X direction once and the Y direction twice.
  • Page 52 Chapter 4 Performing Particle Analysis Measurement cwimaqMeasurementSumXXY cwimaqMeasurementSumXY cwimaqMeasurementSumXYY cwimaqMeasurementSumY cwimaqMeasurementSumYY cwimaqMeasurementSumYYY cwimaqMeasurementTypesFactor cwimaqMeasurementWaddelDiskDiameter IMAQ Vision for Visual Basic User Manual Table 4-1. Measurement Types (Continued) The sum of all X-coordinates squared times Y-coordinates in the particle. The sum of all X-coordinates times Y-coordinates in the particle.
  • Page 53: Performing Machine Vision Tasks

    All the elements of the image acquisition chain directly affect the accuracy of the measurements. Figure 5-1 illustrates the basic steps involved in performing machine vision. © National Instruments Corporation IMAQ Vision for Visual Basic User Manual...
  • Page 54: Locate Objects To Inspect

    Chapter 5 Performing Machine Vision Tasks Diagram items enclosed with dashed lines are optional steps. Note Locate Objects to Inspect In a typical machine vision application, you extract measurements from regions of interest rather than the entire image. To use this technique, the parts of the object you are interested in must always appear inside the regions of interest you define.
  • Page 55: Using Edge Detection To Build A Coordinate Transformation

    Follow the steps below to build a coordinate transformation using edge detection. To use this technique, the object cannot rotate more than ±65° in the image. Note © National Instruments Corporation CWMachineVision.FindCoordTransformUsingRect Specify one or two rectangular ROIs. If you use CWMachineVision.FindCoordTransformUsingRect...
  • Page 56 Chapter 5 Performing Machine Vision Tasks 1 Search Area for the Coordinate System 2 Object Edges IMAQ Vision for Visual Basic User Manual 3 Origin of the Coordinate System 4 Measurement Area Figure 5-2. Coordinate Systems of a Reference Image and Inspection Image If you use CWMachineVision.FindCoordTransformUsingTwoRects specify two rectangular ROIs, each containing one separate,...
  • Page 57: Using Pattern Matching To Build A Coordinate Transformation

    Note The object may rotate 360° in the image using this technique if you use rotation-invariant pattern matching. © National Instruments Corporation 3 Origin of the Coordinate System 4 Measurement Area Figure 5-3. Locating Coordinate System Axes with Two Search Areas Choose the parameters you need to locate the edges on the object.
  • Page 58 Chapter 5 Performing Machine Vision Tasks IMAQ Vision for Visual Basic User Manual Define a template that represents the part of the object that you want to use as a reference feature. For more information about defining a template, refer to the Find Measurement Points Define a rectangular search area in which you expect to find the template.
  • Page 59: Choosing A Method To Build The Coordinate Transformation

    Build a coordinate transformation based on edge detection using a single search area. © National Instruments Corporation The object contains a second distinct edge not parallel to the main axis in a separate search area. Object positioning accuracy better than ±5 degrees.
  • Page 60: Set Search Areas

    Chapter 5 Performing Machine Vision Tasks Set Search Areas Select ROIs in the images to limit the areas in which you perform the processing and inspection. You can define ROIs interactively or programmatically. Defining Regions Interactively Follow these steps to interactively define an ROI: You also can use the techniques described in Chapter 3, and Color Table 5-1 indicates which ROI selection methods to use with a given...
  • Page 61: Defining Regions Programmatically

    Use the edge detection tools to identify and locate sharp discontinuities in an image. Discontinuities typically represent abrupt changes in pixel intensity values, which characterize the boundaries of objects. © National Instruments Corporation Chapter 5 Performing Machine Vision Tasks CWMachineVision Method...
  • Page 62: Finding Lines Or Circles

    Chapter 5 Performing Machine Vision Tasks Finding Lines or Circles If you want to find points along the edge of an object and find a line describing the edge, use CWMachineVision.FindStraightEdge on rectangular search areas, as shown in Figure 5-5. CWMachineVision.FindConcentricEdge on annular search areas.
  • Page 63: Finding Edge Points Along One Search Contour

    These methods determine the edge points based on their contrast and slope. You can specify if you want to find the edge points using subpixel accuracy. © National Instruments Corporation Figure 5-6. Finding a Circular Feature CWIMAQVision.SimpleEdge CWIMAQVision.SimpleEdge...
  • Page 64: Finding Edge Points Along Multiple Search Contours

    Chapter 5 Performing Machine Vision Tasks Finding Edge Points Along Multiple Search Contours Use the CWIMAQVision.ConcentricRake along multiple search contours. These methods behave like CWIMAQVision.FindEdges2 These methods find only the first edge that meets the criteria along each contour. Pass in a CWIMAQRegions object to define the search region for these methods.
  • Page 65: Defining And Creating Effective Template Images

    A rotationally symmetric template provides good positioning information but no orientation information. a Rotationally Symmetric © National Instruments Corporation Define an image or an area of an image as the search area. A small search area reduces the time to find the features.
  • Page 66 Chapter 5 Performing Machine Vision Tasks Feature Detail A template with relatively coarse features is less sensitive to variations in size and rotation than a model with fine features. However, the model must contain enough detail to identify it. a Good Feature Detail Positional Information A template with strong edges in both the x and y directions is easier to locate.
  • Page 67: Training The Pattern Matching Algorithm

    Learning the template for shift-invariant matching is faster than learning for rotation-invariant matching. You also can save time by training the pattern matching algorithm offline, and then saving the template image with © National Instruments Corporation Figure 5-10. Background Information parameter of LearnPatternOptions...
  • Page 68: Defining A Search Area

    Chapter 5 Performing Machine Vision Tasks Defining a Search Area Two equally important factors define the success of a pattern matching algorithm: accuracy and speed. You can define a search area to reduce ambiguity in the search process. For example, if the image has multiple instances of a pattern and only one of them is required for the inspection task, the presence of additional instances of the pattern can produce incorrect results.
  • Page 69: Setting Matching Parameters And Tolerances

    ±5° from the template, set CWIMAQMatchPatternOptions.MatchMode cwimaqMatchShiftInvariant cwimaqMatchRotationInvariant Shift-invariant matching is faster than rotation-invariant matching. Note © National Instruments Corporation Figure 5-11. Selecting a Search Area for Grayscale Pattern Matching . Otherwise, set the mode element 5-17 Chapter 5 Performing Machine Vision Tasks...
  • Page 70: Testing The Search Algorithm On Test Images

    Chapter 5 Performing Machine Vision Tasks Minimum Contrast Contrast is the difference between the smallest and largest pixel values in a region. You can set the minimum contrast to potentially increase the speed of the pattern matching algorithm. The pattern matching algorithm ignores all image regions where contrast values fall beneath a set minimum contrast value.
  • Page 71: Using A Ranking Method To Verify Results

    Follow these general steps to find features in an image using color pattern matching: © National Instruments Corporation The object you want to locate has color information that is very different from the background, and you want to find a very precise location of the object in the image.
  • Page 72: Defining And Creating Effective Color Template Images

    Chapter 5 Performing Machine Vision Tasks Defining and Creating Effective Color Template Images The selection of a effective template image plays a critical part in obtaining accurate results with the color pattern matching algorithm. Because the template image represents the color and the pattern that you want to find, make sure that all the important and unique characteristics of the pattern are well defined in the image.
  • Page 73: Training The Color Pattern Matching Algorithm

    However, you can train the pattern matching algorithm offline, and save the template image using CWIMAQVision.WriteImageAndVisionInfo © National Instruments Corporation Chapter 5 Training the Pattern Matching Algorithm to learn the template. The CWIMAQVision.LearnColor...
  • Page 74: Defining A Search Area

    Chapter 5 Performing Machine Vision Tasks Defining a Search Area Two equally important factors define the success of a color pattern matching algorithm—accuracy and speed. You can define a search area to reduce ambiguity in the search process. For example, if the image has multiple instances of a pattern and only one instance is required for the inspection task, the presence of additional instances of the pattern can produce incorrect results.
  • Page 75: Setting Matching Parameters And Tolerances

    Use the search strategy to optimize the speed of the color pattern matching algorithm. The search strategy controls the step size, sub-sampling factor, and the percentage of color information used from the template. © National Instruments Corporation 5-23 IMAQ Vision for Visual Basic User Manual...
  • Page 76 Chapter 5 Performing Machine Vision Tasks Use one of the following four search strategies: • • • • Use the conservative strategy if you have multiple targets located very close to each Note other in the image. Decide on the best strategy by experimenting with the different options. a search strategy.
  • Page 77: Testing The Search Algorithm On Test Images

    Use color location under the following circumstances: • • • © National Instruments Corporation section of this chapter for more information about minimum CWIMAQMatchPatternOptions.RotationAngleRanges CWIMAQVision.MatchColorPattern Requires the location and the number of regions in an image with their...
  • Page 78: Convert Pixel Coordinates To Real-World Coordinates

    Chapter 5 Performing Machine Vision Tasks • • Complete the following steps to find features in an image using color location: image. Convert Pixel Coordinates to Real-World Coordinates The measurement points you located with edge detection and pattern matching are in pixel coordinates. If you need to make measurements using real-world units, use CWIMAQVision.ConvertPixelToRealWorldCoordinates the pixel coordinates into real-world units.
  • Page 79: Analytic Geometry Measurements

    • • • • • • • © National Instruments Corporation CWMachineVision.MeasureMaximumDistance largest separation between two edges in a rectangular search region. CWMachineVision.MeasureMinimumDistance smallest separation between two edges in a rectangular search region. CWIMAQVision.FindPointDistances Find Measurement Points —Fits a line to a set of points and computes the equation of FitLine the line.
  • Page 80: Instrument Reader Measurements

    Chapter 5 Performing Machine Vision Tasks • • Instrument Reader Measurements You can make measurements based on the values obtained by meter, LCD, and barcode readers. CWIMAQMeterArc.CreateFromLines gauge that you want to read. calibrates the meter using the initial position and the full-scale position of the needle.
  • Page 81: Reading Characters

    Before you classify objects, you must create a classifier file with samples of the objects using the NI Classification Training Interface. Go to Start» Programs»National Instruments»Classification Training to launch the NI Classification Training Interface. After you have trained samples of the objects you want to classify, use the following methods to classify the image under inspection: •...
  • Page 82: Read Data Matrix Barcode

    Chapter 5 Performing Machine Vision Tasks types: Codabar, Code 39, Code 93, Code 128, EAN 8, EAN 13, Interleaved 2 of 5, MSI, and UPCA. Read Data Matrix Barcode in a Data Matrix barcode. This method can automatically determine the location of the barcode and appropriate search options for the application.
  • Page 83: Read Pdf417 Barcode

    Overlays on a viewer image are automatically updated when you call one of these methods. • • © National Instruments Corporation CWIMAQVision.ReadDataMatrixBarcode CWIMAQVision.ReadPDF417Barcode CWIMAQVision.ReadPDF417Barcode Instrument Reader Measurements CWIMAQImage.Overlays CWIMAQImage.Overlay(1)
  • Page 84 Chapter 5 Performing Machine Vision Tasks • • • • • • You can select the color of overlays by using one of these methods. If you do not supply a color to an overlay method, the is used. You can configure the following CWMachineVision methods to overlay different types of information about the inspection image: •...
  • Page 85 CWIMAQVision.ReadImageAndVisionInfo As with calibration information, overlay information is removed from an image Note when the image size or orientation changes. © National Instruments Corporation . With CWMachineVision.FindPattern to clear any previous overlay information CWIMAQOverlay.Clear CWIMAQVision.WriteImageAndVisionInfo...
  • Page 86: Calibrating Images

    Depending on your needs, you can either apply calibration information in one of the following ways: • • © National Instruments Corporation Define a calibration template. Define a reference coordinate system. Learn the calibration information.
  • Page 87: Defining A Calibration Template

    Note You can use the calibration grid installed with IMAQ Vision at Start»Programs» National Instruments»Vision»Documentation»Calibration Grid. The dots have radii of 2 mm and center-to-center distances of 1 cm. Depending on the printer, these measurements may change by a fraction of a millimeter. You can purchase highly accurate calibration grids from optics suppliers, such as Edmund Industrial Optics.
  • Page 88: Defining A Reference Coordinate System

    If you specify a grid for the calibration process, the software defines the following default coordinate system, as shown in Figure 6-3: © National Instruments Corporation Figure 6-2. Axis Direction in the Image Plane The origin is placed at the center of the left, topmost dot in the calibration grid.
  • Page 89 Chapter 6 Calibrating Images 1 Origin of a Calibration Grid in the Real World If you specify a list of points instead of a grid for the calibration process, Note the software defines a default coordinate system, as follows: If you define a coordinate system yourself, carefully consider the requirements of the application: •...
  • Page 90: Learning Calibration Information

    If you want to specify a list of points instead of a grid, use Note CWIMAQVision.LearnCalibrationPoints Use the CWIMAQCalibrationPoints object to specify the pixel to real-world mapping. © National Instruments Corporation 2 User-Defined Origin Figure 6-4. Defining a Coordinate System Acquire or Read an Image section of Chapter 2, Images.
  • Page 91: Specifying Scaling Factors

    Chapter 6 Calibrating Images Specifying Scaling Factors Scaling factors are the real-world distances between the dots in the calibration grid in the x and y directions and the units in which the distances are measured. Use CWIMAQCalibrationGridOptions.GridDescriptor specify the scaling factors. Choosing a Region of Interest Define a learning ROI during the learning process to define a region of the calibration grid you want to learn.
  • Page 92: Using The Learning Score

    A high learning score indicates that you chose the the appropriate learning algorithm, that the grid image complies with the guideline, and that the vision system setup is adequate. © National Instruments Corporation Perspective Algorithm Figure 6-6. Calibration ROIs...
  • Page 93: Learning The Error Map

    Chapter 6 Calibrating Images A high score does not reflect the accuracy of the system. Note If the learning process returns a learning score below 600, try the following: Learning the Error Map An error map helps you gauge the quality of the complete system. The error map returns an estimated error range to expect when a pixel coordinate is transformed into a real-world coordinate.
  • Page 94: Calibration Invalidation

    Use CWIMAQSimpleCalibrationOptions.GridDescriptor to specify the scaling factors. Use CWIMAQSimpleCalibrationOptions.CorrectionScalingMode to set the scaling mode. Set CWIMAQSimpleCalibrationOptions.LearnCorrectionTable True © National Instruments Corporation CWIMAQVision.Extract2 , and CWIMAQImage.ArrayToImage CWIMAQSimpleCalibrationOptions.CalibrationAxisInfo to learn the correction table. Chapter 6 Calibrating Images...
  • Page 95: Save Calibration Information

    Chapter 6 Calibrating Images 1 Origin Save Calibration Information After you learn the calibration information, you can save it so that you do not have to relearn the information for subsequent processing. Use CWIMAQVision.WriteImageAndVisionInfo the grid and its associated calibration information to a file. To read the file containing the calibration information use CWIMAQVision.ReadImageAndVisionInfo about attaching the calibration information you read from another image,...
  • Page 96 Use CWIMAQVision.WriteImageAndVisionInfo calibration information to a file. If you modify the image after using CWIMAQVision.WriteImageAndVisionInfo information and use © National Instruments Corporation CWIMAQVision.CorrectCalibratedImage to save the image and all of the attached , you must relearn the calibration CWIMAQVision.WriteImageAndVisionInfo...
  • Page 97 Technical Support and Professional Services Visit the following sections of the National Instruments Web site at ni.com • • • If you searched your local office or NI corporate headquarters. Phone numbers for our worldwide offices are listed at the front of this manual. You also can visit...
  • Page 98 Numbers One-dimensional. Two-dimensional. Three-dimensional. AIPD The National Instruments internal image file format used for saving complex images and calibration information associated with an image (extension APD). alignment The process by which a machine vision application determines the location, orientation, and scale of a part being inspected.
  • Page 99 Glossary barycenter The grayscale value representing the centroid of the range of an image’s grayscale values in the image histogram. binary image An image in which the objects usually have a pixel intensity of 1 (or 255) and the background has a pixel intensity of 0. binary morphology Functions that perform morphological operations on a binary image.
  • Page 100 32 bits for the real part and 32 bits for the imaginary part. connectivity Defines which of the surrounding pixels of a given pixel constitute its neighborhood. © National Instruments Corporation IMAQ Vision for Visual Basic User Manual Glossary...
  • Page 101 Glossary connectivity-4 Only pixels adjacent in the horizontal and vertical directions are considered neighbors. connectivity-8 All adjacent pixels are considered neighbors. contrast A constant multiplication factor applied to the luma and chroma components of a color pixel in the color decoding process. convex hull The smallest convex polygon that can encapsulate a particle.
  • Page 102 The nonlinear change in the difference between the video signal’s brightness level and the voltage level needed to produce that brightness. gradient convolution filter © National Instruments Corporation histogram equalization. gradient filter. Glossary center of mass.
  • Page 103 Glossary gradient filter An edge detection algorithm that extracts the contours in gray-level values. Gradient filters include the Prewitt and Sobel filters. gray level The brightness of a pixel in an image. gray-level dilation Increases the brightness of pixels in an image that are surrounded by other pixels with a higher intensity.
  • Page 104 The number of values a pixel can take on, which is the number of colors or shades that you can see in the image. image display A window or control that displays an image. environment © National Instruments Corporation IMAQ Vision for Visual Basic User Manual Glossary...
  • Page 105 Glossary image enhancement The process of improving the quality of an image that you acquire from a sensor in terms of signal-to-noise ratio, image contrast, edge definition, and so on. image file A file containing pixel data and additional information about the image. image format Defines how an image is stored in a file.
  • Page 106 This function also can step and repeat its measurements across the image. line profile Represents the gray-level distribution along a line of pixels in an image. © National Instruments Corporation IMAQ Vision for Visual Basic User Manual Glossary...
  • Page 107 Glossary linear filter A special algorithm that calculates the value of a pixel based on its own pixel value as well as the pixel values of its neighbors. The sum of this calculation is divided by the sum of the elements in the matrix to obtain a new pixel value.
  • Page 108 Operations on a point in an image that take into consideration the values of operations the pixels neighboring that point. © National Instruments Corporation G-11 IMAQ Vision for Visual Basic User Manual Glossary , when used with...
  • Page 109 Glossary NI-IMAQ The driver software for National Instruments IMAQ hardware. nonlinear filter Replaces each pixel value with a nonlinear function of its surrounding pixels. nonlinear A highpass edge-extraction filter that favors vertical edges. gradient filter nonlinear Prewitt filter A highpass, edge-extraction filter based on two-dimensional gradient information.
  • Page 110 PNG images have the file extension PNG. Prewitt filter An edge detection algorithm that extracts the contours in gray-level values using a 3 × 3 filter kernel. © National Instruments Corporation G-13 IMAQ Vision for Visual Basic User Manual Glossary...
  • Page 111 Glossary proper-closing A finite combination of successive closing and opening operations that you can use to fill small holes and smooth the boundaries of objects. proper-opening A finite combination of successive opening and closing operations that you can use to remove small particles and smooth the boundaries of objects. quantitative analysis Obtaining various measurements of objects in an image.
  • Page 112 An edge detection algorithm that extracts the contours in gray-level values using a 3 × 3 filter kernel. spatial calibration Assigns physical dimensions to the area of a pixel in an image. © National Instruments Corporation G-15 IMAQ Vision for Visual Basic User Manual Glossary...
  • Page 113 Glossary spatial filters Alter the intensity of a pixel relative to variations in intensities of its neighboring pixels. You can use these filters for edge detection, image enhancement, noise reduction, smoothing, and so forth. spatial resolution The number of pixels in an image, in terms of the number of rows and columns in the image.
  • Page 114 The grayscale intensity of a color pixel computed as the average of the maximum and minimum red, green, and blue values of that pixel. © National Instruments Corporation G-17 IMAQ Vision for Visual Basic User Manual Glossary...
  • Page 115 5-29 reading 1D, 5-29 reading data matrix barcodes, 5-30 reading PDF417 barcodes, 5-31 binary images, improving, 4-2 Broken Line tool, 3-2 © National Instruments Corporation building coordinate transformation with edge detection, 5-3 coordinate transformation with pattern matching, 5-5 building coordinate transformations, 5-7...
  • Page 116 Index color pattern matching finding points, 5-19 optimize speed with search strategy, 5-23 setting rotation angle ranges, 5-25 color pattern matching algorithms training, 5-21 using contrast, 5-25 color scores, 5-24 color sensitivity, using to control granularity in template images, 5-23 color spectrums, learning, 3-10 color statistics, measuring, 3-6, 3-7 color template images, defining, 5-20...
  • Page 117 5-10 points using color pattern matching, 5-19 points using pattern matching, 5-12 points with color location, 5-25 Free Region tool, 3-3 © National Instruments Corporation Freeline tool, 3-3 geometrical measurements, 5-27 granularity specifying requirements for learning a...
  • Page 118 5-7 multiple ROIs, using to view color differences in an image, 3-11 multiple search contours, finding edge points, 5-12 National Instruments support and services, A-1 NI-IMAQ, xi niocr.ocx, 1-4 nonlinear calibration, 6-1 Nth order filter, 2-10...
  • Page 119 4-1 perspective calibration, 6-1 pixel coordinates, converting to real-world coordinates, 5-26 Point tool, 3-2 © National Instruments Corporation points finding along one search contour, 5-11 finding along the edge of a circle, 5-10 finding measurement points, 5-9...
  • Page 120 Index ROIs adding shapes, 3-5 programmatically defining, 3-5 Rotated Rectangle tool, 3-2 rotation angle ranges setting for color pattern matching, 5-25 setting for pattern matching, 5-18 rotationally symmetric template, 5-20 saving calibration information, 6-10 scaling factors, specifying, 6-6 scaling mode, setting, 6-8 search algorithms, testing on test images, 5-18, 5-25 search area, defining, 5-16, 5-22...
  • Page 121 (NI resources), A-1 using learning scores, 6-7 ranking to verify pattern matching results, 5-19 © National Instruments Corporation viewing color differences in an image using multiple regions, 3-11 Vision for Visual Basic organization, 1-2 voiding calibrations, 6-9 Web resources, A-1...

This manual is also suitable for:

Imaq

Table of Contents