Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Need some help getting started with IMAQ and VB.Net

Hi

I am very new to Imaq and quite new to VB. I have 1 month to complete the my software.  I am using a NI PCIe-1427 with a 12bit 1004x1004 greyscale 30fps camera (due to arrive by the end of the week - stuck in South African customs). I have Vision Development module 8.5 and use Visual Basic .Net 2005.

I only have 4 samples (Getting Started, Triggering Ring, Triggering Sequence and Triggering) which show some basics.

My software has the following sequence of events:

1.   Start software
2.   Start live video display (display in 8bit - I am not sure if the camera handles this) with some histogram stretching
3.   Overlay text on live video (updated every 500ms and can be distructive)
4.   Average up to 128 frame, apply more histogram stretching and then display enhanced frame.
5.   Save as a JPEG (8bit so it can be displayed on any computer)
6.   Go back to live video
7.   Repeat steps 4 to 6
8.   Stop live video
9.   Close software

There is some other thing like writing a report and controlling PLCs but I have that covered.

Any help, examples, docs or where to look will be appreciated.

Best regards
Bestbier
0 Kudos
Message 1 of 8
(4,474 Views)
Hello Bestbier,

You can find a more extensive list of examples via in the following location:
C:\Program Files\National Instruments\Vision\Examples\MSVB.NET

I also suggest you use the NI Vision for Visual Basic Reference Help (the file is actually named cwimaq.chm) and the VDM_VB_User_Manual.pdf, both of which are powerful resources.  You can find these documents in the following location:
C:\Program Files\National Instruments\Vision\Documentation

I suggest you consider giving particular consideration to the following CWIMAQVision methods:
DrawText2
Histogram2
WriteJPEGFile

Best Regards,
T. McCarty 
0 Kudos
Message 2 of 8
(4,457 Views)
Hi

Thanks for the reply.

I am getting quite a good picture of how this is going to work. One question on averageing up to 128 frames. I have thought of two ways to do this, the first one I know will work but is the long way of doing it, the second version uses build-in functions which makes it less cumbersome.

First way:
1. Capture frame
2. Use ImageToArray to convert pixels values to an array
3. Add the values from this array to the values in the cumilitive array.
4. Repeat 128 times
5. Divide all the values in the cumilitive array
6. Use ArrayToImage to convert the array back to an image

Second Way
1. Capture frame
2. Use .Add to add this frame to a cumilitive frame
3. Repeat 128 times
4. Use .Devide to devide all the pixels by 128

I know the first way will work, I am not sure about the second way because the frames will be U8 and the cumilitive frame will have to be U16.

Hope this makes some sense

Best regards
Bestbier

P.S. I am still waiting for my supplier to send me the configuration file for the camera (cameralink), that's why I have not tried this.


0 Kudos
Message 3 of 8
(4,423 Views)
bestbier -

I think your second approach will work as well if you accumulate the frames in an I16 image, since the maximum possible value of a pixel is 255*128=32640 which is less than 32767. (which is the maximum pixel value in an I16 image)  Your first approach should work as well, but the second one does sound easier 🙂

Greg Stoll
Vision R&D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 4 of 8
(4,420 Views)
Hi

The second approach does work, but not exactily as planned because if you Vision.Add a U8 image to a I16 image it converts the I16 image to U8.

I solved this by deviding the U8 frames by 128 first and then adding them together.

I have a problem with Viewer.Displaymapping of my live video stream. None of these options do anything.

My camera is 12bit grayscale.

I need to be able to have histogram stretching on the live display


Bestbier
0 Kudos
Message 5 of 8
(4,377 Views)
If you divide a U8 image by 128, you will get either a 1 or a zero.  I wouldn't think adding these together would give you a very good average.
 
I would convert the U8 image to I16 before adding it to the I16, then divide when done.
 
Bruce
Bruce Ammons
Ammons Engineering
0 Kudos
Message 6 of 8
(4,364 Views)
Hi

Sorry, got my wording wrong in the previous post.

I copy the 12-bit image from the viewer into a I16 image.
Then devide by the number of frames I am averaging (up tp 128)
Then I add this image to the cumilitive image.
That image then gets some histrogram processing is displayed and saved.

My current problem is that the Viewer.Displaymapping does not work. Surely the 12bit image has to be resampled to show on the screen. I would like to use .MapGivenRange(Min,Max) to change the way it is mapped. I think I have had this working, not sure, but it does not work any more.

Best regards
Bestbier
0 Kudos
Message 7 of 8
(4,359 Views)
Hi Bestbier,

If you take an I16 image and divide it by 128, you are just bit-shifting each pixel by 7 so you lose the 7 least significant bits. This method gives you an average of the 5 MSB, which reduces your resolution from 12 bits to 5. I imagine you would want more than 5 bits of resolution,  but if you add 128 12 bit images, you could overflow the I16 image. I suggest using the single precision floating point image format. You would have no problem dividing by 128 before or after you add all the images because the calculations would all be floating point. You could then convert back to I16, and have a higher precision average than if you did all the calculations with integers.

When you go to display the image, you can convert from the float to U8 without having to deal with the display mapping, because that conversion just normalizes the float image to the destination range. The reason you have to map from an I16 to a U8 is because you have to tell the display how to convert 16 bits to 12, whereas the float to int image conversion is just a linear equation (m*x+b). In that linear equation, m = 255/(Maximum float pixel value - Minimum float pixel value) and b = -1*(Minimum float pixel value). This is just normalizing the range of float pixel values onto the U8 integer range.

Hope this helps!


Message Edited by Maclean on 12-13-2007 07:50 AM
Maclean G.
Applications Engineering
National Instruments
0 Kudos
Message 8 of 8
(4,341 Views)