Advertisement

NI myRIO
Vision Essentials Guide
Ed Doering

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the NI myRIO and is the answer not in the manual?

Questions and answers

Summary of Contents for National Instruments NI myRIO

  • Page 1 NI myRIO Vision Essentials Guide Ed Doering...
  • Page 3 NI myRIO Vision Essentials Guide Ed Doering Electrical and Computer Engineering Department Rose-Hulman Institute of Technology...
  • Page 4 LabVIEW and National Instruments are trademarks of National Instruments. All other trademarks or product names are the property of their respective owners. Additional Disclaimers: The reader assumes all risk of use of this book and of all in- formation, theories, and programs contained or described in it.
  • Page 5: Table Of Contents

    Contents 1 Introduction I Machine Vision Fundamentals 2 Application Development Flow 3 Design Pattern for Machine Vision Applications II Introductory Machine Vision Projects 4 Camera Setup 5 Stereo Vision 6 Coin Caliper I 7 Coin Caliper II III Machine Vision Application Projects 8 Coin Counter 9 POS Terminal 10 Keyed Optical Lock...
  • Page 6 CONTENTS 12 Gauging Station 13 Product Label Inspector 14 Component Placement Inspector 15 Motion Detector 16 Auto-Pan Camera 17 Marble Sorter IV Appendices A Recommended Equipment B MXP and MSP Connector Diagrams C LabVIEW Quick Tips D Build a Stand-Alone Application E Marble Sorter Construction Details F Video Tutorial Links...
  • Page 7: Introduction

    This book serves as your guide to the essential techniques necessary to add vision to your NI myRIO project. You will learn through a mixture of written materials, video tutorials, and guided hands-on projects. Part I, Machine Vision Fundamentals, introduces you to a generalized application development flow suitable for all of the machine vision projects in this book.
  • Page 8 Book Resources The most-recent version of NI myRIO Vision Essentials Guide is always avail- able as a free download at http://www.ni.com/myrio/vision-guide; page iv shows the document version. The download also includes the “Machine Vision App”...
  • Page 9 A solutions manual is available to qualified instructors; please contact your local National Instruments representative for details.
  • Page 10 App” project template; Isaac Sanchez and Alex Drane for timely advice on LabVIEW vision techniques; and Margaret Barett for inviting me to participate in the original NI myRIO Beta Program. I am also grateful to Andrew Watchorn for his ongoing assistance and to Tom Robbins at NTS Press for his editorial support on this project.
  • Page 11: I Machine Vision Fundamentals

    Part I Machine Vision Fundamentals...
  • Page 13: Application Development Flow

    : The application development flow described here may also be used to create a desktop application in case you do not have access to the NI myRIO target. Figure 2.1 on the following page visualizes the application development flow...
  • Page 14 CHAPTER 2. APPLICATION DEVELOPMENT FLOW define requirements configure imaging system acquire representative images real-world units? calibrate camera develop processing script develop LabVIEW project validate application Figure 2.1: Development flow for a machine vision application.
  • Page 15 3. Acquire representative images Connect the camera to the desktop or to the NI myRIO Use Vision Assistant to collect images over the range of possible conditions: Select the “Target” as “This Computer” for a desktop- connected camera and as “Select Network Target”...
  • Page 16 Use available on-board devices as needed, e.g., LEDs, accelerometer, PWM output for servomotors, and switches Refer to the NI myRIO Project Essentials Guide for detailed instruc- tions on a wide range of useful external devices such as proximity sensors and LCD display 10.
  • Page 17: Design Pattern For Machine Vision Applications

    Design Pattern for Machine Vision Applications A LabVIEW design pattern is a particular block diagram coding style that has emerged over time and has been “vetted” by many developers as a useful way to develop a broad range of specific applications. Design patterns range from the very simple to the very complex, but all design patterns provide a systematic way to transform your concept into a functional and reliable software application.
  • Page 18 Figure 3.1 on page 19 illustrates the task diagram for a generic QSM intended for machine vision applications that target NI myRIO. Each box corresponds to a state, and a bundle of states indicates a task. The QSM executes the start-up task and then schedules tasks according to conditions determined by analysis results, front-panel buttons, and external controls and sensors.
  • Page 19 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS 3.3 “Machine Vision App” Template Download the .zip file from the NI myRIO Vision Essentials Guide main page, extract the “Machine Vision App” folder, open the “machine vision app” Lab- VIEW project (double-click the .lvproj file), and then double-click Main.vi to open its block diagram.
  • Page 20 .lvproj file, and view the organized files. 2. MVA Main.vi Quick Tour – Quick-paced tour of the “Main” VI: while- loop, case-structure, state queue, front-panel controls, NI myRIO ports, and data highway. 3. MVA States – Review the standard states (qsm, myRIO, image), the example application-specific state, and the expansion states.
  • Page 21 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS Data highway: The data highway is a combination of a LabVIEW cluster and a while-loop shift register. The cluster is a collection of front-panel controls stored as a “type def” (type definition); any change to the type definition propagates throughout the entire project.
  • Page 22 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS 4. Add State at End – Add a state at the end: open the state type def, edit the enumerated control, show two ways to create a new case-structure subdiagram. 5. Remove State –...
  • Page 23 The default task handles ongoing activities related to the image stream and NI myRIO port activity. myRIO states: The myRIO states perform activities required by applications tar- geted to NI myRIO. These tutorials discuss each state and typical modifications. 1. (myRIO) initialize – (myRIO) initialize – Perform one-time initializa-...
  • Page 24 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS how to use NI-MAX while configuring Vision Acquisition to select the webcam resolution (mode) and attributes. 2. (image) analyze – (image) analyze – Use the Vision Assistant Express VI to load the script created during development with the stand-alone Vision Assistant tool, select the necessary options to create an image buffer for the analyzed image (allocates memory only on the first run), and then select the necessary controls and indicators so that the script inputs and outputs...
  • Page 25 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS start start up condition A task A condition B task B schedule states condition C task C update otherwise images and devices "stop" or error shut down stop Figure 3.1: Task diagram for the Queued State Machine (QSM).
  • Page 26 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS start start up "save image" save image schedule states update otherwise images and devices "stop" or error shut down stop Figure 3.2: Task diagram for the “Machine Vision App” (MVA).
  • Page 27 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS (image) get • Check "stop camera" flag, stop webcam if set • Get next available webcam image • Optionally flip the image when using camera stand • Write webcam image buffer reference; buffer memory allocated on first call only (image) analyze •...
  • Page 28 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS save image • Confirm that USB flash drive is attached • Read image buffer references intended for saving • Determine which image buffer to save based on mode switches and flags • Merge overlay (if required) and write the image file (qsm) release •...
  • Page 29 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS (qsm) initialize • Allocate memory for additional image buffers required by the application • Initialize data highway lane values • Perform other needed one-time-only initializations (qsm) release • Reinitialize all front-panel action buttons to their default (unclicked) state (myRIO) initialize •...
  • Page 30 CHAPTER 3. DESIGN PATTERN FOR MACHINE VISION APPLICATIONS (qsm) clean up • Set the "stop webcam" flag • Perform other needed activities such as writing closing comments to a log file and closing open files (image) get • Check "stop webcam" flag, stop webcam if set •...
  • Page 31: Introductory Machine Vision Projects

    Part II Introductory Machine Vision Projects...
  • Page 33: Camera Setup

    Camera Setup 4.1 Synopsis Camera setup constitutes an important early step in the development of every machine vision application. Everything hinges on the minimum feature size and the number of pixels to allocate to this size; these two values define the required image spatial resolution which in turn can be adjusted by a suitable camera- to-object distance.
  • Page 34 Computer” as the target device and displays a list of all desktop-connected cameras from which you can choose. You can also access cameras con- nected to NI myRIO within Vision Assistant: Choose “Select Network Target” instead of “This Computer” and then enter the IP address as either 172.22.11.2 when myRIO is connected by its USB cable or the IP...
  • Page 35 CHAPTER 4. CAMERA SETUP 4.6 Pixel Aspect Ratio Set up your camera to image a metric ruler with a field of view (FOV) of be- tween 10 and 20 centimeters. Place the ruler in the horizontal direction. Use the horizontal edge of another application’s window on your computer desktop to serve as an alignment aid so that the ruler marks follow a single image pixel row.
  • Page 36 CHAPTER 4. CAMERA SETUP Measure the actual image spatial resolution and compare it to your target value with a percent error calculation. How well does the actual value match your intended value? Adjust the ruler position so that the 0 cm mark appears at the left edge of the image;...
  • Page 37 CHAPTER 4. CAMERA SETUP dot locations and therefore reduces the errors associated with the simple point distance calibration. NI Vision Assistant provides convenient tools to evaluate the performance of the correction and to select an appropriate balance between performance and computational effort. Study the video Grid Calibration to learn how to print a dot grid target and then calibrate the camera according to the dot grid.
  • Page 38 CHAPTER 4. CAMERA SETUP...
  • Page 39: Stereo Vision

    Stereo Vision 5.1 Synopsis A stereo vision system views the same scene with two cameras at different van- tage points to calculate depth information by evaluating the disparity between the two views for common edge and texture features. NI Vision provides two example desktop VIs to demonstrate its stereo vision capability, and one of the demos works on live video streams from two webcams.
  • Page 40 Image. Open each of these folders and confirm that you see a VI that you can run. : A modified version of the Calibrate Stereo Vision System VI is available in the NI myRIO Vision Essentials Guide download file. This modified version works with the table-top camera copy stand so that the telescoping camera column may placed in back so as not to obstruct access to the baseboard.
  • Page 41 5.7 Compute a Depth Image (Live Images) Print the dot grid on a laser printer: Open the NI Vision installation folder, e.g., C:\Program Files (x86)\National Instruments\Vision, open the Documentation subfolder, and then open the CalibrationGrid.pdf file. Choose the “Actual size” option when printing. Measure the distances between the alignment marks in both the horizontal and vertical directions to confirm that the dot grid has been printed accurately.
  • Page 42 CHAPTER 5. STEREO VISION Set up your stereo vision apparatus to match that shown in Figure 5.1. The camera-to-camera baseline distance B is 6 cm and the camera-to-baseboard distance D is 24 cm. Figure 5.1: Stereo camera setup: D = camera-to-baseboard distance and B = camera baseline.
  • Page 43 CHAPTER 5. STEREO VISION Open the Calibrate Stereo Vision System (mod) VI available in the NI myRIO Vision Essentials Guide distribution file. See the video tutorial Configure Stereo Cameras to learn how to configure the two Vision Acquisition Express VIs for your two webcams.
  • Page 44 CHAPTER 5. STEREO VISION...
  • Page 45: Coin Caliper I

    6.1 Required Resources 1. NI LabVIEW and NI Vision Assistant 2. NI myRIO with power supply and USB cable 3. USB webcam and tabletop camera copy stand 4. Black velvet paper background 5.
  • Page 46 The default settings may be defined independently for the same webcam connected to the desktop and to NI myRIO. Also learn how to deter- mine the frame rate for the displayed and acquired images for a given video mode and output image type.
  • Page 47 NI Vision Assistant; select Windows “Start” and then select “All Programs | National Instruments | Vision | Vision Assistant.” Adjust your webcam setup to obtain images similar to those presented in the video, and choose a video mode with reasonably high resolution.
  • Page 48 LabVIEW project for the NI myRIO target. : You can also use the desktop as your target if you do not have access to NI myRIO. Simply create a new LabVIEW VI or project as usual and then continue with the same development flow.
  • Page 49 Follow along with the video Step 7: Add I/O Devices to learn how to add the NI myRIO on-board LEDs to indicate whether the coin diameter is larger or smaller than a threshold value. This very simple example illustrates how to add I/O devices to the application.
  • Page 50 CHAPTER 6. COIN CALIPER I , and illuminate a proportional number of LEDs for a measured diameter between...
  • Page 51: Coin Caliper Ii

    Coin Caliper II Learn how to adapt the “Machine Vision App” template to implement a more sophisticated version of the “Coin Caliper” application you created in the previous project. Follow along with the step-by-step tutorials to gain experience with the various template editing techniques. Figure 7.1: Front panel of the Coin Caliper II VI.
  • Page 52 8. Display the number of images saved during the current session, 9. Illuminate the NI myRIO onboard LED 0 when a coin is present, and 10. Illuminate the NI myRIO onboard LEDs 1 to 3 when a coin’s measured diameter exceeds a user-defined threshold entered on the front panel.
  • Page 53 CHAPTER 7. COIN CALIPER II Deliverables: 1. Lab report or notebook formatted according to instructor’s requirements; include front-panel screen shots to demonstrate that your application meets functional specifications 2. .zip archive file containing all project files: (a) Representative images (b) Vision Assistant script (c) LabVIEW project file set 7.1 Technical Approach NI Vision Assistant Script...
  • Page 54 1. Step 1: Rename and Open Project – Extract the “Machine Vision App” (MVA) template from the .zip file downloaded from the NI myRIO Vision Essentials Guide site, rename the folder, rename the .lvproj file, open the project, rename the while-loop structure, and rename the app.
  • Page 55 CHAPTER 7. COIN CALIPER II i. Calibrate (Figure 7.3 on page 52), ii. Save Image (Figure 7.4 on page 53, and iii. Default task (Figure 7.5 on page 54 3. Step 3: Develop Vision Script – Coin Caliper II demo Step 3/15: Develop the vision script in the stand-alone version of Vision Assistant to measure and report the coin diameter in pixels and in real-world units.
  • Page 56 CHAPTER 7. COIN CALIPER II 13. Step 13: Edit Scheduler State – Edit the (qsm) schedule state to create the necessary tasks. 14. Step 14: Set Up Camera – Coin Caliper II demo Step 14/15: Set up the camera mode (resolution) and attributes. 15.
  • Page 57 CHAPTER 7. COIN CALIPER II start start up "save image" save image "calibrate" calibrate schedule states update otherwise images and devices "stop" or error shut down stop Figure 7.2: Task diagram for the Coin Caliper II application.
  • Page 58 CHAPTER 7. COIN CALIPER II calibrate • Read "diameter [pixels]" • Read "known diameter [mm]" front-panel control • Calculate calibration scale factor • Write scale factor to "Calibration.X Step" and "Calibration.Y Step" (qsm) release • Reinitialize all front-panel action buttons to their default (unclicked) state Figure 7.3: Calibrate task for the Coin Caliper II application.
  • Page 59 CHAPTER 7. COIN CALIPER II save image • Confirm that USB flash drive is attached • Read image buffer references; use "show analyzed" mode switch to select the buffer to write • Form image file name from "image file basename" front-panel control and file number •...
  • Page 60 CHAPTER 7. COIN CALIPER II (image) get • Check "stop webcam" flag, stop webcam if set • Get next available webcam image • Optionally flip the image when using camera stand • Write webcam image buffer reference; buffer memory allocated on first call only (image) analyze •...
  • Page 61: Machine Vision Application Projects

    Part III Machine Vision Application Projects...
  • Page 63: Coin Counter

    Coin Counter Do you have piles of loose change accumulating here and there? Does counting all of those pennies seem like too much bother? Save a trip to the bank and create your own machine vision application to “look” at a collection of coins and instantly show you the total value! Figure 8.1: Front panel of the Coin Counter application.
  • Page 64 Figure 8.2 on the facing page shows the image produced by the Vision Assistant script. Required Resources: 1. NI LabVIEW and NI Vision Assistant 2. NI myRIO with power supply and USB cable 3. USB webcam and tabletop camera copy stand 4. Black velvet paper background 5. LCD display (Digilent PmodCLS) 6.
  • Page 65 CHAPTER 8. COIN COUNTER Figure 8.2: Front-panel for the Coin Counter application showing the output of the Vision Assistant script. 2. .zip archive file containing all project files: (a) Representative images (b) Vision Assistant script (c) LabVIEW project file set 8.1 Technical Approach NI Vision Assistant Script NI Vision Assistant provides the Circle Detector step as a powerful yet simple-...
  • Page 66 CHAPTER 8. COIN COUNTER clean image free of extraneous features, and the morphological operations “re- move small objects” and “fill holes” available under the Advanced Morphology step work well for this purpose. The Threshold step offers a wide variety of auto-thresholding operations to separate the foreground coin objects from the background, and the auto-thresholding feature allows the thresholding step to work reliably under changing lighting conditions.
  • Page 67 Digilent PmodCLS LCD display using its UART, SPI, or I bus interface as well as LabVIEW demonstration code available at NI myRIO Project Essentials Guide .zip Files that you can drop into this project. Study...
  • Page 68 CHAPTER 8. COIN COUNTER Select Image Palette – Use a Property Node to set the image display palette to either “Binary” or “Grayscale.” Note that the Circle Detector step produces a binary output that appears like an all-black screen unless the “Binary”...
  • Page 69 CHAPTER 8. COIN COUNTER Collect images to study intraclass variation: place as many samples of a given class as will fit in the FOV without touching or overlap, and then repeat for each class of coin. With these images you will be able to measure the expected spread of measurements due to measurement error.
  • Page 70 CHAPTER 8. COIN COUNTER that contains these four elements (see Create “Coin Info” Cluster Array and then create a data highway lane for this control. Create another lane as an array of corresponding known coin diameters. Define these values as constants in the (qsm) initialize state. Create a subVI to produce the coin info record that is closest to the mea- sured coin radius;...
  • Page 71 CHAPTER 8. COIN COUNTER Touching coins, overlapping coins and coins only partly in view – how much overlap can be tolerated before you observe classification errors? 8.4 Optional Extra Features: You may wish to add one or more of these extra features: Blink an on-board LED when no coins are detected.
  • Page 72 CHAPTER 8. COIN COUNTER...
  • Page 73: Pos Terminal

    POS Terminal A point-of-sale (POS) terminal is a familiar sight at the end of a shopping trip. Create your own POS terminal to tally up the total price of barcoded items, and use external switches and an LCD display to make your terminal run as a stand-alone application.
  • Page 74 LCD display; display “unknown item” when a barcode is not found in the inventory list, 6. Activate two NI myRIO on-board LEDs and a front-panel indicator when a barcode is in view that has been read successfully, 7. Clear the shopping cart total to zero when either the Empty Cart front- panel button or an external switch is enabled, and 8.
  • Page 75 CHAPTER 9. POS TERMINAL (a) Representative images (b) Vision Assistant script (c) LabVIEW project file set 9.1 Technical Approach NI Vision Assistant Script NI Vision Assistant provides the Barcode Reader step as a flexible and easy-to- use method to detect 1-D barcodes from among ten different standards including “EAN 13”...
  • Page 76 Digilent PmodCLS LCD display using its UART, SPI, or I bus interface as well as LabVIEW demonstration code available at NI myRIO Project Essentials Guide .zip Files that you can drop into this project. Study...
  • Page 77 CHAPTER 9. POS TERMINAL These LabVIEW techniques are also required for this project: Add Custom Data Lane – Create a custom control for the Barcodes Vision Assistant script output and insert this into the data highway Create Formatted Text String –...
  • Page 78 The two switches in this project could be replaced with any two-state device presented in the NI myRIO Project Essentials Guide , e.g., the photodetector and photointerrupter. Add a buzzer to emit a short beep when the shopping cart updates (see Chapter 11 in the NI myRIO Project Essentials Guide).
  • Page 79: Keyed Optical Lock

    Keyed Optical Lock Mechanical locks opened by metal keys represent a centuries-old technology. Modern-day electronic locks replace the metal key with encrypted radio pulses, RFID, magnetic stripes, and integrated circuits. Before the familiar metal keys disappear completely, try this “mash-up” of the old and the new by presenting a metal key to an optical scanner to make the decision as to whether or not to open a lock.
  • Page 80 4. Black velvet paper background 5. USB hub (Stratom X-HUB or equivalent) 6. USB flash drive 7. Relay and associated driver electronics; refer to Chapter 6 of the NI myRIO Project Essentials Guide for a complete discussion of relays and sample LabVIEW code for this relay 8.
  • Page 81 CHAPTER 10. KEYED OPTICAL LOCK Figure 10.2: Front-panel for the Keyed Optical Lock application showing the output of the Vision Assistant script. Deliverables: 1. Lab report or notebook formatted according to instructor’s requirements; include front-panel screen shots to demonstrate that your application meets functional specifications 2.
  • Page 82 “NI myRIO Starter Kit.” Refer to the LabVIEW demonstration project in this chapter to obtain block diagram code that you can drop into this project. Study...
  • Page 83 CHAPTER 10. KEYED OPTICAL LOCK Get ROI from Image Display – Use a Property Node to retrieve a rectan- gular ROI from the image display. Some tasks should execute only one time after a Boolean flag sets. For example, the valid key flag is clear when no valid key is visible and is set the entire time a valid key is in view.
  • Page 84 CHAPTER 10. KEYED OPTICAL LOCK Vision Assistant Script: The Geometric Matching step requires a grayscale image; see Extract Luminance Plane to learn how to extract the luminance plane with Color Plane Extraction. Select the key image with the horizontal flat side on top and the key cuts on the bottom.
  • Page 85 CHAPTER 10. KEYED OPTICAL LOCK Figure 10.3: Typical expected results for the Geometric Matching step.
  • Page 86 CHAPTER 10. KEYED OPTICAL LOCK...
  • Page 87: Dmm Test Stand

    DMM Test Stand Suppose you are in business to manufacture inexpensive digital multime- ters (DMMs) that do not offer a digital data interface. As part of your product testing you need to apply a range of DC voltages and confirm that the numerical display is correct for each voltage.
  • Page 88 7. Run a single measurement sequence when the step button is pressed. Required Resources: 1. NI LabVIEW and NI Vision Assistant 2. NI myRIO with power supply and USB cable 3. USB webcam and tabletop camera copy stand 4. Hand-held DMM with LCD or LED display Deliverables: 1.
  • Page 89 CHAPTER 11. DMM TEST STAND 11.1 Technical Approach NI Vision Assistant Script NI Vision provides the IMAQ Read LCD instrument reader VI that accepts an image of a digital multimeter (DMM) display and interprets the pattern of active segments as a numerical value; it can also identify the decimal point in the dis- play.
  • Page 90 IMAQ Read LCD VI. NI myRIO Analog Outputs NI myRIO provides a total of eight analog outputs (AOs), with two on each of the two MXP connectors, two on the MSP connector, and two more on the audio output jack.
  • Page 91 CHAPTER 11. DMM TEST STAND : Use the “Quick Drop” shortcut (Ctrl + space bar) to look up and place a LabVIEW element by name. See Appendix C on page 139 for more LabVIEW tips. 11.3 Validation Tips Select “DC volts” mode on your DMM and connect it to your selected analog output, With no buttons pressed you should see the live webcam image, the ac- tive segments seen by the instrument reader, and the numerical value...
  • Page 92 CHAPTER 11. DMM TEST STAND...
  • Page 93: Gauging Station

    Gauging Station Quality assurance for fabricated components requires gauging, a proce- dure in which critical physical dimensions are measured and compared against specified tolerances. Traditional manual gauging requires tools such as dial calipers and micrometers, but you can create a vision-based gauging station that will take a large number of dimensional measurements simultaneously with the press of a button.
  • Page 94 CHAPTER 12. GAUGING STATION Functional Requirements: The Gauging Station will: 1. Accept an image of a single component, 2. Apply the following gauging steps when the gauge button is pressed: (a) Apply grid calibration and correction to the image, (b) Locate a reference feature on the component and define a relative coordinate system based on this feature, (c) Take measurements on specified dimensions such as height, width, depth, angle, and hole radius, and...
  • Page 95 CHAPTER 12. GAUGING STATION 2. NI myRIO with power supply and USB cable 3. USB webcam and tabletop camera copy stand 4. Black velvet paper background 5. USB hub (Stratom X-HUB or equivalent) 6. USB flash drive 7. Paper cutout representation of a machined component Deliverables: 1.
  • Page 96 Grid Calibration for details. The calibration image must be stored on a USB flash drive to be accessible to the vision script running on NI myRIO. In addi- tion, applying the correction to the image itself will improve the measurement accuracy and automatic detection of straight edges.
  • Page 97 CHAPTER 12. GAUGING STATION Set the coordinate system to a reference feature After calibrating and correcting the image the gauging application must identify a reference feature on the component to establish a local coordinate system for subsequent measurements. In this way the gauging application allows a certain degree of variety in component alignment with the camera pixel array and eliminates the need for a precise mechanical fixture to accomplish the alignment.
  • Page 98 CHAPTER 12. GAUGING STATION Measure the bored hole radii Use three Shape Detection steps to look for each of the three circles. A single such step is able to detect all circles at once and present them as an array of measurement results, but then it is not easy to determine which measurement belongs to which circle.
  • Page 99 CHAPTER 12. GAUGING STATION LabVIEW Techniques Once your Vision Assistant script is packaged into an Express VI the LabVIEW project is almost done, however, interpreting and using the output of the Caliper step takes some care. See “Gauging Demo” Connections to learn how to extract specific values from the 2-D array output of the Caliper step.
  • Page 100 CHAPTER 12. GAUGING STATION If you plan to use the “image flip” option in the Machine Vision App template you will want to collect all of your images (including the grid calibration image) so that they appear in the same orientation when you develop your script.
  • Page 101: Product Label Inspector

    Product Label Inspector At first glance the artwork and graphics on a typical product label seem to pose a difficult inspection challenge – how can small imperfections such as tears or smudges be detected among so many features? The golden tem- plate technique makes this type of inspection a snap: images are compared to a defect-free image (the golden template) and any difference regions are highlighted and counted.
  • Page 102 3. Accommodate arbitrary rotation and translation of the product label, 4. Illuminate a proportional number of NI myRIO on-board LEDs as a bar- graph to indicate the number of defects found, 5. Maintain a count of the total number of labels processed and a count of the number of defective labels found during the current session, and 6.
  • Page 103 CHAPTER 13. PRODUCT LABEL INSPECTOR Figure 13.2: Product label with two pencil smudge defects (outlined) and the corresponding binary image produced by the analysis script. 2. .zip archive file containing all project files: (a) Representative images (b) Vision Assistant script (c) LabVIEW project file set...
  • Page 104 CHAPTER 13. PRODUCT LABEL INSPECTOR 13.1 Technical Approach NI Vision Assistant Script The NI Vision Assistant Machine Vision | Golden Template Comparison step compares a region of interest (ROI) of an image to a template image and returns a binary image in which non-zero pixels indicate differences between the current image and the template.
  • Page 105 CHAPTER 13. PRODUCT LABEL INSPECTOR to learn how to use the Particle Analysis step to count the remaining particles (now assumed to represent the product label defects) and to report their areas. LabVIEW Techniques The following LabVIEW techniques are required for this project: (qsm) initialize: Front-Panel –...
  • Page 106 CHAPTER 13. PRODUCT LABEL INSPECTOR Collect additional images of the defect-free label with varying amounts of translation and rotation. Use these images during vision script devel- opment to verify that your script detects zero defects even when the label orientation changes. Collect multiple views of each product label defect, again to verify that your script delivers similar results for a given label defect with different orientations.
  • Page 107: Component Placement Inspector

    Component Placement Inspector Machine vision systems play an important role in the manufacture of printed circuit boards (PCBs). Just before the crucial reflow soldering step the board must be checked to ensure that all of the components are placed properly. Create a mock-up of a PCB component placement inspector that confirms whether or not a multitude of colored plastic bricks are properly attached to a baseboard.
  • Page 108 3. Indicate the pass/fail status of each component, 4. Accommodate arbitrary rotation and translation of the board, 5. Illuminate a proportional number of NI myRIO on-board LEDs as a bar- graph to indicate the number of defects found, 6. Maintain a count of the total number of boards processed and a count of the number of defective boards found during the current session, and 7.
  • Page 109 CHAPTER 14. COMPONENT PLACEMENT INSPECTOR Figure 14.2: Analyzed output from the vision script with a board that is tilted and missing a red brick and a yellow brick. 14.1 Technical Approach NI Vision Assistant Script The NI Vision Assistant Color Matching step compares a region of interest (ROI) to a color and indicates whether or not the ROI matches the expected color.
  • Page 110 CHAPTER 14. COMPONENT PLACEMENT INSPECTOR The Color Matching ROIs must be placed relative to a coordinate system derived from a reference feature on the board to permit the vision script to adapt to some baseboard rotation and translation. Use the following sequence of steps to place the origin of the coordinate system at the lower-left corner of the board: 1.
  • Page 111 CHAPTER 14. COMPONENT PLACEMENT INSPECTOR with Add Array Elements that indicates the number of defects found for a given component color. : Use the “Quick Drop” shortcut (Ctrl + space bar) to look up and place a LabVIEW element by name. See Appendix C on page 139 for more LabVIEW tips.
  • Page 112 CHAPTER 14. COMPONENT PLACEMENT INSPECTOR mode (resolution), right-click on the image display, and choose “Save Image,” – Run NI-MAX and save the images directly; these will need to be flipped by batch processing in Vision Assistant; see Batch Process a Folder of Images for details.
  • Page 113: Motion Detector

    Motion Detector Do you have some property in a room that you would like to secure? Set up your webcam as a motion detector that will sound an alarm the moment that even the smallest feature in the camera’s field of view has noticeable motion, also known as optical flow velocity.
  • Page 114 (f) Thresholded version of the Velocity Image #1 4. Display the motion activity with a panel meter, 5. Activate all four NI myRIO on-board LEDs when the motion activity value exceeds a user-defined threshold. Figure 15.1 on the preceding page shows the front-panel of the Motion Detector application viewing a moving object.
  • Page 115 CHAPTER 15. MOTION DETECTOR 15.1 Technical Approach NI Vision Assistant Script The vision script merely needs to extract the luminance image from the color webcam image because the optical flow VIs are not available in Vision Assistant; see Extract Luminance Plane for details.
  • Page 116 Optional extra features: You may wish to add one or more of these extra features: Add an audible alarm; see Chapter 11 of the NI myRIO Project Essentials Guide for details on the piezoelectric buzzer.
  • Page 117: Auto-Pan Camera

    Auto-Pan Camera Suppose you need to make a video recording of a speaker’s presentation. The speaker usually stands at a podium, but occasionally moves side to side and may even walk away from the podium altogether. Create an auto-pan camera that combines a servo-mounted webcam, a position sensing algo- rithm based on color, and a closed-loop control system move the camera so as to maintain the target object in the center at the camera’s field of view.
  • Page 118 Vision Assistant script. Required Resources: 1. NI LabVIEW and NI Vision Assistant 2. NI myRIO with power supply and USB cable 3. USB webcam and tabletop camera copy stand 4. Servo motor (GWS S03N STD );...
  • Page 119 CHAPTER 16. AUTO-PAN CAMERA Figure 16.2: Front-panel for the Auto-Pan Camera application showing the output of the Vision Assistant script. Deliverables: 1. Lab report or notebook formatted according to instructor’s requirements; include front-panel screen shots to demonstrate that your application meets functional specifications 2.
  • Page 120 CHAPTER 16. AUTO-PAN CAMERA plane (refer to Extract Luminance Plane but select hue instead of luminance, of course), dual-threshold the hue image with user-defined low and high values to select the pixels that match the defined hue (see Dual-Threshold Grayscale to Binary ), remove noise pixels and other small objects (see Remove Small Objects...
  • Page 121 Servo control Chapter 17 of the NI myRIO Project Essentials Guide describes how to set the angle of a servomotor with the NI myRIO PWM (pulse-width modulated) output; see Servo Interfacing Theory for details. Use the block diagram code described in that chapter to convert a desired angle expressed in percent of full-scale rotation (−100 to +100) into the corresponding duty cycle of the PWM...
  • Page 122 PWM Express VI. You only need a single instance of this Express VI. : Refer to the NI myRIO connector diagrams in Appendix B on page 137. PID Controller The closed-loop PID controller can be easily implemented with the PID Ad- vanced VI located in the “Control &...
  • Page 123 CHAPTER 16. AUTO-PAN CAMERA the camera takes too long to settle on the target object after it has moved to a new position. Refer to these articles on PID control loop tuning at Motion Engineering’s page Servo Tuning to learn more. LabVIEW Techniques The following LabVIEW techniques are required for this project: Add Custom Data Lane...
  • Page 124 CHAPTER 16. AUTO-PAN CAMERA Get some inspiration for extreme-performance auto-panning developed by the Ishikawa Watanabe Laboratory of the University of Tokyo. Two demo videos show the 1ms Auto Pan-Tilt system in action as it tracks a ping- pong ball in play as well as a yo-yo in the hands of an expert. The tracked object remains perfectly centered in the camera’s field of view at all times! Optional extra features: You may wish to add one or more of these extra features:...
  • Page 125: Marble Sorter

    Marble Sorter Vision systems excel at sorting objects into categories according to size, shape, and color. A typical sorting system consists of a hopper, feeder, camera, vision algorithm, and selector. Create a marble sorter based on a color camera and two servomotors that automatically sorts a hopper full of marbles into bins, one for each color of marble.
  • Page 126 Required Resources: 1. NI LabVIEW and NI Vision Assistant 2. NI myRIO with power supply and USB cable...
  • Page 127 Checker Marbles (b) Two servo motors (GWS S03N STD ); refer to Chapter 17 of the NI myRIO Project Essentials Guide for a complete discussion of servo motors and sample LabVIEW code for this servo (c) Marble track; see Appendix E on page 143 for construction details Deliverables: 1.
  • Page 128 CHAPTER 17. MARBLE SORTER completely to the “load” position, even if the feed slot sometimes fills earlier. This ensures that any remaining marbles on the left side of the hopper will fall into the feed slot. In addition, rotating the feed disk back and forth through the hopper agitates the queued marbles to reduce the chance of jamming.
  • Page 129 The demo code uses the low-level PWM VIs Open and Set Duty Cycle and Frequency. See the NI myRIO low-level PWM subpalette to find the related VIs Set Duty Cycle and Close. You may wish to modify this demo code to add a...
  • Page 130 CHAPTER 17. MARBLE SORTER 100 F electrolytic capacitor as a bypass (decoupling) capacitor between the NI myRIO 5-volt supply and ground. Be careful to observe proper polarity of the electrolytic capacitor! Create the set servo angle VI to simplify the interface to your two servomo- tors and to speed development of your Marble Sorter application.
  • Page 131 CHAPTER 17. MARBLE SORTER LabVIEW Techniques The following LabVIEW techniques are required for this project: Get ROI from Image Display or Default – Get the ROI (region of interest) from the main image display with a "Property Node." Use a default ROI defined by the Vision Assistant script when no ROI is defined on the image display.
  • Page 132 Optional Extra Features: You may wish to add one or more of these extra features: Display the sensed color code index as a binary pattern on the NI myRIO on-board LEDs; see Number to Boolean Array. Add the LCD display to show the sensed color code; see Chapter 8 on page 57 for details on the LCD.
  • Page 133 CHAPTER 17. MARBLE SORTER Figure 17.3: Bin selector arm located under the feed disk. The bin selector rotates to one of the six color bins depending on the color analysis result of the vision script.
  • Page 134 CHAPTER 17. MARBLE SORTER...
  • Page 135: Appendices

    Part IV Appendices...
  • Page 137: A Recommended Equipment

    Recommended Equipment A.1 USB Webcam Microsoft LifeCam Studio Webcam pictured in Figure A.2 on the follow- ing page; search the major resellers such as Amazon to find the best price on this product Desirable features: – Wide range of resolutions from 176 144 to 1920 1080 –...
  • Page 138 APPENDIX A. RECOMMENDED EQUIPMENT Figure A.1: Webcam stabilizer: (1) Insert a plastic block of material, (2) wrap with two narrow strips of duct tape, and (3) wrap with a single wide piece of duct tape. A.2 Tabletop Camera Copy Stand Figure A.2: Microsoft LifeCam Studio webcam mounted to the RPS RS-CS305 tabletop camera copy stand.
  • Page 139 APPENDIX A. RECOMMENDED EQUIPMENT RPS RS-CS305 Copy Stand pictured in Figure A.2 on the facing page – One 1/4"-20 threaded camera mount with plastic tightening wheel – Telescoping column (6" to 12") for adjustable camera height – Two-position camera mounting bracket to extend the range of baseboard- to-camera distance –...
  • Page 140 Desirable features: – Designed for direct connection to NI myRIO: X-HUB replicates the existing USB connectors and power supply jack – Extends the NI myRIO USB port count to three (instead of one) and adds an Ethernet port http://www.hotp.com/products/10358 http://www.amazon.com/3M-836R-OS-Lint-Roller/dp/B00006IA8Q/ref=sr_ 1_11 http://sine.ni.com/nips/cds/view/p/lang/en/nid/213322...
  • Page 141 APPENDIX A. RECOMMENDED EQUIPMENT Figure A.3: Stratom X-HUB 3-port USB hub and Ethernet port expander. • Practical considerations: – Required for any machine vision project that needs a USB flash drive A.6 Stereo Camera Bracket • Desmond D3D-3 Mini Stereo Camera Bracket , pictured in Figure A.4 on the following page –...
  • Page 142 APPENDIX A. RECOMMENDED EQUIPMENT Figure A.4: Desmond D3D-3 mini stereo camera bracket. – Provides a range of stereo webcam baselines • Practical considerations: – Required for stereo vision machine vision projects...
  • Page 143: B Mxp And Msp Connector Diagrams

    MXP and MSP Connector Diagrams Figure B.1: MXP (myRIO eXpansion Port) connector diagram.
  • Page 144 APPENDIX B. MXP AND MSP CONNECTOR DIAGRAMS Figure B.2: MSP (miniSystem Port) connector diagram.
  • Page 145: C Labview Quick Tips

    LabVIEW Quick Tips LabVIEW offers a huge number of keyboard shortcuts to help you to program more efficiently. This appendix lists some of the most commonly-used shortcuts. You may also wish to print out this LabVIEW Quick Reference Card (2010) C.1 Find VIs and learn how they work Quick Drop: Ctrl+Space in block diagram, start typing the name of the VI Context Help: Ctrl+H to toggle on and off, hover cursor over any object...
  • Page 146 APPENDIX C. LABVIEW QUICK TIPS Open up more space between objects: Ctrl+[left mouse drag] in white space between objects; drag horizontally to open up horizontal space, same idea for vertical space, and drag diagonally to open up horizontal and vertical space at the same time Clean up wires: Right-click on the wire, choose “Clean Up Wire”...
  • Page 147: D Build A Stand-Alone Application

    Build a Stand-Alone Application During development you normally connect NI myRIO to your computer with a USB cable. Once development is complete you can easily deploy your project as a stand-alone application stored on the myRIO solid-state hard drive that starts automatically when you power up the myRIO;...
  • Page 148 APPENDIX D. BUILD A STAND-ALONE APPLICATION...
  • Page 149: E Marble Sorter Construction Details

    Marble Sorter Construction Details To be continued...
  • Page 150 APPENDIX E. MARBLE SORTER CONSTRUCTION DETAILS...
  • Page 151: F Video Tutorial Links

    Video Tutorial Links F.1 Image Acquisition and Calibration Camera Setup Principles – From the minimum feature size determine the necessary camera-to-object distance to obtain the desired spatial resolution and field-of-view (FOV). Set Camera Defaults in NI-MAX – Use NI-MAX to set the USB webcam video mode (resolution and frame rate), select color (RGB) or grayscale acquisition, set the camera attributes (brightness, contrast, focus, etc.), and save as the default for all NI vision-related programs.
  • Page 152 Step 4: Create LabVIEW Project – Coin Caliper I Demo Step 4/7: Create a new LabVIEW project for execution on the NI myRIO real-time target, and then prepare the block diagram. Step 5: Configure “Vision Acquisition” Express VI –...
  • Page 153 .lvproj file, and view the organized files. MVA Main.vi Quick Tour – Quick-paced tour of the “Main” VI: while- loop, case-structure, state queue, front-panel controls, NI myRIO ports, and data highway. MVA States – Review the standard states (qsm, myRIO, image), the example application-specific state, and the expansion states.
  • Page 154 APPENDIX F. VIDEO TUTORIAL LINKS Standard States (qsm) initialize: Image Buffer – (qsm) initialize activity: Create an image buffer with “IMAQ Create” and then merge the reference into the data highway. (qsm) initialize: Front-Panel – (qsm) initialize activity: Initialize a front- panel control or indicator with an “Invoke Node.”...
  • Page 155 APPENDIX F. VIDEO TUTORIAL LINKS illustrate how to change the camera mode and attributes in NI-MAX and then retrieve these values with Vision Acquisition Express VI. (image) analyze – (image) analyze: Illustrate how to load a Vision Assistant script into the Express VI. (image) overlay –...
  • Page 156 APPENDIX F. VIDEO TUTORIAL LINKS Rearrange States – Reposition a state in both the state type def and in the case structure’s subdiagram ordering. Add State at End – Add a state at the end: open the state type def, edit the enumerated control, show two ways to create a new case-structure subdiagram.
  • Page 157 APPENDIX F. VIDEO TUTORIAL LINKS Step 5: Connect Script – Coin Caliper II demo Step 5/15: Connect the Vision Assistant Express VI controls and indicators to the data highway. Step 6: Obtain ROI – Coin Caliper II demo Step 6/15: Use a “Property Node”...
  • Page 158 APPENDIX F. VIDEO TUTORIAL LINKS F.5 NI Vision Assistant Batch Processing Batch Process a Folder of Images – Apply a Vision Assistant script in batch mode to process a set of images, e.g., flip the image geometry of a set of images. Binary Images Remove Small Objects –...
  • Page 159 APPENDIX F. VIDEO TUTORIAL LINKS Grayscale Images Find Energy Center (Centroid) – Find the X-Y coordinates of the energy center (centroid) of an image. Suppress Highlights – Use the “Grayscale | Operators” with “Min” option to suppress the highlights (hotspots) in a grayscale image. Pixel intensitiies that exceed a threshold are clipped to that threshold value.
  • Page 160 APPENDIX F. VIDEO TUTORIAL LINKS Grid Calibration – Set up a grid-based calibration to correct camera lens and tangential distortion: print the grid target, convert the image to grayscale, and evaluate the performance of the available distortion models. Correct a Grid-Calibrated Image –...
  • Page 161 APPENDIX F. VIDEO TUTORIAL LINKS Measure Width with “Clamp (Rake)” – Measure the height or width of an object with the “Clamp (Rake)” step. Measure Width with “Clamp (Rake)” (Rotated ROI) – Measure the height or width of an object with the “Clamp (Rake)” step that uses a rotated ROI referred to a local coordinate system.
  • Page 162 APPENDIX F. VIDEO TUTORIAL LINKS Adjust Overlay Text Alignment – Adjust the horizontal and vertical alignment of an overlay text label. Select Overlay Text Font – Select the “NI Vision” user-defined text font and set its attributes such as font size and alignment. Graphics Overlay Line –...
  • Page 163 – Place and configure the NI myRIO Analog Output Express VI. myRIO Onboard Button – Place the NI myRIO onboard button Express Create Formatted Text String – Create a formatted text string with the “Format Into String” VI. The syntax is similar to the “printf” function in C.

Table of Contents