Академический Документы
Профессиональный Документы
Культура Документы
le
Course Manual
mp
Course Software Version 8.5
April 2008 Edition
Part Number 321998F-01
Worldwide Offices
Australia 1800 300 800, Austria 43 662 457990-0, Belgium 32 (0) 2 757 0020, Brazil 55 11 3262 3599, Canada 800 433 3488,
China 86 21 5050 9800, Czech Republic 420 224 235 774, Denmark 45 45 76 26 00, Finland 358 (0) 9 725 72511,
France 01 57 66 24 24, Germany 49 89 7413130, India 91 80 41190000, Israel 972 3 6393737, Italy 39 02 41309277,
Japan 0120-527196, Korea 82 02 3451 3400, Lebanon 961 (0) 1 33 28 28, Malaysia 1800 887710, 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 495 783 6851, Singapore 1800 226 5886, Slovenia 386 3 425 42 00,
South Africa 27 0 11 805 8197, Spain 34 91 640 0085, Sweden 46 (0) 8 587 895 00, Switzerland 41 56 2005151,
Taiwan 886 02 2377 2222, Thailand 662 278 6777, Turkey 90 212 279 3031, United Kingdom 44 (0) 1635 523545
For further support information, refer to the Additional Information and Resources appendix. To comment on National Instruments
documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback.
Contents
Student Guide
A. Course Description ...............................................................................................v
B. What You Need to Get Started .............................................................................vi
C. Installing the Course Software..............................................................................vii
D. Course Goals.........................................................................................................vii
E. Course Conventions ..............................................................................................viii
le
Lesson 1
Introduction to Machine Vision
A. National Instruments Machine Vision ..................................................................1-2
B. NI Vision Products................................................................................................1-2
C. Measurement & Automation Explorer .................................................................1-6
Lesson 2 mp
Preparing Your Imaging Environment
A. Preparing Your Imaging Environment .................................................................2-2
B. Selecting a Camera ...............................................................................................2-11
Lesson 3
Acquiring and Displaying Images
A. Acquisition Modes ................................................................................................3-2
B. Property Nodes .....................................................................................................3-35
C. Triggering .............................................................................................................3-45
Lesson 4
Processing Images
A. NI Vision VIs........................................................................................................4-2
B. Prototyping Applications with NI Vision Assistant .............................................4-3
Sa
Lesson 5
Enhancing Acquired Images
A. Using Spatial Calibration......................................................................................5-2
B. Calibrating Images with NI Vision .......................................................................5-3
C. Calibrating Your Imaging Setup...........................................................................5-4
D. Using Spatial Filters..............................................................................................5-13
© National Instruments Corporation iii LabVIEW Machine Vision and Image Processing
Contents
Lesson 6
Measuring Features
A. NI Vision Machine Vision VIs .............................................................................6-2
B. Regions of Interest ................................................................................................6-2
C. Nondestructive Overlays.......................................................................................6-8
D. Edge Detection......................................................................................................6-9
Lesson 7
le
Using Machine Vision Techniques
A. Pattern Matching...................................................................................................7-2
B. Geometric Matching .............................................................................................7-6
C. Coordinate Systems ..............................................................................................7-20
Lesson 8
Processing Binary Images
A.
mp Collecting Image Information with Histograms ...................................................8-2
B. Thresholds.............................................................................................................8-4
C. Morphology ..........................................................................................................8-11
D. Making Particle Measurements ............................................................................8-15
E. Using the Golden Template ..................................................................................8-25
Lesson 9
Identifying Images
A. Binary Particle Classification ...............................................................................9-2
B. Optical Character Recognition..............................................................................9-5
C. 2D Barcode Functions ..........................................................................................9-17
Appendix A
Using Color Tools
A. Introduction to Color ............................................................................................A-2
Sa
B. Using Color Tools.................................................................................................A-3
Appendix B
Additional Information and Resources
Glossary
Course Evaluation
le
Calibrating your imaging setup is important when you need to make
accurate measurements in real-world units.
Topics
mp A. Using Spatial Calibration
B. Calibrating Images with NI Vision
C. Calibrating Your Imaging Setup
D. Using Spatial Filters
Sa
© National Instruments Corporation 5-1 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
le
and lens distortion. In Figure 5-1a, the camera is in the ideal position:
perpendicular to the image plane. If the camera is not perpendicular to the
image plane, as shown in Figure 5-1b, the image results can have
perspective errors and lens distortion errors.
1
mp 2
a. b.
Perspective errors and lens errors cause images to appear distorted. This
distortion misplaces information in an image, but it does not necessarily
Sa
destroy the information in the image. Calibration accounts for possible
errors by constructing mappings that you can use to convert between pixel
and real-world units. You can also use the calibration information to correct
perspective errors and nonlinear distortion errors in image displays and
shape measurements.
le
coordinates in a calibrated image. In addition, you can transform a distorted
image into an image in which distortions are corrected. NI Vision also
allows you to save and load calibrated images for processing.
© National Instruments Corporation 5-3 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
le
around each dot, only the area in the image covered by the grid dots is
calibrated accurately.
Note National Instruments provides a calibration template that you can use to calibrate
your image. However, this template may not be appropriate for all applications. Consider
the size of your object under inspection, as well as whether or not you need a calibration
template that has a certificate of accuracy. You can purchase highly accurate calibration
templates from optics suppliers, such as Edmund Optics.
You have the option of generating an error map. An error map returns an
estimate of the worst-case error when a pixel coordinate is transformed into
a real-world coordinate.
le
convert any pixel coordinate to its real-world coordinate and back.
© National Instruments Corporation 5-5 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
Scenario
Many machine vision applications are completely useless if they cannot
le
report information in real-world units. NI Vision calibration functions can
calibrate pixel separation in your images to a real-world distance.
Lens distortion and perspective distortion are also common problems found
in image acquisition. If careful consideration is not taken, measurement
accuracy will vary according to the location of the object in your image. NI
Vision calibration functions can account for distortion factors and correction
mp functions can adjust the image accordingly.
Description
In this exercise, you will create a script in Vision Assistant to correct lens
distortion and examine an example program to observe the perspective
calibration process in LabVIEW.
Implementation
Complete both parts of this exercise.
❑ Click Next.
❑ Click Next.
le
❑ On the front panel, right-click the Image Display indicator and select
Snapshot.
4. Use the ELP cal template grid to calibrate the image to account for
nonlinear lens distortion.
© National Instruments Corporation 5-7 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
le
mp
Figure 5-3. Vision Assistant Express VI Configuration Window
❑ Click the Zoom Out button in order to see the entire image.
❑ Click Next.
❑ Enter 0 for the Threshold Range Min and enter 110 for the Max.
This setting allows the algorithm to find most of the grid dots
without letting noise particles through.
❑ Click Next.
❑ Enter 0.375 for the X-Spacing and enter 0.375 for the Y-Spacing.
❑ Click Next.
le
❑ Set the Axis Reference to Indirect, as shown in Figure 5-4a.
X Y
mp Y
a. Indirect b. Direct
© National Instruments Corporation 5-9 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
❑ Click OK.
le
Note Although the image perspective has not been corrected, the image perspective is
fully calibrated at this point to accommodate lens distortion. You can take measurements
in real-world units, and the results will be spatially correct.
5. Correct the image perspective. The text in the image will appear without
curvature.
le
7. Add image management and error handling to the VI.
© National Instruments Corporation 5-11 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
Testing
1. Test the VI.
❑ Run the VI. You should see the corrected image in the image display.
le
❑ Go to the block diagram.
Filters are divided into two types: linear (also called convolution) and
nonlinear. A linear filter replaces each pixel by a weighted sum of its
le
neighbors. The matrix defining the neighborhood of the pixel also specifies
the weight assigned to each neighbor. This matrix is called the convolution
kernel. A nonlinear filter replaces each pixel value with a nonlinear function
of its surrounding pixels. Like the linear filters, the nonlinear filters operate
on a neighborhood.
Lowpass Highpass
Linear Gaussian Gradient
Smoothing Laplacian
Nonlinear Lowpass Differentiation
Sa
Median Gradient
Nth Order Prewitt
Roberts
Sigma
Sobel
© National Instruments Corporation 5-13 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
Convolution Kernels
A convolution kernel defines a 2D filter that you can apply to a grayscale
image. A convolution kernel is a 2D structure whose coefficients define the
characteristics of the convolution filter that it represents. In a typical
filtering operation, the coefficients of the convolution kernel determine the
filtered value of each pixel in the image. NI Vision provides a set of
convolution kernels that you can use to perform different types of filtering
operations on an image. You can also define your own convolution kernels,
le
thus creating custom filters.
mp
Sa
Scenario
Some images require filtering before they can be analyzed or displayed.
NI Vision provides multiple filters.
le
Design
In this exercise, you will acquire an image and use the Vision Assistant
express VI to apply smoothing and sharpening filters.
Flowchart
mp Display the
Original Image
© National Instruments Corporation 5-15 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
Implementation
1. Open Snap and Display.vi (or Snap and Display 1394.vi),
located in the <Exercises>\LabVIEW Machine Vision directory.
le
Figure 5-10. Snap and Display VI Block Diagram
2. Save the VI as Using Filters.vi in the <Exercises>\LabVIEW
Machine Vision directory.
3. Apply a Smoothing Filter to your image.
mp ❑ Place a Vision Assistant Express VI (Vision and Motion»Vision
Express»Vision Assistant) on the block diagram.
Note This image will not be used when the VI runs, but it will be displayed while
configuring the Vision Assistant Express VI so that the effects of the processing steps can
be visualized.
Sa
❑ Select Processing Functions: Grayscale»Filters in the bottom left
window of Vision Assistant.
❑ Click OK.
le
mp
Figure 5-11. Applying a Smoothing – Low Pass Filter
Tip You can double-click the Smoothing – Low Pass step to edit the filter. Vary the size
of the filter to see the effect on the image.
❑ Click OK.
© National Instruments Corporation 5-17 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
❑ Click Finish.
le
mp
Figure 5-12. Applying a Convolution – Highlight Details Filter
Sa
le
Figure 5-13. Block Diagram of Using Filters VI
Note Create the array constant by right-clicking the Kernal input of the Vision Assistant
mpExpress VI and selecting Create»Constant. Display multiple elements of the array
constant by clicking and dragging the bottom right corner of the array constant.
❑ Run the VI and view the result in the Image Display indicator on the
front panel.
❑ Run the VI with the different array constant values to see the results.
Challenge
1. Modify the block diagram to display both the filtered and original
images on the front panel at the same time.
Sa
2. Save and close the VI.
© National Instruments Corporation 5-19 LabVIEW Machine Vision and Image Processing
Lesson 5 Enhancing Acquired Images
Notes
le
mp
Sa