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.
The media on which you receive National Instruments software are warranted not to fail to execute programming instructions, due to defects
in materials and workmanship, for a period of 90 days from date of shipment, as evidenced by receipts or other documentation. National
Instruments will, at its option, repair or replace software media that do not execute programming instructions if National Instruments receives
notice of such defects during the warranty period. National Instruments does not warrant that the operation of the software shall be
uninterrupted or error free.
A Return Material Authorization (RMA) number must be obtained from the factory and clearly marked on the outside of the package before
any equipment will be accepted for warranty work. National Instruments will pay the shipping costs of returning to the owner parts which are
covered by warranty.
National Instruments believes that the information in this document is accurate. The document has been carefully reviewed for technical
accuracy. In the event that technical or typographical errors exist, National Instruments reserves the right to make changes to subsequent
editions of this document without prior notice to holders of this edition. 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.
E
XCEPTASSPECIFIEDHEREIN, NATIONAL INSTRUMENTSMAKESNOWARRANTIES, EXPRESSORIMPLIED, ANDSPECIFICALLYDISCLAIMSANYWAR RANTYOF
MERCHANTABILITYORFITNESSFORAPARTICULARPURPOSE . CUSTOMER’SRIGHTTORECOVERDAMAGESCAUSEDBYFAULTORNEGLIGENCEONTHEPART OF
N
ATIONAL INSTRUMENTSSHALLBELIMITEDTOTHEAMOUNTTHERETOFOREPAIDBYTHECUSTOMER. NATIONAL INSTRUMENTSWILLNOTBELIABLEFOR
DAMAGESRESULTINGFROMLOSSOFDATA, PROFITS, USEOFPRODUCTS, ORINCIDENTALORCONSEQUENTIALDAMAGES, EVENIFADVISEDOFTHEPOSS IBILITY
THEREOF. This limitation of the liability of National Instruments will apply regardless of the form of action, whether in contract or tort, including
negligence. Any action against National Instruments must be brought within one year after the cause of action accrues. National Instruments
shall not be liable for any delay in performance due to causes beyond its reasonable control. The warranty provided herein does not cover
damages, defects, malfunctions, or service failures caused by owner’s failure to follow the National Instruments installation, operation, or
maintenance instructions; owner’s modification of the product; owner’s abuse, misuse, or negligent acts; and power failure or surges, fire,
flood, accident, actions of third parties, or other events outside 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 Alliance Partner™, NI™, ni.com™, NI Developer Zone™, and
™
NI-IMAQ
Product and company names mentioned herein are trademarks or trade names of their respective companies.
Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have no
agency, partnership, or joint-venture relationship with National Instruments.
are trademarks of National Instruments Corporation.
WARNING REGARDING USE OF NATIONAL INSTRUMENTS PRODUCTS
(1) NATIONAL INSTRUMENTS PRODUCTS ARE NOT DESIGNED WITH COMPONENTS AND TESTING FOR A LEVEL OF
RELIABILITY SUITABLE FOR USE IN OR IN CONNECTION WITH SURGICAL IMPLANTS OR AS CRITICAL COMPONENTS IN
ANY LIFE SUPPORT SYSTEMS WHOSE FAILURE TO PERFORM CAN REASONABLY BE EXPECTED TO CAUSE SIGNIFICANT
INJURY TO A HUMAN.
(2) IN ANY APPLICATION, INCLUDING THE ABOVE, RELIABILITY OF OPERATION OF THE SOFTWARE PRODUCTS CAN BE
IMPAIRED BY ADVERSE FACTORS, INCLUDING BUT NOT LIMITED TO FLUCTUATIONS IN ELECTRICAL POWER SUPPLY,
COMPUTER HARDWARE MALFUNCTIONS, COMPUTER OPERATING SYSTEM SOFTWARE FITNESS, FITNESS OF COMPILERS
AND DEVELOPMENT SOFTWARE USED TO DEVELOP AN APPLICATION, INSTALLATION ERRORS, SOFTWARE AND
HARDWARE COMPATIBILITY PROBLEMS, MALFUNCTIONS OR FAILURES OF ELECTRONIC MONITORING OR CONTROL
DEVICES, TRANSIENT FAILURES OF ELECTRONIC SYSTEMS (HARDWARE AND/OR SOFTWARE), UNANTICIPATED USES OR
MISUSES, OR ERRORS ON THE PART OF THE USER OR APPLICATIONS DESIGNER (ADVERSE FACTORS SUCH AS THESE ARE
HEREAFTER COLLECTIVELY TERMED “SYSTEM FAILURES”). ANY APPLICATION WHERE A SYSTEM FAILURE WOULD
CREATE A RISK OF HARM TO PROPERTY OR PERSONS (INCLUDING THE RISK OF BODILY INJURY AND DEATH) SHOULD
NOT BE RELIANT SOLELY UPON ONE FORM OF ELECTRONIC SYSTEM DUE TO THE RISK OF SYSTEM FAILURE. TO AVOID
DAMAGE, INJURY, OR DEATH, THE USER OR APPLICATION DESIGNER MUST TAKE REASONABLY PRUDENT STEPS TO
PROTECT AGAINST SYSTEM FAILURES, INCLUDING BUT NOT LIMITED TO BACK-UP OR SHUT DOWN MECHANISMS.
BECAUSE EACH END-USER SYSTEM IS CUSTOMIZED AND DIFFERS FROM NATIONAL INSTRUMENTS' TESTING
PLATFORMS AND BECAUSE A USER OR APPLICATION DESIGNER MAY USE NATIONAL INSTRUMENTS PRODUCTS IN
COMBINATION WITH OTHER PRODUCTS IN A MANNER NOT EVALUATED OR CONTEMPLATED BY NATIONAL
INSTRUMENTS, THE USER OR APPLICATION DESIGNER IS ULTIMATELY RESPONSIBLE FOR VERIFYING AND VALIDATING
THE SUITABILITY OF NATIONAL INSTRUMENTS PRODUCTS WHENEVER NATIONAL INSTRUMENTS PRODUCTS ARE
INCORPORATED IN A SYSTEM OR APPLICATION, INCLUDING, WITHOUT LIMITATION, THE APPROPRIATE DESIGN,
PROCESS AND SAFETY LEVEL OF SUCH SYSTEM OR APPLICATION.
Save Calibration Information ........................................................................................ 6-10
Attach Calibration Information ..................................................................................... 6-10
Appendix A
Technical Support and Professional Services
Glossary
Index
IMAQ Vision for Visual Basic User Manualviiini.com
About This Manual
The IMAQ Vision for Visual Basic User Manual is intended for engineers
and scientists who have knowledge of Microsoft Visual Basic and need to
create machine vision and image processing applications using Visual
Basic objects. The manual guides you through tasks beginning with setting
up the imaging system to taking measurements.
Conventions
The following conventions appear in this manual:
»The » symbol leads you through nested menu items and dialog box options
to a final action. The sequence File»Page Setup»Options directs you to
pull down the File menu, select the Page 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.
boldBold 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.
italicItalic text denotes variables, emphasis, a cross reference, or an introduction
to a key concept. This font also denotes text that is a placeholder for a word
or value that you must supply.
monospaceText in this font denotes text or characters that you should enter from the
keyboard, sections of code, programming examples, and syntax examples.
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.
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:
•
msdn.microsoft.com
•Documentation that accompanies Microsoft Visual Studio
In addition to this manual, the following documentation resources are
available to help you create your vision application.
IMAQ Vision
•IMAQ Vision Concepts Manual—If you are new to machine vision
and imaging, read this manual to understand the concepts behind
IMAQ Vision.
•IMAQ Vision for Visual Basic Reference—If you need information
about 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
•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 use any of the functions or features of NI Vision
Assistant, refer to this help file.
NI Vision Builder for Automated Inspection
•NI Vision Builder for Automated Inspection Tutorial—If you have
little experience with machine vision, and you need information about
how to solve common inspection tasks with NI Vision Builder AI,
follow the instructions in this tutorial.
•NI Vision Builder for Automated Inspection: Configuration Help—If you need descriptions or step-by-step guidance about how to
use any of the NI Vision Builder AI functions to create an automated
vision inspection system, refer to this help file.
IMAQ Vision for Visual Basic User Manualxni.com
•NI Vision Builder for Automated Inspection: Inspection Help—If you
Other Documentation
•NI OCR Training Interface Help—If you need information about the
•National Instruments IMAQ device user manual—If you need
•Getting Started With Your IMAQ System—If you need instructions for
•NI-IMAQ User Manual—If you need information about how to use
•NI-IMAQ VI or function reference guides—If you need information
•IMAQ Vision Deployment Engine Note to Users—If you need
•Example programs—If you want examples of how to create specific
•Application Notes—If you want to know more about advanced
•NI Developer Zone (NIDZ)—If you want even more information
About This Manual
need information about how to run an automated vision inspection
system using NI Vision Builder AI, refer to this help file.
OCR Training Interface, refer to this help file.
installation instructions and device-specific information, refer to your
device user manual.
installing the NI-IMAQ software and your IMAQ hardware,
connecting your camera, running Measurement & Automation
Explorer (MAX) and the NI-IMAQ Diagnostics, selecting a camera
file, and acquiring an image, refer to this getting started document.
NI-IMAQ and IMAQ image acquisition devices to capture images for
processing, refer to this manual.
about the features, functions, and operation of the NI-IMAQ image
acquisition VIs or functions, refer to these help files.
information about how to deploy your custom IMAQ Vision
applications on target computers, read this CD insert.
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.
IMAQ Vision concepts and applications, refer to the Application
Notes located on the National Instruments Web site at
appnotes.nsf
.
ni.com/
about developing your vision application, visit the NI Developer Zone
at
ni.com/zone. The NI Developer Zone contains example
programs, tutorials, technical presentations, the Instrument Driver
Network, a measurement glossary, an online magazine, a product
advisor, and a community area where you can share ideas, questions,
and source code with vision developers around the world.
This chapter describes the IMAQ Vision for Visual Basic software and
associated software products, discusses the documentation and examples
available, outlines the IMAQ Vision for Visual Basic architecture, and lists
the steps for creating a machine vision application.
Note For information about the system requirements and installation procedure for
IMAQ Vision for Visual Basic, refer to the Vision Development Module Release Notes that
came with the software.
About IMAQ Vision
IMAQ Vision for Visual Basic is a collection of ActiveX controls that you
can use to develop machine vision and scientific imaging applications. The
Vision Development Module also includes the same imaging functions for
LabWindows
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. Additionally, NI offers
Vision Builder for Automated Inspection: configurable machine vision
software that you can use to prototype, benchmark, and deploy
applications.
™
/CVI™ and other C development environments, as well as
1
Documentation and Examples
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:
•
msdn.microsoft.com
•Documentation that accompanies Microsoft Visual Studio
In addition to this manual, several documentation resources are available
to help you create a vision application:
•IMAQ Vision Concepts Manual—If you are new to machine vision
and imaging, read this manual to understand the concepts behind
IMAQ Vision.
•IMAQ Vision for Visual Basic Reference—If you need information
about individual methods, properties, or objects, refer to this help file.
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»Documentation. You need Adobe Acrobat Reader to open this file.
•Example programs—If you want examples of how to create specific
applications in Visual Basic, go to
want examples of how to create specific applications in Microsoft
Visual Basic .NET, go to
•CWMachineVision source code—If you want to refer to the source
code for the CWMachineVision control, go to
MSVB
•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)—For additional information about
developing a vision application, visit the NI Developer Zone at
ni.com/zone. The NI Developer Zone contains example programs,
tutorials, technical presentations, the Instrument Driver Network, a
measurement glossary, an online magazine, a product advisor, and a
community area where you can share ideas, questions, and source code
with vision developers around the world.
Vision\Examples\MSVB. If you
Vision\Examples\MSVB.NET.
Vision\Source\
.
ni.com/
.
IMAQ Vision for Visual Basic Organization
IMAQ Vision for Visual Basic consists of five ActiveX controls contained
in three files:
IMAQ Vision for Visual Basic User Manual1-2ni.com
cwimaq.ocx, cwmv.ocx, and niocr.ocx.
cwimaq.ocx
Note You must have the NI-IMAQ driver 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.
Chapter 1Introduction to IMAQ Vision
cwimaq.ocx contains the following three ActiveX controls and a
collection of ActiveX objects: CWIMAQ, CWIMAQVision, and
CWIMAQViewer. Refer to the ActiveX Objects section for information
about the ActiveX objects.
CWIMAQ Control
Use this control to configure and perform an acquisition from the IMAQ
device. The CWIMAQ control has property pages that allow you to modify
various parameters to configure the acquisition and gather information
about the IMAQ device. Most of the functionality available from the
property pages during design time is also available through the properties
of the CWIMAQ control during run-time. The control has methods that
allow you to perform and control acquisitions, as well.
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
processing algorithms on images.
CWIMAQViewer Control
Use this control to display images and provide the interface through which
the user will interact with the displayed image. This includes the ability to
zoom and pan images and to draw regions of interest (ROIs) on an image.
The CWIMAQViewer control has property pages that allow you to
configure the viewer’s appearance and behavior during design time as well
as properties that you can configure during run-time. The control has
methods that allow you to attach images to and detach images from the
viewer for display purposes.
Note The CWIMAQViewer control is referred to as a viewer in the remainder of this
niocr.ocx provides one ActiveX control and a collection of ActiveX
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:
•Training characters
•Reading characters
Training characters is the process by which you teach the machine vision
software the types of characters and/or patterns you want to read in the
image during the reading procedure. You can use IMAQ Vision to train any
number of characters, creating a character set, which is the set of characters
that you later compare with objects during the reading procedure. You store
the character set 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 vision application reads characters in
an image using the character set that you created when you trained
characters.
cwmv.ocx
cwmv.ocx contains one ActiveX control and a collection of ActiveX
objects. Refer to the ActiveX Objects section for more information about
ActiveX objects.
CWMachineVision control
Use this control to perform high-level machine vision tasks, such as
measuring distances. This control is written entirely in Visual Basic using
the methods on the CWIMAQVision and CWIMAQViewer controls. The
source code for the CWMachineVision control is included in the product.
For more information about CWMachineVision methods, refer to
Chapter 5, Performing Machine Vision Tasks.
IMAQ Vision for Visual Basic User Manual1-4ni.com
Tip Refer to the source code of the CWMachineVision control for an example of how to
use the CWIMAQVision methods.
ActiveX Objects
Note ActiveX objects in cwimaq.ocx have a CWIMAQ prefix, objects in niocr.ocx
have an NIOCR prefix, and objects in
If you intend to develop an application in Visual C++, National Instruments
Tip
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 CWIMAQImage object, use the
CWIMAQVision.CreateCWIMAQImage method.
Chapter 1Introduction to IMAQ Vision
Use the objects to group related input parameters and output parameters to
certain methods, thus reducing the number of parameters that you actually
need to pass to those methods.
cwmv.ocx have a CWMV prefix.
You must create an ActiveX object before you can use it. You can use the
New keyword in Visual Basic to create these objects. For example, use the
following syntax to create and store an image in a variable named
Dim image As New CWIMAQImage
image:
Creating IMAQ Vision Applications
Figures 1-1 and 1-2 illustrate the steps for creating an application with
IMAQ Vision. Figure 1-1 describes the general steps for designing a
Vision application. The last step in Figure 1-1 is expanded upon in
Figure 1-2. You can use a combination of the items in the last step to create
a IMAQ Vision application. For more information about items in either
diagram, refer to the corresponding chapter listed beside the item.
Note Diagram items enclosed with dashed lines are optional steps.
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
color and monochrome devices as well as digital devices. Visit
ni.com/imaq for more information about IMAQ devices.
4.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 &
Automation Explorer icon on the desktop. For more information, refer
to the NI-IMAQ User Manual and the Measurement & Automation Explorer Help for IMAQ.
Calibrate Your Imaging System
After you set up the imaging system, you may want to calibrate the system.
Calibrate the imaging system to assign real-world coordinates to pixel
coordinates and compensate for perspective and nonlinear 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.
Use simple calibration if you want only to assign real-world coordinates to
pixel coordinates. Use perspective and nonlinear distortion calibration if
you need to compensate for perspective errors and nonlinear lens distortion.
For detailed information about calibration, refer to Chapter 6, Calibrating
Images.
Create an Image
The CWIMAQImage object encapsulates all the information required to
represent an image.
Note CWIMAQImage is referred to as an image in the remainder of this document.
An image can be one of many types, depending on the data it stores.
The following image types are valid:
•8-bit
•16-bit
•Single-precision floating point
IMAQ Vision for Visual Basic User Manual2-2ni.com
Chapter 2Getting Measurement-Ready Images
•Complex
•32-bit RGB
•32-bit HSL
•64-bit RGB
When you create an image, it is an 8-bit image by default. You can set the
Type property on the image object to change the image type.
When you create an image, no memory is allocated to store the image
pixels. IMAQ Vision methods automatically allocate the appropriate
amount of memory when the image size is modified. For example, methods
that acquire or resample an image alter the image size, so they allocate the
appropriate memory space for the image pixels.
Most methods belonging to the IMAQ Vision library require an input of one
or more image objects. The number of images a method takes depends on
the image processing function and the type of image you want to use.
IMAQ Vision methods that analyze the image but do not modify the image
contents require the input of one 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 whose corresponding
pixels in the mask image are non-zero. If a mask image pixel is 0, the
corresponding source image pixel is not processed or analyzed. The mask
image must be an 8-bit image.
If you want to apply a processing or analysis method to the entire image,
do not supply the optional mask image. Using the same image for both the
source image and mask image also has the same effect as not using the
mask image, except in this case the source image must be an 8-bit image.
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.
After you create an image, you can acquire an image into the imaging
system in one of the following three ways:
•Acquire an image with a camera through the image acquisition device.
•Load an image from a file stored on the computer.
•Convert the data stored in a 2D array to an image.
Methods that acquire images, load images from file, or convert data
from a 2D array automatically allocate the memory space required to
accommodate the image data.
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. 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
cwimaqAcquisitionOneShot or cwimaqAcquisitionContinuous.
CWIMAQ.AcquisitionType property to
One-Shot Acquisition
Use a one-shot acquisition to start an acquisition, perform the acquisition,
and stop the acquisition using a single method. The number of frames
acquired is equal to the number of images in the images collection. Use the
CWIMAQ.AcquireImage method to perform this operation synchronously.
Use the
For information about synchronous and asynchronous acquisitions, refer to
the NI-IMAQ User Manual.
If you want to acquire a single field or frame into a buffer, set the image
count to 1. This operation is also referred to as a snap. Use a snap for
low-speed or single capture applications. The following code illustrates a
synchronous snap:
Private Sub Start_Click()
End Sub
IMAQ Vision for Visual Basic User Manual2-4ni.com
CWIMAQ.Start method to perform this operation asynchronously.
If you want to acquire multiple frames, set the image count to the number
of frames you want to acquire. This operation is called a sequence. Use a
sequence for applications that process multiple images. The following code
illustrates an asynchronous sequence, where
Use a continuous acquisition to start an acquisition and continuously
acquire frames into the image buffers, and then explicitly stop the
acquisition. Use the
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=_
cwimaqAcquisitionContinuous
CWIMAQ1.Start
End Sub
CWIMAQ.Start method to start the acquisition. Use
Private Sub Stop_Click()
CWIMAQ1.Stop
End Sub
A ring operation uses multiple buffers for the acquisition. Use a ring for
high-speed applications that require processing on every image. The
following code illustrates a ring, where
Use the CWIMAQVision.ReadImage method to open and read data from
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. In all cases, the software automatically converts the pixels
it reads into the type of image you pass in.
Use the
image file containing additional information, such as calibration
information, template information for pattern matching, or overlay
information. For more information about pattern matching templates
and overlays, refer to Chapter 5, Performing Machine Vision Tasks.
You also can use the
to retrieve image properties—image size, pixel depth, recommended image
type, and calibration units—without actually reading all the image data.
CWIMAQVision.ReadImageAndVisionInfo method to open an
Converting an Array to an Image
Use the CWIMAQImage.ArrayToImage method to convert an array to an
image. You also can use the
convert an image to an array.
Display an Image
Display an image using the CWIMAQViewer control. Use
CWIMAQViewer.Attach to attach the image you want the viewer
to display. When you attach an image to a viewer, the image automatically
updates the viewer whenever an operation modifies the contents of the
image. You can access the image attached to the viewer using the
CWIMAQViewer.Image property. Before you attach an image to the
viewer, the viewer already has an image attached by default. Therefore, the
viewer has an image attached to it at all times. You can use the attached
image as either a source image, destination image, or both using the
CWIMAQViewer.Image property.
CWIMAQVision.GetFileInformation method
CWIMAQImage.ImageToArray method to
You can use the
CWIMAQPalette object associated with the viewer. Use the
CWIMAQPalette object to programmatically apply a color palette to
IMAQ Vision for Visual Basic User Manual2-6ni.com
CWIMAQViewer.Palette property to access the
the viewer. You can set the CWIMAQPalette.Type property to apply
predefined color palettes. For example, if you need to display a binary
image—an image that contains particle regions with pixel values of 1
and a background region with pixel values of 0—set the
cwimaqPaletteBinary. For more information about color palettes, refer
to Chapter 2, Display, of the IMAQ Vision Concepts Manual.
You also can set a default palette during design time using the Menu
property page. Users can change the color palette during run time by using
the right-click menu on the viewer.
Attach Calibration Information
If you want to attach the calibration information of the current setup
to each image you acquire, use
CWIMAQVision.SetCalibrationInformation. 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.
Chapter 2Getting Measurement-Ready Images
Type property to
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 geometrical transforms, void the calibration information. Use
CWIMAQVision.WriteImageAndVisionInfo to save the image and all of the
attached calibration information to a file.
Analyze an Image
When you acquire and display an image, you may want to analyze the
contents of the image for the following reasons:
•To determine if the image quality is high enough for the inspection
task.
•To obtain the values of parameters that you want to use in processing
methods during the inspection process.
The histogram and line profile tools can help you analyze the quality of the
images.
Use CWIMAQVision.Histogram2 to analyze the overall grayscale
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. If the image has too much light, the majority
of the pixels will have a high intensity values, which appear as
a concentration of peaks on the right side of the histogram. If the image has
an appropriate amount of contrast, the histogram will have distinct regions
of pixel concentrations. Use the histogram information to decide if the
image quality is high enough to separate objects of interest from the
background.
If the image quality meets your needs, use the histogram to determine the
range of pixel values that correspond to objects in the image. You can use
this range in processing methods, such as determining a threshold range
during particle analysis.
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 needs, try to improve the
image quality using the image processing techniques described in the
Improve an Image section of this chapter.
Use
CWIMAQVision.LineProfile2 to get the pixel distribution along a
line in the image, or use
CWIMAQVision.RegionsProfile to get the
pixel distribution along a one-dimensional path in the image. By looking at
the pixel distribution, you can determine if the image quality is high enough
to provide you with sharp edges at object boundaries. Also, you can
determine if the image is noisy, and identify the characteristics of the noise.
If the image quality meets your needs, use the pixel distribution
information to determine some parameters of the inspection methods you
want to use. For example, use the information from the line profile to
determine the strength of the edge at the boundary of an object. You can
input this information into
CWIMAQVision.FindEdges2 to find the edges
of objects along the line.
IMAQ Vision for Visual Basic User Manual2-8ni.com
Improve an Image
Using the information you gathered from analyzing the image, you may
want to improve the quality of the image for inspection. You can improve
the image with lookup tables, filters, grayscale morphology, and Fast
Fourier transforms (FFT).
Lookup Tables
Apply lookup table (LUT) transformations to highlight image details in
areas containing significant information at the expense of other areas.
A LUT transformation converts input grayscale values in the source image
into other grayscale values in the transformed image. IMAQ Vision
provides four methods that directly or indirectly apply lookup tables to
images:
•
•
•
•
Chapter 2Getting Measurement-Ready Images
CWIMAQVision.MathLookup—Converts the pixel values of an
image by replacing them with values from a predefined lookup table.
IMAQ Vision has seven predefined lookup tables based on
mathematical transformations. For more 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 grayscale values.
CWIMAQVision.Inverse—Inverts the pixel intensities of an image
to compute the negative of the image. For example, use this method
before applying an automatic threshold to the image if the background
pixels are brighter than the object pixels.
Filters
Filter the image when you need to improve the sharpness of transitions in
the image or increase the overall signal-to-noise ratio of the image. You can
choose either a lowpass or highpass filter, depending on your needs.
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
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
or
CWIMAQVision.NthOrder, or you can use a predefined highpass
allows you to find edges in an image using predefined edge detection
kernels, such as the Sobel, Prewitt, and Roberts kernels.
Convolution Filter
CWIMAQVision.Convolute allows you to use a predefined set of
lowpass and highpass filters. Each filter is defined by a kernel of
coefficients. Use the CWIMAQKernel object to define the filter. Use
CWIMAQKernel.LoadKernel to load a predefined kernel into the
object. If the predefined kernels do not meet your needs, use the
CWIMAQKernel.SetSize method to set the 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, Image Processing, of the IMAQ Vision Concepts Manual.
CWIMAQVision.Convolute
Grayscale Morphology
Perform grayscale morphology when you want to filter grayscale
features of an image. Grayscale morphology helps you remove or
enhance isolated features, such as bright pixels on a dark background.
Use these transformations on a grayscale image to enhance non-distinct
features before thresholding the image in preparation for particle analysis.
Grayscale morphological transformations, which include erosions and
dilations, compare a pixel to those pixels that surround it. An erosion keeps
the smallest pixel values. A dilation keeps the largest pixel values.
For more information about grayscale morphology transformations, refer
to Chapter 5, Image Processing, of the IMAQ Vision Concepts Manual.
IMAQ Vision for Visual Basic User Manual2-10ni.com
FFT
Chapter 2Getting Measurement-Ready Images
Use CWIMAQVision.GrayMorphology to perform one of the following
seven transformations:
•Erosion—Reduces the brightness of pixels that are surrounded by
neighbors with a lower intensity.
•Dilation—Increases the brightness of pixels surrounded by neighbors
with a higher intensity. A dilation has the opposite effect of an erosion.
•Opening—Removes bright pixels isolated in dark regions and smooths
boundaries.
•Closing—Removes dark pixels isolated in bright regions and smooths
boundaries.
•Proper-opening—Removes bright pixels isolated in dark regions and
smooths the inner contours of particles.
•Proper-closing—Removes dark pixels isolated in bright regions and
smooths the inner contours of particles.
•Auto-median—Generates simpler particles that have fewer details.
Use the Fast Fourier Transform (FFT) to convert an image into its
frequency domain. In an image, details and sharp 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 frequencies. Also, the
imaging setup may produce non-uniform lighting of the field of view,
which produces an image with a light drift superimposed on the
information you want to analyze. In the frequency domain, the light drift
appears as a limited set of low frequencies around the average intensity of
the image, which is the DC component.
You can use algorithms working in the frequency domain to isolate and
remove these unwanted frequencies from the image. Complete the
following steps to obtain an image in which the unwanted pattern has
disappeared but the overall features remain:
1.Use
CWIMAQVision.FFT to convert an image from the spatial domain
to the frequency domain. This method computes the FFT of the image
and results in a complex image representing the frequency information
of the image.
2.Improve the image in the frequency domain with a lowpass or highpass
frequency filter. Specify which type of filter to use with
CWIMAQVision.CxAttenuate or CWIMAQVision.CxTruncate.
Lowpass filters smooth noise, details, textures, and sharp edges in an
image. Highpass filters emphasize details, textures, and sharp edges in
images, but they also emphasize noise.
•Lowpass attenuation—The amount of attenuation is directly
proportional to the frequency information. At low frequencies,
there is little attenuation. As the frequencies increase, the
attenuation increases. This operation preserves all of the zero
frequency information. Zero frequency information corresponds
to the DC component of the image or the average intensity 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, and
the frequencies below it remain unaltered.
•Highpass truncation—Specify a frequency. The frequency
components above the ideal cutoff frequency remain unaltered,
and the frequencies below it are removed.
3.To transform the image back to the spatial domain, use
CWIMAQVision.InverseFFT.
Complex Image Operations
CWIMAQVision.ReplaceComplexPlane and
CWIMAQVision.ExtractComplexPlane allow you to access, process,
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 Manual2-12ni.com
CWIMAQImage.ImageToArray and
Making Grayscale and Color
Measurements
This chapter describes how to take measurements from grayscale and color
images. You can make inspection decisions based on image statistics, such
as the mean intensity level in a region. Based on the image statistics, you
can perform many machine vision inspection tasks on grayscale or color
images, such as detecting the presence or absence of components, detecting
flaws in parts, and comparing a color component with a reference.
Figure 3-1 illustrates the basic steps involved in making grayscale and
color measurements.
Define Regions of Interest
3
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
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.