I'm using LabVIEW to control a piece of testing hardware that is designed to break test specimens. I am hoping to use a simple USB camera to verify if the specimen has broken, and stop the test. The image of the test specimen will go from bright (test specimen present) to dark (test specimen half-gone). My approach is to use average brightness values (one could do image correlation but it's simply not worth it for simple fail-detection).
I have attached a piece of .VI to grab the screen at a location (where the USB camera is running), as a hack to avoid needing to integrate a camera directly into LabVIEW (all .VI I have found show very complicated, camera model dependent solutions for direct integration).
My questions are:
-I'm struggling to understand the datatype handling: the image seems to be converted from array, to unsigned byte array, to png, to "image". Is there a suggested datatype to handle these operations? If I were writing this in python, I would perform all operations with the image as an array.
-Does anyone have experience in either using the "image", or png, datatype to perform basic arithmetic (average brightness value)? I am having difficulty finding the operations which accept the proper datatypes, and then output the correct value.
Thanks so much in advance!
Solved! Go to Solution.
If you unbundle the image data, and choose the "image" element, that has all the values of the picture. I'm not sure what order they are in in terms of R, G, and B, but you can probably play around and figure that out. Then you need to find a formula for conversion from RBG to grayscale or brightness (some people like different ratios of the colors). Then add those up.
I've done something similar to this before, but it's on my home computer. I'll see if I can dig it up and post it tonight.
If you want the Image as an Array Value you have function in LabVIEW Vision (IMAQ ImageToArray VI), From the converted data you can process for your need.
Even you have arithmetic operations for Image datatype.
Try taking a look at this code. I can't guarantee it's completely correct, I just wrote it once quickly for something I was trying to test, but it seems like it's similar to what you want, so maybe it will help you.
Hey prettypwnie, thanks for the reply! I sadly can't open that .vi as i've got an older version of labVIEW. Is there a way to save that as a version compatible with 16.0f2?
This is prettypwnie's example saved for LabVIEW 2016. A potentially very nice feature of this example is that it uses LabVIEW's Picture functions, rather than the Vision Toolkit, so you can do some "image analysis" without needing any of the IMAQ/IMAQdx functions. Kudos to prettypwnie (I would not have thought to try this ...).
Thanks so much Bob! This works great: I'm able to take the average brightness value and see it change in realtime.
My current aim would be to take the first 5 seconds average of this value (determine the baseline for a given test), and then apply a threshold condition for a stop condition.
I assume the best way to do this would be a for loop running for 5000ms, then continue into another for loop where the value is always compared to this average?
Thanks so much!
When you start getting into an architecture where you are thinking about doing one thing in a loop, then finishing and going to the next loop for another thing, etc... it's good to take a step back and think about your architecture first. Maybe if you are only doing those two things one after another every time, this will work okay. But what if later you decide you want your program to go back to do another baseline? It is better to use a more flexible architecture, like a state machine. Here is an example for you: