Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

AVIOuputSession not working with 16 bit Image

Solved!
Go to solution

 I am trying to save incoming data to an AVI using the AVIOutputSession in C# (.Net VS 2008).

The data is a grayscale image and is captured as ImageType.I16, but when I try to use the WriteFrame() method, I get an invalid image type error.

 

I have been reading the forum and I saw a few similar issues with the fix being to convert the images to ImageType.U8 and I can confirm this works, however it destroys the upper 8 bits of my image and (of course) can not be recovered when trying to read the AVI later (using AVIInputSession).

 

I am under the impression (right, wrong or indifferent) that AVI's support 16 bits per pixel, correct?

 

Is this a bug in the NI-IMAQdx?

 

Any help is appreciated,

 

 

Thank you,

 

-Tom

 

 

Code snippet:

 

AviOutputSession aOut = new AviOutputSession(@"C:\TEMP\temp.avi");

VisionImage im = new VisionImage();
for (int i = 0; i < updwnMultiple.Value; i++)
{
    _session.Grab(im, true);
    aOut.WriteFrame(im);                <------------error here!

}
aOut.Dispose();
0 Kudos
Message 1 of 10
(6,748 Views)

Tom.Net wrote:

 

I am under the impression (right, wrong or indifferent) that AVI's support 16 bits per pixel, correct?

 

Is this a bug in the NI-IMAQdx?


Yes and no.

 

At the first, this is not a bug in IMAQdx. (IMAQdx is not involved into AVI creation. IMAQdx does just acquisition, and 16 bit image acquisition correctly by IMAQdx).

 

The problem is more deep. For storing 16 bit video you need a codec with 16 bit support. NI AVI functions - are just interface to codec, nothing more. So, they theoretically can support 16 bit, but only if coded will support this type. As far as I know, the only LEAD codec able to support 16 bit grayscaly (LGRY). But another problem is that this codec cannot handle 16 bit from standard Windows interface, because Windows Bitmaps cannot support 16 bit. As result you can't use this codec through NI AVI functions.

 

Andrey.

 

Message 2 of 10
(6,725 Views)

@Andrey - Thank you for the information.

That is good to know that the AVI class is just an interface to the codec. 

It is unfortunate that this is the case because saving to the AVI during video streaming proved to be very fast and left me with a single file.

Is there another way to grab 'n' frames of data and store them to disk for further analysis (besides individually saving the images one at a time)?

 

After searching online it I am finding it difficult to find a 16 bppp grayscale codec. I know they are out there (via fourcc.org), but actually finding them for download has been the issue.

 

 

Thank you,

 

-Tom

 

0 Kudos
Message 3 of 10
(6,703 Views)
I have successfully done this before by getting the lower byte and upper byte of the image and then making this the red and green plane of a 32 bit colour image. Store the data in an AVI, as they handle colour, and then just invert this process for the player.
Message 4 of 10
(6,686 Views)

Mike Bailey wrote:
I have successfully done this before by getting the lower byte and upper byte of the image and then making this the red and green plane of a 32 bit colour image. Store the data in an AVI, as they handle colour, and then just invert this process for the player.

 

This way will work good for uncompressed AVI. But with compression you will get big troubles with upper byte (because small color deviations will cause big intencities changes in 16 bit file). Mike, which codec was used in your experiments?

 

Andrey.

 

Message 5 of 10
(6,684 Views)

Tom.Net wrote:

 

Is there another way to grab 'n' frames of data and store them to disk for further analysis (besides individually saving the images one at a time)?

 

After searching online it I am finding it difficult to find a 16 bppp grayscale codec. I know they are out there (via fourcc.org), but actually finding them for download has been the issue.


This codec have support for 12/16 bit grayscale:

 

http://leadtools.com/sdk/multimedia/mjpeg2000.htm

 

Otherwise it can be integrated with DirectShow applications only, and such action can be quite complicated when you try to use it from LabVIEW environment (you have to create appropriate wrapper).

 

Andrey.

 

Message 6 of 10
(6,682 Views)

Great information.

 

For my application I am not interested in compression and is actually undesirable.

 

Mike - I will try this, my only concern is speed. The latency in converting each frame could sink me. I am currently working with a camera that is 1400x1024 at 30fps. The final product will be more like 4Kx1K so speed is a serious factor. Of course the 4Kx1K is a goal, not a requirement at this point.

 

 

Thank you,

 

-Tom

0 Kudos
Message 7 of 10
(6,677 Views)

@Andrey - I downloaded the codec but I am stilling having the issue with an invalid image type (possibly because I am doing it wrong).

I am using C# (.NET) and not Labview anyway. I am using the  LEAD codec, but there are many choices:

 

LEAD H263 Encoder(2.0)

LEAD H264 Encoder(4.0)

LEAD MCMP/MJPEG Codec (2.0)

LEAD MCMW Encoder (3.0)

LEAD MJ2K Encoder (2.0)

LEAD MPEG2 Encoder (3.0)

LEAD MPEG4 Encoder (2.0)

 

 

LEAD H263 Codec(2.0)

LEAD MCMP/MJPEG Codec (2.0) (VFW)

 

I would assume that it is one of the options containing "codec" or the one with "MJ2K" , but I have tried them all with ImageType.I16 and ImageType.U16, but I get the invalid image type error.

 

Any ideas?

 

Thank you,

 

-Tom

0 Kudos
Message 8 of 10
(6,662 Views)
Solution
Accepted by topic author Tom.Net

The following are the LEADTOOLS encoders that support 16-bit Grayscale:
- LEAD MCMP/MJPEG Codec (2.0)
- LEAD MCMW Encoder (3.0)
- LEAD MJ2K Encoder (2.0)

 

But you will be not able to use it through NI functions, becuase these function uses standard Windows way for interfacing with codec, you will be not able to pass your 16 bit image to the codec, because this type is not supported in Windows. I already tried to modify GenAVI example shipped with LEAD library (located in "C:\Program Files\LEAD Technologies\LEADTOOLS Multimedia EVAL 16.5\Examples\Ltmm\C\GenAVI\") and it was unsuccessful.

 

You need to have Microsoft SDK, then develop the DirectShow Filter (Source), which will push your images to the LEAD codec. From another side this Filter should receive your IMAQ images. The "Getting started" example for such filter located in "C:\Program Files\Microsoft SDKs\Windows\v7.0\Samples\multimedia\directshow\filters\pushsource\"...

 

Right now there are no other ways, because "some of the internal objects inside of ltmmConvert controls do not have the ability to connect the 16-bit gray media type, so a color converter filter is inserted causing conversion to 8-bit grayscale." (Italic highlighted text is answer from LEAD engineer).

 

Andrey.

 

Message 9 of 10
(6,658 Views)

Thanks for the information.

 

This is starting to look like a bit of work and seeing as 16-bit AVI are NOT directly called out in my requirements, I am inclined to push this off until it is needed. The 8-bit version does what the requirements call for and this will have to do for the time being.

 


Thank you Andrey for the help and useful information.

I am going to mark your post as the solution, but the solution is that it can not be done (easily) for now.


 

0 Kudos
Message 10 of 10
(6,651 Views)