cancel
Showing results for 
Search instead for 
Did you mean: 
Knowledge Base

Community Documents

Top Contributors
Sort by:
  Find the Fruit Experiment My wonderful son had just turned 18 months old. It is such a exciting age. He is getting remarkably good at identifying and naming "stuff" in the world around him. Also, he is getting a little too good at demanding more of that "stuff". But that’s a different story   A child’s ability to identify and name objects doesn't magically happen. Like most parents, I've spent countless hours flicking through picture books, repeatedly naming the objects on each page.     We take it for granted that our massive adult brains can see a picture of, for example, an apple... and just know it's an apple. But through training a little kiddie, I realise how complex object identification is.     In one book an apple looks like this...   ...in another book, an apple looks like this...   ... while, in another book, an apple looks like this...             So what makes an apple an apple? The colour? The size? The shape?   Question Being an unashamed nerd, I wondered if it would be easier to teach a computer to identify pictures of fruit than an 18 month old child.   Answer A resounding YES!! It took me several weeks to teach my son a dozen types of fruit. Armed with a copy of LabVIEW, I was able to teach my PC to do the same thing in just 45mins.   Disclaimer: Existing processing technology (and, certainly, my silly applications) do NOT come close to the wonders of the human brain. My awesome son can already do many things that no technology can – including converting an apple into energy [suck on that PC!!].   This is just a fun, tongue-in-cheek experiment.    Experiment Part #1: Find Fruit in Static Images      Using LabVIEW to classify objects in static imagery is easy!! The Vision Development Module (VDM) installs all of the LabVIEW functionality required to load and process images - including dedicated functions for object classification through colour or shape. VDM also installs a stand-alone Classification Training application, which allows you to teach your application what different objects (or, in my case, fruit) look like.     NI Color Classification Training Interface You simply create object classes (banana, apple, orange etc), then provide examples of what each class (fruit) looks like. The app then generates a classification file (.clf), which can be quickly loaded into a LabVIEW app.   The only real coding I had to do was some basic morphology, which allowed me to locate and separate the different objects (fruit) within the image.   This requires a 4 step process...   1. Remove the White Background. Apply a threshold to the image, to produce a binary image (ie. all pixel values are either 1 or 0). Clusters of 1's, known as Binary Large Objects (BLOBs), might be a fruit!   2. Remove Noise. Apply erosion to the BLOBs, to strip layers of pixels from the periphery of the BLOBs to remove noise (false fruit) and separate the BLOBs.   3. Fill Holes. Apply dilation to the image, to add pixels back to the innner and outer periphery of the blobs, thereby filling holes which could cause erroneous readings.   4. Optional: remove any objects touching the border of the image (ie. Fruit that are partially off-screen)   Once the locations of potencial fruit are found, their positions (defined by regions of interest) can be passed the prebuilt classification functions.   Job done.   Experiment Part #2: Find Fruit in Live Camera Feeds   Next, I wanted the code to classify fruit in live images streamed from a camera – a significantly more complicated task. As anyone who has worked on machine vision application will know, it is imperative that you have appropriate camera, optics and lighting. I had none of those things   Best Practice 1: Select a sensitive, high-res camera that provides full control over everything from focus and shutter speed, to gain and white balense. My Camera: I used a the crappy webcam, which is integrated in my laptop. The webcam provided minimal control over acquisition parameters   Best Practice 2: A quality ring light (provides consistent illumination) and a diffuser (to minimise reflections) My Lighting: The flickery office strip lights   Due to the immense limitations in my setup, colour classification would not work. Instead, I moved to geometry based classification - by recreating the classification file using the NI Particle Classification Training Interface (installed with VDM). Against all odds, this worked great!     Armed with my new particle classification file, I then replaced the IMAQ functions that load images from disk with the IMAQdx functions that streamed images from my webcam.   The resulting program was remarkably resilient to focus, lighting and even image rotation.       Requirements LabVIEW 2014 Vision Development Module     Steps to Run the Code 1.          Download attached zip file, and extract content onto your desktop 2.          Open Fruit Classifier.lvproj. From the project, open Fruit Classifier (StaticImages).vi 3.          Using the file path control at the bottom of the front panel, select one of the supplied fruit images (inside a subfolder called Images) 4.          Run the code   Note: You are welcome to try the code with images of your own. This may require to train the code to classify the new fruit. To do this, open the Fruit (Colour Classifier)2.clf in the Color Classification Tool, open your new image, and tell the tool what the different fruit are.   The code is fairly neat and well documented, so should be easy to follow.     Useful Resources Learn More About Machine Vision A Practical Guide to Machine Vision Lighting   Update: As per request, I have just uploaded the code in LabVIEW 2013
View full article
I was working on a presentation for an internal user group and started playing around with race conditions and how to avoid them.  This VI was the result.   So this VI has two FOR loops that each run 25 times in parallel.  Each loop attempts to increment the variable by doing a Read, Increment, Write process.  I did this using local variables, global variables, a Set/Get Functional Global Variable, an Action Engine with Get/Set/Increment actions, and a Data Value Reference.  These two loops were ran 100,000 times and benchmarks were done out of curiosity on performance.   This VI also shows one of my pet peeves: the Set/Get FGV.  As I have argued with people, you do not avoid race conditions just by using a FGV.  In fact, you just made things worse by using the FGV over a simple Global Variable (just look at the execution times).  It is only when you protect the entire Read, Modify, Write as an entire entity do you avoid the race conditions.  Race Conditions and Functional Global Variables in LabVIEW   So feel free to try out my code.  Tell me if I did something stupid or if there is something else you would like compared in here.     Code saved in LabVIEW 2014.  The main VI is Race Conditions.vi   Revision 1: Added a case for Semaphores to protect the global variable to prevent the race condition.  It should be clear that Semaphores are SLOW.
View full article
Overview There is a potential trap in using the "Std Deviation and Variance.vi" of the Mathematics >> Probability & Statistics Palette. Description I have argued elsewhere that among other Math VIs, the Std Deviation and Variance.vi has a default setting that may not necessarily be the one the user may want to use. It is possible to use the VI without specifying the "Weighting" input, which is not a required input, and defaults to the "Sample" definition. As illustrated in this example, the only useful option is "Sample", as the "Population" option does not really compute the "Population Variance", which formally would require knowledge of (and therefore inputting) the population mean. The example generates N (default = 10) Poisson random variables with mean Lambda (default = 1) and computes the Variance of that sample using 3 methods: - "Sample" option of the Std Deviation and Variance.vi - "Population" option of the same VI - True "Population" variance formula, using the known population mean (= lambda) The mean is subtracted from these values and the results are stored and the process is repeated over and over again until you stop the VI. The idea is that for a Poisson variable, "Variance = Mean", loosely speaking, therefore any difference is of interest. Each set of values is histogrammed and the overall mean of these distribution is calculated (the <Mean - Variance> indicators at the bottom right). In other words, unless for whatever reason you are interested in a biased result, you do not want to use the "Population" option (luckily, this is not the default). However, if you want to use the TRUE definition of the "Population" definition of the variance, you have to compute it yourself (for instance as shown in the attached VI), because Std Deviation and Variance.vi will be of no help to you. Steps to Implement or Execute Code Run the VI Observe how the <Mean - Variance> of the "Sample" calculation is unbiased, as is the "True Population" calculation, while the "Population" option of the Std Deviation and Variance.vi gives a biased result ( = lambda/n). Requirements Software LabVIEW 2013 Hardware None Additional Images or Video
View full article