From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

max min math function in Vision Builder calculator

Hi all,
 
Hope this is the most appropriate board. Couldn't see one for machine vision software.
Please let me know if I should post some where else.
 
I'm in the process of configuring Vision Builder for a 2 camera industrial measurement application. Seems pretty much ideal for my application. One thing I've found in trying to account for initial conditions, is that min/max functions would be very handy within the calculator module. That is, a block which would simply pass the min or max value of the input since start of the inspection.
 
Does anyone know if min/max functions can be constructed from the available functions?
I've tried, but haven't found a way.
If not possible, my application will survive, but it would be good if these functions could be provided in the future.
 
Any advice appreciated!
 
Greg Shearer
0 Kudos
Message 1 of 23
(3,988 Views)
Greg,
 
Good news!
 
You can do what you want by combining a "greater than" function with a "selector" function.  I have attached a screenshot showing how I accomplished your request.
 
Basically you use the "greater than" symbol to determine which input is larger and then use the "selector" to select the larger input based off of the output of the "greater than" function.
 
If I did not answer your question please inform me.
 
Lorne Hengst
Application Engineer
National Instruments
Message 2 of 23
(3,979 Views)
Lorne,
 
Thanks for your response. Very elegant! Unfortunately I don't think its quite what I need, although I'm going to keep thinking along those lines. I'm not very experienced with the calculator environment yet and I'm sure there are a lot of features I simply haven't realised yet.
 
What I'm really trying to do is register the initial value of a measurement. The application is to measure extension of steel cable as it undergoes destructive tensile testing. The cable has white cable ties applied as gauge markings at nominal 600mm separation. Ideally, the system output will be actual extension since the beginning of the test. This is easy to determine accurately if the initial sample gauge length can be captured. This is where I thought a 'min' function block would be handy. However, the measurement is not being compared with any other measurement, just its previous value. So, the 'min' block I had in mind would only have one input and would simply pass the lowest value seen since start of the inspection.
 
What I haven't found is a way of structuring the inspection which supports this requirement. That is, outputs determined at a point some way through an inspection can't be referenced by a calculation located earlier in the inspection. Alternative to a 'min' function would be an 'initial value' or 'first scan' type function block which would allow for capturing a value to an output on the first scan of the inspection only. This value could then be used in all subsequent scans to determine the actual change from initial value.
 
Anyway, I know all this could be achieved within the LabView environment, but the Vision Builder AI system is basically all that is needed for this application. As it is, I'm sure my application will work fine by simply subtracting my nominal gauge length of 600mm from all measurements. It just means that, depending on the exact positioning of the gauge marks, the system will generally report slight +ve or -ve extension at the beginning of inspections. Subsequent data processing can correct this offset, so no real drama in this situation ... just not particularly elegant!
 
Thanks again for your reply. If you can see I'm missing something pretty basic conceptually, PLEASE let me know. I have to say that I've been very impressed with the power and ease of use of the Vision Builder AI environment.
 
Greg
0 Kudos
Message 3 of 23
(3,972 Views)

Greg,

Thanks for explaining the issue more thoroughly.  I am still a bit confused regarding why you are unable to do what you want.

Originally I thought you wanted to pass the value inside the same inspection.  Is the problem that you are unable to pass this minimum value from one inspection to another?

If you are dealing with multiple inspections and want to pass the minimum value from inspection to inspection, then you are in luck.  You can use Datasocket to store your minimum value, Datasocket can act as a global variable storage mechanism.

I am convinced that you can do what you want fairly easily in Vision Builder, but I think I need more information about your application.  Below is how I understand your application, please tell me if I misunderstood anything.

You have a long steel cable that you are stretching until it snaps.  Along the length of the cable you have many white cable ties initially spaced 600mm apart.  As the cable stretches you are measuring the distance between the cable ties so that you can see how the cable is stretching.

Questions:
How exactly are you using Vision Builder to measure the distance between the cable ties?
a.  Do you run 1 inspection for each pair of cable ties (50 cable ties would be 49 inspections)?
b.  Or, do you just run one inspection which measures the distance between all of the cable ties?

Do I understand your system correctly or am I completely off base?

Like I said, I am 99% sure that you can do what you want in Vision Builder.

Lorne Hengst
Application Engineer
National Instruments

Message 4 of 23
(3,956 Views)
Lorne,
 
You're not too far off base, although the inspection I'm doing is simpler than your interpretation.
Absolutely correct on stretching steel sample until it breaks.
However there are only 2 cable ties (gauge marks) involved, one near each end of the sample.
There is also only the one inspection, and it is really very similar to the example 'Tutorial 5 - Two cameras inspection' supplied with the current Vision Builder release. I first saw this example on the NI website and was very impressed, as it is very similar to the application I'm building. The system I'm building is replacing an older custom built system, and feeds data serially to a quality control system. I may replace this with a TCP interface in the near future.
 
So, my inspection uses 2 cameras, one directed at each gauge mark. Calibration of the two images is OK, much as in the NI example. Also, I have a 'standard' gauge bar with a range of engraved markings, which allows calibration of the image separation of the cameras. Again, much as per the NI example.
 
This means that after calibration will be able to place a marked sample into the test rig and tell exactly the separation of the gauge marks. This is fine, and will be very close to ... but not exactly ... 600mm, but what the inspection needs to report is the sample extension from the commencement of the inspection, NOT the absolute length of the sample.
 
So, ideally, on the first pass of the inspection the value reported should be 0.000mm. That is, current gauge separation minus the original gauge separation. Then, as load is applied and the sample stretches, the extension (current measurement minus original) should increase. Just for your information, the material being tested is called steel strand (used for bridge cables, concrete reinforcement etc). We typically record extension only up to about 1.5% (9mm) during testing, but the sample is tested to breaking.
 
The thing I haven't been able to figure out is how to capture the original gauge separation for use as I've described. As mentioned in my earlier posts, I've imagined a 'min' function or 'first scan trigger' would be required to allow capture of what is effectively an initial condition. If you know of a way to capture and retain initial conditions e.g. a measurement, during the first scan of an inspection, then that is what I need!
 
But PLEASE don't spend too much time or effort on this enquiry. As I mentioned earlier, I can correct for any initial offset within the quality system data processing environment. The quality system records the progress of each sample test (or inspection), recording both extension data (from the Vision Builder application) and tensile data from another interface. As we know there should be 0 extension at the commencement of an inspection, any initial offset from 0 can be corrected by the quality system.
 
I'm not really expecting Vision Builder to do any more. I've already been very impressed with what can be done with very little programming effort. I just thought I'd ask the question in case I'm missing something obvious, and I can see having knowledge of initial conditions may be useful in other applications.
 
At this stage, I intend determining the extension figure as current measurement minus 600mm. As the initial gauge markings won't be at exactly 600mm, this will result in a small +ve or -ve offset at the beginning of each inspection. I expect this offset will barely be significant, and can be corrected within the quality system.
 
Out of interest, I'm commencing installation of the new equipment tomorrow and hope to have it up and running within a couple of days. I'll let you know how I go! One thing I'm not really sure about is the precision I'll get from the system, although I expect it will be quite adequate. Luckily, lighting and camera mounting was taken care off for the original installation, so all I really have to do is install a PC and new cameras and carry out final configuration of the inspection software.
 
Here's hoping!!!!
 
Greg
0 Kudos
Message 5 of 23
(3,950 Views)
Greg,
 
What I mentioned in the previous post will allow you to keep the minimum value throughout your inspections.  You will need to use datasocket.
 
DataSocket is a utility that National Instruments created to make TCP/IP communications easy with National Instruments software.  Basically, you can open the DataSocket server (goto the Start Menu->Programs->National Instruments->DataSocket and select "DataSocket Server").  The server runs on your machine and your program can store values onto the server and read values off of the server.  DataSocket is very easy to use.
 
I altered the Tutorial 5 to do what you want.  I added 4 steps to the inspection and now it should do what want (or very close to it).
 
Added Steps:
1.  Created a DataSocket step.  The step initializes a DataSocket Variable called "MinLength" to a large value (I used 30000).  I selected the option to only run this step on the first inspection, since it is an initialization step.
2.  Created a DataSocket step.  This step reads the DataSocket Variable called "MinLength" and stores the value in the Vision Builder variable "Minimum Length".
3.  Created a Calculator step.  This step Compares the recently calculated variable "Part Width" with "Minimum Length" and outputs the smaller of the two to the variable "New Minimum Length".
4.  Created a DataSocket step.  This step writes the variable "New Minimum Length" to the previously created data socket object "MinLength".
 
When the next inspection starts it will execute every step execept for step 1 (remeber I set step 1 to only run on the first inspection).
 
In order for this Inspection to work you must have started the DataSocket server.
 
Lorne Hengst
Application Engineer
National Instruments
0 Kudos
Message 6 of 23
(3,942 Views)

Lorne,

Thanks so much for the advice. That method works fine. It would have taken me a fair while to realise to even investigate the communications tools as a means of achieving what I was after. Thanks again!!

And guess what ..... if you're interested I have another question which is a bit more nitty gritty! I now have the application up and running, but the resolution I'm achieving isn't quite what I was hoping .... although not really too far off.

If you remember, the application uses 2 fixed cameras to inspect 2 gauge marks on a piece of material which is being stretched. Each camera has a field of view of approximately 150mm, which roughly equates to pixel equivalence of 0.25mm. Overall extension of the material being measured is approximately 10mm over the duration of the test.

Problem is that, in essence, 0.25mm is the kind of variation or noise I'm seeing in the overall measurement. I was hoping to see considerably less. Reading various documentation has suggested that 0.25 pixel resolution should be achievable with a good image. I think my images are good .... although they could be better! I expect that given a 2 camera system, achievable resolution should be expected to be of the order of half of this i.e. 0.5 pixel resolution .... but I don't seem to be getting there!!!

Main reason I wasn't anticipating noise is due to the output achieved from the prior system which showed virtually no noise in its generated output. However I know nothing of how the output was achieved technically.

Anyway, the really puzzling thing I've found when looking at the raw pixel measurements being generated is that they seem to 'toggle' or oscillate rather than gradually change in value. For instance, if measuring a sample not under load i.e. essentially a fixed length, the individual X pixel values seem to vary between 2 extreme alternatives rather than just vary slightly around an average. I know this all is essentially to do with the resolution of the system, but as mentioned, I thought I could achieve better.

I may also be missing something to do with synchronisation between the two images involved. To try and ensure synchronisation, acquiring the 2 images are the first blocks in the code, so as far as I can tell they should be obtained at essentially identical times. However, when the raw pixel separation of the gauge marks in the 2 images is monitored (just via screen display) it is clear that the figure essentially 'toggles' between 2 values which are approximately 1 pixel apart. Clearly, this is associated with the addition of the 2 individual image values combining. And this is what I see in the final system output.

Hopefully what I've outlined above is clear, although I know it may not be! Just wondering if you might have any clear advice on filtering the sort of variation I'm seeing from my measurements. Although I'm confident that this variation won't badly affect the material characteristics determined from the measurements .... it doesn't look very good ... and convincing others may be a problem! I will try to obtain a graphical image today to give you some idea of the system output.

I'm about to do some more experimenting with edge 'smoothing' and 'steepness' although, even having read the 'IMAQ Vision Concepts Manual', I'm not clear on their correct usage. Trials so far haven't looked encouraging!

Hope you have some advice! If not, do you know anyone who might?

Any suggestions would be appreciated. Thanks again!!

Greg

0 Kudos
Message 7 of 23
(3,928 Views)

Greg,

I am not sure I understand the issue perfectly.  and...  I think understanding your issue in detail is essential to solving the problem.  Can you asnwer a few quetions for me?

1.  What is the resolution of your camera?

2.  What is the color depth of your camera?

3.  What is the field of view of your camera? (I think you said approx 150mm)

4.  Can you send the images of your cable (both ends)?

5.  Your measurement is fluctuating by 0.25mm (jumping back and forth, not evenly), is this correct?

Thanks,
Lorne Hengst
Application Engineer
National Instruments

0 Kudos
Message 8 of 23
(3,920 Views)

Lorne,

You are right. Amasing how difficult it is to explain some situations in words! However, your interpretation sounds pretty close to the mark. I realised overnight that I could have obtained images of each end to show you fairly easily, and will do that today. What has proved ridiculously difficult is grabbing a screen image of the system output as displayed on our interfaced testing system ..... but that is another story! However, to answer your questions:

1. Camera resolution is 640x480 - Basler A601f - selected on price and as original analogue cameras were same resolution.

2. Monochrome - I'll include more on the camera settings later if required.

3. Field of view approx 150mm along the 640 pixel orientation. This is the axis of extension interest.

4. Will reply with images later today.

5. This is where a video or similar would be useful. The observations I've made of the output isn't that it necessarily jumps between 2 extreme values, but that it appears to cycle between the extremes, generally spending more time at the extremes than on the transition between. Hard to describe. But I'll give it a go!
 
While investigating the system yesterday, I set up an overlay display of the difference between the raw X pixel values of the sample gauge marks in the two images. I also displayed the individual gauge mark X pixel values. Both the individual and difference values displayed similar variation characteristics. (This is one reason I'm pretty sure my problem lies purely and simply with base image resolution.) Watching the individual image X pixel values, they would vary over roughly a 0.5 pixel range, however the variation did not appear random. Rather, the values appeared to generally run towards one extreme and then back to the other at varying rates. That is, the values were not simply randomly distributed between the 2 extreme values. This behavior appeared the same for both camera images, and the combined effect resulted in an approximate 1 pixel similarly cyclic variation in the difference value.
 
So it is an apparent approx 0.5 pixel cyclic variation in the individual image X pixel values that is of interest to me. The fact that this occurs in each image independently leads me to suspect that the variation is to do with base resolution. I've tried implementing a simple moving average of the output, but the initial attempt seemed to emphasis the extreme values and result in a more definitely quantised or stepped output. (Here a screen image would be handy!) I'm still investigating a statistical approach to filtering the 'noise', but am not overly hopeful. Either way, I intend to begin using the system for production today and will continue investigating means of improving the output.
 
Hope the explanation above makes things a bit clearer. I will attempt to get camera and system output images today.
And by the way .... Happy Christmas!
 
Greg
0 Kudos
Message 9 of 23
(3,913 Views)

Greg,

Like you said, this sounds like a noise issue.

Some things to check.

1.  Make sure your camera is not autozooming, autogaining, autooffsetting, autofocusing, etc.
2.  Make sure you have good lighting.
3.  Make sure your camera is firmly mounted.

Can you post the pictures of your acquisition, showing subsequent picutures (with an overlay showing the measurements made).

Thanks,
Lorne Hengst
Application Engineer
National Instruments

0 Kudos
Message 10 of 23
(3,901 Views)