background image

©

 National Instruments Corporation

2-1

IMAQ Vision for Visual Basic User Manual

2

Getting Measurement-Ready 
Images

This chapter describes how to set up an imaging system, acquire and 
display an image, analyze the image, and prepare the image for additional 
processing.

Set Up Your Imaging System

Before you acquire, analyze, and process images, you must set up an 
imaging system. The manner in which you set up the system depends on the 
imaging environment and the type of analysis and processing you need to 
do. Your imaging system should produce images with high enough quality 
so that you can extract the information you need from the images.

Follow the guidelines below to set up an imaging system.

1.

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

.

a.

Make sure the camera sensor is large enough to satisfy the 
minimum resolution requirement. 

b.

Make sure the lens has a depth of field high enough to keep all of 
the objects in focus regardless of their distance from the lens. 
Also, make sure the lens has a focal length that meets your needs.

c.

Make sure the lighting provides enough contrast between the 
object under inspection and the background for you to extract the 
information you need from the image.

2.

Position the camera so that it is parallel to the object under inspection. 
If the camera acquires images of the object from an angle, perspective 
errors occur. Even though you can compensate for these errors with 
software, NI recommends that you use a perpendicular inspection 
angle to obtain the fastest and most accurate results.

3.

Select an image acquisition device that meets your needs. National 
Instruments offers several image acquisition devices, such as analog 

Summary of Contents for IMAQ

Page 1: ...IMAQ TM IMAQ Vision for Visual Basic User Manual IMAQ Vision for Visual Basic User Manual August 2004 Edition Part Number 371257A 01 ...

Page 2: ...190000 Israel 972 0 3 6393737 Italy 39 02 413091 Japan 81 3 5472 2970 Korea 82 02 3451 3400 Malaysia 603 9131 0918 Mexico 01 800 010 0793 Netherlands 31 0 348 433 466 New Zealand 0800 553 322 Norway 47 0 66 90 76 60 Poland 48 22 3390150 Portugal 351 210 311 210 Russia 7 095 783 68 51 Singapore 65 6226 5886 Slovenia 386 3 425 4200 South Africa 27 0 11 805 8197 Spain 34 91 640 0085 Sweden 46 0 8 587...

Page 3: ...ide reasonable control Copyright Under the copyright laws this publication may not be reproduced or transmitted in any form electronic or mechanical including photocopying recording storing in an information retrieval system or translating in whole or in part without the prior written consent of National Instruments Corporation Trademarks CVI IMAQ LabVIEW National Instruments National Instruments ...

Page 4: ...ontrol 1 3 CWIMAQViewer Control 1 3 niocr ocx 1 4 NIOCR control 1 4 cwmv ocx 1 4 CWMachineVision control 1 4 ActiveX Objects 1 5 Creating IMAQ Vision Applications 1 5 Chapter 2 Getting Measurement Ready Images Set Up Your Imaging System 2 1 Calibrate Your Imaging System 2 2 Create an Image 2 2 Acquire or Read an Image 2 4 Acquiring an Image 2 4 One Shot Acquisition 2 4 Continuous Acquisition 2 5 R...

Page 5: ...ing Colors 3 9 Learning Color Information 3 9 Specifying the Color Information to Learn 3 10 Using the Entire Image 3 10 Choosing a Color Representation Sensitivity 3 12 Ignoring Learned Colors 3 13 Chapter 4 Performing Particle Analysis Create a Binary Image 4 1 Improve the Binary Image 4 2 Removing Unwanted Particles 4 3 Separating Touching Particles 4 3 Improving Particle Shapes 4 4 Make Partic...

Page 6: ... Testing the Search Algorithm on Test Images 5 18 Using a Ranking Method to Verify Results 5 19 Finding Points Using Color Pattern Matching 5 19 Defining and Creating Effective Color Template Images 5 20 Training the Color Pattern Matching Algorithm 5 21 Defining a Search Area 5 22 Setting Matching Parameters and Tolerances 5 23 Testing the Search Algorithm on Test Images 5 25 Finding Points Using...

Page 7: ...libration Information 6 5 Specifying Scaling Factors 6 6 Choosing a Region of Interest 6 6 Choosing a Learning Algorithm 6 6 Using the Learning Score 6 7 Learning the Error Map 6 8 Learning the Correction Table 6 8 Setting the Scaling Mode 6 8 Calibration Invalidation 6 9 Simple Calibration 6 9 Save Calibration Information 6 10 Attach Calibration Information 6 10 Appendix A Technical Support and P...

Page 8: ... Setup item and select Options from the last dialog box This icon denotes a tip which alerts you to advisory information This icon denotes a note which alerts you to important information bold Bold text denotes items that you must select or click in the software such as menu items and dialog box options Bold text also denotes parameter names italic Italic text denotes variables emphasis a cross re...

Page 9: ...n access this file by selecting Start Programs National Instruments Documentation Vision IMAQ Vision for Visual Basic Reference NI Vision Assistant 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 NI Vision Assistant Help If you need descriptions or step by step guidance about how to ...

Page 10: ...s manual NI IMAQ VI or function reference guides If you need information about the features functions and operation of the NI IMAQ image acquisition VIs or functions refer to these help files IMAQ Vision Deployment Engine Note to Users If you need information about how to deploy your custom IMAQ Vision applications on target computers read this CD insert Example programs If you want examples of ho...

Page 11: ...that you can use to develop machine vision and scientific imaging applications The Vision Development Module also includes the same imaging functions for LabWindows CVI and other C development environments as well as VIs for LabVIEW Vision Assistant another Vision Development Module software product enables you to prototype your application strategy quickly without having to do any programming Add...

Page 12: ... to open this file Example programs If you want examples of how to create specific applications in Visual Basic go to Vision Examples MSVB If you want examples of how to create specific applications in Microsoft Visual Basic NET go to Vision Examples MSVB NET CWMachineVision source code If you want to refer to the source code for the CWMachineVision control go to Vision Source MSVB Application Not...

Page 13: ...er software installed on the target system to use the CWIMAQ control For information about NI IMAQ refer to the NI IMAQ User Manual that came with the IMAQ device CWIMAQVision Control Use this control to analyze and process images and their related data The CWIMAQVision control provides methods for reading and writing images to and from files analyzing images and performing a variety of image proc...

Page 14: ... you create in a character set file Training might be a one time process or it might be a process you repeat several times creating several character sets to broaden the scope of characters you want to detect in an image Reading characters is the process by which the machine vision application you create analyzes an image to determine if the objects match the characters you trained The machine vis...

Page 15: ...ge Dim image As New CWIMAQImage Tip 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 to use IMAQ Vision for Visual Basic to develop applications for Visual C you can create objects using the respective Create methods on the CWIMAQVision control or CWMachineVision control For example to create a CWI...

Page 16: ...librate Your Imaging System Create an Image Acquire or Read an Image Display an Image Attach Calibration Information Analyze an Image Improve an Image Make Measurements or Identify Objects in an Image Using 1 Grayscale or Color Measurements and or 2 Particle Analysis and or 3 Machine Vision Chapter 2 Getting Measurement Ready Images Improve an Image Chapter 6 Calibrating Images ...

Page 17: ...ents Measure Grayscale Statistics Measure Color Statistics 2 Create a Binary Image Improve a Binary Image Make Particle Measurements Chapter 4 Performing Particle Analysis 3 Chapter 5 Performing Machine Vision Tasks Display Results Locate Objects to Inspect Set Search Areas 4 Find Measurement Points Convert Pixel Coordinates to Real World Coordinates Make Measurements Identify Parts Under Inspecti...

Page 18: ...more information refer to Chapter 3 System Setup and Calibration of the IMAQ Vision Concepts Manual a Make sure the camera sensor is large enough to satisfy the minimum resolution requirement b Make sure the lens has a depth of field high enough to keep all of the objects in focus regardless of their distance from the lens Also make sure the lens has a focal length that meets your needs c Make sur...

Page 19: ...nlinear errors inherent in the imaging system Perspective errors occur when the camera axis is not perpendicular to the object under inspection Nonlinear distortion may occur from aberrations in the camera lens Perspective errors and lens aberrations cause images to appear distorted This distortion displaces information in an image but it does not necessarily destroy the information in the image U...

Page 20: ...ne source image Methods that process the contents of the image require one or more source images and a destination image Exceptions to the preceding statements are methods that take a mask image as input The presence of a MaskImage parameter indicates that the processing or analysis is dependent on the contents of the mask image The only pixels in the source image that are processed are those whos...

Page 21: ...Shot or Continuous The Acquisition Type combo box is located on the Acquisition property page of the CWIMAQ control You can set the value at run time by setting the CWIMAQ AcquisitionType property to cwimaqAcquisitionOneShot or cwimaqAcquisitionContinuous One Shot Acquisition Use a one shot acquisition to start an acquisition perform the acquisition and stop the acquisition using a single method T...

Page 22: ...sition and continuously acquire frames into the image buffers and then explicitly stop the acquisition Use the CWIMAQ Start method to start the acquisition Use the CWIMAQ Stop method to stop the acquisition If you use a single buffer for the acquisition this operation is called a grab The following code illustrates a grab Private Sub Start_Click CWIMAQ1 AcquisitionType _ cwimaqAcquisitionContinuou...

Page 23: ...l depth recommended image type and calibration units without actually reading all the image data Converting an Array to an Image Use the CWIMAQImage ArrayToImage method to convert an array to an image You also can use the CWIMAQImage ImageToArray method to convert an image to an array Display an Image Display an image using the CWIMAQViewer control Use CWIMAQViewer Attach to attach the image you w...

Page 24: ...ationInformation This method takes in a source image that contains the calibration information and a destination image that you want to calibrate The output image is the inspection image with the calibration information attached to it For detailed information about calibration refer to Chapter 6 Calibrating Images Note Because calibration information is part of the image it is propagated throughou...

Page 25: ...is If the image quality does not meet your needs try to improve the imaging conditions to get the appropriate image quality You may need to re evaluate and modify each component of the imaging setup lighting equipment and setup lens tuning camera operation mode and acquisition board parameters If you reach the best possible conditions with the setup but the image quality still does not meet your n...

Page 26: ...ore information about these lookup tables refer to Chapter 5 Image Processing in the IMAQ Vision Concepts Manual CWIMAQVision UserLookup Converts the pixel values of an image by replacing them with values from a user defined lookup table CWIMAQVision Equalize2 Distributes the grayscale values evenly within a given grayscale range Use this method to increase the contrast in images containing few gr...

Page 27: ...size of the kernel and the CWIMAQKernel Element property to set the data in the kernel Nth Order Filter CWIMAQVision NthOrder allows you to define a lowpass or highpass filter depending on the value of N that you choose One specific Nth order filter the median filter removes speckle noise which appears as small black and white dots For more information about Nth order filters refer to Chapter 5 Im...

Page 28: ...edges are associated with mid to high spatial frequencies because they introduce significant gray level variations over short distances Gradually varying patterns are associated with low spatial frequencies An image can have extraneous noise such as periodic stripes introduced during the digitization process In the frequency domain the periodic pattern is reduced to a limited set of high spatial f...

Page 29: ...ty of the image in the spatial domain Highpass attenuation The amount of attenuation is inversely proportional to the frequency information At high frequencies there is little attenuation As the frequencies decrease the attenuation increases The zero frequency component is removed entirely Lowpass truncation Specify a frequency The frequency components above the ideal cutoff frequency are removed ...

Page 30: ...ng a color component with a reference Figure 3 1 illustrates the basic steps involved in making grayscale and color measurements Figure 3 1 Steps to Taking Grayscale and Color Measurements Define Regions of Interest An ROI is an area of an image in which you want to focus the image analysis You can define an ROI interactively programmatically or with an image mask Defining Regions Interactively Yo...

Page 31: ...Draw a rectangle or square in the image Action Click one corner and drag to the opposite corner Rotated Rectangle Draw a rotated rectangle in the image Action Click one corner and drag to the opposite corner to create the rectangle Then click on the lines inside the rectangle and drag to adjust the rotation angle Oval Draw an oval or circle in the image Action Click the center position and drag to...

Page 32: ...about the characteristics of ROIs you draw as shown in Figure 3 2 Check the Show Tool Info check box on the Status Bar property page during design time or set the CWIMAQViewer ShowToolInfo property to True during run time to display tool information You also can show or hide the tool information from the right click menu Polygon Draw a polygon in the image Action Click to place a new vertex and do...

Page 33: ... Tools Information 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 5 Pixel Intensity 6 Coordinates of the Mouse 7 Size of an Active Region of Interest 8 Length and Horizontal Angle of a Line Region 1 2 3 4 5 7 8 6 ...

Page 34: ...s to the regions Use the CWIMAQRegions CopyTo method to copy all the data from one CWIMAQRegions object to another You can define the regions on a viewer and access the regions using the CWIMAQViewer Regions property 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 property to determine...

Page 35: ...rocessed If a pixel in the image mask has a value other than 0 the corresponding pixel in the source image is processed If a pixel in the image mask has a value of 0 the corresponding pixel in the source image is left unchanged You can use a mask to define particles in a grayscale image when you need to make intensity measurements on those particles First threshold the image to make a new binary i...

Page 36: ... mask Use CWIMAQVision Centroid2 to compute the energy center of the image or of a region within an image Measure Color Statistics Most image processing and analysis methods apply to 8 bit and 16 bit images However you can analyze and process individual components of a color image Using CWIMAQVision ExtractColorPlanes you can break down a color image into various sets of primary components such as...

Page 37: ...ert a pixel value represented in any color model into its components in any other color model using CWIMAQVision ColorValueConversion2 32 Color Image 8 bit Image Processing Saturation Value Hue Green Blue Red Saturation Intensity Hue Saturation Luminance Hue 32 Color Image Saturation Value Hue Green Blue Red Saturation Intensity Hue Saturation Luminance Hue 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ...

Page 38: ...ormation that you learned Refer to Chapter 14 Color Inspection of the IMAQ Vision Concepts Manual for more information Use the CWIMAQColorInformation object to represent the learned color information for all subsequent matching operations 3 Define an entire image a region or multiple regions in an image as the inspection or comparison area 4 Use CWIMAQVision MatchColor to compare the learned color...

Page 39: ...cceptable region containing background colors Figure 3 5 Template Color Information The following sections specify when to learn the color information associated with an entire image a region in an image or multiple regions in an image Using the Entire Image You can use an entire image to learn the color spectrum that represents the entire color distribution of the image In a fabric identification...

Page 40: ...ns Figure 3 8 shows how light reflects differently off of the 3D surfaces of the fuses resulting in slightly different colors for identical fuses To view the color differences compare the 3 amp fuse in the upper row with the 3 amp fuse in the lower row If you learn the color spectrum by drawing a region of interest around the 3 amp fuse in the upper row and then do a color matching for the 3 amp f...

Page 41: ...en you learn a color you need to specify the granularity required to specify the color information An image that contains a few well separated colors in the color space requires a lower granularity to describe the color than an image that contains colors that are close to one another in the color space Use the ColorSensitivity parameter of CWIMAQVision LearnColor to specify the granularity you wan...

Page 42: ... second to last component in the color spectrum array to 1 ignores the color black To ignore other color components in color matching determine the index to the color spectrum by locating the corresponding bins in the color wheel where each bin corresponds to a component in the color spectrum array Ignoring certain colors such as the background color results in a more accurate color matching score...

Page 43: ...teps involved in performing particle analysis Figure 4 1 Steps for Performing Particle Analysis Create a Binary Image Threshold the grayscale or color image to create a binary image Creating a binary image separates the objects that you want to inspect from the background The threshold operation sets the background pixels to 0 in the binary image while setting the object pixels to a non zero value...

Page 44: ... and Luminance The binary image resulting from a color threshold is an 8 bit binary image Improve the Binary Image After you threshold the image you may want to improve the resulting binary image with binary morphology You can use primary binary morphology or advanced binary morphology to remove unwanted particles separate connected particles or improve the shape of particles Primary morphology me...

Page 45: ...ht angles along the edges of particles and other user specified shapes For more information about structuring elements refer to Chapter 9 Binary Morphology of the IMAQ Vision Concepts Manual If you know enough about the shape features of the particles you want to keep use CWIMAQVision ParticleFilter2 to filter out particles that do not interest you If you do not have enough information about the p...

Page 46: ...the location of particles and their shape features Use the following methods to perform particle measurements CWIMAQVision ParticleReport This method returns a CWIMAQParticleReport object which contains for each particle nine of the most commonly used measurements including the particle area bounding rectangle and center of mass The bounding rectangle is returned as one measurement but contains fo...

Page 47: ...ementBoundingRectRight X coordinate of the rightmost particle point cwimaqMeasurementBoundingRectTop Y coordinate of highest particle point cwimaqMeasurementBoundingRectWidth Distance between the X coordinate of the leftmost particle point and the X coordinate of the rightmost particle point cwimaqMeasurementCenterMassX X coordinate of the point representing the average position of the total parti...

Page 48: ...length to the Max Feret Diameter cwimaqMeasurementEquivalentRectDiagonal Distance between opposite corners of the rectangle with the same perimeter and area as the particle cwimaqMeasurementEquivalentRectLongSide Longest side of the rectangle with the same perimeter and area as the particle cwimaqMeasurementEquivalentRectShortSide Shortest side of the rectangle with the same perimeter and area as ...

Page 49: ...by the particle perimeter cwimaqMeasurementImageArea Area of the image cwimaqMeasurementMaxFeretDiameter Distance between the start and end of the line segment connecting the two perimeter points that are the furthest apart cwimaqMeasurementMaxFeretDiameterEndX X coordinate of the end of the line segment connecting the two perimeter points that are the furthest apart cwimaqMeasurementMaxFeretDiame...

Page 50: ...surementMomentOfInertiaXXX The moment of inertia in the X direction three times cwimaqMeasurementMomentOfInertiaXXY The moment of inertia in the X direction twice and the Y direction once cwimaqMeasurementMomentOfInertiaXY The moment of inertia in the X and Y directions cwimaqMeasurementMomentOfInertiaXYY The moment of inertia in the X direction once and the Y direction twice cwimaqMeasurementMome...

Page 51: ...erOfVertSegments Number of vertical segments in the particle cwimaqMeasurementOrientation The angle of the line that passes through the particle Center of Mass about which the particle has the lowest moment of inertia cwimaqMeasurementParticleAndHolesArea Percentage of the particle Area in relation to its Particle Holes Area cwimaqMeasurementPerimeter Sum of the perimeters of each hole in the part...

Page 52: ...um of all X coordinates times Y coordinates squared in the particle cwimaqMeasurementSumY The sum of all Y coordinates in the particle cwimaqMeasurementSumYY The sum of all Y coordinates squared in the particle cwimaqMeasurementSumYYY The sum of all Y coordinates cubed in the particle cwimaqMeasurementTypesFactor Factor relating area to moment of inertia cwimaqMeasurementWaddelDiskDiameter Diamete...

Page 53: ...ted in the image They locate with high accuracy the position of the edge of an object in the image For example you can a technique called clamping which uses the edge location to measure the width of the part You can combine multiple edge locations to compute intersection points projections circles or ellipse fits Pattern matching algorithms use edges and patterns Pattern matching can locate with ...

Page 54: ...his chapter for information about selecting a region of interest Often the object under inspection appears rotated or shifted in the image you need to process with respect to the reference image in which you located the object When this occurs the ROIs must shift and rotate with the parts of the object in which you are interested For the ROIs to move with the object you must define a reference coo...

Page 55: ...adjust the regions of inspection automatically You also can use these outputs to move the regions of inspection relative to the object programmatically Using Edge Detection to Build a Coordinate Transformation You can build a coordinate transformation using two edge detection techniques UseCWMachineVision FindCoordTransformUsingRect to define a reference coordinate system using one rectangular reg...

Page 56: ...oordTransformUsingTwoRects specify two rectangular ROIs each containing one separate straight boundary of the object as shown in Figure 5 3 The boundaries cannot be parallel The regions must be large enough to include the boundaries in all of the images you want to inspect 1 Search Area for the Coordinate System 2 Object Edges 3 Origin of the Coordinate System 4 Measurement Area 1 4 1 4 a b 2 3 3 ...

Page 57: ...ation in subsequent images set this parameter to False Using Pattern Matching to Build a Coordinate Transformation You can build a coordinate transformation using pattern matching Use CWMachineVision FindCoordTransformUsingPattern to define a reference coordinate system based on the location of a reference feature Use this technique when the object under inspection does not have straight distinct ...

Page 58: ... search area in which you expect to find the template 3 Set the MatchMode property of the CWMVFindCTUsingPatternOptions object to cwimaqRotationInvariant when you expect the template to appear rotated in the inspection images Otherwise set it to cwimaqShiftInvariant 4 Choose the results you want to overlay onto the image 5 Choose the mode for the method To build a transformation for the first time...

Page 59: ...nspection has a straight distinct edge main axis The object contains a second distinct edge not parallel to the main axis in a separate search area The object contains a second distinct edge not parallel to the main axis in the same search area Build a coordinate transformation based on edge detection using two distinct search areas Build a coordinate transformation based on edge detection using a...

Page 60: ...I on the image Resize or reposition the ROI until it defines the area of the image you want to process 3 Use CWMachineVision GetSelected shapename FromViewer to programmatically retrieve the shape from the viewer You also can use the techniques described in Chapter 3 Making Grayscale and Color Measurements to select an ROI Table 5 1 indicates which ROI selection methods to use with a given CWMachi...

Page 61: ...an specify a line by setting the coordinates of the start and end points Refer to Chapter 3 Making Grayscale and Color Measurements for more information about defining regions of interest Find Measurement Points After you set regions of inspection locate points in the regions on which you can base measurements You can locate measurement points using edge detection pattern matching color pattern ma...

Page 62: ...dConcentricEdge CWMachineVision FindStraightEdge finds edges based on rectangular search areas as shown in Figure 5 5 CWMachineVision FindConcentricEdge finds edges based on annular search areas Figure 5 5 Finding a Straight Feature If you want to find points along a circular edge and find the circle that best fits the edge as shown in Figure 5 6 use CWMachineVision FindCircularEdge 1 Search Regio...

Page 63: ... SimpleEdge and CWIMAQVision FindEdges2 to find edge points along a contour You can find the first edge last edge or all edges along the contour Use CWIMAQVision SimpleEdge when the image contains little noise and the object and background are clearly differentiated Otherwise use CWIMAQVision FindEdges2 These methods require you to input the coordinates of the points along the search contour Use C...

Page 64: ...a Control the number of lines in the region by specifying the angle in degrees between each line Specify the search direction as either going from the center outward or from the outer boundary to the center CWIMAQVision ConcentricRake works on an annular search region The concentric rake is an adaptation of the rake to an annular region Edge detection is performed along search lines that occur in ...

Page 65: ...selection of a effective template image plays a critical part in obtaining good results Because the template image represents 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 Several factors are critical in creating a template image These critical factors include symmetry feature detail positional information...

Page 66: ...ation than a model with fine features However the model must contain enough detail to identify it Figure 5 8 Feature Detail Positional Information A template with strong edges in both the x and y directions is easier to locate Figure 5 9 Positional Information a Good Feature Detail b Ambiguous Feature Detail a Good Positional Information in x and y b Insufficient Positional Information in y a b a ...

Page 67: ...match the template at any orientation the learning mode must consider the possibility of arbitrary orientations To specify which type of learning mode to use pass the learn mode to the LearnPatternOptions parameter of CWIMAQVision LearnPattern2 You also can set the LearnMode property of a CWIMAQLearnPatternOptions object and pass this object for the LearnPatternOptions parameter of CWIMAQVision Le...

Page 68: ...creasing the template size you can reduce the required search time In many inspection applications you have general information about the location of the fiducial Use this information to define a search area For example in a typical component placement application each printed circuit board PCB being tested may not be placed in the same location with the same orientation The location of the PCB in...

Page 69: ... are not optimal To efficiently select the best pattern matching parameters for the application you must have a clear understanding of the application and the images you want to process The following sections discuss parameters that influence the IMAQ Vision pattern matching algorithm Match Mode You can set the match mode to control how the pattern matching algorithm handles the template at differ...

Page 70: ... Use CWIMAQMatchPatternOptions MinimumContrast to set the minimum contrast Rotation Angle Ranges If you know that the pattern rotation is restricted to a certain range such as between 15 to 15 provide this restriction information to the pattern matching algorithm in the CWIMAQMatchPatternOptions RotationAngleRanges property This information improves your search time because the pattern matching al...

Page 71: ...Color pattern matching algorithms provide a quick way to locate objects when color is present Use color pattern matching under the following circumstances 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 The object to locate has grayscale properties that are very difficult to chara...

Page 72: ...he pattern are well defined in the image Several factors are critical in creating a template image These critical factors include color information symmetry feature detail positional information and background information Color Information A template with colors that are unique to the pattern provides better results than a template that contains many colors especially colors found in the backgroun...

Page 73: ...pe of matching that you expect to perform By default the color pattern matching algorithm learns only those features from the template that are necessary for shift invariant matching However if you want to match the template at any orientation the learning process must consider the possibility of arbitrary orientations Use the CWIMAQLearnColorPatternOptions LearnMode property to specify which type...

Page 74: ...e incorrect results To avoid this reduce the search area so that only the appropriate pattern lies within the search area For example in the fuse box inspection example use the location of the fuses to be inspected to define the search area Because the inspected fuse box may not be in the exact location or have the same orientation in the image as the previous one the search area you define should...

Page 75: ...u want to process The following sections discuss parameters of the IMAQ Vision color pattern matching algorithm and how they influence the algorithm Color Sensitivity Use the color sensitivity to control the granularity of the color information in the template image If the background and objects in the image contain colors that are very close to colors in the template image use a higher color sens...

Page 76: ...most reliable method to look for a template in any image at potentially reduced speed Note Use the conservative strategy if you have multiple targets located very close to each other in the image Decide on the best strategy by experimenting with the different options Use CWIMAQMatchColorPatternOptions SearchStrategy to select a search strategy Color Score Weight When you search for a template usin...

Page 77: ...to Chapter 12 Pattern Matching in the IMAQ Vision Concepts Manual for more information about pattern matching Testing the Search Algorithm on Test Images To determine if the selected template or reference pattern is appropriate for the machine vision application test the template on a few test images by using the CWIMAQVision MatchColorPattern method These test images should reflect the images gen...

Page 78: ...WIMAQMatchColorPatternOptions 6 Use CWIMAQVision MatchColorPattern to test the color location algorithm on test images 7 Verify the results using a ranking method Use CWIMAQVision WriteImageAndVisionInfo to save the template 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 m...

Page 79: ...in a rectangular search region Use CWIMAQVision FindPointDistances to compute the distances between consecutive pairs of points in an array of points You can obtain these points from the image using any one of the feature detection methods described in the Find Measurement Points section of this chapter Analytic Geometry Measurements Use the following CWIMAQVision methods to make geometrical measu...

Page 80: ...AQVision ReadMeter to read the position of the needle using the CWIMAQMeterArc object Use CWIMAQVision FindLCDSegments to calculate the regions of interest around each digit in an LCD or LED To find the area of each digit all the segments of the indicator must be activated Use CWIMAQVision ReadLCD to read the digits of an LCD or LED Identify Parts Under Inspection In addition to making measurement...

Page 81: ... text and or characters in an image you must create a character set file with samples of the characters using the OCR Training Interface Go to Start Programs National Instruments Vision OCR Training to launch the OCR Training Interface After you have trained samples of the characters you want to read use the following methods to read the characters Use NIOCR ReadOCRFile to read in a character set ...

Page 82: ...nly one barcode per image set CWIMAQDataMatrixOptions SearchMode to cwimaqBarcode2DSearchSingleConservative to increase the speed of the method By default CWIMAQVision ReadDataMatrixBarcode determines if the barcode has black cells on a white background or white cells on a black background Note Specify round cells only if the Data Matrix cells are round and have clearly defined edges If the cells ...

Page 83: ...Mode parameter to cwimaqBarcode2DSearchSingleConservative to increase the speed of the method Display Results You can display the results obtained at various stages of the inspection process on the window that displays the inspection image by overlaying information about an image The software attaches the information that you want to overlay to the image but it does not modify the image Access ove...

Page 84: ...figure the following CWMachineVision methods to overlay different types of information about the inspection image FindStraightEdge FindCircularEdge FindConcentricEdge MeasureMaximumDistance MeasureMinimumDistance FindPattern CountAndMeasureObjects FindCoordTransformUsingRect FindCoordTransformUsingTwoRects FindCoordTransformUsingPattern You can overlay the following information with all the above ...

Page 85: ...lt Use CWIMAQOverlay Clear to clear any previous overlay information from the image Use CWIMAQVision WriteImageAndVisionInfo to save an image with its overlay information to a file You can read the information from the file into an image using the CWIMAQVision ReadImageAndVisionInfo Note As with calibration information overlay information is removed from an image when the image size or orientation...

Page 86: ...ration to calibrate the system Perspective and Nonlinear Distortion Calibration Perspective errors and lens aberrations cause images to appear distorted This distortion misplaces information in an image but it does not necessarily destroy the information in the image Calibrate the imaging system if you need to compensate for perspective errors or nonlinear lens distortion Follow these general step...

Page 87: ...splacement in the x and y directions must equal dx dy The dots must cover the appropriate portion of the working area The radius of the dots must be 6 10 pixels The center to center distance between dots must range from 18 to 32 pixels as shown in Figure 6 1 The minimum distance between the edges of the dots must be 6 pixels as shown in Figure 6 1 Figure 6 1 Defining a Calibration Grid Note You ca...

Page 88: ...n of the horizontal axis in the real world The vertical axis direction can either be indirect as shown in Figure 6 2a or direct as shown in Figure 6 2b Figure 6 2 Axis Direction in the Image Plane If you do not specify a coordinate system the calibration process defines a default coordinate system If you specify a grid for the calibration process the software defines the following default coordina...

Page 89: ...sOrientation cwimaqAxisOrientationIndirect If you define a coordinate system yourself carefully consider the requirements of the application Express the origin in pixels Always choose an origin location that lies within the calibration grid so that you can convert the location to real world units Specify the angle as the angle between the x axis of the new coordinate system x and the top row of do...

Page 90: ...etting Measurement Ready Images The grid does not need to occupy the entire image You can choose a region within the image that contains the grid After you acquire an image of the grid learn the calibration information by inputting the image of the grid into CWIMAQVision LearnCalibrationGrid Note If you want to specify a list of points instead of a grid use CWIMAQVision LearnCalibrationPoints to l...

Page 91: ...bration options selected Pass a CWIMAQRegions collection representing the region you want to learn to the Regions parameter of CWIMAQVision LearnCalibrationGrid or CWIMAQVision LearnCalibrationPoints Note The user defined ROI represents the area in which you are interested The learning ROI is separate from the calibration ROI that is generated by the calibration algorithm Refer to Figure 6 6 for a...

Page 92: ...aging setup exhibits nonlinear distortion use the nonlinear method The nonlinear method guarantees accurate results only in the area that the calibration grid covers as shown in Figure 6 6 If the system exhibits both perspective and nonlinear distortion use the nonlinear method to correct for both Set CWIMAQLearnCalibrationOptions CalibrationMethod to cwimaqNonLinearCalibration to chose the nonlin...

Page 93: ... real world coordinate The transformation accuracy may be higher than the value the error range indicates Set CWIMAQLearnCalibrationOptions LearnErrorMap to True to learn the error map Learning the Correction Table If the speed of image correction is a critical factor for the application use a correction table The correction table is a lookup table that contains the real world location information...

Page 94: ...id The software rotates and scales a pixel coordinate according to predefined coordinate reference and scaling factors You can assign the calibration to an arbitrary image using CWIMAQVision SetSimpleCalibration To perform a simple calibration set a coordinate system angle center and axis direction and scaling factors on the defined axis as shown in Figure 6 7 Express the angle between the x axis ...

Page 95: ...rmation you read from another image refer to the Attach Calibration Information section Attach Calibration Information When you finish calibrating the setup you can apply the calibration settings to images that you acquire Use CWIMAQVision SetCalibrationInformation to attach the calibration information of the current setup to each image you acquire This method takes in a source image containing th...

Page 96: ...mage is different from a corrected image Note Because calibration information is part of the image it is propagated throughout the processing and analysis of the image Methods that modify the image size such as an image rotation method void the calibration information Use CWIMAQVision WriteImageAndVisionInfo to save the image and all of the attached calibration information to a file If you modify ...

Page 97: ...per Exchange at ni com exchange National Instruments Application Engineers make sure every question receives an answer Training and Certification Visit ni com training for self paced training eLearning virtual classrooms interactive CDs and Certification program information You also can register for instructor led hands on courses at locations around the world System Integration If you have time c...

Page 98: ...ion about a color image The alpha channel is stored as the first byte in the four byte representation of an RGB pixel area 1 A rectangular portion of an acquisition window or frame that is controlled and defined by software 2 The size of an object in pixels or user defined units arithmetic operators The image operations multiply divide add subtract and modulo array An ordered indexed set of data e...

Page 99: ...xel can take 2n different values For example if n equals 8 a pixel can take 256 different values ranging from 0 to 255 If n equals 16 a pixel can take 65 536 different values ranging from 0 to 65 535 or 32 768 to 32 767 blurring Reduces the amount of detail in an image Blurring commonly occurs because the camera is out of focus You can blur an image intentionally by applying a lowpass frequency fi...

Page 100: ...lor closing A dilation followed by an erosion A closing fills small holes in objects and smooths the boundaries of objects clustering A technique where the image is sorted within a discrete number of classes corresponding to the number of phases perceived in an image The gray values and a barycenter are determined for each class This process is repeated until a value is obtained that represents th...

Page 101: ...lse response of the filter that they represent D Danielsson function Similar to the distance functions but with more accurate results determinism A characteristic of a system that describes how consistently it can respond to external events or perform operations within a given time limit digital image An image f x y that has been converted into a discrete number of pixels Both spatial coordinates ...

Page 102: ...ontrast in dark regions of an image F FFT Fast Fourier Transform A method used to compute the Fourier transform of an image fiducial A reference pattern on a part that helps a machine vision application find the part s location and orientation in an image Fourier transform Transforms an image from the spatial domain to the frequency domain frequency filters The counterparts of spatial filters in t...

Page 103: ...tensity variations in an image detects edges or object boundaries and enhances fine details in an image highpass frequency filter Removes or attenuates low frequencies present in the frequency domain of the image A highpass frequency filter suppresses information related to slow variations of light intensities in the spatial image highpass truncation The inverse of lowpass truncation histogram Ind...

Page 104: ...tz Frequency in units of 1 second I I O Input output The transfer of data to from a computer system involving communications channels operator interface devices and or data acquisition and control interfaces image A two dimensional light intensity function f x y where x and y denote spatial coordinates and the value f at any point x y is proportional to the brightness at that point image border A ...

Page 105: ...mage processing Encompasses various processes and analysis functions that you can apply to an image image source The original input image imaging Any process of acquiring and displaying images and analyzing image data IMAQ Image Acquisition inner gradient Finds the inner boundary of objects inspection The process by which parts are tested for simple defects such as missing parts or cracks on part ...

Page 106: ...ext JPEG Joint Photographic Experts Group An image file format for storing 8 bit and color images with lossy compression JPEG images have the file extension JPG K kernel A structure that represents a pixel and its relationship to its neighbors The relationship is specified by weighted coefficients of each neighbor L labeling A morphology operation that identifies each object in a binary image and ...

Page 107: ...west frequency and full attenuation at the highest frequency lowpass FFT filter Removes or attenuates high frequencies present in the FFT domain of an image lowpass filter Attenuates intensity variations in an image You can use these filters to smooth an image by eliminating fine details and blurring edges lowpass frequency filter Attenuates high frequencies present in the frequency domain of the ...

Page 108: ...his filter effectively removes isolated pixels without blurring the contours of objects memory buffer See buffer MMX Multimedia Extensions An Intel chip based technology that allows parallel operations on integers which results in accelerated processing of 8 bit images morphological transformations Extract and alter the structure of objects in an image You can use these transformations for expandi...

Page 109: ...processed The pixel being processed is set to the Nth pixel value where N is the order of the filter number of planes in an image The number of arrays of pixels that compose the image A gray level or pseudo color image is composed of one plane while an RGB image is composed of three planes one for the red component one for the blue and one for the green O OCR Optical Character Recognition The abil...

Page 110: ...gital image Also called pixel pixel Picture element The smallest division that makes up the video scan line For display on a computer monitor a pixel s optimum dimension is square aspect ratio of 1 1 or the width equal to the height pixel aspect ratio The ratio between the physical horizontal size and the vertical size of the region covered by the pixel An acquired pixel should optimally be square...

Page 111: ... at a later time resolution The number of rows and columns of pixels An image composed of m rows and n columns has a resolution of reverse function Inverts the pixel values in an image producing a photometric negative of the image RGB A color encoding scheme using red green and blue RGB color information where each pixel in the color image is encoded using 32 bits 8 bits for red 8 bits for green 8...

Page 112: ...of white added to a pure color Saturation relates to the richness of a color A saturation of zero corresponds to a pure color with no white added Pink is a red with low saturation scale invariant matching A pattern matching technique in which the reference pattern can be any size in the test image segmentation function Fully partitions a labeled binary image into non overlapping segments with each...

Page 113: ...rdinates in terms of fractions of a pixel T template A color shape or pattern that you are trying to match in an image using the color matching shape matching or pattern matching functions A template can be a region selected from an image or it can be an entire image threshold Separates objects from the background by assigning all pixels with intensities within a specified range to the object and ...

Page 114: ...onal Instruments Corporation G 17 IMAQ Vision for Visual Basic User Manual V value The grayscale intensity of a color pixel computed as the average of the maximum and minimum red green and blue values of that pixel ...

Page 115: ...odes 5 30 reading PDF417 barcodes 5 31 binary images improving 4 2 Broken Line tool 3 2 building coordinate transformation with edge detection 5 3 coordinate transformation with pattern matching 5 5 building coordinate transformations 5 7 choosing a method 5 7 C calibrating images 2 2 6 1 calibration nonlinear 6 1 perspective 6 1 voiding 6 9 calibration information 6 5 attaching to images 2 7 6 10...

Page 116: ...ncy domain 2 11 pixel coordinates to real world coordinates 5 26 convolution filter 2 10 coordinate systems reference 6 3 coordinate transformation building with edge detection 5 3 building with pattern matching 5 5 correction tables learning 6 8 creating binary images 4 1 4 2 images 2 2 IMAQ Vision applications 1 5 template images 5 13 CWIMAQ control 1 3 cwimaq ocx 1 3 CWIMAQViewer control 1 3 CW...

Page 117: ...es 5 10 measurement points 5 9 points along the edge of a circle 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 Freeline tool 3 3 G geometrical measurements 5 27 granularity specifying requirements for learning a color 3 12 using color sensitivity to control 5 23 grayscale features filtering 2 10 grayscale morph...

Page 118: ...fying a learning algorithm 6 6 specifying a region of interest 6 6 specifying scaling factors 6 6 using learning scores 6 7 voiding calibrations 6 9 learning score using 6 7 light intensity measuring 3 6 lighting effects on image colors 3 11 Line tool 3 2 lines finding 5 10 locating objects to detect 5 2 lowpass attenuation 2 12 filter 2 9 LUTs 2 9 highlighting details in images 2 9 M machine visi...

Page 119: ...rspective calibration 6 1 pixel coordinates converting to real world coordinates 5 26 Point tool 3 2 points finding along one search contour 5 11 finding along the edge of a circle 5 10 finding measurement points 5 9 finding with color location 5 25 finding with color pattern matching 5 19 finding with pattern matching 5 12 Polygon tool 3 3 programmatically defining regions 5 9 regions of interest...

Page 120: ... 17 5 23 rotation angle ranges for pattern matching 5 18 5 25 scaling mode 6 8 search areas 5 8 setting up measurement systems 2 1 shape scores 5 24 signal to noise ratio 2 9 simple calibration 6 9 software NI resources A 1 specifying color information 3 10 granularity to learn a color 3 12 learning algorithm 6 6 region of interest 6 6 scaling factors 6 6 specifying scaling factors learning calibr...

Page 121: ...characters 5 29 color pattern matching algorithms 5 21 pattern matching algorithm 5 15 training and certification NI resources A 1 troubleshooting NI resources A 1 U using learning scores 6 7 ranking to verify pattern matching results 5 19 V viewing color differences in an image using multiple regions 3 11 Vision for Visual Basic organization 1 2 voiding calibrations 6 9 W Web resources A 1 Z Zoom...

Reviews: