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.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How can i average frames using visual basic?

I am using a 1408 frame grabber with a non-standard input and programming in visual basic .net.  It works fine for continuous or single acquire.
 
Is there a way to average frames and have the average displayed to the user?
eg, acquire 30fps but display 15fps with a 2 frame average?
 
Thanks
Jomile
0 Kudos
Message 1 of 7
(3,793 Views)
Hi Jomile,

Do you happen to have Vision Development Module?  If you do, there are two ways to go about it.  If not, then there is no way to do averaging since averaging is image manipulation and is apart of the VDM.

The first way is to convert the images to an array, store them in a buffer and then average them, and reconvert them back into images.

The other way is to convert the image to a larger type, so say if you're working with U8 convert it to an SGL, use the IMAQ Add fuction, then IMAQ Divide then reconvert it back to an image.  The convert does not automatically scale the data so physical values remain the same.  You cannot convert from a U8 to an I16 because they contain the same upper limit of 255.  You also cannot just add two images together without upconverting because you will hit the data type's limit on certain values.

Let me know if this helps or not.

Justin
0 Kudos
Message 2 of 7
(3,787 Views)

Hi Justin,

Thank you for your response.

I am fairly new to using this card. I have looked through the VB manual but cant seem to find out the exact commands to do this.
Currently all i can do is single or continuous acquire and the image is being displayed in the window.

I did see the command to convert the image to an array but there are a few things I am not clear on.

1) How can I access the frame as I am acquiring?

2) Once I access the frame how can I save it as an image or put it into a buffer?

 

I appreciate your help

Jomile

 

0 Kudos
Message 3 of 7
(3,785 Views)
I found the syntax to save the images and get them out of the buffer.
When i try to use the method to convert the image to an array i notice that i dont have it.
 
Is the method CWIMAQImage part of an aditional package i need to install?
 
Thanks again
Jomile
0 Kudos
Message 4 of 7
(3,778 Views)
What you should be looking for is

IMAQImageToArray

For the C API it is:

int imaqArrayToImage(Image* image, const void* array, int numCols, int numRows);

You'll have to do some searching through the documentation to find what the exact VB syntax is but that should be a good starting point.

Justin
0 Kudos
Message 5 of 7
(3,772 Views)
Here is the code that i am using that i know doesnt work but you can get the idea from it.
I want to take 5 images and just as a sanity check i want to convert the first image to an array and then back to an image and store it in the second location of the buffer.
Is this a syntax problem?
 
Thanks
Jomile       
 
AxCWIMAQ1.Images.RemoveAll()
        AxCWIMAQ1.Images.Add(5)
        'Configure Continuous Acquire Region of Interest
        AxCWIMAQ1.ROILeft = 1
        AxCWIMAQ1.ROITop = 1
        AxCWIMAQ1.ROIWidth = 1000
        AxCWIMAQ1.ROIHeight = 1000
        AxCWIMAQ1.AcquisitionType = NationalInstruments.CWIMAQControls.CWIMAQAcquisitionTypes.cwimaqAcquisitionOneShot
        AxCWIMAQ1.AcquireImage()
        AxCWIMAQViewer1.Attach(AxCWIMAQ1.Images.Item(1))
        AxCWIMAQ1.SaveImageToDisk("c:\temp\image1.bmp", AxCWIMAQ1.Images.Item(1))
 
        a = AxCWIMAQ1.Images.Item(1).ImageToArray
        b = a
        AxCWIMAQ1.Images.Item(2).ArrayToImage(b)
        AxCWIMAQ1.SaveImageToDisk("c:\temp\image2.bmp", AxCWIMAQ1.Images.Item(2))
        AxCWIMAQ1.SaveImageToDisk("c:\temp\image3.bmp", AxCWIMAQ1.Images.Item(1))
0 Kudos
Message 6 of 7
(3,766 Views)
It looks like syntax is the problem, but are you getting any errors?  The ArrayToImage and ImageToArray have more parameters than that.  Did you look at the function prototypes to see what they pass back?  In VB, the ImageToArray does not pass back an array.  Look through the help in

Start -> Programs -> National Instruments -> Vision -> Documentation -> NI Vision

Then in there select the cwimaq.chm file.  That's our function API for VB.

Justin
0 Kudos
Message 7 of 7
(3,729 Views)