Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

I would like to implement a DVR, i.e.: continues recording to the computer's hard drive.

Hi

I am using NI IMAQ 3.7 and a NI1428 PCI CAMERA LINK BASE frame grabber.
I would like to implement a DVR, i.e.: continues recording to the computer's hard drive.
I thought about using their "LL Sequence demo" that records N buffer to the host's RAM and then call the function "imgSessionSaveBufferEx"
Is it the right configuration?
Is there any better alternative?
I'll appreciate if some one can send me a suitable code for this application

Thanks
0 Kudos
Message 1 of 7
(5,434 Views)
Hi amirb,

Here's a great resource for general purpose information on data streaming:

http://zone.ni.com/devzone/cda/tut/p/id/6355

For IMAQ applications, I would suggest starting with the LL Ring example, which is a continuous acquisition,  The LL Sequence example is a finite acquisition. I have several good examples for LabVIEW, but have not written anything for C yet.  Starting with the LL Ring example, you can open a file during configuration with CreateFile().  Make sure to use the FILE_FLAG_NO_BUFFERING flag to prevent the OS from buffering the image data.  This significantly enhances file IO efficiency for sequential reads and writes.  In the acquisition thread, just after imgSessionExamineBuffer, you can write the data to file using WriteFile().  Unbuffered writes must be done in a multiple of the disk sector size, usually 512 bytes, so you will need to calculate the size of the image buffer and round up.

Windows File IO resources:
http://msdn.microsoft.com/en-us/library/aa364232(VS.85).aspx

Most modern hard drives are capable of 50-70MB/s, so depending on your acquisition rate, you may need a few drives in a RAID array.  The NI HDD-8263 (sine.ni.com/nips/cds/view/p/lang/en/nid/203954) would easily keep up with any acquisition with the PCI 1428.

Thanks,
Brent
Message 2 of 7
(5,420 Views)

Hi, was searching the forum to do exactly that: unbuffered IMAG Image streaming to disk, so thanks for the info. I had the impression I needed to use a special Win32 Open File.vi to open a file in unbuffered mode. Is this also possible with the standard VI? My second question is how best to match the 512 byte multiple write requirement. I can check the image size with the "flatten to string" trick, but this seems like a bit of a hack to me. Is there a better way to do it? Even if I use the trick, how can I increase the size to the next 512 byte multiple without copying the data?

 

Dixie

0 Kudos
Message 3 of 7
(5,296 Views)

Hi Dixie,

 

I’m not sure exactly what you are referring to with the “512 byte multiple” write requirement. Could you please elaborate?

 

For information on how to stream to disk with NI-IMAQ, have a look at this DevZone article specific to NI Vision. I hope this helps 🙂

David G
Sales Engineer - SE Michigan & N Ohio
National Instruments
0 Kudos
Message 4 of 7
(5,262 Views)

Hi David,

 

What I meant was the comment from the post above that "Unbuffered writes must be done in a multiple of the disk sector size, usually 512 bytes, so you will need to calculate the size of the image buffer and round up" . I can calculate the size, but then simply rounding up and writing more bytes with Win32 WriteFile() would lead to access violations. This means that I have two choices:

 

1) copy the entire image into a larger buffer of the proper size which seems very wasteful and partially negates the point of doing unbuffered writing in the first place. 

 

or

 

2) split the write into two parts: first write the largest part of the data that is N*512 bytes and then copy the last few bytes that are left into a 0 padded buffer of 512 bytes and write that separately

 

I think both options are a bit cumbersome and I would like suggestions for a better way. If there is a way of making an IMAQ image of size N*512 from the start that would be great.

 

Thanks for the link, I'll have a look at the article.

 

Dixie 

0 Kudos
Message 5 of 7
(5,252 Views)

Hi Dixie,

 

I wrote that article several years ago and it needs to be updated.  All of the benchmark results shown were acquired using the NI Vision AVI file writing functions, which while convenient and straightforward, are not the most efficient way to put images on disk. In the mean time we have created more efficient tools using the winapi functions for unbuffered reads and writes. The attached examples are not completely polished, but should provide a good start.

 

Unbuffered IO operation do need to be performed in a multiple of the disk sector size, which is usually 512 bytes. In the general case, an image is not a multiple of 512 bytes, but this really doesn't pose a problem.  We can calculate the image data length and round up to the next sector.  No additional copy is required. Alternately, you can manually choose an image size that is an even multiple.

 

In some cases you can actually achieve better throughput by copying multiple small images into one larger "mosaic" image before writing to disk.  For high frame rate applications with small image sizes, the copy is less of a penalty than waiting on a synchronous IO operation to complete for each acquired image. 

 

Thanks,

Brent 

 

 

 

0 Kudos
Message 6 of 7
(5,229 Views)

I'm running into the same problems: building a DVR geared for 500 fps @1.3Mpixel, based on an 8 core machine with a 9x RAID array capable of 700MB/s sustained, but only when the write chunk size is of the order of 6MB (and yes, obviously sector aligned for unbuffered disk write). And solutions based on IMAQ image to Array.vi, Replace Array Subset are sooo inefficient. Your examples in streaming.zip seem what I'm looking for, though the VIs are a little untidy.

Please keep me posted too if there is any new on this thread. Thanks!

Eneico

0 Kudos
Message 7 of 7
(4,789 Views)