LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write 16 bit images into AVI file

David,

The IMAQImageToArray and IMAQArrayToImage should take care of your needs as it can take many different types of images, and it's output will vary depending on the image type your provide it.

Image Types Supported
IMAQ_IMAGE_U8, IMAQ_IMAGE_I16, IMAQ_IMAGE_SGL, IMAQ_IMAGE_COMPLEX, IMAQ_IMAGE_RGB, IMAQ_IMAGE_HSL, IMAQ_IMAGE_RGB_U64



Regarding your problem with the vertical stripes,
Is it the same snippet of code that is being executed in order to save the first and the subsequent AVIs? If you view the image as it is being acquired, does the image also exhibit this behavior on the second AVI? You might try displaying the image, and seeing if this happens, so that we can narrow down where the vertical lines are coming from.

0 Kudos
Message 11 of 33
(2,396 Views)
Hi Michael,

Thanks again for your answer.

Effectively, the same code is used to generate the two AVIs.

In my application, I have a Start button that call the "DoWork" method of a BackgroundWorker and a Stop button that call the "CancelAsync" method of this background worker.

The "DoWork" method is constructed like this :

...DoWork(...)
{
    Declarations,
    Initialisations,
    Acquisition configurations,
    ...
    while(1)
    {
               imaqGrab(NI_SESSION_ID, ImaqLiveFeedImage, TRUE);            // Grab new image

               // Convert 16bits image to color avi
               errChkVISION(imaqDispose(AVIlongArray));                                  // Dispose previous image array 
               AVIlongArray = (unsigned long int *)imaqImageToArray(ImaqLiveFeedImage, IMAQ_NO_RECT , &numCols , &numRows );
               errChkVISION(imaqArrayToImage(ImaqAVIColorImage,AVIlongArray,numCols, numRows));
               errChkVISION(imaqWriteAVIFrame(ImaqAVIColorImage,AVI,"data_to_write",13));

                // Display current image
               errChkVISION(imaqDisplayImage(ImaqLiveFeedImage,handle,TRUE));

                if(IMAQbackgroundWorker->CancellationPending)   // Stop button pressed
                {
                                errChkVISION(imaqDispose(ImaqLiveFeedImage));
                                errChkVISION(imaqCloseAVI(AVI));
                                errChkVISION(imaqDispose(AVIlongArray));
                                errChkVISION(imaqDispose(ImaqAVIColorImage));

                                errChkVISION(imaqCloseWindow(handle));

                                errChkVISION(imaqStopAcquisition(NI_SESSION_ID));
                                errChkIMAQ(imgClose(NI_SESSION_ID,TRUE));
                                errChkIMAQ(imgClose(NI_INTERFACE_ID,TRUE));
                           
                                e->Cancel = TRUE;
                                break;                            // Exit the BackgroundWorker
                  }
                Sleep(0);
    }
}


The first time the BackgroundWorker is called, the AVI file is correct. If the BackgroundWorker is called again, the second AVI has the vertical stripes. If I exit completely the application and start it again, the first AVI is ok while every others have the stripes.

At all the time, the displayed images are correct while making the AVIs.

If instead of usign a color avi to write 16bits images, I cast the images to 8bits and then save it to monochrome AVI, everything is working fine.  So, I suspect that the problem is when I convert the 16bits images to color avi.

Is it possible that even if I use imaqDispose to clear everything before exiting the BackgroundWorker, there is still some garbage that are not cleared until I completely close the application ?

Regards,

David



0 Kudos
Message 12 of 33
(2,382 Views)
David,

I don't see any glaring issues with your code. What happens when you display the converted image at "ImaqAVIColorImage" instead of the acquired image "ImaqLiveFeedImage"? Does it always look correct as well?
0 Kudos
Message 13 of 33
(2,360 Views)

Hello Michael,

 

It’s hard to tell if the « ImaqAVIColorImage » buffer is correct because it is not really viewable (see attachment).

 

But if I reconvert it immediately after saving it the AVI frame and then display it, it is always ok. But when reading back the AVI file, the problem remains.

 

I try several approaches :


  • Not stopping the BackgroundWorker between two acquisitions ;

  • Not closing the acquisition session and interface between two acquisitions ;

  • Not disposing the image buffers between two acquisitions ;

  • Using a “void*” instead of the “unsigned long int *” pointer to use with the imaqArrayToImage and imaqImageToArray functions ;

  • Forcing a really new AVI session by not closing the previous AVI before calling the imaqCreateAVI function  (otherwise, the AVI session is always “33”) ;

  • Try the application on another computer with another frame grabber (same model) ;

  • Other things I don’t remember !

 

The result is always the same : black stripes on the second AVI.

 

So, unless you or someone else have another idea, I think I will try something else (as saving directly the image arrays to a binary file).

 

The only thing I could think of is that a memory location is locked by the first AVI session (or something in my code) and it is only released when stopping completely the application.

 

Thank you for your help !

 

David

0 Kudos
Message 14 of 33
(2,331 Views)
David,

It sounds like you've been doing a lot of troubleshooting! The only other time I've heard of someone having a similar problem (vertical streaks) was when they were using a Redlake camera that for some reason required the shutter to be closed during acquisition. What type of camera/settings are you using? Since the image is fine whenever you save it as an AVI frame and then view it, it's hard to believe that anything is wrong hardware wise, but it may be helpful to know anyway. You don't happen to be resampling or resizing the image before saving are you?
0 Kudos
Message 15 of 33
(2,310 Views)

Michael,

I’m using a PCI-1410 frame grabber tested with three video sources (standard RS-170) : infrared camera, handycam, DV-R. This was tested on two computers with distinct PCI-1410 card. I don’t see this problem if I save 8bits AVI files. I believe this most be a software issue concerning the image conversion to the pseudo 16 bits grayscale AVI.

For troubleshooting purpose, I use a simplified version of my software were I only grab a new image, convert it to RGB image and then save it to the AVI file. There is no resampling, resizing, processing or anything else done on the image. But perhaps I could try to do a bit shift or a resampling and see if the lines are still black (my images are 10bits grayscale). Maybe this will point out some bugs in my conversion algorithm.

And maybe I will just use 8 bits images. I’m not sure the 2 remaining bits worth all the time spent to try to save them.

David

 

PS.: Sorry for the long delay between replies. The new firewall settings prevent me to use the NI forums at work and I must post at home when I can 😞.

0 Kudos
Message 16 of 33
(2,293 Views)
David,

It's hard to believe there is something wrong with the conversion process, especially since the first AVI works perfectly fine. Have you tried creating/allocating completely seperate image buffers, arrays, etc for the subsequent AVI's?
0 Kudos
Message 17 of 33
(2,265 Views)

Michael,


As you suggested, I tried to use new buffers and arrays for the second AVI. I also tried to use a completely separate backgroundworker for the second acquisition sequence (consequently, with absolutely new buffers, arrays, etc.). I still get the same result. I get the same result using another computer too.

 

Now, I’m really out of idea !


David

0 Kudos
Message 18 of 33
(2,254 Views)
David, would it be possible for you to upload your code in its entirety, so that I can try to replicate it on my machine?
0 Kudos
Message 19 of 33
(2,236 Views)

Hi Michael,


There is a very simplified version of my code which can grab an AVI file (in pseudo-16bits format) and playback the acquired files. I was able to reproduce my issue with this code.


The files were saved in the folder path you can type in the text box and a pop-up window will ask for a file to read. Just select to play an AVI or grab from the card then click the start button.


To reproduce my issue, I grab two AVI files (or more) without closing the application. Every times, the second and other AVI have the black stripes when playing it back.


There is the info on the developing environment :


Microsoft Visual Studio 2005
Version 8.0.50727.42  (RTM.050727-4200)

Microsoft .NET Framework
Version 2.0.50727

Installed Edition: Standard


Microsoft Visual C++ 2005   77633-235-2943881-41426


VISION 7.1.1 and IMAQ 3.7.1


Windows XP Professional.

Thanks again for your help !

David

0 Kudos
Message 20 of 33
(2,222 Views)